Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

Commit f5a7dea

Browse files
authored
Embedded version into API (#88)
* Embedded version into API * Updated version and revision to match PCUI standard
1 parent 8062107 commit f5a7dea

File tree

5 files changed

+71
-1
lines changed

5 files changed

+71
-1
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import globals from 'globals';
66
export default [
77
...playcanvasConfig,
88
{
9-
files: ['**/*.ts'],
9+
files: ['**/*.ts', '**/*.mjs'],
1010
languageOptions: {
1111
ecmaVersion: 2022,
1212
sourceType: 'module',

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@rollup/plugin-babel": "^6.0.4",
3737
"@rollup/plugin-commonjs": "^26.0.1",
3838
"@rollup/plugin-node-resolve": "^15.2.3",
39+
"@rollup/plugin-replace": "^6.0.2",
3940
"@rollup/plugin-typescript": "^12.1.2",
4041
"@types/sharedb": "^3.2.1",
4142
"@typescript-eslint/parser": "^8.19.1",

rollup.config.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
1+
import { execSync } from 'child_process';
2+
import fs from 'fs';
3+
14
import { babel } from '@rollup/plugin-babel';
25
import commonjs from '@rollup/plugin-commonjs';
36
import resolve from '@rollup/plugin-node-resolve';
7+
import replace from '@rollup/plugin-replace';
48
import typescript from '@rollup/plugin-typescript';
59
import { dts } from 'rollup-plugin-dts';
610
import polyfills from 'rollup-plugin-polyfill-node';
711

812
import { runTsc } from './utils/plugins/rollup-run-tsc.mjs';
913

14+
/**
15+
* @returns {string} Version string like `1.58.0-dev`
16+
*/
17+
const getVersion = () => {
18+
const text = fs.readFileSync('./package.json', 'utf8');
19+
const json = JSON.parse(text);
20+
return json.version;
21+
};
22+
23+
/**
24+
* @returns {string} Revision string like `644d08d39` (9 digits/chars).
25+
*/
26+
const getRevision = () => {
27+
let revision;
28+
try {
29+
revision = execSync('git rev-parse --short HEAD').toString().trim();
30+
} catch (e) {
31+
revision = 'unknown';
32+
}
33+
return revision;
34+
};
35+
36+
const replacements = {
37+
values: {
38+
'PACKAGE_VERSION': getVersion(),
39+
'PACKAGE_REVISION': getRevision()
40+
},
41+
preventAssignment: true
42+
};
43+
1044
const umd = {
1145
external: ['@playcanvas/observer'],
1246
input: 'src/index.ts',
@@ -22,6 +56,7 @@ const umd = {
2256
typescript({
2357
sourceMap: false
2458
}),
59+
replace(replacements),
2560
commonjs(),
2661
polyfills(),
2762
resolve(),
@@ -61,6 +96,7 @@ const module = {
6196
typescript({
6297
sourceMap: false
6398
}),
99+
replace(replacements),
64100
commonjs(),
65101
polyfills(),
66102
resolve()

src/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,13 @@ export * from './jobs';
4242
export * from './localstorage';
4343
export * from './clipboard';
4444
export * from './rest';
45+
46+
/**
47+
* The version of the Editor API library. This is a string in semantic version format of `major.minor.patch`.
48+
*/
49+
export const version = 'PACKAGE_VERSION';
50+
51+
/**
52+
* The git revision of the Editor API library. This is a string of the git commit hash.
53+
*/
54+
export const revision = 'PACKAGE_REVISION';

0 commit comments

Comments
 (0)