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

generate-target

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate-target - npm Package Compare versions

Comparing version
0.1.0
to
0.1.1
+58
-9
package.json
{
"name": "generate-target",
"description": "Plugin for automatically creating tasks from declarative `target` configurations. Works with generate, assemble, verb, or any other base application with plugin support.",
"version": "0.1.0",
"homepage": "https://github.com/jonschlinkert/generate-target",
"version": "0.1.1",
"homepage": "https://github.com/generate/generate-target",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/generate-target",
"repository": "generate/generate-target",
"bugs": {
"url": "https://github.com/jonschlinkert/generate-target/issues"
"url": "https://github.com/generate/generate-target/issues"
},
"license": "MIT",
"files": [
"index.js",
"LICENSE",
"README.md",
"templates"
],
"main": "index.js",
"engines": {

@@ -18,6 +25,2 @@ "node": ">=0.10.0"

},
"keywords": [
"generate",
"target"
],
"dependencies": {

@@ -35,2 +38,3 @@ "base-files-each": "^0.1.5",

"fs-exists-sync": "^0.1.0",
"gulp-format-md": "^0.1.9",
"mocha": "^2.5.3",

@@ -40,2 +44,36 @@ "rimraf": "^2.5.3",

},
"keywords": [
"boilerplate",
"build",
"cli",
"cli-app",
"command-line",
"create",
"dev",
"development",
"framework",
"front",
"frontend",
"generate",
"generate-generator",
"generate-plugin",
"generategenerator",
"generateplugin",
"generator",
"init",
"initialize",
"new",
"plugin",
"project",
"projects",
"scaffold",
"scaffolder",
"scaffolding",
"target",
"template",
"templates",
"webapp",
"yeoman",
"yo"
],
"verb": {

@@ -50,4 +88,15 @@ "reflinks": [

"gulp"
]
],
"toc": false,
"layout": "common-minimal",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"lint": {
"reflinks": true
}
}
}
+44
-17

@@ -0,4 +1,8 @@

