Skip to content

Commit ad4985a

Browse files
committed
Merge pull request #476 from getsentry/plugin-bower
Build plugin files into /dist for use w/o package manager
2 parents 5922523 + 4634c52 commit ad4985a

File tree

1 file changed

+88
-43
lines changed

1 file changed

+88
-43
lines changed

Gruntfile.js

+88-43
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,25 @@ module.exports = function(grunt) {
6969
return all;
7070
};
7171

72-
var pluginCombinations = combine(grunt.file.expand('plugins/*.js'));
72+
var plugins = grunt.file.expand('plugins/*.js');
73+
74+
var cleanedPlugins = plugins.filter(function (plugin) {
75+
var pluginName = path.basename(plugin, '.js');
76+
77+
return excludedPlugins.indexOf(pluginName) === -1;
78+
});
79+
80+
var pluginSingleFiles = cleanedPlugins.map(function (plugin) {
81+
var filename = path.basename(plugin);
82+
83+
var file = {};
84+
file.src = plugin;
85+
file.dest = path.join('build', 'plugins', filename);
86+
87+
return file;
88+
});
89+
90+
var pluginCombinations = combine(plugins);
7391
var pluginConcatFiles = _.reduce(pluginCombinations, function (dict, comb) {
7492
var key = _.map(comb, function (plugin) {
7593
return path.basename(plugin, '.js');
@@ -82,46 +100,71 @@ module.exports = function(grunt) {
82100
return dict;
83101
}, {});
84102

85-
var gruntConfig = {
86-
pkg: grunt.file.readJSON('package.json'),
87-
aws: grunt.file.exists('aws.json') ? grunt.file.readJSON('aws.json'): {},
88-
89-
clean: ['build'],
90-
91-
browserify: {
92-
options: {
93-
banner: grunt.file.read('template/_copyright.js'),
103+
var browserifyConfig = {
104+
options: {
105+
banner: grunt.file.read('template/_copyright.js'),
94106
browserifyOptions: {
95-
standalone: 'Raven' // umd
96-
97-
},
98-
transform: [versionify],
99-
plugin: [ derequire ]
107+
standalone: 'Raven' // umd
100108
},
101-
core: {
102-
src: 'src/singleton.js',
103-
dest: 'build/raven.js'
104-
},
105-
plugins: {
106-
files: pluginConcatFiles,
109+
transform: [ versionify ],
110+
plugin: [ derequire ]
111+
},
112+
core: {
113+
src: 'src/singleton.js',
114+
dest: 'build/raven.js'
115+
},
116+
'plugins-combined': {
117+
files: pluginConcatFiles,
107118
options: {
108-
transform: [
109-
[ versionify ],
110-
[ new AddPluginBrowserifyTransformer() ]
111-
]
112-
}
113-
},
114-
test: {
115-
src: 'test/**/*.test.js',
119+
transform: [
120+
[ versionify ],
121+
[ new AddPluginBrowserifyTransformer() ]
122+
]
123+
}
124+
},
125+
test: {
126+
src: 'test/**/*.test.js',
116127
dest: 'build/raven.test.js',
117128
options: {
118-
browserifyOptions: {
119-
debug: true // source maps
120-
},
121-
plugin: [proxyquire.plugin]
129+
browserifyOptions: {
130+
debug: true // source maps
131+
},
132+
plugin: [proxyquire.plugin]
133+
}
134+
}
135+
};
136+
137+
// Create a dedicated entry in browserify config for
138+
// each individual plugin (each needs a unique `standalone`
139+
// config)
140+
var browserifyPluginTaskNames = [];
141+
pluginSingleFiles.forEach(function (item) {
142+
var name = item.src
143+
.replace(/.*\//, '') // everything before slash
144+
.replace('.js', ''); // extension
145+
var capsName = name.charAt(0).toUpperCase() + name.slice(1);
146+
var config = {
147+
src: item.src,
148+
dest: item.dest,
149+
options: {
150+
browserifyOptions: {
151+
// e.g. Raven.Plugins.Angular
152+
standalone: 'Raven.Plugins.' + capsName
122153
}
123154
}
124-
},
155+
};
156+
browserifyConfig[name] = config;
157+
browserifyPluginTaskNames.push('browserify:' + name);
158+
});
159+
160+
161+
var gruntConfig = {
162+
pkg: grunt.file.readJSON('package.json'),
163+
aws: grunt.file.exists('aws.json') ? grunt.file.readJSON('aws.json'): {},
164+
165+
clean: ['build'],
166+
167+
browserify: browserifyConfig,
125168

126169
uglify: {
127170
options: {
@@ -161,11 +204,11 @@ module.exports = function(grunt) {
161204
options: {
162205
mocha: {
163206
ignoreLeaks: true,
164-
grep: grunt.option('grep')
207+
grep: grunt.option('grep')
165208
},
166-
log: true,
209+
log: true,
167210
reporter: 'Dot',
168-
run: true
211+
run: true
169212
},
170213
unit: {
171214
src: ['test/index.html'],
@@ -179,7 +222,7 @@ module.exports = function(grunt) {
179222

180223
release: {
181224
options: {
182-
npm: false,
225+
npm: false,
183226
commitMessage: 'Release <%= version %>'
184227
}
185228
},
@@ -228,7 +271,7 @@ module.exports = function(grunt) {
228271
copy: {
229272
dist: {
230273
expand: true,
231-
flatten: true,
274+
flatten: false,
232275
cwd: 'build/',
233276
src: '**',
234277
dest: 'dist/'
@@ -314,12 +357,14 @@ module.exports = function(grunt) {
314357
// Build tasks
315358
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
316359
grunt.registerTask('browserify.core', ['_prep', 'browserify:core']);
317-
grunt.registerTask('browserify.plugins', ['_prep', 'browserify:plugins']);
360+
grunt.registerTask('browserify.plugins', ['_prep'].concat(browserifyPluginTaskNames));
361+
grunt.registerTask('browserify.plugins-combined', ['_prep', 'browserify:plugins-combined']);
318362
grunt.registerTask('build.test', ['_prep', 'browserify:test']);
319363
grunt.registerTask('build.core', ['browserify.core', 'uglify', 'fixSourceMaps', 'sri:dist']);
320-
grunt.registerTask('build.all', ['browserify.plugins', 'uglify', 'fixSourceMaps', 'sri:dist', 'sri:build']);
321-
grunt.registerTask('build', ['build.all']);
322-
grunt.registerTask('dist', ['build.core', 'copy:dist']);
364+
grunt.registerTask('build.plugins', ['browserify.plugins', 'uglify', 'fixSourceMaps', 'sri:dist']);
365+
grunt.registerTask('build.plugins-combined', ['browserify.plugins-combined', 'uglify', 'fixSourceMaps', 'sri:dist', 'sri:build']);
366+
grunt.registerTask('build', ['build.plugins-combined']);
367+
grunt.registerTask('dist', ['build.core', 'build.plugins', 'copy:dist']);
323368

324369
// Test task
325370
grunt.registerTask('test', ['eslint', 'browserify.core', 'browserify:test', 'mocha']);

0 commit comments

Comments
 (0)