Skip to content

Commit 3b465ce

Browse files
committed
Add --strict option to custom bundle command so that strict traces can be used in a custom bundle
1 parent 3f8cfe7 commit 3b465ce

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

CUSTOM_BUNDLE.md

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Or use `transforms none` to exclude them all.
3030
npm run custom-bundle -- --transforms none
3131
```
3232

33+
Use the `strict` option to use strict trace types where possible.
34+
```sh
35+
npm run custom-bundle -- --traces scatter,scattergl --strict
36+
```
37+
3338
Use the `out` option to change the bundle filename (default `custom`).
3439
The new bundle will be created in the `dist/` directory and named `plotly-<out>.min.js` or `plotly-<out>.js` if unminified.
3540
```sh

tasks/custom_bundle.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ if(process.argv.length > 2) {
5656
var out = args.out ? args.out : 'custom';
5757
var traces = inputArray(args.traces, allTraces);
5858
var transforms = inputArray(args.transforms, allTransforms);
59+
var strict = inputBoolean(args.strict, false);
5960

6061
var opts = {
6162
traceList: createList(['scatter'], traces, allTraces, 'trace'),
6263
transformList: createList([], transforms, allTransforms, 'transform'),
6364

6465
name: out,
65-
index: path.join(constants.pathToLib, 'index-' + out + '.js')
66+
index: path.join(constants.pathToLib, 'index-' + (strict ? 'strict-' : '') + out + '.js'),
67+
strict: strict,
6668
};
6769

6870
if(unminified) {

tasks/partial_bundle.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var header = constants.licenseDist + '\n';
88
var allTransforms = constants.allTransforms;
99
var allTraces = constants.allTraces;
1010
var mainIndex = constants.mainIndex;
11+
var strictIndex = constants.strictIndex;
1112

1213
// Bundle the plotly.js partial bundles
1314
module.exports = function partialBundle(tasks, opts) {
@@ -19,11 +20,12 @@ module.exports = function partialBundle(tasks, opts) {
1920
var traceList = opts.traceList;
2021
var transformList = opts.transformList;
2122
var calendars = opts.calendars;
23+
var strict = opts.strict;
2224

2325
// skip strict bundle which is no longer a partial bundle and has a special index file for regl traces
2426
if(name !== 'strict') {
2527
tasks.push(function(done) {
26-
var partialIndex = mainIndex;
28+
var partialIndex = (strict) ? strictIndex : mainIndex;
2729

2830
var all = ['calendars'].concat(allTransforms).concat(allTraces);
2931
var includes = (calendars ? ['calendars'] : []).concat(transformList).concat(traceList);
@@ -35,8 +37,9 @@ module.exports = function partialBundle(tasks, opts) {
3537
var newCode = partialIndex.replace(
3638
new RegExp(
3739
WHITESPACE_BEFORE +
38-
'require\\(\'\\./' + t + '\'\\),',
39-
'g'), ''
40+
'require\\(\'\\./' + t + '\'\\),' + '|' +
41+
'require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),',
42+
'g'), ''
4043
);
4144

4245
// test removal

tasks/util/constants.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function startsWithLowerCase(v) {
2020
var pathToPlotlyIndex = path.join(pathToLib, 'index.js');
2121
var pathToPlotlyStrict = path.join(pathToLib, 'index-strict.js');
2222
var mainIndex = fs.readFileSync(pathToPlotlyIndex, 'utf-8');
23+
var strictIndex = fs.readFileSync(pathToPlotlyStrict, 'utf-8');
2324
var allTraces = fs.readdirSync(path.join(pathToSrc, 'traces'))
2425
.filter(startsWithLowerCase);
2526

@@ -191,6 +192,7 @@ module.exports = {
191192
allTransforms: allTransforms,
192193
allTraces: allTraces,
193194
mainIndex: mainIndex,
195+
strictIndex: strictIndex,
194196
pathToPlotlyIndex: pathToPlotlyIndex,
195197
pathToPlotlyStrict: pathToPlotlyStrict,
196198
pathToPlotlyCore: path.join(pathToSrc, 'core.js'),

0 commit comments

Comments
 (0)