assemble-fs
Advanced tools
Comparing version 1.0.1 to 2.0.0
275
index.js
/*! | ||
* assemble-fs <https://github.com/assemble/assemble-fs> | ||
* | ||
* Copyright (c) 2015, 2017, Jon Schlinkert. | ||
* Copyright (c) 2015-2018, Jon Schlinkert. | ||
* Released under the MIT License. | ||
@@ -10,146 +10,137 @@ */ | ||
var utils = require('./utils'); | ||
const utils = require('./utils'); | ||
/** | ||
* Plugin is registered on `app` and `collection` instances | ||
*/ | ||
module.exports = function(options) { | ||
const set = new Set(); | ||
module.exports = function() { | ||
return function() { | ||
if (!this.isApp) return; | ||
plugin.call(this, this); | ||
return function plugin(app) { | ||
if ((!app.collections && !app.isCollection) || set.has(app)) return; | ||
set.add(app); | ||
return function() { | ||
if (!this.isCollection) return; | ||
plugin.call(this, this); | ||
}; | ||
}; | ||
}; | ||
/** | ||
* Setup middleware handlers. Assume none of the handlers exist if `onStream` | ||
* does not exist. | ||
*/ | ||
/** | ||
* The actual `fs` plugin | ||
*/ | ||
addHandlers(app, ['onLoad', 'onStream', 'preWrite', 'postWrite']); | ||
function plugin(app) { | ||
if (!utils.isValidApp(app, 'assemble-fs', ['app', 'views', 'collection'])) return; | ||
/** | ||
* Copy files with the given glob `patterns` to the specified `dest`. | ||
* | ||
* ```js | ||
* app.task('assets', function(cb) { | ||
* app.copy('assets/**', 'dist/') | ||
* .on('error', cb) | ||
* .on('finish', cb) | ||
* }); | ||
* ``` | ||
* @name .copy | ||
* @param {String|Array} `patterns` Glob patterns of files to copy. | ||
* @param {String|Function} `dest` Desination directory. | ||
* @return {Stream} Stream, to continue processing if necessary. | ||
* @api public | ||
*/ | ||
/** | ||
* Setup middleware handlers. Assume none of the handlers exist if `onStream` | ||
* does not exist. | ||
*/ | ||
utils.define(app, 'copy', function(patterns, dest, options) { | ||
const opts = Object.assign({ allowEmpty: true }, options); | ||
return utils.vfs.src(patterns, opts) | ||
.pipe(utils.vfs.dest(dest, opts)); | ||
}); | ||
if (typeof app.handler === 'function' && typeof app.onStream !== 'function') { | ||
app.handler('onStream'); | ||
app.handler('preWrite'); | ||
app.handler('postWrite'); | ||
app.handler('onLoad'); | ||
} | ||
/** | ||
* Glob patterns or filepaths to source files. | ||
* | ||
* ```js | ||
* app.src('src/*.hbs', {layout: 'default'}); | ||
* ``` | ||
* @name .src | ||
* @param {String|Array} `glob` Glob patterns or file paths to source files. | ||
* @param {Object} `options` Options or locals to merge into the context and/or pass to `src` plugins | ||
* @api public | ||
*/ | ||
/** | ||
* Copy files with the given glob `patterns` to the specified `dest`. | ||
* | ||
* ```js | ||
* app.task('assets', function(cb) { | ||
* app.copy('assets/**', 'dist/') | ||
* .on('error', cb) | ||
* .on('finish', cb) | ||
* }); | ||
* ``` | ||
* @name .copy | ||
* @param {String|Array} `patterns` Glob patterns of files to copy. | ||
* @param {String|Function} `dest` Desination directory. | ||
* @return {Stream} Stream, to continue processing if necessary. | ||
* @api public | ||
*/ | ||
utils.define(app, 'src', function(patterns, options) { | ||
const opts = Object.assign({ allowEmpty: true }, options); | ||
return utils.vfs.src(patterns, opts) | ||
.pipe(handle(this, 'onStream')) | ||
.pipe(toViews(this, options)); | ||
}); | ||
this.define('copy', function(patterns, dest, options) { | ||
var opts = utils.extend({ allowEmpty: true }, options); | ||
return utils.vfs.src(patterns, opts) | ||
.pipe(utils.vfs.dest(dest, opts)); | ||
}); | ||
/** | ||
* Glob patterns or paths for symlinks. | ||
* | ||
* ```js | ||
* app.symlink('src/**'); | ||
* ``` | ||
* @name .symlink | ||
* @param {String|Array} `glob` | ||
* @api public | ||
*/ | ||
/** | ||
* Glob patterns or filepaths to source files. | ||
* | ||
* ```js | ||
* app.src('src/*.hbs', {layout: 'default'}); | ||
* ``` | ||
* @name .src | ||
* @param {String|Array} `glob` Glob patterns or file paths to source files. | ||
* @param {Object} `options` Options or locals to merge into the context and/or pass to `src` plugins | ||
* @api public | ||
*/ | ||
utils.define(app, 'symlink', utils.vfs.symlink.bind(utils.vfs)); | ||
this.define('src', function(glob, options) { | ||
var opts = utils.extend({ allowEmpty: true }, options); | ||
return utils.vfs.src(glob, opts) | ||
.pipe(toCollection(this, opts)) | ||
.pipe(utils.handle.once(this, 'onLoad')) | ||
.pipe(utils.handle.once(this, 'onStream')); | ||
}); | ||
/** | ||
* Specify a destination for processed files. Runs `.preWrite` and | ||
* `.postWrite` middleware handlers on all files. | ||
* | ||
* ```js | ||
* app.dest('dist/'); | ||
* ``` | ||
* @name .dest | ||
* @param {String|Function} `dest` File path or rename function. | ||
* @param {Object} `options` Options and locals to pass to `dest` plugins | ||
* @api public | ||
*/ | ||
/** | ||
* Glob patterns or paths for symlinks. | ||
* | ||
* ```js | ||
* app.symlink('src/**'); | ||
* ``` | ||
* @name .symlink | ||
* @param {String|Array} `glob` | ||
* @api public | ||
*/ | ||
utils.define(app, 'dest', function(dest, options) { | ||
if (!dest) { | ||
throw new TypeError('expected dest to be a string or function'); | ||
} | ||
this.define('symlink', function() { | ||
return utils.vfs.symlink.apply(utils.vfs, arguments); | ||
}); | ||
// ensure "dest" is added to the context before rendering | ||
utils.prepareDest(app, dest, options); | ||
/** | ||
* Specify a destination for processed files. | ||
* | ||
* ```js | ||
* app.dest('dist/'); | ||
* ``` | ||
* @name .dest | ||
* @param {String|Function} `dest` File path or rename function. | ||
* @param {Object} `options` Options and locals to pass to `dest` plugins | ||
* @api public | ||
*/ | ||
const output = utils.combine([ | ||
handle(this, 'preWrite'), | ||
utils.vfs.dest(dest, options), | ||
handle(this, 'postWrite') | ||
]); | ||
this.define('dest', function fn(dest, options) { | ||
if (!dest) { | ||
throw new TypeError('expected dest to be a string or function.'); | ||
} | ||
output.once('error', app.emit.bind(app, 'error')); | ||
output.once('end', function() { | ||
output.emit('finish'); | ||
app.emit('end'); | ||
}); | ||
// ensure "dest" is added to the context before rendering | ||
utils.prepareDest(app, dest, options); | ||
return output; | ||
}); | ||
var output = utils.combine([ | ||
utils.handle.once(this, 'preWrite'), | ||
utils.vfs.dest.apply(utils.vfs, arguments), | ||
utils.handle.once(this, 'postWrite') | ||
]); | ||
return plugin; | ||
}; | ||
}; | ||
output.on('end', function() { | ||
output.emit('finish'); | ||
app.emit('end'); | ||
}); | ||
return output; | ||
}); | ||
function addHandlers(app, handlers) { | ||
for (const name of handlers) { | ||
if (typeof app[name] !== 'function') { | ||
app.handler(name); | ||
} | ||
} | ||
} | ||
/** | ||
* Push vinyl files onto a collection or list. | ||
* Ensure vinyl files are assemble views, and add | ||
* then to a collection if specified. | ||
*/ | ||
function toCollection(app, options) { | ||
var opts = utils.extend({collection: 'streamFiles'}, options); | ||
var name = opts.collection; | ||
var collection; | ||
function toViews(app, options) { | ||
const opts = Object.assign({ collection: null }, options); | ||
const name = opts.collection; | ||
let collection = app.collections ? name && app[name] : app; | ||
let view; | ||
if (app.isApp) { | ||
collection = app[name] || app.create(name, options); | ||
if (!collection && name) { | ||
collection = app.create(name, opts); | ||
} | ||
return utils.through.obj(function(file, enc, next) { | ||
return utils.through.obj(async function(file, enc, next) { | ||
if (file.isNull()) { | ||
@@ -159,24 +150,46 @@ next(null, file); | ||
} | ||
if (collection && collection.isCollection) { | ||
try { | ||
view = await collection.set(file.path, file); | ||
} catch (err) { | ||
next(err); | ||
return; | ||
} | ||
next(null, view); | ||
return; | ||
} | ||
if (utils.isBinary(file)) { | ||
next(null, file); | ||
view = app.view(file.path, file); | ||
try { | ||
await app.handle('onLoad', view); | ||
} catch (err) { | ||
next(err); | ||
return; | ||
} | ||
// disable default `onLoad` handling inside templates | ||
file.options = utils.extend({ onLoad: false }, options, file.options); | ||
next(null, view); | ||
}); | ||
} | ||
if (app.isApp) { | ||
file = collection.addView(file.path, file); | ||
} else if (app.isCollection || app.isViews) { | ||
file = app.addView(file.path, file); | ||
} else if (app.isList) { | ||
file = app.setItem(file.path, file); | ||
} else { | ||
next(new Error('assemble-fs expects an instance, collection or view')); | ||
function handle(app, method) { | ||
return utils.through.obj(async function(file, enc, next) { | ||
if (!file.path && !file.isNull && !file.contents) { | ||
next(); | ||
return; | ||
} | ||
if (file.isNull() || !app.handle) { | ||
next(null, file); | ||
return; | ||
} | ||
if (typeof app[method] !== 'function') { | ||
next(new Error(`middleware handler "${method}" is not registered`)); | ||
return; | ||
} | ||
await app.handle(method, file); | ||
next(null, file); | ||
}); | ||
} |
{ | ||
"name": "assemble-fs", | ||
"description": "Assemble plugin to add methods to assemble for working with the file system, like src, dest, copy and symlink.", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/assemble/assemble-fs", | ||
@@ -22,3 +22,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4.0" | ||
}, | ||
@@ -28,42 +28,16 @@ "scripts": { | ||
}, | ||
"lintDeps": { | ||
"devDependencies": { | ||
"files": { | ||
"patterns": [ | ||
"test/vfs/*.js", | ||
"test/support/*.js" | ||
] | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"assemble-handle": "^0.1.3", | ||
"extend-shallow": "^2.0.1", | ||
"file-is-binary": "^1.0.0", | ||
"fs-exists-sync": "^0.1.0", | ||
"is-valid-app": "^0.3.0", | ||
"lazy-cache": "^2.0.2", | ||
"readable-stream": "^2.3.6", | ||
"stream-combiner": "^0.2.2", | ||
"through2": "^2.0.3", | ||
"vinyl-fs": "^2.4.4" | ||
"vinyl-fs": "^3.0.2" | ||
}, | ||
"devDependencies": { | ||
"buffer-equal": "^1.0.0", | ||
"default-resolution": "^2.0.0", | ||
"delete": "^1.0.1", | ||
"expect": "^1.20.2", | ||
"from2": "^2.3.0", | ||
"graceful-fs": "^4.1.11", | ||
"gulp-format-md": "^0.1.12", | ||
"mocha": "^3.4.1", | ||
"readable-stream": "^2.2.9", | ||
"rimraf": "^2.6.1", | ||
"should": "^11.2.1", | ||
"sinon": "^2.2.0", | ||
"templates": "^1.2.8", | ||
"vinyl": "^2.0.2" | ||
"mocha": "^3.5.3", | ||
"rimraf": "^2.6.2", | ||
"templates": "file:/Users/jonschlinkert/dev/templates/templates-next/", | ||
"vinyl": "^2.1.0", | ||
"gulp-format-md": "^1.0.0" | ||
}, | ||
"keywords": [ | ||
"assemble", | ||
"assembleplugin", | ||
"boilerplate", | ||
@@ -74,6 +48,9 @@ "build", | ||
"command-line", | ||
"copy", | ||
"create", | ||
"dest", | ||
"dev", | ||
"development", | ||
"file", | ||
"file-system", | ||
"framework", | ||
@@ -89,6 +66,9 @@ "front", | ||
"scaffolding", | ||
"system", | ||
"src", | ||
"stream", | ||
"streams", | ||
"template", | ||
"templates", | ||
"vinyl", | ||
"vinyl-fs", | ||
"webapp", | ||
@@ -98,2 +78,11 @@ "yeoman", | ||
], | ||
"lintDeps": { | ||
"devDendencies": { | ||
"files": { | ||
"patterns": [ | ||
"./test/vfs/*.js" | ||
] | ||
} | ||
} | ||
}, | ||
"verb": { | ||
@@ -111,13 +100,7 @@ "run": true, | ||
"list": [ | ||
"assemble", | ||
"assemble-loader", | ||
"assemble-render-file", | ||
"assemble-streams", | ||
"generate", | ||
"update", | ||
"verb" | ||
] | ||
}, | ||
"reflinks": [ | ||
], | ||
"lint": { | ||
@@ -124,0 +107,0 @@ "reflinks": true |
135
README.md
@@ -5,2 +5,4 @@ # assemble-fs [![NPM version](https://img.shields.io/npm/v/assemble-fs.svg?style=flat)](https://www.npmjs.com/package/assemble-fs) [![NPM monthly downloads](https://img.shields.io/npm/dm/assemble-fs.svg?style=flat)](https://npmjs.org/package/assemble-fs) [![NPM total downloads](https://img.shields.io/npm/dt/assemble-fs.svg?style=flat)](https://npmjs.org/package/assemble-fs) [![Linux Build Status](https://img.shields.io/travis/assemble/assemble-fs.svg?style=flat&label=Travis)](https://travis-ci.org/assemble/assemble-fs) | ||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. | ||
## Install | ||
@@ -19,13 +21,81 @@ | ||
```js | ||
var assemble = require('assemble'); | ||
const Assemble = require('assemble'); | ||
// create your application and add the plugin | ||
var app = assemble() | ||
.use(require('assemble-fs')) | ||
const app = new Assemble(); | ||
app.use(require('assemble-fs')) | ||
// now you can use `src` and `dest` | ||
app.src(['foo/*.hbs']) | ||
.pipe(app.dest('site/')) | ||
.pipe(app.dest('site/')); | ||
``` | ||
## API | ||
Adds the following methods to your [assemble](https://github.com/assemble/assemble) instance (works with any [Templates][] application): | ||
### [.copy](index.js#L43) | ||
Copy files with the given glob `patterns` to the specified `dest`. | ||
**Params** | ||
* `patterns` **{String|Array}**: Glob patterns of files to copy. | ||
* `dest` **{String|Function}**: Desination directory. | ||
* `returns` **{Stream}**: Stream, to continue processing if necessary. | ||
**Example** | ||
```js | ||
app.task('assets', function(cb) { | ||
app.copy('assets/**', 'dist/') | ||
.on('error', cb) | ||
.on('finish', cb) | ||
}); | ||
``` | ||
### [.src](index.js#L61) | ||
Glob patterns or filepaths to source files. | ||
**Params** | ||
* `glob` **{String|Array}**: Glob patterns or file paths to source files. | ||
* `options` **{Object}**: Options or locals to merge into the context and/or pass to `src` plugins | ||
**Example** | ||
```js | ||
app.src('src/*.hbs', {layout: 'default'}); | ||
``` | ||
### [.symlink](index.js#L79) | ||
Glob patterns or paths for symlinks. | ||
**Params** | ||
* `glob` **{String|Array}** | ||
**Example** | ||
```js | ||
app.symlink('src/**'); | ||
``` | ||
### [.dest](index.js#L94) | ||
Specify a destination for processed files. Runs `.preWrite` and `.postWrite` middleware handlers on all files. | ||
**Params** | ||
* `dest` **{String|Function}**: File path or rename function. | ||
* `options` **{Object}**: Options and locals to pass to `dest` plugins | ||
**Example** | ||
```js | ||
app.dest('dist/'); | ||
``` | ||
## History | ||
@@ -46,24 +116,23 @@ | ||
### Related projects | ||
<details> | ||
<summary><strong>Contributing</strong></summary> | ||
* [assemble-loader](https://www.npmjs.com/package/assemble-loader): Assemble plugin (^0.6.0) for loading globs of views onto custom view collections. Also works with… [more](https://github.com/assemble/assemble-loader) | [homepage](https://github.com/assemble/assemble-loader "Assemble plugin (^0.6.0) for loading globs of views onto custom view collections. Also works with verb or other Templates.js based applications.") | ||
* [assemble-render-file](https://www.npmjs.com/package/assemble-render-file): Assemble plugin for rendering views in a vinyl pipeline. | [homepage](https://github.com/assemble/assemble-render-file "Assemble plugin for rendering views in a vinyl pipeline.") | ||
* [assemble-streams](https://www.npmjs.com/package/assemble-streams): Assemble pipeline plugin for pushing views into a vinyl stream. | [homepage](https://github.com/assemble/assemble-streams "Assemble pipeline plugin for pushing views into a vinyl stream.") | ||
* [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit") | ||
* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.") | ||
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.") | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
### Contributing | ||
</details> | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). | ||
<details> | ||
<summary><strong>Running Tests</strong></summary> | ||
### Contributors | ||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 89 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 11 | [doowb](https://github.com/doowb) | | ||
```sh | ||
$ npm install && npm test | ||
``` | ||
### Building docs | ||
</details> | ||
<details> | ||
<summary><strong>Building docs</strong></summary> | ||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ | ||
@@ -77,10 +146,19 @@ | ||
### Running tests | ||
</details> | ||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: | ||
### Related projects | ||
```sh | ||
$ npm install && npm test | ||
``` | ||
You might also be interested in these projects: | ||
* [generate](https://www.npmjs.com/package/generate): Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… [more](https://github.com/generate/generate) | [homepage](https://github.com/generate/generate "Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the robustness and configurability of Yeoman, the expressiveness and simplicity of Slush, and more powerful flow control and composability than either.") | ||
* [update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update "Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.") | ||
* [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.") | ||
### Contributors | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 95 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 11 | [doowb](https://github.com/doowb) | | ||
### Author | ||
@@ -90,8 +168,9 @@ | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert) | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
* [GitHub Profile](https://github.com/jonschlinkert) | ||
* [Twitter Profile](https://twitter.com/jonschlinkert) | ||
### License | ||
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert). | ||
Released under the [MIT License](LICENSE). | ||
@@ -101,2 +180,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 19, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 04, 2018._ |
111
utils.js
'use strict'; | ||
var path = require('path'); | ||
var utils = require('lazy-cache')(require); | ||
var fn = require; | ||
require = utils; | ||
const path = require('path'); | ||
const assign = Object.assign; | ||
const noop = (data, enc, next) => next(null, data); | ||
const { Transform } = require('readable-stream'); | ||
const utils = exports = module.exports; | ||
/** | ||
* Lazily required module dependencies | ||
*/ | ||
define(utils, 'vfs', () => require('vinyl-fs')); | ||
define(utils, 'combine', () => require('stream-combiner')); | ||
require('assemble-handle', 'handle'); | ||
require('extend-shallow', 'extend'); | ||
require('fs-exists-sync', 'exists'); | ||
require('file-is-binary', 'isBinary'); | ||
require('is-valid-app'); | ||
require('stream-combiner', 'combine'); | ||
require('through2', 'through'); | ||
require('vinyl-fs', 'vfs'); | ||
require = fn; | ||
function define(obj, key, fn) { | ||
Reflect.defineProperty(obj, key, { get: fn }); | ||
} | ||
utils.define = function(obj, key, value) { | ||
Reflect.defineProperty(obj, key, { | ||
configurable: true, | ||
enumerable: false, | ||
writable: true, | ||
value | ||
}); | ||
}; | ||
/** | ||
@@ -39,8 +42,8 @@ * This function does all of the path-specific operations that | ||
utils.prepare = function(view, dest, options) { | ||
var file = view.clone(); | ||
var opts = utils.extend({cwd: process.cwd()}, options); | ||
var cwd = path.resolve(opts.cwd); | ||
utils.prepare = function(app, view, dest, options = {}) { | ||
if (view.preparedDest) return; | ||
const file = new view.constructor(view); | ||
const cwd = app.paths.templates; | ||
var destDir = typeof dest === 'function' ? dest(file) : dest; | ||
const destDir = typeof dest === 'function' ? dest(file) : dest; | ||
if (typeof destDir !== 'string') { | ||
@@ -50,4 +53,4 @@ throw new TypeError('expected destination directory to be a string'); | ||
var baseDir = typeof opts.base === 'function' | ||
? opts.base(file) | ||
const baseDir = typeof options.base === 'function' | ||
? options.base(file) | ||
: path.resolve(cwd, destDir); | ||
@@ -59,5 +62,4 @@ | ||
var writePath = path.resolve(baseDir, file.relative); | ||
var data = {}; | ||
const writePath = path.join(destDir, view.basename); | ||
const data = {}; | ||
data.cwd = cwd; | ||
@@ -67,2 +69,3 @@ data.base = baseDir; | ||
data.path = writePath; | ||
view.preparedDest = true; | ||
return data; | ||
@@ -78,26 +81,54 @@ }; | ||
utils.prepareDest = function _(app, dest, options) { | ||
utils.prepareDest = function fn(app, dest, options) { | ||
app.emit('dest', dest, options); | ||
var appOpts = utils.extend({}, this.options); | ||
const appOpts = assign({}, this.options); | ||
delete appOpts.engine; | ||
delete appOpts.tasks; | ||
delete appOpts.engine; | ||
var opts = utils.extend({}, appOpts, options); | ||
if (_.prepare) { | ||
app.off('_prepare', _.prepare); | ||
const opts = assign({}, appOpts, options); | ||
if (fn.prepare) { | ||
app.off('prepareDest', fn.prepare); | ||
} | ||
_.prepare = function(view) { | ||
var data = utils.prepare(view, dest, opts); | ||
view.data = utils.extend({}, view.data, data); | ||
fn.prepare = function(view) { | ||
const data = utils.prepare(app, view, dest, opts); | ||
view.data = assign({}, view.data, data); | ||
}; | ||
app.on('_prepare', _.prepare); | ||
app.on('prepareDest', fn.prepare); | ||
}; | ||
/** | ||
* Expose `utils` | ||
*/ | ||
utils.through = function(options, transform, flush) { | ||
if (typeof options === 'function') { | ||
flush = transform; | ||
transform = options; | ||
options = null; | ||
} | ||
module.exports = utils; | ||
if (!transform) { | ||
transform = noop; | ||
} | ||
if (transform.length === 2) { | ||
const fn = transform; | ||
transform = (data, enc, cb) => fn(data, cb); | ||
} | ||
const stream = new Transform({ transform, flush, ...options }); | ||
stream.setMaxListeners(0); | ||
return stream; | ||
}; | ||
utils.through.obj = (options, transform, flush) => { | ||
if (typeof options === 'function') { | ||
flush = transform; | ||
transform = options; | ||
options = null; | ||
} | ||
const opts = Object.assign({ objectMode: true, highWaterMark: 16 }, options); | ||
return utils.through(opts, transform, flush); | ||
}; | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
17244
3
5
267
175
1
1
+ Addedreadable-stream@^2.3.6
+ Addedappend-buffer@1.0.2(transitive)
+ Addedbuffer-equal@1.0.1(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedclone@2.1.2(transitive)
+ Addedclone-buffer@1.0.0(transitive)
+ Addedclone-stats@1.0.0(transitive)
+ Addedcloneable-readable@1.1.3(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedflush-write-stream@1.1.1(transitive)
+ Addedfs-mkdirp-stream@1.0.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-stream@6.1.0(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedis-absolute@1.0.0(transitive)
+ Addedis-negated-glob@1.0.0(transitive)
+ Addedis-relative@1.0.0(transitive)
+ Addedis-unc-path@1.0.0(transitive)
+ Addedis-valid-glob@1.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedlead@1.0.0(transitive)
+ Addednow-and-later@2.0.1(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedordered-read-streams@1.0.1(transitive)
+ Addedpump@2.0.1(transitive)
+ Addedpumpify@1.5.1(transitive)
+ Addedremove-bom-buffer@3.0.0(transitive)
+ Addedremove-bom-stream@1.2.0(transitive)
+ Addedreplace-ext@1.0.1(transitive)
+ Addedresolve-options@1.1.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedto-absolute-glob@2.0.2(transitive)
+ Addedto-through@2.0.0(transitive)
+ Addedunc-path-regex@0.1.2(transitive)
+ Addedvalue-or-function@3.0.0(transitive)
+ Addedvinyl@2.2.1(transitive)
+ Addedvinyl-fs@3.0.3(transitive)
+ Addedvinyl-sourcemap@1.1.0(transitive)
- Removedassemble-handle@^0.1.3
- Removedextend-shallow@^2.0.1
- Removedfile-is-binary@^1.0.0
- Removedfs-exists-sync@^0.1.0
- Removedis-valid-app@^0.3.0
- Removedlazy-cache@^2.0.2
- Removedthrough2@^2.0.3
- Removedarr-diff@2.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarray-unique@0.2.1(transitive)
- Removedassemble-handle@0.1.4(transitive)
- Removedbraces@1.8.5(transitive)
- Removedclone@1.0.4(transitive)
- Removedclone-stats@0.0.1(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddefine-property@0.2.5(transitive)
- Removedexpand-brackets@0.1.5(transitive)
- Removedexpand-range@1.8.2(transitive)
- Removedextend-shallow@2.0.1(transitive)
- Removedextglob@0.3.2(transitive)
- Removedfile-is-binary@1.0.0(transitive)
- Removedfilename-regex@2.0.1(transitive)
- Removedfill-range@2.2.4(transitive)
- Removedfirst-chunk-stream@1.0.0(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedfs-exists-sync@0.1.0(transitive)
- Removedglob@5.0.15(transitive)
- Removedglob-base@0.3.0(transitive)
- Removedglob-parent@2.0.0(transitive)
- Removedglob-stream@5.3.5(transitive)
- Removedgulp-sourcemaps@1.6.0(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-binary-buffer@1.0.0(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.7(transitive)
- Removedis-dotfile@1.0.3(transitive)
- Removedis-equal-shallow@0.1.3(transitive)
- Removedis-extendable@0.1.1(transitive)
- Removedis-extglob@1.0.0(transitive)
- Removedis-glob@2.0.1(transitive)
- Removedis-number@2.1.04.0.0(transitive)
- Removedis-posix-bracket@0.1.1(transitive)
- Removedis-primitive@2.0.0(transitive)
- Removedis-registered@0.1.5(transitive)
- Removedis-stream@1.1.0(transitive)
- Removedis-valid-app@0.3.0(transitive)
- Removedis-valid-glob@0.3.0(transitive)
- Removedis-valid-instance@0.3.0(transitive)
- Removedisarray@0.0.1(transitive)
- Removedisobject@2.1.03.0.1(transitive)
- Removedkind-of@3.2.26.0.3(transitive)
- Removedlazy-cache@2.0.2(transitive)
- Removedlodash.isequal@4.5.0(transitive)
- Removedmath-random@1.0.4(transitive)
- Removedmerge-stream@1.0.1(transitive)
- Removedmicromatch@2.3.11(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@2.0.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedobject.omit@2.0.1(transitive)
- Removedordered-read-streams@0.3.0(transitive)
- Removedparse-glob@3.0.4(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedpreserve@0.2.0(transitive)
- Removedrandomatic@3.1.1(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedregex-cache@0.4.4(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedreplace-ext@0.0.1(transitive)
- Removedset-getter@0.1.1(transitive)
- Removedstring_decoder@0.10.31(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedstrip-bom-stream@1.0.0(transitive)
- Removedthrough2@0.6.5(transitive)
- Removedthrough2-filter@2.0.0(transitive)
- Removedto-absolute-glob@0.1.1(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedvali-date@1.0.0(transitive)
- Removedvinyl@1.2.0(transitive)
- Removedvinyl-fs@2.4.4(transitive)
Updatedvinyl-fs@^3.0.2