Skip to content

Commit

Permalink
beautify bin
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Aug 9, 2015
1 parent 5f14ee4 commit 2e2cb74
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 122 deletions.
137 changes: 46 additions & 91 deletions bin/config-optimist.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,48 @@
module.exports = function(optimist) {
optimist

.boolean("help").alias("help", "h").alias("help", "?").describe("help")

.string("config").describe("config")

.string("context").describe("context")

.string("entry").describe("entry")

.string("module-bind").describe("module-bind")

.string("module-bind-post").describe("module-bind-post")

.string("module-bind-pre").describe("module-bind-pre")

.string("output-path").describe("output-path")

.string("output-file").describe("output-file")

.string("output-chunk-file").describe("output-chunk-file")

.string("output-named-chunk-file").describe("output-named-chunk-file")

.string("output-source-map-file").describe("output-source-map-file")

.string("output-public-path").describe("output-public-path")

.string("output-jsonp-function").describe("output-jsonp-function")

.boolean("output-pathinfo").describe("output-pathinfo")

.string("output-library").describe("output-library")

.string("output-library-target").describe("output-library-target")

.string("records-input-path").describe("records-input-path")

.string("records-output-path").describe("records-output-path")

.string("records-path").describe("records-path")

.string("define").describe("define")

.string("target").describe("target")

.boolean("cache").describe("cache").default("cache", true)

.boolean("watch").alias("watch", "w").describe("watch")

.describe("watch-aggregate-timeout")

.describe("watch-poll")

.boolean("hot").alias("hot", "h").describe("hot")

.boolean("debug").describe("debug")

.string("devtool").describe("devtool")

.boolean("progress").describe("progress")

.string("resolve-alias").describe("resolve-alias")

.string("resolve-loader-alias").describe("resolve-loader-alias")

.describe("optimize-max-chunks")

.describe("optimize-min-chunk-size")

.boolean("optimize-minimize").describe("optimize-minimize")

.boolean("optimize-occurence-order").describe("optimize-occurence-order")

.boolean("optimize-dedupe").describe("optimize-dedupe")

.string("prefetch").describe("prefetch")

.string("provide").describe("provide")

.boolean("labeled-modules").describe("labeled-modules")

.string("plugin").describe("plugin")

.boolean("bail").describe("bail")

.boolean("profile").describe("profile")

.boolean("d").describe("d", "shortcut for --debug --devtool sourcemap --output-pathinfo")

.boolean("p").describe("p", "shortcut for --optimize-minimize");
};
.boolean("help").alias("help", "h").alias("help", "?").describe("help")
.string("config").describe("config")
.string("context").describe("context")
.string("entry").describe("entry")
.string("module-bind").describe("module-bind")
.string("module-bind-post").describe("module-bind-post")
.string("module-bind-pre").describe("module-bind-pre")
.string("output-path").describe("output-path")
.string("output-file").describe("output-file")
.string("output-chunk-file").describe("output-chunk-file")
.string("output-named-chunk-file").describe("output-named-chunk-file")
.string("output-source-map-file").describe("output-source-map-file")
.string("output-public-path").describe("output-public-path")
.string("output-jsonp-function").describe("output-jsonp-function")
.boolean("output-pathinfo").describe("output-pathinfo")
.string("output-library").describe("output-library")
.string("output-library-target").describe("output-library-target")
.string("records-input-path").describe("records-input-path")
.string("records-output-path").describe("records-output-path")
.string("records-path").describe("records-path")
.string("define").describe("define")
.string("target").describe("target")
.boolean("cache").describe("cache").default("cache", true)
.boolean("watch").alias("watch", "w").describe("watch")
.describe("watch-aggregate-timeout")
.describe("watch-poll")
.boolean("hot").alias("hot", "h").describe("hot")
.boolean("debug").describe("debug")
.string("devtool").describe("devtool")
.boolean("progress").describe("progress")
.string("resolve-alias").describe("resolve-alias")
.string("resolve-loader-alias").describe("resolve-loader-alias")
.describe("optimize-max-chunks")
.describe("optimize-min-chunk-size")
.boolean("optimize-minimize").describe("optimize-minimize")
.boolean("optimize-occurence-order").describe("optimize-occurence-order")
.boolean("optimize-dedupe").describe("optimize-dedupe")
.string("prefetch").describe("prefetch")
.string("provide").describe("provide")
.boolean("labeled-modules").describe("labeled-modules")
.string("plugin").describe("plugin")
.boolean("bail").describe("bail")
.boolean("profile").describe("profile")
.boolean("d").describe("d", "shortcut for --debug --devtool sourcemap --output-pathinfo")
.boolean("p").describe("p", "shortcut for --optimize-minimize");
};
27 changes: 15 additions & 12 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ module.exports = function(optimist, argv, convertOptions) {
}

var configPath, ext;
var extensions = Object.keys(interpret.extensions).sort(function(a, b){
var extensions = Object.keys(interpret.extensions).sort(function(a, b) {
return a.length - b.length;
});

if (argv.config) {
if(argv.config) {
configPath = path.resolve(argv.config);
for (var i = extensions.length - 1; i >= 0; i--) {
for(var i = extensions.length - 1; i >= 0; i--) {
var tmpExt = extensions[i];
if (configPath.indexOf(tmpExt, configPath.length - tmpExt.length) > -1){
if(configPath.indexOf(tmpExt, configPath.length - tmpExt.length) > -1) {
ext = tmpExt;
break;
}
};
if (!ext) {
}
if(!ext) {
ext = path.extname(configPath);
}
} else {
for(var i = 0; i < extensions.length; i++) {
var webpackConfig = path.resolve('webpack.config' + extensions[i]);
var webpackConfig = path.resolve("webpack.config" + extensions[i]);
if(fs.existsSync(webpackConfig)) {
ext = extensions[i];
configPath = webpackConfig;
Expand All @@ -58,8 +58,8 @@ module.exports = function(optimist, argv, convertOptions) {
if(configPath) {

function registerCompiler(moduleDescriptor) {
if (moduleDescriptor) {
if(typeof(moduleDescriptor) == "string") {
if(moduleDescriptor) {
if(typeof moduleDescriptor === "string") {
require(moduleDescriptor);
} else if(!Array.isArray(moduleDescriptor)) {
moduleDescriptor.register(require(moduleDescriptor.module));
Expand Down Expand Up @@ -98,7 +98,7 @@ module.exports = function(optimist, argv, convertOptions) {
options.context = process.cwd();
}

if(argv["watch"]) {
if(argv.watch) {
// TODO remove this in next major version
if(options.watch && typeof options.watch === "object") {
console.warn("options.watch is deprecated: Use 'options.watchOptions' instead");
Expand Down Expand Up @@ -197,7 +197,7 @@ module.exports = function(optimist, argv, convertOptions) {
var args = null;
try {
var p = name && name.indexOf("?");
if (p > -1) {
if(p > -1) {
args = loadUtils.parseQuery(name.substring(p));
name = name.substring(0, p);
}
Expand Down Expand Up @@ -364,7 +364,8 @@ module.exports = function(optimist, argv, convertOptions) {
ifBooleanArg("progress", function() {
var ProgressPlugin = require("../lib/ProgressPlugin");
ensureArray(options, "plugins");
var chars = 0, lastState, lastStateTime;
var chars = 0,
lastState, lastStateTime;
options.plugins.push(new ProgressPlugin(function(percentage, msg) {
var state = msg;
if(percentage < 1) {
Expand Down Expand Up @@ -397,6 +398,7 @@ module.exports = function(optimist, argv, convertOptions) {
goToLineStart(msg);
process.stderr.write(msg);
}));

function goToLineStart(nextMessage) {
var str = "";
for(; chars > nextMessage.length; chars--) {
Expand Down Expand Up @@ -518,6 +520,7 @@ module.exports = function(optimist, argv, convertOptions) {
};
}
ensureObject(options, "entry");

function addTo(name, entry) {
if(options.entry[name]) {
if(!Array.isArray(options.entry[name])) {
Expand Down
16 changes: 1 addition & 15 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,21 @@ var optimist = require("optimist")
require("./config-optimist")(optimist);

optimist

.boolean("json").alias("json", "j").describe("json")

.boolean("colors").alias("colors", "c").describe("colors")

.string("sort-modules-by").describe("sort-modules-by")

.string("sort-chunks-by").describe("sort-chunks-by")

.string("sort-assets-by").describe("sort-assets-by")

.boolean("hide-modules").describe("hide-modules")

.string("display-exclude").describe("display-exclude")

.boolean("display-modules").describe("display-modules")

.boolean("display-chunks").describe("display-chunks")

.boolean("display-error-details").describe("display-error-details")

.boolean("display-origins").describe("display-origins")

.boolean("display-cached").describe("display-cached")

.boolean("display-cached-assets").describe("display-cached-assets")

.boolean("display-reasons").alias("display-reasons", "verbose").alias("display-reasons", "v").describe("display-reasons");


var argv = optimist.argv;

var options = require("./convert-argv")(optimist, argv);
Expand Down Expand Up @@ -155,6 +140,7 @@ var webpack = require("../lib/webpack.js");
Error.stackTraceLimit = 30;
var lastHash = null;
var compiler = webpack(options);

function compilerCallback(err, stats) {
if(!options.watch) {
// Do not keep cache anymore
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"component-webpack-plugin": "~0.2.0",
"coveralls": "^2.11.2",
"css-loader": "~0.15.0",
"diff": "^1.4.0",
"eslint": "^0.24.0",
"diff": "^2.0.2",
"eslint": "^1.1.0",
"eslint-plugin-nodeca": "^1.0.3",
"express": "~4.13.1",
"extract-text-webpack-plugin": "~0.8.0",
Expand Down Expand Up @@ -76,7 +76,7 @@
"pretest": "npm run lint && npm run beautify-lint",
"test": "mocha",
"travis": "npm run cover -- --report lcovonly",
"lint": "eslint lib",
"lint": "eslint lib bin",
"beautify-lint": "node ./scripts/beautify-check",
"beautify": "node ./scripts/beautify-rewrite",
"precover": "npm run lint && npm run beautify-lint",
Expand Down
2 changes: 1 addition & 1 deletion scripts/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
exports.beautify = {
files: "{{lib,hot,scripts}/**/*.js,benchmark/*.js}"
files: "{{lib,hot,scripts,bin}/**/*.js,benchmark/*.js}"
};

0 comments on commit 2e2cb74

Please sign in to comment.