File tree Expand file tree Collapse file tree 5 files changed +19
-22
lines changed Expand file tree Collapse file tree 5 files changed +19
-22
lines changed Original file line number Diff line number Diff line change 3
3
createFolder ,
4
4
checkFileExists ,
5
5
findApiDir ,
6
- findPagesDir
6
+ findPagesDir ,
7
+ getConfigs
7
8
} from '../lib'
8
9
import { Options } from '../types'
9
10
import colors from '@colors/colors/safe'
@@ -13,7 +14,10 @@ export const createAction = async (
13
14
options : Options
14
15
) : Promise < void > => {
15
16
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'
17
21
const pagesDir = await findPagesDir ( )
18
22
const apiDir = await findApiDir ( pagesDir )
19
23
Original file line number Diff line number Diff line change 1
1
export default {
2
- tsConfig : ( name : string ) : string => `
2
+ tsContent : ( name : string ) : string => `
3
3
import type { NextApiRequest, NextApiResponse } from 'next'
4
4
5
5
// @methods [GET,POST,PUT,DELETE]
@@ -44,5 +44,6 @@ export default {
44
44
return res.status(405).end(\`Method \${req.method} Not Allowed\`)
45
45
}
46
46
}
47
- `
47
+ ` ,
48
+ typescript : false
48
49
}
Original file line number Diff line number Diff line change 1
- import { writeFile } from 'fs/promises'
2
1
import colors from '@colors/colors/safe'
2
+ import { writeFile } from 'fs/promises'
3
3
import { toCamelCase } from './sanitizeRoutes'
4
- import _configs from '../defaultConfig'
5
- import { findConfigFile } from './findConfigFile'
6
- import { Configs } from '../types'
4
+ import { getConfigs } from './getConfigs'
7
5
8
6
export const createFile = async (
9
7
filePath : string ,
10
8
language : string
11
9
) : Promise < void > => {
12
10
// CONFIG OPTIONS
13
-
14
- const { tsContent, jsContent, typescript } : Configs = {
15
- ..._configs ,
16
- ...findConfigFile ( )
17
- }
11
+ const { jsContent, tsContent, typescript } = getConfigs ( )
18
12
19
13
const file = filePath . split ( '/' ) . pop ( ) as string // filename.extension
20
14
const filename = toCamelCase ( file . split ( '.' ) [ 0 ] ?? '' ) // filename
Original file line number Diff line number Diff line change @@ -3,8 +3,10 @@ import colors from '@colors/colors/safe'
3
3
import { join } from 'path'
4
4
import { isDirectory } from './isDirectory'
5
5
import fs from 'fs'
6
+ import { Configs } from '../types'
7
+ import defaultConfig from '../defaultConfig'
6
8
7
- export const findConfigFile = ( ) : any => {
9
+ export const getConfigs = ( ) : Configs => {
8
10
const routePath = join ( process . cwd ( ) )
9
11
if ( isDirectory ( routePath ) ) {
10
12
// check if file exists
@@ -13,18 +15,14 @@ export const findConfigFile = (): any => {
13
15
const jsPath = fs . existsSync ( jsConfig )
14
16
const tsPath = fs . existsSync ( tsConfig )
15
17
16
- if ( ! jsPath && ! tsPath ) {
17
- return { }
18
- }
19
-
20
18
if ( jsPath ) {
21
- return require ( jsConfig )
19
+ return { ... defaultConfig , ... require ( jsConfig ) }
22
20
}
23
21
24
22
if ( tsPath ) {
25
- return require ( tsConfig )
23
+ return { ... defaultConfig , ... require ( tsConfig ) }
26
24
}
27
- return { }
25
+ return { ... defaultConfig }
28
26
}
29
27
30
28
throw colors . red (
Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ export * from './checkFileExists'
6
6
export * from './createFile'
7
7
export * from './createFolder'
8
8
export * from './findDirectories'
9
- export * from './findConfigFile '
9
+ export * from './getConfigs '
You can’t perform that action at this time.
0 commit comments