8000 refactor: further modernize codebase · coder-caicai/vue-cli@230314c · GitHub
[go: up one dir, main page]

Skip to content

Commit 230314c

Browse files
committed
refactor: further modernize codebase
1 parent ad2b191 commit 230314c

File tree

9 files changed

+31
-33
lines changed

9 files changed

+31
-33
lines changed

lib/ask.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const promptMapping = {
1717
*/
1818

1919
module.exports = function ask (prompts, data, done) {
20-
async.eachSeries(Object.keys(prompts), function (key, next) {
20+
async.eachSeries(Object.keys(prompts), (key, next) => {
2121
prompt(data, key, prompts[key], next)
2222
}, done)
2323
}
@@ -50,11 +50,11 @@ function prompt (data, key, prompt, done) {
5050
message: prompt.message || prompt.label || key,
5151
default: promptDefault,
5252
choices: prompt.choices || [],
53-
validate: prompt.validate || function () { return true }
54-
}], function (answers) {
53+
validate: prompt.validate || (() => true)
54+
}], answers => {
5555
if (Array.isArray(answers[key])) {
5656
data[key] = {}
57-
answers[key].forEach( 8000 function (multiChoiceAnswer) {
57+
answers[key].forEach(multiChoiceAnswer => {
5858
data[key][multiChoiceAnswer] = true
5959
})
6060
} else if (typeof answers[key] === 'string') {

lib/check-version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const semver = require('semver')
33
const chalk = require('chalk')
44
const packageConfig = require('../package.json')
55

6-
module.exports = function (done) {
6+
module.exports = done => {
77
// Ensure minimum supported node version is used
88
if (!semver.satisfies(process.version, packageConfig.engines.node)) {
99
return console.log(chalk.red(
@@ -14,7 +14,7 @@ module.exports = function (done) {
1414
request({
1515
url: 'https://registry.npmjs.org/vue-cli',
1616
timeout: 1000
17-
}, function (err, res, body) {
17+
}, (err, res, body) => {
1818
if (!err && res.statusCode === 200) {
1919
const latestVersion = JSON.parse(body)['dist-tags'].latest
2020
const localVersion = packageConfig.version

lib/filter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const match = require('minimatch')
22
const evaluate = require('./eval')
33

4-
module.exports = function (files, filters, data, done) {
4+
module.exports = (files, filters, data, done) => {
55
if (!filters) {
66
return done()
77
}
88
const fileNames = Object.keys(files)
9-
Object.keys(filters).forEach(function (glob) {
10-
fileNames.forEach(function (file) {
9+
Object.keys(filters).forEach(glob => {
10+
fileNames.forEach(file => {
1111
if (match(file, glob, { dot: true })) {
1212
const condition = filters[glob]
1313
if (!evaluate(condition, data)) {

lib/generate.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = function generate (name, src, dest, done) {
4040
inPlace: dest === process.cwd(),
4141
noEscape: true
4242
})
43-
opts.helpers && Object.keys(opts.helpers).map(function (key) {
43+
opts.helpers && Object.keys(opts.helpers).map(key => {
4444
Handlebars.registerHelper(key, opts.helpers[key])
4545
})
4646

@@ -63,7 +63,7 @@ module.exports = function generate (name, src, dest, done) {
6363
metalsmith.clean(false)
6464
.source('.') // start from template root instead of `./src` which is Metalsmith's default for `source`
6565
.destination(dest)
66-
.build(function (err, files) {
66+
.build((err, files) => {
6767
done(err)
6868
if (typeof opts.complete === 'function') {
6969
const helpers = { chalk, logger, files }
@@ -84,7 +84,7 @@ module.exports = function generate (name, src, dest, done) {
8484
*/
8585

8686
function askQuestions (prompts) {
87-
return function (files, metalsmith, done) {
87+
return (files, metalsmith, done) => {
8888
ask(prompts, metalsmith.metadata(), done)
8989
}
9090
}
@@ -97,7 +97,7 @@ function askQuestions (prompts) {
9797
*/
9898

9999
function filterFiles (filters) {
100-
return function (files, metalsmith, done) {
100+
return (files, metalsmith, done) => {
101101
filter(files, filters, metalsmith.metadata(), done)
102102
}
103103
}
@@ -114,10 +114,10 @@ function renderTemplateFiles (skipInterpolation) {
114114
skipInterpolation = typeof skipInterpolation === 'string'
115115
? [skipInterpolation]
116116
: skipInterpolation
117-
return function (files, metalsmith, done) {
117+
return (files, metalsmith, done) => {
118118
const keys = Object.keys(files)
119119
const metalsmithMetadata = metalsmith.metadata()
120-
async.each(keys, function (file, next) {
120+
async.each(keys, (file, next) => {
121121
// skipping files with skipInterpolation option
122122
if (skipInterpolation && multimatch([file], skipInterpolation, { dot: true }).length) {
123123
return next()
@@ -127,7 +127,7 @@ function renderTemplateFiles (skipInterpolation) {
127127
if (!/{{([^{}]+)}}/g.test(str)) {
128128
return next()
129129
}
130-
render(str, metalsmithMetadata, function (err, res) {
130+
render(str, metalsmithMetadata, (err, res) => {
131131
if (err) {
132132
err.message = `[${file}] ${err.message}`
133133
return next(err)
@@ -148,13 +148,11 @@ function renderTemplateFiles (skipInterpolation) {
148148

149149
function logMessage (message, data) {
150150
if (!message) return
151-
render(message, data, function (err, res) {
151+
render(message, data, (err, res) => {
152152
if (err) {
153153
console.error('\n Error when rendering template complete message: ' + err.message.trim())
154154
} else {
155-
console.log('\n' + res.split(/\r?\n/g).map(function (line) {
156-
return ' ' + line
157-
}).join('\n'))
155+
console.log('\n' + res.split(/\r?\n/g).map(line => ' ' + line).join('\n'))
158156
}
159157
})
160158
}

lib/git-user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const exec = require('child_process').execSync
22

3-
module.exports = function () {
3+
module.exports = () => {
44
let name
55
let email
66

lib/local-path.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const path = require('path')
22

33
module.exports = {
4-
isLocalPath: function (templatePath) {
4+
isLocalPath (templatePath) {
55
return /^[./]|(^[a-zA-Z]:)/.test(templatePath)
66
},
77

8-
getTemplatePath: function (templatePath) {
8+
getTemplatePath (templatePath) {
99
return path.isAbsolute(templatePath)
1010
? templatePath
1111
: path.normalize(path.join(process.cwd(), templatePath))

lib/logger.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const sep = chalk.gray('·')
1414
* @param {String} message
1515
*/
1616

17-
exports.log = function () {
18-
const msg = format.apply(format, arguments)
17+
exports.log = function (...args) {
18+
const msg = format.apply(format, args)
1919
console.log(chalk.white(prefix), sep, msg)
2020
}
2121

@@ -25,9 +25,9 @@ exports.log = function () {
2525
* @param {String} message
2626
*/
2727

28-
exports.fatal = function (message) {
29-
if (message instanceof Error) message = message.message.trim()
30-
const msg = format.apply(format, arguments)
28+
exports.fatal = function (...args) {
29+
if (args[0] instanceof Error) args[0] = args[0].message.trim()
30+
const msg = format.apply(format, args)
3131
console.error(chalk.red(prefix), sep, msg)
3232
process.exit(1)
3333
}
@@ -38,7 +38,7 @@ exports.fatal = function (message) {
3838
* @param {String} message
3939
*/
4040

41-
exports.success = function () {
42-
const msg = format.apply(format, arguments)
41+
exports.success = function (...args) {
42+
const msg = format.apply(format, args)
4343
console.log(chalk.white(prefix), sep, msg)
4444
}

lib/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function setDefault (opts, key, val) {
7777
function setValidateName (opts) {
7878
const name = opts.prompts.name
7979
const customValidate = name.validate
80-
name.validate = function (name) {
80+
name.validate = name => {
8181
const its = validateName(name)
8282
if (!its.validForNewPackages) {
8383
const errors = (its.errors || []).concat(its.warnings || [])

lib/warnings.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const chalk = require('chalk')
22

33
module.exports = {
4-
v2SuffixTemplatesDeprecated: function (template, name) {
4+
v2SuffixTemplatesDeprecated (template, name) {
55
const initCommand = 'vue init ' + template.replace('-2.0', '') + ' ' + name
66

77
console.log(chalk.red(' This template is deprecated, as the original template now uses Vue 2.0 by default.'))
88
console.log()
99
console.log(chalk.yellow(' Please use this command instead: ') + chalk.green(initCommand))
1010
console.log()
1111
},
12-
v2BranchIsNowDefault: function (template, name) {
12+
v2BranchIsNowDefault (template, name) {
1313
const vue1InitCommand = 'vue init ' + template + '#1.0' + ' ' + name
1414

1515
console.log(chalk.green(' This will install Vue 2.x version of the template.'))

0 commit comments

Comments
 (0)
0