mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-30 00:41:12 -05:00
setup test and help
This commit is contained in:
@@ -39,7 +39,7 @@ Both utilize a plugin-based architecture.
|
||||
|
||||
### Generator
|
||||
|
||||
Generator are globally-installed plugins for the Creator. `@vue/cli` ships with a number of [built-in generators][2].
|
||||
Generators are globally-installed plugins for the Creator. `@vue/cli` ships with a number of [built-in generators][2].
|
||||
|
||||
A generator should export a function which receives a [GeneratorAPI][3] instance as the only argument. The API allows a generator to inject prompts, `package.json` fields and files to the project being created.
|
||||
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
machine:
|
||||
node:
|
||||
version: 8
|
||||
environment:
|
||||
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
|
||||
|
||||
dependencies:
|
||||
override:
|
||||
- yarn
|
||||
cache_directories:
|
||||
- ~/.cache/yarn
|
||||
|
||||
test:
|
||||
override:
|
||||
- yarn test
|
||||
+13
-1
@@ -5,17 +5,29 @@
|
||||
"packages/test/*"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "jest --env node",
|
||||
"lint": "eslint --fix packages/**/*.js",
|
||||
"precommit": "lint-staged"
|
||||
},
|
||||
"jest": {
|
||||
"testEnvironment": "node",
|
||||
"testPathIgnorePatterns": [
|
||||
"/node_modules/",
|
||||
"/packages/"
|
||||
]
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": ["eslint --fix", "git add"]
|
||||
"*.js": [
|
||||
"eslint --fix",
|
||||
"git add"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"debug": "^3.1.0",
|
||||
"eslint": "^4.14.0",
|
||||
"eslint-plugin-vue-libs": "^2.0.1",
|
||||
"husky": "^0.14.3",
|
||||
"jest": "^22.0.4",
|
||||
"lerna": "^2.5.1",
|
||||
"lint-staged": "^6.0.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
module.exports = api => {
|
||||
api.registerCommand('test', (webpackConfig, args) => {
|
||||
require('./runner')(webpackConfig, args)
|
||||
api.registerCommand('test', {
|
||||
description: 'run unit tests'
|
||||
}, args => {
|
||||
api.setEnv('test')
|
||||
require('./runner')(api.resolveWebpackConfig(), args)
|
||||
})
|
||||
|
||||
api.configureWebpack(webpackConfig => {
|
||||
|
||||
@@ -15,8 +15,12 @@ module.exports = class PluginAPI {
|
||||
process.env.BABEL_ENV = env === 'production' ? env : 'development'
|
||||
}
|
||||
|
||||
registerCommand (name, fn) {
|
||||
this.service.commands[name] = fn
|
||||
registerCommand (name, opts, fn) {
|
||||
if (typeof opts === 'function') {
|
||||
fn = opts
|
||||
opts = null
|
||||
}
|
||||
this.service.commands[name] = { fn, opts }
|
||||
}
|
||||
|
||||
chainWebpack (fn) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const chalk = require('chalk')
|
||||
const { dirname } = require('path')
|
||||
const getPkg = require('read-pkg-up')
|
||||
const merge = require('webpack-merge')
|
||||
@@ -28,6 +29,7 @@ module.exports = class Service {
|
||||
'./command-plugins/serve',
|
||||
'./command-plugins/build',
|
||||
'./command-plugins/inspect',
|
||||
'./command-plugins/help',
|
||||
'./config-plugins/base',
|
||||
'./config-plugins/css',
|
||||
'./config-plugins/dev',
|
||||
@@ -43,14 +45,18 @@ module.exports = class Service {
|
||||
}))
|
||||
}
|
||||
|
||||
run (command, args) {
|
||||
const runner = this.commands[command]
|
||||
if (runner) {
|
||||
args._.shift() // remove command itself
|
||||
runner(args)
|
||||
} else {
|
||||
// TODO warn unknown command
|
||||
run (name, args) {
|
||||
let command = this.commands[name]
|
||||
if (!command && name) {
|
||||
console.log(chalk.red(`\n command "${name}" does not exist.`))
|
||||
}
|
||||
if (!command || args.help) {
|
||||
command = this.commands.help
|
||||
} else {
|
||||
args._.shift() // remove command itself
|
||||
}
|
||||
const { fn } = command
|
||||
return fn(args)
|
||||
}
|
||||
|
||||
resolveWebpackConfig (env) {
|
||||
@@ -75,7 +81,7 @@ module.exports = class Service {
|
||||
}
|
||||
|
||||
loadProjectConfig () {
|
||||
// TODO
|
||||
// TODO load project config from vue.config.js or vue field in package.json
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
module.exports = (api, options) => {
|
||||
api.registerCommand('build', args => {
|
||||
api.registerCommand('build', {
|
||||
description: 'build for production',
|
||||
usage: 'vue-cli-service build',
|
||||
options: {
|
||||
'--extractCSS': 'extract component CSS into one file.'
|
||||
}
|
||||
}, args => {
|
||||
// TODO
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
const chalk = require('chalk')
|
||||
const padEnd = require('string.prototype.padend')
|
||||
|
||||
module.exports = (api, options) => {
|
||||
api.registerCommand('help', args => {
|
||||
const command = args._[0]
|
||||
if (!command) {
|
||||
logMainHelp()
|
||||
} else {
|
||||
logHelpForCommand(command, api.service.commands[command])
|
||||
}
|
||||
})
|
||||
|
||||
function logMainHelp () {
|
||||
console.log(
|
||||
`\n Usage: vue-cli-service <command> [options]\n` +
|
||||
`\n Commands:\n`
|
||||
)
|
||||
const commands = api.service.commands
|
||||
const padLength = getLongest(commands)
|
||||
for (const name in commands) {
|
||||
if (name !== 'help') {
|
||||
const opts = commands[name].opts || {}
|
||||
console.log(` ${
|
||||
chalk.blue(padEnd(name, padLength))
|
||||
}${
|
||||
opts.description || ''
|
||||
}`)
|
||||
}
|
||||
}
|
||||
console.log(`\n run ${
|
||||
chalk.green(`vue-cli-service help [command]`)
|
||||
} for usage of a specific command.\n`)
|
||||
}
|
||||
|
||||
function logHelpForCommand (name, command) {
|
||||
if (!command) {
|
||||
console.log(chalk.red(`\n command "${name}" does not exist.`))
|
||||
} else {
|
||||
const opts = command.opts || {}
|
||||
if (opts.usage) {
|
||||
console.log(`\n Usage: ${opts.usage}`)
|
||||
}
|
||||
if (opts.options) {
|
||||
console.log(`\n Options:\n`)
|
||||
const padLength = getLongest(opts.options)
|
||||
for (const name in opts.options) {
|
||||
console.log(` ${
|
||||
chalk.blue(padEnd(name, padLength))
|
||||
}${
|
||||
opts.options[name]
|
||||
}`)
|
||||
}
|
||||
}
|
||||
console.log()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getLongest (commands) {
|
||||
let longest = 10
|
||||
for (const name in commands) {
|
||||
if (name.length + 1 > longest) {
|
||||
longest = name.length + 1
|
||||
}
|
||||
}
|
||||
return longest
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
module.exports = (api, options) => {
|
||||
api.registerCommand('inspect', args => {
|
||||
api.registerCommand('inspect', {
|
||||
description: 'inspect internal webpack config',
|
||||
usage: 'vue-cli-service inspect [...keys]',
|
||||
options: {
|
||||
'--env': 'specify NODE_ENV (default: development)'
|
||||
}
|
||||
}, args => {
|
||||
api.setEnv(args.env || 'development')
|
||||
|
||||
const stringify = require('javascript-stringify')
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
module.exports = (api, options) => {
|
||||
api.registerCommand('serve', args => {
|
||||
api.registerCommand('serve', {
|
||||
description: 'start development server',
|
||||
usage: 'vue-cli-service serve',
|
||||
options: {
|
||||
'--env': 'specify NODE_ENV (default: development)',
|
||||
'--host': 'specify host (default: 0.0.0.0)',
|
||||
'--port': 'specify port (default: 8080)',
|
||||
'--https': 'use https'
|
||||
}
|
||||
}, args => {
|
||||
// TODO improve log formatting
|
||||
console.log('[vue-cli] starting dev server, hang tight...')
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"ora": "^1.3.0",
|
||||
"portfinder": "^1.0.13",
|
||||
"read-pkg-up": "^3.0.0",
|
||||
"string.prototype.padend": "^3.0.0",
|
||||
"uglifyjs-webpack-plugin": "^1.1.4",
|
||||
"url-loader": "^0.6.2",
|
||||
"vue-loader": "^13.6.1",
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
"vue-create": "bin/vue-create",
|
||||
"vue-init": "bin/vue-init"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/vuejs/vue-cli.git"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"env": {
|
||||
"jest": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
it('should pass', () => {
|
||||
expect(1).toBe(1)
|
||||
})
|
||||
@@ -259,6 +259,10 @@ assert@^1.1.1:
|
||||
dependencies:
|
||||
util "0.10.3"
|
||||
|
||||
assertion-error@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c"
|
||||
|
||||
astral-regex@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
|
||||
@@ -1191,6 +1195,17 @@ center-align@^0.1.1:
|
||||
align-text "^0.1.3"
|
||||
lazy-cache "^1.0.3"
|
||||
|
||||
chai@^4.1.2:
|
||||
version "4.1.2"
|
||||
resolved "https://registry.yarnpkg.com/chai/-/chai-4.1.2.tgz#0f64584ba642f0f2ace2806279f4f06ca23ad73c"
|
||||
dependencies:
|
||||
assertion-error "^1.0.1"
|
||||
check-error "^1.0.1"
|
||||
deep-eql "^3.0.0"
|
||||
get-func-name "^2.0.0"
|
||||
pathval "^1.0.0"
|
||||
type-detect "^4.0.0"
|
||||
|
||||
chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
|
||||
version "1.1.3"
|
||||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
|
||||
@@ -1213,6 +1228,10 @@ chardet@^0.4.0:
|
||||
version "0.4.2"
|
||||
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
|
||||
|
||||
check-error@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82"
|
||||
|
||||
chokidar@^1.6.0, chokidar@^1.6.1, chokidar@^1.7.0:
|
||||
version "1.7.0"
|
||||
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
|
||||
@@ -1904,6 +1923,12 @@ dedent@^0.7.0:
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c"
|
||||
|
||||
deep-eql@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df"
|
||||
dependencies:
|
||||
type-detect "^4.0.0"
|
||||
|
||||
deep-equal@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
|
||||
@@ -2219,7 +2244,7 @@ error-stack-parser@^2.0.0, error-stack-parser@^2.0.1:
|
||||
dependencies:
|
||||
stackframe "^1.0.3"
|
||||
|
||||
es-abstract@^1.5.1, es-abstract@^1.7.0:
|
||||
es-abstract@^1.4.3, es-abstract@^1.5.1, es-abstract@^1.7.0:
|
||||
version "1.10.0"
|
||||
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.10.0.tgz#1ecb36c197842a00d8ee4c2dfd8646bb97d60864"
|
||||
dependencies:
|
||||
@@ -2853,6 +2878,10 @@ get-caller-file@^1.0.1:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5"
|
||||
|
||||
get-func-name@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
|
||||
|
||||
get-own-enumerable-property-symbols@^2.0.1:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-2.0.1.tgz#5c4ad87f2834c4b9b4e84549dc1e0650fb38c24b"
|
||||
@@ -5167,6 +5196,10 @@ path-type@^3.0.0:
|
||||
dependencies:
|
||||
pify "^3.0.0"
|
||||
|
||||
pathval@^1.0.0:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0"
|
||||
|
||||
pbkdf2@^3.0.3:
|
||||
version "3.0.14"
|
||||
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.14.tgz#a35e13c64799b06ce15320f459c230e68e73bade"
|
||||
@@ -6444,6 +6477,14 @@ string-width@^2.0.0, string-width@^2.1.0, string-width@^2.1.1:
|
||||
is-fullwidth-code-point "^2.0.0"
|
||||
strip-ansi "^4.0.0"
|
||||
|
||||
string.prototype.padend@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/string.prototype.padend/-/string.prototype.padend-3.0.0.tgz#f3aaef7c1719f170c5eab1c32bf780d96e21f2f0"
|
||||
dependencies:
|
||||
define-properties "^1.1.2"
|
||||
es-abstract "^1.4.3"
|
||||
function-bind "^1.0.2"
|
||||
|
||||
string_decoder@^1.0.0, string_decoder@~1.0.3:
|
||||
version "1.0.3"
|
||||
resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.0.3.tgz#0fc67d7c141825de94282dd536bec6b9bce860ab"
|
||||
@@ -6741,6 +6782,10 @@ type-check@~0.3.2:
|
||||
dependencies:
|
||||
prelude-ls "~1.1.2"
|
||||
|
||||
type-detect@^4.0.0:
|
||||
version "4.0.5"
|
||||
resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.5.tgz#d70e5bc81db6de2a381bcaca0c6e0cbdc7635de2"
|
||||
|
||||
type-is@~1.6.15:
|
||||
version "1.6.15"
|
||||
resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.15.tgz#cab10fb4909e441c82842eafe1ad646c81804410"
|
||||
|
||||
Reference in New Issue
Block a user