-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathgen_version.js
34 lines (30 loc) · 945 Bytes
/
gen_version.js
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
const { readdirSync, existsSync, fstat, writeFileSync } = require('fs');
const { join } = require('path');
const prettier = require('prettier');
// utils must build before core
// runtime must build before renderer-react
const packagesPath = join(__dirname, '../packages');
const pkgList = readdirSync(packagesPath)
.filter((pkg) => pkg.charAt(0) !== '.')
.map((pkg) => {
const package_path = join(packagesPath, pkg);
if (!existsSync(join(package_path, 'package.json'))) return;
const json = require(join(package_path, 'package.json'));
return {
name: json.name,
version: json.version,
};
});
const file_content = `
export const version = {
${pkgList
.map((pak) => {
return `"${pak.name}": '${pak.version}'`;
})
.join(',\n ')}
}
`;
writeFileSync(
join(packagesPath, 'common', '/src/version.ts'),
prettier.format(file_content, { parser: 'typescript' }).toString(),
);