forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquasar-create
More file actions
executable file
·170 lines (143 loc) · 4.38 KB
/
quasar-create
File metadata and controls
executable file
·170 lines (143 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env node
const parseArgs = require('minimist')
const chalk = require('chalk')
const argv = parseArgs(process.argv.slice(2), {
alias: {
b: 'branch',
k: 'kit',
c: 'clone',
o: 'offline',
h: 'help'
},
boolean: ['c', 'o', 'h'],
string: ['k', 'b']
})
if (argv.help) {
console.log(`
Description
Creates a Quasar App or App Extension project folder
Usage
$ quasar create <project-name> [--kit <kit-name>] [--branch <version-name>]
App Examples
$ quasar create my-project
# installs an App project with the latest App starter kit
$ quasar create my-project --branch v0.17
# installs an App project from a specific version (only major+minor version)
$ quasar create my-project --kit user/github-starter-kit
# installs an App project with a custom starter kit from GitHub
$ quasar create my-project --kit ./starter-kit-folder
# installs an App project using a starter kit located at ./starter-kit-folder
App Extension Examples
$ quasar create my-extension-project --kit app-extension
# installs an App Extension project with the latest Quasar App Extension starter kit
$ quasar create my-extension-project --kit user/github-extension-starter-kit
# installs an App Extension project with a custom starter kit from GitHub
$ quasar create my-extension-project --kit user/github-extension-starter-kit --branch dev
# installs an App Extension project with a custom starter kit from GitHub using the dev branch
Options
--kit, -k Use specific starter kit
--branch, -b Use specific branch of the starter kit
--clone, -c Use git clone
--offline, -o Use a cached starter kit
--help, -h Displays this message
`)
process.exit(0)
}
require('../lib/ensure-outside-project')()
console.log()
console.log(
require('fs').readFileSync(
require('path').join(__dirname, '../assets/logo.art'),
'utf8'
)
)
// Following is adapted from Vue CLI v2 "init" command
const download = require('download-git-repo')
const exists = require('fs').existsSync
const path = require('path')
const ora = require('ora')
const home = require('os').homedir()
const tildify = require('tildify')
const inquirer = require('inquirer')
const rm = require('rimraf').sync
const generate = require('../lib/generate')
const logger = require('../lib/logger')
const { isLocalPath, getTemplatePath } = require('../lib/local-path')
let template = argv.kit
? (
argv.kit.indexOf('/') > -1
? argv.kit
: 'quasarframework/quasar-starter-kit-' + argv.kit
)
: 'quasarframework/quasar-starter-kit'
const rawName = argv._[0]
const inPlace = !rawName || rawName === '.'
const name = inPlace ? path.relative('../', process.cwd()) : rawName
const to = path.resolve(rawName || '.')
if (isLocalPath(template) !== true) {
template += '#' + (argv.branch || 'master')
}
const tmp = path.join(home, '.quasar-starter-kits', template.replace(/[\/:]/g, '-'))
if (argv.offline) {
console.log(`> Use cached template at ${chalk.yellow(tildify(tmp))}`)
template = tmp
}
console.log()
process.on('exit', () => {
console.log()
})
if (inPlace || exists(to)) {
inquirer.prompt([{
type: 'confirm',
message: inPlace
? 'Generate project in current directory?'
: 'Target directory exists. Continue?',
name: 'ok'
}]).then(answers => {
if (answers.ok) {
run()
}
}).catch(logger.fatal)
}
else {
run()
}
function run () {
// check if template isn't local
if (isLocalPath(template) !== true) {
downloadAndGenerate(template)
return
}
const templatePath = getTemplatePath(template)
if (exists(templatePath)) {
generate(name, templatePath, to, err => {
if (err) logger.fatal(err)
console.log()
logger.success('Generated "%s".', name)
})
}
else {
logger.fatal('Local template "%s" not found.', template)
}
}
function downloadAndGenerate (template) {
const spinner = ora(' Downloading Quasar starter kit')
spinner.start()
// Remove if local template exists
if (exists(tmp)) {
rm(tmp)
}
download(template, tmp, { clone: argv.clone }, err => {
spinner.stop()
if (err) {
logger.fatal('Failed to download repo ' + template + ': ' + err.message.trim())
}
generate(name, tmp, to, err => {
if (err) {
logger.fatal(err)
}
console.log()
logger.success('Generated "%s".', name)
})
})
}