Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
extracted args-parse.js to ender-args-parser lib
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Dec 27, 2012
1 parent ae728d8 commit 10d060f
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 570 deletions.
203 changes: 0 additions & 203 deletions lib/args-parse.js

This file was deleted.

6 changes: 3 additions & 3 deletions lib/main-add.js
Expand Up @@ -32,8 +32,8 @@
* module which does all the hard work. * module which does all the hard work.
*/ */


var util = require('./util') var argsParser = require('ender-args-parser')
, argsParse = require('./args-parse') , util = require('./util')
, parseContext = require('./parse-context') , parseContext = require('./parse-context')
, mainBuild = require('./main-build') , mainBuild = require('./main-build')


Expand All @@ -43,7 +43,7 @@ var util = require('./util')
parseContext(filename, function (err, context) { parseContext(filename, function (err, context) {
if (err) return callback(err) // err wrapped in SourceBuild.parseContext() if (err) return callback(err) // err wrapped in SourceBuild.parseContext()
// merge commandline args with the build command in ender.js // merge commandline args with the build command in ender.js
options = argsParse.extend(context.options, options) options = argsParser.extend(context.options, options)
mainBuild.exec(options, out, callback) mainBuild.exec(options, out, callback)
}) })
} }
Expand Down
6 changes: 3 additions & 3 deletions lib/main-remove.js
Expand Up @@ -35,9 +35,9 @@


var async = require('async') var async = require('async')
, repository = require('ender-repository') , repository = require('ender-repository')
, argsParser = require('ender-args-parser')
, util = require('./util') , util = require('./util')
, mainBuild = require('./main-build') , mainBuild = require('./main-build')
, argsParse = require('./args-parse')
, mainBuildUtil = require('./main-build-util') , mainBuildUtil = require('./main-build-util')
, parseContext = require('./parse-context') , parseContext = require('./parse-context')


Expand All @@ -52,13 +52,13 @@ var async = require('async')
} }


; delete options.use // don't want --use showing up in the 'Build:' context string ; delete options.use // don't want --use showing up in the 'Build:' context string
options.packages = [] // reset the packages list so argsParse.extend() doesn't include them options.packages = [] // reset the packages list so argsParser.extend() doesn't include them


