|
2 | 2 | * This script is run after `nx package core` is executed
|
3 | 3 | * to remove the `.npmignore` file from the `core` package as we want to publish `plugin` package.json
|
4 | 4 | **/
|
5 |
| -import { existsSync, unlinkSync } from 'node:fs'; |
| 5 | +import { execSync } from 'node:child_process'; |
| 6 | +import { existsSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs'; |
6 | 7 |
|
7 |
| -const coreDistPath = './dist/libs/core'; |
| 8 | +const distPath = './dist/libs'; |
| 9 | +const coreDistPath = `${distPath}/core`; |
8 | 10 | const npmIgnorePath = `${coreDistPath}/.npmignore`;
|
9 | 11 |
|
10 | 12 | if (existsSync(npmIgnorePath)) {
|
11 | 13 | console.log('Removing .npmignore from core package');
|
12 | 14 | unlinkSync(npmIgnorePath);
|
13 | 15 | }
|
| 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