tools: use prettier to format javascript files
This commit is contained in:
parent
20af8d02c7
commit
06dd355e33
@ -1,27 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"es6": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 7,
|
||||
"ecmaFeatures": { "experimentalObjectRestSpread": true }
|
||||
},
|
||||
"rules": {
|
||||
"linebreak-style": [ "error", "unix" ],
|
||||
"no-console": "off",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-var": "error",
|
||||
"prefer-const": "error",
|
||||
"quotes": [ "error", "single" ],
|
||||
"semi": [ "error", "always" ],
|
||||
"indent": [ "error", 2, {
|
||||
"ArrayExpression": "first",
|
||||
"ObjectExpression": "first",
|
||||
"FunctionExpression": { "parameters": "first" },
|
||||
"FunctionDeclaration": { "parameters": "first" },
|
||||
"CallExpression": { "arguments": "first" }
|
||||
}]
|
||||
}
|
||||
}
|
||||
5
.prettierrc.json
Normal file
5
.prettierrc.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"endOfLine": "lf",
|
||||
"proseWrap": "always",
|
||||
"singleQuote": true
|
||||
}
|
||||
@ -9,23 +9,23 @@ const files = [];
|
||||
const includeDirs = [];
|
||||
let stripGuardsEnabled = false;
|
||||
|
||||
process.argv
|
||||
.slice(2)
|
||||
.forEach(arg => {
|
||||
process.argv.slice(2).forEach(arg => {
|
||||
let match;
|
||||
if ((match = /^-I(.*)$/.exec(arg)))
|
||||
if ((match = /^-I(.*)$/.exec(arg))) {
|
||||
includeDirs.push(match[1]);
|
||||
else if (arg === '--strip-guards')
|
||||
} else if (arg === '--strip-guards') {
|
||||
stripGuardsEnabled = true;
|
||||
else
|
||||
} else {
|
||||
files.push(arg);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const included = {};
|
||||
|
||||
function readFileWithPath(fileName, dirs) {
|
||||
if (/[/\\]/.test(fileName))
|
||||
if (/[/\\]/.test(fileName)) {
|
||||
return fs.readFileSync(fileName, 'utf8');
|
||||
}
|
||||
|
||||
for (let i = 0; i < dirs.length; i++) {
|
||||
const filePath = path.resolve(dirs[i], fileName);
|
||||
@ -70,14 +70,17 @@ function strip_guards(filename, source) {
|
||||
|
||||
function lines(filename, strip) {
|
||||
let source = readFileWithPath(filename, ['.'].concat(includeDirs));
|
||||
if (strip) source = strip_guards(filename, source);
|
||||
if (strip) {
|
||||
source = strip_guards(filename, source);
|
||||
}
|
||||
return source.split(/\r?\n/g);
|
||||
}
|
||||
|
||||
function include(line, filename) {
|
||||
const key = path.basename(filename).toLowerCase();
|
||||
if (included[key])
|
||||
if (included[key]) {
|
||||
return ''; // Included earlier.
|
||||
}
|
||||
console.error('Including: ' + key);
|
||||
included[key] = true;
|
||||
return lines(filename, true);
|
||||
@ -93,16 +96,19 @@ function add(filename) {
|
||||
const sys_included = {};
|
||||
function include_sys(line, filename) {
|
||||
const key = path.basename(filename).toLowerCase();
|
||||
if (sys_included[key])
|
||||
if (sys_included[key]) {
|
||||
return ''; // Included earlier.
|
||||
|
||||
}
|
||||
sys_included[key] = true;
|
||||
}
|
||||
|
||||
let source = [];
|
||||
|
||||
source = source.concat('/*')
|
||||
.concat(fs.readFileSync('LICENSE', 'utf8')
|
||||
source = source
|
||||
.concat('/*')
|
||||
.concat(
|
||||
fs
|
||||
.readFileSync('LICENSE', 'utf8')
|
||||
.replace(/^\s+|\s+$/g, '')
|
||||
.split(/\r?\n/g)
|
||||
.map(line => ' * ' + line)
|
||||
@ -121,7 +127,7 @@ const patterns = [
|
||||
{ re: /^\s*#include\s*<([^"]*)>.*$/, fn: include_sys }
|
||||
];
|
||||
|
||||
restart: for (let lno = 0; lno < source.length;) {
|
||||
restart: for (let lno = 0; lno < source.length; ) {
|
||||
for (const i in patterns) {
|
||||
const line = source[lno];
|
||||
const pattern = patterns[i];
|
||||
|
||||
@ -42,12 +42,14 @@ const distTree = getSHA(stdout);
|
||||
|
||||
exec('git reset');
|
||||
|
||||
// prettier-ignore
|
||||
stdout = exec(`git commit-tree -S ${distTree} ` +
|
||||
`-p ${previousTagCommit} ` +
|
||||
`-p ${sourceCommit} ` +
|
||||
`-m "version ${version}"`, utf8);
|
||||
const distCommit = getSHA(stdout);
|
||||
|
||||
// prettier-ignore
|
||||
stdout = exec(`git commit-tree -S ${sourceTree} ` +
|
||||
`-p ${sourceCommit} ` +
|
||||
`-p ${distCommit} ` +
|
||||
@ -60,6 +62,7 @@ console.log('');
|
||||
console.log(`Previous release tag: ${previousTag}`);
|
||||
console.log(`New release tag ${distTag}`);
|
||||
|
||||
// prettier-ignore
|
||||
exec(`git tag ${distTag} ${distCommit} ` +
|
||||
`-sm "version ${version}"`, inherit);
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
const spawn = require('child_process').spawn;
|
||||
const basename = require('path').basename;
|
||||
|
||||
@ -6,21 +5,22 @@ const test_exes = process.argv.slice(2);
|
||||
run_tests(test_exes);
|
||||
|
||||
function run_tests(test_exes, num = 0, fail_count = 0) {
|
||||
if (test_exes.length <= num)
|
||||
if (test_exes.length <= num) {
|
||||
return done(test_exes, fail_count);
|
||||
}
|
||||
|
||||
const test_exe = test_exes[num];
|
||||
const test_name = basename(test_exe, '.exe');
|
||||
|
||||
console.log('(%d/%d) %s...', (num + 1), test_exes.length, test_name);
|
||||
console.log('(%d/%d) %s...', num + 1, test_exes.length, test_name);
|
||||
|
||||
const child = spawn(test_exe, [], { encoding: 'utf8' });
|
||||
|
||||
let out = '';
|
||||
child.stdout.on('data', (data) => out += data);
|
||||
child.stderr.on('data', (data) => out += data);
|
||||
child.stdout.on('data', data => (out += data));
|
||||
child.stderr.on('data', data => (out += data));
|
||||
|
||||
child.on('exit', (code) => {
|
||||
child.on('exit', code => {
|
||||
if (code === 0) {
|
||||
console.log(' PASS');
|
||||
} else {
|
||||
@ -38,4 +38,3 @@ function done(test_exes, fail_count) {
|
||||
|
||||
process.exit(fail_count == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user