Skip to content

Commit

Permalink
refactor: all options are configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Estelle00 authored and HcySunYang committed Oct 25, 2018
1 parent 8dda590 commit bf897e8
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
phantomjs_cdnurl=http://cnpmjs.org/downloads
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ Output directory of the [docute](https://docute.org/) document.

The output directory of the markdown file, note: `markdownDir` is based on `outdir`, which means that the markdown file will be output to the `website/components` directory.

#### genType

* Type: `string`
* Default: ``

Select the target to generate.

#### title

* Type: `string`
* Default: ``

Sidbar title, note: when `genType === 'docute'` can optionally.

### Used in nodejs

`vuese` exposes two modules: `parser` and `Render`.
Expand Down
11 changes: 7 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ cli.command('*', 'vuese cli', () => {
cli.command('gen', 'Generate target resources', async (input, flags) => {
const config = await getConfig(flags)
const questions = require('./questions')
const answser = await require('inquirer').prompt(questions)
if (answser.genType === 'docute') require('../lib/genDocute')(config)
if (answser.genType === 'markdown') require('../lib')(config)
if (['docute', 'markdown'].indexOf(config.genType) < 0) {
const {genType} = await require('inquirer').prompt(questions)
config.genType = genType
}
if (config.genType === 'docute') require('../lib/genDocute')(config)
else if (config.genType === 'markdown') require('../lib')(config)
})

cli.command('serve', 'Serve generated docute website', async (input, flags) => {
const config = await getConfig(flags)
require('../lib/server')(config)
})

cli.parse()
cli.parse()
5 changes: 3 additions & 2 deletions lib/genDocute.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ module.exports = async (config) => {
targetPath: path.resolve(config.outDir),
configOptions: {
componentNames,
title: config.title,
markdownDir: config.markdownDir
}
})
logger.success('Generated successfully')
} catch (err) {
console.error(err.name === 'SAOError' ? err.message : err.stack)
process.exit(1)
}
}
process.exit(1)
}
6 changes: 3 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require('path')
const getProt = require('get-port')
const getPort = require('get-port')
const opn = require('opn')
const logger = require('log-horizon').create()

Expand All @@ -12,11 +12,11 @@ module.exports = async (config) => {
public: path.resolve(config.outDir)
})
})
const port = await getProt({ prot: 5000 })
const port = await getPort({ port: 5000 })

server.listen(port, '127.0.0.1',() => {
const addr = `http://127.0.0.1:${port}/`
logger.success(`Server running at ${addr}`);
if (config.open) opn(addr)
})
}
}
22 changes: 12 additions & 10 deletions lib/templates/docute/sao.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
module.exports = (options) => {
return {
prompts: {
title: {
type: 'input',
message: 'Sidbar title:',
default: 'Components'
}
},
const {title} = options
const config = {
data (answers) {
return {
title: answers.title,
title: title || answers.title,
componentNames: options.componentNames,
markdownDir: options.markdownDir
}
}
}
}
if (!title) config.prompts = {
title: {
type: 'input',
message: 'Sidbar title:',
default: 'Components'
}
}
return config;
}

0 comments on commit bf897e8

Please sign in to comment.