@@ -7,13 +7,14 @@ import { fileURLToPath } from 'url'
7
7
const __dirname = dirname ( fileURLToPath ( import . meta. url ) )
8
8
9
9
const paramOr = ( map , arg , def ) => map . get ( arg ) || def
10
+ const valueOr = ( value , def ) => value || def
10
11
const makePath = ( ...p ) => Path . join ( ...p )
11
12
const ignoreContent =
12
13
( ...values ) =>
13
14
source =>
14
15
! values . some ( x => source === x )
15
16
16
- const Ignores = [
17
+ const FilesToIgnore = [
17
18
'.git' ,
18
19
'.idea' ,
19
20
'.vscode' ,
@@ -38,13 +39,13 @@ const Ignores = [
38
39
'CODE_OF_CONDUCT.md' ,
39
40
'LICENSE' ,
40
41
'README.md' ,
41
- 'Makefile' ,
42
42
'package.json' ,
43
43
'package-lock.json' ,
44
44
'yarn.lock' ,
45
+ 'tsconfig.build.tsbuildinfo' ,
45
46
]
46
47
47
- const NoDeps = [ 'fs-extra' , 'standard-release' ]
48
+ const DepsToIgnore = [ 'fs-extra' , '@types/ fs-extra', 'standard-release' ]
48
49
49
50
const Templates = [
50
51
{ file : 'ci.yml' , copyTo : '.github/workflows/ci.yml' } ,
@@ -54,13 +55,13 @@ const Templates = [
54
55
{ file : '.dockerignore.root' , copyTo : '.dockerignore' } ,
55
56
]
56
57
57
- const PkgFieldsToKeep = [ 'scripts' , 'dependencies' , 'devDependencies' ]
58
+ const PkgFieldsToKeep = [ 'type' , 'main' , 'types' , ' scripts', 'dependencies' , 'devDependencies' ]
58
59
59
60
function main ( ) {
60
61
console . log ( 'NodeJS Starter Kit - Bootstrapping New Project' )
61
62
62
63
const argv = process . argv . slice ( 2 )
63
- const argMap = new Map ( )
64
+ const args = new Map ( )
64
65
65
66
for ( let i = 0 ; i < argv . length ; i ++ ) {
66
67
const arg = argv [ i ]
@@ -70,18 +71,18 @@ function main() {
70
71
const key = match [ 1 ]
71
72
const value = match [ 2 ]
72
73
73
- argMap . set ( key , value )
74
+ args . set ( key , value )
74
75
} else if ( / ^ - - .+ / . test ( arg ) ) {
75
76
const key = arg . match ( / ^ - - ( .+ ) / ) [ 1 ]
76
77
const next = argv [ i + 1 ]
77
78
78
- argMap . set ( key , next )
79
+ args . set ( key , next )
79
80
}
80
81
}
81
82
82
83
const source = makePath ( __dirname , '../..' )
83
- const dest = paramOr ( argMap , 'destination' , process . cwd ( ) ) . trim ( )
84
- const app = paramOr ( argMap , 'app ' , 'my-app' ) . trim ( )
84
+ const dest = valueOr ( argv [ 0 ] , process . cwd ( ) ) . trim ( )
85
+ const app = paramOr ( args , 'name ' , 'my-app' ) . trim ( )
85
86
const destination = makePath ( dest , app )
86
87
87
88
console . log (
@@ -94,7 +95,7 @@ App: ${app}
94
95
95
96
console . log ( 'Copying Project Files ...' )
96
97
97
- FsExt . copySync ( source , destination , { filter : ignoreContent ( ...Ignores . map ( x => makePath ( source , x ) ) ) } )
98
+ FsExt . copySync ( source , destination , { filter : ignoreContent ( ...FilesToIgnore . map ( x => makePath ( source , x ) ) ) } )
98
99
99
100
console . log ( 'Copying Templates ...' )
100
101
@@ -105,7 +106,6 @@ App: ${app}
105
106
const pkg = FsExt . readJsonSync ( makePath ( source , 'package.json' ) )
106
107
const newPkg = {
107
108
name : app ,
108
- main : 'dist/main.js' ,
109
109
}
110
110
111
111
PkgFieldsToKeep . forEach ( field => {
@@ -114,7 +114,7 @@ App: ${app}
114
114
}
115
115
} )
116
116
117
- NoDeps . forEach ( dep => {
117
+ DepsToIgnore . forEach ( dep => {
118
118
if ( pkg . dependencies [ dep ] ) {
119
119
delete pkg . dependencies [ dep ]
120
120
}
0 commit comments