diff --git a/Gruntfile.js b/Gruntfile.js index 60262ab87c..1262a668a2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -438,7 +438,7 @@ module.exports = function (grunt) { grunt.registerTask('test', testSubtasks); // JS distribution task. - grunt.registerTask('dist-js', ['concat', 'uglify:core']); + grunt.registerTask('dist-js', ['concat', 'uglify:core', 'commonjs']); // CSS distribution task. grunt.registerTask('less-compile', ['less:compileCore', 'less:compileTheme']); @@ -464,8 +464,9 @@ module.exports = function (grunt) { }); grunt.registerTask('commonjs', 'Generate CommonJS entrypoint module in dist dir.', function () { - var files = grunt.config.get('concat.bootstrap.src'); - generateCommonJSModule(grunt, files); + var srcFiles = grunt.config.get('concat.bootstrap.src'); + var destFilepath = 'dist/js/npm.js'; + generateCommonJSModule(grunt, srcFiles, destFilepath); }); // Docs task. diff --git a/grunt/bs-commonjs-generator.js b/grunt/bs-commonjs-generator.js index 0a76333d92..8ab309b332 100644 --- a/grunt/bs-commonjs-generator.js +++ b/grunt/bs-commonjs-generator.js @@ -2,17 +2,16 @@ var fs = require('fs'); var path = require('path'); -var destDir = 'dist/js'; -var destFilename = 'npm.js'; -var destFilepath = path.join(destDir, destFilename); +module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) { + var destDir = path.dirname(destFilepath); -function srcPathToDestRequire(srcFilepath) { - var requirePath = path.relative(destDir, srcFilepath); - return "require('"+requirePath+"')"; -} + 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'); + var moduleOutputJs = srcFiles.map(srcPathToDestRequire).join('\n'); + try { fs.writeFileSync(destFilepath, moduleOutputJs); }