parseContext(filename, function (err, context) { parseContext(filename, function (err, context) {
if (err) return callback(err) // wrapped in source-build.js if (err) return callback(err) // wrapped in source-build.js


// merge the commandline with the ender.js build command // merge the commandline with the ender.js build command
options = argsParse.extend(context.options, options) options = argsParser.extend(context.options, options)
options.packages = options.packages.filter(function (p) { options.packages = options.packages.filter(function (p) {
return packages.indexOf(p) == -1 // do the remove! return packages.indexOf(p) == -1 // do the remove!
}) })
Expand Down
7 changes: 3 additions & 4 deletions lib/main.js
Expand Up @@ -42,9 +42,8 @@
process.title = 'Ender' process.title = 'Ender'


var sysUtil = require('util') var sysUtil = require('util')
, argsParser = require('ender-args-parser')
, Output = require('./output/output') , Output = require('./output/output')
, argsParse = require('./args-parse')
, EnderError = require('./errors').EnderError


// basic error handler, differentiates between 'known' EnderErrors and everything else // basic error handler, differentiates between 'known' EnderErrors and everything else
, complete = function (out, callback, err) { , complete = function (out, callback, err) {
Expand All @@ -66,15 +65,15 @@ var sysUtil = require('util')
} }


try { try {
options = argsParse[parseType](argv) options = argsParser[parseType](argv)


// get the module to execute and it's partner output module // get the module to execute and it's partner output module
exe = options && require('./main-' + options.main) exe = options && require('./main-' + options.main)
out = options && require('./output/main-' + options.main + '-output').create(sysUtil, options.debug, options.quiet) out = options && require('./output/main-' + options.main + '-output').create(sysUtil, options.debug, options.quiet)


if (exe && out) { if (exe && out) {
exe.exec(options, out, complete.bind(null, out, callback)) exe.exec(options, out, complete.bind(null, out, callback))
} // else err? argsParse should take care of this if it's list of mains corresponds to the modules we have } // else err? argsParser should take care of this if it's list of mains corresponds to the modules we have
} catch (ex) { } catch (ex) {
// create a generic/base 'out' module which can do the error printing // create a generic/base 'out' module which can do the error printing
out = Output.create(sysUtil, argv.indexOf('--debug') != -1) out = Output.create(sysUtil, argv.indexOf('--debug') != -1)
Expand Down
14 changes: 7 additions & 7 deletions lib/output/main-info-output.js
Expand Up @@ -23,12 +23,12 @@
*/ */




var archy = require('archy') var archy = require('archy')
, colors = require('colors') , colors = require('colors')
, extend = require('../util').extend , argsParser = require('ender-args-parser')
, toKb = require('../util').toKb , extend = require('../util').extend
, Output = require('./output') , toKb = require('../util').toKb
, argsParse = require('../args-parse') , Output = require('./output')


, InfoOutput = extend(Output, { // inherit from Output , InfoOutput = extend(Output, { // inherit from Output


Expand All @@ -45,7 +45,7 @@ var archy = require('archy')
prepareTree(archyTree) prepareTree(archyTree)


//this.log('Your current build type is ' + ('"' + options.main + '"').yellow) //this.log('Your current build type is ' + ('"' + options.main + '"').yellow)
this.log('Your current build command is: ' + ('ender ' + argsParse.toContextString(options)).yellow) this.log('Your current build command is: ' + ('ender ' + argsParser.toContextString(options)).yellow)
this.log( this.log(
'Your current build size is: ' 'Your current build size is: '
+ toKb(sizes.raw).yellow + ' raw' + toKb(sizes.raw).yellow + ' raw'
Expand Down
6 changes: 3 additions & 3 deletions lib/parse-context.js
Expand Up @@ -25,11 +25,11 @@
/****************************************************************************** /******************************************************************************
* a utility to partially read an ender build file and parse the head comment * a utility to partially read an ender build file and parse the head comment
* to pull out the 'Build:' and 'Packages:' lines. Returns the build command as a properly * to pull out the 'Build:' and 'Packages:' lines. Returns the build command as a properly
* parsed options object (via argsParse). * parsed options object (via argsParser).
*/ */


const fs = require('fs') const fs = require('fs')
, argsParse = require('./args-parse') , argsParser = require('ender-args-parser')
, FilesystemError = require('./errors').FilesystemError , FilesystemError = require('./errors').FilesystemError
, BuildParseError = require('./errors').BuildParseError , BuildParseError = require('./errors').BuildParseError


Expand All @@ -56,7 +56,7 @@ var parseContext = function (file, callback) {
} }


try { try {
options = argsParse.parseClean(match[1].split(' ')) options = argsParser.parseClean(match[1].split(' '))
} catch (ex) { } catch (ex) {
error = 'Could not parse ender spec from "' + file + '"' error = 'Could not parse ender spec from "' + file + '"'
return callback(new BuildParseError(error, ex)) return callback(new BuildParseError(error, ex))
Expand Down
12 changes: 6 additions & 6 deletions lib/source-build.js
Expand Up @@ -29,11 +29,11 @@
* on the list of SourcePackages. * on the list of SourcePackages.
*/ */


var async = require('async') var async = require('async')
, util = require('./util') , argsParser = require('ender-args-parser')
, minify = require('./minify') , util = require('./util')
, template = require('./template') , minify = require('./minify')
, argsParse = require('./args-parse') , template = require('./template')


, templateFile = '../resources/build.mustache' , templateFile = '../resources/build.mustache'


Expand All @@ -59,7 +59,7 @@ var async = require('async')
, tmplData = function (sources) { , tmplData = function (sources) {
return { return {
source: sources.join('\n\n') source: sources.join('\n\n')
, context: argsParse.toContextString(this.options) , context: argsParser.toContextString(this.options)
, sandbox: !!this.options.sandbox , sandbox: !!this.options.sandbox
, packages: this.packages.map(function (p) { , packages: this.packages.map(function (p) {
return p.identifier return p.identifier
Expand Down
4 changes: 3 additions & 1 deletion package.json
@@ -1,7 +1,7 @@
{ {
"name": "ender" "name": "ender"
, "description": "Open Module JavaScript Framework" , "description": "Open Module JavaScript Framework"
, "version": "0.9.9-dev" , "version": "0.9.10-dev"
, "authors": [ , "authors": [
"Jacob Thornton @fat <jacob@twitter.com> (https://github.com/fat)" "Jacob Thornton @fat <jacob@twitter.com> (https://github.com/fat)"
, "Dustin Diaz @ded <dustin@obvious.com> (https://github.com/ded)" , "Dustin Diaz @ded <dustin@obvious.com> (https://github.com/ded)"
Expand All @@ -15,6 +15,8 @@
, "ender-minify" : "0.1.0" , "ender-minify" : "0.1.0"
, "ender-dependency-graph" , "ender-dependency-graph"
: "0.0.1" : "0.0.1"
, "ender-args-parser"
: "0.0.1"
, "colors" : "~0.6.0" , "colors" : "~0.6.0"
, "async" : "~0.1.22" , "async" : "~0.1.22"
, "hogan.js" : "~2.0.0" , "hogan.js" : "~2.0.0"
Expand Down

0 comments on commit 10d060f

Please sign in to comment.