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

Commit 0de715d

Browse files
authoredOct 28, 2017
feat(test): Update textlint-tester (#4)
* feat(test): Update textlint-tester * style: apply prettier
1 parent a3f7a6d commit 0de715d

File tree

12 files changed

+554
-353
lines changed

12 files changed

+554
-353
lines changed
 

‎bin/cmd.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
#!/usr/bin/env node
2-
var spawn = require('cross-spawn');
2+
var spawn = require("cross-spawn");
33
var script = process.argv[2];
44
var args = process.argv.slice(3);
55

66
switch (script) {
7-
case 'init':
8-
case 'build':
9-
case 'test':
10-
var result = spawn.sync(
11-
'node',
12-
[require.resolve('../scripts/' + script)].concat(args),
13-
{stdio: 'inherit'}
14-
);
7+
case "init":
8+
case "build":
9+
case "test":
10+
var result = spawn.sync("node", [require.resolve("../scripts/" + script)].concat(args), { stdio: "inherit" });
1511
process.exit(result.status);
1612
break;
1713
default:
1814
console.log('Unknown script "' + script + '".');
19-
console.log('Perhaps you need to update textlint-scripts?');
15+
console.log("Perhaps you need to update textlint-scripts?");
2016
break;
21-
}
17+
}

‎configs/babel-register.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"use strict";
2-
require("babel-register")(require("./babelrc"));
2+
require("babel-register")(require("./babelrc"));

‎configs/babelrc.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module.exports = {
2-
"presets": [
3-
"env"
4-
]
2+
presets: ["env"]
53
};

