1 | #!/usr/bin/env node
|
2 |
|
3 | const parseArgs = require('minimist')
|
4 |
|
5 | const argv = parseArgs(process.argv.slice(2), {
|
6 | alias: {
|
7 | v: 'version',
|
8 | t: 'type',
|
9 | h: 'help'
|
10 | },
|
11 | boolean: ['h'],
|
12 | string: ['v', 't']
|
13 | })
|
14 |
|
15 | if (argv.help) {
|
16 | console.log(`
|
17 | Description
|
18 | Create a Quasar App folder from the starter kit.
|
19 | You need "vue-cli" package installed globally.
|
20 | Usage
|
21 | # Install latest starter kit:
|
22 | $ quasar init <folder_name>
|
23 |
|
24 | # Install starter kit for specific Quasar version.
|
25 | # Only specify the major and minor version (no patch version).
|
26 | # Good example: 0.15, 1.0, 1.2
|
27 | # Bad example: 0.15.2, 1.0.1, 1.2.2
|
28 | $ quasar init -v 0.15
|
29 |
|
30 | # Install UMD starter kit
|
31 | $ quasar init -t umd <folder_name>
|
32 |
|
33 | Options
|
34 | --version, -v Install specific Quasar version
|
35 | --type, -t Install specific starter kit
|
36 | --help, -h Displays this message
|
37 | `)
|
38 | process.exit(0)
|
39 | }
|
40 |
|
41 | const
|
42 | logger = require('../lib/helpers/logger'),
|
43 | log = logger('app:init'),
|
44 | warn = logger('app:init', 'red'),
|
45 | spawn = require('cross-spawn'),
|
46 | resolve = require('path').resolve
|
47 |
|
48 | if (argv.type && !['umd'].includes(argv.type)) {
|
49 | warn(`Specified type ("${argv.type}") is not recognized.`)
|
50 | warn()
|
51 | process.exit(0)
|
52 | }
|
53 |
|
54 | if (!argv._[0]) {
|
55 | warn(`Missing folder name as parameter.`)
|
56 | warn()
|
57 | process.exit(0)
|
58 | }
|
59 |
|
60 | const
|
61 | cliDir = resolve(__dirname, '..')
|
62 |
|
63 | let template = `quasarframework/quasar-starter-kit${argv.type ? `-${argv.type}` : ''}`
|
64 | if (argv.version) {
|
65 | template += `#v${argv.version}`
|
66 | }
|
67 |
|
68 | try {
|
69 | console.log(` Running command: vue init '${template}' ${argv._[0]}`)
|
70 | const child = spawn.sync('vue', [
|
71 | 'init',
|
72 | template,
|
73 | argv._[0]
|
74 | ], { stdio: ['inherit', 'inherit', 'inherit'] })
|
75 |
|
76 | if (child.status !== 0) {
|
77 | warn(`⚠️ Something went wrong... Try running the "vue init" command above manually.`)
|
78 | warn(`Reasons for failure: Package @vue/cli and @vue/cli-init are not installed globally, specified template is unavailable or it failed to download.`)
|
79 | warn()
|
80 | process.exit(1)
|
81 | }
|
82 | }
|
83 | catch (err) {
|
84 | console.log(err)
|
85 | warn(`⚠️ Package vue-cli not installed globally.`)
|
86 | warn('Run "yarn global add @vue/cli @vue/cli-init" or "npm i -g @vue/cli @vue/cli-init" to install Vue CLI and then try again.')
|
87 | warn()
|
88 | process.exit(1)
|
89 | }
|