Skip to content

Commit 4f862ca

Browse files
committed
add extra_bundles - handle options in partial_bundle
1 parent c3a8b48 commit 4f862ca

File tree

7 files changed

+102
-29
lines changed

7 files changed

+102
-29
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
"plotly"
2222
],
2323
"scripts": {
24-
"bundle": "node tasks/bundle.js",
2524
"partial-bundle": "node tasks/partial_bundle.js",
25+
"bundle": "node tasks/bundle.js",
26+
"extra-bundles": "node tasks/extra_bundles.js",
2627
"stats": "node tasks/stats.js",
2728
"find-strings": "node tasks/find_locale_strings.js",
2829
"preprocess": "node tasks/preprocess.js",
29-
"build": "node tasks/empty_dist.js && npm run preprocess && npm run find-strings && npm run bundle && npm run partial-bundle && npm run stats",
30+
"build": "node tasks/empty_dist.js && npm run preprocess && npm run find-strings && npm run bundle && npm run extra-bundles && npm run stats",
3031
"cibuild": "node tasks/empty_dist.js && npm run preprocess && node tasks/cibundle.js",
3132
"watch": "node tasks/watch.js",
3233
"lint": "eslint --version && eslint .",

tasks/extra_bundles.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var runSeries = require('run-series');
2+
3+
var partialBundle = require('./partial_bundle');
4+
var constants = require('./util/constants');
5+
var partialBundlePaths = constants.partialBundleNames.map(constants.makePartialBundleOpts);
6+
7+
var tasks = [];
8+
9+
// Browserify the plotly.js partial bundles
10+
for(var i = 0; i < partialBundlePaths.length; i++) {
11+
var opts = partialBundlePaths[i];
12+
13+
partialBundle(tasks, {
14+
name: opts.name,
15+
index: opts.index,
16+
dist: opts.dist,
17+
distMin: opts.distMin,
18+
traceList: opts.traceList
19+
});
20+
}
21+
22+
runSeries(tasks, function(err) {
23+
if(err) throw err;
24+
});

tasks/no_es6_dist.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var eslint = require('eslint');
22
var constants = require('./util/constants');
33
var EXIT_CODE = 0;
44

5+
var partialBundlePaths = constants.partialBundleNames.map(constants.makePartialBundleOpts);
6+
57
assertES5();
68

79
// Ensure no ES6 has snuck through into the build:
@@ -17,7 +19,7 @@ function assertES5() {
1719
}
1820
});
1921

20-
var files = constants.partialBundlePaths.map(function(f) { return f.dist; });
22+
var files = partialBundlePaths.map(function(f) { return f.dist; });
2123
files.unshift(constants.pathToPlotlyDist);
2224

2325
var report = cli.executeOnFiles(files);

tasks/partial_bundle.js

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,59 @@ var common = require('./util/common');
88
var _bundle = require('./util/browserify_wrapper');
99

1010
var header = constants.licenseDist + '\n';
11-
12-
var tasks = [];
1311
var allTraces = fs.readdirSync(path.join(constants.pathToSrc, 'traces'));
1412
var fullIndex = fs.readFileSync(constants.pathToPlotlyIndex, 'utf-8');
1513

