├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── lib
├── cli.js
└── index.js
├── package.json
└── templates
├── README.md
├── cli.js
├── gitignore
├── index.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | npm-debug.log
2 | node_modules/
3 | dist/
4 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | lib/
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Luke Horvat
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # module [](https://www.npmjs.org/package/module)
2 |
3 | Generate the minimal skeleton/boilerplate for a new Node.js module.
4 |
5 | ## Installation
6 |
7 | Install the package with NPM:
8 |
9 | ```bash
10 | $ npm install -g module
11 | ```
12 |
13 | ## Usage
14 |
15 | For example, to create a module in the current working directory:
16 |
17 | ```bash
18 | $ module
19 | ```
20 |
21 | And to create a module in another directory, specify a relative or absolute path:
22 |
23 | ```bash
24 | $ module hello
25 | ```
26 |
27 | If the directory doesn't exist yet, it will be automatically created.
28 |
29 | The following boilerplate files are generated for you:
30 |
31 | - `package.json`
32 | - `index.js`
33 | - `cli.js`
34 | - `README.md`
35 | - `.gitignore`
36 |
--------------------------------------------------------------------------------
/lib/cli.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | import module from "./";
4 | import pkg from "../package.json";
5 | import path from "path";
6 | import chalk from "chalk";
7 | import tildify from "tildify";
8 | import yargs from "yargs";
9 |
10 | const {argv} =
11 | yargs
12 | .usage(`Usage: ${chalk.cyan(pkg.name, chalk.underline("
"))}`)
13 | .demand(0, 1, chalk.red("Too many directories specified."))
14 | .option("h", { alias: "help", describe: "Show help", type: "boolean" })
15 | .option("v", { alias: "version", describe: "Show version", type: "boolean" });
16 |
17 | if (argv.help || argv.h) {
18 | yargs.showHelp();
19 | process.exit();
20 | }
21 |
22 | if (argv.version || argv.v) {
23 | console.log(pkg.version);
24 | process.exit();
25 | }
26 |
27 | Promise.resolve(
28 | path.resolve(process.cwd(), argv._.length > 0 ? String(argv._[0]) : ".")
29 | ).then(dir => {
30 | console.log(chalk.green("Creating module..."));
31 | return module(dir);
32 | }).then(files => {
33 | files.map(tildify).forEach(file => console.log(chalk.green("+", file)));
34 | console.log(chalk.green("Module created!"));
35 | process.exit();
36 | }).catch(() => {
37 | console.error(chalk.red("An error occurred."));
38 | process.exit(1);
39 | });
40 |
--------------------------------------------------------------------------------
/lib/index.js:
--------------------------------------------------------------------------------
1 | import path from "path";
2 | import concat from "concat-stream";
3 | import template from "lodash.template";
4 | import map from "map-stream";
5 | import fs from "vinyl-fs";
6 | export default createModule;
7 |
8 | function createModule(dir) {
9 | return new Promise((resolve, reject) => {
10 | fs
11 | .src(path.resolve(__dirname, "..", "templates", "**", "*"), { dot: true })
12 | .pipe(renameFiles({ gitignore: ".gitignore" })) // See: https://github.com/npm/npm/issues/3763
13 | .pipe(templateFiles({ name: path.basename(dir) }))
14 | .once("error", reject)
15 | .pipe(fs.dest(dir))
16 | .pipe(collectFiles(resolve));
17 | });
18 | }
19 |
20 | function renameFiles(renames) {
21 | return map((file, cb) => {
22 | if (file.basename in renames) {
23 | file.basename = renames[file.basename];
24 | }
25 | cb(null, file);
26 | });
27 | }
28 |
29 | function templateFiles(data) {
30 | return map((file, cb) => {
31 | file.contents = new Buffer(template(file.contents)(data));
32 | cb(null, file);
33 | });
34 | }
35 |
36 | function collectFiles(cb) {
37 | return concat(files => cb(files.map(file => file.path)));
38 | }
39 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "module",
3 | "version": "1.2.5",
4 | "description": "Generate the minimal skeleton/boilerplate for a new Node.js module.",
5 | "author": "Luke Horvat",
6 | "license": "MIT",
7 | "repository": {
8 | "type": "git",
9 | "url": "https://github.com/lukehorvat/module.git"
10 | },
11 | "bugs": {
12 | "url": "https://github.com/lukehorvat/module/issues"
13 | },
14 | "main": "./dist/index.js",
15 | "bin": "./dist/cli.js",
16 | "scripts": {
17 | "build": "rimraf dist && babel lib -d dist",
18 | "prepublish": "npm run build"
19 | },
20 | "dependencies": {
21 | "chalk": "1.1.3",
22 | "concat-stream": "1.5.1",
23 | "lodash.template": "4.2.4",
24 | "map-stream": "0.0.6",
25 | "tildify": "1.2.0",
26 | "vinyl-fs": "2.4.3",
27 | "yargs": "4.6.0"
28 | },
29 | "devDependencies": {
30 | "babel-cli": "6.7.5",
31 | "babel-preset-es2015": "6.6.0",
32 | "rimraf": "2.5.2"
33 | },
34 | "keywords": [
35 | "npm",
36 | "node",
37 | "module",
38 | "package",
39 | "skeleton",
40 | "boilerplate",
41 | "scaffold",
42 | "generator",
43 | "generic",
44 | "cli"
45 | ],
46 | "babel": {
47 | "presets": [
48 | "es2015"
49 | ]
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/templates/README.md:
--------------------------------------------------------------------------------
1 | # <%= name %>
2 |
3 | TODO.
4 |
--------------------------------------------------------------------------------
/templates/cli.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | "use strict";
4 |
5 | var fn = require("./");
6 | fn();
7 |
--------------------------------------------------------------------------------
/templates/gitignore:
--------------------------------------------------------------------------------
1 | npm-debug.log
2 | node_modules/
3 |
--------------------------------------------------------------------------------
/templates/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | module.exports = function() {
4 | console.log("<%= name %>");
5 | };
6 |
--------------------------------------------------------------------------------
/templates/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "name": "<%= name %>",
4 | "version": "0.0.0",
5 | "main": "./index.js",
6 | "bin": "./cli.js",
7 | "dependencies": {},
8 | "devDependencies": {}
9 | }
10 |
--------------------------------------------------------------------------------