Skip to content

Commit

Permalink
Review comments: Move targetList to common helper
Browse files Browse the repository at this point in the history
Add provision to get cli args when src/cli.js is run separately
  • Loading branch information
ksashikumar committed Feb 12, 2018
1 parent f16e437 commit a08dfc6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 52 deletions.
38 changes: 38 additions & 0 deletions src/cli-flags-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const targetList = new Set([
"acorn",
"babel",
"babylon",
"buble",
"chai",
"coffeescript",
"espree",
"esprima",
"jshint",
"lebab",
"prepack",
"prettier",
"source-map",
"typescript",
"uglify-es",
"uglify-js"
]);

function getOnlyFlag(argv) {
if (process.argv.indexOf("--only") != -1) {
return process.argv[process.argv.indexOf("--only") + 1];
}
}

module.exports = {
getTarget: function() {
let onlyArg = getOnlyFlag();
if (targetList.has(onlyArg)) {
return [onlyArg];
} else if (typeof ONLY != "undefined" && targetList.has(ONLY)) {
return [ONLY];
} else {
return [...targetList];
}
},
targetList: targetList
};
31 changes: 5 additions & 26 deletions src/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

const Benchmark = require("benchmark");
const getTarget = require("./cli-flags-helper").getTarget;

// We need to run deterministically, so we set 'maxTime' to 0, which
// disables the variable iteration count feature of benchmark.js,
Expand All @@ -14,34 +15,12 @@ const defaultOptions = {
minSamples: 20
};

const targetList = [
"acorn",
"babel",
"babylon",
"buble",
"chai",
"coffeescript",
"espree",
"esprima",
"jshint",
"lebab",
"prepack",
"prettier",
"source-map",
"typescript",
"uglify-es",
"uglify-js"
];

const suite = new Benchmark.Suite();
const targetItems = ONLY ? [ONLY] : null;

const requireList = (targetItems || targetList).map(val => {
return require(`./${val}-benchmark`);
});

requireList.forEach(options => {
suite.add(Object.assign({}, options, defaultOptions));
getTarget().forEach(target => {
suite.add(
Object.assign({}, require(`./${target}-benchmark`), defaultOptions)
);
});

module.exports = suite;
28 changes: 2 additions & 26 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,10 @@ const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const webpack = require("webpack");

const targetList = [
"acorn",
"babel",
"babylon",
"buble",
"chai",
"coffeescript",
"espree",
"esprima",
"jshint",
"lebab",
"prepack",
"prettier",
"source-map",
"typescript",
"uglify-es",
"uglify-js"
];
const targetList = require("./src/cli-flags-helper").targetList;

function getTarget(env) {
return (
env &&
env.only &&
targetList.find(elem => {
return elem == env.only;
})
);
return env && targetList.has(env.only) && env.only;
}

module.exports = env => [
Expand Down

0 comments on commit a08dfc6

Please sign in to comment.