‎example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"scripts" : {
3+
"scripts": {
44
"build": "textlint-scripts build",
55
"test": "textlint-scripts test"
66
},

‎example/src/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"use strict";
22
import assert from "assert";
33
module.exports = function(context, options = {}) {
4-
const {Syntax, RuleError, report, getSource} = context;
4+
const { Syntax, RuleError, report, getSource } = context;
55
return {
6-
[Syntax.Str](node){ // "Str" node
6+
[Syntax.Str](node) {
7+
// "Str" node
78
const text = getSource(text);
89
if (/bugs/.test(text)) {
910
const indexOfBugs = text.search(/bugs/);
@@ -13,5 +14,5 @@ module.exports = function(context, options = {}) {
1314
report(node, ruleError);
1415
}
1516
}
16-
}
17+
};
1718
};

‎example/test/index-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict";
2+
// See https://github.com/textlint/textlint/tree/master/packages/textlint-tester
23
const TextLintTester = require("textlint-tester");
34
const tester = new TextLintTester();
45
// rule
@@ -40,7 +41,6 @@ One more bugs`,
4041
column: 13
4142
}
4243
]
43-
},
44-
44+
}
4545
]
46-
});
46+
});

‎package.json

+25-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"textlint-scripts": "./bin/cmd.js"
1717
},
1818
"scripts": {
19-
"test": "bash test/test-example.sh"
19+
"test": "bash test/test-example.sh",
20+
"prettier": "prettier --write '**/*.{js,jsx,ts,tsx,css}'",
21+
"precommit": "lint-staged",
22+
"postcommit": "git reset"
2023
},
2124
"keywords": [
2225
"textlint"
@@ -29,15 +32,29 @@
2932
"url": "https://github.com/textlint/textlint-scripts/issues"
3033
},
3134
"homepage": "https://github.com/textlint/textlint-scripts",
32-
"devDependencies": {},
35+
"devDependencies": {
36+
"husky": "^0.14.3",
37+
"lint-staged": "^4.3.0",
38+
"prettier": "^1.7.4"
39+
},
3340
"dependencies": {
34-
"babel-cli": "^6.18.0",
35-
"babel-preset-env": "^1.3.2",
36-
"babel-register": "^6.18.0",
41+
"babel-cli": "^6.26.0",
42+
"babel-preset-env": "^1.6.1",
43+
"babel-register": "^6.26.0",
3744
"confirmer": "^1.1.1",
3845
"cross-spawn": "^5.0.1",
39-
"mocha": "^3.1.2",
46+
"mocha": "^4.0.1",
4047
"pkg-to-readme": "^1.1.0",
41-
"textlint-tester": "^2.0.0"
48+
"textlint-tester": "^3.0.1"
49+
},
50+
"prettier": {
51+
"printWidth": 120,
52+
"tabWidth": 4
53+
},
54+
"lint-staged": {
55+
"*.{js,jsx,ts,tsx,css}": [
56+
"prettier --write",
57+
"git add"
58+
]
4259
}
43-
}
60+
}

‎scripts/build.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
// LICENSE : MIT
22
"use strict";
33
// Do this as the first thing so that any code reading it knows the right env.
4-
process.env.NODE_ENV = 'production';
4+
process.env.NODE_ENV = "production";
55

6-
var path = require("path");
76
var spawn = require("cross-spawn");
87
var args = process.argv.slice(2);
9-
var babel = require.resolve('.bin/babel');
8+
var babel = require.resolve(".bin/babel");
109
var babelrc = require("../configs/babelrc");
1110
// babel src --out-dir lib --watch --source-maps
12-
var child = spawn(babel, [
13-
"--presets", babelrc.presets.join(","),
14-
"--source-maps",
15-
"--out-dir", "lib",
16-
"src"
17-
].concat(args));
18-
child.stderr.on('data', function(data) {
11+
var child = spawn(
12+
babel,
13+
["--presets", babelrc.presets.join(","), "--source-maps", "--out-dir", "lib", "src"].concat(args)
14+
);
15+
child.stderr.on("data", function(data) {
1916
process.stderr.write(data);
2017
});
21-
child.stdout.on('data', function(data) {
18+
child.stdout.on("data", function(data) {
2219
process.stdout.write(data);
2320
});
24-
child.on('error', function(error) {
21+
child.on("error", function(error) {
2522
console.error(error);
2623
});
27-
child.on('exit', function(code) {
24+
child.on("exit", function(code) {
2825
process.exit(code);
29-
});
26+
});

‎scripts/init.js

+20-17
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@
22
"use strict";
33
var pkgToReadme = require("pkg-to-readme");
44
var path = require("path");
5-
var confirmer = require('confirmer');
6-
var fs = require('fs');
5+
var confirmer = require("confirmer");
6+
var fs = require("fs");
77
// Update README.md
88
var templatePath = path.resolve(__dirname, "..", "configs", "README.md.template");
9-
Promise.resolve().then(function() {
10-
if (!fs.existsSync(path.resolve('README.md'))) {
11-
return;
12-
}
13-
return confirmer('Would you overwrite README.md? (y/n)')
14-
.then(function(result) {
9+
Promise.resolve()
10+
.then(function() {
11+
if (!fs.existsSync(path.resolve("README.md"))) {
12+
return;
13+
}
14+
return confirmer("Would you overwrite README.md? (y/n)").then(function(result) {
1515
return result ? Promise.resolve() : Promise.reject(new Error("Not overwrite"));
1616
});
17-
}).then(function() {
18-
return pkgToReadme({
19-
template: templatePath
2017
})
21-
}).then(function() {
22-
console.log('Generated README.md');
23-
}).catch(error => {
24-
console.error(error.message);
25-
process.exit(1);
26-
});
18+
.then(function() {
19+
return pkgToReadme({
20+
template: templatePath
21+
});
22+
})
23+
.then(function() {
24+
console.log("Generated README.md");
25+
})
26+
.catch(error => {
27+
console.error(error.message);
28+
process.exit(1);
29+
});

‎scripts/test.js

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
// LICENSE : MIT
22
"use strict";
3-
process.env.NODE_ENV = 'test';
3+
process.env.NODE_ENV = "test";
44
var path = require("path");
55
var spawn = require("cross-spawn");
66
var args = process.argv.slice(2);
7-
var mocha = require.resolve('.bin/mocha');
7+
var mocha = require.resolve(".bin/mocha");
88
// mocha
99
var babelRegisterPath = require.resolve("../configs/babel-register");
10-
var child = spawn(mocha, [
11-
"--require", babelRegisterPath,
12-
"--timeout", "5000",
13-
"--recursive",
14-
"test/"
15-
].concat(args));
10+
var child = spawn(mocha, ["--require", babelRegisterPath, "--timeout", "5000", "--recursive", "test/"].concat(args));
1611

17-
child.stderr.on('data', function(data) {
12+
child.stderr.on("data", function(data) {
1813
process.stderr.write(data);
1914
});
20-
child.stdout.on('data', function(data) {
15+
child.stdout.on("data", function(data) {
2116
process.stdout.write(data);
2217
});
23-
child.on('error', function(error) {
18+
child.on("error", function(error) {
2419
console.error(error);
2520
});
26-
child.on('exit', function(code) {
21+
child.on("exit", function(code) {
2722
process.exit(code);
28-
});
23+
});

‎test/test-example.sh

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ declare parentDir=$(dirname "${currentDir}")
66
declare exampleDir="${parentDir}/example"
77
# init
88
cd "${exampleDir}"
9-
npm uninstall textlint-scripts
109
npm install
1110
npm test
1211
npm run build

0 commit comments

Comments
 (0)
This repository has been archived.