Chore: Reorg the x-pack gulp tasks (#22785)

- Removes deprecated, non-functional lint scripts
- Removes some unused (and barely used) dependencies
- Replaces deprecated `gulp-util` dependency
- Adds eslint rule to prevent future use of deprecated `gulp-util` dependency
- Moves all gulp tasks into `tasks` path
- Moves `gulp_helpers` into `tasks/helpers`
- All tasks in `gulpfile.js` were moved into `tasks` and broken up by domain

This is basically a no-op moving files around PR. All the existing tasks appear to work the same with these changes.

<img width="334" alt="screenshot 2018-09-06 15 42 45" src="https://user-images.githubusercontent.com/404731/45188971-8618c000-b1eb-11e8-9b26-b072ccc7ddb7.png">
This commit is contained in:
Joe Fleming 2018-09-07 09:43:17 -07:00 committed by GitHub
parent b5c8cbea10
commit ef4b694e83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 206 additions and 219 deletions

View file

@ -2,6 +2,8 @@ const { resolve } = require('path');
const { readdirSync } = require('fs');
const dedent = require('dedent');
const restrictedModules = { paths: ['gulp-util'] };
module.exports = {
extends: ['@elastic/eslint-config-kibana', '@elastic/eslint-config-kibana/jest'],
@ -17,6 +19,11 @@ module.exports = {
},
},
rules: {
'no-restricted-imports': [2, restrictedModules],
'no-restricted-modules': [2, restrictedModules],
},
overrides: [
/**
* Prettier
@ -116,7 +123,7 @@ module.exports = {
'packages/kbn-ui-framework/generator-kui/**/*',
'packages/kbn-ui-framework/Gruntfile.js',
'packages/kbn-es/src/**/*',
'x-pack/{dev-tools,gulp_helpers,scripts,test,build_chromium}/**/*',
'x-pack/{dev-tools,tasks,scripts,test,build_chromium}/**/*',
'x-pack/**/{__tests__,__test__,__jest__,__fixtures__,__mocks__}/**/*',
'x-pack/**/*.test.js',
'x-pack/gulpfile.js',

View file

@ -7,120 +7,32 @@
require('@kbn/plugin-helpers').babelRegister();
require('dotenv').config({ silent: true });
const { writeFileSync } = require('fs');
const gulp = require('gulp');
const g = require('gulp-load-plugins')();
const path = require('path');
const del = require('del');
const runSequence = require('run-sequence');
const pluginHelpers = require('@kbn/plugin-helpers');
const { ToolingLog } = require('@kbn/dev-utils');
const logger = require('./gulp_helpers/logger');
const buildVersion = require('./gulp_helpers/build_version')();
const gitInfo = require('./gulp_helpers/git_info');
const fileGlobs = require('./gulp_helpers/globs');
const { getEnabledPlugins } = require('./gulp_helpers/get_plugins');
const getFlags = require('./gulp_helpers/get_flags');
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const fancyLog = require('fancy-log');
const ansiColors = require('ansi-colors');
const pkg = require('./package.json');
const { ensureAllBrowsersDownloaded } = require('./plugins/reporting/server/browsers');
const { createAutoJUnitReporter, generateNoticeFromSource } = require('../src/dev');
const buildDir = path.resolve(__dirname, 'build');
const buildTarget = path.resolve(buildDir, 'plugin');
const packageDir = path.resolve(buildDir, 'distributions');
const coverageDir = path.resolve(__dirname, 'coverage');
const MOCHA_OPTIONS = {
ui: 'bdd',
reporter: createAutoJUnitReporter({
reportName: 'X-Pack Mocha Tests',
rootDirectory: __dirname,
}),
const gulpHelpers = {
log: fancyLog,
colors: ansiColors,
mocha,
pkg,
buildDir,
buildTarget,
packageDir,
coverageDir,
};
gulp.task('prepare', () => ensureAllBrowsersDownloaded());
gulp.task('dev', ['prepare'], () => pluginHelpers.run('start', { flags: getFlags() }));
gulp.task('clean-test', () => {
logger('Deleting', coverageDir);
return del([coverageDir]);
});
gulp.task('clean', ['clean-test'], () => {
const toDelete = [
buildDir,
packageDir,
];
logger('Deleting', toDelete.join(', '));
return del(toDelete);
});
gulp.task('report', () => {
return gitInfo()
.then(function (info) {
g.util.log('Package Name', g.util.colors.yellow(pkg.name));
g.util.log('Version', g.util.colors.yellow(buildVersion));
g.util.log('Build Number', g.util.colors.yellow(info.number));
g.util.log('Build SHA', g.util.colors.yellow(info.sha));
});
});
gulp.task('build', ['clean', 'report', 'prepare'], async () => {
await pluginHelpers.run('build', {
skipArchive: true,
buildDestination: buildTarget,
});
const buildRoot = path.resolve(buildTarget, 'kibana/x-pack');
const log = new ToolingLog({
level: 'info',
writeTo: process.stdout
});
writeFileSync(
path.resolve(buildRoot, 'NOTICE.txt'),
await generateNoticeFromSource({
productName: 'Kibana X-Pack',
log,
directory: buildRoot
})
);
});
gulp.task('test', (cb) => {
const preTasks = ['clean-test'];
runSequence(preTasks, 'testserver', 'testbrowser', cb);
});
gulp.task('testonly', ['testserver', 'testbrowser']);
gulp.task('testserver', () => {
const globs = [
'common/**/__tests__/**/*.js',
'server/**/__tests__/**/*.js',
].concat(fileGlobs.forPluginServerTests());
return gulp.src(globs, { read: false })
.pipe(g.mocha(MOCHA_OPTIONS));
});
gulp.task('testbrowser', () => {
return getEnabledPlugins().then(plugins => {
return pluginHelpers.run('testBrowser', {
plugins: plugins.join(','),
});
});
});
gulp.task('testbrowser-dev', () => {
return getEnabledPlugins().then(plugins => {
return pluginHelpers.run('testBrowser', {
dev: true,
plugins: plugins.join(','),
});
});
});
require('./tasks/build')(gulp, gulpHelpers);
require('./tasks/clean')(gulp, gulpHelpers);
require('./tasks/dev')(gulp, gulpHelpers);
require('./tasks/prepare')(gulp, gulpHelpers);
require('./tasks/report')(gulp, gulpHelpers);
require('./tasks/test')(gulp, gulpHelpers);

View file

@ -9,8 +9,6 @@
"kbn": "node ../scripts/kbn",
"start": "gulp dev",
"build": "gulp build",
"lint": "gulp lint",
"lintroller": "gulp lint --fixLint",
"testonly": "gulp testonly",
"test": "gulp test",
"test:browser:dev": "gulp testbrowser-dev",
@ -30,6 +28,7 @@
"@types/jest": "^22.2.3",
"@types/pngjs": "^3.3.1",
"abab": "^1.0.4",
"ansi-colors": "^3.0.5",
"ansicolors": "0.3.2",
"aws-sdk": "2.2.33",
"axios": "^0.18.0",
@ -44,13 +43,10 @@
"enzyme-adapter-react-16": "^1.1.1",
"enzyme-to-json": "3.3.1",
"expect.js": "0.3.1",
"fancy-log": "^1.3.2",
"fetch-mock": "^5.13.1",
"gulp": "3.9.1",
"gulp-load-plugins": "1.2.0",
"gulp-mocha": "2.2.0",
"gulp-rename": "1.2.2",
"gulp-util": "3.0.7",
"gulp-zip": "3.1.0",
"hapi": "14.2.0",
"jest": "^22.4.3",
"jest-cli": "^22.4.3",
@ -170,4 +166,4 @@
"engines": {
"yarn": "^1.6.0"
}
}
}

35
x-pack/tasks/build.js Normal file
View file

@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { resolve } from 'path';
import { writeFileSync } from 'fs';
import pluginHelpers from '@kbn/plugin-helpers';
import { ToolingLog } from '@kbn/dev-utils';
import { generateNoticeFromSource } from '../../src/dev';
export default (gulp, { buildTarget }) => {
gulp.task('build', ['clean', 'report', 'prepare'], async () => {
await pluginHelpers.run('build', {
skipArchive: true,
buildDestination: buildTarget,
});
const buildRoot = resolve(buildTarget, 'kibana/x-pack');
const log = new ToolingLog({
level: 'info',
writeTo: process.stdout
});
writeFileSync(
resolve(buildRoot, 'NOTICE.txt'),
await generateNoticeFromSource({
productName: 'Kibana X-Pack',
log,
directory: buildRoot
})
);
});
};

22
x-pack/tasks/clean.js Normal file
View file

@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import del from 'del';
export default (gulp, { coverageDir, buildDir, packageDir, log }) => {
gulp.task('clean-test', () => {
log('Deleting', coverageDir);
return del([coverageDir]);
});
gulp.task('clean', ['clean-test'], () => {
const toDelete = [
buildDir,
packageDir,
];
log('Deleting', toDelete.join(', '));
return del(toDelete);
});
};

View file

@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
module.exports = function logger() {
const DEBUG = process.env.DEBUG || false;
import pluginHelpers from '@kbn/plugin-helpers';
import getFlags from './helpers/get_flags';
if (!DEBUG) return;
console.log.apply(console, arguments);
};
export default (gulp) => {
gulp.task('dev', ['prepare'], () => pluginHelpers.run('start', { flags: getFlags() }));
};

View file

@ -4,15 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
const yargs = require('yargs');
const semver = require('semver');
const pkg = require('../package.json');
import yargs from 'yargs';
import semver from 'semver';
yargs
.alias('r', 'release').describe('r', 'Create a release build, not a snapshot');
const argv = yargs.argv;
function getVersion() {
export default function getVersion(pkg) {
const { version } = pkg;
if (!version) {
throw new Error('No version found in package.json');
@ -24,5 +23,3 @@ function getVersion() {
const snapshotText = (argv.release) ? '' : '-SNAPSHOT';
return `${version}${snapshotText}`;
}
module.exports = getVersion;

View file

@ -4,6 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
module.exports = function getFlags() {
export default function getFlags() {
return process.argv.slice(3);
};
}

View file

@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
const path = require('path');
const yargs = require('yargs');
const glob = require('glob');
const { toArray } = require('rxjs/operators');
const { findPluginSpecs } = require('../../src/plugin_discovery');
import { resolve } from 'path';
import yargs from 'yargs';
import glob from 'glob';
import { toArray } from 'rxjs/operators';
import { findPluginSpecs } from '../../../src/plugin_discovery';
/*
Usage:
@ -22,7 +22,7 @@ const { findPluginSpecs } = require('../../src/plugin_discovery');
const argv = yargs
.describe('plugins', 'Comma-separated list of plugins')
.argv;
const allPlugins = glob.sync('*', { cwd: path.resolve(__dirname, '..', 'plugins') });
const allPlugins = glob.sync('*', { cwd: resolve(__dirname, '..', '..', 'plugins') });
export function getPlugins() {
const plugins = argv.plugins && argv.plugins.split(',');
@ -33,7 +33,7 @@ export function getPlugins() {
}
const { spec$ } = findPluginSpecs({
plugins: { paths: [path.resolve(__dirname, '../')] }
plugins: { paths: [resolve(__dirname, '..', '..')] }
});
export async function getEnabledPlugins() {

View file

@ -4,11 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/
const path = require('path');
const simpleGit = require('simple-git');
const gitDir = path.resolve(__dirname, '..');
import path from 'path';
import simpleGit from 'simple-git';
function gitInfo() {
const gitDir = path.resolve(__dirname, '..', '..');
export default function gitInfo() {
const git = simpleGit(gitDir);
return new Promise((resolve, reject) => {
@ -21,5 +22,3 @@ function gitInfo() {
});
});
}
module.exports = gitInfo;

View file

@ -35,12 +35,12 @@ function getPluginPaths(plugins, opts = {}) {
}, []);
}
exports.forPlugins = function () {
export function forPlugins() {
const plugins = getPlugins();
return getPluginPaths(plugins, { browser: true });
};
}
exports.forPluginServerTests = function () {
export function forPluginServerTests() {
const plugins = getPlugins();
return getPluginPaths(plugins, { tests: true });
};
}

12
x-pack/tasks/prepare.js Normal file
View file

@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { ensureAllBrowsersDownloaded } from '../plugins/reporting/server/browsers';
export default gulp => {
// anything that needs to happen pre-build or pre-dev
gulp.task('prepare', () => ensureAllBrowsersDownloaded());
};

20
x-pack/tasks/report.js Normal file
View file

@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import buildVersion from './helpers/build_version';
import gitInfo from './helpers/git_info';
export default (gulp, { log, colors, pkg }) => {
gulp.task('report', () => {
return gitInfo()
.then(function (info) {
log('Package Name', colors.yellow(pkg.name));
log('Version', colors.yellow(buildVersion(pkg)));
log('Build Number', colors.yellow(info.number));
log('Build SHA', colors.yellow(info.sha));
});
});
};

55
x-pack/tasks/test.js Normal file
View file

@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import runSequence from 'run-sequence';
import pluginHelpers from '@kbn/plugin-helpers';
import { getEnabledPlugins } from './helpers/get_plugins';
import { forPluginServerTests } from './helpers/globs';
import { createAutoJUnitReporter } from '../../src/dev';
const MOCHA_OPTIONS = {
ui: 'bdd',
reporter: createAutoJUnitReporter({
reportName: 'X-Pack Mocha Tests',
rootDirectory: __dirname,
}),
};
export default (gulp, { mocha }) => {
gulp.task('test', (cb) => {
const preTasks = ['clean-test'];
runSequence(preTasks, 'testserver', 'testbrowser', cb);
});
gulp.task('testonly', ['testserver', 'testbrowser']);
gulp.task('testserver', () => {
const globs = [
'common/**/__tests__/**/*.js',
'server/**/__tests__/**/*.js',
].concat(forPluginServerTests());
return gulp.src(globs, { read: false })
.pipe(mocha(MOCHA_OPTIONS));
});
gulp.task('testbrowser', () => {
return getEnabledPlugins().then(plugins => {
return pluginHelpers.run('testBrowser', {
plugins: plugins.join(','),
});
});
});
gulp.task('testbrowser-dev', () => {
return getEnabledPlugins().then(plugins => {
return pluginHelpers.run('testBrowser', {
dev: true,
plugins: plugins.join(','),
});
});
});
};

