@gx-design-vue/create-gx-cli 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -10,6 +10,15 @@ npm init @gx-design-vue/create-gx-cli
10
10
  npx @gx-design-vue/create-gx-cli
11
11
  # or
12
12
  npm install -g @gx-design-vue/create-gx-cli
13
+
14
+ # create project
13
15
  create-gx-cli
16
+ # cli version
17
+ create-gx-cli -v
18
+ # short create(first: project name、--template: template project)
19
+ create-gx-cli app --template gx-design-pro
20
+ create-gx-cli app --template gx-design-thin
21
+ create-gx-cli app --template mobile-vant-cli
22
+ create-gx-cli app --template mobile-vant-html
14
23
  ```
15
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gx-design-vue/create-gx-cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "license": "MIT",
5
5
  "description": "a cli to bootstrap gx project",
6
6
  "main": "src/index.js",
@@ -16,6 +16,7 @@
16
16
  "dependencies": {
17
17
  "chalk": "^2.4.2",
18
18
  "esm": "^3.2.18",
19
+ "execa": "^8.0.1",
19
20
  "inquirer": "^6.2.2",
20
21
  "kolorist": "^1.6.0",
21
22
  "listr": "^0.14.3",
package/src/cli.js CHANGED
@@ -1,9 +1,14 @@
1
+ import chalk from 'chalk'
1
2
  import minimist from 'minimist'
2
3
  import prompts from 'prompts'
3
4
  import { yellow, reset, blue, red, green } from 'kolorist'
4
5
  import { createProject } from './main'
5
6
 
6
- const defaultTargetDir = 'gx-cli-project'
7
+ import pag from '../package.json'
8
+
9
+ const { version } = pag
10
+
11
+ const defaultTargetDir = 'vue3-project'
7
12
 
8
13
  const FRAMEWORKS = [
9
14
  {
@@ -37,20 +42,24 @@ function parseArgumentsIntoOptions() {
37
42
  const argTargetDir = formatTargetDir(argv._[0])
38
43
  const argTemplate = argv.template || argv.t
39
44
  return {
45
+ v: argv.v,
40
46
  template: argTemplate,
41
47
  projectName: argTargetDir
42
48
  }
43
49
  }
44
50
 
45
51
  async function promptForMissingOptions(options) {
46
- const answers = await prompts([
47
- {
52
+ const projectNamePrompts = []
53
+ if (!options.projectName) {
54
+ projectNamePrompts.push({
48
55
  type: options.projectName ? null : 'text',
49
56
  name: 'projectName',
50
57
  message: reset('Project name:'),
51
58
  initial: defaultTargetDir
52
- },
53
- {
59
+ })
60
+ }
61
+ if (typeof options.template !== 'string' || !TEMPLATES.includes(options.template)) {
62
+ projectNamePrompts.push({
54
63
  type: 'select',
55
64
  name: 'template',
56
65
  message:
@@ -66,20 +75,36 @@ async function promptForMissingOptions(options) {
66
75
  value: framework
67
76
  }
68
77
  })
69
- }
70
- ])
78
+ })
79
+ }
80
+ let answers = {
81
+ template: {
82
+ name: ''
83
+ },
84
+ projectName: ''
85
+ }
86
+
87
+ if (projectNamePrompts.length) {
88
+ answers = await prompts(projectNamePrompts)
89
+ }
71
90
 
72
91
  return {
73
92
  ...options,
74
- template: options.template || answers.template ? answers.template.name : '',
93
+ template: options.template || (answers.template ? answers.template.name : ''),
75
94
  projectName: options.projectName || answers.projectName || ''
76
95
  }
77
96
  }
78
97
 
79
98
  export async function cli() {
80
99
  let options = parseArgumentsIntoOptions()
100
+ if (options.v) {
101
+ console.log(chalk.whiteBright(version))
102
+ process.exit(1)
103
+ }
81
104
  options = await promptForMissingOptions(options)
82
105
  if (options.template && options.projectName) {
83
106
  await createProject(options)
107
+ } else {
108
+ process.exit(1)
84
109
  }
85
110
  }
package/src/main.js CHANGED
@@ -64,8 +64,8 @@ function doneLog(cwd, root) {
64
64
  if (root !== cwd) {
65
65
  console.log(chalk.blueBright(`cd ${path.relative(cwd, root)}`))
66
66
  }
67
- console.log(chalk.blueBright(`pnpm(yarn、npm) install`))
68
- console.log(chalk.blueBright(`pnpm(yarn、npm) run dev`))
67
+ console.log(chalk.blueBright(`pnpmyarn、npm install`))
68
+ console.log(chalk.blueBright(`pnpmyarn、npm run dev`))
69
69
  console.log()
70
70
  }
71
71