From 4293515b3d9d527d9cf96a92c2663325f04c10a0 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 13:26:14 -0400 Subject: [PATCH] Add `help` and `version` options to build.js. Former-commit-id: 95a9fdaa7a00550922e71ce01a3f742b845d082c --- README.md | 18 +++++++++--------- build.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 052d4839b..66e7deb11 100644 --- a/README.md +++ b/README.md @@ -75,23 +75,23 @@ lodash category=collections,functions lodash category="collections, functions" ~~~ - 2. Use the `include` argument to pass the names of methods to include in the build. -~~~ bash -lodash include=each,filter,map -lodash include="each, filter, map" -~~~ - - 3. Use the `exclude` argument to pass the names of methods to exclude from the build. + 2. Use the `exclude` argument to pass the names of methods to exclude from the build. ~~~ bash lodash exclude=union,uniq,zip lodash exclude="union, uniq, zip" ~~~ -All arguments, except `include` with `exclude` and `mobile` with `legacy`, may be combined. + 3. Use the `include` argument to pass the names of methods to include in the build. +~~~ bash +lodash include=each,filter,map +lodash include="each, filter, map" +~~~ + +All arguments, except `exclude` with `include` and `legacy` with `mobile`, may be combined. ~~~ bash -lodash backbone mobile category=functions include=pick,uniq lodash backbone legacy category=utilities exclude=first,last +lodash backbone mobile category=functions include=pick,uniq ~~~ The `lodash` command-line utility is available when Lo-Dash is installed as a global package (i.e. `npm install -g lodash`). diff --git a/build.js b/build.js index 26ba3eea9..2a57c6a83 100755 --- a/build.js +++ b/build.js @@ -29,7 +29,6 @@ /** Load customized Lo-Dash module */ var lodash = (function() { var sandbox = {}; - if (isLegacy) { ['isBindFast', 'isKeysFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) { source = replaceVar(source, varName, 'false'); @@ -261,6 +260,33 @@ /*--------------------------------------------------------------------------*/ + /** + * Logs the help message to the console. + * + * @private + */ + function displayHelp() { + console.log([ + '', + ' Commands:', + '', + ' lodash backbone Build containing all methods required by Backbone', + ' lodash legacy Build tailored for older browsers without ES5 support', + ' lodash mobile Build with IE < 9 bug fixes and method compilation removed', + ' lodash category=... Comma separated categories of methods to include in the build', + ' lodash exclude=... Comma separated names of methods to exclude from the build', + ' lodash include=... Comma separated names of methods to include in the build', + '', + ' All arguments, except `exclude` with `include` and `legacy` with `mobile`, may be combined.', + '', + ' Options:', + '', + ' -h, --help Display help information', + ' -V, --version Output current version of Lo-Dash', + '' + ].join('\n')); + } + /** * Gets the aliases associated with a given function name. * @@ -537,6 +563,24 @@ /*--------------------------------------------------------------------------*/ + // display help message + if (lodash.find(process.argv, function(arg) { + return /^(?:-h|--help)$/.test(arg); + })) { + displayHelp(); + process.exit(); + } + + // display `lodash.VERSION` + if (lodash.find(process.argv, function(arg) { + return /^(?:-V|--version)$/.test(arg); + })) { + console.log(lodash.VERSION); + process.exit(); + } + + /*--------------------------------------------------------------------------*/ + // Backbone build if (isBackbone) { // add any additional sub-dependencies