Skip to content

Commit

Permalink
feat(core): add version exposure and control
Browse files Browse the repository at this point in the history
- Add version.ts to expose package version
- Include version in ZenUml class and main.ts
- Update types to include version information
- Modify vite config files to inject version during build
  • Loading branch information
MrCoder committed Dec 17, 2024
1 parent 286f771 commit cf69cf8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Store, { RenderMode } from "./store/Store";
import DiagramFrame from "./components/DiagramFrame/DiagramFrame.vue";
// @ts-ignore
import SeqDiagram from "./components/DiagramFrame/SeqDiagram/SeqDiagram.vue";
import { VERSION } from "./version";

import "./assets/tailwind.css";
import "./assets/tailwind-preflight.less";
Expand Down Expand Up @@ -46,6 +47,8 @@ interface IZenUml {
}

export default class ZenUml implements IZenUml {
static readonly version = VERSION;

private readonly el: Element;
private _code: string | undefined;
private _theme: string | undefined;
Expand Down
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const elm = document.querySelector("pre.zenuml");
// @ts-ignore
const zenUml = new ZenUml(elm);

// Expose ZenUML version to window for easy access in developer console
// @ts-ignore
window.ZENUML_VERSION = ZenUml.version;
// @ts-ignore
window.zenUml = zenUml;
zenUml
Expand All @@ -20,6 +23,7 @@ zenUml
})
.then((r) => {
logger.debug("render resolved", r);
console.log("ZenUML Core Version:", ZenUml.version);
});
// @ts-ignore
window.parentLogger = parentLogger;
1 change: 1 addition & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const VERSION = import.meta.env.PACKAGE_VERSION;
9 changes: 9 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { defineConfig } from "vite";
import createVuePlugin from "@vitejs/plugin-vue";
import { execSync } from "child_process";
import svgLoader from "vite-svg-loader";
import { readFileSync } from "fs";

process.env.VITE_APP_GIT_HASH = process.env.DOCKER
? ""
Expand All @@ -11,6 +12,11 @@ process.env.VITE_APP_GIT_BRANCH = process.env.DOCKER
? ""
: execSync("git branch --show-current").toString().trim();

// Read version from package.json
const packageJson = JSON.parse(
readFileSync(resolve(__dirname, "package.json"), "utf-8"),
);

function getCypressHtmlFiles() {
const cypressFolder = resolve(__dirname, "cy");
const strings = execSync(`find ${cypressFolder} -name '*.html'`)
Expand Down Expand Up @@ -49,6 +55,9 @@ export default defineConfig(({ mode }) => ({
}),
svgLoader(),
],
define: {
"import.meta.env.PACKAGE_VERSION": JSON.stringify(packageJson.version),
},
test: {
// used by vitest: https://vitest.dev/guide/#configuring-vitest
environment: "jsdom",
Expand Down
8 changes: 8 additions & 0 deletions vite.config.lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import { defineConfig } from "vite";
import createVuePlugin from "@vitejs/plugin-vue";
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
import svgLoader from "vite-svg-loader";
import { readFileSync } from "fs";

// Read version from package.json
const packageJson = JSON.parse(
readFileSync(resolve(__dirname, "package.json"), "utf-8"),
);

export default defineConfig({
build: {
Expand Down Expand Up @@ -57,5 +63,7 @@ export default defineConfig({
],
define: {
"process.env.NODE_ENV": '"production"',
// Replace version placeholder during build
"import.meta.env.PACKAGE_VERSION": JSON.stringify(packageJson.version),
},
});

0 comments on commit cf69cf8

Please sign in to comment.