Skip to content

Commit f6932a7

Browse files
authored
Merge pull request #5712 from plotly/separate-custom-bundle-script
Separate command line script for making custom bundles and rename it to "custom-bundle"
2 parents d92a59d + 75af4cd commit f6932a7

File tree

5 files changed

+119
-95
lines changed

5 files changed

+119
-95
lines changed

CUSTOM_BUNDLE.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,47 @@ npm i
1010

1111
By default all traces and transforms are included in the bundle if you simply run:
1212
```sh
13-
npm run partial-bundle
13+
npm run custom-bundle
1414
```
1515

1616
Use the `traces` option to include just the trace types you need.
1717
```sh
18-
npm run partial-bundle -- --traces scatter,scattergl,scatter3d
18+
npm run custom-bundle -- --traces scatter,scattergl,scatter3d
1919
```
2020
Please note that the `scatter` trace is currently included in all bundles and cannot be removed.
2121
[This behaviour may change in the future](https://github.com/plotly/plotly.js/pull/5535), so we recommend that you explicitly include `scatter` anyway if you need it in your bundle.
2222

2323
Use the `transforms` option to specify which should be included.
2424
```sh
25-
npm run partial-bundle -- --transforms sort,filter
25+
npm run custom-bundle -- --transforms sort,filter
2626
```
2727

2828
Or use `transforms none` to exclude them all.
2929
```sh
30-
npm run partial-bundle -- --transforms none
30+
npm run custom-bundle -- --transforms none
3131
```
3232

3333
Use the `out` option to change the bundle filename (default `custom`).
3434
The new bundle will be created in the `dist/` directory and named `plotly-<out>.min.js` or `plotly-<out>.js` if unminified.
3535
```sh
36-
npm run partial-bundle -- --out myBundleName
36+
npm run custom-bundle -- --out myBundleName
3737
```
3838

3939
Use the `unminified` option to disable compression.
4040
```sh
41-
npm run partial-bundle -- --unminified
41+
npm run custom-bundle -- --unminified
4242
```
4343

4444
# Example illustrating use of different options together
4545
To create an unminified custom bundle named `myScatters` including `scatter`, `scattergl` and `scatter3d` traces without any transforms:
4646
```sh
47-
npm run partial-bundle -- \
47+
npm run custom-bundle -- \
4848
--unminified \
4949
--out myScatters \
5050
--traces scatter,scattergl,scatter3d \
5151
--transforms none
5252
```
5353
Or simply on one line:
5454
```sh
55-
npm run partial-bundle -- --unminified --out myScatters --traces scatter,scattergl,scatter3d --transforms none
55+
npm run custom-bundle -- --unminified --out myScatters --traces scatter,scattergl,scatter3d --transforms none
5656
```

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"plotly"
2222
],
2323
"scripts": {
24-
"partial-bundle": "node tasks/partial_bundle.js",
24+
"custom-bundle": "node tasks/custom_bundle.js",
2525
"bundle": "node tasks/bundle.js",
2626
"extra-bundles": "node tasks/extra_bundles.js",
2727
"stats": "node tasks/stats.js",

tasks/custom_bundle.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
var path = require('path');
2+
var minimist = require('minimist');
3+
var runSeries = require('run-series');
4+
5+
var partialBundle = require('./partial_bundle');
6+
var constants = require('./util/constants');
7+
8+
var allTransforms = constants.allTransforms;
9+
var allTraces = constants.allTraces;
10+
11+
function createList(outList, inList, allList, type) {
12+
for(var i = 0; i < inList.length; i++) {
13+
var t = inList[i];
14+
if(
15+
outList.indexOf(t) === -1 // not added before
16+
) {
17+
if(allList.indexOf(t) === -1) {
18+
console.error(t, 'is not a valid ' + type + '!', 'Valid ' + type + 's are:', allList);
19+
} else {
20+
outList.push(t);
21+
}
22+
}
23+
}
24+
25+
return outList.sort();
26+
}
27+
28+
function isFalse(a) {
29+
return (
30+
a === 'none' ||
31+
a === 'false'
32+
);
33+
}
34+
35+
function inputBoolean(a, dflt) {
36+
return !a ? dflt : !isFalse(a);
37+
}
38+
39+
function inputArray(a, dflt) {
40+
dflt = dflt.slice();
41+
42+
return (
43+
isFalse(a) ? [] :
44+
!a || a === 'all' ? dflt :
45+
a.split(',')
46+
);
47+
}
48+
49+
if(process.argv.length > 2) {
50+
// command line
51+
52+
var args = minimist(process.argv.slice(2), {});
53+
54+
// parse arguments
55+
var unminified = inputBoolean(args.unminified, false);
56+
var out = args.out ? args.out : 'custom';
57+
var traces = inputArray(args.traces, allTraces);
58+
var transforms = inputArray(args.transforms, allTransforms);
59+
60+
var opts = {
61+
traceList: createList(['scatter'], traces, allTraces, 'trace'),
62+
transformList: createList([], transforms, allTransforms, 'transform'),
63+
64+
name: out,
65+
index: path.join(constants.pathToLib, 'index-' + out + '.js')
66+
};
67+
68+
if(unminified) {
69+
opts.dist = path.join(constants.pathToDist, 'plotly-' + out + '.js');
70+
} else {
71+
opts.distMin = path.join(constants.pathToDist, 'plotly-' + out + '.min.js');
72+
}
73+
74+
console.log(opts);
75+
76+
opts.calendars = true;
77+
opts.deleteIndex = true;
78+
79+
var tasks = [];
80+
81+
partialBundle(tasks, opts);
82+
83+
runSeries(tasks, function(err) {
84+
if(err) throw err;
85+
});
86+
}

tasks/extra_bundles.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
1+
var minimist = require('minimist');
12
var runSeries = require('run-series');
23

34
var partialBundle = require('./partial_bundle');
45
var constants = require('./util/constants');
56
var partialBundlePaths = constants.partialBundleNames.map(constants.makePartialBundleOpts);
67

8+
var list = partialBundlePaths;
9+
10+
if(process.argv.length > 2) {
11+
// command line
12+
13+
var args = minimist(process.argv.slice(2), {});
14+
var names = args._;
15+
list = [];
16+
for(var k = 0; k < names.length; k++) {
17+
for(var q = 0; q < partialBundlePaths.length; q++) {
18+
var p = partialBundlePaths[q];
19+
if(partialBundlePaths[q].name === names[k]) {
20+
list.push(p);
21+
break;
22+
}
23+
}
24+
}
25+
}
26+
727
var tasks = [];
828

929
// Browserify the plotly.js partial bundles
10-
for(var i = 0; i < partialBundlePaths.length; i++) {
11-
var opts = partialBundlePaths[i];
30+
for(var i = 0; i < list.length; i++) {
31+
var opts = list[i];
1232

1333
partialBundle(tasks, {
1434
name: opts.name,

tasks/partial_bundle.js

+2-84
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
var path = require('path');
2-
var minimist = require('minimist');
3-
var runSeries = require('run-series');
41
var prependFile = require('prepend-file');
52

63
var constants = require('./util/constants');
@@ -12,85 +9,8 @@ var allTransforms = constants.allTransforms;
129
var allTraces = constants.allTraces;
1310
var mainIndex = constants.mainIndex;
1411

15-
function createList(outList, inList, allList, type) {
16-
for(var i = 0; i < inList.length; i++) {
17-
var t = inList[i];
18-
if(
19-
outList.indexOf(t) === -1 // not added before
20-
) {
21-
if(allList.indexOf(t) === -1) {
22-
console.error(t, 'is not a valid ' + type + '!', 'Valid ' + type + 's are:', allList);
23-
} else {
24-
outList.push(t);
25-
}
26-
}
27-
}
28-
29-
return outList.sort();
30-
}
31-
32-
function isFalse(a) {
33-
return (
34-
a === 'none' ||
35-
a === 'false'
36-
);
37-
}
38-
39-
function inputBoolean(a, dflt) {
40-
return !a ? dflt : !isFalse(a);
41-
}
42-
43-
function inputArray(a, dflt) {
44-
dflt = dflt.slice();
45-
46-
return (
47-
isFalse(a) ? [] :
48-
!a || a === 'all' ? dflt :
49-
a.split(',')
50-
);
51-
}
52-
53-
if(process.argv.length > 2) {
54-
// command line
55-
56-
var args = minimist(process.argv.slice(2), {});
57-
58-
// parse arguments
59-
var unminified = inputBoolean(args.unminified, false);
60-
var out = args.out ? args.out : 'custom';
61-
var traces = inputArray(args.traces, allTraces);
62-
var transforms = inputArray(args.transforms, allTransforms);
63-
64-
var opts = {
65-
traceList: createList(['scatter'], traces, allTraces, 'trace'),
66-
transformList: createList([], transforms, allTransforms, 'transform'),
67-
68-
name: out,
69-
index: path.join(constants.pathToLib, 'index-' + out + '.js')
70-
};
71-
72-
if(unminified) {
73-
opts.dist = path.join(constants.pathToDist, 'plotly-' + out + '.js');
74-
} else {
75-
opts.distMin = path.join(constants.pathToDist, 'plotly-' + out + '.min.js');
76-
}
77-
78-
console.log(opts);
79-
80-
opts.calendars = true;
81-
opts.deleteIndex = true;
82-
83-
var tasks = [];
84-
85-
partialBundle(tasks, opts);
86-
87-
runSeries(tasks, function(err) {
88-
if(err) throw err;
89-
});
90-
}
91-
9212
// Browserify the plotly.js partial bundles
93-
function partialBundle(tasks, opts) {
13+
module.exports = function partialBundle(tasks, opts) {
9414
var name = opts.name;
9515
var index = opts.index;
9616
var deleteIndex = opts.deleteIndex;
@@ -146,6 +66,4 @@ function partialBundle(tasks, opts) {
14666
done();
14767
});
14868
});
149-
}
150-
151-
module.exports = partialBundle;
69+
};

0 commit comments

Comments
 (0)