@gx-design-vue/create-gx-cli 0.0.2 → 0.0.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/package.json +1 -1
  2. package/src/cli.js +23 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gx-design-vue/create-gx-cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "license": "MIT",
5
5
  "description": "a cli to bootstrap gx project",
6
6
  "main": "src/index.js",
package/src/cli.js CHANGED
@@ -1,24 +1,28 @@
1
+ import fs from 'fs'
2
+ import path from 'path'
1
3
  import minimist from 'minimist'
2
4
  import prompts from 'prompts'
3
- import { blue, reset, yellow } from 'kolorist'
5
+ import { yellow, reset } from 'kolorist'
4
6
  import { createProject } from './main'
5
7
 
6
8
  const defaultTargetDir = 'gx-cli-project'
7
9
 
8
- const FRAMEWORKS = [
9
- {
10
- name: 'vue',
11
- color: yellow
12
- },
13
- {
14
- name: 'mobile',
15
- color: blue
16
- }
17
- ]
10
+ function getTemplate() {
11
+ const templateList = []
12
+ const files = fs.readdirSync(path.join(process.cwd(), '../'))
18
13
 
19
- const TEMPLATES = FRAMEWORKS.map(
20
- (f) => (f.variants && f.variants.map((v) => v.name)) || [f.name]
21
- ).reduce((a, b) => a.concat(b), [])
14
+ for (const file of files) {
15
+ if (file.indexOf('template') >= 0) {
16
+ templateList.push(file)
17
+ }
18
+ }
19
+ return templateList.map((el) => {
20
+ return {
21
+ name: el.split('-')[1],
22
+ color: yellow
23
+ }
24
+ })
25
+ }
22
26
 
23
27
  function formatTargetDir(targetDir) {
24
28
  return targetDir ? targetDir.trim().replace(/\/+$/g, '') : ''
@@ -35,6 +39,11 @@ function parseArgumentsIntoOptions() {
35
39
  }
36
40
 
37
41
  async function promptForMissingOptions(options) {
42
+ const FRAMEWORKS = getTemplate()
43
+
44
+ const TEMPLATES = FRAMEWORKS.map(
45
+ (f) => (f.variants && f.variants.map((v) => v.name)) || [f.name]
46
+ ).reduce((a, b) => a.concat(b), [])
38
47
  const answers = await prompts([
39
48
  {
40
49
  type: options.projectName ? null : 'text',