assemble-fs
Advanced tools
Comparing version 2.0.0 to 2.0.1
98
index.js
@@ -10,10 +10,10 @@ /*! | ||
const lead = require('lead'); | ||
const pumpify = require('pumpify'); | ||
const toThrough = require('to-through'); | ||
const utils = require('./utils'); | ||
module.exports = function(options) { | ||
const set = new Set(); | ||
module.exports = options => { | ||
return function plugin(app) { | ||
if ((!app.collections && !app.isCollection) || set.has(app)) return; | ||
set.add(app); | ||
if (app.src || (!app.collections && !app.isCollection)) return; | ||
@@ -44,6 +44,5 @@ /** | ||
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)); | ||
utils.define(app, 'copy', (patterns, dest, options) => { | ||
return utils.vfs.src(patterns, { allowEmpty: true, ...options }) | ||
.pipe(utils.vfs.dest(dest, options)); | ||
}); | ||
@@ -63,7 +62,9 @@ | ||
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)); | ||
utils.define(app, 'src', (patterns, options) => { | ||
let streams = pumpify.obj([ | ||
utils.src(patterns, { allowEmpty: true, ...options }), | ||
handle(app, 'onStream'), | ||
toFiles(app, options) | ||
]); | ||
return toThrough(streams); | ||
}); | ||
@@ -82,3 +83,3 @@ | ||
utils.define(app, 'symlink', utils.vfs.symlink.bind(utils.vfs)); | ||
utils.define(app, 'symlink', (...args) => utils.vfs.symlink(...args)); | ||
@@ -98,3 +99,3 @@ /** | ||
utils.define(app, 'dest', function(dest, options) { | ||
utils.define(app, 'dest', (dest, options = {}) => { | ||
if (!dest) { | ||
@@ -107,15 +108,9 @@ throw new TypeError('expected dest to be a string or function'); | ||
const output = utils.combine([ | ||
handle(this, 'preWrite'), | ||
utils.vfs.dest(dest, options), | ||
handle(this, 'postWrite') | ||
let output = pumpify.obj([ | ||
handle(app, 'preWrite'), | ||
utils.dest(dest, options), | ||
handle(app, 'postWrite') | ||
]); | ||
output.once('error', app.emit.bind(app, 'error')); | ||
output.once('end', function() { | ||
output.emit('finish'); | ||
app.emit('end'); | ||
}); | ||
return output; | ||
return lead(output); | ||
}); | ||
@@ -128,3 +123,3 @@ | ||
function addHandlers(app, handlers) { | ||
for (const name of handlers) { | ||
for (let name of handlers) { | ||
if (typeof app[name] !== 'function') { | ||
@@ -137,9 +132,9 @@ app.handler(name); | ||
/** | ||
* Ensure vinyl files are assemble views, and add | ||
* then to a collection if specified. | ||
* Make sure vinyl files are assemble files, and add | ||
* them to a collection, if specified. | ||
*/ | ||
function toViews(app, options) { | ||
const opts = Object.assign({ collection: null }, options); | ||
const name = opts.collection; | ||
function toFiles(app, options) { | ||
let opts = Object.assign({ collection: null }, options); | ||
let name = opts.collection; | ||
let collection = app.collections ? name && app[name] : app; | ||
@@ -152,3 +147,7 @@ let view; | ||
return utils.through.obj(async function(file, enc, next) { | ||
return utils.through.obj(async (file, enc, next) => { | ||
if (!app.File.isFile(file)) { | ||
file = app.file(file.path, file); | ||
} | ||
if (file.isNull()) { | ||
@@ -158,3 +157,4 @@ next(null, file); | ||
} | ||
if (collection && collection.isCollection) { | ||
if (collection && isCollection(collection)) { | ||
try { | ||
@@ -170,19 +170,18 @@ view = await collection.set(file.path, file); | ||
view = app.view(file.path, file); | ||
view = !app.File.isFile(file) ? app.file(file.path, file) : file; | ||
try { | ||
await app.handle('onLoad', view); | ||
} catch (err) { | ||
next(err); | ||
return; | ||
} | ||
next(null, view); | ||
app.handle('onLoad', view) | ||
.then(() => next(null, view)) | ||
.catch(next); | ||
}); | ||
} | ||
function isCollection(collection) { | ||
return collection.files && !collection.collections; | ||
} | ||
function handle(app, method) { | ||
return utils.through.obj(async function(file, enc, next) { | ||
if (!file.path && !file.isNull && !file.contents) { | ||
next(); | ||
return utils.through.obj(async (file, enc, next) => { | ||
if (!file || (!file.path && !file.isNull && !file.contents)) { | ||
next(null, file); | ||
return; | ||
@@ -201,5 +200,6 @@ } | ||
await app.handle(method, file); | ||
next(null, file); | ||
app.handle(method, file) | ||
.then(() => next(null, file)) | ||
.catch(next); | ||
}); | ||
} |
{ | ||
"name": "assemble-fs", | ||
"description": "Assemble plugin to add methods to assemble for working with the file system, like src, dest, copy and symlink.", | ||
"version": "2.0.0", | ||
"description": "Light wrapper for vinyl-fs to add streams support in a way that plays nice with Assemble middleware.", | ||
"version": "2.0.1", | ||
"homepage": "https://github.com/assemble/assemble-fs", | ||
@@ -22,18 +22,25 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"engines": { | ||
"node": ">=4.0" | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha test/{*.js,vfs/*.js}" | ||
}, | ||
"dependencies": { | ||
"readable-stream": "^2.3.6", | ||
"lead": "^1.0.0", | ||
"pumpify": "^1.5.1", | ||
"readable-stream": "^3.0.6", | ||
"stream-combiner": "^0.2.2", | ||
"vinyl-fs": "^3.0.2" | ||
"to-through": "^2.0.0", | ||
"vinyl-fs": "^3.0.3" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^3.5.3", | ||
"expect": "^1.19.0", | ||
"graceful-fs": "^4.1.15", | ||
"gulp-format-md": "^2.0.0", | ||
"mississippi": "^3.0.0", | ||
"mocha": "^5.2.0", | ||
"rimraf": "^2.6.2", | ||
"templates": "file:/Users/jonschlinkert/dev/templates/templates-next/", | ||
"vinyl": "^2.1.0", | ||
"gulp-format-md": "^1.0.0" | ||
"sinon": "^7.1.1", | ||
"templates": "file:../../../templates/templates-next", | ||
"vinyl": "^2.2.0" | ||
}, | ||
@@ -76,6 +83,6 @@ "keywords": [ | ||
"lintDeps": { | ||
"devDendencies": { | ||
"devDependencies": { | ||
"files": { | ||
"patterns": [ | ||
"./test/vfs/*.js" | ||
"test/vfs/**/*.js" | ||
] | ||
@@ -82,0 +89,0 @@ } |
# 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) | ||
> Assemble plugin to add methods to assemble for working with the file system, like src, dest, copy and symlink. | ||
> Light wrapper for vinyl-fs to add streams support in a way that plays nice with Assemble middleware. | ||
@@ -15,4 +15,6 @@ Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. | ||
This is an assemble core plugin, you probably won't need to use this directly. | ||
## Heads up! | ||
Major breaking changes in v2.0 of this plugin! [See the Release History](#release-history) for details. | ||
## Usage | ||
@@ -56,3 +58,3 @@ | ||
### [.src](index.js#L61) | ||
### [.src](index.js#L60) | ||
@@ -72,3 +74,3 @@ Glob patterns or filepaths to source files. | ||
### [.symlink](index.js#L79) | ||
### [.symlink](index.js#L80) | ||
@@ -87,3 +89,3 @@ Glob patterns or paths for symlinks. | ||
### [.dest](index.js#L94) | ||
### [.dest](index.js#L95) | ||
@@ -103,4 +105,8 @@ Specify a destination for processed files. Runs `.preWrite` and `.postWrite` middleware handlers on all files. | ||
## History | ||
## Release History | ||
**v2.0.0** | ||
* Major breaking changes based on v1.0 of Assemble! Requires Assemble v1.0 or above. | ||
**v0.6.0** | ||
@@ -160,6 +166,6 @@ | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 95 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 11 | [doowb](https://github.com/doowb) | | ||
| **Commits** | **Contributor** | | ||
| --- | --- | | ||
| 100 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 11 | [doowb](https://github.com/doowb) | | ||
@@ -170,5 +176,5 @@ ### Author | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
* [GitHub Profile](https://github.com/jonschlinkert) | ||
* [Twitter Profile](https://twitter.com/jonschlinkert) | ||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) | ||
@@ -182,2 +188,2 @@ ### License | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 04, 2018._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on December 11, 2018._ |
70
utils.js
@@ -5,22 +5,12 @@ 'use strict'; | ||
const assign = Object.assign; | ||
const { Transform } = require('readable-stream'); | ||
const noop = (data, enc, next) => next(null, data); | ||
const { Transform } = require('readable-stream'); | ||
const utils = exports = module.exports; | ||
const define = (obj, key, fn) => Reflect.defineProperty(obj, key, { get: fn }); | ||
define(utils, 'vfs', () => require('vinyl-fs')); | ||
define(utils, 'combine', () => require('stream-combiner')); | ||
define(exports, 'combine', () => require('stream-combiner')); | ||
define(exports, 'vfs', () => require('vinyl-fs')); | ||
define(exports, 'src', () => require('vinyl-fs/lib/src')); | ||
define(exports, 'dest', () => require('vinyl-fs/lib/dest')); | ||
define(exports, 'symlink', () => require('vinyl-fs/lib/symlink')); | ||
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 | ||
}); | ||
}; | ||
/** | ||
@@ -43,8 +33,8 @@ * This function does all of the path-specific operations that | ||
utils.prepare = function(app, view, dest, options = {}) { | ||
if (view.preparedDest) return; | ||
const file = new view.constructor(view); | ||
const cwd = app.paths.templates; | ||
exports.prepare = function(app, view, dest, options = {}) { | ||
if (view.preparedDest === true) return; | ||
let file = new view.constructor(view); | ||
let cwd = app.paths.templates; | ||
const destDir = typeof dest === 'function' ? dest(file) : dest; | ||
let destDir = typeof dest === 'function' ? dest(file) : dest; | ||
if (typeof destDir !== 'string') { | ||
@@ -54,3 +44,3 @@ throw new TypeError('expected destination directory to be a string'); | ||
const baseDir = typeof options.base === 'function' | ||
let baseDir = typeof options.base === 'function' | ||
? options.base(file) | ||
@@ -63,4 +53,4 @@ : path.resolve(cwd, destDir); | ||
const writePath = path.join(destDir, view.basename); | ||
const data = {}; | ||
let writePath = path.join(destDir, view.basename); | ||
let data = {}; | ||
data.cwd = cwd; | ||
@@ -81,10 +71,10 @@ data.base = baseDir; | ||
utils.prepareDest = function fn(app, dest, options) { | ||
exports.prepareDest = function fn(app, dest, options) { | ||
app.emit('dest', dest, options); | ||
const appOpts = assign({}, this.options); | ||
let appOpts = assign({}, this.options); | ||
delete appOpts.engine; | ||
delete appOpts.tasks; | ||
const opts = assign({}, appOpts, options); | ||
let opts = assign({}, appOpts, options); | ||
@@ -95,4 +85,4 @@ if (fn.prepare) { | ||
fn.prepare = function(view) { | ||
const data = utils.prepare(app, view, dest, opts); | ||
fn.prepare = view => { | ||
let data = exports.prepare(app, view, dest, opts); | ||
view.data = assign({}, view.data, data); | ||
@@ -104,3 +94,3 @@ }; | ||
utils.through = function(options, transform, flush) { | ||
exports.through = (options, transform, flush) => { | ||
if (typeof options === 'function') { | ||
@@ -117,7 +107,7 @@ flush = transform; | ||
if (transform.length === 2) { | ||
const fn = transform; | ||
let fn = transform; | ||
transform = (data, enc, cb) => fn(data, cb); | ||
} | ||
const stream = new Transform({ transform, flush, ...options }); | ||
let stream = new Transform({ transform, flush, ...options }); | ||
stream.setMaxListeners(0); | ||
@@ -127,3 +117,3 @@ return stream; | ||
utils.through.obj = (options, transform, flush) => { | ||
exports.through.obj = (options, transform, flush) => { | ||
if (typeof options === 'function') { | ||
@@ -135,5 +125,13 @@ flush = transform; | ||
const opts = Object.assign({ objectMode: true, highWaterMark: 16 }, options); | ||
return utils.through(opts, transform, flush); | ||
let opts = Object.assign({ objectMode: true, highWaterMark: 16 }, options); | ||
return exports.through(opts, transform, flush); | ||
}; | ||
exports.define = function(obj, key, value) { | ||
Reflect.defineProperty(obj, key, { | ||
configurable: true, | ||
enumerable: false, | ||
writable: true, | ||
value | ||
}); | ||
}; |
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
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
17770
181
0
6
9
+ Addedlead@^1.0.0
+ Addedpumpify@^1.5.1
+ Addedto-through@^2.0.0
Updatedreadable-stream@^3.0.6
Updatedvinyl-fs@^3.0.3