Merge pull request #9634 from OlegZharkov/skip_viz_build

Skip visualization build, if no changes were registered
This commit is contained in:
Dannon
2020-04-24 10:32:12 -04:00
committed by GitHub
2 changed files with 43 additions and 17 deletions
+1
View File
@@ -178,3 +178,4 @@ packages/*/*.egg-info
config/plugins/visualizations/**/static/script.js
# TODO: Really need to follow up on this and make it standard.
config/plugins/visualizations/**/static/main.css
config/plugins/visualizations/**/static/plugin_build_hash.txt
+42 -17
View File
@@ -2,14 +2,14 @@ const path = require("path");
const fs = require("fs");
const del = require("del");
const { src, dest, series, parallel } = require("gulp");
const spawn = require("child_process").spawnSync;
const child_process = require("child_process");
const glob = require("glob");
const paths = {
node_modules: "./node_modules",
plugin_dirs: [
"../config/plugins/{visualizations,interactive_environments}/*/static/**/*",
"../config/plugins/{visualizations,interactive_environments}/*/*/static/**/*"
"../config/plugins/{visualizations,interactive_environments}/*/*/static/**/*",
],
/*
* We'll want a flexible glob down the road, but for now there are no
@@ -20,9 +20,7 @@ const paths = {
// "../config/plugins/{visualizations,interactive_environments}/*/package.json",
// "../config/plugins/{visualizations,interactive_environments}/*/*/package.json"
//],
plugin_build_dirs: [
"../config/plugins/visualizations/{annotate_image,hyphyvision,openlayers,editor}/package.json",
],
plugin_build_dirs: ["../config/plugins/visualizations/{annotate_image,hyphyvision,openlayers,editor}/package.json"],
lib_locs: {
// This is a stepping stone towards having all this staged
// automatically. Eventually, this dictionary and staging step will
@@ -37,13 +35,13 @@ const paths = {
"jquery-mousewheel": ["jquery.mousewheel.js", "jquery/jquery.mousewheel.js"],
"raven-js": ["dist/raven.js", "raven.js"],
requirejs: ["require.js", "require.js"],
underscore: ["underscore.js", "underscore.js"]
underscore: ["underscore.js", "underscore.js"],
},
libs: ["galaxy/scripts/libs/**/*.js"]
libs: ["galaxy/scripts/libs/**/*.js"],
};
function stageLibs(callback) {
Object.keys(paths.lib_locs).forEach(lib => {
Object.keys(paths.lib_locs).forEach((lib) => {
var p1 = path.resolve(path.join(paths.node_modules, lib, paths.lib_locs[lib][0]));
var p2 = path.resolve(path.join("galaxy", "scripts", "libs", paths.lib_locs[lib][1]));
if (fs.existsSync(p1)) {
@@ -69,18 +67,45 @@ function stagePlugins() {
return src(paths.plugin_dirs).pipe(dest("../static/plugins/"));
}
function buildPlugins(callback){
function buildPlugins(callback) {
/*
* Walk plugin build glob and attempt to build anything with a package.json
* Walk plugin_build_dirs glob and attempt to build modules.
* */
paths.plugin_build_dirs.map( build_dir => {
paths.plugin_build_dirs.map((build_dir) => {
glob(build_dir, {}, (er, files) => {
files.map( file => {
files.map((file) => {
let skip_build = false;
const f = path.join(process.cwd(), file).slice(0, -12);
console.log("Installing Dependencies for", f);
spawn('yarn', ['install', '--production=false', '--network-timeout=300000', '--check-files'], { cwd: f, stdio: 'inherit', shell: true });
console.log("Building ", f);
spawn('yarn', ['build'], { cwd: f, stdio: 'inherit', shell: true });
const plugin_name = path.dirname(file).split(path.sep).pop();
const hash_file_path = path.join(f, "static", "plugin_build_hash.txt");
if (fs.existsSync(hash_file_path)) {
skip_build =
child_process.spawnSync("git", ["diff", "--quiet", `$(cat ${hash_file_path})`, "--", f], {
stdio: "inherit",
shell: true,
}).status === 0;
} else {
console.log(`No build hashfile detected for ${plugin_name}, generating now.`);
}
if (skip_build) {
console.log(`No changes detected for ${plugin_name}`);
} else {
console.log(`Installing Dependencies for ${plugin_name}`);
child_process.spawnSync(
"yarn",
["install", "--production=false", "--network-timeout=300000", "--check-files"],
{
cwd: f,
stdio: "inherit",
shell: true,
}
);
console.log(`Building ${plugin_name}`);
child_process.spawnSync("yarn", ["build"], { cwd: f, stdio: "inherit", shell: true });
child_process.exec(`"(git rev-parse HEAD 2>/dev/null || echo \`\`) > ${hash_file_path} "`);
}
});
});
});
@@ -92,7 +117,7 @@ function cleanPlugins() {
}
client = parallel(fonts, stageLibs);
plugins = series(cleanPlugins, buildPlugins, stagePlugins);
plugins = series(buildPlugins, cleanPlugins, stagePlugins);
module.exports.client = client;
module.exports.plugins = plugins;