Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Commit

Permalink
⚡ improvement(docs): add cli service docs:serve alias command
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Jan 31, 2019
1 parent b7e3251 commit 59b2b2b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = (api, options, rootOptions) => {
api.extendPackage({
scripts: {
'demo': 'vue-cli-service demo',
'docs:serve': 'vue-cli-service docs --mode dev',
'docs': 'npm run docs:serve',
'docs:serve': 'vue-cli-service docs --mode serve',
'docs:build': 'vue-cli-service docs --mode build'
},
sideeffects: false,
Expand Down
3 changes: 3 additions & 0 deletions lib/docs/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = api => ({
}
},
fn: async args => {
if (!args.mode || args.mode !== 'build') {
args.mode = 'dev'
}
args.mode = args.mode || 'serve'
const bin = require.resolve(path.join(api.getCwd(), './node_modules/.bin/vuepress'))
return service(bin, args)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/commands/docs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('docs default', () => {

const calls = docsService.mock.calls
expect(calls[0][0]).toMatch(`${process.cwd()}/node_modules/vuepress/cli.js`)
expect(calls[0][1]).toEqual({ _: [], mode: 'serve' })
expect(calls[0][1]).toEqual({ _: [], mode: 'dev' })
})

test('docs serve', () => {
Expand All @@ -39,7 +39,7 @@ test('docs serve', () => {
service.run('docs', { mode: 'serve' })

const calls = docsService.mock.calls
expect(calls[0][1]).toEqual({ _: [], mode: 'serve' })
expect(calls[0][1]).toEqual({ _: [], mode: 'dev' })
})

test('docs build', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/generators/docs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ test('docs', async () => {
}])

// check pkg
expect(pkg.scripts['docs:serve']).toMatch('vue-cli-service docs --mode dev')
expect(pkg.scripts['docs']).toMatch('npm run docs:serve')
expect(pkg.scripts['docs:serve']).toMatch('vue-cli-service docs --mode serve')
expect(pkg.scripts['docs:build']).toMatch('vue-cli-service docs --mode build')

// check files
Expand Down

0 comments on commit 59b2b2b

Please sign in to comment.