@htyf-mp/cli 0.1.1 → 0.1.3
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/cli.js +27 -11
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -12,6 +12,7 @@ import ora from 'ora'
|
|
|
12
12
|
import childProcess from 'child_process'
|
|
13
13
|
import { v4 as uuidv4 } from 'uuid';
|
|
14
14
|
import md5 from 'md5'
|
|
15
|
+
import os from 'os'
|
|
15
16
|
|
|
16
17
|
const v4options = {
|
|
17
18
|
random: [
|
|
@@ -70,7 +71,7 @@ async function main() {
|
|
|
70
71
|
default: 'my-htyf-mp',
|
|
71
72
|
validate: d => {
|
|
72
73
|
if(!kebabRegez.test(d)) {
|
|
73
|
-
return '请以my-app-name
|
|
74
|
+
return '请以my-app-name格式输入您的应用程序英文目录名称'
|
|
74
75
|
}
|
|
75
76
|
return true
|
|
76
77
|
}
|
|
@@ -138,16 +139,29 @@ async function main() {
|
|
|
138
139
|
|
|
139
140
|
log(`\n初始化项目. \n`)
|
|
140
141
|
|
|
142
|
+
|
|
143
|
+
const root_path = path.join(process.cwd(), `${appName}`);
|
|
144
|
+
const isExists = fs.existsSync(root_path);
|
|
145
|
+
if (isExists) {
|
|
146
|
+
console.error('目录已经存在。')
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (/[\u4e00-\u9fa5]/gi.test(root_path)) {
|
|
150
|
+
console.error('禁止目录中包含中文字符')
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
141
153
|
spinner.start()
|
|
142
|
-
|
|
154
|
+
const tmpdir = path.join(os.tmpdir(), md5(`__HTYF__`), appName);
|
|
155
|
+
fse.emptyDirSync(tmpdir)
|
|
156
|
+
await execa('git', ['clone', repoType, tmpdir])
|
|
143
157
|
let appRootPath = '';
|
|
144
|
-
const taro_path = path.join(
|
|
145
|
-
const expo_path = path.join(
|
|
146
|
-
const game_path = path.join(
|
|
147
|
-
const cli_path = path.join(
|
|
148
|
-
const git_path = path.join(
|
|
149
|
-
const docs_path = path.join(
|
|
150
|
-
const README_path = path.join(
|
|
158
|
+
const taro_path = path.join(tmpdir, `${taroTempPath}`)
|
|
159
|
+
const expo_path = path.join(tmpdir, `${expoTempPath}`)
|
|
160
|
+
const game_path = path.join(tmpdir, `${gameTempPath}`)
|
|
161
|
+
const cli_path = path.join(tmpdir, `cli`)
|
|
162
|
+
const git_path = path.join(tmpdir, `.git`)
|
|
163
|
+
const docs_path = path.join(tmpdir, `docs`)
|
|
164
|
+
const README_path = path.join(tmpdir, `README.md`)
|
|
151
165
|
try {
|
|
152
166
|
if (tempType === 'taro') {
|
|
153
167
|
appRootPath = taro_path
|
|
@@ -256,9 +270,11 @@ async function main() {
|
|
|
256
270
|
|
|
257
271
|
spinner.text = ''
|
|
258
272
|
|
|
273
|
+
fse.moveSync(appRootPath, root_path)
|
|
274
|
+
|
|
259
275
|
spinner.stop()
|
|
260
|
-
log(`${green.bold('Success!')} 创建项目 ${appName} 在 ${
|
|
261
|
-
log(`切换到【 ${
|
|
276
|
+
log(`${green.bold('Success!')} 创建项目 ${appName} 在 ${root_path} \n`)
|
|
277
|
+
log(`切换到【 ${root_path} 】目录并运行开发`)
|
|
262
278
|
log('\n')
|
|
263
279
|
} catch (err) {
|
|
264
280
|
console.log(err)
|