Skip to content

Commit

Permalink
chore: update json-stringify-pretty-compact (#9475)
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz authored Nov 19, 2024
1 parent 8dab373 commit 8fa04c8
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 654 deletions.
4 changes: 2 additions & 2 deletions bin/vl2vg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

const {createWriteStream} = require('fs');
const vegaLite = require('..');
const compactStringify = require('json-stringify-pretty-compact');
const read = require('./read');
const args = require('./args');

Expand All @@ -13,13 +12,14 @@ const arg = args('vega');
// load spec, compile vg spec
read(arg._[0]).then(text => compile(JSON.parse(text)));

function compile(vlSpec) {
async function compile(vlSpec) {
// @ts-ignore
const vgSpec = vegaLite.compile(vlSpec).spec;

const file = arg._[1] || null;
const out = file ? createWriteStream(file) : process.stdout;
if (arg.p) {
const compactStringify = (await import('json-stringify-pretty-compact')).default;
out.write(compactStringify(vgSpec) + '\n');
} else {
out.write(JSON.stringify(vgSpec) + '\n');
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0",
"@babel/preset-typescript": "^7.26.0",
"@release-it/conventional-changelog": "^8.0.1",
"@release-it/conventional-changelog": "^9.0.3",
"@rollup/plugin-alias": "^5.1.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.1",
Expand All @@ -99,7 +99,7 @@
"cheerio": "^1.0.0",
"conventional-changelog-cli": "^5.0.0",
"d3": "^7.9.0",
"del-cli": "^5.1.0",
"del-cli": "^6.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.9.0",
Expand All @@ -113,21 +113,21 @@
"prettier": "^3.3.3",
"puppeteer": "^15.0.0",
"release-it": "17.10.0",
"rollup": "^4.26.0",
"rollup": "^4.27.3",
"rollup-plugin-bundle-size": "^1.0.3",
"serve": "^14.2.4",
"terser": "^5.36.0",
"ts-jest": "^29.2.5",
"ts-json-schema-generator": "^2.3.0",
"typescript": "~5.6.3",
"vega-cli": "^5.30.0",
"vega-datasets": "^2.10.0",
"vega-datasets": "^2.11.0",
"vega-embed": "^6.28.0",
"vega-tooltip": "^0.35.1",
"vega-tooltip": "^0.35.2",
"yaml-front-matter": "^4.1.1"
},
"dependencies": {
"json-stringify-pretty-compact": "~3.0.0",
"json-stringify-pretty-compact": "~4.0.0",
"tslib": "~2.8.1",
"vega-event-selector": "~3.0.1",
"vega-expression": "~5.1.1",
Expand Down
23 changes: 12 additions & 11 deletions scripts/build-normalized-examples
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
const fs = require('fs');
const vl = require('../build/vega-lite');
const stableStringify = require('fast-json-stable-stringify');
const compactStringify = require('json-stringify-pretty-compact');

const DIR = __dirname + '/..';
const SPECS = '/examples/specs';
const examples = fs.readdirSync(DIR + SPECS);

examples.forEach(example => {
if (example && example.includes('.vl.json')) {
const path = DIR + SPECS + '/' + example;
async function main() {
const {default: compactStringify} = await import('json-stringify-pretty-compact');

const vlExamples = examples.filter(example => example.includes('.vl.json'));
for (const example of vlExamples) {
const path = `${DIR + SPECS}/${example}`;
const spec = JSON.parse(fs.readFileSync(path));

const preNormalized = stableStringify(spec);
Expand All @@ -29,14 +31,13 @@ examples.forEach(example => {

// console.log(preNormalized, postNormalized);
if (preNormalized !== postNormalized) {
const postNormalizedOutput = compactStringify(fullSpec, null, 2);
const postNormalizedOutput = compactStringify(fullSpec, {indent: 2});
// -8 is cutting .vl.json
const newFilename = example.slice(0, -8) + '_normalized.vl.json';
const newFilenameAndPath = DIR + SPECS + '/normalized/' + newFilename;
fs.writeFile(newFilenameAndPath, postNormalizedOutput, err => {
if (err) return console.log(err);
console.log('Built:', newFilename);
});
const newFilenameAndPath = `${DIR + SPECS}/normalized/${newFilename}`;
fs.writeFileSync(newFilenameAndPath, postNormalizedOutput);
}
}
});
}

main();
Loading

0 comments on commit 8fa04c8

Please sign in to comment.