Skip to content
Browse files

Added mincer script

  • Loading branch information...
1 parent da31335 commit 6dcf86aa3e5f1228d08139ed893d9d42d86a889a @ixti ixti committed May 16, 2012
Showing with 143 additions and 9 deletions.
  1. +134 −0 bin/mincer.js
  2. +9 −9 package.json
View
134 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);
View
18 package.json
@@ -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" }

0 comments on commit 6dcf86a

Please sign in to comment.
Something went wrong with that request. Please try again.