Skip to content

Instantly share code, notes, and snippets.

@shanestillwell
Created February 22, 2013 13:40
Show Gist options
  • Select an option

  • Save shanestillwell/5013440 to your computer and use it in GitHub Desktop.

Select an option

Save shanestillwell/5013440 to your computer and use it in GitHub Desktop.
Find assets and version them.
'use strict';
var mime = require('mime');
var subDir = '/public';
var files = [];
var assets = [];
var grepFiles = [];
// Mime types that we consider assets
var assetExtensions = [
'image/png',
'text/css'
];
var grepFileExtensions = [
'text/html'
];
var finder = require('findit').find(__dirname + subDir);
finder.on('file', function (file) {
files.push(file);
});
finder.on('end', function() {
var cwd = __dirname.length + 1;
for (var i = 0; i < files.length; i++) {
var mimetype = mime.lookup(files[i]);
var file;
if (-1 !== assetExtensions.indexOf(mimetype)) {
file = files[i].substr(cwd);
assets.push(file);
}
if (-1 !== grepFileExtensions.indexOf(mimetype)) {
file = files[i].substr(cwd);
grepFiles.push(file);
}
}
var Version = require("node-version-assets");
var versionInstance = new Version({
assets: assets,
grepFiles: grepFiles
});
versionInstance.run();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment