Skip to content

Commit b3aa325

Browse files
committed
feat: declare version
1 parent fcace53 commit b3aa325

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import './version';
2+
13
import { CubeTextProps, Text } from './components/content/Text';
24
import { CubeTitleProps, Title } from './components/content/Title';
35
import { CubeParagraphProps, Paragraph } from './components/content/Paragraph';

src/version.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2+
interface Window {
3+
CubeUIKit: {
4+
version: string[];
5+
};
6+
}
7+
8+
if (!window.CubeUIKit || !Array.isArray(window.CubeUIKit)) {
9+
window.CubeUIKit = {
10+
version: [],
11+
};
12+
}
13+
14+
window.CubeUIKit.version.push(process.env.VERSION as string);
15+
16+
if (window.CubeUIKit.version.length > 1) {
17+
console.error('More than one version of CubeUIKit is loaded');
18+
}

vite.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
// vite.config.ts
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
25
import { defineConfig } from 'vite';
36
import react from '@vitejs/plugin-react';
47

8+
// Read and parse the package.json file
9+
const packageJson = JSON.parse(
10+
readFileSync(resolve(__dirname, 'package.json'), 'utf-8'),
11+
);
12+
const version = packageJson.version;
13+
514
// https://vitejs.dev/config/
615
export default defineConfig({
716
plugins: [
817
react({
918
jsxRuntime: 'automatic',
1019
}),
1120
],
21+
define: {
22+
'process.env.VERSION': JSON.stringify(version),
23+
},
1224
});

0 commit comments

Comments
 (0)