unisolution-create-app 1.0.1 → 1.0.2

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/bin/index.js ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require('commander')
4
+ const figlet = require('figlet')
5
+ const inquirer = require('inquirer')
6
+
7
+ const fs = require('fs-extra')
8
+ const path = require('path')
9
+ const gitClone = require('git-clone');
10
+ const ora = require('ora');
11
+ // 首航提示
12
+ program.name('runcli').usage('<command> [options]')
13
+
14
+ // 版本
15
+ program.version(`${require('../package.json')['version']}`)
16
+
17
+ // 命令
18
+ program
19
+ .command('create <app-name>')
20
+ .description('create a new project')
21
+ .action(projectName => {
22
+ createProject(projectName)
23
+ })
24
+
25
+ // program.on('--help', function () {
26
+ // console.log('')
27
+ // });
28
+
29
+ program.parse(process.argv);
30
+
31
+ function log (obj) {
32
+ console.log(JSON.stringify(obj))
33
+ }
34
+
35
+ const projectList = {
36
+ 'react': '',
37
+ 'react-ts': 'https://gitee.com/unisolution_cn_lhj/reactdemo.git'
38
+ }
39
+
40
+ async function createProject (projectName) {
41
+ // 创建一个名字为projectName的文件夹,将模板代码放在文件夹下面
42
+ // 判断有没有 name 的文件夹
43
+ const currentFolder = process.cwd();
44
+ const fullPath = path.join(currentFolder, projectName);
45
+ const isExist = fs.existsSync(fullPath)
46
+
47
+ if (isExist) {
48
+ const answers = await inquirer.prompt([
49
+ {
50
+ type: 'confirm',
51
+ name: 'overWrite',
52
+ message: `${projectName}已经存在,是否要覆盖?`
53
+ }
54
+ ])
55
+ const { overWrite } = answers;
56
+ if (overWrite) {
57
+ fs.remove(fullPath)
58
+ generateNewProject(fullPath)
59
+ } else return;
60
+ } else {
61
+ generateNewProject(fullPath)
62
+ }
63
+ }
64
+
65
+ async function generateNewProject (projectPath) {
66
+ const answers = await inquirer.prompt([
67
+ {
68
+ type: 'list',
69
+ name: 'type',
70
+ message: `请选择模板`,
71
+ choices: [
72
+ {
73
+ name: 'react',
74
+ value: 'react'
75
+ },
76
+ {
77
+ name: 'react-ts',
78
+ value: 'react-ts'
79
+ }
80
+ ]
81
+ }
82
+ ])
83
+ const { type } = answers;
84
+ if (type === 'react-ts') {
85
+ const address = projectList[type];
86
+ // 拿到仓库的地址?
87
+ const loading = ora('正在生成模板...').start();
88
+ gitClone(address, projectPath, {
89
+ checkout: 'master'
90
+ }, function (err) {
91
+ if (err) {
92
+ loading.fail('生成失败,请检查网络问题重试')
93
+ } else {
94
+ loading.succeed('创建完毕')
95
+ }
96
+ })
97
+ }
98
+ if (type === 'react') {
99
+ console.log('不选ts你是怎么想的');
100
+ console.log('重新创建去吧');
101
+ }
102
+ }
package/dist/bin/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "unisolution-create-app",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
- "bin": "/bin/runcli.js",
6
+ "bin": "/bin/index.js",
7
7
  "type": "module",
8
8
  "scripts": {
9
9
  "build": "rollup -c"