Skip to content

Commit

Permalink
Added mincer script
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed May 16, 2012
1 parent da31335 commit 6dcf86a
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 9 deletions.
134 changes: 134 additions & 0 deletions bin/mincer.js
@@ -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);
18 changes: 9 additions & 9 deletions package.json
Expand Up @@ -13,16 +13,16 @@

"main" : "./index.js",

"scripts" : {
"test": "make test"
},
"bin" : { "ndoc": "bin/mincer.js" },
"scripts" : { "test": "make test" },
"dependencies" : {
"hike": "0.1.0",
"types": "0.1.0",
"mimoza": "0.1.0",
"fs-tools": "0.2.1",
"async": "0.1.15",
"underscore": "1.3.3"
"hike" : "0.1.0",
"types" : "0.1.0",
"mimoza" : "0.1.0",
"argparse" : "0.1.0",
"fs-tools" : "0.2.1",
"async" : "0.1.15",
"underscore" : "1.3.3"
},
"devDependencies" : { "mocha": "1.0.1" },
"engines" : { "node": ">= 0.6.0" }
Expand Down

0 comments on commit 6dcf86a

Please sign in to comment.