2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-11 18:02:28 +03:00

generate commonjs/npm entrypoint module via grunt task

This commit is contained in:
James Friend
2014-08-28 09:24:23 +08:00
parent 689faaf16f
commit e7991a9a1e
3 changed files with 41 additions and 12 deletions
+23
View File
@@ -0,0 +1,23 @@
'use strict';
var fs = require('fs');
var path = require('path');
var destDir = 'dist/js';
var destFilename = 'npm.js';
var destFilepath = path.join(destDir, destFilename);
function srcPathToDestRequire(srcFilepath) {
var requirePath = path.relative(destDir, srcFilepath);
return "require('"+requirePath+"')";
}
module.exports = function generateCommonJSModule(grunt, files) {
var moduleOutputJs = files.map(srcPathToDestRequire).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
}
catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
};