Skip to content

Commit d5408d2

Browse files
committed
export package version
1 parent 026f824 commit d5408d2

4 files changed

Lines changed: 45 additions & 5 deletions

File tree

pnpm-lock.yaml

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

viewers/snippet/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@rollup/plugin-babel": "^6.0.3",
5858
"@rollup/plugin-commonjs": "^25.0.4",
5959
"@rollup/plugin-node-resolve": "^15.2.1",
60+
"@rollup/plugin-replace": "^5.0.5",
6061
"@rollup/plugin-terser": "^0.4.3",
6162
"@rollup/plugin-typescript": "^11.1.2",
6263
"@rollup/plugin-url": "^8.0.1",

viewers/snippet/rollup.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import dotenv from 'dotenv';
22
dotenv.config();
33

4+
import { readFileSync } from 'fs';
5+
import { fileURLToPath } from 'url';
6+
import { dirname, resolve as pathResolve } from 'path';
47
import resolve from '@rollup/plugin-node-resolve';
58
import commonjs from '@rollup/plugin-commonjs';
69
import babel from '@rollup/plugin-babel';
@@ -14,10 +17,25 @@ import url from '@rollup/plugin-url';
1417
import terser from '@rollup/plugin-terser';
1518
import copy from 'rollup-plugin-copy';
1619
import alias from '@rollup/plugin-alias';
20+
import replace from '@rollup/plugin-replace';
21+
22+
// Read version from package.json
23+
const __dirname = dirname(fileURLToPath(import.meta.url));
24+
const { version } = JSON.parse(readFileSync(pathResolve(__dirname, 'package.json'), 'utf8'));
1725

1826
// Check if we are in 'development' mode
1927
const isDev = process.env.ROLLUP_WATCH;
2028

29+
// Version replacement plugin
30+
function versionReplacer() {
31+
return replace({
32+
preventAssignment: true,
33+
values: {
34+
__EMBEDPDF_VERSION__: version,
35+
},
36+
});
37+
}
38+
2139
export default [
2240
{
2341
input: 'src/embedpdf.ts',
@@ -75,6 +93,7 @@ export default [
7593
plugins: [autoprefixer(), tailwindcss()],
7694
}),
7795
typescript(),
96+
versionReplacer(),
7897
babel({
7998
exclude: 'node_modules/**',
8099
extensions: ['.js', '.jsx', '.ts', '.tsx'],

viewers/snippet/src/embedpdf.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { EmbedPdfContainer } from './web-components/container';
22
import { PDFViewerConfig } from './components/app';
33

4+
// ============================================================================
5+
// Version
6+
// ============================================================================
7+
8+
/**
9+
* The version of the EmbedPDF snippet package
10+
*/
11+
export const version: string = '__EMBEDPDF_VERSION__';
12+
413
// ============================================================================
514
// Plugin Classes - for use with registry.getPlugin<T>()
615
// ============================================================================
@@ -135,6 +144,14 @@ function initContainer(config: ContainerConfig): EmbedPdfContainer {
135144
}
136145

137146
export default {
147+
/**
148+
* The version of the EmbedPDF snippet package
149+
*/
150+
version,
151+
152+
/**
153+
* Initialize the EmbedPDF viewer
154+
*/
138155
init: (config: ContainerConfig): EmbedPdfContainer | undefined => {
139156
if (config.type === 'container') {
140157
return initContainer(config);

0 commit comments

Comments
 (0)