Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using Node.js to create simple build tools. In this case, 'concat.js' which concatenates JS files (or, really any text files).
var fs = require('fs');
var os = require('os');
var program = require('commander');
var importList = [];
//Options -- also sets up automatic --help message/usage info
.option('-f, --filelist [txtfile]', 'use an input file with a comma separated list of files to concat')
.option('-s, --files [files]', 'specify the files to concat in the option')
.option('-d, --dest [dest]', 'the destination file')
//does the actual concatenating work
function concat(list, destPath) {
var out ={
var current = filePath.trim();
return fs.readFileSync(current);
fs.writeFileSync(destPath, out.join(os.EOL));
console.log(' '+ destPath +' built.');
// do we need to display the help?
if (!program.filelist && !program.files || !program.dest) {; // exits automatically
// the js files are listed in a text file
if (program.filelist) {
var string = fs.readFileSync(program.filelist).toString();
//TODO replace EOL's with ',' so that either could be used.
importList = string.split(',');
// there are js files on the command line.
if (program.files) {
var list = program.files.split(',');
// supports both a list file and command line, but list file goes first.
importList = importList.concat(list);
// go.
concat(importList, program.dest.trim());
Copy link

tripleshotsw commented Feb 11, 2013

You'll need commander:
$ npm install commander

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment