create-valaxy 0.14.57 → 0.14.59
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/index.ts +204 -0
- package/template/package.json +2 -2
package/package.json
CHANGED
package/src/index.ts
CHANGED
@@ -0,0 +1,204 @@
|
|
1
|
+
// #!/usr/bin/env node
|
2
|
+
// /* eslint-disable @typescript-eslint/no-var-requires */
|
3
|
+
// /* eslint-disable no-console */
|
4
|
+
|
5
|
+
// // @todo migrate to ts
|
6
|
+
|
7
|
+
// import process from 'node:process'
|
8
|
+
// import fs from 'node:fs'
|
9
|
+
// import path from 'node:path'
|
10
|
+
// import prompts from 'prompts'
|
11
|
+
// import execa from 'execa'
|
12
|
+
// import { blue, bold, cyan, dim, gray, green, red, yellow } from 'kolorist'
|
13
|
+
// import minimist from 'minimist'
|
14
|
+
// import { version } from '../package.json'
|
15
|
+
|
16
|
+
// const argv = minimist(process.argv.slice(2))
|
17
|
+
|
18
|
+
// const cwd = process.cwd()
|
19
|
+
|
20
|
+
// const renameFiles = {
|
21
|
+
// _gitignore: '.gitignore',
|
22
|
+
// _npmrc: '.npmrc',
|
23
|
+
// }
|
24
|
+
|
25
|
+
// async function init() {
|
26
|
+
// console.log()
|
27
|
+
// console.log(` ${bold('🌌 Valaxy')} ${blue(`v${version}`)}`)
|
28
|
+
// console.log()
|
29
|
+
|
30
|
+
// let targetDir = argv._[0]
|
31
|
+
// if (!targetDir) {
|
32
|
+
// /**
|
33
|
+
// * @type {{ projectName: string }}
|
34
|
+
// */
|
35
|
+
// const { projectName } = await prompts({
|
36
|
+
// type: 'text',
|
37
|
+
// name: 'projectName',
|
38
|
+
// message: 'Project name:',
|
39
|
+
// initial: 'valaxy-blog',
|
40
|
+
// })
|
41
|
+
// targetDir = projectName.trim()
|
42
|
+
|
43
|
+
// const packageName = await getValidPackageName(targetDir)
|
44
|
+
// const root = path.join(cwd, targetDir)
|
45
|
+
|
46
|
+
// if (!fs.existsSync(root)) {
|
47
|
+
// fs.mkdirSync(root, { recursive: true })
|
48
|
+
// }
|
49
|
+
// else {
|
50
|
+
// const existing = fs.readdirSync(root)
|
51
|
+
// if (existing.length) {
|
52
|
+
// console.log(yellow(` Target directory "${targetDir}" is not empty.`))
|
53
|
+
// /**
|
54
|
+
// * @type {{ yes: boolean }}
|
55
|
+
// */
|
56
|
+
// const { yes } = await prompts({
|
57
|
+
// type: 'confirm',
|
58
|
+
// name: 'yes',
|
59
|
+
// initial: 'Y',
|
60
|
+
// message: 'Remove existing files and continue?',
|
61
|
+
// })
|
62
|
+
// if (yes)
|
63
|
+
// emptyDir(root)
|
64
|
+
|
65
|
+
// else
|
66
|
+
// return
|
67
|
+
// }
|
68
|
+
// }
|
69
|
+
|
70
|
+
// console.log(` ${dim('📁')} ${dim(root)}`)
|
71
|
+
// console.log()
|
72
|
+
// console.log(dim(' Scaffolding project in ') + targetDir + dim(' ...'))
|
73
|
+
|
74
|
+
// const templateDir = path.join(__dirname, 'template')
|
75
|
+
// const write = (file, content) => {
|
76
|
+
// const targetPath = renameFiles[file]
|
77
|
+
// ? path.join(root, renameFiles[file])
|
78
|
+
// : path.join(root, file)
|
79
|
+
// if (content)
|
80
|
+
// fs.writeFileSync(targetPath, content)
|
81
|
+
|
82
|
+
// else
|
83
|
+
// copy(path.join(templateDir, file), targetPath)
|
84
|
+
// }
|
85
|
+
|
86
|
+
// const files = fs.readdirSync(templateDir)
|
87
|
+
// for (const file of files.filter(f => f !== 'package.json'))
|
88
|
+
// write(file)
|
89
|
+
|
90
|
+
// // write pkg name & version
|
91
|
+
// // eslint-disable-next-line @typescript-eslint/no-require-imports
|
92
|
+
// const pkg = require(path.join(templateDir, 'package.json'))
|
93
|
+
// if (packageName)
|
94
|
+
// pkg.name = packageName
|
95
|
+
// pkg.version = version
|
96
|
+
|
97
|
+
// write('package.json', JSON.stringify(pkg, null, 2))
|
98
|
+
|
99
|
+
// const pkgManager = (/pnpm/.test(process.env.npm_execpath) || /pnpm/.test(process.env.npm_config_user_agent))
|
100
|
+
// ? 'pnpm'
|
101
|
+
// : /yarn/.test(process.env.npm_execpath) ? 'yarn' : 'npm'
|
102
|
+
|
103
|
+
// const related = path.relative(cwd, root)
|
104
|
+
// console.log(green(' Done.\n'))
|
105
|
+
|
106
|
+
// /**
|
107
|
+
// * @type {{ yes: boolean }}
|
108
|
+
// */
|
109
|
+
// const { yes } = await prompts({
|
110
|
+
// type: 'confirm',
|
111
|
+
// name: 'yes',
|
112
|
+
// initial: 'Y',
|
113
|
+
// message: 'Install and start it now?',
|
114
|
+
// })
|
115
|
+
|
116
|
+
// if (yes) {
|
117
|
+
// const { agent } = await prompts({
|
118
|
+
// name: 'agent',
|
119
|
+
// type: 'select',
|
120
|
+
// message: 'Choose the agent',
|
121
|
+
// choices: ['npm', 'yarn', 'pnpm'].map(i => ({ value: i, title: i })),
|
122
|
+
// })
|
123
|
+
|
124
|
+
// if (!agent)
|
125
|
+
// return
|
126
|
+
|
127
|
+
// await execa(agent, ['install'], { stdio: 'inherit', cwd: root })
|
128
|
+
// await execa(agent, ['run', 'dev'], { stdio: 'inherit', cwd: root })
|
129
|
+
// }
|
130
|
+
// else {
|
131
|
+
// console.log(dim('\n start it later by:\n'))
|
132
|
+
// if (root !== cwd)
|
133
|
+
// console.log(blue(` cd ${bold(related)}`))
|
134
|
+
|
135
|
+
// console.log(blue(` ${pkgManager === 'yarn' ? 'yarn' : `${pkgManager} install`}`))
|
136
|
+
// console.log(blue(` ${pkgManager === 'yarn' ? 'yarn dev' : `${pkgManager} run dev`}`))
|
137
|
+
// console.log()
|
138
|
+
// console.log(` ${cyan('✨')}`)
|
139
|
+
// console.log()
|
140
|
+
// }
|
141
|
+
// }
|
142
|
+
// }
|
143
|
+
|
144
|
+
// function copy(src, dest) {
|
145
|
+
// const stat = fs.statSync(src)
|
146
|
+
// if (stat.isDirectory())
|
147
|
+
// copyDir(src, dest)
|
148
|
+
|
149
|
+
// else
|
150
|
+
// fs.copyFileSync(src, dest)
|
151
|
+
// }
|
152
|
+
|
153
|
+
// function copyDir(srcDir, destDir) {
|
154
|
+
// fs.mkdirSync(destDir, { recursive: true })
|
155
|
+
// for (const file of fs.readdirSync(srcDir)) {
|
156
|
+
// const srcFile = path.resolve(srcDir, file)
|
157
|
+
// const destFile = path.resolve(destDir, file)
|
158
|
+
// copy(srcFile, destFile)
|
159
|
+
// }
|
160
|
+
// }
|
161
|
+
|
162
|
+
// async function getValidPackageName(projectName) {
|
163
|
+
// projectName = path.basename(projectName)
|
164
|
+
// const packageNameRegExp = /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/
|
165
|
+
// if (packageNameRegExp.test(projectName)) {
|
166
|
+
// return projectName
|
167
|
+
// }
|
168
|
+
// else {
|
169
|
+
// const suggestedPackageName = projectName
|
170
|
+
// .trim()
|
171
|
+
// .toLowerCase()
|
172
|
+
// .replace(/\s+/g, '-')
|
173
|
+
// .replace(/^[._]/, '')
|
174
|
+
// .replace(/[^a-z0-9-~]+/g, '-')
|
175
|
+
|
176
|
+
// /**
|
177
|
+
// * @type {{ inputPackageName: string }}
|
178
|
+
// */
|
179
|
+
// const { inputPackageName } = await prompts({
|
180
|
+
// type: 'text',
|
181
|
+
// name: 'inputPackageName',
|
182
|
+
// message: 'Package name:',
|
183
|
+
// initial: suggestedPackageName,
|
184
|
+
// // validate: input =>
|
185
|
+
// // packageNameRegExp.test(input) ? true : 'Invalid package.json name',
|
186
|
+
// })
|
187
|
+
// return inputPackageName
|
188
|
+
// }
|
189
|
+
// }
|
190
|
+
|
191
|
+
// /**
|
192
|
+
// * @param {string} dir
|
193
|
+
// * @returns
|
194
|
+
// */
|
195
|
+
// function emptyDir(dir) {
|
196
|
+
// if (!fs.existsSync(dir))
|
197
|
+
// return
|
198
|
+
// console.log(red(' Remove ') + gray(dir))
|
199
|
+
// fs.rmSync(dir, { recursive: true, force: true })
|
200
|
+
// }
|
201
|
+
|
202
|
+
// init().catch((e) => {
|
203
|
+
// console.error(e)
|
204
|
+
// })
|
package/template/package.json
CHANGED