Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 4991393

Browse files
committed
style: setup lint and format
1 parent 296b574 commit 4991393

File tree

9 files changed

+357
-114
lines changed

9 files changed

+357
-114
lines changed

Diff for: .eslintrc.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
root: true,
3+
4+
env: {
5+
node: true,
6+
es6: true
7+
},
8+
9+
extends: ['plugin:prettier/recommended'],
10+
11+
rules: {
12+
'no-undef': ['error']
13+
}
14+
};

Diff for: .prettierrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
singleQuote: true,
3+
tabWidth: 2,
4+
}

Diff for: cli.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
const {existsSync} = require('fs');
4-
const {join} = require('path');
3+
const { existsSync } = require('fs');
4+
const { join } = require('path');
55
const yParser = require('yargs-parser');
66
const semver = require('semver');
77
const chalk = require('chalk');
@@ -11,22 +11,22 @@ const run = require('./lib/run');
1111
const args = yParser(process.argv.slice(2));
1212

1313
if (args.v || args.version) {
14-
console.log(require('./package').version);
15-
if (existsSync(join(__dirname, '.local'))) {
16-
console.log(chalk.cyan('@local'));
17-
}
18-
process.exit(0);
14+
console.log(require('./package').version);
15+
if (existsSync(join(__dirname, '.local'))) {
16+
console.log(chalk.cyan('@local'));
17+
}
18+
process.exit(0);
1919
}
2020

2121
if (!semver.satisfies(process.version, '>= 8.0.0')) {
22-
console.error(
23-
chalk.red('✘ The generator will only work with Node v8.0.0 and up!')
24-
);
25-
process.exit(1);
22+
console.error(
23+
chalk.red('✘ The generator will only work with Node v8.0.0 and up!')
24+
);
25+
process.exit(1);
2626
}
2727

2828
const name = args._[0] || '';
2929
run({
30-
name,
31-
args
30+
name,
31+
args
3232
});

Diff for: lib/BasicGenerator.js

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
const {statSync} = require('fs');
2-
const {basename} = require('path');
1+
const { statSync } = require('fs');
2+
const { basename } = require('path');
33
const Generator = require('yeoman-generator');
44
const glob = require('glob');
55
const debug = require('debug')('create-vuepress:BasicGenerator');
66

77
function noop() {
8-
return true;
8+
return true;
99
}
1010

1111
class BasicGenerator extends Generator {
12-
constructor(opts) {
13-
super(opts);
14-
this.opts = opts;
15-
this.name = basename(opts.env.cwd);
16-
}
12+
constructor(opts) {
13+
super(opts);
14+
this.opts = opts;
15+
this.name = basename(opts.env.cwd);
16+
}
1717

18-
isTsFile(f) {
19-
return (
20-
f.endsWith('.ts') ||
21-
f.endsWith('.tsx') ||
22-
['tsconfig.json', 'tslint.yml'].includes(f)
23-
);
24-
}
18+
isTsFile(f) {
19+
return (
20+
f.endsWith('.ts') ||
21+
f.endsWith('.tsx') ||
22+
['tsconfig.json', 'tslint.yml'].includes(f)
23+
);
24+
}
2525

26-
writeFiles({context, filterFiles = noop}) {
27-
debug(`context: ${JSON.stringify(context)}`);
28-
glob
29-
.sync('**/*', {
30-
cwd: this.templatePath(),
31-
dot: true
32-
})
33-
.filter(filterFiles)
34-
.forEach(file => {
35-
debug(`copy ${file}`);
36-
const filePath = this.templatePath(file);
37-
if (statSync(filePath).isFile()) {
38-
this.fs.copyTpl(
39-
this.templatePath(filePath),
40-
this.destinationPath(file.replace(/^_/, '.')),
41-
context
42-
);
43-
}
44-
});
45-
}
26+
writeFiles({ context, filterFiles = noop }) {
27+
debug(`context: ${JSON.stringify(context)}`);
28+
glob
29+
.sync('**/*', {
30+
cwd: this.templatePath(),
31+
dot: true
32+
})
33+
.filter(filterFiles)
34+
.forEach(file => {
35+
debug(`copy ${file}`);
36+
const filePath = this.templatePath(file);
37+
if (statSync(filePath).isFile()) {
38+
this.fs.copyTpl(
39+
this.templatePath(filePath),
40+
this.destinationPath(file.replace(/^_/, '.')),
41+
context
42+
);
43+
}
44+
});
45+
}
4646
}
4747

4848
module.exports = BasicGenerator;

Diff for: lib/generators/blog/index.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
const BasicGenerator = require('../../BasicGenerator');
22

