-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0305fd7
commit 518b3ef
Showing
9 changed files
with
251 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
const path = require('path'); | ||
const execa = require('execa'); | ||
const test = require('ava'); | ||
const path = require('path') | ||
const execa = require('execa') | ||
const test = require('ava') | ||
|
||
const rootCommand = path.join(process.cwd(), 'bin/docsify'); | ||
const rootCommand = path.join(process.cwd(), 'bin/docsify') | ||
|
||
test('shows up help message without any args', async t => { | ||
const { stderr } = await execa(rootCommand, {reject: false}); | ||
t.snapshot(stderr); | ||
}); | ||
const {stderr} = await execa(rootCommand, {reject: false}) | ||
t.snapshot(stderr) | ||
}) | ||
|
||
const matchSnapshot = async (t, arg) => { | ||
const { stdout } = await execa(rootCommand, [arg]); | ||
t.snapshot(stdout); | ||
}; | ||
const {stdout} = await execa(rootCommand, [arg]) | ||
t.snapshot(stdout) | ||
} | ||
|
||
test('shows help with -h flag', matchSnapshot, '-h'); | ||
test('shows help with --help flag', matchSnapshot, '--help'); | ||
test('shows version information with -v flag', matchSnapshot, '-v'); | ||
test('shows version information with --version flag', matchSnapshot, '--version'); | ||
test('shows help with -h flag', matchSnapshot, '-h') | ||
test('shows help with --help flag', matchSnapshot, '--help') | ||
test('shows version information with -v flag', matchSnapshot, '-v') | ||
test('shows version information with --version flag', matchSnapshot, '--version') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,126 @@ | ||
const chalk = require("chalk"); | ||
const updateNotifier = require("update-notifier"); | ||
const chalk = require('chalk') | ||
const updateNotifier = require('update-notifier') | ||
|
||
const pkg = require("../package.json"); | ||
const run = require("../lib"); | ||
const pkg = require('../package.json') | ||
const run = require('../lib') | ||
|
||
updateNotifier({ pkg: pkg }).notify(); | ||
updateNotifier({pkg: pkg}).notify() | ||
|
||
const Locales = require("../tools/locales"); | ||
const y18n = new Locales(); | ||
const Locales = require('../tools/locales') | ||
const y18n = new Locales() | ||
|
||
require("yargonaut") | ||
.style("yellow", "required") | ||
.helpStyle("green") | ||
.errorsStyle("red.bold"); | ||
require('yargonaut') | ||
.style('yellow', 'required') | ||
.helpStyle('green') | ||
.errorsStyle('red.bold') | ||
|
||
const yargs = require("yargs") | ||
.demandCommand(1, chalk.red("[ERROR] 0 arguments passed. Please specify a command")) | ||
const yargs = require('yargs') | ||
.demandCommand(1, chalk.red('[ERROR] 0 arguments passed. Please specify a command')) | ||
.strict() | ||
.recommendCommands() | ||
.usage(chalk.bold(y18n.__("usage") + ": docsify <init|serve> <path>")) | ||
.usage(chalk.bold(y18n.__('usage') + ': docsify <init|serve> <path>')) | ||
.command({ | ||
command: "init [path]", | ||
alias: "i", | ||
desc: chalk.gray(y18n.__("init")), | ||
command: 'init [path]', | ||
alias: 'i', | ||
desc: chalk.gray(y18n.__('init')), | ||
builder: yargs => | ||
yargs.options({ | ||
local: { | ||
alias: "l", | ||
alias: 'l', | ||
default: false, | ||
desc: chalk.gray(y18n.__("init.local")), | ||
desc: chalk.gray(y18n.__('init.local')), | ||
nargs: 0, | ||
requiresArg: false, | ||
type: "boolean" | ||
type: 'boolean' | ||
}, | ||
theme: { | ||
alias: "t", | ||
default: "vue", | ||
desc: chalk.gray(y18n.__("init.theme")), | ||
choices: ["vue", "buble", "dark", "pure"], | ||
alias: 't', | ||
default: 'vue', | ||
desc: chalk.gray(y18n.__('init.theme')), | ||
choices: ['vue', 'buble', 'dark', 'pure'], | ||
nargs: 1, | ||
requiresArg: true, | ||
type: "string" | ||
type: 'string' | ||
} | ||
}), | ||
handler: argv => run.init(argv.path, argv.local, argv.theme) | ||
}) | ||
.command({ | ||
command: "serve [path]", | ||
alias: "s", | ||
desc: chalk.gray(y18n.__("serve")), | ||
command: 'serve [path]', | ||
alias: 's', | ||
desc: chalk.gray(y18n.__('serve')), | ||
builder: yargs => | ||
yargs.options({ | ||
open: { | ||
alias: "o", | ||
alias: 'o', | ||
default: false, | ||
desc: chalk.gray(y18n.__("serve.open")), | ||
desc: chalk.gray(y18n.__('serve.open')), | ||
nargs: 0, | ||
requiresArg: false, | ||
type: "boolean" | ||
type: 'boolean' | ||
}, | ||
port: { | ||
alias: "p", | ||
alias: 'p', | ||
default: 3000, | ||
desc: chalk.gray(y18n.__("serve.port")), | ||
desc: chalk.gray(y18n.__('serve.port')), | ||
nargs: 1, | ||
requiresArg: true, | ||
type: "number" | ||
type: 'number' | ||
}, | ||
"livereload-port": { | ||
alias: "P", | ||
'livereload-port': { | ||
alias: 'P', | ||
default: 35729, | ||
desc: chalk.gray(y18n.__("livereload.port")), | ||
desc: chalk.gray(y18n.__('livereload.port')), | ||
nargs: 1, | ||
requiresArg: true, | ||
type: "number" | ||
type: 'number' | ||
}, | ||
"index-name": { | ||
alias: "i", | ||
desc: chalk.gray(y18n.__("serve.indexname")), | ||
'index-name': { | ||
alias: 'i', | ||
desc: chalk.gray(y18n.__('serve.indexname')), | ||
nargs: 1, | ||
requiresArg: true, | ||
type: "string" | ||
type: 'string' | ||
} | ||
}), | ||
handler: argv => run.serve(argv.path, argv.open, argv.port, argv.P, argv.i) | ||
}) | ||
.command({ | ||
command: "start <path>", | ||
desc: chalk.gray(y18n.__("start")), | ||
command: 'start <path>', | ||
desc: chalk.gray(y18n.__('start')), | ||
builder: yargs => | ||
yargs.options({ | ||
config: { | ||
alias: "c", | ||
alias: 'c', | ||
default: false, | ||
desc: chalk.gray(y18n.__("start.config")), | ||
desc: chalk.gray(y18n.__('start.config')), | ||
nargs: 0, | ||
requiresArg: false, | ||
type: "string" | ||
type: 'string' | ||
}, | ||
port: { | ||
alias: "p", | ||
alias: 'p', | ||
default: 4000, | ||
desc: chalk.gray(y18n.__("start.port")), | ||
desc: chalk.gray(y18n.__('start.port')), | ||
nargs: 1, | ||
requiresArg: true, | ||
type: "number" | ||
type: 'number' | ||
} | ||
}), | ||
handler: argv => run.start(argv.path, argv.config, argv.port) | ||
}) | ||
.help() | ||
.option("help", { | ||
alias: "h", | ||
type: "boolean", | ||
desc: chalk.gray(y18n.__("help")), | ||
group: chalk.green(y18n.__("group.globaloptions")) | ||
.option('help', { | ||
alias: 'h', | ||
type: 'boolean', | ||
desc: chalk.gray(y18n.__('help')), | ||
group: chalk.green(y18n.__('group.globaloptions')) | ||
}) | ||
.version("\ndocsify-cli version:\n " + pkg.version + "\n") | ||
.option("version", { | ||
alias: "v", | ||
type: "boolean", | ||
desc: chalk.gray(y18n.__("version")), | ||
group: chalk.green(y18n.__("group.globaloptions")) | ||
.version('\ndocsify-cli version:\n ' + pkg.version + '\n') | ||
.option('version', { | ||
alias: 'v', | ||
type: 'boolean', | ||
desc: chalk.gray(y18n.__('version')), | ||
group: chalk.green(y18n.__('group.globaloptions')) | ||
}) | ||
.epilog(chalk.gray(y18n.__("epilog"))).argv; | ||
.epilog(chalk.gray(y18n.__('epilog'))).argv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,75 @@ | ||
"use strict"; | ||
'use strict' | ||
|
||
const fs = require("fs"); | ||
const cp = require("cp-file").sync; | ||
const chalk = require("chalk"); | ||
const util = require("../util/index"); | ||
const fs = require('fs') | ||
const cp = require('cp-file').sync | ||
const chalk = require('chalk') | ||
const util = require('../util/index') | ||
|
||
const exists = util.exists; | ||
const cwd = util.cwd; | ||
const pwd = util.pwd; | ||
const resolve = util.resolve; | ||
const read = util.read; | ||
const exists = util.exists | ||
const cwd = util.cwd | ||
const pwd = util.pwd | ||
const resolve = util.resolve | ||
const read = util.read | ||
|
||
const replace = function(file, tpl, replace) { | ||
fs.writeFileSync(file, read(file).replace(tpl, replace), "utf-8"); | ||
}; | ||
const replace = function (file, tpl, replace) { | ||
fs.writeFileSync(file, read(file).replace(tpl, replace), 'utf-8') | ||
} | ||
|
||
const PKG = util.pkg(); | ||
const PKG = util.pkg() | ||
|
||
module.exports = function(path = "", local, theme) { | ||
module.exports = function (path = '', local, theme) { | ||
const msg = | ||
"\n" + | ||
chalk.green("Initialization succeeded!") + | ||
" Please run " + | ||
'\n' + | ||
chalk.green('Initialization succeeded!') + | ||
' Please run ' + | ||
chalk.inverse(`docsify serve ${path}`) + | ||
"\n"; | ||
'\n' | ||
|
||
path = cwd(path || "."); | ||
const target = file => resolve(path, file); | ||
const readme = exists(cwd("README.md")) || pwd("template/README.md"); | ||
const main = pwd("template/index.html"); | ||
path = cwd(path || '.') | ||
const target = file => resolve(path, file) | ||
const readme = exists(cwd('README.md')) || pwd('template/README.md') | ||
const main = pwd('template/index.html') | ||
|
||
if (local) { | ||
main = pwd("template/index.local.html"); | ||
main = pwd('template/index.local.html') | ||
|
||
const vendor = | ||
exists(cwd("node_modules/docsify")) || pwd("../node_modules/docsify"); | ||
exists(cwd('node_modules/docsify')) || pwd('../node_modules/docsify') | ||
|
||
cp(resolve(vendor, "lib/docsify.min.js"), target("vendor/docsify.js")); | ||
cp(resolve(vendor, 'lib/docsify.min.js'), target('vendor/docsify.js')) | ||
cp( | ||
resolve(vendor, `lib/themes/${theme}.css`), | ||
target(`vendor/themes/${theme}.css`) | ||
); | ||
) | ||
} | ||
const filename = "index.html"; | ||
|
||
cp(readme, target("README.md")); | ||
cp(main, target(filename)); | ||
cp(pwd("template/.nojekyll"), target(".nojekyll")); | ||
const filename = 'index.html' | ||
|
||
replace(target(filename), "vue.css", `${theme}.css`); | ||
cp(readme, target('README.md')) | ||
cp(main, target(filename)) | ||
cp(pwd('template/.nojekyll'), target('.nojekyll')) | ||
|
||
replace(target(filename), 'vue.css', `${theme}.css`) | ||
|
||
if (PKG.name) { | ||
replace( | ||
target(filename), | ||
"Document", | ||
PKG.name + (PKG.description ? " - " + PKG.description : "") | ||
); | ||
replace(target(filename), "name: '',", `name: '${PKG.name}',`); | ||
'Document', | ||
PKG.name + (PKG.description ? ' - ' + PKG.description : '') | ||
) | ||
replace(target(filename), 'name: \'\',', `name: '${PKG.name}',`) | ||
} | ||
|
||
if (PKG.description) { | ||
replace(target(filename), "Description", PKG.description); | ||
replace(target(filename), 'Description', PKG.description) | ||
} | ||
|
||
if (PKG.repository) { | ||
const repo = (PKG.repository.url || PKG.repository) | ||
.replace(/\.git$/g, "") | ||
.replace(/^git\+/g, ""); | ||
replace(target(filename), "repo: ''", `repo: '${repo}'`); | ||
.replace(/\.git$/g, '') | ||
.replace(/^git\+/g, '') | ||
replace(target(filename), 'repo: \'\'', `repo: '${repo}'`) | ||
} | ||
console.log(msg); | ||
}; | ||
|
||
console.log(msg) | ||
} |
Oops, something went wrong.