View file

@ -302,6 +302,10 @@ angular-ui-ace@0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/angular-ui-ace/-/angular-ui-ace-0.2.3.tgz#3cb903428100621a367fc7f641440e97a42a26d0"
ansi-colors@^3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.0.5.tgz#cb9dc64993b64fd6945485f797fc3853137d9a7b"
ansi-cyan@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/ansi-cyan/-/ansi-cyan-0.1.1.tgz#538ae528af8982f28ae30d86f2f17456d2609873"
@ -1815,13 +1819,6 @@ dashdash@^1.12.0:
dependencies:
assert-plus "^1.0.0"
dateformat@^1.0.11:
version "1.0.12"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-1.0.12.tgz#9f124b67594c937ff706932e4a642cca8dbbfee9"
dependencies:
get-stdin "^4.0.1"
meow "^3.3.0"
dateformat@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-2.2.0.tgz#4065e2013cf9fb916ddfd82efb506ad4c6769062"
@ -2580,12 +2577,6 @@ find-up@^2.1.0:
dependencies:
locate-path "^2.0.0"
findup-sync@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-0.2.1.tgz#e0a90a450075c49466ee513732057514b81e878c"
dependencies:
glob "~4.3.0"
findup-sync@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/findup-sync/-/findup-sync-2.0.0.tgz#9326b1488c22d1a6088650a86901b2d9a90a2cbc"
@ -2961,15 +2952,6 @@ glob@~3.1.21:
inherits "1"
minimatch "~0.2.11"
glob@~4.3.0:
version "4.3.5"
resolved "https://registry.yarnpkg.com/glob/-/glob-4.3.5.tgz#80fbb08ca540f238acce5d11d1e9bc41e75173d3"
dependencies:
inflight "^1.0.4"
inherits "2"
minimatch "^2.0.1"
once "^1.3.0"
global-modules@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-1.0.0.tgz#6d770f0eb523ac78164d72b5e71a8877265cc3ea"
@ -3096,15 +3078,6 @@ growly@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
gulp-load-plugins@1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/gulp-load-plugins/-/gulp-load-plugins-1.2.0.tgz#49513d284313cba79b8446e17cb36311e5175b70"
dependencies:
findup-sync "^0.2.1"
gulp-util "^3.0.7"
multimatch "2.0.0"
resolve "^1.1.6"
gulp-mocha@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/gulp-mocha/-/gulp-mocha-2.2.0.tgz#1ce5eba4b94b40c7436afec3c4982c8eea894192"
@ -3120,30 +3093,7 @@ gulp-rename@1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/gulp-rename/-/gulp-rename-1.2.2.tgz#3ad4428763f05e2764dec1c67d868db275687817"
gulp-util@3.0.7:
version "3.0.7"
resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.7.tgz#78925c4b8f8b49005ac01a011c557e6218941cbb"
dependencies:
array-differ "^1.0.0"
array-uniq "^1.0.2"
beeper "^1.0.0"
chalk "^1.0.0"
dateformat "^1.0.11"
fancy-log "^1.1.0"
gulplog "^1.0.0"
has-gulplog "^0.1.0"
lodash._reescape "^3.0.0"
lodash._reevaluate "^3.0.0"
lodash._reinterpolate "^3.0.0"
lodash.template "^3.0.0"
minimist "^1.1.0"
multipipe "^0.1.2"
object-assign "^3.0.0"
replace-ext "0.0.1"
through2 "^2.0.0"
vinyl "^0.5.0"
gulp-util@^3.0.0, gulp-util@^3.0.7:
gulp-util@^3.0.0:
version "3.0.8"
resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.8.tgz#0054e1e744502e27c04c187c3ecc505dd54bbb4f"
dependencies:
@ -3166,16 +3116,6 @@ gulp-util@^3.0.0, gulp-util@^3.0.7:
through2 "^2.0.0"
vinyl "^0.5.0"
gulp-zip@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/gulp-zip/-/gulp-zip-3.1.0.tgz#4a72449da666e9a9c23c4da7e7d559f99dfc4c09"
dependencies:
chalk "^1.0.0"
concat-stream "^1.4.7"
gulp-util "^3.0.0"
through2 "^0.6.1"
yazl "^2.1.0"
gulp-zip@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/gulp-zip/-/gulp-zip-4.1.0.tgz#dab178bd99afa190923f1eb78abaf0db47817704"
@ -4947,7 +4887,7 @@ mem@^1.1.0:
dependencies:
mimic-fn "^1.0.0"
meow@^3.3.0, meow@^3.7.0:
meow@^3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/meow/-/meow-3.7.0.tgz#72cb668b425228290abbfa856892587308a801fb"
dependencies:
@ -5189,14 +5129,6 @@ ms@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"
multimatch@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/multimatch/-/multimatch-2.0.0.tgz#c5ada425357b744ba54842ebdce1c8f0be542b6f"
dependencies:
array-differ "^1.0.0"
array-union "^1.0.1"
minimatch "^2.0.1"
multipipe@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/multipipe/-/multipipe-0.1.2.tgz#2a8f2ddf70eed564dff2d57f1e1a137d9f05078b"