Skip to content

Commit

Permalink
Chore: Reorg the x-pack gulp tasks (#22785)
Browse files Browse the repository at this point in the history
- 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">
  • Loading branch information
w33ble committed Sep 7, 2018
1 parent b5c8cbe commit ef4b694
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 219 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],

Expand All @@ -17,6 +19,11 @@ module.exports = {
},
},

rules: {
'no-restricted-imports': [2, restrictedModules],
'no-restricted-modules': [2, restrictedModules],
},

overrides: [
/**
* Prettier
Expand Down Expand Up @@ -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',
Expand Down
126 changes: 19 additions & 107 deletions x-pack/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
10 changes: 3 additions & 7 deletions x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -170,4 +166,4 @@
"engines": {
"yarn": "^1.6.0"
}
}
}
35 changes: 35 additions & 0 deletions x-pack/tasks/build.js
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions x-pack/tasks/clean.js
Original file line number Diff line number Diff line change
@@ -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);
});
};
10 changes: 5 additions & 5 deletions x-pack/gulp_helpers/logger.js → x-pack/tasks/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() }));
};
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -24,5 +23,3 @@ function getVersion() {
const snapshotText = (argv.release) ? '' : '-SNAPSHOT';
return `${version}${snapshotText}`;
}

module.exports = getVersion;
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(',');
Expand All @@ -33,7 +33,7 @@ export function getPlugins() {
}

const { spec$ } = findPluginSpecs({
plugins: { paths: [path.resolve(__dirname, '../')] }
plugins: { paths: [resolve(__dirname, '..', '..')] }
});

export async function getEnabledPlugins() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -21,5 +22,3 @@ function gitInfo() {
});
});
}

module.exports = gitInfo;
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
};
}
Loading

0 comments on commit ef4b694

Please sign in to comment.