diff options
author | James Friend <james.friend@agworld.com.au> | 2014-08-28 05:24:23 +0400 |
---|---|---|
committer | James Friend <james.friend@agworld.com.au> | 2014-08-28 05:24:23 +0400 |
commit | e7991a9a1e2f474c8f1d8a2e0ed113816f1c5e82 (patch) | |
tree | d36a0d90ccef10b77ca7b379021eb93ad52e2db2 /grunt | |
parent | 689faaf16f255ae5bc37c6e348fd593ae270a103 (diff) |
generate commonjs/npm entrypoint module via grunt task
Diffstat (limited to 'grunt')
-rw-r--r-- | grunt/bs-commonjs-generator.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/grunt/bs-commonjs-generator.js b/grunt/bs-commonjs-generator.js new file mode 100644 index 0000000000..0a76333d92 --- /dev/null +++ b/grunt/bs-commonjs-generator.js @@ -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.'); +}; |