Skip to content

Commit 0ff3ebb

Browse files
committed
Move build step into schema script
1 parent c8818ec commit 0ff3ebb

File tree

3 files changed

+30
-42
lines changed

3 files changed

+30
-42
lines changed

devtools/test_dashboard/build.mjs

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"bundle": "node tasks/bundle.mjs",
2929
"extra-bundles": "node tasks/extra_bundles.mjs",
3030
"locales": "node tasks/locales.js",
31-
"schema": "node devtools/test_dashboard/build.mjs && node tasks/schema.mjs",
31+
"schema": "node tasks/schema.mjs",
3232
"stats": "node tasks/stats.js",
3333
"find-strings": "node tasks/find_locale_strings.js",
3434
"preprocess": "node tasks/preprocess.js",

tasks/schema.mjs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,72 @@
1+
import { build } from 'esbuild';
12
import fs from 'fs';
23
import path from 'path';
4+
import { localDevConfig } from '../esbuild-config.js';
35

46
import constants from './util/constants.js';
57
import plotlyNode from './util/plotly_node.mjs';
68

7-
function caseInsensitive(a, b) {
8-
return a.toLowerCase().localeCompare(b.toLowerCase());
9-
}
9+
const caseInsensitive = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase());
1010

11-
function isArray(v) {
12-
return Array.isArray(v);
13-
}
11+
const { isArray } = Array;
1412

15-
function isObject(v) {
16-
return typeof v === 'object' && v !== null && !isArray(v);
17-
}
13+
const isObject = (v) => typeof v === 'object' && v !== null && !isArray(v);
1814

19-
function isArrayOfObjects(v) {
20-
return isArray(v) && isObject(v[0]);
21-
}
15+
const isArrayOfObjects = (v) => isArray(v) && isObject(v[0]);
2216

23-
function typeHandle(v) {
24-
return isArrayOfObjects(v) ? sortArrayOfObjects(v) : isObject(v) ? sortObject(v) : v;
25-
}
17+
const typeHandle = (v) => (isArrayOfObjects(v) ? sortArrayOfObjects(v) : isObject(v) ? sortObject(v) : v);
2618

2719
function sortArrayOfObjects(list) {
28-
var newList = [];
29-
for (var i = 0; i < list.length; i++) {
20+
const newList = [];
21+
for (let i = 0; i < list.length; i++) {
3022
newList[i] = typeHandle(list[i]);
3123
}
3224

3325
return newList;
3426
}
3527

3628
function sortObject(obj) {
37-
var allKeys = Object.keys(obj);
29+
const allKeys = Object.keys(obj);
3830
allKeys.sort(caseInsensitive);
3931

40-
var newObj = {};
41-
for (var i = 0; i < allKeys.length; i++) {
42-
var key = allKeys[i];
32+
const newObj = {};
33+
for (let i = 0; i < allKeys.length; i++) {
34+
const key = allKeys[i];
4335
newObj[key] = typeHandle(obj[key]);
4436
}
4537

4638
return newObj;
4739
}
4840

4941
function makeSchema(plotlyPath, schemaPath) {
50-
var Plotly = plotlyNode(plotlyPath);
51-
52-
var obj = Plotly.PlotSchema.get();
53-
var sortedObj = sortObject(obj);
54-
var plotSchemaRaw = JSON.stringify(obj, null, 1);
55-
var plotSchemaStr = JSON.stringify(sortedObj, null, 1);
42+
const Plotly = plotlyNode(plotlyPath);
43+
const obj = Plotly.PlotSchema.get();
44+
const sortedObj = sortObject(obj);
45+
const plotSchemaRaw = JSON.stringify(obj, null, 1);
46+
const plotSchemaStr = JSON.stringify(sortedObj, null, 1);
5647

5748
fs.writeFileSync(schemaPath, plotSchemaStr);
5849

59-
var lenBeforeSort = plotSchemaRaw.length;
60-
var lenAfterSort = plotSchemaStr.length;
61-
var linesBeforeSort = plotSchemaRaw.split('\n').length;
62-
var linesAfterSort = plotSchemaStr.split('\n').length;
50+
const lenBeforeSort = plotSchemaRaw.length;
51+
const lenAfterSort = plotSchemaStr.length;
52+
const linesBeforeSort = plotSchemaRaw.split('\n').length;
53+
const linesAfterSort = plotSchemaStr.split('\n').length;
6354
if (linesAfterSort !== linesBeforeSort || lenAfterSort !== lenBeforeSort) {
6455
throw 'plot schema should have the same length & number of lines before and after sort';
6556
} else {
6657
console.log('ok ' + path.basename(schemaPath));
6758
}
6859
}
6960

70-
var isDist = process.argv.indexOf('dist') !== -1;
61+
const isDist = process.argv.indexOf('dist') !== -1;
62+
63+
const pathToSchema = isDist ? constants.pathToSchemaDist : constants.pathToSchemaDiff;
7164

72-
var pathToSchema = isDist ? constants.pathToSchemaDist : constants.pathToSchemaDiff;
65+
const pathToPlotly = isDist ? constants.pathToPlotlyDistWithMeta : constants.pathToPlotlyBuild;
7366

74-
var pathToPlotly = isDist ? constants.pathToPlotlyDistWithMeta : constants.pathToPlotlyBuild;
67+
// Build plotly.js to ensure changes to attributes are picked up. This is the same
68+
// process used in the test dashboard server script, but run only once.
69+
await build(localDevConfig);
7570

7671
// output plot-schema JSON
7772
makeSchema(pathToPlotly, pathToSchema);

0 commit comments

Comments
 (0)