From fce19d377e778e94b402acbaa94058a12eb8a4e0 Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Fri, 23 Jan 2015 17:16:35 +1100 Subject: [PATCH 1/3] =BG= begin parsing command line arguments using yargs NOTE that version now will require a `-` suffix --- bin/cli-args.js | 11 +++++++++++ bin/cli.js | 45 +++++++++++++++++++-------------------------- package.json | 7 ++++--- 3 files changed, 34 insertions(+), 29 deletions(-) create mode 100644 bin/cli-args.js diff --git a/bin/cli-args.js b/bin/cli-args.js new file mode 100644 index 0000000..ad4f78f --- /dev/null +++ b/bin/cli-args.js @@ -0,0 +1,11 @@ +var yargs = require('yargs'); +var args = yargs + .describe('p', 'Define a port number when serving files') + .alias('p', 'port') + .default('p', 10101) + .describe('v', 'Version number') + .alias('v', 'version') + .boolean('v') + .usage() + .wrap(80); +module.exports = yargs; diff --git a/bin/cli.js b/bin/cli.js index cc46d15..0099535 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -33,29 +33,22 @@ gulp.on('task_stop', function (e) { ); }); -// expect the second argument to be the task name -var taskName = process.argv[2]; -switch(taskName) { - - // with no arguments, prompt the main menu. - case undefined: - mainMenu.prompt(); - break; - - // allow a version command with `angularity -v` - case 'v': - case '-v': - var packagePath = path.join(__dirname, '..', 'package.json'); - var version = require(packagePath).version; - console.log('angularity:', version); - break; - - // use the project generator with `angularity generate ` - case 'generate': - generator.util.generateProject(process.argv[3]); - break; - - // allow the default gulp tasks to be run on the global cli - default: - gulp.start(gulp.hasTask(taskName) ? taskName : 'default'); -} \ No newline at end of file +// gulp tasks can access argv using this same method +var argv = require('./cli-args').argv; + +var subCmd = (argv._.length > 0) ? argv._[0] : undefined; + +if (argv.v) { + var packagePath = path.join(__dirname, '..', 'package.json'); + var version = require(packagePath).version; + console.log('angularity:', version); +} +else if (!subCmd) { + mainMenu.prompt(); +} +else if (subCmd === 'generate') { + generator.util.generateProject(argv._[1]); +} +else { + gulp.start(gulp.hasTask(subCmd) ? subCmd : 'default'); +} diff --git a/package.json b/package.json index 4cd9b6e..7decc1e 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "bower-directory": "latest", "browser-sync": "latest", "browserify": "latest", + "browserify-ngannotate": "latest", "browserify-transform-tools": "latest", "chalk": "latest", "combined-stream": "latest", @@ -69,13 +70,12 @@ "lodash.defaults": "latest", "lodash.flatten": "latest", "lodash.merge": "latest", - "lodash.template": "latest", "lodash.reduce": "latest", + "lodash.template": "latest", "mime": "latest", "minifyify": "latest", "minimatch": "latest", "mold-source-map": "latest", - "browserify-ngannotate": "latest", "node-bourbon": "latest", "node-sass": "latest", "pretty-hrtime": "latest", @@ -90,7 +90,8 @@ "stream-spigot": "latest", "stringify": "latest", "through-pipes": "latest", - "through2": "latest" + "through2": "latest", + "yargs": "latest" }, "devDependencies": { "jasmine-node": "latest", From 5bab1648c94c1032a87b6e39e5ee43e7895e704f Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Tue, 27 Jan 2015 15:15:37 +1100 Subject: [PATCH 2/3] =BG= server task uses port number from cli options generate task created, used name from cli options --- bin/cli-args.js | 17 ++++++++++++----- bin/cli.js | 12 ++++-------- tasks/generate.js | 9 +++++++++ tasks/server.js | 6 ++++-- tasks/watch.js | 3 +-- 5 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 tasks/generate.js diff --git a/bin/cli-args.js b/bin/cli-args.js index ad4f78f..e3b5833 100644 --- a/bin/cli-args.js +++ b/bin/cli-args.js @@ -1,11 +1,18 @@ +'use strict'; + var yargs = require('yargs'); +var config = require('../lib/config/config'); + var args = yargs .describe('p', 'Define a port number when serving files') .alias('p', 'port') - .default('p', 10101) - .describe('v', 'Version number') + .default('p', config.getServerHttpPort()) + .describe('v', 'Display version number') .alias('v', 'version') .boolean('v') - .usage() - .wrap(80); -module.exports = yargs; + .describe('n', 'Name of the project to create or work on') + .alias('n', 'name') + .string('n') + .usage('Angularity is an opinionated build tool for AngularJs projects.') + .wrap(config.getConsoleWidth()); +module.exports = args; diff --git a/bin/cli.js b/bin/cli.js index 0099535..de1b208 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -14,7 +14,6 @@ var path = require('path'), prettyTime = require('pretty-hrtime'); var mainMenu = require('../lib/cli/mainMenu'); - require('../index'); var generator = require('../lib/generator/generator'); @@ -36,19 +35,16 @@ gulp.on('task_stop', function (e) { // gulp tasks can access argv using this same method var argv = require('./cli-args').argv; -var subCmd = (argv._.length > 0) ? argv._[0] : undefined; +var taskName = (!!argv._) ? argv._[0] : undefined; -if (argv.v) { +if (argv.version) {argv._ var packagePath = path.join(__dirname, '..', 'package.json'); var version = require(packagePath).version; console.log('angularity:', version); } -else if (!subCmd) { +else if (!taskName) { mainMenu.prompt(); } -else if (subCmd === 'generate') { - generator.util.generateProject(argv._[1]); -} else { - gulp.start(gulp.hasTask(subCmd) ? subCmd : 'default'); + gulp.start(gulp.hasTask(taskName) ? taskName : 'default'); } diff --git a/tasks/generate.js b/tasks/generate.js new file mode 100644 index 0000000..3c66646 --- /dev/null +++ b/tasks/generate.js @@ -0,0 +1,9 @@ +'use strict'; + +var gulp = require('gulp'); +var argv = require('../bin/cli-args').argv; +var generator = require('../lib/generator/generator'); + +gulp.task('generate', [], function() { + generator.util.generateProject(argv.name); +}); diff --git a/tasks/server.js b/tasks/server.js index 0134d5a..325228a 100644 --- a/tasks/server.js +++ b/tasks/server.js @@ -8,7 +8,9 @@ var config = require('../lib/config/config'), hr = require('../lib/util/hr'), streams = require('../lib/config/streams'); -var HTTP_PORT = config.getServerHttpPort(); +var argv = require('../bin/cli-args').argv; + +var HTTP_PORT = argv.port; var CONSOLE_WIDTH = config.getConsoleWidth(); gulp.task('server', ['build'], function () { @@ -29,4 +31,4 @@ gulp.task('reload', function () { console.log(hr('-', CONSOLE_WIDTH, 'reload')); gutil.log('serving on port:', HTTP_PORT); browserSync.reload(); -}); \ No newline at end of file +}); diff --git a/tasks/watch.js b/tasks/watch.js index f608523..7279442 100644 --- a/tasks/watch.js +++ b/tasks/watch.js @@ -11,7 +11,6 @@ var config = require('../lib/config/config'), var CONSOLE_WIDTH = config.getConsoleWidth(); gulp.task('watch', ['server'], function () { - // enqueue actions to avoid multiple trigger var queue = watchSequence(500, function () { console.log(hr('\u2591', CONSOLE_WIDTH)); @@ -42,4 +41,4 @@ gulp.task('watch', ['server'], function () { name : 'TEST', emitOnGlob: false }, queue.getHandler('test')); -}); \ No newline at end of file +}); From cf818912ee794d89fbfa2942a1a16f73a1f4d161 Mon Sep 17 00:00:00 2001 From: Brendan Graetz Date: Tue, 27 Jan 2015 15:33:12 +1100 Subject: [PATCH 3/3] =BG= minor --- bin/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index de1b208..baadf8f 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -37,7 +37,7 @@ var argv = require('./cli-args').argv; var taskName = (!!argv._) ? argv._[0] : undefined; -if (argv.version) {argv._ +if (argv.version) { var packagePath = path.join(__dirname, '..', 'package.json'); var version = require(packagePath).version; console.log('angularity:', version);