提交 71c01821 编写于 作者: J Joao Moreno

use git index in hygiene

上级 50810920
......@@ -12,9 +12,11 @@ const gulptslint = require('gulp-tslint');
const gulpeslint = require('gulp-eslint');
const tsfmt = require('typescript-formatter');
const tslint = require('tslint');
const VinylFile = require('vinyl');
const vfs = require('vinyl-fs');
const path = require('path');
const fs = require('fs');
const pall = require('p-all');
/**
* Hygiene works by creating cascading subsets of all our files and
......@@ -157,7 +159,7 @@ gulp.task('tslint', () => {
.pipe(gulptslint.default.report(options));
});
const hygiene = exports.hygiene = (some, options) => {
function hygiene(some, options) {
options = options || {};
let errorCount = 0;
......@@ -279,7 +281,15 @@ const hygiene = exports.hygiene = (some, options) => {
this.emit('data', file);
});
const result = vfs.src(some || all, { base: '.', follow: true, allowEmpty: true })
let input;
if (Array.isArray(some) || typeof some === 'string' || !some) {
input = vfs.src(some || all, { base: '.', follow: true, allowEmpty: true });
} else {
input = some;
}
const result = input
.pipe(filter(f => !f.stat.isDirectory()))
.pipe(filter(eolFilter))
.pipe(options.skipEOL ? es.through() : eol)
......@@ -331,9 +341,39 @@ const hygiene = exports.hygiene = (some, options) => {
this.emit('end');
}
}));
};
}
function createGitIndexVinyls(paths) {
const cp = require('child_process');
const repositoryPath = process.cwd();
const fns = paths.map(relativePath => () => new Promise((c, e) => {
const fullPath = path.join(repositoryPath, relativePath);
fs.stat(fullPath, (err, stat) => {
if (err) {
return e(err);
}
cp.exec(`git show :${relativePath}`, { maxBuffer: 2000 * 1024, encoding: 'buffer' }, (err, out) => {
if (err) {
return e(err);
}
c(new VinylFile({
path: fullPath,
base: repositoryPath,
contents: out,
stat
}));
});
});
}));
return pall(fns, { concurrency: 4 });
}
gulp.task('hygiene', () => hygiene(''));
gulp.task('hygiene', () => hygiene());
// this allows us to run hygiene as a git pre-commit hook
if (require.main === module) {
......@@ -360,6 +400,7 @@ if (require.main === module) {
console.error();
console.error(err);
process.exit(1);
return;
}
const some = out
......@@ -367,11 +408,17 @@ if (require.main === module) {
.filter(l => !!l);
if (some.length > 0) {
hygiene(some, { skipEOL: skipEOL }).on('error', err => {
console.error();
console.error(err);
process.exit(1);
});
console.log('Reading git index versions...');
createGitIndexVinyls(some)
.then(vinyls => new Promise((c, e) => hygiene(es.readArray(vinyls), { skipEOL: skipEOL })
.on('end', () => c())
.on('error', e)))
.catch(err => {
console.error();
console.error(err);
process.exit(1);
});
}
});
});
......
......@@ -104,6 +104,7 @@
"mocha": "^2.2.5",
"object-assign": "^4.0.1",
"optimist": "0.3.5",
"p-all": "^1.0.0",
"pump": "^1.0.1",
"queue": "3.0.6",
"remap-istanbul": "^0.6.4",
......
......@@ -4160,6 +4160,12 @@ osenv@^0.1.3:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"
p-all@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-all/-/p-all-1.0.0.tgz#93bdf53a55a23821fdfa98b4174a99bf7f31df8d"
dependencies:
p-map "^1.0.0"
p-finally@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
......@@ -4176,6 +4182,10 @@ p-locate@^2.0.0:
dependencies:
p-limit "^1.1.0"
p-map@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/p-map/-/p-map-1.2.0.tgz#e4e94f311eabbc8633a1e79908165fca26241b6b"
p-try@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册