Skip to content

Commit

Permalink
feat: 线上版本号应该以线上为准,而不是部署时
Browse files Browse the repository at this point in the history
  • Loading branch information
孙颢 committed Jan 2, 2019
1 parent 4d6e545 commit 7e514f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion @types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,16 @@ declare namespace build {
*/
interface options extends BuildService.serverInitOptions {
/**
* 当前运行版本
* 当前程序运行版本
*/
version?: string

/**
* 当前 @bestminr/build 运行版本
* * readonly
*/
buildVersion?: string

/**
* 根目录 地址
*/
Expand Down
24 changes: 23 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 配置
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 7e514f3

Please sign in to comment.