-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatePinnedVersions.ts
51 lines (38 loc) · 1.3 KB
/
updatePinnedVersions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { writeFileSync } from 'fs';
import * as prettier from 'prettier';
import { basePrettierRc } from './src/writeConfigs/basePrettierRc';
import PINNED_VERSIONS from './src/installDependencies/pinnedVersions.json';
const main = async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { _UPDATED_AT, ...oldPackages } = PINNED_VERSIONS;
const getLatestVersion = async (packageName: string) => {
const res = await fetch(
'https://registry.npmjs.org/' + packageName + '/latest'
);
const json = await res.json();
return json.version;
};
const newPackages = {};
for (const [key, value] of Object.entries(oldPackages)) {
const newVersion = await getLatestVersion(key);
if (newVersion && newVersion !== value) {
newPackages[key] = newVersion;
}
}
console.log({ newPackages });
if (!Object.keys(newPackages).length) {
console.error('no new package versions to update, exiting.');
process.exit(1);
}
const newJson = JSON.stringify({
_UPDATED_AT: new Date().toLocaleDateString(),
...oldPackages,
...newPackages,
});
const formattedJson = await prettier.format(newJson, {
...basePrettierRc,
parser: 'json',
});
writeFileSync('./src/installDependencies/pinnedVersions.json', formattedJson);
};
main();