Skip to content

Commit fd20ec5

Browse files
committed
refactor: adjust cmd script
Signed-off-by: Vitor Hugo Salgado <[email protected]>
1 parent 13ba79a commit fd20ec5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cmd/create-nodejs-ts/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { fileURLToPath } from 'url'
77
const __dirname = dirname(fileURLToPath(import.meta.url))
88

99
const paramOr = (map, arg, def) => map.get(arg) || def
10-
const valueOr = (value, def) => value || def
1110
const makePath = (...p) => Path.join(...p)
1211
const ignoreContent =
1312
(...values) =>
@@ -20,9 +19,12 @@ const FilesToIgnore = [
2019
'.vscode',
2120
'.github',
2221
'.husky/_',
22+
'.yarn',
2323
'.yarn/cache',
2424
'.yarn/build-state.yml',
2525
'.yarn/install-state.gz',
26+
'.yarnrc.yml',
27+
'.versionrc.js',
2628
'cmd',
2729
'coverage',
2830
'dist',
@@ -81,7 +83,7 @@ function main() {
8183
}
8284

8385
const source = makePath(__dirname, '../..')
84-
const dest = valueOr(argv[0], process.cwd()).trim()
86+
const dest = paramOr(args, 'destination', process.cwd()).trim()
8587
const app = paramOr(args, 'name', 'my-app').trim()
8688
const destination = makePath(dest, app)
8789

@@ -99,7 +101,9 @@ App: ${app}
99101

100102
console.log('Copying Templates ...')
101103

102-
Templates.forEach(x => FsExt.copySync(makePath(source, 'templates', x.file), makePath(destination, x.copyTo)))
104+
for (const x of Templates) {
105+
FsExt.copySync(makePath(source, 'templates', x.file), makePath(destination, x.copyTo))
106+
}
103107

104108
console.log('Preparing package.json ...')
105109

@@ -108,21 +112,21 @@ App: ${app}
108112
name: app,
109113
}
110114

111-
PkgFieldsToKeep.forEach(field => {
115+
for (const field of PkgFieldsToKeep) {
112116
if (typeof pkg[field] !== 'undefined') {
113117
newPkg[field] = pkg[field]
114118
}
115-
})
119+
}
116120

117-
DepsToIgnore.forEach(dep => {
121+
for (const dep of DepsToIgnore) {
118122
if (pkg.dependencies[dep]) {
119123
delete pkg.dependencies[dep]
120124
}
121125

122126
if (pkg.devDependencies[dep]) {
123127
delete pkg.dependencies[dep]
124128
}
125-
})
129+
}
126130

127131
FsExt.writeJsonSync(makePath(destination, 'package.json'), newPkg, { spaces: 2 })
128132

0 commit comments

Comments
 (0)