Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Commit

Permalink
All manifest file to have prefix values on keys
Browse files Browse the repository at this point in the history
  • Loading branch information
sonthonaxrk committed May 6, 2016
1 parent 6d03a46 commit cd9206b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,15 @@ var plugin = function () {
});
};


plugin.manifest = function (pth, opts) {
if (typeof pth === 'string') {
pth = {path: pth};
}

opts = objectAssign({
path: 'rev-manifest.json',
merge: false,
// Apply the default JSON transformer.
// The user can pass in his on transformer if he wants. The only requirement is that it should
// support 'parse' and 'stringify' methods.
transformer: JSON
merge: false
}, opts, pth);

var manifest = {};
Expand All @@ -138,8 +135,8 @@ plugin.manifest = function (pth, opts) {
return;
}

var revisionedFile = relPath(file.base, file.path);
var originalFile = path.join(path.dirname(revisionedFile), path.basename(file.revOrigPath)).replace(/\\/g, '/');
var revisionedFile = opts.prefixValue + relPath(file.base, file.path);
var originalFile = opts.prefixKey + path.join( path.dirname(revisionedFile), path.basename(file.revOrigPath)).replace(/\\/g, '/');

manifest[originalFile] = revisionedFile;

Expand All @@ -161,17 +158,18 @@ plugin.manifest = function (pth, opts) {
var oldManifest = {};

try {
oldManifest = opts.transformer.parse(manifestFile.contents.toString());
oldManifest = JSON.parse(manifestFile.contents.toString());
} catch (err) {}

manifest = objectAssign(oldManifest, manifest);
}

manifestFile.contents = new Buffer(opts.transformer.stringify(sortKeys(manifest), null, ' '));
manifestFile.contents = new Buffer(JSON.stringify(sortKeys(manifest), null, ' '));
this.push(manifestFile);
cb();
}.bind(this));
});
};


module.exports = plugin;

0 comments on commit cd9206b

Please sign in to comment.