Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move build step into schema script
  • Loading branch information
camdecoster committed Oct 16, 2025
commit 0ff3ebb0897f72ca33bb46820ca0767bb6f267d4
7 changes: 0 additions & 7 deletions devtools/test_dashboard/build.mjs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camdecoster After the cleanup you've done, does this step really need a separate file? Couldn't you just now add build(localDevConfig); to the beginning of the makeSchema() function in schema.mjs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair question. I envisioned this script as being one that could be called elsewhere, but that seems like it violates the YAGNI principle. I'll do as you suggest. We can always add it back.

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"bundle": "node tasks/bundle.mjs",
"extra-bundles": "node tasks/extra_bundles.mjs",
"locales": "node tasks/locales.js",
"schema": "node devtools/test_dashboard/build.mjs && node tasks/schema.mjs",
"schema": "node tasks/schema.mjs",
"stats": "node tasks/stats.js",
"find-strings": "node tasks/find_locale_strings.js",
"preprocess": "node tasks/preprocess.js",
Expand Down
63 changes: 29 additions & 34 deletions tasks/schema.mjs
Original file line number Diff line number Diff line change
@@ -1,77 +1,72 @@
import { build } from 'esbuild';
import fs from 'fs';
import path from 'path';
import { localDevConfig } from '../esbuild-config.js';

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

function caseInsensitive(a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
}
const caseInsensitive = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase());

function isArray(v) {
return Array.isArray(v);
}
const { isArray } = Array;

function isObject(v) {
return typeof v === 'object' && v !== null && !isArray(v);
}
const isObject = (v) => typeof v === 'object' && v !== null && !isArray(v);

function isArrayOfObjects(v) {
return isArray(v) && isObject(v[0]);
}
const isArrayOfObjects = (v) => isArray(v) && isObject(v[0]);

function typeHandle(v) {
return isArrayOfObjects(v) ? sortArrayOfObjects(v) : isObject(v) ? sortObject(v) : v;
}
const typeHandle = (v) => (isArrayOfObjects(v) ? sortArrayOfObjects(v) : isObject(v) ? sortObject(v) : v);

function sortArrayOfObjects(list) {
var newList = [];
for (var i = 0; i < list.length; i++) {
const newList = [];
for (let i = 0; i < list.length; i++) {
newList[i] = typeHandle(list[i]);
}

return newList;
}

function sortObject(obj) {
var allKeys = Object.keys(obj);
const allKeys = Object.keys(obj);
allKeys.sort(caseInsensitive);

var newObj = {};
for (var i = 0; i < allKeys.length; i++) {
var key = allKeys[i];
const newObj = {};
for (let i = 0; i < allKeys.length; i++) {
const key = allKeys[i];
newObj[key] = typeHandle(obj[key]);
}

return newObj;
}

function makeSchema(plotlyPath, schemaPath) {
var Plotly = plotlyNode(plotlyPath);

var obj = Plotly.PlotSchema.get();
var sortedObj = sortObject(obj);
var plotSchemaRaw = JSON.stringify(obj, null, 1);
var plotSchemaStr = JSON.stringify(sortedObj, null, 1);
const Plotly = plotlyNode(plotlyPath);
const obj = Plotly.PlotSchema.get();
const sortedObj = sortObject(obj);
const plotSchemaRaw = JSON.stringify(obj, null, 1);
const plotSchemaStr = JSON.stringify(sortedObj, null, 1);

fs.writeFileSync(schemaPath, plotSchemaStr);

var lenBeforeSort = plotSchemaRaw.length;
var lenAfterSort = plotSchemaStr.length;
var linesBeforeSort = plotSchemaRaw.split('\n').length;
var linesAfterSort = plotSchemaStr.split('\n').length;
const lenBeforeSort = plotSchemaRaw.length;
const lenAfterSort = plotSchemaStr.length;
const linesBeforeSort = plotSchemaRaw.split('\n').length;
const linesAfterSort = plotSchemaStr.split('\n').length;
if (linesAfterSort !== linesBeforeSort || lenAfterSort !== lenBeforeSort) {
throw 'plot schema should have the same length & number of lines before and after sort';
} else {
console.log('ok ' + path.basename(schemaPath));
}
}

var isDist = process.argv.indexOf('dist') !== -1;
const isDist = process.argv.indexOf('dist') !== -1;

const pathToSchema = isDist ? constants.pathToSchemaDist : constants.pathToSchemaDiff;

var pathToSchema = isDist ? constants.pathToSchemaDist : constants.pathToSchemaDiff;
const pathToPlotly = isDist ? constants.pathToPlotlyDistWithMeta : constants.pathToPlotlyBuild;

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

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