Closed johnnyreilly closed 10 years ago
@vanjacosic - I think I have it. The code in npm (0.0.4) looks like it's out of date. This is the index.js
I downloaded from npm:
// Requirements
var map = require('map-stream');
var gutil = require('gulp-util');
var path = require('path');
var fs = require('fs');
// Helper function
function errorMessage(message){
throw new gutil.PluginError('gulp-asset-manifest', message);
}
function checkManifestFile(filename) {
// Check if manifest file exists
return fs.existsSync(filename, function (exists) {
return exists;
});
}
function readManifestFile(filename) {
// Read data from manifest file
return fs.readFileSync(filename, 'utf8', function(err, data) {
if (err) {
errorMessage('Error reading manifest file.');
}
return data;
});
}
function writeManifestFile(data, filename) {
// Write data to manifest file
fs.writeFileSync(filename, JSON.stringify(data));
}
function resetManifestFile(bundlename, filename) {
// Check if manifest file exists
var doesFileExist = checkManifestFile(filename);
if(doesFileExist){
// Read manifest file contents
var contents = readManifestFile(filename);
// Copy data into file list
fileList = JSON.parse(contents);
// Reset or create array for each bundle
fileList[bundlename] = [];
}
else{
// Create empty file list
fileList = {};
}
// Write file list to manifest file
writeManifestFile(fileList, filename);
}
// Plugin function
module.exports = function(options) {
// Reset file list
var fileList;
// Prepare options
options = options || {};
options.manifestFile = options.manifestFile || 'asset_manifest.json';
var pathPrepend = options.pathPrepend || '';
if(!options.bundleName){
errorMessage('A bundle name is required. Please refer to the docs.');
}
if (options.log) {
gutil.log('Preparing bundle:', gutil.colors.green(options.bundleName));
}
// Reset asset file
resetManifestFile(options.bundleName, options.manifestFile);
// Process files
return map(function(file, callback) {
// Let empty files pass
if (file.isNull()) {
return callback(null, file);
}
// Emit error for streams
if (file.isStream()) {
errorMessage('Streams are not supported');
}
// Read asset file contents
var contents = readManifestFile(options.manifestFile);
// Copy data into file list
fileList = JSON.parse(contents);
var filename;
// Retrieve filename
if (options.includeRelativePath) {
filename = path.relative(process.cwd(), file.path);
}
else {
filename = path.basename(file.path);
}
// Add filename to fileList
if (!fileList[options.bundleName]){
fileList[options.bundleName] = [];
}
fileList[options.bundleName].push(pathPrepend + filename);
// Write list to asset file
writeManifestFile(fileList, options.manifestFile);
if (options.log) {
gutil.log('Added', gutil.colors.green(filename), 'to asset manifest.');
}
callback(null, file);
});
};
As you can see this does not feature the pathSeparator
at all whereas the code on GitHub does. I think you might need to update npm with the latest version of index.js
.
Yup - bingo. I just manually copied the index.js
from GitHub to my project and it all worked as expected. It would be great if you could update npm. Thanks again for your hard work!
@johnnyreilly oh wow, I feel like an idiot :smile:
I took a look at the problem yesterday but couldn't immediately figure out what was wrong, so decided to take a closer look today.
But you of course beat me to it, I totally forgot to publish to npm after the last two PRs.
Thanks for letting me know - and please keep it up. It's so great to get feedback on this stuff :)
No problem @vanjacosic - it happens to us all! Do you know when you'll get a chance to publish?
@johnnyreilly Yeah (I guess I didn't state that very explicitly) but I did an npm publish right before I closed the issue :)
Fantastic!
Hello again!,
I've just been experimenting with the
options.pathSeparator
property and it doesn't seem to have any effect.I've been supplying apathSeparator
of"/"
but the output of my manifest looks like this:So still using the `"\\"`` as a separator (I'm on Windows).
In case it helps the gulpfile I'm using is here. (This is part of a little toy project of mine that I use to test out technologies.)