diff --git a/.fatherrc.js b/.fatherrc.js
index 048528b..c869c21 100644
--- a/.fatherrc.js
+++ b/.fatherrc.js
@@ -1,3 +1,11 @@
+import { writeFileSync } from 'fs';
+import { join } from 'path';
+import { version } from './package.json';
+
+// generate version.ts
+const versionFilePath = join(__dirname, './src/version.ts');
+writeFileSync(versionFilePath, `export const version = '${version}';`);
+
export default {
target: 'browser',
esm: 'babel',
diff --git a/src/__tests__/utils.test.ts b/src/__tests__/utils.test.ts
index a240848..7c92813 100644
--- a/src/__tests__/utils.test.ts
+++ b/src/__tests__/utils.test.ts
@@ -7,6 +7,7 @@ import {
sleep,
validateExportLifecycle,
} from '../utils';
+import { version } from '../../package.json';
test('should wrap the id [1]', () => {
const id = 'REACT16';
@@ -26,7 +27,9 @@ test('should wrap string with div', () => {
const ret = factory(tpl);
- expect(ret).toBe(`
${tpl}
`);
+ expect(ret).toBe(
+ `${tpl}
`,
+ );
});
test('should be able to validate lifecycle', () => {
diff --git a/src/utils.ts b/src/utils.ts
index 9746a6d..0b0ea75 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -4,6 +4,8 @@
*/
import { isFunction, snakeCase } from 'lodash';
+import { version } from './version';
+
import type { FrameworkConfiguration } from './interfaces';
export function toArray(array: T | T[]): T[] {
@@ -100,7 +102,7 @@ export function isBoundedFunction(fn: CallableFunction) {
}
export function getDefaultTplWrapper(id: string, name: string) {
- return (tpl: string) => `${tpl}
`;
+ return (tpl: string) => `${tpl}
`;
}
export function getWrapperId(id: string) {
diff --git a/src/version.ts b/src/version.ts
new file mode 100644
index 0000000..a725083
--- /dev/null
+++ b/src/version.ts
@@ -0,0 +1 @@
+export { version } from '../package.json';
diff --git a/tsconfig.json b/tsconfig.json
index bb98735..f7e23a0 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -5,7 +5,7 @@
"lib": ["es2018", "dom"],
"declaration": true,
"outDir": "./esm",
- "rootDir": "./src",
+ "rootDir": "./",
"importHelpers": true,
"downlevelIteration": true,
"strict": true,