From 7e514f303e9df3bf9f1c59747905e2a5d0ba424c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E9=A2=A2?= Date: Wed, 2 Jan 2019 12:23:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BA=BF=E4=B8=8A=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7=E5=BA=94=E8=AF=A5=E4=BB=A5=E7=BA=BF=E4=B8=8A=E4=B8=BA?= =?UTF-8?q?=E5=87=86=EF=BC=8C=E8=80=8C=E4=B8=8D=E6=98=AF=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- @types/index.d.ts | 8 +++++++- src/utils/index.ts | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/@types/index.d.ts b/@types/index.d.ts index 4c79723..5d8d1f9 100644 --- a/@types/index.d.ts +++ b/@types/index.d.ts @@ -271,10 +271,16 @@ declare namespace build { */ interface options extends BuildService.serverInitOptions { /** - * 当前运行版本 + * 当前程序运行版本 */ version?: string + /** + * 当前 @bestminr/build 运行版本 + * * readonly + */ + buildVersion?: string + /** * 根目录 地址 */ diff --git a/src/utils/index.ts b/src/utils/index.ts index b40dc95..16f2dab 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -105,6 +105,26 @@ function setBabelrc(options: ConfigOptions.options) { return options } +/** + * 设置 版本号 + * @param options build 通用 webpack 配置 + */ +function setVersion(options: ConfigOptions.options) { + if (options.version) return options + try { + const PACKAGE = JSON.parse( + readFileSync(resolve(options.rootDir || '', 'package.json'), { + encoding: 'utf-8' + }) + ) + options.version = PACKAGE.version + return options + } catch (error) { + consola.fatal('setVersion', error) + return process.exit(0) + } +} + /** * 设置 webpack * @param options build 通用 webpack 配置 @@ -250,7 +270,9 @@ export async function initConfig( await setWebpack(options, mode) - options.version = options.version || argv.version + options.buildVersion = argv.version + + setVersion(options) buildServiceConfig = options