Skip to content

Commit 518b3ef

Browse files
fix: lint codebase
1 parent 0305fd7 commit 518b3ef

File tree

9 files changed

+251
-247
lines changed

9 files changed

+251
-247
lines changed

e2e/index.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
'use strict';
1+
'use strict'
22

3-
const path = require('path');
4-
const execa = require('execa');
5-
const test = require('ava');
3+
const path = require('path')
4+
const execa = require('execa')
5+
const test = require('ava')
66

7-
const rootCommand = path.join(process.cwd(), 'bin/docsify');
7+
const rootCommand = path.join(process.cwd(), 'bin/docsify')
88

99
test('shows up help message without any args', async t => {
10-
const { stderr } = await execa(rootCommand, {reject: false});
11-
t.snapshot(stderr);
12-
});
10+
const {stderr} = await execa(rootCommand, {reject: false})
11+
t.snapshot(stderr)
12+
})
1313

1414
const matchSnapshot = async (t, arg) => {
15-
const { stdout } = await execa(rootCommand, [arg]);
16-
t.snapshot(stdout);
17-
};
15+
const {stdout} = await execa(rootCommand, [arg])
16+
t.snapshot(stdout)
17+
}
1818

19-
test('shows help with -h flag', matchSnapshot, '-h');
20-
test('shows help with --help flag', matchSnapshot, '--help');
21-
test('shows version information with -v flag', matchSnapshot, '-v');
22-
test('shows version information with --version flag', matchSnapshot, '--version');
19+
test('shows help with -h flag', matchSnapshot, '-h')
20+
test('shows help with --help flag', matchSnapshot, '--help')
21+
test('shows version information with -v flag', matchSnapshot, '-v')
22+
test('shows version information with --version flag', matchSnapshot, '--version')

lib/cli.js

+62-62
Original file line numberDiff line numberDiff line change
@@ -1,126 +1,126 @@
1-
const chalk = require("chalk");
2-
const updateNotifier = require("update-notifier");
1+
const chalk = require('chalk')
2+
const updateNotifier = require('update-notifier')
33

4-
const pkg = require("../package.json");
5-
const run = require("../lib");
4+
const pkg = require('../package.json')
5+
const run = require('../lib')
66

7-
updateNotifier({ pkg: pkg }).notify();
7+
updateNotifier({pkg: pkg}).notify()
88

9-
const Locales = require("../tools/locales");
10-
const y18n = new Locales();
9+
const Locales = require('../tools/locales')
10+
const y18n = new Locales()
1111

12-
require("yargonaut")
13-
.style("yellow", "required")
14-
.helpStyle("green")
15-
.errorsStyle("red.bold");
12+
require('yargonaut')
13+
.style('yellow', 'required')
14+
.helpStyle('green')
15+
.errorsStyle('red.bold')
1616

