UNPKG

825 BJavaScriptView Raw
1/*!
2 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3 * Licensed under the MIT License.
4 */
5
6const fs = require("fs");
7const path = require("path");
8const sortJson = require("sort-json");
9
10(async () => {
11 const args = process.argv.slice(2);
12 const sourcePath = args[0];
13 const files = await fs.promises.readdir(sourcePath);
14
15 for (const file of files) {
16 const filePath = path.join(sourcePath, file);
17 const content = fs.readFileSync(filePath);
18 const json = JSON.parse(content);
19
20 // Remove the parser property because it's an absolute path and will vary based on the local environment.
21 delete json.parser;
22
23 // Write out the file.
24 fs.writeFileSync(filePath, JSON.stringify(json, undefined, 4));
25
26 // Sort the JSON in-place.
27 sortJson.overwrite(filePath, { indentSize: 4 });
28 }
29})();