create-jwn-js 1.0.17 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/index.js +270 -270
- package/package.json +25 -25
- package/template-vite-node-ts/connect-template.json +34 -34
- package/template-vite-node-ts/docs/index.md +31 -31
- package/template-vite-node-ts/index.ts +0 -0
- package/template-vite-node-ts/jest.config.ts +36 -36
- package/template-vite-node-ts/package.json +2 -1
- package/template-vite-node-ts/src/backend/server/helpers/createConfigServer.ts +18 -18
- package/template-vite-node-ts/src/backend/server/helpers/createMariadb.ts +15 -15
- package/template-vite-node-ts/src/backend/server/helpers/createMemcached.ts +14 -14
- package/template-vite-node-ts/src/backend/server/helpers/nameFormaters.ts +8 -8
- package/template-vite-node-ts/src/backend/server/index.ts +54 -54
- package/template-vite-node-ts/src/backend/server/site-schema.ts +27 -27
- package/template-vite-node-ts/src/backend/server/web-routes/index.ts +8 -8
- package/template-vite-node-ts/src/backend/views/Api/v1/Clients/ClientsController.ts +15 -15
- package/template-vite-node-ts/src/backend/views/Api/v1/Clients/__its__/clients.spec.ts +8 -8
- package/template-vite-node-ts/src/scripts/jest.global.setup.ts +21 -21
- package/template-vite-node-ts/src/scripts/jest.global.teardown.ts +8 -8
- package/template-vite-node-ts/src/scripts/jest.setup.ts +17 -17
- package/template-vite-node-ts/vite.config.ts +91 -91
- package/template-vite-vue3-ts/connect-template.json +34 -34
- package/template-vite-vue3-ts/cron.js +89 -89
- package/template-vite-vue3-ts/docs/index.md +26 -26
- package/template-vite-vue3-ts/index.html +18 -18
- package/template-vite-vue3-ts/index.ts +0 -0
- package/template-vite-vue3-ts/jest.config.ts +37 -37
- package/template-vite-vue3-ts/package.json +12 -10
- package/template-vite-vue3-ts/postcss.config.js +27 -27
- package/template-vite-vue3-ts/src/backend/server/helpers/createConfigServer.ts +18 -18
- package/template-vite-vue3-ts/src/backend/server/helpers/createMariadb.ts +15 -15
- package/template-vite-vue3-ts/src/backend/server/helpers/createMemcached.ts +14 -14
- package/template-vite-vue3-ts/src/backend/server/helpers/readManifest.ts +15 -15
- package/template-vite-vue3-ts/src/backend/server/index.ts +52 -52
- package/template-vite-vue3-ts/src/backend/server/site-schema.ts +20 -20
- package/template-vite-vue3-ts/src/backend/server/web-routes/index.ts +8 -8
- package/template-vite-vue3-ts/src/backend/views/Index/IndexController.ts +15 -15
- package/template-vite-vue3-ts/src/frontend/App.vue +29 -29
- package/template-vite-vue3-ts/src/frontend/entry-options.ts +67 -67
- package/template-vite-vue3-ts/src/frontend/helpers/customerPrefetch.ts +45 -45
- package/template-vite-vue3-ts/src/frontend/routes/index.ts +41 -41
- package/template-vite-vue3-ts/src/frontend/shims-plugins.d.ts +17 -17
- package/template-vite-vue3-ts/src/frontend/shims-vuex.d.ts +9 -9
- package/template-vite-vue3-ts/src/frontend/store/fetch.ts +173 -173
- package/template-vite-vue3-ts/src/frontend/store/index.ts +130 -130
- package/template-vite-vue3-ts/src/frontend/store/types.d.ts +83 -83
- package/template-vite-vue3-ts/src/frontend/views/Error/Error.vue +61 -61
- package/template-vite-vue3-ts/src/frontend/views/Index/Index.vue +26 -26
- package/template-vite-vue3-ts/src/frontend/views/Index/__tests__/Index.spec.ts +30 -30
- package/template-vite-vue3-ts/src/helpers/langLink.ts +16 -16
- package/template-vite-vue3-ts/src/helpers/parseLang.ts +9 -9
- package/template-vite-vue3-ts/src/scripts/jest.global.setup.ts +21 -21
- package/template-vite-vue3-ts/src/scripts/jest.global.teardown.ts +8 -8
- package/template-vite-vue3-ts/src/scripts/jest.setup.ts +23 -17
- package/template-vite-vue3-ts/vite.config.ts +89 -89
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
## create-jwn-js
|
|
2
|
-
|
|
3
|
-
Create jwn-js utility
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
```bash
|
|
7
|
-
yarn create jwn-js project-name
|
|
1
|
+
## create-jwn-js
|
|
2
|
+
|
|
3
|
+
Create jwn-js utility
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
yarn create jwn-js project-name
|
|
8
8
|
```
|
package/index.js
CHANGED
|
@@ -1,271 +1,271 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const margv = require('margv')
|
|
6
|
-
const argv = margv();
|
|
7
|
-
const prompts = require('prompts');
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
yellow,
|
|
11
|
-
blue,
|
|
12
|
-
red
|
|
13
|
-
} = require('kolorist')
|
|
14
|
-
const cwd = process.cwd()
|
|
15
|
-
const FRAMEWORKS = [
|
|
16
|
-
{
|
|
17
|
-
name: 'vite-node',
|
|
18
|
-
color: yellow,
|
|
19
|
-
variants: [
|
|
20
|
-
{
|
|
21
|
-
name: 'vite-node-ts',
|
|
22
|
-
display: 'TypeScript',
|
|
23
|
-
color: blue
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: 'vite-vue3',
|
|
29
|
-
color: yellow,
|
|
30
|
-
variants: [
|
|
31
|
-
{
|
|
32
|
-
name: 'vite-vue3-ts',
|
|
33
|
-
display: 'TypeScript',
|
|
34
|
-
color: blue
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
]
|
|
39
|
-
const TEMPLATES = FRAMEWORKS.map(
|
|
40
|
-
(f) => (f.variants && f.variants.map((v) => v.name)) || [f.name]
|
|
41
|
-
).reduce((a, b) => a.concat(b), []);
|
|
42
|
-
|
|
43
|
-
const renameFiles = {
|
|
44
|
-
_gitignore: '.gitignore'
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function init() {
|
|
48
|
-
let targetDir = argv["$"][2];
|
|
49
|
-
let template = argv.template || argv.t
|
|
50
|
-
const defaultProjectName = targetDir || 'vite-node';
|
|
51
|
-
let result = {}
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
result = await prompts(
|
|
55
|
-
[
|
|
56
|
-
{
|
|
57
|
-
type: targetDir ? null : 'text',
|
|
58
|
-
name: 'projectName',
|
|
59
|
-
message: 'Project name:',
|
|
60
|
-
initial: defaultProjectName,
|
|
61
|
-
onState: (state) =>
|
|
62
|
-
(targetDir = state.value.trim() || defaultProjectName)
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
type: () =>
|
|
66
|
-
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm',
|
|
67
|
-
name: 'overwrite',
|
|
68
|
-
message: () =>
|
|
69
|
-
(targetDir === '.'
|
|
70
|
-
? 'Current directory'
|
|
71
|
-
: `Target directory "${targetDir}"`) +
|
|
72
|
-
` is not empty. Remove existing files and continue?`
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
type: (_, { overwrite } = {}) => {
|
|
76
|
-
if (overwrite === false) {
|
|
77
|
-
throw new Error(red('✖') + ' Operation cancelled')
|
|
78
|
-
}
|
|
79
|
-
return null
|
|
80
|
-
},
|
|
81
|
-
name: 'overwriteChecker'
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
type: () => (isValidPackageName(targetDir) ? null : 'text'),
|
|
85
|
-
name: 'packageName',
|
|
86
|
-
message: 'Package name:',
|
|
87
|
-
initial: () => toValidPackageName(targetDir),
|
|
88
|
-
validate: (dir) =>
|
|
89
|
-
isValidPackageName(dir) || 'Invalid package.json name'
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
type: template && TEMPLATES.includes(template) ? null : 'select',
|
|
93
|
-
name: 'framework',
|
|
94
|
-
message:
|
|
95
|
-
typeof template === 'string' && !TEMPLATES.includes(template)
|
|
96
|
-
? `"${template}" isn't a valid template. Please choose from below: `
|
|
97
|
-
: 'Select a framework:',
|
|
98
|
-
initial: 0,
|
|
99
|
-
choices: FRAMEWORKS.map((framework) => {
|
|
100
|
-
const frameworkColor = framework.color;
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
title: frameworkColor(framework.name),
|
|
104
|
-
value: framework
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
type: (framework) =>
|
|
110
|
-
framework && framework.variants ? 'select' : null,
|
|
111
|
-
name: 'variant',
|
|
112
|
-
message: 'Select a variant:',
|
|
113
|
-
// @ts-ignore
|
|
114
|
-
choices: (framework) =>
|
|
115
|
-
framework.variants.map((variant) => {
|
|
116
|
-
const variantColor = variant.color
|
|
117
|
-
return {
|
|
118
|
-
title: variantColor(variant.name),
|
|
119
|
-
value: variant.name
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
],
|
|
124
|
-
{
|
|
125
|
-
onCancel: () => {
|
|
126
|
-
throw new Error(red('✖') + ' Operation cancelled')
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
)
|
|
130
|
-
} catch (cancelled) {
|
|
131
|
-
console.log(cancelled.message);
|
|
132
|
-
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// user choice associated with prompts
|
|
137
|
-
const { framework, overwrite, packageName, variant } = result
|
|
138
|
-
|
|
139
|
-
const root = path.join(cwd, targetDir)
|
|
140
|
-
|
|
141
|
-
if (overwrite) {
|
|
142
|
-
emptyDir(root)
|
|
143
|
-
} else if (!fs.existsSync(root)) {
|
|
144
|
-
fs.mkdirSync(root)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// determine template
|
|
148
|
-
template = variant || framework || template
|
|
149
|
-
|
|
150
|
-
console.log(`\nScaffolding project in ${root}...`)
|
|
151
|
-
|
|
152
|
-
const templateDir = path.join(__dirname, `template-${template}`)
|
|
153
|
-
|
|
154
|
-
const write = (file, content) => {
|
|
155
|
-
const targetPath = renameFiles[file]
|
|
156
|
-
? path.join(root, renameFiles[file])
|
|
157
|
-
: path.join(root, file)
|
|
158
|
-
if (content) {
|
|
159
|
-
fs.writeFileSync(targetPath, content)
|
|
160
|
-
} else {
|
|
161
|
-
copy(path.join(templateDir, file), targetPath)
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const files = fs.readdirSync(templateDir)
|
|
166
|
-
for (const file of files.filter((f) => f !== 'package.json')) {
|
|
167
|
-
write(file);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// connect.json
|
|
171
|
-
const connect = require(path.join(templateDir, `connect-template.json`));
|
|
172
|
-
delete(connect.db);
|
|
173
|
-
write('connect.json', JSON.stringify(connect, null, 2));
|
|
174
|
-
|
|
175
|
-
// package.json
|
|
176
|
-
const pkg = require(path.join(templateDir, `package.json`))
|
|
177
|
-
|
|
178
|
-
pkg.name = packageName || targetDir
|
|
179
|
-
|
|
180
|
-
write('package.json', JSON.stringify(pkg, null, 2))
|
|
181
|
-
|
|
182
|
-
const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
|
|
183
|
-
const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
|
|
184
|
-
|
|
185
|
-
console.log(`\nDone. Now run:\n`)
|
|
186
|
-
if (root !== cwd) {
|
|
187
|
-
console.log(` cd ${path.relative(cwd, root)}`)
|
|
188
|
-
}
|
|
189
|
-
switch (pkgManager) {
|
|
190
|
-
case 'yarn':
|
|
191
|
-
console.log(' yarn')
|
|
192
|
-
console.log(' yarn dev')
|
|
193
|
-
break
|
|
194
|
-
default:
|
|
195
|
-
console.log(` ${pkgManager} install`)
|
|
196
|
-
console.log(` ${pkgManager} run dev`)
|
|
197
|
-
break
|
|
198
|
-
}
|
|
199
|
-
console.log();
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function copy(src, dest) {
|
|
203
|
-
const stat = fs.statSync(src)
|
|
204
|
-
if (stat.isDirectory()) {
|
|
205
|
-
copyDir(src, dest)
|
|
206
|
-
} else {
|
|
207
|
-
fs.copyFileSync(src, dest)
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function isValidPackageName(projectName) {
|
|
212
|
-
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
213
|
-
projectName
|
|
214
|
-
)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function toValidPackageName(projectName) {
|
|
218
|
-
return projectName
|
|
219
|
-
.trim()
|
|
220
|
-
.toLowerCase()
|
|
221
|
-
.replace(/\s+/g, '-')
|
|
222
|
-
.replace(/^[._]/, '')
|
|
223
|
-
.replace(/[^a-z0-9-~]+/g, '-')
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function copyDir(srcDir, destDir) {
|
|
227
|
-
fs.mkdirSync(destDir, { recursive: true })
|
|
228
|
-
for (const file of fs.readdirSync(srcDir)) {
|
|
229
|
-
const srcFile = path.resolve(srcDir, file)
|
|
230
|
-
const destFile = path.resolve(destDir, file)
|
|
231
|
-
copy(srcFile, destFile)
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function isEmpty(path) {
|
|
236
|
-
return fs.readdirSync(path).length === 0
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function emptyDir(dir) {
|
|
240
|
-
if (!fs.existsSync(dir)) {
|
|
241
|
-
return
|
|
242
|
-
}
|
|
243
|
-
for (const file of fs.readdirSync(dir)) {
|
|
244
|
-
const abs = path.resolve(dir, file)
|
|
245
|
-
// baseline is Node 12 so can't use rmSync :(
|
|
246
|
-
if (fs.lstatSync(abs).isDirectory()) {
|
|
247
|
-
emptyDir(abs)
|
|
248
|
-
fs.rmdirSync(abs)
|
|
249
|
-
} else {
|
|
250
|
-
fs.unlinkSync(abs)
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* @param {string | undefined} userAgent process.env.npm_config_user_agent
|
|
257
|
-
* @returns object | undefined
|
|
258
|
-
*/
|
|
259
|
-
function pkgFromUserAgent(userAgent) {
|
|
260
|
-
if (!userAgent) return undefined
|
|
261
|
-
const pkgSpec = userAgent.split(' ')[0]
|
|
262
|
-
const pkgSpecArr = pkgSpec.split('/')
|
|
263
|
-
return {
|
|
264
|
-
name: pkgSpecArr[0],
|
|
265
|
-
version: pkgSpecArr[1]
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
init().catch((e) => {
|
|
270
|
-
console.error(e)
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const margv = require('margv')
|
|
6
|
+
const argv = margv();
|
|
7
|
+
const prompts = require('prompts');
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
yellow,
|
|
11
|
+
blue,
|
|
12
|
+
red
|
|
13
|
+
} = require('kolorist')
|
|
14
|
+
const cwd = process.cwd()
|
|
15
|
+
const FRAMEWORKS = [
|
|
16
|
+
{
|
|
17
|
+
name: 'vite-node',
|
|
18
|
+
color: yellow,
|
|
19
|
+
variants: [
|
|
20
|
+
{
|
|
21
|
+
name: 'vite-node-ts',
|
|
22
|
+
display: 'TypeScript',
|
|
23
|
+
color: blue
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'vite-vue3',
|
|
29
|
+
color: yellow,
|
|
30
|
+
variants: [
|
|
31
|
+
{
|
|
32
|
+
name: 'vite-vue3-ts',
|
|
33
|
+
display: 'TypeScript',
|
|
34
|
+
color: blue
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
const TEMPLATES = FRAMEWORKS.map(
|
|
40
|
+
(f) => (f.variants && f.variants.map((v) => v.name)) || [f.name]
|
|
41
|
+
).reduce((a, b) => a.concat(b), []);
|
|
42
|
+
|
|
43
|
+
const renameFiles = {
|
|
44
|
+
_gitignore: '.gitignore'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function init() {
|
|
48
|
+
let targetDir = argv["$"][2];
|
|
49
|
+
let template = argv.template || argv.t
|
|
50
|
+
const defaultProjectName = targetDir || 'vite-node';
|
|
51
|
+
let result = {}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
result = await prompts(
|
|
55
|
+
[
|
|
56
|
+
{
|
|
57
|
+
type: targetDir ? null : 'text',
|
|
58
|
+
name: 'projectName',
|
|
59
|
+
message: 'Project name:',
|
|
60
|
+
initial: defaultProjectName,
|
|
61
|
+
onState: (state) =>
|
|
62
|
+
(targetDir = state.value.trim() || defaultProjectName)
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: () =>
|
|
66
|
+
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm',
|
|
67
|
+
name: 'overwrite',
|
|
68
|
+
message: () =>
|
|
69
|
+
(targetDir === '.'
|
|
70
|
+
? 'Current directory'
|
|
71
|
+
: `Target directory "${targetDir}"`) +
|
|
72
|
+
` is not empty. Remove existing files and continue?`
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
type: (_, { overwrite } = {}) => {
|
|
76
|
+
if (overwrite === false) {
|
|
77
|
+
throw new Error(red('✖') + ' Operation cancelled')
|
|
78
|
+
}
|
|
79
|
+
return null
|
|
80
|
+
},
|
|
81
|
+
name: 'overwriteChecker'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: () => (isValidPackageName(targetDir) ? null : 'text'),
|
|
85
|
+
name: 'packageName',
|
|
86
|
+
message: 'Package name:',
|
|
87
|
+
initial: () => toValidPackageName(targetDir),
|
|
88
|
+
validate: (dir) =>
|
|
89
|
+
isValidPackageName(dir) || 'Invalid package.json name'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: template && TEMPLATES.includes(template) ? null : 'select',
|
|
93
|
+
name: 'framework',
|
|
94
|
+
message:
|
|
95
|
+
typeof template === 'string' && !TEMPLATES.includes(template)
|
|
96
|
+
? `"${template}" isn't a valid template. Please choose from below: `
|
|
97
|
+
: 'Select a framework:',
|
|
98
|
+
initial: 0,
|
|
99
|
+
choices: FRAMEWORKS.map((framework) => {
|
|
100
|
+
const frameworkColor = framework.color;
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
title: frameworkColor(framework.name),
|
|
104
|
+
value: framework
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: (framework) =>
|
|
110
|
+
framework && framework.variants ? 'select' : null,
|
|
111
|
+
name: 'variant',
|
|
112
|
+
message: 'Select a variant:',
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
choices: (framework) =>
|
|
115
|
+
framework.variants.map((variant) => {
|
|
116
|
+
const variantColor = variant.color
|
|
117
|
+
return {
|
|
118
|
+
title: variantColor(variant.name),
|
|
119
|
+
value: variant.name
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
{
|
|
125
|
+
onCancel: () => {
|
|
126
|
+
throw new Error(red('✖') + ' Operation cancelled')
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
} catch (cancelled) {
|
|
131
|
+
console.log(cancelled.message);
|
|
132
|
+
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// user choice associated with prompts
|
|
137
|
+
const { framework, overwrite, packageName, variant } = result
|
|
138
|
+
|
|
139
|
+
const root = path.join(cwd, targetDir)
|
|
140
|
+
|
|
141
|
+
if (overwrite) {
|
|
142
|
+
emptyDir(root)
|
|
143
|
+
} else if (!fs.existsSync(root)) {
|
|
144
|
+
fs.mkdirSync(root)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// determine template
|
|
148
|
+
template = variant || framework || template
|
|
149
|
+
|
|
150
|
+
console.log(`\nScaffolding project in ${root}...`)
|
|
151
|
+
|
|
152
|
+
const templateDir = path.join(__dirname, `template-${template}`)
|
|
153
|
+
|
|
154
|
+
const write = (file, content) => {
|
|
155
|
+
const targetPath = renameFiles[file]
|
|
156
|
+
? path.join(root, renameFiles[file])
|
|
157
|
+
: path.join(root, file)
|
|
158
|
+
if (content) {
|
|
159
|
+
fs.writeFileSync(targetPath, content)
|
|
160
|
+
} else {
|
|
161
|
+
copy(path.join(templateDir, file), targetPath)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const files = fs.readdirSync(templateDir)
|
|
166
|
+
for (const file of files.filter((f) => f !== 'package.json')) {
|
|
167
|
+
write(file);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// connect.json
|
|
171
|
+
const connect = require(path.join(templateDir, `connect-template.json`));
|
|
172
|
+
delete(connect.db);
|
|
173
|
+
write('connect.json', JSON.stringify(connect, null, 2));
|
|
174
|
+
|
|
175
|
+
// package.json
|
|
176
|
+
const pkg = require(path.join(templateDir, `package.json`))
|
|
177
|
+
|
|
178
|
+
pkg.name = packageName || targetDir
|
|
179
|
+
|
|
180
|
+
write('package.json', JSON.stringify(pkg, null, 2))
|
|
181
|
+
|
|
182
|
+
const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);
|
|
183
|
+
const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
|
|
184
|
+
|
|
185
|
+
console.log(`\nDone. Now run:\n`)
|
|
186
|
+
if (root !== cwd) {
|
|
187
|
+
console.log(` cd ${path.relative(cwd, root)}`)
|
|
188
|
+
}
|
|
189
|
+
switch (pkgManager) {
|
|
190
|
+
case 'yarn':
|
|
191
|
+
console.log(' yarn')
|
|
192
|
+
console.log(' yarn dev')
|
|
193
|
+
break
|
|
194
|
+
default:
|
|
195
|
+
console.log(` ${pkgManager} install`)
|
|
196
|
+
console.log(` ${pkgManager} run dev`)
|
|
197
|
+
break
|
|
198
|
+
}
|
|
199
|
+
console.log();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function copy(src, dest) {
|
|
203
|
+
const stat = fs.statSync(src)
|
|
204
|
+
if (stat.isDirectory()) {
|
|
205
|
+
copyDir(src, dest)
|
|
206
|
+
} else {
|
|
207
|
+
fs.copyFileSync(src, dest)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function isValidPackageName(projectName) {
|
|
212
|
+
return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(
|
|
213
|
+
projectName
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function toValidPackageName(projectName) {
|
|
218
|
+
return projectName
|
|
219
|
+
.trim()
|
|
220
|
+
.toLowerCase()
|
|
221
|
+
.replace(/\s+/g, '-')
|
|
222
|
+
.replace(/^[._]/, '')
|
|
223
|
+
.replace(/[^a-z0-9-~]+/g, '-')
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function copyDir(srcDir, destDir) {
|
|
227
|
+
fs.mkdirSync(destDir, { recursive: true })
|
|
228
|
+
for (const file of fs.readdirSync(srcDir)) {
|
|
229
|
+
const srcFile = path.resolve(srcDir, file)
|
|
230
|
+
const destFile = path.resolve(destDir, file)
|
|
231
|
+
copy(srcFile, destFile)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function isEmpty(path) {
|
|
236
|
+
return fs.readdirSync(path).length === 0
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function emptyDir(dir) {
|
|
240
|
+
if (!fs.existsSync(dir)) {
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
for (const file of fs.readdirSync(dir)) {
|
|
244
|
+
const abs = path.resolve(dir, file)
|
|
245
|
+
// baseline is Node 12 so can't use rmSync :(
|
|
246
|
+
if (fs.lstatSync(abs).isDirectory()) {
|
|
247
|
+
emptyDir(abs)
|
|
248
|
+
fs.rmdirSync(abs)
|
|
249
|
+
} else {
|
|
250
|
+
fs.unlinkSync(abs)
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @param {string | undefined} userAgent process.env.npm_config_user_agent
|
|
257
|
+
* @returns object | undefined
|
|
258
|
+
*/
|
|
259
|
+
function pkgFromUserAgent(userAgent) {
|
|
260
|
+
if (!userAgent) return undefined
|
|
261
|
+
const pkgSpec = userAgent.split(' ')[0]
|
|
262
|
+
const pkgSpecArr = pkgSpec.split('/')
|
|
263
|
+
return {
|
|
264
|
+
name: pkgSpecArr[0],
|
|
265
|
+
version: pkgSpecArr[1]
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
init().catch((e) => {
|
|
270
|
+
console.error(e)
|
|
271
271
|
})
|
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "create-jwn-js",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"license": "PRIVATE",
|
|
5
|
-
"author": "Webigorkiev",
|
|
6
|
-
"bin": {
|
|
7
|
-
"create-jwn-js": "index.js",
|
|
8
|
-
"cjj": "index.js"
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"index.js",
|
|
12
|
-
"template-*"
|
|
13
|
-
],
|
|
14
|
-
"main": "index.js",
|
|
15
|
-
"scripts": {
|
|
16
|
-
},
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=14.0.0"
|
|
19
|
-
},
|
|
20
|
-
"homepage": "https://github.com/webigorkiev",
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"kolorist": "^1.5.0",
|
|
23
|
-
"margv": "^1.1.2",
|
|
24
|
-
"prompts": "^2.4.2"
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "create-jwn-js",
|
|
3
|
+
"version": "1.0.20",
|
|
4
|
+
"license": "PRIVATE",
|
|
5
|
+
"author": "Webigorkiev",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create-jwn-js": "index.js",
|
|
8
|
+
"cjj": "index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"index.js",
|
|
12
|
+
"template-*"
|
|
13
|
+
],
|
|
14
|
+
"main": "index.js",
|
|
15
|
+
"scripts": {
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=14.0.0"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/webigorkiev",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"kolorist": "^1.5.0",
|
|
23
|
+
"margv": "^1.1.2",
|
|
24
|
+
"prompts": "^2.4.2"
|
|
25
|
+
}
|
|
26
26
|
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"server": {
|
|
3
|
-
"development": {
|
|
4
|
-
"mode": "development",
|
|
5
|
-
"https": false,
|
|
6
|
-
"port": 80,
|
|
7
|
-
"host": "localhost"
|
|
8
|
-
},
|
|
9
|
-
"production": {
|
|
10
|
-
"mode": "production",
|
|
11
|
-
"port": 3000,
|
|
12
|
-
"host": "127.0.0.1",
|
|
13
|
-
"url": "http://127.0.0.1"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"db": {
|
|
17
|
-
"home": {
|
|
18
|
-
"engine": "mysql",
|
|
19
|
-
"host": "localhost",
|
|
20
|
-
"user": "",
|
|
21
|
-
"password": "",
|
|
22
|
-
"database": "",
|
|
23
|
-
"connectTimeout": 10000,
|
|
24
|
-
"acquireTimeout": 10000,
|
|
25
|
-
"connectionLimit": 2,
|
|
26
|
-
"charset": "utf8",
|
|
27
|
-
"compress": true,
|
|
28
|
-
"port": 3306,
|
|
29
|
-
"multipleStatements": true,
|
|
30
|
-
"namedPlaceholders": true,
|
|
31
|
-
"dateStrings": true
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"server": {
|
|
3
|
+
"development": {
|
|
4
|
+
"mode": "development",
|
|
5
|
+
"https": false,
|
|
6
|
+
"port": 80,
|
|
7
|
+
"host": "localhost"
|
|
8
|
+
},
|
|
9
|
+
"production": {
|
|
10
|
+
"mode": "production",
|
|
11
|
+
"port": 3000,
|
|
12
|
+
"host": "127.0.0.1",
|
|
13
|
+
"url": "http://127.0.0.1"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"db": {
|
|
17
|
+
"home": {
|
|
18
|
+
"engine": "mysql",
|
|
19
|
+
"host": "localhost",
|
|
20
|
+
"user": "",
|
|
21
|
+
"password": "",
|
|
22
|
+
"database": "",
|
|
23
|
+
"connectTimeout": 10000,
|
|
24
|
+
"acquireTimeout": 10000,
|
|
25
|
+
"connectionLimit": 2,
|
|
26
|
+
"charset": "utf8",
|
|
27
|
+
"compress": true,
|
|
28
|
+
"port": 3306,
|
|
29
|
+
"multipleStatements": true,
|
|
30
|
+
"namedPlaceholders": true,
|
|
31
|
+
"dateStrings": true
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|