17-
const yargs = require("yargs")
18-
.demandCommand(1, chalk.red("[ERROR] 0 arguments passed. Please specify a command"))
17+
const yargs = require('yargs')
18+
.demandCommand(1, chalk.red('[ERROR] 0 arguments passed. Please specify a command'))
1919
.strict()
2020
.recommendCommands()
21-
.usage(chalk.bold(y18n.__("usage") + ": docsify <init|serve> <path>"))
21+
.usage(chalk.bold(y18n.__('usage') + ': docsify <init|serve> <path>'))
2222
.command({
23-
command: "init [path]",
24-
alias: "i",
25-
desc: chalk.gray(y18n.__("init")),
23+
command: 'init [path]',
24+
alias: 'i',
25+
desc: chalk.gray(y18n.__('init')),
2626
builder: yargs =>
2727
yargs.options({
2828
local: {
29-
alias: "l",
29+
alias: 'l',
3030
default: false,
31-
desc: chalk.gray(y18n.__("init.local")),
31+
desc: chalk.gray(y18n.__('init.local')),
3232
nargs: 0,
3333
requiresArg: false,
34-
type: "boolean"
34+
type: 'boolean'
3535
},
3636
theme: {
37-
alias: "t",
38-
default: "vue",
39-
desc: chalk.gray(y18n.__("init.theme")),
40-
choices: ["vue", "buble", "dark", "pure"],
37+
alias: 't',
38+
default: 'vue',
39+
desc: chalk.gray(y18n.__('init.theme')),
40+
choices: ['vue', 'buble', 'dark', 'pure'],
4141
nargs: 1,
4242
requiresArg: true,
43-
type: "string"
43+
type: 'string'
4444
}
4545
}),
4646
handler: argv => run.init(argv.path, argv.local, argv.theme)
4747
})
4848
.command({
49-
command: "serve [path]",
50-
alias: "s",
51-
desc: chalk.gray(y18n.__("serve")),
49+
command: 'serve [path]',
50+
alias: 's',
51+
desc: chalk.gray(y18n.__('serve')),
5252
builder: yargs =>
5353
yargs.options({
5454
open: {
55-
alias: "o",
55+
alias: 'o',
5656
default: false,
57-
desc: chalk.gray(y18n.__("serve.open")),
57+
desc: chalk.gray(y18n.__('serve.open')),
5858
nargs: 0,
5959
requiresArg: false,
60-
type: "boolean"
60+
type: 'boolean'
6161
},
6262
port: {
63-
alias: "p",
63+
alias: 'p',
6464
default: 3000,
65-
desc: chalk.gray(y18n.__("serve.port")),
65+
desc: chalk.gray(y18n.__('serve.port')),
6666
nargs: 1,
6767
requiresArg: true,
68-
type: "number"
68+
type: 'number'
6969
},
70-
"livereload-port": {
71-
alias: "P",
70+
'livereload-port': {
71+
alias: 'P',
7272
default: 35729,
73-
desc: chalk.gray(y18n.__("livereload.port")),
73+
desc: chalk.gray(y18n.__('livereload.port')),
7474
nargs: 1,
7575
requiresArg: true,
76-
type: "number"
76+
type: 'number'
7777
},
78-
"index-name": {
79-
alias: "i",
80-
desc: chalk.gray(y18n.__("serve.indexname")),
78+
'index-name': {
79+
alias: 'i',
80+
desc: chalk.gray(y18n.__('serve.indexname')),
8181
nargs: 1,
8282
requiresArg: true,
83-
type: "string"
83+
type: 'string'
8484
}
8585
}),
8686
handler: argv => run.serve(argv.path, argv.open, argv.port, argv.P, argv.i)
8787
})
8888
.command({
89-
command: "start <path>",
90-
desc: chalk.gray(y18n.__("start")),
89+
command: 'start <path>',
90+
desc: chalk.gray(y18n.__('start')),
9191
builder: yargs =>
9292
yargs.options({
9393
config: {
94-
alias: "c",
94+
alias: 'c',
9595
default: false,
96-
desc: chalk.gray(y18n.__("start.config")),
96+
desc: chalk.gray(y18n.__('start.config')),
9797
nargs: 0,
9898
requiresArg: false,
99-
type: "string"
99+
type: 'string'
100100
},
101101
port: {
102-
alias: "p",
102+
alias: 'p',
103103
default: 4000,
104-
desc: chalk.gray(y18n.__("start.port")),
104+
desc: chalk.gray(y18n.__('start.port')),
105105
nargs: 1,
106106
requiresArg: true,
107-
type: "number"
107+
type: 'number'
108108
}
109109
}),
110110
handler: argv => run.start(argv.path, argv.config, argv.port)
111111
})
112112
.help()
113-
.option("help", {
114-
alias: "h",
115-
type: "boolean",
116-
desc: chalk.gray(y18n.__("help")),
117-
group: chalk.green(y18n.__("group.globaloptions"))
113+
.option('help', {
114+
alias: 'h',
115+
type: 'boolean',
116+
desc: chalk.gray(y18n.__('help')),
117+
group: chalk.green(y18n.__('group.globaloptions'))
118118
})
119-
.version("\ndocsify-cli version:\n " + pkg.version + "\n")
120-
.option("version", {
121-
alias: "v",
122-
type: "boolean",
123-
desc: chalk.gray(y18n.__("version")),
124-
group: chalk.green(y18n.__("group.globaloptions"))
119+
.version('\ndocsify-cli version:\n ' + pkg.version + '\n')
120+
.option('version', {
121+
alias: 'v',
122+
type: 'boolean',
123+
desc: chalk.gray(y18n.__('version')),
124+
group: chalk.green(y18n.__('group.globaloptions'))
125125
})
126-
.epilog(chalk.gray(y18n.__("epilog"))).argv;
126+
.epilog(chalk.gray(y18n.__('epilog'))).argv

lib/commands/init.js

+46-42
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,75 @@
1-
"use strict";
1+
'use strict'
22

3-
const fs = require("fs");
4-
const cp = require("cp-file").sync;
5-
const chalk = require("chalk");
6-
const util = require("../util/index");
3+
const fs = require('fs')
4+
const cp = require('cp-file').sync
5+
const chalk = require('chalk')
6+
const util = require('../util/index')
77

8-
const exists = util.exists;
9-
const cwd = util.cwd;
10-
const pwd = util.pwd;
11-
const resolve = util.resolve;
12-
const read = util.read;
8+
const exists = util.exists
9+
const cwd = util.cwd
10+
const pwd = util.pwd
11+
const resolve = util.resolve
12+
const read = util.read
1313

14-
const replace = function(file, tpl, replace) {
15-
fs.writeFileSync(file, read(file).replace(tpl, replace), "utf-8");
16-
};
14+
const replace = function (file, tpl, replace) {
15+
fs.writeFileSync(file, read(file).replace(tpl, replace), 'utf-8')
16+
}
1717

18-
const PKG = util.pkg();
18+
const PKG = util.pkg()
1919

20-
module.exports = function(path = "", local, theme) {
20+
module.exports = function (path = '', local, theme) {
2121
const msg =
22-
"\n" +
23-
chalk.green("Initialization succeeded!") +
24-
" Please run " +
22+
'\n' +
23+
chalk.green('Initialization succeeded!') +
24+
' Please run ' +
2525
chalk.inverse(`docsify serve ${path}`) +
26-
"\n";
26+
'\n'
2727

28-
path = cwd(path || ".");
29-
const target = file => resolve(path, file);
30-
const readme = exists(cwd("README.md")) || pwd("template/README.md");
31-
const main = pwd("template/index.html");
28+
path = cwd(path || '.')
29+
const target = file => resolve(path, file)
30+
const readme = exists(cwd('README.md')) || pwd('template/README.md')
31+
const main = pwd('template/index.html')
3232

3333
if (local) {
34-
main = pwd("template/index.local.html");
34+
main = pwd('template/index.local.html')
3535

3636
const vendor =
37-
exists(cwd("node_modules/docsify")) || pwd("../node_modules/docsify");
37+
exists(cwd('node_modules/docsify')) || pwd('../node_modules/docsify')
3838

39-
cp(resolve(vendor, "lib/docsify.min.js"), target("vendor/docsify.js"));
39+
cp(resolve(vendor, 'lib/docsify.min.js'), target('vendor/docsify.js'))
4040
cp(
4141
resolve(vendor, `lib/themes/${theme}.css`),
4242
target(`vendor/themes/${theme}.css`)
43-
);
43+
)
4444
}
45-
const filename = "index.html";
4645

47-
cp(readme, target("README.md"));
48-
cp(main, target(filename));
49-
cp(pwd("template/.nojekyll"), target(".nojekyll"));
46+
const filename = 'index.html'
5047

51-
replace(target(filename), "vue.css", `${theme}.css`);
48+
cp(readme, target('README.md'))
49+
cp(main, target(filename))
50+
cp(pwd('template/.nojekyll'), target('.nojekyll'))
51+
52+
replace(target(filename), 'vue.css', `${theme}.css`)
5253

5354
if (PKG.name) {
5455
replace(
5556
target(filename),
56-
"Document",
57-
PKG.name + (PKG.description ? " - " + PKG.description : "")
58-
);
59-
replace(target(filename), "name: '',", `name: '${PKG.name}',`);
57+
'Document',
58+
PKG.name + (PKG.description ? ' - ' + PKG.description : '')
59+
)
60+
replace(target(filename), 'name: \'\',', `name: '${PKG.name}',`)
6061
}
62+
6163
if (PKG.description) {
62-
replace(target(filename), "Description", PKG.description);
64+
replace(target(filename), 'Description', PKG.description)
6365
}
66+
6467
if (PKG.repository) {
6568
const repo = (PKG.repository.url || PKG.repository)
66-
.replace(/\.git$/g, "")
67-
.replace(/^git\+/g, "");
68-
replace(target(filename), "repo: ''", `repo: '${repo}'`);
69+
.replace(/\.git$/g, '')
70+
.replace(/^git\+/g, '')
71+
replace(target(filename), 'repo: \'\'', `repo: '${repo}'`)
6972
}
70-
console.log(msg);
71-
};
73+
74+
console.log(msg)
75+
}

0 commit comments

Comments
 (0)