@gx-design-vue/create-gx-cli 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gx-design-vue/create-gx-cli",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "license": "MIT",
5
5
  "description": "a cli to bootstrap gx project",
6
6
  "main": "src/index.js",
@@ -23,7 +23,7 @@
23
23
  "nanospinner": "^1.1.0",
24
24
  "ncp": "^2.0.0",
25
25
  "obtain-git-repo": "^1.0.2",
26
- "prompts": "^2.4.2"
26
+ "prompts": "^2.4.1"
27
27
  },
28
28
  "files": [
29
29
  "bin/",
package/src/cli.js CHANGED
@@ -43,6 +43,7 @@ function parseArgumentsIntoOptions() {
43
43
  }
44
44
 
45
45
  async function promptForMissingOptions(options) {
46
+ console.log(typeof options.template === 'string' && !TEMPLATES.includes(options.template))
46
47
  const answers = await prompts([
47
48
  {
48
49
  type: options.projectName ? null : 'text',
@@ -51,7 +52,7 @@ async function promptForMissingOptions(options) {
51
52
  initial: defaultTargetDir
52
53
  },
53
54
  {
54
- type: options.template && TEMPLATES.includes(options.template) ? null : 'select',
55
+ type: 'select',
55
56
  name: 'template',
56
57
  message:
57
58
  typeof options.template === 'string' && !TEMPLATES.includes(options.template)
@@ -65,8 +66,7 @@ async function promptForMissingOptions(options) {
65
66
  title: frameworkColor(framework.name),
66
67
  value: framework
67
68
  }
68
- }),
69
- default: 'vue'
69
+ })
70
70
  }
71
71
  ])
72
72
 
@@ -80,6 +80,7 @@ async function promptForMissingOptions(options) {
80
80
  export async function cli() {
81
81
  let options = parseArgumentsIntoOptions()
82
82
  options = await promptForMissingOptions(options)
83
+ console.log(options)
83
84
  if (options.template && options.projectName) {
84
85
  await createProject(options)
85
86
  }
package/src/main.js CHANGED
@@ -8,9 +8,7 @@ import { promisify } from 'util'
8
8
  import { createSpinner } from 'nanospinner'
9
9
  import { download } from 'obtain-git-repo'
10
10
 
11
- const access = promisify(fs.access)
12
11
  const copy = promisify(ncp)
13
- const writeFileSync = promisify(fs.writeFileSync)
14
12
 
15
13
  const gitRepositoryList = [
16
14
  {
@@ -31,7 +29,7 @@ async function copyTemplateFiles(templateDir, root) {
31
29
 
32
30
  function writeFile(path, content) {
33
31
  if (Object.keys(content).length > 0) {
34
- writeFileSync(path, content)
32
+ fs.writeFileSync(path, content)
35
33
  }
36
34
  }
37
35
 
@@ -43,10 +41,11 @@ function editPackageJson(root, projectName) {
43
41
  fs.readFileSync(path.join(root, `package.json`), 'utf-8')
44
42
  )
45
43
 
44
+ console.log(projectName)
45
+
46
46
  pkg.name = projectName
47
+ writeFile(path.join(root, 'package.json'), JSON.stringify(pkg, null, 2))
47
48
  }
48
-
49
- writeFile(path.join(root, 'package.json'), JSON.stringify(pkg, null, 2))
50
49
  }
51
50
 
52
51
  function doneLog(cwd, root) {
@@ -74,9 +73,9 @@ export async function createProject(options) {
74
73
  `template-${options.template}`
75
74
  )
76
75
 
77
- try {
78
- await access(templateDir, fs.constants.R_OK)
79
- } catch (err) {
76
+ const dirIsTemplate = fs.existsSync(templateDir)
77
+
78
+ if (!dirIsTemplate) {
80
79
  if (!downloadGit) {
81
80
  console.log(chalk.redBright('模版目录不存在'))
82
81
  process.exit(1)
@@ -94,7 +93,7 @@ export async function createProject(options) {
94
93
  if (downloadGit) {
95
94
  const spinner = createSpinner(`开始下载...${downloadGit.git}`).start()
96
95
  // 下载git代码
97
- download(`direct:${downloadGit.git}`, root, { clone: true }, async function(err) {
96
+ download(`direct:${downloadGit.git}`, root, { clone: true }, async function (err) {
98
97
  if (err) {
99
98
  spinner.error({ text: '下载失败' })
100
99
  } else {
@@ -102,26 +101,20 @@ export async function createProject(options) {
102
101
  spinner.success({
103
102
  text: '项目创建成功,请依次执行以下命令'
104
103
  })
105
- fs.
106
- doneLog(cwd, root)
104
+ fs.doneLog(cwd, root)
107
105
  }
108
106
  })
109
107
  } else {
110
- let pkg = {}
111
-
112
- if (fs.existsSync(path.join(templateDir, `package.json`))) {
113
- pkg = JSON.parse(
114
- fs.readFileSync(path.join(templateDir, `package.json`), 'utf-8')
115
- )
116
-
117
- pkg.name = options.projectName || getProjectName()
118
- }
119
108
  const tasks = new Listr(
120
109
  [
121
110
  {
122
- title: '项目创建成功,请依次执行以下命令',
111
+ title: '项目创建',
123
112
  task: () => copyTemplateFiles(templateDir, root)
124
- }
113
+ },
114
+ options.template !== 'mobile-vant-html' ? {
115
+ title: '项目文件修改',
116
+ task: () => editPackageJson(root, options.projectName || getProjectName())
117
+ } : {}
125
118
  ],
126
119
  {
127
120
  exitOnError: false
@@ -130,7 +123,6 @@ export async function createProject(options) {
130
123
 
131
124
  await tasks.run()
132
125
 
133
- await editPackageJson(root)
134
126
  doneLog(cwd, root)
135
127
  }
136
128
  return true
@@ -8,8 +8,8 @@
8
8
  "preview": "vite preview"
9
9
  },
10
10
  "dependencies": {
11
- "@gx-design-vue/pro-hooks": "^0.0.8",
12
- "@gx-design-vue/pro-utils": "^0.0.33",
11
+ "@gx-design-vue/pro-hooks": "^0.1.1",
12
+ "@gx-design-vue/pro-utils": "^0.1.1",
13
13
  "@vueuse/core": "^9.10.0",
14
14
  "@vueuse/shared": "^9.10.0",
15
15
  "axios": "^1.1.3",
@@ -22,7 +22,7 @@
22
22
  "qs": "^6.11.0",
23
23
  "unocss": "^0.48.2",
24
24
  "vant": "^4.0.8",
25
- "vue": "^3.2.41",
25
+ "vue": "^3.2.45",
26
26
  "vue-router": "^4.1.6"
27
27
  },
28
28
  "devDependencies": {
@@ -54,11 +54,11 @@
54
54
  "typescript": "^4.6.4",
55
55
  "unplugin-auto-import": "^0.11.4",
56
56
  "unplugin-vue-components": "^0.22.9",
57
- "vite": "^4.0.0",
57
+ "vite": "^4.0.4",
58
58
  "vite-plugin-html": "^3.2.0",
59
59
  "vite-plugin-mock": "^2.9.6",
60
60
  "vite-plugin-vue-setup-extend": "^0.4.0",
61
61
  "vue-eslint-parser": "^9.1.0",
62
62
  "vue-tsc": "^1.0.9"
63
63
  }
64
- }
64
+ }