Skip to content

Commit

Permalink
Use json5 for studies storage (#1227)
Browse files Browse the repository at this point in the history
Replace `JSON.parse/stringify` with `JSON5.parser/stringify`, also
remove prefix `PLATFORM_` from platforms.
  • Loading branch information
goodov authored Oct 21, 2024
1 parent 9a1c927 commit 09f6d47
Show file tree
Hide file tree
Showing 39 changed files with 774 additions and 607 deletions.
8 changes: 8 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ module.exports = {
parser: 'json-stringify',
},
},
{
files: '*.json5',
options: {
// Sync with JSON5.stringify logic.
plugins: ['prettier-plugin-multiline-arrays'],
trailingComma: 'all',
},
},
],
};
136 changes: 135 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"jest": "29.7.0",
"lint-staged": "15.2.10",
"prettier": "3.3.3",
"prettier-plugin-multiline-arrays": "3.0.6",
"prettier-plugin-organize-imports": "3.2.4",
"protobufjs": "7.4.0",
"protobufjs-cli": "1.1.3",
Expand All @@ -54,6 +55,7 @@
"moduleResolution": "node",
"dependencies": {
"@protobuf-ts/runtime": "2.9.4",
"json5": "2.2.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-router": "6.27.0",
Expand Down
3 changes: 3 additions & 0 deletions src/seed_tools/commands/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('create command', () => {
const testDataDir = wsPath('//src/test/data');

let tempDir: string;
let logMock: jest.SpyInstance;
let exitMock: jest.SpyInstance;
let errorMock: jest.SpyInstance;

Expand All @@ -23,11 +24,13 @@ describe('create command', () => {
exitMock = jest.spyOn(process, 'exit').mockImplementation((code) => {
throw new Error(`process.exit(${code})`);
});
logMock = jest.spyOn(console, 'log').mockImplementation();
errorMock = jest.spyOn(console, 'error').mockImplementation();
});

afterEach(async () => {
await fs.rm(tempDir, { recursive: true, force: true });
logMock.mockRestore();
exitMock.mockRestore();
errorMock.mockRestore();
});
Expand Down
7 changes: 5 additions & 2 deletions src/seed_tools/commands/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ describe('lint command', () => {

let tempDir: string;
let exitMock: jest.SpyInstance;
let logMock: jest.SpyInstance;
let errorMock: jest.SpyInstance;

beforeEach(async () => {
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'create_seed-'));
exitMock = jest.spyOn(process, 'exit').mockImplementation((code) => {
throw new Error(`process.exit(${code})`);
});
logMock = jest.spyOn(console, 'log').mockImplementation();
errorMock = jest.spyOn(console, 'error').mockImplementation();
});

afterEach(async () => {
await fs.rm(tempDir, { recursive: true, force: true });
logMock.mockRestore();
exitMock.mockRestore();
errorMock.mockRestore();
});
Expand Down Expand Up @@ -86,8 +89,8 @@ describe('lint command', () => {
// copy the unformatted studies to a temp dir
await fs.mkdir(tempStudiesDir);
await fs.copyFile(
path.join(studiesDir, 'TestStudy.json'),
path.join(tempStudiesDir, 'TestStudy.json'),
path.join(studiesDir, 'TestStudy.json5'),
path.join(tempStudiesDir, 'TestStudy.json5'),
);

// lint should fail.
Expand Down
2 changes: 1 addition & 1 deletion src/seed_tools/commands/split_seed_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function main(seedPath: string, outputDir: string) {
for (const study of studies) {
const studyName = study[0];
const studyArray = study[1];
const studyFile = `${outputDir}/${studyName}.json`;
const studyFile = `${outputDir}/${studyName}.json5`;
await study_json_utils.writeStudyFile(studyArray, studyFile);
}
}
Expand Down
Loading

0 comments on commit 09f6d47

Please sign in to comment.