Skip to content

Commit 4733ca4

Browse files
committed
refactor: finish up
1 parent 230314c commit 4733ca4

File tree

8 files changed

+304
-144
lines changed

8 files changed

+304
-144
lines changed

.babelrc

-9
This file was deleted.

bin/vue-build

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
var chalk = require('chalk')
3+
const chalk = require('chalk')
44

55
console.log(chalk.yellow(
66
'\n' +

bin/vue-init

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/usr/bin/env node
22

3-
var download = require('download-git-repo')
4-
var program = require('commander')
5-
var exists = require('fs').existsSync
6-
var path = require('path')
7-
var ora = require('ora')
8-
var home = require('user-home')
9-
var tildify = require('tildify')
10-
var chalk = require('chalk')
11-
var inquirer = require('inquirer')
12-
var rm = require('rimraf').sync
13-
var logger = require('../lib/logger')
14-
var generate = require('../lib/generate')
15-
var checkVersion = require('../lib/check-version')
16-
var warnings = require('../lib/warnings')
17-
var localPath = require('../lib/local-path')
18-
19-
var isLocalPath = localPath.isLocalPath
20-
var getTemplatePath = localPath.getTemplatePath
3+
const download = require('download-git-repo')
4+
const program = require('commander')
5+
const exists = require('fs').existsSync
6+
const path = require('path')
7+
const ora = require('ora')
8+
const home = require('user-home')
9+
const tildify = require('tildify')
10+
const chalk = require('chalk')
11+
const inquirer = require('inquirer')
12+
const rm = require('rimraf').sync
13+
const logger = require('../lib/logger')
14+
const generate = require('../lib/generate')
15+
const checkVersion = require('../lib/check-version')
16+
const warnings = require('../lib/warnings')
17+
const localPath = require('../lib/local-path')
18+
19+
const isLocalPath = localPath.isLocalPath
20+
const getTemplatePath = localPath.getTemplatePath
2121

2222
/**
2323
* Usage.
@@ -32,7 +32,7 @@ program
3232
* Help.
3333
*/
3434

35-
program.on('--help', function () {
35+
program.on('--help', () => {
3636
console.log(' Examples:')
3737
console.log()
3838
console.log(chalk.gray(' # create a new project with an official template'))
@@ -57,15 +57,15 @@ help()
5757
* Settings.
5858
*/
5959

60-
var template = program.args[0]
61-
var hasSlash = template.indexOf('/') > -1
62-
var rawName = program.args[1]
63-
var inPlace = !rawName || rawName === '.'
64-
var name = inPlace ? path.relative('../', process.cwd()) : rawName
65-
var to = path.resolve(rawName || '.')
66-
var clone = program.clone || false
60+
let template = program.args[0]
61+
const hasSlash = template.indexOf('/') > -1
62+
const rawName = program.args[1]
63+
const inPlace = !rawName || rawName === '.'
64+
const name = inPlace ? path.relative('../', process.cwd()) : rawName
65+
const to = path.resolve(rawName || '.')
66+
const clone = program.clone || false
6767

68-
var tmp = path.join(home, '.vue-templates', template.replace(/\//g, '-'))
68+
const tmp = path.join(home, '.vue-templates', template.replace(/\//g, '-'))
6969
if (program.offline) {
7070
console.log(`> Use cached template at ${chalk.yellow(tildify(tmp))}`)
7171
template = tmp
@@ -76,7 +76,7 @@ if (program.offline) {
7676
*/
7777

7878
console.log()
79-
process.on('exit', function () {
79+
process.on('exit', () => {
8080
console.log()
8181
})
8282

@@ -87,11 +87,11 @@ if (exists(to)) {
8787
? 'Generate project in current directory?'
8888
: 'Target directory exists. Continue?',
8989
name: 'ok'
90-
}], function (answers) {
90+
}]).then(answers => {
9191
if (answers.ok) {
9292
run()
9393
}
94-
})
94+
}).catch(logger.fatal)
9595
} else {
9696
run()
9797
}
@@ -103,9 +103,9 @@ if (exists(to)) {
103103
function run () {
104104
// check if template is local
105105
if (isLocalPath(template)) {
106-
var templatePath = getTemplatePath(template)
106+
const templatePath = getTemplatePath(template)
107107
if (exists(templatePath)) {
108-
generate(name, templatePath, to, function (err) {
108+
generate(name, templatePath, to, err => {
109109
if (err) logger.fatal(err)
110110
console.log()
111111
logger.success('Generated "%s".', name)
@@ -114,10 +114,10 @@ function run () {
114114
logger.fatal('Local template "%s" not found.', template)
115115
}
116116
} else {
117-
checkVersion(function () {
117+
checkVersion(() => {
118118
if (!hasSlash) {
119119
// use official templates
120-
var officialTemplate = 'vuejs-templates/' + template
120+
const officialTemplate = 'vuejs-templates/' + template
121121
if (template.indexOf('#') !== -1) {
122122
downloadAndGenerate(officialTemplate)
123123
} else {
@@ -143,14 +143,14 @@ function run () {
143143
*/
144144

145145
function downloadAndGenerate (template) {
146-
var spinner = ora('downloading template')
146+
const spinner = ora('downloading template')
147147
spinner.start()
148148
// Remove if local template exists
149149
if (exists(tmp)) rm(tmp)
150-
download(template, tmp, { clone: clone }, function (err) {
150+
download(template, tmp, { clone }, err => {
151151
spinner.stop()
152152
if (err) logger.fatal('Failed to download repo ' + template + ': ' + err.message.trim())
153-
generate(name, tmp, to, function (err) {
153+
generate(name, tmp, to, err => {
154154
if (err) logger.fatal(err)
155155
console.log()
156156
logger.success('Generated "%s".', name)

bin/vue-list

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env node
22

3-
var logger = require('../lib/logger')
4-
var request = require('request')
5-
var chalk = require('chalk')
3+
const logger = require('../lib/logger')
4+
const request = require('request')
5+
const chalk = require('chalk')
66

77
/**
88
* Padding.
99
*/
1010

1111
console.log()
12-
process.on('exit', function () {
12+
process.on('exit', () => {
1313
console.log()
1414
})
1515

@@ -22,13 +22,13 @@ request({
2222
headers: {
2323
'User-Agent': 'vue-cli'
2424
}
25-
}, function (err, res, body) {
25+
}, (err, res, body) => {
2626
if (err) logger.fatal(err)
27-
var requestBody = JSON.parse(body)
27+
const requestBody = JSON.parse(body)
2828
if (Array.isArray(requestBody)) {
2929
console.log(' Available official templates:')
3030
console.log()
31-
requestBody.forEach(function (repo) {
31+
requestBody.forEach(repo => {
3232
console.log(
3333
' ' + chalk.yellow('★') +
3434
' ' + chalk.blue(repo.name) +

lib/ask.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function prompt (data, key, prompt, done) {
5151
default: promptDefault,
5252
choices: prompt.choices || [],
5353
validate: prompt.validate || (() => true)
54-
}], answers => {
54+
}]).then(answers => {
5555
if (Array.isArray(answers[key])) {
5656
data[key] = {}
5757
answers[key].forEach(multiChoiceAnswer => {
@@ -63,5 +63,5 @@ function prompt (data, key, prompt, done) {
6363
data[key] = answers[key]
6464
}
6565
done()
66-
})
66+
}).catch(done)
6767
}

0 commit comments

Comments
 (0)