arduino-ide/scripts/sort-dependencies
Akos Kitta ac9cce16f7
chore: Updated to Theia 1.31.1 (#1662)
Closes #1655
Closes #1656

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
2022-11-29 09:39:54 +01:00

27 lines
874 B
JavaScript
Executable File

#!/usr/bin/env node
// Sorts the dependencies and devDependencies in the package.json without yarn.
// Usage `./scripts/sort-dependencies ./path/to/package.json`
const { promises: fs } = require('fs');
const { join, isAbsolute } = require('path');
const arg = process.argv.slice(2).pop();
const path = isAbsolute(arg) ? arg : join(process.cwd(), arg);
fs.readFile(path, { encoding: 'utf8' }).then((raw) => {
const json = JSON.parse(raw);
['dependencies', 'devDependencies'].forEach((prop) => {
const value = json[prop];
if (value) {
json[prop] = Array.from(Object.entries(value))
.sort(([left], [right]) => left.localeCompare(right))
.reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {});
}
});
fs.writeFile(path, JSON.stringify(json, null, 2) + '\n', {
encoding: 'utf8',
});
});