1 | #!/usr/bin/env node
|
2 |
|
3 | "use strict";
|
4 |
|
5 | var pkg = require("./package.json");
|
6 | var path = require("path");
|
7 | var chalk = require("chalk");
|
8 | var template = require("lodash.template");
|
9 | var map = require("map-stream");
|
10 | var tildify = require("tildify");
|
11 | var vfs = require("vinyl-fs");
|
12 | var yargs = require("yargs");
|
13 | var argv = yargs
|
14 | .usage("Usage: $0 <dir>")
|
15 | .demand(0, 1)
|
16 | .option("h", { alias: "help", describe: "Show help" })
|
17 | .option("v", { alias: "version", describe: "Show version" })
|
18 | .argv;
|
19 |
|
20 | if (argv.help || argv.h) {
|
21 | yargs.showHelp();
|
22 | process.exit();
|
23 | }
|
24 |
|
25 | if (argv.version || argv.v) {
|
26 | console.log(pkg.version);
|
27 | process.exit();
|
28 | }
|
29 |
|
30 | var dir = process.cwd();
|
31 | if (argv._.length > 0) {
|
32 | dir = path.resolve(dir, argv._[0]);
|
33 | }
|
34 |
|
35 | console.log(chalk.green("Creating module..."));
|
36 |
|
37 | vfs
|
38 | .src(path.join(__dirname, "templates", "**", "*"), { dot: true })
|
39 | .pipe(map(function(file, callback) {
|
40 | file.contents = new Buffer(template(file.contents)({ name: path.basename(dir) }));
|
41 | callback(null, file);
|
42 | }))
|
43 | .once("error", function() {
|
44 | console.error(chalk.red("An error occurred."));
|
45 | process.exit(1);
|
46 | })
|
47 | .pipe(vfs.dest(dir))
|
48 | .pipe(map(function(file, callback) {
|
49 | console.log(chalk.green("+", tildify(file.path)));
|
50 | callback();
|
51 | }))
|
52 | .once("end", function() {
|
53 | console.log(chalk.green("Module created!"));
|
54 | process.exit();
|
55 | });
|