aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Friend <[email protected]>2014-08-28 09:24:23 +0800
committerJames Friend <[email protected]>2014-08-28 09:24:23 +0800
commite7991a9a1e2f474c8f1d8a2e0ed113816f1c5e82 (patch)
treed36a0d90ccef10b77ca7b379021eb93ad52e2db2
parent689faaf16f255ae5bc37c6e348fd593ae270a103 (diff)
downloadbootstrap-e7991a9a1e2f474c8f1d8a2e0ed113816f1c5e82.tar.xz
bootstrap-e7991a9a1e2f474c8f1d8a2e0ed113816f1c5e82.zip
generate commonjs/npm entrypoint module via grunt task
-rw-r--r--Gruntfile.js6
-rw-r--r--dist/js/npm.js24
-rw-r--r--grunt/bs-commonjs-generator.js23
3 files changed, 41 insertions, 12 deletions
diff --git a/Gruntfile.js b/Gruntfile.js
index ca9d43eec..3fc645faf 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -20,6 +20,7 @@ module.exports = function (grunt) {
var generateGlyphiconsData = require('./grunt/bs-glyphicons-data-generator.js');
var BsLessdocParser = require('./grunt/bs-lessdoc-parser.js');
var generateRawFiles = require('./grunt/bs-raw-files-generator.js');
+ var generateCommonJSModule = require('./grunt/bs-commonjs-generator.js');
var updateShrinkwrap = require('./grunt/shrinkwrap.js');
// Project configuration.
@@ -459,6 +460,11 @@ module.exports = function (grunt) {
generateRawFiles(grunt, banner);
});
+ grunt.registerTask('build-commonjs', 'Build CommonJS entrypoint module for JS.', function () {
+ var files = grunt.config.get('concat.bootstrap.src');
+ generateCommonJSModule(grunt, files);
+ });
+
// Task for updating the npm packages used by the Travis build.
grunt.registerTask('update-shrinkwrap', ['exec:npmUpdate', 'exec:npmShrinkWrap', '_update-shrinkwrap']);
grunt.registerTask('_update-shrinkwrap', function () { updateShrinkwrap.call(this, grunt); });
diff --git a/dist/js/npm.js b/dist/js/npm.js
index 17b0feda3..c7c20adfe 100644
--- a/dist/js/npm.js
+++ b/dist/js/npm.js
@@ -1,12 +1,12 @@
-require('../../js/transition')
-require('../../js/alert')
-require('../../js/button')
-require('../../js/carousel')
-require('../../js/collapse')
-require('../../js/dropdown')
-require('../../js/modal')
-require('../../js/tooltip')
-require('../../js/popover')
-require('../../js/scrollspy')
-require('../../js/tab')
-require('../../js/affix')
+require('../../js/transition.js')
+require('../../js/alert.js')
+require('../../js/button.js')
+require('../../js/carousel.js')
+require('../../js/collapse.js')
+require('../../js/dropdown.js')
+require('../../js/modal.js')
+require('../../js/tooltip.js')
+require('../../js/popover.js')
+require('../../js/scrollspy.js')
+require('../../js/tab.js')
+require('../../js/affix.js') \ No newline at end of file
diff --git a/grunt/bs-commonjs-generator.js b/grunt/bs-commonjs-generator.js
new file mode 100644
index 000000000..0a76333d9
--- /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.');
+};