Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map function to allow custom manifest #33

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The plugin fully supports both buffers and streams. If you encounter any problem
| options.space | null | [The space parameter for JSON.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)|
| options.deleteOld | false | If set to `true`, deletes old versions of hashed files |
| options.sourceDir | __dirname | Used with `deleteOld`. Specifies where to search for old files to delete. |
| options.map | (none) | Function allowing to modify keys (source) and values (destination) before the creation of the manifest. Should return an array with the new key-value pair respectively in the first and second entry. |

### hash.manifest(manifestPath, append, space)

Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ exportObj.manifest = function(manifestPath, options) {
var space = null;
var append = true;
var sourceDir = __dirname;
var map = null;
var deleteOld = false;

if (arguments.length === 2 && typeof options === 'object') {
// New signature
if (options.append != null) append = options.append;
if (options.space != null) space = options.space;
if (options.sourceDir) sourceDir = options.sourceDir;
if (options.map) map = options.map;
deleteOld = !!options.deleteOld;
} else {
// Old signature
Expand Down Expand Up @@ -115,8 +117,9 @@ exportObj.manifest = function(manifestPath, options) {
return through2.obj(
function(file, enc, cb) {
if (typeof file.origPath !== 'undefined') {
var manifestSrc = formatManifestPath(file.origPath);
var manifestDest = formatManifestPath(file.relative);
var mapped = typeof map === 'function' ? map(file.origPath, file.relative) || [] : [];
var manifestSrc = formatManifestPath(mapped[0] || file.origPath);
var manifestDest = formatManifestPath(mapped[1] || file.relative);
newManifest[manifestSrc] = manifestDest;
}

Expand Down