Skip to content

Commit

Permalink
Include package version and git revision during build
Browse files Browse the repository at this point in the history
  • Loading branch information
cyraxx committed Aug 30, 2024
1 parent 58356ab commit 03e8cb1
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 3 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist/*', 'eslint.config.js'] },
{ ignores: ['dist/*', 'eslint.config.js', 'prebuild.js', 'postbuild.js'] },
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
Expand Down
163 changes: 163 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"mocha": "^10.7.3",
"mocha-ctrf-json-reporter": "^0.0.6",
"prettier": "3.3.3",
"replace-in-file": "^8.1.0",
"rimraf": "^6.0.1",
"ts-node": "^10.9.2",
"tsx": "^4.18.0",
Expand All @@ -75,6 +76,6 @@
"lint": "eslint src tests",
"format": "prettier --write src tests",
"test": "mocha 'tests/**/*test.ts'",
"build": "rimraf dist && tsc -p tsconfig.json"
"build": "rimraf dist && node prebuild.js && tsc -p tsconfig.json; node postbuild.js"
}
}
5 changes: 5 additions & 0 deletions postbuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as fs from 'node:fs';

try {
fs.renameSync('src/util/Version.ts.bak', 'src/util/Version.ts');
} catch {}
13 changes: 13 additions & 0 deletions prebuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {replaceInFileSync} from 'replace-in-file'
import {execSync} from 'node:child_process';
import * as fs from 'node:fs';

const gitRevision = execSync('git rev-parse --short HEAD').toString().trim();

fs.copyFileSync('src/util/Version.ts', 'src/util/Version.ts.bak');

replaceInFileSync({
files: 'src/util/Version.ts',
from: '@VERSION@',
to: `${process.env.npm_package_version}-${gitRevision}`,
});
2 changes: 1 addition & 1 deletion src/util/Version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export class Version {
public static readonly productName = 'c2pa-ts';
public static readonly productVersion = '0.1.0';
public static readonly productVersion = '@VERSION@';

private constructor() {}
}

0 comments on commit 03e8cb1

Please sign in to comment.