14+
var argv = process.argv;
15+
16+
if(argv.length > 2) {
17+
// command line
18+
19+
var traceList = ['scatter']; // added by default
20+
var name;
21+
for(var i = 2; i < argv.length; i++) {
22+
var a = argv[i];
23+
24+
if(
25+
allTraces.indexOf(a) !== -1 && // requested
26+
traceList.indexOf(a) === -1 // not added before
27+
) {
28+
traceList.push(a);
29+
}
30+
if(a.indexOf('name=') !== -1) name = a.replace('name=', '');
31+
}
32+
if(!name) name = 'custom';
33+
traceList = traceList.sort();
34+
35+
var opts = {
36+
traceList: traceList,
37+
name: name,
38+
39+
index: path.join(constants.pathToBuild, 'index-' + name + '.js'),
40+
dist: path.join(constants.pathToDist, 'plotly-' + name + '.js'),
41+
distMin: path.join(constants.pathToDist, 'plotly-' + name + '.min.js')
42+
};
43+
44+
console.log(opts);
45+
46+
var tasks = [];
47+
48+
partialBundle(tasks, opts);
49+
50+
runSeries(tasks, function(err) {
51+
if(err) throw err;
52+
});
53+
}
54+
1655
// Browserify the plotly.js partial bundles
17-
constants.partialBundlePaths.forEach(function(pathObj) {
18-
tasks.push(function(done) {
19-
var traceList = constants.partialBundleTraces[pathObj.name];
56+
function partialBundle(tasks, opts) {
57+
var name = opts.name;
58+
var index = opts.index;
59+
var dist = opts.dist;
60+
var distMin = opts.distMin;
61+
var traceList = opts.traceList;
2062

63+
tasks.push(function(done) {
2164
var partialIndex = fullIndex;
2265
allTraces.forEach(function(trace) {
2366
if(traceList.indexOf(trace) === -1) {
@@ -37,25 +80,23 @@ constants.partialBundlePaths.forEach(function(pathObj) {
3780
}
3881
});
3982

40-
common.writeFile(pathObj.index, partialIndex, done);
83+
common.writeFile(index, partialIndex, done);
4184
});
4285

4386
tasks.push(function(done) {
44-
_bundle(pathObj.index, pathObj.dist, {
87+
_bundle(index, dist, {
4588
standalone: 'Plotly',
46-
pathToMinBundle: pathObj.distMin
89+
pathToMinBundle: distMin
4790
}, function() {
48-
var headerDist = header.replace('plotly.js', 'plotly.js (' + pathObj.name + ')');
49-
var headerDistMin = header.replace('plotly.js', 'plotly.js (' + pathObj.name + ' - minified)');
91+
var headerDist = header.replace('plotly.js', 'plotly.js (' + name + ')');
92+
var headerDistMin = header.replace('plotly.js', 'plotly.js (' + name + ' - minified)');
5093

51-
prependFile(pathObj.dist, headerDist, common.throwOnError);
52-
prependFile(pathObj.distMin, headerDistMin, common.throwOnError);
94+
prependFile(dist, headerDist, common.throwOnError);
95+
prependFile(distMin, headerDistMin, common.throwOnError);
5396

5497
done();
5598
});
5699
});
57-
});
100+
}
58101

59-
runSeries(tasks, function(err) {
60-
if(err) throw err;
61-
});
102+
module.exports = partialBundle;

tasks/stats.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ var ENC = 'utf-8';
1919
var JS = '.js';
2020
var MINJS = '.min.js';
2121

22+
var partialBundlePaths = constants.partialBundleNames.map(constants.makePartialBundleOpts);
23+
2224
// main
2325
common.writeFile(pathDistREADME, getReadMeContent());
2426

@@ -136,7 +138,7 @@ function getMainBundleInfo() {
136138
'',
137139
'Starting in `v1.15.0`, plotly.js also ships with several _partial_ bundles:',
138140
'',
139-
constants.partialBundlePaths.map(makeBundleHeaderInfo).join('\n'),
141+
partialBundlePaths.map(makeBundleHeaderInfo).join('\n'),
140142
'',
141143
'Starting in `v1.39.0`, each plotly.js partial bundle has a corresponding npm package with no dependencies.',
142144
'',
@@ -151,7 +153,7 @@ function getMainBundleInfo() {
151153

152154
// info about partial bundles
153155
function getPartialBundleInfo() {
154-
return constants.partialBundlePaths.map(makeBundleInfo);
156+
return partialBundlePaths.map(makeBundleInfo);
155157
}
156158

157159
// footer info
@@ -172,7 +174,7 @@ function makeBundleHeaderInfo(pathObj) {
172174
function makeBundleInfo(pathObj) {
173175
var name = pathObj.name;
174176
var sizes = findSizes(pathObj);
175-
var traceList = constants.partialBundleTraces[pathObj.name];
177+
var traceList = pathObj.traceList;
176178
var pkgName = 'plotly.js-' + name + '-dist';
177179

178180
return [

tasks/sync_packages.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ var copyrightAndLicense = [
2323
''
2424
].join('\n');
2525

26+
var partialBundlePaths = constants.partialBundleNames.map(constants.makePartialBundleOpts);
27+
2628
// sync "partial bundle" packages
27-
constants.partialBundlePaths
29+
partialBundlePaths
2830
.map(function(d) {
2931
return {
3032
name: 'plotly.js-' + d.name + '-dist',
@@ -44,7 +46,7 @@ constants.partialBundlePaths
4446
.forEach(syncPartialBundlePkg);
4547

4648
// sync "minified partial bundle" packages
47-
constants.partialBundlePaths
49+
partialBundlePaths
4850
.map(function(d) {
4951
return {
5052
name: 'plotly.js-' + d.name + '-dist-min',
@@ -103,7 +105,7 @@ function syncPartialBundlePkg(d) {
103105

104106

105107
function writeREADME(cb) {
106-
var traceList = constants.partialBundleTraces[d.name];
108+
var traceList = d.traceList;
107109

108110
var cnt = [
109111
'# ' + d.name,

tasks/util/constants.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,21 @@ var partialBundleTraces = {
131131
]
132132
};
133133

134-
var partialBundlePaths = partialBundleNames.map(function(name) {
134+
function makePartialBundleOpts(name) {
135135
return {
136136
name: name,
137+
traceList: partialBundleTraces[name],
137138
index: path.join(pathToBuild, 'index-' + name + '.js'),
138139
dist: path.join(pathToDist, 'plotly-' + name + '.js'),
139140
distMin: path.join(pathToDist, 'plotly-' + name + '.min.js')
140141
};
141-
});
142+
}
142143

143144
var year = (new Date()).getFullYear();
144145

145146
module.exports = {
147+
makePartialBundleOpts: makePartialBundleOpts,
148+
146149
pathToRoot: pathToRoot,
147150
pathToSrc: pathToSrc,
148151
pathToLib: pathToLib,
@@ -162,9 +165,7 @@ module.exports = {
162165
pathToSchema: path.join(pathToDist, 'plot-schema.json'),
163166
pathToTranslationKeys: path.join(pathToDist, 'translation-keys.txt'),
164167

165-
partialBundleTraces: partialBundleTraces,
166168
partialBundleNames: partialBundleNames,
167-
partialBundlePaths: partialBundlePaths,
168169

169170
pathToTopojsonSrc: pathToTopojsonSrc,
170171
pathToTopojsonDist: path.join(pathToDist, 'topojson/'),

0 commit comments

Comments
 (0)