@htyf-mp/cli 0.1.2 → 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.
Files changed (2) hide show
  1. package/cli.js +22 -12
  2. 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: [
@@ -138,22 +139,29 @@ async function main() {
138
139
 
139
140
  log(`\n初始化项目. \n`)
140
141
 
141
- spinner.start()
142
+
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
+ }
143
149
  if (/[\u4e00-\u9fa5]/gi.test(root_path)) {
144
150
  console.error('禁止目录中包含中文字符')
145
- spinner.stop()
146
151
  return;
147
152
  }
148
- await execa('git', ['clone', repoType, appName])
153
+ spinner.start()
154
+ const tmpdir = path.join(os.tmpdir(), md5(`__HTYF__`), appName);
155
+ fse.emptyDirSync(tmpdir)
156
+ await execa('git', ['clone', repoType, tmpdir])
149
157
  let appRootPath = '';
150
- const taro_path = path.join(root_path, `${taroTempPath}`)
151
- const expo_path = path.join(root_path, `${expoTempPath}`)
152
- const game_path = path.join(root_path, `${gameTempPath}`)
153
- const cli_path = path.join(root_path, `cli`)
154
- const git_path = path.join(root_path, `.git`)
155
- const docs_path = path.join(root_path, `docs`)
156
- const README_path = path.join(root_path, `README.md`)
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`)
157
165
  try {
158
166
  if (tempType === 'taro') {
159
167
  appRootPath = taro_path
@@ -262,9 +270,11 @@ async function main() {
262
270
 
263
271
  spinner.text = ''
264
272
 
273
+ fse.moveSync(appRootPath, root_path)
274
+
265
275
  spinner.stop()
266
- log(`${green.bold('Success!')} 创建项目 ${appName} 在 ${appRootPath} \n`)
267
- log(`切换到【 ${appRootPath} 】目录并运行开发`)
276
+ log(`${green.bold('Success!')} 创建项目 ${appName} 在 ${root_path} \n`)
277
+ log(`切换到【 ${root_path} 】目录并运行开发`)
268
278
  log('\n')
269
279
  } catch (err) {
270
280
  console.log(err)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htyf-mp/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "红糖云服app小程序模板-cli",
5
5
  "type": "module",
6
6
  "bin": "cli.js",