@pdfme/common 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/cjs/__tests__/dynamicTemplate.test.js +275 -0
- package/dist/cjs/__tests__/dynamicTemplate.test.js.map +1 -0
- package/dist/cjs/__tests__/expression.test.js +474 -0
- package/dist/cjs/__tests__/expression.test.js.map +1 -0
- package/dist/cjs/__tests__/helper.test.js +647 -0
- package/dist/cjs/__tests__/helper.test.js.map +1 -0
- package/dist/cjs/__tests__/pluginRegistry.test.js +83 -0
- package/dist/cjs/__tests__/pluginRegistry.test.js.map +1 -0
- package/dist/cjs/src/constants.js +27 -0
- package/dist/cjs/src/constants.js.map +1 -0
- package/dist/cjs/src/dynamicTemplate.js +284 -0
- package/dist/cjs/src/dynamicTemplate.js.map +1 -0
- package/dist/cjs/src/expression.js +463 -0
- package/dist/cjs/src/expression.js.map +1 -0
- package/dist/cjs/src/helper.js +217 -0
- package/dist/cjs/src/helper.js.map +1 -0
- package/dist/cjs/src/index.js +42 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/pluginRegistry.js +33 -0
- package/dist/cjs/src/pluginRegistry.js.map +1 -0
- package/dist/cjs/src/schema.js +190 -0
- package/dist/cjs/src/schema.js.map +1 -0
- package/dist/cjs/src/types.js +3 -0
- package/dist/cjs/src/types.js.map +1 -0
- package/dist/cjs/src/version.js +5 -0
- package/dist/cjs/src/version.js.map +1 -0
- package/dist/esm/__tests__/dynamicTemplate.test.js +240 -0
- package/dist/esm/__tests__/dynamicTemplate.test.js.map +1 -0
- package/dist/esm/__tests__/expression.test.js +472 -0
- package/dist/esm/__tests__/expression.test.js.map +1 -0
- package/dist/esm/__tests__/helper.test.js +612 -0
- package/dist/esm/__tests__/helper.test.js.map +1 -0
- package/dist/esm/__tests__/pluginRegistry.test.js +81 -0
- package/dist/esm/__tests__/pluginRegistry.test.js.map +1 -0
- package/dist/esm/src/constants.js +24 -0
- package/dist/esm/src/constants.js.map +1 -0
- package/dist/esm/src/dynamicTemplate.js +280 -0
- package/dist/esm/src/dynamicTemplate.js.map +1 -0
- package/dist/esm/src/expression.js +426 -0
- package/dist/esm/src/expression.js.map +1 -0
- package/dist/esm/src/helper.js +193 -0
- package/dist/esm/src/helper.js.map +1 -0
- package/dist/esm/src/index.js +8 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/pluginRegistry.js +29 -0
- package/dist/esm/src/pluginRegistry.js.map +1 -0
- package/dist/esm/src/schema.js +187 -0
- package/dist/esm/src/schema.js.map +1 -0
- package/dist/esm/src/types.js +2 -0
- package/dist/esm/src/types.js.map +1 -0
- package/dist/esm/src/version.js +2 -0
- package/dist/esm/src/version.js.map +1 -0
- package/dist/node/__tests__/dynamicTemplate.test.js +275 -0
- package/dist/node/__tests__/dynamicTemplate.test.js.map +1 -0
- package/dist/node/__tests__/expression.test.js +474 -0
- package/dist/node/__tests__/expression.test.js.map +1 -0
- package/dist/node/__tests__/helper.test.js +647 -0
- package/dist/node/__tests__/helper.test.js.map +1 -0
- package/dist/node/__tests__/pluginRegistry.test.js +83 -0
- package/dist/node/__tests__/pluginRegistry.test.js.map +1 -0
- package/dist/node/src/constants.js +27 -0
- package/dist/node/src/constants.js.map +1 -0
- package/dist/node/src/dynamicTemplate.js +284 -0
- package/dist/node/src/dynamicTemplate.js.map +1 -0
- package/dist/node/src/expression.js +463 -0
- package/dist/node/src/expression.js.map +1 -0
- package/dist/node/src/helper.js +217 -0
- package/dist/node/src/helper.js.map +1 -0
- package/dist/node/src/index.js +42 -0
- package/dist/node/src/index.js.map +1 -0
- package/dist/node/src/pluginRegistry.js +33 -0
- package/dist/node/src/pluginRegistry.js.map +1 -0
- package/dist/node/src/schema.js +190 -0
- package/dist/node/src/schema.js.map +1 -0
- package/dist/node/src/types.js +3 -0
- package/dist/node/src/types.js.map +1 -0
- package/dist/node/src/version.js +5 -0
- package/dist/node/src/version.js.map +1 -0
- package/dist/types/__tests__/dynamicTemplate.test.d.ts +1 -0
- package/dist/types/__tests__/expression.test.d.ts +1 -0
- package/dist/types/__tests__/helper.test.d.ts +1 -0
- package/dist/types/__tests__/pluginRegistry.test.d.ts +1 -0
- package/dist/types/src/constants.d.ts +20 -0
- package/dist/types/src/dynamicTemplate.d.ts +15 -0
- package/dist/types/src/expression.d.ts +6 -0
- package/dist/types/src/helper.d.ts +35 -0
- package/dist/types/src/index.d.ts +9 -0
- package/dist/types/src/pluginRegistry.d.ts +5 -0
- package/dist/types/src/schema.d.ts +820 -0
- package/dist/types/src/types.d.ts +181 -0
- package/dist/types/src/version.d.ts +1 -0
- package/eslint.config.mjs +22 -0
- package/package.json +84 -0
- package/set-version.js +31 -0
- package/src/constants.ts +30 -0
- package/src/dynamicTemplate.ts +349 -0
- package/src/expression.ts +460 -0
- package/src/helper.ts +284 -0
- package/src/index.ts +136 -0
- package/src/pluginRegistry.ts +30 -0
- package/src/schema.ts +223 -0
- package/src/types.ts +198 -0
- package/src/version.ts +1 -0
- package/tsconfig.cjs.json +10 -0
- package/tsconfig.esm.json +11 -0
- package/tsconfig.json +6 -0
- package/tsconfig.node.json +11 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { PDFPage, PDFDocument } from '@pdfme/pdf-lib';
|
|
3
|
+
import type { ThemeConfig, GlobalToken } from 'antd';
|
|
4
|
+
import type { WidgetProps as _PropPanelWidgetProps, Schema as _PropPanelSchema } from 'form-render';
|
|
5
|
+
import { Lang, Dict, Mode, Size, Schema, Font, SchemaForUI, BasePdf, BlankPdf, CustomPdf, CommonOptions, Template, GeneratorOptions, GenerateProps, UIOptions, UIProps, PreviewProps, DesignerProps, ColorType, LegacySchemaPageArray, SchemaPageArray } from './schema.js';
|
|
6
|
+
export type PropPanelSchema = _PropPanelSchema;
|
|
7
|
+
export type ChangeSchemaItem = {
|
|
8
|
+
key: string;
|
|
9
|
+
value: unknown;
|
|
10
|
+
schemaId: string;
|
|
11
|
+
};
|
|
12
|
+
export type ChangeSchemas = (objs: ChangeSchemaItem[]) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Properties used for PDF rendering.
|
|
15
|
+
* @template T Type of the extended Schema object.
|
|
16
|
+
* @property {string} value The string used for PDF rendering.
|
|
17
|
+
* @property {T} schema Extended Schema object for rendering.
|
|
18
|
+
* @property {BasePdf} basePdf Base PDF object for rendering.
|
|
19
|
+
* @property {typeof import('@pdfme/pdf-lib')} pdfLib The pdf-lib library used for rendering.
|
|
20
|
+
* @property {PDFDocument} pdfDoc PDFDocument object from pdf-lib.
|
|
21
|
+
* @property {PDFPage} page PDFPage object from pdf-lib.
|
|
22
|
+
* @property {GeneratorOptions} options Options object passed from the generator.
|
|
23
|
+
* @property {Map<string | number, unknown>} _cache Cache shared only during the execution of the generate function (useful for caching images, etc. if needed).
|
|
24
|
+
*/
|
|
25
|
+
export interface PDFRenderProps<T extends Schema> {
|
|
26
|
+
value: string;
|
|
27
|
+
schema: T;
|
|
28
|
+
basePdf: BasePdf;
|
|
29
|
+
pdfLib: typeof import('@pdfme/pdf-lib');
|
|
30
|
+
pdfDoc: PDFDocument;
|
|
31
|
+
page: PDFPage;
|
|
32
|
+
options: GeneratorOptions;
|
|
33
|
+
_cache: Map<string | number, unknown>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Type for properties used in UI rendering.
|
|
37
|
+
*
|
|
38
|
+
* @template T - Type of the extended Schema object.
|
|
39
|
+
* @property {T} schema - Extended Schema object for rendering.
|
|
40
|
+
* @property {BasePdf} basePdf Base PDF object for rendering.
|
|
41
|
+
* @property {Mode} mode - String indicating the rendering state. 'designer' is only used when the field is in edit mode in the Designer.
|
|
42
|
+
* @property {number} [tabIndex] - Tab index for Form.
|
|
43
|
+
* @property {string} [placeholder] - Placeholder text for Form.
|
|
44
|
+
* @property {() => void} [stopEditing] - Stops editing mode, can be used when the mode is 'designer'.
|
|
45
|
+
* @property {string} value - The string used for UI rendering.
|
|
46
|
+
* @property {(arg: { key: string; value: unknown } | { key: string; value: unknown }[]) => void} [onChange] - Used to change the value and schema properties. Only applicable when the mode is 'form' or 'designer'.
|
|
47
|
+
* @property {HTMLDivElement} rootElement - The root HTMLDivElement for the UI.
|
|
48
|
+
* @property {UIOptions} options - Options object passed from the Viewer, Form, or Designer.
|
|
49
|
+
* @property {ThemeConfig} theme - An object that merges the 'theme' passed as an options with the default theme.
|
|
50
|
+
* @property {(key: keyof Dict | string) => string} i18n - An object merged based on the options 'lang' and 'labels'.
|
|
51
|
+
* @property {number} scale - The scale of the UI.
|
|
52
|
+
* @property {Map<string | number, unknown>} _cache - Cache shared only during the execution of the render function (useful for caching images, etc. if needed).
|
|
53
|
+
*/
|
|
54
|
+
export type UIRenderProps<T extends Schema> = {
|
|
55
|
+
schema: T;
|
|
56
|
+
basePdf: BasePdf;
|
|
57
|
+
mode: Mode;
|
|
58
|
+
tabIndex?: number;
|
|
59
|
+
placeholder?: string;
|
|
60
|
+
stopEditing?: () => void;
|
|
61
|
+
value: string;
|
|
62
|
+
onChange?: (arg: {
|
|
63
|
+
key: string;
|
|
64
|
+
value: unknown;
|
|
65
|
+
} | {
|
|
66
|
+
key: string;
|
|
67
|
+
value: unknown;
|
|
68
|
+
}[]) => void;
|
|
69
|
+
rootElement: HTMLDivElement;
|
|
70
|
+
options: UIOptions;
|
|
71
|
+
theme: GlobalToken;
|
|
72
|
+
i18n: (key: string) => string;
|
|
73
|
+
scale: number;
|
|
74
|
+
_cache: Map<string | number, unknown>;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Type for properties used in configuring the property panel.
|
|
78
|
+
*
|
|
79
|
+
* @property {HTMLDivElement} rootElement - The root HTML element of the property panel.
|
|
80
|
+
* @property {SchemaForUI} activeSchema - The currently active schema for UI rendering.
|
|
81
|
+
* @property {HTMLElement[]} activeElements - Array of currently active HTML elements in the UI.
|
|
82
|
+
* @property {ChangeSchemas} changeSchemas - Function to change multiple schemas simultaneously.
|
|
83
|
+
* @property {SchemaForUI[]} schemas - Array of schemas for UI rendering.
|
|
84
|
+
* @property {Size} pageSize - The size of the page being edited.
|
|
85
|
+
* @property {UIOptions} options - UI options for the property panel.
|
|
86
|
+
* @property {GlobalToken} theme - The theme configuration used in the UI.
|
|
87
|
+
* @property {(key: keyof Dict | string) => string} i18n - Internationalization dictionary for UI labels and texts.
|
|
88
|
+
*/
|
|
89
|
+
type PropPanelProps = {
|
|
90
|
+
rootElement: HTMLDivElement;
|
|
91
|
+
activeSchema: SchemaForUI;
|
|
92
|
+
activeElements: HTMLElement[];
|
|
93
|
+
changeSchemas: ChangeSchemas;
|
|
94
|
+
schemas: SchemaForUI[];
|
|
95
|
+
options: UIOptions;
|
|
96
|
+
theme: GlobalToken;
|
|
97
|
+
i18n: (key: string) => string;
|
|
98
|
+
};
|
|
99
|
+
export type PropPanelWidgetProps = _PropPanelWidgetProps & PropPanelProps;
|
|
100
|
+
/**
|
|
101
|
+
* Used for customizing the property panel.
|
|
102
|
+
* @template T - Type of the extended Schema object.
|
|
103
|
+
* @property {Record<string, PropPanelSchema> | ((propPanelProps: Omit<PropPanelProps, 'rootElement'>) => Record<string, PropPanelSchema>)} schema - A function returning a form-render schema object or the schema object itself. When a function, it takes properties passed from the designer as arguments.
|
|
104
|
+
* @property {Record<string, (props: PropPanelWidgetProps) => void>} [widgets] - An object of functions returning form-render widgets. The functions take, as arguments, both form-render's WidgetProps and properties passed from the designer.
|
|
105
|
+
* @property {T} defaultSchema - The default schema set when adding the schema.
|
|
106
|
+
*/
|
|
107
|
+
export interface PropPanel<T extends Schema> {
|
|
108
|
+
schema: ((propPanelProps: Omit<PropPanelProps, 'rootElement'>) => Record<string, PropPanelSchema>) | Record<string, PropPanelSchema>;
|
|
109
|
+
widgets?: Record<string, (props: PropPanelWidgetProps) => void>;
|
|
110
|
+
defaultSchema: T;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The Plugin interface is used for PDF and UI rendering, as well as defining the property panel.
|
|
114
|
+
* The 'pdf' is used in the generator package, 'ui' is used in the viewer, form, and designer packages, and 'propPanel' is used in the designer package.
|
|
115
|
+
* Objects defined as Plugins using this interface can be used with a consistent interface across all packages.
|
|
116
|
+
* @template T Type of the extended Schema object.
|
|
117
|
+
* @property {function} pdf Function for rendering PDFs.
|
|
118
|
+
* @property {function} ui Function for rendering UI.
|
|
119
|
+
* @property {PropPanel} propPanel Object for defining the property panel.
|
|
120
|
+
* @property {string} [icon] Icon SVG for the plugin.
|
|
121
|
+
* @property {boolean} [uninterruptedEditMode] When editing in the UI, should the field avoid re-rendering while in edit mode?
|
|
122
|
+
*/
|
|
123
|
+
export type Plugin<T = Schema> = {
|
|
124
|
+
pdf: (arg: PDFRenderProps<T & Schema>) => Promise<void> | void;
|
|
125
|
+
ui: (arg: UIRenderProps<T & Schema>) => Promise<void> | void;
|
|
126
|
+
propPanel: PropPanel<T & Schema>;
|
|
127
|
+
icon?: string;
|
|
128
|
+
uninterruptedEditMode?: boolean;
|
|
129
|
+
};
|
|
130
|
+
export type Plugins = {
|
|
131
|
+
[key: string]: Plugin<any>;
|
|
132
|
+
};
|
|
133
|
+
export interface PluginRegistry {
|
|
134
|
+
plugins: {
|
|
135
|
+
[key: string]: Plugin;
|
|
136
|
+
};
|
|
137
|
+
exists(): boolean;
|
|
138
|
+
values(): Plugin[];
|
|
139
|
+
entries(): [string, Plugin][];
|
|
140
|
+
findByType(type: string): Plugin | undefined;
|
|
141
|
+
findWithLabelByType(type: string): [string, Plugin | undefined];
|
|
142
|
+
}
|
|
143
|
+
export type Lang = z.infer<typeof Lang>;
|
|
144
|
+
export type Dict = z.infer<typeof Dict>;
|
|
145
|
+
export type Mode = z.infer<typeof Mode>;
|
|
146
|
+
export type Size = z.infer<typeof Size>;
|
|
147
|
+
export type Schema = z.infer<typeof Schema>;
|
|
148
|
+
export type SchemaForUI = z.infer<typeof SchemaForUI>;
|
|
149
|
+
/**
|
|
150
|
+
* Represents the Font type definition.
|
|
151
|
+
* @property {Object} [x: string] - Object key is the font name.
|
|
152
|
+
* @property {(string | ArrayBuffer | Uint8Array)} data - The font data.
|
|
153
|
+
* @property {boolean} [fallback] - Please set to true for the fallback font when no font is specified. Only one value within the given Font object needs to be set to true.
|
|
154
|
+
* @property {boolean} [subset] - The default is true (use subset font). So if you don't want to use a subset font, please set it to false.
|
|
155
|
+
*/
|
|
156
|
+
export type Font = z.infer<typeof Font>;
|
|
157
|
+
export type ColorType = z.infer<typeof ColorType>;
|
|
158
|
+
export type BasePdf = z.infer<typeof BasePdf>;
|
|
159
|
+
export type BlankPdf = z.infer<typeof BlankPdf>;
|
|
160
|
+
export type CustomPdf = z.infer<typeof CustomPdf>;
|
|
161
|
+
export type Template = z.infer<typeof Template>;
|
|
162
|
+
export type CommonOptions = z.infer<typeof CommonOptions>;
|
|
163
|
+
export type GeneratorOptions = z.infer<typeof GeneratorOptions>;
|
|
164
|
+
export type GenerateProps = z.infer<typeof GenerateProps> & {
|
|
165
|
+
plugins?: Plugins;
|
|
166
|
+
};
|
|
167
|
+
export type UIOptions = z.infer<typeof UIOptions> & {
|
|
168
|
+
theme?: ThemeConfig;
|
|
169
|
+
};
|
|
170
|
+
export type UIProps = z.infer<typeof UIProps> & {
|
|
171
|
+
plugins?: Plugins;
|
|
172
|
+
};
|
|
173
|
+
export type PreviewProps = z.infer<typeof PreviewProps> & {
|
|
174
|
+
plugins?: Plugins;
|
|
175
|
+
};
|
|
176
|
+
export type DesignerProps = z.infer<typeof DesignerProps> & {
|
|
177
|
+
plugins?: Plugins;
|
|
178
|
+
};
|
|
179
|
+
export type SchemaPageArray = z.infer<typeof SchemaPageArray>;
|
|
180
|
+
export type LegacySchemaPageArray = z.infer<typeof LegacySchemaPageArray>;
|
|
181
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PDFME_VERSION = "5.5.7";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import { dirname, resolve } from 'path';
|
|
3
|
+
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
|
|
7
|
+
// Import the root config
|
|
8
|
+
const rootConfigPath = resolve(__dirname, '../../eslint.config.mjs');
|
|
9
|
+
const rootConfig = await import(rootConfigPath);
|
|
10
|
+
|
|
11
|
+
export default [
|
|
12
|
+
...rootConfig.default,
|
|
13
|
+
{
|
|
14
|
+
files: ['src/**/*.ts'],
|
|
15
|
+
languageOptions: {
|
|
16
|
+
parserOptions: {
|
|
17
|
+
project: ['./tsconfig.esm.json'],
|
|
18
|
+
tsconfigRootDir: __dirname,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
];
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pdfme/common",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"author": "hand-dot",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"pdf",
|
|
9
|
+
"pdf-generation",
|
|
10
|
+
"pdf-designer",
|
|
11
|
+
"pdf-viewer",
|
|
12
|
+
"typescript",
|
|
13
|
+
"react"
|
|
14
|
+
],
|
|
15
|
+
"description": "TypeScript base PDF generator and React base UI. Open source, developed by the community, and completely free to use under the MIT license!",
|
|
16
|
+
"homepage": "https://pdfme.com",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git@github.com:pdfme/pdfme.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/pdfme/pdfme/issues"
|
|
23
|
+
},
|
|
24
|
+
"main": "dist/cjs/src/index.js",
|
|
25
|
+
"module": "dist/esm/src/index.js",
|
|
26
|
+
"types": "dist/types/src/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"node": "./dist/node/src/index.js",
|
|
31
|
+
"default": "./dist/esm/src/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": "./dist/cjs/src/index.js",
|
|
34
|
+
"types": "./dist/types/src/index.d.ts"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "node set-version.js && tsc -p tsconfig.esm.json -w",
|
|
39
|
+
"prebuild": "node set-version.js",
|
|
40
|
+
"build": "run-p build:cjs build:esm build:node",
|
|
41
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
42
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
43
|
+
"build:node": "tsc -p tsconfig.node.json",
|
|
44
|
+
"clean": "rimraf dist",
|
|
45
|
+
"lint": "eslint --ext .ts src --config eslint.config.mjs",
|
|
46
|
+
"test": "jest",
|
|
47
|
+
"prune": "ts-prune src",
|
|
48
|
+
"prettier": "prettier --write 'src/**/*.ts'"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@pdfme/pdf-lib": "*",
|
|
52
|
+
"acorn": "^8.15.0",
|
|
53
|
+
"buffer": "^6.0.3",
|
|
54
|
+
"zod": "^4.1.12"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"antd": "^5.11.2",
|
|
58
|
+
"form-render": "^2.2.20"
|
|
59
|
+
},
|
|
60
|
+
"jest": {
|
|
61
|
+
"resolver": "ts-jest-resolver",
|
|
62
|
+
"moduleFileExtensions": [
|
|
63
|
+
"js",
|
|
64
|
+
"ts"
|
|
65
|
+
],
|
|
66
|
+
"transform": {
|
|
67
|
+
"^.+\\.ts?$": [
|
|
68
|
+
"ts-jest",
|
|
69
|
+
{
|
|
70
|
+
"tsconfig": "tsconfig.esm.json"
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"testMatch": [
|
|
75
|
+
"**/*.test.ts"
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"publishConfig": {
|
|
79
|
+
"access": "public"
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@types/estree": "^1.0.6"
|
|
83
|
+
}
|
|
84
|
+
}
|
package/set-version.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
|
+
|
|
5
|
+
const updateVersion = (version) => {
|
|
6
|
+
const filePath = path.join(__dirname, 'src/version.ts');
|
|
7
|
+
let content = '';
|
|
8
|
+
|
|
9
|
+
if (!fs.existsSync(filePath)) {
|
|
10
|
+
content = `export const PDFME_VERSION = '${version}';\n`;
|
|
11
|
+
} else {
|
|
12
|
+
content = fs.readFileSync(filePath, 'utf8');
|
|
13
|
+
const versionRegex = /export const PDFME_VERSION = '.*';/;
|
|
14
|
+
if (versionRegex.test(content)) {
|
|
15
|
+
content = content.replace(versionRegex, `export const PDFME_VERSION = '${version}';`);
|
|
16
|
+
} else {
|
|
17
|
+
content += `\nexport const PDFME_VERSION = '${version}';\n`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
22
|
+
console.log(`Replaced PDFME_VERSION with '${version}' in ${filePath}`);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const gitTag = execSync('git describe --tags $(git rev-list --tags --max-count=1)', { encoding: 'utf8' }).trim();
|
|
27
|
+
updateVersion(gitTag);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
console.error('Error replacing PDFME_VERSION:', error);
|
|
30
|
+
updateVersion('x.x.x');
|
|
31
|
+
}
|