UNPKG

san-cli-docit

Version:

san-cli-docit 是 [San](https://github.com/baidu/san) CLI 工具中 Markdown 文档建站部分。 是一个 [command 插件](https://ecomfe.github.io/san-cli)。

90 lines (83 loc) 2.22 kB
/** * @file command Component * @author ksky521 */ exports.builder = { https: { type: 'boolean', default: false, describe: 'Enable https' }, public: { type: 'string', describe: 'Specify the public URL for the HMR client' }, output: { type: 'boolean', default: false, describe: 'Export static files generated by building' }, config: { alias: 'config-file', type: 'string', describe: 'Project config file' }, theme: { type: 'string', describe: 'Use theme' }, port: { alias: 'p', type: 'number', describe: 'Port number of the URL' }, open: { alias: 'O', type: 'boolean', default: false, describe: 'Open Browser after the build is complete' }, host: { alias: 'H', type: 'string', describe: 'Hostname of the URL' }, qrcode: { type: 'boolean', default: true, describe: 'Print out the QRCode of the URL' } }; exports.description = 'Convert Markdown to San component'; exports.command = 'docit [entry]'; exports.handler = cliApi => { const Service = require('san-cli-service'); const flatten = require('san-cli-utils/utils').flatten; const cwd = cliApi.getCwd(); const {configFile, noProgress, profile, watch, output} = cliApi; // 处理 rc 文件传入的 Service Class arguments let {servicePlugins: plugins, useBuiltInPlugin = true, projectOptions} = cliApi.getPresets() || {}; let mode; let run; if (output) { run = require('./build'); cliApi.mode = mode = cliApi.mode || process.env.NODE_ENV || 'production'; } else { run = require('./serve'); cliApi.mode = mode = cliApi.mode || process.env.NODE_ENV || 'development'; } const service = new Service('docit', { cwd, configFile, watch, mode, useBuiltInPlugin, projectOptions, plugins: flatten(plugins), useProgress: !noProgress, useProfiler: profile }); let callback = run.bind(run, cliApi); service.run(callback); };