vscode/build/gulpfile.hygiene.js

69 lines
2.1 KiB
JavaScript
Raw Normal View History

2015-11-24 19:09:31 +01: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 14:37:04 +02: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 11:12:35 +02:00
2020-09-22 14:37:04 +02:00
gulp.task('eslint', () => {
2020-09-22 11:12:35 +02:00
return vfs
2020-09-22 14:37:04 +02:00
.src(all, { base: '.', follow: true, allowEmpty: true })
2020-01-03 09:01:41 +01:00
.pipe(filter(jsHygieneFilter.concat(tsHygieneFilter)))
2020-09-22 11:12:35 +02:00
.pipe(
gulpeslint({
2020-09-22 14:37:04 +02:00
configFile: '.eslintrc.json',
rulePaths: ['./build/lib/eslint'],
2020-09-22 11:12:35 +02:00
})
)
2020-09-22 14:37:04 +02:00
.pipe(gulpeslint.formatEach('compact'))
2020-09-22 11:12:35 +02:00
.pipe(
gulpeslint.results((results) => {
if (results.warningCount > 0 || results.errorCount > 0) {
2020-09-22 14:37:04 +02:00
throw new Error('eslint failed with warnings and/or errors');
2020-09-22 11:12:35 +02:00
}
})
);
2017-06-20 16:21:44 +02:00
});
2016-02-18 16:02:16 +01:00
2019-09-11 16:49:49 +02:00
function checkPackageJSON(actualPath) {
2020-09-22 14:37:04 +02:00
const actual = require(path.join(__dirname, '..', actualPath));
const rootPackageJSON = require('../package.json');
2019-09-11 16:49:49 +02: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 11:12:35 +02:00
this.emit(
2020-09-22 14:37:04 +02:00
'error',
2020-09-22 11:12:35 +02:00
`The dependency ${depName} in '${actualPath}' (${depVersion}) is different than in the root package.json (${rootDepVersion})`
);
2019-09-11 16:49:49 +02:00
}
}
}
2020-09-22 14:37:04 +02:00
const checkPackageJSONTask = task.define('check-package-json', () => {
return gulp.src('package.json').pipe(
2020-09-22 11:12:35 +02:00
es.through(function () {
2020-09-22 14:37:04 +02:00
checkPackageJSON.call(this, 'remote/package.json');
checkPackageJSON.call(this, 'remote/web/package.json');
2020-09-22 11:12:35 +02:00
})
);
2019-09-11 16:49:49 +02:00
});
gulp.task(checkPackageJSONTask);
2020-09-22 11:12:35 +02:00
gulp.task(
2020-09-22 14:37:04 +02:00
'hygiene',
2020-09-22 11:12:35 +02:00
task.series(checkPackageJSONTask, () => hygiene())
);