Skip to content

Commit

Permalink
feat: 增加 pkgName, pkgVersion 导出
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Apr 1, 2023
1 parent c62b0f8 commit 64df5da
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
36 changes: 35 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"@commitlint/types": "^17.4.4",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-typescript": "^11.0.0",
"@types/node": "^18.15.7",
"@types/prettier": "^2.7.2",
Expand Down
7 changes: 7 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import pkg from './package.json' assert { type: 'json' };

/** @type {import('rollup').RollupOptions} */
export default {
Expand All @@ -20,6 +22,11 @@ export default {
},
],
plugins: [
replace({
preventAssignment: true,
'process.env.PKG_NAME': JSON.stringify(pkg.name),
'process.env.PKG_VERSION': JSON.stringify(pkg.version),
}),
typescript({
tsconfig: 'tsconfig.json',
}),
Expand Down
3 changes: 3 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import path from 'path';

export const pkgName = process.env.PKG_NAME!;
export const pkgVersion = process.env.PKG_VERSION!;

const dirname = __dirname;

export const templatesDir = path.join(dirname, '../templates');
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { pkgName, pkgVersion } from './const';
export * from './generator';
export * from './configure';
export * from './types';
Expand Down
9 changes: 9 additions & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module 'process' {
interface ProcessEnv {
// package name
PKG_NAME: string;

// package version
PKG_VERSION: string;
}
}

0 comments on commit 64df5da

Please sign in to comment.