l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

import (1404B)


      1 #!/usr/bin/env node
      2 
      3 var optimist = require('optimist'),
      4 	importFile = require('./index.js');
      5 
      6 	var argv = optimist
      7 		.usage(
      8 			  "Usage: \033[1mimport\033[0m [options] [file …]\n\n"
      9 			+ "Version: 0.0.5\n\n"
     10 			+ "Minimized fork of smash.\n"
     11 			+ "Concatenates one or more input files, outputting a single merged file.\n"
     12 			+ "Any import statements in the input files are expanded in-place to the\n"
     13 			+ "contents of the imported file. If the same file is imported multiple\n"
     14 			+ "times, only the first instance of the file is included."
     15 		)
     16 		.options("list", {
     17 			describe: "output a list of imported files",
     18 			type: "boolean",
     19 			default: false
     20 		})
     21 		.options("delimiter", {
     22 			describe: "specify the delimiter used for concatenating files",
     23 			type: "string",
     24 			default: "\n"
     25 		})
     26 		.options("ignore-missing", {
     27 			describe: "ignore missing files instead of throwing an error",
     28 			type: "boolean",
     29 			default: false
     30 		})
     31 		.options("help", {
     32 			describe: "display this helpful message",
     33 			type: "boolean",
     34 			default: false
     35 		})
     36 		.check(function(argv) {
     37 			if (argv.help){ return optimist.showHelp(); }
     38 			if (!argv._.length){ throw new Error("input required"); }
     39 			if (argv.list && argv.graph){ throw new Error("--list and --graph are exclusive"); }
     40 		})
     41 		.argv;
     42 
     43 // Output to stdout
     44 console.log( argv._.map(function(fileName){
     45 	return importFile(fileName);
     46 }).join(argv.delimiter) );