Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

boilerplate

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boilerplate - npm Package Compare versions

Comparing version
0.3.2
to
0.4.0
+159
-69
index.js

@@ -1,22 +0,21 @@

/*!
* boilerplate <https://github.com/jonschlinkert/boilerplate>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var Base = require('base-methods');
var merge = require('mixin-deep');
var utils = require('expand-utils');
var extend = require('extend-shallow');
var define = require('define-property');
var Target = require('expand-target');
var Scaffold = require('scaffold');
var use = require('use');
/**
* Create an instance of Boilerplate with the
* given `options`
* Expand a declarative configuration with scaffolds and targets.
* Create a new Boilerplate with the given `options`
*
* ```js
* var boilerplate = new Boilerplate({
* templates: {
* files: [{src: 'templates/*.hbs', dest: 'src/'}]
* var boilerplate = new Boilerplate();
*
* // example usage
* boilerplate.expand({
* jshint: {
* src: ['*.js', 'lib/*.js']
* }

@@ -29,52 +28,132 @@ * });

function Boilerplate(config) {
if (!config || typeof config !== 'object') {
throw new TypeError('expected config to be an object.');
}
function Boilerplate(options) {
if (!(this instanceof Boilerplate)) {
return new Boilerplate(config);
return new Boilerplate(options);
}
Base.call(this);
this.isBoilerplate = true;
utils.is(this, 'boilerplate');
use(this);
// sift out options and non-target config values
this.options = config.options || {};
delete config.options;
this.config = {};
define(this, 'count', 0);
this.options = options || {};
this.scaffolds = {};
this.targets = {};
if (utils.isConfig(options)) {
this.options = {};
this.expand(options);
return this;
}
}
/**
* Static method, returns `true` if the given value is an
* instance of `Boilerplate` or appears to be a valid `boilerplate`
* configuration object.
*
* ```js
* Boilerplate.isBoilerplate({});
* //=> false
*
* var h5bp = new Boilerplate({
* options: {cwd: 'vendor/h5bp/dist'},
* root: {src: ['{.*,*.*}'], dest: 'src/'},
* // ...
* });
* Boilerplate.isBoilerplate(h5bp);
* //=> true
* ```
* @static
* @param {Object} `config` The value to check
* @return {Boolean}
* @api public
*/
Boilerplate.isBoilerplate = function(config) {
if (!utils.isObject(config)) {
return false;
}
if (config.isBoilerplate) {
return true;
}
for (var key in config) {
var val = config[key];
if (isTarget(val)) {
this.target(key, this.init(val, this.options));
} else {
this.config[key] = val;
if (Scaffold.isScaffold(config[key])) {
return true;
}
}
}
return false;
};
Base.extend(Boilerplate);
/**
* Initialize Boilerplate defaults
* Expand and normalize a declarative configuration into scaffolds, targets,
* and `options`.
*
* ```js
* boilerplate.expand({
* options: {},
* marketing: {
* site: {
* mapDest: true,
* src: 'templates/*.hbs',
* dest: 'site/'
* },
* docs: {
* src: 'content/*.md',
* dest: 'site/'
* }
* },
* developer: {
* site: {
* mapDest: true,
* src: 'templates/*.hbs',
* dest: 'site/'
* },
* docs: {
* src: 'content/*.md',
* dest: 'site/docs/'
* }
* }
* });
* ```
* @param {Object} `boilerplate` Boilerplate object with scaffolds and/or targets.
* @return {Object}
* @api public
*/
Boilerplate.prototype.init = function(config, options) {
config.options = merge({}, options, config.options);
return config;
Boilerplate.prototype.expand = function(boilerplate) {
// support anonymous targets
if (utils.isTarget(boilerplate)) {
this.addTarget('target' + (this.count++), boilerplate);
return this;
}
for (var key in boilerplate) {
if (boilerplate.hasOwnProperty(key)) {
var val = boilerplate[key];
if (Scaffold.isScaffold(val)) {
this.addScaffold(key, val);
} else if (utils.isTarget(val)) {
this.addTarget(key, val);
} else {
this[key] = val;
}
}
}
};
/**
* Register a boilerplate `target` with the given `name` and
* configuration options. A target is just a way to organize
* the files or content of a boilerplate into smaller groups.
* Add a scaffold to the boilerplate, while also normalizing targets with
* src-dest mappings and expanding glob patterns in each target.
*
* ```js
* boilerplate.target('webapp', ...);
* boilerplate.addScaffold('assemble', {
* site: {src: '*.hbs', dest: 'templates/'},
* docs: {src: '*.md', dest: 'content/'}
* });
* ```
*
* @param {String} `name` The name of the target.
* @param {Object} `config` The configuration to use.
* @param {String} `name` the scaffold's name
* @param {Object} `boilerplate` Scaffold object where each key is a target or `options`.
* @return {Object}

@@ -84,37 +163,48 @@ * @api public

Boilerplate.prototype.target = function(name, config) {
Boilerplate.prototype.addScaffold = function(name, boilerplate) {
if (typeof name !== 'string') {
throw new TypeError('expected name to be a string.');
throw new TypeError('expected a string');
}
if (!config || typeof config !== 'object') {
throw new TypeError('expected config to be an object.');
}
this.targets[name] = !(config instanceof Scaffold)
? new Scaffold(config)
: config;
return this;
var scaffold = new Scaffold(this.options);
define(scaffold, 'name', name);
utils.run(this, 'boilerplate', scaffold);
scaffold.addTargets(boilerplate);
this.scaffolds[name] = scaffold;
return scaffold;
};
/**
* Return `true` if an object has any of the given keys.
* Add a target to the boilerplate, while also normalizing src-dest mappings and
* expanding glob patterns in the target.
*
* @param {Object} `obj`
* @param {Array} `keys`
* @return {Boolean}
* ```js
* boilerplate.addTarget({src: '*.hbs', dest: 'templates/'});
* ```
* @param {String} `name` The target's name
* @param {Object} `target` Target object with a `files` property, or `src` and optionally a `dest` property.
* @return {Object}
* @api public
*/
function isTarget(val) {
if (Array.isArray(val)) {
return false;
Boilerplate.prototype.addTarget = function(name, boilerplate) {
if (typeof name !== 'string') {
throw new TypeError('expected a string');
}
if (typeof val !== 'object') {
return false;
if (!utils.isObject(boilerplate)) {
throw new TypeError('expected an object');
}
var keys = ['src', 'dest', 'files'];
for (var key in val) {
if (keys.indexOf(key) > -1) return true;
}
return false;
}
var target = new Target(this.options);
define(target, 'name', name);
utils.run(this, 'target', target);
target.addFiles(boilerplate);
this.targets[name] = target;
return target;
};
/**

@@ -121,0 +211,0 @@ * Expose `Boilerplate`

The MIT License (MIT)
Copyright (c) 2015, Jon Schlinkert.
Copyright (c) 2015-2016, Jon Schlinkert.

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy

{
"name": "boilerplate",
"description": "Tools and conventions for authoring and publishing boilerplates that can be generated by any build system or generator.",
"version": "0.3.2",
"version": "0.4.0",
"homepage": "http://boilerplates.io",

@@ -23,19 +23,17 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"dependencies": {
"base-methods": "^0.2.5",
"mixin-deep": "^1.1.3",
"scaffold": "^0.1.2"
"define-property": "^0.2.5",
"expand-target": "^0.5.3",
"expand-utils": "^0.1.4",
"extend-shallow": "^2.0.1",
"scaffold": "^0.2.5",
"use": "^1.1.2"
},
"devDependencies": {
"expand-config": "^0.2.1",
"expand-target": "^0.2.3",
"get-value": "^1.2.1",
"gulp": "^3.9.0",
"gulp-istanbul": "^0.10.0",
"gulp-jshint": "^1.11.2",
"gulp-mocha": "^2.1.3",
"jshint-stylish": "^2.0.1",
"mocha": "^2.3.0",
"set-value": "^0.2.0",
"should": "^7.1.0",
"stringify-object": "jonschlinkert/stringify-object"
"gulp-eslint": "^1.1.1",
"gulp-format-md": "^0.1.4",
"gulp-istanbul": "^0.10.3",
"gulp-mocha": "^2.2.0",
"mocha": "*",
"should": "*"
},

@@ -72,9 +70,29 @@ "keywords": [

"list": [
"assemble",
"boilerplate",
"assemble",
"template",
"scaffold"
"generate",
"scaffold",
"templates",
"update",
"verb"
]
}
},
"reflinks": [
"assemble",
"boilerplate",
"broccoli",
"expand-files",
"expand-target",
"grunt",
"gulp",
"metalsmith",
"scaffold",
"templates",
"verb",
"yeoman"
],
"plugins": [
"gulp-format-md"
]
}
}
+183
-38

@@ -1,2 +0,2 @@

# boilerplate [![NPM version](https://badge.fury.io/js/boilerplate.svg)](http://badge.fury.io/js/boilerplate)
# boilerplate [![NPM version](https://img.shields.io/npm/v/boilerplate.svg)](https://www.npmjs.com/package/boilerplate)

@@ -7,25 +7,70 @@ > Tools and conventions for authoring and publishing boilerplates that can be generated by any build system or generator.

**What does this do?**
1. Makes it easy to create and publish new projects from boilerplates that have reusable [scaffolds](https://github.com/jonschlinkert/scaffold), templates, styles, themes, data etc.
2. To uncouple these "non-moving-parts" from any particular build system or generator, so we can easily generate new projects by simply passing the boilerplate config object to your build system or project generator of choice!
**Example**
In the following example, we define:
* **scaffolds** for our marketing and developer sites
* **targets** inside each scaffold (`site` and `blog`)
* **files** configurations inside each "site" and "blog" target
The configuration is similar to how [Grunt](http://gruntjs.com/) tasks would be defined.
```js
var boilerplate = require('boilerplate');
boilerplate({
marketing: {
site: {
src: 'templates/mktg/*.hbs',
dest: 'site/'
},
blog: {
src: 'content/blog/*.md',
dest: 'site/blog/'
}
},
developer: {
site: {
src: 'templates/dev/*.hbs',
dest: 'site/developer'
},
blog: {
src: 'content/dev/blog/*.md',
dest: 'site/developer/blog/'
}
}
});
```
The `Boilerplate` library "expands" this configuration into a normalized object that can easily be passed to [gulp](http://gulpjs.com), [grunt](http://gruntjs.com/), [assemble](http://assemble.io), [metalsmith][], or even [yeoman](http://yeoman.io), for scaffolding out various parts of a blog, website, web application or whatever you think a boilerplate might be useful for!
## Table of contents
<!-- toc -->
- [html5-boilerplate example](#html5-boilerplate-example)
- [About](#about)
* [Comparison table](#comparison-table)
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Related projects](#related-projects)
- [Test coverage](#test-coverage)
- [Running tests](#running-tests)
- [Contributing](#contributing)
- [Author](#author)
- [License](#license)
* [Example](#example)
* [QA](#qa)
* [Install](#install)
* [Usage](#usage)
* [API](#api)
* [Related projects](#related-projects)
* [Test coverage](#test-coverage)
* [Running tests](#running-tests)
* [Contributing](#contributing)
* [Author](#author)
* [License](#license)
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
_(Table of contents generated by [verb](https://github.com/verbose/verb))_
## html5-boilerplate example
<!-- tocstop -->
Just to show how easy it is to convert an existing project into a `Boilerplate` project using the most popular boilerplate of them all: [html5-boilerplate](https://github.com/h5bp/html5-boilerplate).
## Example
_(Get hands-on with the [h5bp recipe](./recipes/h5bp))_
This example shows how easy it is to convert an existing project into a `Boilerplate` project using the most popular boilerplate of them all: [html5-boilerplate](https://github.com/h5bp/html5-boilerplate).
**Install h5bp**

@@ -38,2 +83,4 @@ First, install `boilerplate` and [html5-boilerplate](https://github.com/h5bp/html5-boilerplate):

**Define the boilerplate**
The following examples returns a normalized configuration object for every file in the [html5-boilerplate](https://github.com/h5bp/html5-boilerplate) project, organized exactly the way the project itself is organized.

@@ -162,3 +209,3 @@

## QA
## About

@@ -178,9 +225,19 @@ **What is a boilerplate?**

Workflows and tools for actually generating new projects from a boilerplate. This is a job much better suited to build systems like [assemble](http://assemble.io), [gulp](http://gulpjs.com), [grunt](http://gruntjs.com/), and [yeoman](http://yeoman.io).
Workflows and tools for actually generating new projects from a boilerplate. This is a job much better suited for build systems like [assemble](http://assemble.io), [gulp](http://gulpjs.com), [grunt](http://gruntjs.com/), [broccoli][], and [yeoman](http://yeoman.io).
If you publish a library that works with Boilerplate, please [let us know about it](https://github.com/boilerplates/boilerplates/issues/new?title=boilerplate-%5Bname%20here%5D&body=I%20created%20a%20new%20boilerplate%253A%0A%0A*%20homepage%253A%20%5Bproject%20url%5D%20%0A*%20description%253A%20%5Bboilerplate%20description%5D)!
### Comparison table
The following table describes the difference between boilerplates, scaffolds and templates.
| **type** | **description** |
| --- | --- |
| [template](https://github.com/jonschlinkert/templates) | Resuable file, code or content which contains "placeholder" values that will eventually be replaced with real values by a rendering (template) engine |
| [scaffold](#boilerplate) | Consists of one or more templates or source files and serves as a "temporary support structure" that may be used to initialize a new project, or to provide ad-hoc "components" throughout the duration of a project. |
| [boilerplate](https://github.com/boilerplates) | Boilerplates consist of all of the necessary files required to initialize a complete project. |
## Install
Install with [npm](https://www.npmjs.com/)
Install with [npm](https://www.npmjs.com/):

@@ -199,5 +256,5 @@ ```sh

### [Boilerplate](index.js#L29)
### [Boilerplate](index.js#L28)
Create an instance of Boilerplate with the given `options`
Expand a declarative configuration with scaffolds and targets. Create a new Boilerplate with the given `options`

@@ -211,5 +268,8 @@ **Params**

```js
var boilerplate = new Boilerplate({
templates: {
files: [{src: 'templates/*.hbs', dest: 'src/'}]
var boilerplate = new Boilerplate();
// example usage
boilerplate.expand({
jshint: {
src: ['*.js', 'lib/*.js']
}

@@ -219,10 +279,33 @@ });

### [.target](index.js#L81)
### [.isBoilerplate](index.js#L71)
Register a boilerplate `target` with the given `name` and configuration options. A target is just a way to organize the files or content of a boilerplate into smaller groups.
Static method, returns `true` if the given value is an instance of `Boilerplate` or appears to be a valid `boilerplate` configuration object.
**Params**
* `name` **{String}**: The name of the target.
* `config` **{Object}**: The configuration to use.
* `config` **{Object}**: The value to check
* `returns` **{Boolean}**
**Example**
```js
Boilerplate.isBoilerplate({});
//=> false
var h5bp = new Boilerplate({
options: {cwd: 'vendor/h5bp/dist'},
root: {src: ['{.*,*.*}'], dest: 'src/'},
// ...
});
Boilerplate.isBoilerplate(h5bp);
//=> true
```
### [.expand](index.js#L122)
Expand and normalize a declarative configuration into scaffolds, targets, and `options`.
**Params**
* `boilerplate` **{Object}**: Boilerplate object with scaffolds and/or targets.
* `returns` **{Object}**

@@ -233,15 +316,77 @@

```js
boilerplate.target('webapp', ...);
boilerplate.expand({
options: {},
marketing: {
site: {
mapDest: true,
src: 'templates/*.hbs',
dest: 'site/'
},
docs: {
src: 'content/*.md',
dest: 'site/'
}
},
developer: {
site: {
mapDest: true,
src: 'templates/*.hbs',
dest: 'site/'
},
docs: {
src: 'content/*.md',
dest: 'site/docs/'
}
}
});
```
### [.addScaffold](index.js#L162)
Add a scaffold to the boilerplate, while also normalizing targets with src-dest mappings and expanding glob patterns in each target.
**Params**
* `name` **{String}**: the scaffold's name
* `boilerplate` **{Object}**: Scaffold object where each key is a target or `options`.
* `returns` **{Object}**
**Example**
```js
boilerplate.addScaffold('assemble', {
site: {src: '*.hbs', dest: 'templates/'},
docs: {src: '*.md', dest: 'content/'}
});
```
### [.addTarget](index.js#L190)
Add a target to the boilerplate, while also normalizing src-dest mappings and expanding glob patterns in the target.
**Params**
* `name` **{String}**: The target's name
* `target` **{Object}**: Target object with a `files` property, or `src` and optionally a `dest` property.
* `returns` **{Object}**
**Example**
```js
boilerplate.addTarget({src: '*.hbs', dest: 'templates/'});
```
## Related projects
* [assemble](https://www.npmjs.com/package/assemble): Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… [more](https://www.npmjs.com/package/assemble) | [homepage](http://assemble.io)
* [assemble](https://www.npmjs.com/package/assemble): Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… [more](https://www.npmjs.com/package/assemble) | [homepage](https://github.com/assemble/assemble)
* [boilerplate](https://www.npmjs.com/package/boilerplate): Tools and conventions for authoring and publishing boilerplates that can be generated by any build… [more](https://www.npmjs.com/package/boilerplate) | [homepage](http://boilerplates.io)
* [scaffold](https://www.npmjs.com/package/scaffold): Conventions and API for creating scaffolds that can by used by any build system or… [more](https://www.npmjs.com/package/scaffold) | [homepage](https://github.com/jonschlinkert/scaffold)
* [template](https://www.npmjs.com/package/template): Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template… [more](https://www.npmjs.com/package/template) | [homepage](https://github.com/jonschlinkert/template)
* [generate](https://www.npmjs.com/package/generate): Fast, composable, highly extendable project generator for node.js | [homepage](https://github.com/jonschlinkert/generate)
* [scaffold](https://www.npmjs.com/package/scaffold): Conventions and API for creating declarative configuration objects for project scaffolds - similar in format… [more](https://www.npmjs.com/package/scaffold) | [homepage](https://github.com/jonschlinkert/scaffold)
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine.… [more](https://www.npmjs.com/package/templates) | [homepage](https://github.com/jonschlinkert/templates)
* [update](https://www.npmjs.com/package/update): Update | [homepage](https://github.com/jonschlinkert/update)
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://www.npmjs.com/package/verb) | [homepage](https://github.com/verbose/verb)
## Test coverage
As of September 04, 2015:
As of January 06, 2016:

@@ -271,8 +416,8 @@ ```

+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright © 2015 Jon Schlinkert
Copyright © 2016 [Jon Schlinkert](https://github.com/jonschlinkert)
Released under the MIT license.

@@ -282,2 +427,2 @@

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 04, 2015._
_This file was generated by [verb](https://github.com/verbose/verb) on January 06, 2016._