Skip to content

Commit a08dfc6

Browse files
committed
Review comments: Move targetList to common helper
Add provision to get cli args when src/cli.js is run separately
1 parent f16e437 commit a08dfc6

File tree

3 files changed

+45
-52
lines changed

3 files changed

+45
-52
lines changed

src/cli-flags-helper.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const targetList = new Set([
2+
"acorn",
3+
"babel",
4+
"babylon",
5+
"buble",
6+
"chai",
7+
"coffeescript",
8+
"espree",
9+
"esprima",
10+
"jshint",
11+
"lebab",
12+
"prepack",
13+
"prettier",
14+
"source-map",
15+
"typescript",
16+
"uglify-es",
17+
"uglify-js"
18+
]);
19+
20+
function getOnlyFlag(argv) {
21+
if (process.argv.indexOf("--only") != -1) {
22+
return process.argv[process.argv.indexOf("--only") + 1];
23+
}
24+
}
25+
26+
module.exports = {
27+
getTarget: function() {
28+
let onlyArg = getOnlyFlag();
29+
if (targetList.has(onlyArg)) {
30+
return [onlyArg];
31+
} else if (typeof ONLY != "undefined" && targetList.has(ONLY)) {
32+
return [ONLY];
33+
} else {
34+
return [...targetList];
35+
}
36+
},
37+
targetList: targetList
38+
};

src/suite.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

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

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

17-
const targetList = [
18-
"acorn",
19-
"babel",
20-
"babylon",
21-
"buble",
22-
"chai",
23-
"coffeescript",
24-
"espree",
25-
"esprima",
26-
"jshint",
27-
"lebab",
28-
"prepack",
29-
"prettier",
30-
"source-map",
31-
"typescript",
32-
"uglify-es",
33-
"uglify-js"
34-
];
35-
3618
const suite = new Benchmark.Suite();
37-
const targetItems = ONLY ? [ONLY] : null;
38-
39-
const requireList = (targetItems || targetList).map(val => {
40-
return require(`./${val}-benchmark`);
41-
});
4219

43-
requireList.forEach(options => {
44-
suite.add(Object.assign({}, options, defaultOptions));
20+
getTarget().forEach(target => {
21+
suite.add(
22+
Object.assign({}, require(`./${target}-benchmark`), defaultOptions)
23+
);
4524
});
4625

4726
module.exports = suite;

webpack.config.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,10 @@ const CopyWebpackPlugin = require("copy-webpack-plugin");
66
const HtmlWebpackPlugin = require("html-webpack-plugin");
77
const path = require("path");
88
const webpack = require("webpack");
9-
10-
const targetList = [
11-
"acorn",
12-
"babel",
13-
"babylon",
14-
"buble",
15-
"chai",
16-
"coffeescript",
17-
"espree",
18-
"esprima",
19-
"jshint",
20-
"lebab",
21-
"prepack",
22-
"prettier",
23-
"source-map",
24-
"typescript",
25-
"uglify-es",
26-
"uglify-js"
27-
];
9+
const targetList = require("./src/cli-flags-helper").targetList;
2810

2911
function getTarget(env) {
30-
return (
31-
env &&
32-
env.only &&
33-
targetList.find(elem => {
34-
return elem == env.only;
35-
})
36-
);
12+
return env && targetList.has(env.only) && env.only;
3713
}
3814

3915
module.exports = env => [

0 commit comments

Comments
 (0)