Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
143 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
|
||
// stdlib | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
|
||
// 3rd-party | ||
var ArgumentParser = require('argparse').ArgumentParser; | ||
|
||
|
||
// internal | ||
var Mincer = require('..'); | ||
var shellwords = require('../lib/mincer/common').shellwords; | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
var cli = new ArgumentParser({ | ||
prog: 'mincer', | ||
version: require('../package.json').version, | ||
addHelp: true | ||
}); | ||
|
||
|
||
cli.addArgument(['--noenv'], { | ||
help: 'Disables .mincerrc file', | ||
action: 'storeTrue' | ||
}); | ||
|
||
cli.addArgument(['-I', '--include'], { | ||
help: 'Adds the directory to the Mincer load path', | ||
metavar: 'DIRECTORY', | ||
action: 'append', | ||
required: true | ||
}); | ||
|
||
cli.addArgument(['-o', '--output'], { | ||
help: 'Copy provided assets into DIRECTORY', | ||
metavar: 'DIRECTORY' | ||
}); | ||
|
||
cli.addArgument(['filenames'], { | ||
help: 'File(s) to process', | ||
metavar: 'FILE', | ||
nargs: '+' | ||
}); | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
if (-1 === process.argv.indexOf('--noenv')) { | ||
if (path.existsSync('./.mincerrc')) { | ||
var rcflags = shellwords(fs.readFileSync('./.mincerrc', 'utf8')); | ||
process.argv = process.argv.concat(rcflags); | ||
} | ||
} | ||
|
||
|
||
var args = cli.parseArgs(); | ||
var environment = new Mincer.Environment(process.cwd()); | ||
var filenames = []; | ||
|
||
|
||
(process.env.MINCER_PATH || '').split(':').forEach(function (path) { | ||
if (path) { | ||
environment.appendPath(path); | ||
} | ||
}); | ||
|
||
args.include.forEach(function (path) { | ||
environment.appendPath(path); | ||
}); | ||
|
||
args.filenames.forEach(function (file) { | ||
filenames.push(path.normalize(file)); | ||
}); | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
// | ||
// Configure Mincer logger | ||
// | ||
|
||
|
||
Mincer.logger.use(console); | ||
|
||
|
||
// | ||
// Compiling manifest with bunch of files | ||
// | ||
|
||
|
||
if (args.output) { | ||
var manifest = new Mincer.Manifest(environment, args.output); | ||
manifest.compile(filenames, function (err) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
}); | ||
return; | ||
} | ||
|
||
|
||
if (1 === filenames.length) { | ||
var asset = environment.findAsset(filenames[0]); | ||
|
||
if (!asset) { | ||
console.error("Cannot find logical path: " + filenames[0]); | ||
process.exit(1); | ||
} | ||
|
||
asset.compile(function (err) { | ||
if (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
|
||
process.stdout.write(asset.toString()); | ||
}); | ||
return; | ||
} | ||
|
||
|
||
console.error("Only one file can be compiled to stdout at a time"); | ||
process.exit(1); |
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