UNPKG

1.36 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3"use strict";
4
5var pkg = require("./package.json");
6var path = require("path");
7var chalk = require("chalk");
8var template = require("lodash.template");
9var map = require("map-stream");
10var tildify = require("tildify");
11var vfs = require("vinyl-fs");
12var yargs = require("yargs");
13var 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
20if (argv.help || argv.h) {
21 yargs.showHelp();
22 process.exit();
23}
24
25if (argv.version || argv.v) {
26 console.log(pkg.version);
27 process.exit();
28}
29
30var dir = process.cwd();
31if (argv._.length > 0) {
32 dir = path.resolve(dir, argv._[0]);
33}
34
35console.log(chalk.green("Creating module..."));
36
37vfs
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 });