Skip to content

Commit 0bef2f4

Browse files
committed
chore(repo): adjust post package script to also update versions
1 parent 9fce320 commit 0bef2f4

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

tools/scripts/release/post-package-core.mjs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,51 @@
22
* This script is run after `nx package core` is executed
33
* to remove the `.npmignore` file from the `core` package as we want to publish `plugin` package.json
44
**/
5-
import { existsSync, unlinkSync } from 'node:fs';
5+
import { execSync } from 'node:child_process';
6+
import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
67

7-
const coreDistPath = './dist/libs/core';
8+
const distPath = './dist/libs';
9+
const coreDistPath = `${distPath}/core`;
810
const npmIgnorePath = `${coreDistPath}/.npmignore`;
911

1012
if (existsSync(npmIgnorePath)) {
1113
console.log('Removing .npmignore from core package');
1214
unlinkSync(npmIgnorePath);
1315
}
16+
17+
// update package.json for all libs
18+
19+
try {
20+
// read latest version of angular-three from npm beta
21+
const latestNpmVersion = execSync('npm view angular-three@beta version').toString().trim();
22+
23+
// read latest version from git tag first
24+
const latestTag = execSync('git describe --tags --abbrev=0').toString().trim();
25+
26+
// increment latestNpmVersion if latestTag equals latestNpmVersion (e.g. beta.288 becomes beta.289)
27+
let latestVersion = undefined;
28+
29+
if (latestTag !== latestNpmVersion) {
30+
latestVersion = latestTag;
31+
} else {
32+
const split = latestNpmVersion.split('.');
33+
const version = parseInt(split.pop()) + 1;
34+
latestVersion = split.join('.') + '.' + version;
35+
}
36+
37+
const libs = ['cannon', 'postprocessing', 'soba', 'core'];
38+
39+
libs.forEach((lib) => {
40+
const libDistPath = `${distPath}/${lib}`;
41+
const packageJsonPath = `${libDistPath}/package.json`;
42+
43+
if (existsSync(packageJsonPath)) {
44+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
45+
packageJson.version = latestVersion;
46+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
47+
console.log(`Updated ${lib} package.json version to ${latestVersion}`);
48+
}
49+
});
50+
} catch (e) {
51+
console.log('Error while getting latest version from npm or git tag');
52+
}

0 commit comments

Comments
 (0)