├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── index.js ├── package.json ├── test ├── app.boilerplate.js └── fixtures │ ├── a.txt │ ├── b.txt │ ├── c.txt │ └── example.txt └── utils.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | 10 | # npm 11 | node_modules 12 | npm-debug.log 13 | 14 | # misc 15 | _gh_pages 16 | benchmark 17 | bower_components 18 | vendor 19 | temp 20 | tmp 21 | TODO.md 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '6' 5 | - '5' 6 | - '4' 7 | - '0.12' 8 | - '0.10' 9 | matrix: 10 | fast_finish: true 11 | allow_failures: 12 | - node_js: '4' 13 | - node_js: '0.10' 14 | - node_js: '0.12' 15 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | var boilerplate = require('{%= name %}'); 5 | var App = require('base-app'); 6 | var app = new App(); 7 | app.use(boilerplate()); 8 | ``` 9 | 10 | ## Example 11 | 12 | **Download h5bp** 13 | 14 | To run the example, first you'll need to git clone [html5-boilerplate](https://github.com/h5bp/html5-boilerplate) with the following command: 15 | 16 | ```js 17 | $ git clone https://github.com/h5bp/html5-boilerplate.git vendor/h5bp 18 | ``` 19 | 20 | **Configuration** 21 | 22 | The following examples returns a normalized configuration object that includes every file in the [html5-boilerplate](https://github.com/h5bp/html5-boilerplate) project, organized exactly the way the project itself is organized. 23 | 24 | ```js 25 | var Boilerplate = require('boilerplate'); 26 | var boilerplate = new Boilerplate({ 27 | options: { 28 | cwd: 'vendor/h5bp/dist', 29 | destBase: 'src' 30 | }, 31 | site: { 32 | root: {src: ['{.*,*.*}'], dest: 'root'}, 33 | css: {src: ['css/*.css'], dest: 'assets/css'}, 34 | js: {src: ['js/**/*.js'], dest: 'assets/js'}, 35 | doc: {src: ['doc/*.md'], dest: 'docs'} 36 | }, 37 | }); 38 | ``` 39 | 40 | **Generate** 41 | 42 | Pass the configuration to the `.boilerplate` or `.boilerplateStream` method to "build" the boilerplate. In this example we're not doing any additional processing, so the source files will simply be copied to the specified destination directories. 43 | 44 | ```js 45 | // stream 46 | app.boilerplateStream(boilerplate) 47 | .on('end', function() { 48 | console.log('done'); 49 | }); 50 | 51 | // async callback 52 | app.boilerplate(boilerplate, function(err) { 53 | if (err) return console.error(err); 54 | console.log('done'); 55 | }); 56 | ``` 57 | 58 | ## API 59 | {%= apidocs("index.js") %} 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016, Jon Schlinkert. 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # base-boilerplate [![NPM version](https://img.shields.io/npm/v/base-boilerplate.svg?style=flat)](https://www.npmjs.com/package/base-boilerplate) [![NPM downloads](https://img.shields.io/npm/dm/base-boilerplate.svg?style=flat)](https://npmjs.org/package/base-boilerplate) [![Build Status](https://img.shields.io/travis/node-base/base-boilerplate.svg?style=flat)](https://travis-ci.org/node-base/base-boilerplate) 2 | 3 | Plugin that adds support for generating project files from a declarative boilerplate configuration. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save base-boilerplate 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | var boilerplate = require('base-boilerplate'); 17 | var App = require('base-app'); 18 | var app = new App(); 19 | app.use(boilerplate()); 20 | ``` 21 | 22 | ## Example 23 | 24 | **Download h5bp** 25 | 26 | To run the example, first you'll need to git clone [html5-boilerplate](https://github.com/h5bp/html5-boilerplate) with the following command: 27 | 28 | ```js 29 | $ git clone https://github.com/h5bp/html5-boilerplate.git vendor/h5bp 30 | ``` 31 | 32 | **Configuration** 33 | 34 | The following examples returns a normalized configuration object that includes every file in the [html5-boilerplate](https://github.com/h5bp/html5-boilerplate) project, organized exactly the way the project itself is organized. 35 | 36 | ```js 37 | var Boilerplate = require('boilerplate'); 38 | var boilerplate = new Boilerplate({ 39 | options: { 40 | cwd: 'vendor/h5bp/dist', 41 | destBase: 'src' 42 | }, 43 | site: { 44 | root: {src: ['{.*,*.*}'], dest: 'root'}, 45 | css: {src: ['css/*.css'], dest: 'assets/css'}, 46 | js: {src: ['js/**/*.js'], dest: 'assets/js'}, 47 | doc: {src: ['doc/*.md'], dest: 'docs'} 48 | }, 49 | }); 50 | ``` 51 | 52 | **Generate** 53 | 54 | Pass the configuration to the `.boilerplate` or `.boilerplateStream` method to "build" the boilerplate. In this example we're not doing any additional processing, so the source files will simply be copied to the specified destination directories. 55 | 56 | ```js 57 | // stream 58 | app.boilerplateStream(boilerplate) 59 | .on('end', function() { 60 | console.log('done'); 61 | }); 62 | 63 | // async callback 64 | app.boilerplate(boilerplate, function(err) { 65 | if (err) return console.error(err); 66 | console.log('done'); 67 | }); 68 | ``` 69 | 70 | ## API 71 | 72 | ### [.boilerplate](index.js#L64) 73 | 74 | Get boilerplate `name` from `app.boilerplates`, or set boilerplate `name` with the given `config`. 75 | 76 | **Params** 77 | 78 | * `name` **{String|Object|Function}** 79 | * `config` **{Object|Fucntion}** 80 | * `returns` **{Object}**: Returns the app instance when setting a boilerplate, or the boilerplate instance when getting a boilerplate. 81 | 82 | **Example** 83 | 84 | ```js 85 | app.boilerplate('foo', { 86 | docs: { 87 | options: {}, 88 | files: { 89 | src: ['*'], 90 | dest: 'foo' 91 | } 92 | } 93 | }); 94 | 95 | // or 96 | var boilerplate = app.boilerplate('foo'); 97 | ``` 98 | 99 | **Params** 100 | 101 | * `name` **{String}** 102 | * `config` **{Object|Function}** 103 | 104 | **Example** 105 | 106 | ```js 107 | app.addBoilerplate('foo', { 108 | docs: { 109 | options: {}, 110 | files: { 111 | src: ['*'], 112 | dest: 'foo' 113 | } 114 | } 115 | }); 116 | ``` 117 | 118 | **Params** 119 | 120 | * `name` **{String}** 121 | * `options` **{Object}** 122 | 123 | **Example** 124 | 125 | ```js 126 | var boilerplate = app.getBoilerplate('foo'); 127 | 128 | // or create an instance of `Boilerplate` using the given object 129 | var boilerplate = app.getBoilerplate({ 130 | docs: { 131 | options: {}, 132 | files: { 133 | src: ['*'], 134 | dest: 'foo' 135 | } 136 | } 137 | }); 138 | ``` 139 | 140 | ### [`.isBoilerplate](index.js#L217) 141 | 142 | Returns true if the given value is a valid [Boilerplate](https://github.com/jonschlinkert/boilerplate). 143 | 144 | **Params** 145 | 146 | * `val` **{any}** 147 | * `returns` **{Boolean}** 148 | 149 | **Example** 150 | 151 | ```js 152 | isBoilerplate('a'); 153 | //=> false 154 | isBoilerplate({}); 155 | //=> false 156 | isBoilerplate({ files: [] }) 157 | //=> false 158 | isBoilerplate(new Boilerplate({ src: ['*.js'] })) 159 | //=> true 160 | ``` 161 | 162 | ### [Boilerplate](index.js#L234) 163 | 164 | Get or set the `Boilerplate` constructor. Exposed as a getter/setter to allow it to be customized before or after instantiation. 165 | 166 | **Example** 167 | 168 | ```js 169 | // set 170 | app.Boilerplate = function MyBoilerplateCtor() {}; 171 | 172 | // get 173 | var scaffold = new app.Boilerplate(); 174 | ``` 175 | 176 | ## About 177 | 178 | ### Related projects 179 | 180 | * [base-generators](https://www.npmjs.com/package/base-generators): Adds project-generator support to your `base` application. | [homepage](https://github.com/node-base/base-generators "Adds project-generator support to your `base` application.") 181 | * [base-scaffold](https://www.npmjs.com/package/base-scaffold): Base plugin that adds support for generating files from a declarative scaffold configuration. | [homepage](https://github.com/node-base/base-scaffold "Base plugin that adds support for generating files from a declarative scaffold configuration.") 182 | * [base-task](https://www.npmjs.com/package/base-task): base plugin that provides a very thin wrapper around [https://github.com/doowb/composer](https://github.com/doowb/composer) for adding task methods to… [more](https://github.com/node-base/base-task) | [homepage](https://github.com/node-base/base-task "base plugin that provides a very thin wrapper around for adding task methods to your application.") 183 | * [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://github.com/node-base/base) | [homepage](https://github.com/node-base/base "base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.") 184 | 185 | ### Contributing 186 | 187 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 188 | 189 | ### Building docs 190 | 191 | _(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ 192 | 193 | To generate the readme and API documentation with [verb](https://github.com/verbose/verb): 194 | 195 | ```sh 196 | $ npm install -g verb verb-generate-readme && verb 197 | ``` 198 | 199 | ### Running tests 200 | 201 | Install dev dependencies: 202 | 203 | ```sh 204 | $ npm install -d && npm test 205 | ``` 206 | 207 | ### Author 208 | 209 | **Jon Schlinkert** 210 | 211 | * [github/jonschlinkert](https://github.com/jonschlinkert) 212 | * [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 213 | 214 | ### License 215 | 216 | Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). 217 | Released under the [MIT license](https://github.com/node-base/base-boilerplate/blob/master/LICENSE). 218 | 219 | *** 220 | 221 | _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on July 21, 2016._ -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * base-boilerplate (https://github.com/node-base/base-boilerplate) 3 | * 4 | * Copyright (c) 2016, Jon Schlinkert. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var debug = require('debug')('base-boilerplate'); 11 | var utils = require('./utils'); 12 | 13 | module.exports = function(config) { 14 | return function fn(app) { 15 | if (!utils.isValid(app, 'base-boilerplate')) return; 16 | debug('initializing base-boilerplate from <%s>', __filename); 17 | 18 | /** 19 | * Boilerplate cache 20 | */ 21 | 22 | this.boilerplates = this.boilerplates || {}; 23 | var Boilerplate; 24 | 25 | /** 26 | * Register plugins 27 | */ 28 | 29 | this.use(utils.pipeline()); 30 | this.use(utils.scaffold()); 31 | this.use(utils.plugins()); 32 | 33 | /** 34 | * Add methods to the API 35 | */ 36 | 37 | this.define({ 38 | 39 | /** 40 | * Get boilerplate `name` from `app.boilerplates`, or set boilerplate `name` with the given 41 | * `config`. 42 | * 43 | * ```js 44 | * app.boilerplate('foo', { 45 | * docs: { 46 | * options: {}, 47 | * files: { 48 | * src: ['*'], 49 | * dest: 'foo' 50 | * } 51 | * } 52 | * }); 53 | * 54 | * // or 55 | * var boilerplate = app.boilerplate('foo'); 56 | * ``` 57 | * @name .boilerplate 58 | * @param {String|Object|Function} `name` 59 | * @param {Object|Fucntion} `config` 60 | * @return {Object} Returns the app instance when setting a boilerplate, or the boilerplate instance when getting a boilerplate. 61 | * @api public 62 | */ 63 | 64 | boilerplate: function(name, config) { 65 | if (!config && typeof name === 'string' || utils.isObject(name)) { 66 | return this.getBoilerplate(name); 67 | } 68 | this.setBoilerplate.apply(this, arguments); 69 | if (typeof name === 'string') { 70 | return this.getBoilerplate(name); 71 | } 72 | return this; 73 | }, 74 | 75 | /** 76 | * Add boilerplate `name` to `app.boilerplates`. 77 | * 78 | * ```js 79 | * app.addBoilerplate('foo', { 80 | * docs: { 81 | * options: {}, 82 | * files: { 83 | * src: ['*'], 84 | * dest: 'foo' 85 | * } 86 | * } 87 | * }); 88 | * ``` 89 | * @param {String} `name` 90 | * @param {Object|Function} `config` 91 | * @api public 92 | */ 93 | 94 | setBoilerplate: function(name, config) { 95 | debug('setBoilerplate', name); 96 | if (typeof name !== 'string') { 97 | throw new TypeError('expected the first argument to be a string'); 98 | } 99 | if (utils.isObject(config)) { 100 | config.name = name; 101 | } 102 | 103 | this.boilerplates[name] = config; 104 | this.emit('boilerplate.set', name, config); 105 | return this; 106 | }, 107 | 108 | /** 109 | * Get boilerplate `name` from `app.boilerplates`, or return a normalized 110 | * instance of `Boilerplate` if an object or function is passed. 111 | * 112 | * ```js 113 | * var boilerplate = app.getBoilerplate('foo'); 114 | * 115 | * // or create an instance of `Boilerplate` using the given object 116 | * var boilerplate = app.getBoilerplate({ 117 | * docs: { 118 | * options: {}, 119 | * files: { 120 | * src: ['*'], 121 | * dest: 'foo' 122 | * } 123 | * } 124 | * }); 125 | * ``` 126 | * @param {String} `name` 127 | * @param {Object} `options` 128 | * @api public 129 | */ 130 | 131 | getBoilerplate: function(name, options) { 132 | debug('getBoilerplate', name); 133 | var opts = utils.merge({}, this.options); 134 | var config; 135 | 136 | switch (utils.typeOf(name)) { 137 | case 'function': 138 | config = name; 139 | break; 140 | case 'object': 141 | config = name; 142 | name = config.name; 143 | break; 144 | case 'string': 145 | default: { 146 | opts.name = name; 147 | config = this.boilerplates[name]; 148 | if (typeof config === 'undefined') { 149 | throw new Error(`boilerplate "${name}" is not registered`); 150 | } 151 | break; 152 | } 153 | } 154 | 155 | if (typeof config === 'function') { 156 | config = config(utils.merge({}, this.options, options)); 157 | } 158 | 159 | if (!utils.isObject(config)) { 160 | throw new TypeError('expected config to be an object'); 161 | } 162 | 163 | // if `config` is not an instance of Boilerplate, make it one 164 | if (!this.isBoilerplate(config)) { 165 | var Boilerplate = this.get('Boilerplate'); 166 | var boilerplate = new Boilerplate(); 167 | boilerplate.options = utils.merge({}, this.options, boilerplate.options, options); 168 | if (typeof name === 'string') { 169 | boilerplate.name = name; 170 | } 171 | if (typeof this.run === 'function') { 172 | this.run(boilerplate); 173 | } 174 | this.emit('boilerplate', boilerplate); 175 | boilerplate.on('scaffold', this.emit.bind(this, 'scaffold')); 176 | config = boilerplate.expand(config); 177 | } else { 178 | // otherwise, ensure options are merged onto the boilerplate, 179 | // and all targets are emitted 180 | config.options = utils.merge({}, this.options, config.options, options); 181 | if (typeof name === 'string') { 182 | config.name = name; 183 | } 184 | if (typeof this.run === 'function') { 185 | this.run(config); 186 | } 187 | for (var key in config.targets) { 188 | if (config.targets.hasOwnProperty(key)) { 189 | this.emit('target', config.targets[key]); 190 | } 191 | } 192 | config.on('target', this.emit.bind(this, 'target')); 193 | this.emit('boilerplate', config); 194 | } 195 | return config; 196 | }, 197 | 198 | /** 199 | * Returns true if the given value is a valid [Boilerplate][]. 200 | * 201 | * ```js 202 | * isBoilerplate('a'); 203 | * //=> false 204 | * isBoilerplate({}); 205 | * //=> false 206 | * isBoilerplate({ files: [] }) 207 | * //=> false 208 | * isBoilerplate(new Boilerplate({ src: ['*.js'] })) 209 | * //=> true 210 | * ``` 211 | * @name `.isBoilerplate 212 | * @param {any} `val` 213 | * @return {Boolean} 214 | * @api public 215 | */ 216 | 217 | isBoilerplate: utils.isBoilerplate, 218 | 219 | /** 220 | * Get or set the `Boilerplate` constructor. Exposed as a getter/setter to allow it to be 221 | * customized before or after instantiation. 222 | * 223 | * ```js 224 | * // set 225 | * app.Boilerplate = function MyBoilerplateCtor() {}; 226 | * 227 | * // get 228 | * var scaffold = new app.Boilerplate(); 229 | * ``` 230 | * @name Boilerplate 231 | * @api public 232 | */ 233 | 234 | Boilerplate: { 235 | configurable: true, 236 | set: function(val) { 237 | if (typeof val !== 'function') { 238 | throw new TypeError('expected Boilerplate to be a constructor function'); 239 | } 240 | Boilerplate = val; 241 | }, 242 | get: function() { 243 | return Boilerplate || this.options.Boilerplate || utils.Boilerplate; 244 | } 245 | } 246 | }); 247 | return fn; 248 | }; 249 | }; 250 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "base-boilerplate", 3 | "description": "Plugin that adds support for generating project files from a declarative boilerplate configuration.", 4 | "version": "0.2.1", 5 | "homepage": "https://github.com/node-base/base-boilerplate", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "node-base/base-boilerplate", 8 | "bugs": { 9 | "url": "https://github.com/node-base/base-boilerplate/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js", 14 | "LICENSE", 15 | "README.md", 16 | "utils.js" 17 | ], 18 | "main": "index.js", 19 | "engines": { 20 | "node": ">=0.10.0" 21 | }, 22 | "scripts": { 23 | "test": "mocha" 24 | }, 25 | "dependencies": { 26 | "async-each-series": "^1.1.0", 27 | "base-pipeline": "^0.3.2", 28 | "base-plugins": "^0.4.13", 29 | "base-scaffold": "^0.3.2", 30 | "debug": "^2.2.0", 31 | "is-boilerplate": "^0.1.1", 32 | "is-valid-app": "^0.2.0", 33 | "kind-of": "^3.0.3", 34 | "lazy-cache": "^2.0.1", 35 | "merge-stream": "^1.0.0", 36 | "mixin-deep": "^1.1.3" 37 | }, 38 | "devDependencies": { 39 | "base-app": "^0.2.6", 40 | "boilerplate": "^0.6.0", 41 | "gulp-format-md": "^0.1.9", 42 | "mocha": "^2.5.3" 43 | }, 44 | "keywords": [ 45 | "api", 46 | "app", 47 | "application", 48 | "base", 49 | "baseplugin", 50 | "boilerplate", 51 | "bp", 52 | "building-blocks", 53 | "config", 54 | "configuration", 55 | "create", 56 | "declarative", 57 | "files", 58 | "framework", 59 | "generate", 60 | "plugin", 61 | "plugins", 62 | "scaffold", 63 | "scaffolding", 64 | "skeleton", 65 | "tool", 66 | "toolkit", 67 | "tools" 68 | ], 69 | "verb": { 70 | "toc": false, 71 | "layout": "default", 72 | "tasks": [ 73 | "readme" 74 | ], 75 | "plugins": [ 76 | "gulp-format-md" 77 | ], 78 | "related": { 79 | "list": [ 80 | "base", 81 | "base-generators", 82 | "base-scaffold", 83 | "base-task" 84 | ] 85 | }, 86 | "reflinks": [ 87 | "boilerplate", 88 | "verb", 89 | "verb-readme-generator" 90 | ], 91 | "lint": { 92 | "reflinks": true 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /test/app.boilerplate.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var assert = require('assert'); 5 | var App = require('base-app'); 6 | var Boilerplate = require('boilerplate'); 7 | var boilerplate = require('..'); 8 | var config; 9 | var app; 10 | 11 | describe('boilerplates', function() { 12 | beforeEach(function() { 13 | app = new App(); 14 | app.use(boilerplate()); 15 | }); 16 | 17 | it('should create a new boilerplate', function() { 18 | config = app.boilerplate({ 19 | docs: { 20 | src: 'b.txt', 21 | dest: 'actual', 22 | cwd: process.cwd() 23 | } 24 | }); 25 | assert(config instanceof Boilerplate); 26 | }); 27 | 28 | it('should add a boilerplate to app.boilerplates', function() { 29 | app.boilerplate('foo', { 30 | docs: { 31 | src: 'b.txt', 32 | dest: 'actual', 33 | cwd: process.cwd() 34 | } 35 | }); 36 | assert(app.boilerplates.hasOwnProperty('foo')); 37 | }); 38 | 39 | it('should get a boilerplate from app.boilerplates', function() { 40 | app.boilerplate('foo', { 41 | docs: { 42 | src: 'b.txt', 43 | dest: 'actual', 44 | cwd: process.cwd() 45 | } 46 | }); 47 | var bp = app.getBoilerplate('foo'); 48 | assert(bp instanceof Boilerplate); 49 | }); 50 | 51 | it('should add scaffolds to boilerplate.scaffolds', function() { 52 | app.boilerplate('foo', { 53 | docs: { 54 | src: 'b.txt', 55 | dest: 'actual', 56 | cwd: process.cwd() 57 | } 58 | }); 59 | var bp = app.getBoilerplate('foo'); 60 | assert(bp instanceof Boilerplate); 61 | }); 62 | }); 63 | 64 | -------------------------------------------------------------------------------- /test/fixtures/a.txt: -------------------------------------------------------------------------------- 1 | this is a test -------------------------------------------------------------------------------- /test/fixtures/b.txt: -------------------------------------------------------------------------------- 1 | this is a test -------------------------------------------------------------------------------- /test/fixtures/c.txt: -------------------------------------------------------------------------------- 1 | this is a test -------------------------------------------------------------------------------- /test/fixtures/example.txt: -------------------------------------------------------------------------------- 1 | this is a test -------------------------------------------------------------------------------- /utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var utils = require('lazy-cache')(require); 4 | var fn = require; 5 | require = utils; 6 | 7 | /** 8 | * Lazily required module dependencies 9 | */ 10 | 11 | require('async-each-series', 'eachSeries'); 12 | require('base-pipeline', 'pipeline'); 13 | require('base-plugins', 'plugins'); 14 | require('base-scaffold', 'scaffold'); 15 | require('boilerplate', 'Boilerplate'); 16 | require('is-boilerplate'); 17 | require('is-valid-app', 'isValid'); 18 | require('kind-of', 'typeOf'); 19 | require('mixin-deep', 'merge'); 20 | require('merge-stream', 'ms'); 21 | require = fn; 22 | 23 | utils.isObject = function(val) { 24 | return utils.typeOf(val) === 'object'; 25 | }; 26 | 27 | /** 28 | * Expose `utils` modules 29 | */ 30 | 31 | module.exports = utils; 32 | --------------------------------------------------------------------------------