-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from davidchambers/sanctuary-scripts
- Loading branch information
Showing
4 changed files
with
218 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,58 @@ | ||
'use strict'; | ||
|
||
var program = require('commander'); | ||
var program = require ('commander'); | ||
|
||
var doctest = require('..'); | ||
var pkg = require('../package.json'); | ||
var doctest = require ('..'); | ||
var pkg = require ('../package.json'); | ||
|
||
|
||
program | ||
.version(pkg.version) | ||
.usage('[options] path/to/js/or/coffee/module') | ||
.option('-m, --module <type>', 'specify module system ("amd" or "commonjs")') | ||
.option(' --nodejs <options>', 'pass options directly to the "node" binary') | ||
.option(' --prefix <prefix>', 'specify Transcribe-style prefix (e.g. ".")') | ||
.option('-p, --print', 'output the rewritten source without running tests') | ||
.option('-s, --silent', 'suppress output') | ||
.option('-t, --type <type>', 'specify file type ("coffee" or "js")') | ||
.parse(process.argv); | ||
.version (pkg.version) | ||
.usage ('[options] path/to/js/or/coffee/module') | ||
.option ('-m, --module <type>', | ||
'specify module system ("amd" or "commonjs")') | ||
.option (' --nodejs <options>', | ||
'pass options directly to the "node" binary') | ||
.option (' --prefix <prefix>', | ||
'specify Transcribe-style prefix (e.g. ".")') | ||
.option ('-p, --print', | ||
'output the rewritten source without running tests') | ||
.option ('-s, --silent', | ||
'suppress output') | ||
.option ('-t, --type <type>', | ||
'specify file type ("coffee" or "js")') | ||
.parse (process.argv); | ||
|
||
// formatErrors :: Array String -> String | ||
function formatErrors(errors) { | ||
return errors.map(function(s) { return 'error: ' + s + '\n'; }).join(''); | ||
return (errors.map (function(s) { return 'error: ' + s + '\n'; })).join (''); | ||
} | ||
|
||
var errors = []; | ||
if (program.module != null && | ||
program.module !== 'amd' && | ||
program.module !== 'commonjs') { | ||
errors.push('Invalid module `' + program.module + "'"); | ||
errors.push ('Invalid module `' + program.module + "'"); | ||
} | ||
if (program.type != null && | ||
program.type !== 'coffee' && | ||
program.type !== 'js') { | ||
errors.push('Invalid type `' + program.type + "'"); | ||
errors.push ('Invalid type `' + program.type + "'"); | ||
} | ||
if (errors.length > 0) { | ||
process.stderr.write(formatErrors(errors)); | ||
process.exit(1); | ||
process.stderr.write (formatErrors (errors)); | ||
process.exit (1); | ||
} | ||
|
||
process.exit(program.args.reduce(function(status, path) { | ||
process.exit (program.args.reduce (function(status, path) { | ||
var results; | ||
try { | ||
results = doctest(path, program); | ||
results = doctest (path, program); | ||
} catch (err) { | ||
process.stderr.write(formatErrors([err.message])); | ||
process.exit(1); | ||
process.stderr.write (formatErrors ([err.message])); | ||
process.exit (1); | ||
} | ||
return results.reduce(function(status, tuple) { | ||
return results.reduce (function(status, tuple) { | ||
return tuple[0] ? status : 1; | ||
}, status); | ||
}, 0)); |
Oops, something went wrong.