-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathupdate-cli-deps.ts
51 lines (41 loc) · 1.4 KB
/
update-cli-deps.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 { readFile as fsReadFile, writeFile as fsWriteFile } from 'node:fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { promisify } from 'util';
export const readFile = /*#__PURE__*/ promisify(fsReadFile);
export const writeFile = /*#__PURE__*/ promisify(fsWriteFile);
export async function readJson(path: string) {
return JSON.parse(await readFile(path, 'utf-8'));
}
export async function writeJson(path: string, content: any) {
const contentStr = JSON.stringify(content, null, 2) + '\n';
await writeFile(path, contentStr);
}
async function updateCLIDepsVersions() {
const currentDir = dirname(fileURLToPath(import.meta.url));
const cliJsonPath = join(
currentDir,
'../',
'../',
'packages',
'cli',
'src',
'_shared',
'external-deps.json',
);
const cliExternalDeps = await readJson(cliJsonPath);
const rootPkgJson = await readJson(join(currentDir, '../', '../', 'package.json'));
if (!cliExternalDeps) {
throw new Error('No content for external-deps.json');
}
Object.keys(cliExternalDeps).forEach((dep) => {
if (rootPkgJson.devDependencies[dep]) {
cliExternalDeps[dep] = rootPkgJson.devDependencies[dep];
}
});
await writeJson(cliJsonPath, cliExternalDeps);
console.log(
`👉 Updated CLI external dependencies versions to ${JSON.stringify(cliExternalDeps)}`,
);
}
await updateCLIDepsVersions();