assemble-fs
Advanced tools
Comparing version 0.9.1 to 1.0.0
12
index.js
/*! | ||
* assemble-fs <https://github.com/jonschlinkert/assemble-fs> | ||
* assemble-fs <https://github.com/assemble/assemble-fs> | ||
* | ||
* Copyright (c) 2015, Jon Schlinkert. | ||
* Licensed under the MIT License. | ||
* Copyright (c) 2015, 2017, Jon Schlinkert. | ||
* Released under the MIT License. | ||
*/ | ||
@@ -117,3 +117,3 @@ | ||
this.define('dest', function(dest, options) { | ||
this.define('dest', function fn(dest, options) { | ||
if (!dest) { | ||
@@ -123,4 +123,6 @@ throw new TypeError('expected dest to be a string or function.'); | ||
// ensure "dest" is added to the context before rendering | ||
utils.prepareDest(app, dest, options); | ||
var output = utils.combine([ | ||
utils.prepare(dest, utils.extend({}, this.options, options)), | ||
utils.handle.once(this, 'preWrite'), | ||
@@ -127,0 +129,0 @@ utils.vfs.dest.apply(utils.vfs, arguments), |
{ | ||
"name": "assemble-fs", | ||
"description": "Assemble plugin to add methods to assemble for working with the file system, like src, dest, copy and symlink.", | ||
"version": "0.9.1", | ||
"version": "1.0.0", | ||
"homepage": "https://github.com/assemble/assemble-fs", | ||
@@ -35,5 +35,8 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"devDependencies": { | ||
"assemble-render-file": "^1.0.0", | ||
"base-task": "^0.7.0", | ||
"buffer-equal": "^1.0.0", | ||
"default-resolution": "^2.0.0", | ||
"delete": "^0.3.2", | ||
"engine-handlebars": "^0.8.0", | ||
"expect": "^1.20.2", | ||
@@ -48,3 +51,3 @@ "from2": "^2.3.0", | ||
"sinon": "^1.17.7", | ||
"templates": "^1.2.0", | ||
"templates": "^1.2.2", | ||
"vinyl": "^2.0.1" | ||
@@ -51,0 +54,0 @@ }, |
@@ -61,3 +61,3 @@ # 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) | ||
| --- | --- | | ||
| 83 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 89 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 11 | [doowb](https://github.com/doowb) | | ||
@@ -97,2 +97,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 02, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 08, 2017._ |
95
utils.js
@@ -22,39 +22,74 @@ 'use strict'; | ||
// until `vinyl-prepare` is published | ||
utils.prepare = function(dest, options) { | ||
return utils.through.obj(function(file, enc, next) { | ||
prepare(dest, file, options, next); | ||
}); | ||
/** | ||
* This function does all of the path-specific operations that | ||
* `prepareWrite` does in http://github.com/wearefractal/vinyl-fs, | ||
* but on a **cloned file**, which accomplishes two things: | ||
* | ||
* 1. We can merge the dest path information onto the context so | ||
* that it can be used to calculate relative paths for navigation, | ||
* pagination, etc. | ||
* 2. Since we use a cloned file, we're not risking any double-processing | ||
* on the actual view when it's finally written to the file system | ||
* by the `.dest()` method. | ||
* | ||
* @param {Object} view | ||
* @param {String|Function} dest | ||
* @param {Object} options | ||
*/ | ||
utils.prepare = function(view, dest, options) { | ||
var file = view.clone(); | ||
var opts = utils.extend({cwd: process.cwd()}, options); | ||
var cwd = path.resolve(opts.cwd); | ||
var destDir = typeof dest === 'function' ? dest(file) : dest; | ||
if (typeof destDir !== 'string') { | ||
throw new TypeError('expected destination directory to be a string'); | ||
} | ||
var baseDir = typeof opts.base === 'function' | ||
? opts.base(file) | ||
: path.resolve(cwd, destDir); | ||
if (typeof baseDir !== 'string') { | ||
throw new TypeError('expected base directory to be a string'); | ||
} | ||
var writePath = path.resolve(baseDir, file.relative); | ||
var data = {}; | ||
data.cwd = cwd; | ||
data.base = baseDir; | ||
data.dest = destDir; | ||
data.path = writePath; | ||
return data; | ||
}; | ||
function prepare(dest, file, options, cb) { | ||
try { | ||
var opts = utils.extend({cwd: process.cwd()}, options); | ||
var cwd = path.resolve(opts.cwd); | ||
/** | ||
* This sets up an event listener that will eventually | ||
* be called by `app.renderFile()`, ensuring that `dest` | ||
* information is loaded onto the context before rendering, | ||
* so that views can render relative paths. | ||
*/ | ||
var destDir = typeof dest === 'function' ? dest(file) : dest; | ||
if (typeof destDir !== 'string') { | ||
cb(new TypeError('expected destination directory to be a string')); | ||
return; | ||
} | ||
utils.prepareDest = function _(app, dest, options) { | ||
app.emit('dest', dest, options); | ||
var baseDir = typeof opts.base === 'function' | ||
? opts.base(file) | ||
: path.resolve(cwd, destDir); | ||
var appOpts = utils.extend({}, this.options); | ||
delete appOpts.tasks; | ||
delete appOpts.engine; | ||
if (!baseDir) { | ||
cb(new TypeError('expected base directory to be a string')); | ||
return; | ||
} | ||
var writePath = path.resolve(baseDir, file.relative); | ||
file.cwd = cwd; | ||
file.base = baseDir; | ||
file.path = writePath; | ||
cb(null, file); | ||
} catch (err) { | ||
cb(err); | ||
var opts = utils.extend({}, appOpts, options); | ||
if (_.prepare) { | ||
app.off('_prepare', _.prepare); | ||
} | ||
} | ||
_.prepare = function(view) { | ||
var data = utils.prepare(view, dest, opts); | ||
view.data = utils.extend({}, view.data, data); | ||
}; | ||
app.on('_prepare', _.prepare); | ||
}; | ||
/** | ||
@@ -61,0 +96,0 @@ * Expose `utils` |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
15568
231
0
17