From 441a239f9b2b380fb958b28af402e9ef59128ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Go=C3=9Fe?= Date: Thu, 7 Jan 2016 17:12:45 +0100 Subject: [PATCH 1/2] add browserify task to build singel plugins --- Gruntfile.js | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 5cd1ac80faaf..24093fb33dcf 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -69,7 +69,25 @@ module.exports = function(grunt) { return all; }; - var pluginCombinations = combine(grunt.file.expand('plugins/*.js')); + var plugins = grunt.file.expand('plugins/*.js'); + + var cleanedPlugins = plugins.filter(function (plugin) { + var pluginName = path.basename(plugin, '.js'); + + return excludedPlugins.indexOf(pluginName) === -1; + }); + + var pluginSingleFiles = cleanedPlugins.map(function (plugin) { + var filename = path.basename(plugin); + + var file = {}; + file.src = plugin; + file.dest = path.join('build', 'plugin', filename); + + return file; + }); + + var pluginCombinations = combine(plugins); var pluginConcatFiles = _.reduce(pluginCombinations, function (dict, comb) { var key = _.map(comb, function (plugin) { return path.basename(plugin, '.js'); @@ -103,6 +121,18 @@ module.exports = function(grunt) { dest: 'build/raven.js' }, plugins: { + files: pluginSingleFiles, + options: { + external: [ + '../src/singleton' + ], + transform: [ + [ versionify ], + [ new AddPluginBrowserifyTransformer() ] + ] + } + }, + 'plugins-combined': { files: pluginConcatFiles, options: { transform: [ @@ -161,11 +191,11 @@ module.exports = function(grunt) { options: { mocha: { ignoreLeaks: true, - grep: grunt.option('grep') + grep: grunt.option('grep') }, - log: true, + log: true, reporter: 'Dot', - run: true + run: true }, unit: { src: ['test/index.html'], @@ -179,7 +209,7 @@ module.exports = function(grunt) { release: { options: { - npm: false, + npm: false, commitMessage: 'Release <%= version %>' } }, @@ -315,11 +345,13 @@ module.exports = function(grunt) { grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']); grunt.registerTask('browserify.core', ['_prep', 'browserify:core']); grunt.registerTask('browserify.plugins', ['_prep', 'browserify:plugins']); + grunt.registerTask('browserify.plugins-combined', ['_prep', 'browserify:plugins-combined']); grunt.registerTask('build.test', ['_prep', 'browserify:test']); grunt.registerTask('build.core', ['browserify.core', 'uglify', 'fixSourceMaps', 'sri:dist']); - grunt.registerTask('build.all', ['browserify.plugins', 'uglify', 'fixSourceMaps', 'sri:dist', 'sri:build']); - grunt.registerTask('build', ['build.all']); - grunt.registerTask('dist', ['build.core', 'copy:dist']); + grunt.registerTask('build.plugins', ['browserify.plugins', 'uglify', 'fixSourceMaps', 'sri:dist']); + grunt.registerTask('build.plugins-combined', ['browserify.plugins-combined', 'uglify', 'fixSourceMaps', 'sri:dist', 'sri:build']); + grunt.registerTask('build', ['build.plugins-combined']); + grunt.registerTask('dist', ['build.core', 'build.plugins', 'copy:dist']); // Test task grunt.registerTask('test', ['eslint', 'browserify.core', 'browserify:test', 'mocha']); From 4634c526a12362d079f1f93a0f24c9263a606437 Mon Sep 17 00:00:00 2001 From: Ben Vinegar Date: Sun, 17 Jan 2016 17:06:49 -0800 Subject: [PATCH 2/2] Each dist/plugin has unique UMD header (e.g. Raven.AngularPlugin) --- Gruntfile.js | 109 ++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 48 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 24093fb33dcf..c4729ac0e4f8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -82,7 +82,7 @@ module.exports = function(grunt) { var file = {}; file.src = plugin; - file.dest = path.join('build', 'plugin', filename); + file.dest = path.join('build', 'plugins', filename); return file; }); @@ -100,58 +100,71 @@ module.exports = function(grunt) { return dict; }, {}); - var gruntConfig = { - pkg: grunt.file.readJSON('package.json'), - aws: grunt.file.exists('aws.json') ? grunt.file.readJSON('aws.json'): {}, - - clean: ['build'], - - browserify: { - options: { - banner: grunt.file.read('template/_copyright.js'), + var browserifyConfig = { + options: { + banner: grunt.file.read('template/_copyright.js'), browserifyOptions: { - standalone: 'Raven' // umd - - }, - transform: [versionify], - plugin: [ derequire ] - }, - core: { - src: 'src/singleton.js', - dest: 'build/raven.js' + standalone: 'Raven' // umd }, - plugins: { - files: pluginSingleFiles, - options: { - external: [ - '../src/singleton' - ], - transform: [ - [ versionify ], - [ new AddPluginBrowserifyTransformer() ] - ] - } - }, - 'plugins-combined': { - files: pluginConcatFiles, + transform: [ versionify ], + plugin: [ derequire ] + }, + core: { + src: 'src/singleton.js', + dest: 'build/raven.js' + }, + 'plugins-combined': { + files: pluginConcatFiles, options: { - transform: [ - [ versionify ], - [ new AddPluginBrowserifyTransformer() ] - ] - } - }, - test: { - src: 'test/**/*.test.js', + transform: [ + [ versionify ], + [ new AddPluginBrowserifyTransformer() ] + ] + } + }, + test: { + src: 'test/**/*.test.js', dest: 'build/raven.test.js', options: { - browserifyOptions: { - debug: true // source maps - }, - plugin: [proxyquire.plugin] + browserifyOptions: { + debug: true // source maps + }, + plugin: [proxyquire.plugin] + } + } + }; + + // Create a dedicated entry in browserify config for + // each individual plugin (each needs a unique `standalone` + // config) + var browserifyPluginTaskNames = []; + pluginSingleFiles.forEach(function (item) { + var name = item.src + .replace(/.*\//, '') // everything before slash + .replace('.js', ''); // extension + var capsName = name.charAt(0).toUpperCase() + name.slice(1); + var config = { + src: item.src, + dest: item.dest, + options: { + browserifyOptions: { + // e.g. Raven.Plugins.Angular + standalone: 'Raven.Plugins.' + capsName } } - }, + }; + browserifyConfig[name] = config; + browserifyPluginTaskNames.push('browserify:' + name); + }); + + + var gruntConfig = { + pkg: grunt.file.readJSON('package.json'), + aws: grunt.file.exists('aws.json') ? grunt.file.readJSON('aws.json'): {}, + + clean: ['build'], + + browserify: browserifyConfig, uglify: { options: { @@ -258,7 +271,7 @@ module.exports = function(grunt) { copy: { dist: { expand: true, - flatten: true, + flatten: false, cwd: 'build/', src: '**', dest: 'dist/' @@ -344,7 +357,7 @@ module.exports = function(grunt) { // Build tasks grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']); grunt.registerTask('browserify.core', ['_prep', 'browserify:core']); - grunt.registerTask('browserify.plugins', ['_prep', 'browserify:plugins']); + grunt.registerTask('browserify.plugins', ['_prep'].concat(browserifyPluginTaskNames)); grunt.registerTask('browserify.plugins-combined', ['_prep', 'browserify:plugins-combined']); grunt.registerTask('build.test', ['_prep', 'browserify:test']); grunt.registerTask('build.core', ['browserify.core', 'uglify', 'fixSourceMaps', 'sri:dist']);