Skip to content

Commit d6f2a66

Browse files
committed
fix: rename files and fns
1 parent a9baecc commit d6f2a66

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

commands/create.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import {
33
createFolder,
44
checkFileExists,
55
findApiDir,
6-
findPagesDir
6+
findPagesDir,
7+
getConfigs
78
} from '../lib'
89
import { Options } from '../types'
910
import colors from '@colors/colors/safe'
@@ -13,7 +14,10 @@ export const createAction = async (
1314
options: Options
1415
): Promise<void> => {
1516
try {
16-
const extension = options.ts ? 'ts' : 'js'
17+
// CONFIG OPTIONS
18+
const { typescript: tsConfig } = getConfigs()
19+
20+
const extension = tsConfig ? 'ts' : options.ts ? 'ts' : 'js'
1721
const pagesDir = await findPagesDir()
1822
const apiDir = await findApiDir(pagesDir)
1923

defaultConfig.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default {
2-
tsConfig: (name: string): string => `
2+
tsContent: (name: string): string => `
33
import type { NextApiRequest, NextApiResponse } from 'next'
44
55
// @methods [GET,POST,PUT,DELETE]
@@ -44,5 +44,6 @@ export default {
4444
return res.status(405).end(\`Method \${req.method} Not Allowed\`)
4545
}
4646
}
47-
`
47+
`,
48+
typescript: false
4849
}

lib/createFile.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
import { writeFile } from 'fs/promises'
21
import colors from '@colors/colors/safe'
2+
import { writeFile } from 'fs/promises'
33
import { toCamelCase } from './sanitizeRoutes'
4-
import _configs from '../defaultConfig'
5-
import { findConfigFile } from './findConfigFile'
6-
import { Configs } from '../types'
4+
import { getConfigs } from './getConfigs'
75

86
export const createFile = async (
97
filePath: string,
108
language: string
119
): Promise<void> => {
1210
// CONFIG OPTIONS
13-
14-
const { tsContent, jsContent, typescript }: Configs = {
15-
..._configs,
16-
...findConfigFile()
17-
}
11+
const { jsContent, tsContent, typescript } = getConfigs()
1812

1913
const file = filePath.split('/').pop() as string // filename.extension
2014
const filename = toCamelCase(file.split('.')[0] ?? '') // filename

lib/findConfigFile.ts renamed to lib/getConfigs.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import colors from '@colors/colors/safe'
33
import { join } from 'path'
44
import { isDirectory } from './isDirectory'
55
import fs from 'fs'
6+
import { Configs } from '../types'
7+
import defaultConfig from '../defaultConfig'
68

7-
export const findConfigFile = (): any => {
9+
export const getConfigs = (): Configs => {
810
const routePath = join(process.cwd())
911
if (isDirectory(routePath)) {
1012
// check if file exists
@@ -13,18 +15,14 @@ export const findConfigFile = (): any => {
1315
const jsPath = fs.existsSync(jsConfig)
1416
const tsPath = fs.existsSync(tsConfig)
1517

16-
if (!jsPath && !tsPath) {
17-
return {}
18-
}
19-
2018
if (jsPath) {
21-
return require(jsConfig)
19+
return { ...defaultConfig, ...require(jsConfig) }
2220
}
2321

2422
if (tsPath) {
25-
return require(tsConfig)
23+
return { ...defaultConfig, ...require(tsConfig) }
2624
}
27-
return {}
25+
return { ...defaultConfig }
2826
}
2927

3028
throw colors.red(

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ export * from './checkFileExists'
66
export * from './createFile'
77
export * from './createFolder'
88
export * from './findDirectories'
9-
export * from './findConfigFile'
9+
export * from './getConfigs'

0 commit comments

Comments
 (0)