From eb0e2a3d96dda12dd47b849b6aff5ad9e10a77f5 Mon Sep 17 00:00:00 2001 From: Larz Conwell Date: Tue, 26 Jun 2012 13:58:20 -0400 Subject: [PATCH] Added help dialog to exec and make sure the CD is a Git repo --- bin/auto_npm.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/bin/auto_npm.js b/bin/auto_npm.js index 908ba84..84f6400 100644 --- a/bin/auto_npm.js +++ b/bin/auto_npm.js @@ -1 +1,67 @@ #!/usr/bin/env node + +var fs = require('fs') + , path = require('path') + , package = require('../package') + , cd = process.cwd() + , args = process.argv.slice(2) + , enabled = false + , gitDir + , help + , arg; + +// +// Help dialog +help = [ + '' + , package.name + ' ' + package.version + , '' + , 'Description' + , ' ' + package.description + , '' + , 'Usage' + , ' --enable, -e # Enable Auto NPM in a git repo' + , ' --disable, -d # Disable Auto NPM in a git repo' + , ' --help, -h # Dipslay this help dialog' +].join('\n'); + +// Show help dialog if no args are given +if(args.length === 0) { + console.log(help); + process.exit(0); +} + +// +// Get arguments +while(args.length) { + arg = args.shift(); + + switch(arg) { + case '-h': + case '--help': + console.log(help); + process.exit(0); + break; + case '-e': + case '--enable': + enabled = true; + break; + case '-d': + case '--disable': + enabled = false; + break; + } +} + +// +// Check if directory is a Git repo +gitDir = path.existsSync(path.join(cd, '.git')); +if(!gitDir) throw new Error('The Directory "' + cd + '" is not a git repo.'); + +// +// Enable Auto NPM or disable it +if(enabled) { + // Start watching for commits +} else { + // Disable watching for commits +} diff --git a/package.json b/package.json index bd9d623..2c9cf1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Auto NPM" - , "description": "Automatically updated NPM packages when you submit a commit" + , "description": "Automatically updated NPM packages when you submit a commit that updates the version number in `package.json`" , "keywords": [ "git" , "commit"