2015-11-24 18:09:31 +00:00
|
|
|
/*---------------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
|
2020-09-22 12:37:04 +00:00
|
|
|
const gulp = require('gulp');
|
|
|
|
const filter = require('gulp-filter');
|
|
|
|
const es = require('event-stream');
|
|
|
|
const gulpeslint = require('gulp-eslint');
|
|
|
|
const vfs = require('vinyl-fs');
|
|
|
|
const path = require('path');
|
|
|
|
const task = require('./lib/task');
|
|
|
|
const { all, jsHygieneFilter, tsHygieneFilter, hygiene } = require('./hygiene');
|
2020-09-22 09:12:35 +00:00
|
|
|
|
2020-09-22 12:37:04 +00:00
|
|
|
gulp.task('eslint', () => {
|
2020-09-22 09:12:35 +00:00
|
|
|
return vfs
|
2020-09-22 12:37:04 +00:00
|
|
|
.src(all, { base: '.', follow: true, allowEmpty: true })
|
2020-01-03 08:01:41 +00:00
|
|
|
.pipe(filter(jsHygieneFilter.concat(tsHygieneFilter)))
|
2020-09-22 09:12:35 +00:00
|
|
|
.pipe(
|
|
|
|
gulpeslint({
|
2020-09-22 12:37:04 +00:00
|
|
|
configFile: '.eslintrc.json',
|
|
|
|
rulePaths: ['./build/lib/eslint'],
|
2020-09-22 09:12:35 +00:00
|
|
|
})
|
|
|
|
)
|
2020-09-22 12:37:04 +00:00
|
|
|
.pipe(gulpeslint.formatEach('compact'))
|
2020-09-22 09:12:35 +00:00
|
|
|
.pipe(
|
|
|
|
gulpeslint.results((results) => {
|
|
|
|
if (results.warningCount > 0 || results.errorCount > 0) {
|
2020-09-22 12:37:04 +00:00
|
|
|
throw new Error('eslint failed with warnings and/or errors');
|
2020-09-22 09:12:35 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
);
|
2017-06-20 14:21:44 +00:00
|
|
|
});
|
2016-02-18 15:02:16 +00:00
|
|
|
|
2019-09-11 14:49:49 +00:00
|
|
|
function checkPackageJSON(actualPath) {
|
2020-09-22 12:37:04 +00:00
|
|
|
const actual = require(path.join(__dirname, '..', actualPath));
|
|
|
|
const rootPackageJSON = require('../package.json');
|
2019-09-11 14:49:49 +00:00
|
|
|
|
|
|
|
for (let depName in actual.dependencies) {
|
|
|
|
const depVersion = actual.dependencies[depName];
|
|
|
|
const rootDepVersion = rootPackageJSON.dependencies[depName];
|
|
|
|
if (!rootDepVersion) {
|
|
|
|
// missing in root is allowed
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (depVersion !== rootDepVersion) {
|
2020-09-22 09:12:35 +00:00
|
|
|
this.emit(
|
2020-09-22 12:37:04 +00:00
|
|
|
'error',
|
2020-09-22 09:12:35 +00:00
|
|
|
`The dependency ${depName} in '${actualPath}' (${depVersion}) is different than in the root package.json (${rootDepVersion})`
|
|
|
|
);
|
2019-09-11 14:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-22 12:37:04 +00:00
|
|
|
const checkPackageJSONTask = task.define('check-package-json', () => {
|
|
|
|
return gulp.src('package.json').pipe(
|
2020-09-22 09:12:35 +00:00
|
|
|
es.through(function () {
|
2020-09-22 12:37:04 +00:00
|
|
|
checkPackageJSON.call(this, 'remote/package.json');
|
|
|
|
checkPackageJSON.call(this, 'remote/web/package.json');
|
2020-09-22 09:12:35 +00:00
|
|
|
})
|
|
|
|
);
|
2019-09-11 14:49:49 +00:00
|
|
|
});
|
|
|
|
gulp.task(checkPackageJSONTask);
|
|
|
|
|
2020-09-22 09:12:35 +00:00
|
|
|
gulp.task(
|
2020-09-22 12:37:04 +00:00
|
|
|
'hygiene',
|
2020-09-22 09:12:35 +00:00
|
|
|
task.series(checkPackageJSONTask, () => hygiene())
|
|
|
|
);
|