33
class Generator extends BasicGenerator {
4-
prompting() {
5-
const prompts = [
6-
{
7-
name: 'name',
8-
message: `What's the name of your project?`,
9-
default: this.name
10-
},
11-
{
12-
name: 'description',
13-
message: `What's the description of your project?`
14-
},
15-
{
16-
name: 'mail',
17-
message: `What's your email?`
18-
},
19-
{
20-
name: 'author',
21-
message: `What's your name?`
22-
},
23-
{
24-
name: 'repo',
25-
message: `What's the repo of your project?`
26-
}
27-
];
28-
return this.prompt(prompts).then(props => {
29-
this.prompts = props;
30-
});
31-
}
4+
prompting() {
5+
const prompts = [
6+
{
7+
name: 'name',
8+
message: `What's the name of your project?`,
9+
default: this.name
10+
},
11+
{
12+
name: 'description',
13+
message: `What's the description of your project?`
14+
},
15+
{
16+
name: 'mail',
17+
message: `What's your email?`
18+
},
19+
{
20+
name: 'author',
21+
message: `What's your name?`
22+
},
23+
{
24+
name: 'repo',
25+
message: `What's the repo of your project?`
26+
}
27+
];
28+
return this.prompt(prompts).then(props => {
29+
this.prompts = props;
30+
});
31+
}
3232

33-
writing() {
34-
this.writeFiles({
35-
context: this.prompts,
36-
filterFiles: () => {
37-
return true;
38-
}
39-
});
40-
}
33+
writing() {
34+
this.writeFiles({
35+
context: this.prompts,
36+
filterFiles: () => {
37+
return true;
38+
}
39+
});
40+
}
4141
}
4242

4343
module.exports = Generator;

Diff for: lib/generators/docs/index.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
const BasicGenerator = require("../../BasicGenerator");
1+
const BasicGenerator = require('../../BasicGenerator');
22

33
class Generator extends BasicGenerator {
44
prompting() {
55
const prompts = [
66
{
7-
name: "name",
7+
name: 'name',
88
message: `What's the name of your project?`,
99
default: this.name
1010
},
1111
{
12-
name: "description",
12+
name: 'description',
1313
message: `What's the description of your project?`
1414
},
1515
{
16-
name: "mail",
16+
name: 'mail',
1717
message: `What's your email?`
1818
},
1919
{
20-
name: "author",
20+
name: 'author',
2121
message: `What's your name?`
2222
},
2323
{
24-
name: "repo",
24+
name: 'repo',
2525
message: `What's the repo of your project?`
2626
}
2727
];

Diff for: lib/run.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const fs = require("fs");
2-
const path = require("path");
3-
const chalk = require("chalk");
4-
const mkdirp = require("mkdirp");
5-
const inquirer = require("inquirer");
6-
const clipboardy = require("clipboardy");
1+
const fs = require('fs');
2+
const path = require('path');
3+
const chalk = require('chalk');
4+
const mkdirp = require('mkdirp');
5+
const inquirer = require('inquirer');
6+
const clipboardy = require('clipboardy');
77

8-
const sequences = ["docs", "blog"];
8+
const sequences = ['docs', 'blog'];
99

1010
const generators = fs
1111
.readdirSync(`${__dirname}/generators`)
12-
.filter(f => !f.startsWith("."))
12+
.filter(f => !f.startsWith('.'))
1313
.sort((previous, next) =>
1414
sequences.indexOf(previous) > sequences.indexOf(next) ? 1 : -1
1515
)
@@ -23,9 +23,9 @@ const generators = fs
2323
};
2424
});
2525

26-
const runGenerator = async (
26+
const runGenerator = (
2727
generatorPath,
28-
{ name = "", cwd = process.cwd(), args = {} }
28+
{ name = '', cwd = process.cwd(), args = {} }
2929
) => {
3030
return new Promise(resolve => {
3131
if (name) {
@@ -47,17 +47,17 @@ const runGenerator = async (
4747
if (name) {
4848
if (process.platform !== `linux` || process.env.DISPLAY) {
4949
clipboardy.writeSync(`cd ${name}`);
50-
console.log("📋 Copied to clipboard, just use Ctrl+V");
50+
console.log('📋 Copied to clipboard, just use Ctrl+V');
5151
}
5252
}
5353

54-
console.log("✨ File Generate Done");
54+
console.log('✨ File Generate Done');
5555
resolve(true);
5656
});
5757
});
5858
};
5959

60-
const run = async config => {
60+
const run = config => {
6161
return inquirer
6262
.prompt([
6363
{

Diff for: package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"bin": {
1111
"create-vuepress-site": "cli.js"
1212
},
13-
"scripts": {},
13+
"scripts": {
14+
"lint": "eslint . --ext .js"
15+
},
1416
"repository": {
1517
"url": "vuepressjs/create-vuepress-site",
1618
"type": "git"
@@ -33,6 +35,9 @@
3335
"yeoman-generator": "^4.0.1"
3436
},
3537
"devDependencies": {
38+
"eslint": "^7.11.0",
39+
"eslint-config-prettier": "^6.12.0",
40+
"eslint-plugin-prettier": "^3.1.4",
3641
"husky": "1.3.1",
3742
"lint-staged": "8.1.0"
3843
},
@@ -43,6 +48,7 @@
4348
},
4449
"lint-staged": {
4550
"*.js": [
51+
"eslint --fix",
4652
"git add"
4753
]
4854
},

0 commit comments

Comments
 (0)