# generate-target [![NPM version](https://img.shields.io/npm/v/generate-target.svg?style=flat)](https://www.npmjs.com/package/generate-target) [![NPM downloads](https://img.shields.io/npm/dm/generate-target.svg?style=flat)](https://npmjs.org/package/generate-target) [![Build Status](https://img.shields.io/travis/generate/generate-target.svg?style=flat)](https://travis-ci.org/generate/generate-target)
Plugin for automatically creating tasks from declarative `target` configurations. Works with generate, assemble, verb, or any other base application with plugin support.
## Usage
Can be used with any [base][] application, including [assemble][], [generate][], and [update][].
Can be used with any [base](https://github.com/node-base/base) application, including [assemble](https://github.com/assemble/assemble), [generate](https://github.com/generate/generate), and [update](https://github.com/update/update).

@@ -32,3 +36,3 @@ ```js

See the [expand-target][] library for additional information and API documentation.
See the [expand-target](https://github.com/jonschlinkert/expand-target) library for additional information and API documentation.

@@ -38,8 +42,9 @@ ## API

### [.targetSeries](index.js#L86)
Asynchronously generate files from a declarative [target][expand-target] configuration.
Asynchronously generate files from a declarative [target](https://github.com/jonschlinkert/expand-target) configuration.
**Params**
* `target` **{Object}**: Target configuration object.
* `next` **{Function}**: Optional callback function. If not passed, `.targetStream` will be called and a stream will be returned.
* `target` **{Object}**: Target configuration object.
* `next` **{Function}**: Optional callback function. If not passed, `.targetStream` will be called and a stream will be returned.

@@ -61,8 +66,9 @@ **Example**

### [.targetStream](index.js#L124)
Generate files from a declarative [target][expand-target] configuration.
Generate files from a declarative [target](https://github.com/jonschlinkert/expand-target) configuration.
**Params**
* `target` **{Object}**: [target][expand-target] configuration object.
* `returns` **{Stream}**: returns a stream with all processed files.
* `target` **{Object}**: [target](https://github.com/jonschlinkert/expand-target) configuration object.
* `returns` **{Stream}**: returns a stream with all processed files.

@@ -90,3 +96,3 @@ **Example**

If the instance has a `task` method, a task is automatically created for each target.
If the instance has a `task` method, a task is automatically created for each target.

@@ -113,9 +119,30 @@ **Example**

[assemble]: https://github.com/assemble/assemble
[base]: https://github.com/node-base/base
[expand-target]: https://github.com/jonschlinkert/expand-target
[generate-dest]: https://github.com/generate/generate-dest
[generate-install]: https://github.com/generate/generate-install
[generate]: https://github.com/generate/generate
[gulp]: http://gulpjs.com
[update]: https://github.com/update/update
## About
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
### Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
### License
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/generate/generate-target/blob/master/LICENSE).
***
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on July 19, 2016._
root = true
[*]
indent_style = space
end_of_line = lf
charset = utf-8
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false
{
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true
},
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": 2,
"arrow-spacing": [
2,
{
"before": true,
"after": true
}
],
"block-spacing": [
2,
"always"
],
"brace-style": [
2,
"1tbs",
{
"allowSingleLine": true
}
],
"comma-dangle": [
2,
"never"
],
"comma-spacing": [
2,
{
"before": false,
"after": true
}
],
"comma-style": [
2,
"last"
],
"constructor-super": 2,
"curly": [
2,
"multi-line"
],
"dot-location": [
2,
"property"
],
"eol-last": 2,
"eqeqeq": [
2,
"allow-null"
],
"generator-star-spacing": [
2,
{
"before": true,
"after": true
}
],
"handle-callback-err": [
2,
"^(err|error)$"
],
"indent": [
2,
2,
{
"SwitchCase": 1
}
],
"key-spacing": [
2,
{
"beforeColon": false,
"afterColon": true
}
],
"keyword-spacing": [
2,
{
"before": true,
"after": true
}
],
"new-cap": [
2,
{
"newIsCap": true,
"capIsNew": false
}
],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [
2,
"functions"
],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [
2,
"functions"
],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [
2,
{
"max": 1
}
],
"no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 0,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [
2,
{
"defaultAssignment": false
}
],
"no-unreachable": 2,
"no-unused-vars": [
2,
{
"vars": "all",
"args": "none"
}
],
"no-useless-call": 0,
"no-with": 2,
"one-var": [
0,
{
"initialized": "never"
}
],
"operator-linebreak": [
0,
"after",
{
"overrides": {
"?": "before",
":": "before"
}
}
],
"padded-blocks": [
0,
"never"
],
"quotes": [
2,
"single",
"avoid-escape"
],
"radix": 2,
"semi": [
2,
"always"
],
"semi-spacing": [
2,
{
"before": false,
"after": true
}
],
"space-before-blocks": [
2,
"always"
],
"space-before-function-paren": [
2,
"never"
],
"space-in-parens": [
2,
"never"
],
"space-infix-ops": 2,
"space-unary-ops": [
2,
{
"words": true,
"nonwords": false
}
],
"spaced-comment": [
0,
"always",
{
"markers": [
"global",
"globals",
"eslint",
"eslint-disable",
"*package",
"!",
","
]
}
],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [
2,
"any"
],
"yoda": [
2,
"never"
]
}
}
* text=auto

Sorry, the diff of this file is not supported yet

sudo: false
language: node_js
node_js:
- "5"
- "4"
- "0.12"
- "0.10"
matrix:
fast_finish: true
allow_failures:
- node_js: "4"
- node_js: "0.10"
- node_js: "0.12"
## Usage
Can be used with any [base][] application, including [assemble][], [generate][], and [update][].
```js
var target = require('{%= name %}');
```
## Example
```js
var Base = require('base');
var targets = require('base-target');
var app = new Base({isApp: true});
app.use(targets());
// create a target
app.target('abc', {
src: 'templates/*.hbs',
dest: 'site',
});
// get a target
app.target('abc')
.generate({cwd: 'fo'}) // build the files in a target
.on('error', console.error)
.on('end', function() {
console.log('done!');
});
```
See the [expand-target][] library for additional information and API documentation.
## API
{%= apidocs("index.js") %}
## Tasks
If the instance has a `task` method, a task is automatically created for each target.
**Example**
```js
app.target('docs', {src: 'src/docs/*.md', dest: 'docs'});
app.target('site', {src: 'src/site/*.hbs', dest: 'site'});
app.build(['docs', 'site'], function(err) {
if (err) return console.log(err);
console.log('done!');
});
```
**Disable auto-tasks**
Pass options to the plugin to disable this feature.
```js
app.use(targets({tasks: false}));
```
'use strict';
var target = require('./');
var Base = require('base-app');
var app = new Base();
app.use(target());
// app.on('target', function(target) {
// app.task(target.name, function(cb) {
// target.generate(cb);
// });
// });
app.target('site', {
options: {},
files: {
src: ['*', '!**/foo/**', '!**/node_modules/**'],
dest: 'test/actual/site'
}
});
app.target('docs', {
options: {},
files: {
src: ['*', '!**/foo/**', '!**/node_modules/**'],
dest: 'test/actual/docs'
}
});
// var target = app.target({
// options: {},
// files: {
// src: ['*', '!**/foo/**', '!**/node_modules/**'],
// dest: 'docs'
// }
// });
// console.log(app.target('site').files);
// console.log(app.target('docs').files);
// console.log(target.files);
// app.target('docs')
// .generate()
// .on('end', function() {
// console.log('done!');
// });
// app.target('site')
// .generate(function(err) {
// if (err) return console.log(err);
// console.log('done');
// });
app.build(['site', 'docs'], function(err) {
if (err) return console.log(err);
console.log('done');
});
'use strict';
require('mocha');
var fs = require('fs');
var path = require('path');
var assert = require('assert');
var rimraf = require('rimraf');
var eachSeries = require('async-each-series');
var exists = require('fs-exists-sync');
var through = require('through2');
var Target = require('expand-target');
var App = require('base');
var target = require('..');
var app;
var fixtures = path.resolve.bind(path, __dirname, 'fixtures');
var actual = path.resolve.bind(path, __dirname, 'actual');
function base(cb) {
return through.obj(function(file, enc, next) {
var str = file.contents.toString();
cb(file, str, next);
});
}
describe('target.generate', function() {
beforeEach(function() {
app = new App({isApp: true});
app.use(target());
});
afterEach(function(cb) {
rimraf(actual(), cb);
});
describe('add target object', function() {
it('should add a target object to app.targets', function() {
app.target('site', {
options: { cwd: fixtures() },
src: 'b.txt',
dest: actual(),
});
assert(app.targets.hasOwnProperty('site'));
});
it('should get a target object from app.targets', function() {
app.target('site', {
options: { cwd: fixtures() },
src: 'b.txt',
dest: actual()
});
var config = app.target('site');
assert(app.isTarget(config));
});
});
describe('add target instance', function() {
it('should add a target object to app.targets', function() {
app.target('site', {
options: { cwd: fixtures() },
src: 'b.txt',
dest: actual()
});
assert(app.targets.hasOwnProperty('site'));
});
it('should get a target object from app.targets', function() {
app.target('site', {
options: { cwd: fixtures() },
src: 'b.txt',
dest: actual()
});
var config = app.target('site');
assert(app.isTarget(config));
});
});
describe('add target function', function() {
it('should add a target function to app.targets', function() {
app.target('site', function(opts) {
return {
options: { cwd: fixtures() },
docs: {
src: 'b.txt',
dest: actual(),
cwd: fixtures()
}
}
});
assert(app.targets.hasOwnProperty('site'));
});
it('should get a target function from app.targets', function() {
app.target('site', function() {
return {
options: { cwd: fixtures() },
docs: {
src: 'b.txt',
dest: actual(),
cwd: fixtures()
}
}
});
var config = app.target('site');
assert(app.isTarget(config));
});
});
describe('.generate', function() {
it('should get a target function and build it with the given options', function(cb) {
app.target('foo', function(options) {
return {
options: { cwd: fixtures() },
src: 'a.txt',
dest: actual()
}
});
var config = app.target('foo');
config.generate(function(err) {
if (err) return cb(err);
assert(exists(actual('a.txt')));
cb();
});
});
it('should generate a target function with the given options', function(cb) {
app.target('site', function(options) {
return {
options: { cwd: options.cwd },
src: 'b.txt',
dest: actual()
}
});
var config = app.getTarget('site', {cwd: fixtures()});
config.generate(function(err) {
if (err) return cb(err);
assert(exists(actual('b.txt')));
cb();
});
});
it('should generate a target function using generateStream', function(cb) {
app.target('site', function(options) {
return {
options: { cwd: options.cwd },
src: 'b.txt',
dest: actual(),
}
});
app.getTarget('site', {cwd: fixtures()})
.generate()
.on('error', cb)
.on('end', function() {
assert(exists(actual('b.txt')));
cb();
});
});
it('should generate a target function using generateSeries', function(cb) {
app.target('site', function(options) {
return {
options: { cwd: options.cwd },
src: 'b.txt',
dest: actual()
}
});
app.getTarget('site', {cwd: fixtures()})
.generate(function(err) {
if (err) return cb(err);
assert(exists(actual('b.txt')));
cb();
})
});
it('should generate a target multiple times with different options', function(cb) {
app.target('site', function(options) {
return {
options: { cwd: fixtures() },
src: options.path,
dest: actual(),
}
});
eachSeries(['b.txt', 'a.txt'], function(val, next) {
app.getTarget('site', {path: val})
.generate(function(err) {
if (err) return next(err);
assert(exists(actual(val)));
next();
});
}, cb);
});
it('should generate a target function with custom src', function(cb) {
app.target('site', function(options) {
return {
options: { cwd: fixtures() },
src: options.src,
dest: actual()
}
});
app.getTarget('site', {src: ['b.txt', 'a.txt']})
.generate(function(err) {
if (err) return cb(err);
assert(exists(actual('b.txt')));
assert(exists(actual('a.txt')));
cb();
});
});
});
describe('target targets', function() {
it('should process files from options.cwd', function(cb) {
var config = new Target({
options: { cwd: fixtures() },
src: 'b.txt',
dest: actual()
});
app.target('test', config)
.generate(function(err) {
if (err) return cb(err);
assert(exists(actual('b.txt')));
cb();
});
});
it('should use the cwd passed on the config.options.cwd', function(cb) {
assert(!exists(actual('b.txt')));
var config = new Target({
cwd: fixtures(),
src: 'b.txt',
dest: actual()
});
app.target('test', config)
.generate()
.on('error', cb)
.on('end', function() {
assert(exists(actual('b.txt')));
cb();
});
});
it('should work with no options:', function(cb) {
var config = new Target({
src: 'b.txt',
dest: actual(),
cwd: fixtures()
});
app.target('test', config)
.generate()
.on('error', cb)
.on('end', function() {
assert(exists(actual('b.txt')));
cb();
});
});
it('should process a single file', function(cb) {
assert(!exists(actual('a.txt')));
var config = new Target({
cwd: fixtures(),
src: 'a.txt',
dest: actual()
});
app.target('test', config)
.generate()
.on('error', cb)
.on('end', function() {
assert(exists(actual('a.txt')));
cb();
});
});
it('should process a glob of files', function(cb) {
assert(!exists(actual('a.txt')));
assert(!exists(actual('b.txt')));
assert(!exists(actual('c.txt')));
var config = new Target({
cwd: fixtures(),
src: '*.txt',
dest: actual()
});
app.target('test', config)
.generate()
.on('error', cb)
.on('end', function() {
assert(exists(actual('a.txt')));
assert(exists(actual('b.txt')));
assert(exists(actual('c.txt')));
cb();
});
});
});
describe('target plugins', function() {
beforeEach(function() {
app = new App({isApp: true});
app.use(target());
});
it('should use a plugin to modify file contents', function(cb) {
app.plugin('append', function(opts) {
opts = opts || {};
return base(function(file, str, next) {
file.contents = new Buffer(str + opts.suffix);
next(null, file);
});
});
var config = new Target({
cwd: fixtures(),
src: '*.txt',
dest: actual()
});
app.target('test', config)
.generate({suffix: 'zzz'})
.on('error', cb)
.on('data', function(data) {
var str = data.contents.toString();
var end = str.slice(-3);
assert.equal(end, 'zzz');
})
.once('end', function() {
assert(exists(actual('a.txt')));
cb();
});
});
it('should run plugins defined on config.options', function(cb) {
function appendString(suffix) {
return base(function(file, str, next) {
file.contents = new Buffer(str + suffix);
next(null, file);
});
}
app.plugin('a', appendString('aaa'));
app.plugin('b', appendString('bbb'));
app.plugin('c', appendString('ccc'));
var config = new Target({
options: {pipeline: ['a', 'c']},
cwd: fixtures(),
src: 'a.txt',
dest: actual()
});
app.target('test', config)
.generate({suffix: 'zzz'})
.on('error', cb)
.on('data', function(data) {
var str = data.contents.toString();
assert.equal(str.indexOf('bbb'), -1);
var end = str.slice(-6);
assert.equal(end, 'aaaccc');
})
.on('finish', function() {
assert(exists(actual('a.txt')));
cb();
});
});
it('should run plugins defined on process.options', function(cb) {
function appendString(suffix) {
return base(function(file, str, next) {
file.contents = new Buffer(str + suffix);
next(null, file);
});
}
app.plugin('a', appendString('aaa'));
app.plugin('b', appendString('bbb'));
app.plugin('c', appendString('ccc'));
var config = new Target({
cwd: fixtures(),
src: 'a.txt',
dest: actual()
});
app.target('test', config)
.generate({pipeline: ['a', 'c'], suffix: 'zzz'})
.on('error', cb)
.on('data', function(data) {
var str = data.contents.toString();
assert.equal(str.indexOf('bbb'), -1);
var end = str.slice(-6);
assert.equal(end, 'aaaccc');
})
.on('finish', function() {
assert(exists(actual('a.txt')));
cb();
});
});
});
});