UNPKG

1.32 kBPlain TextView Raw
1require('source-map-support').install()
2const path = require('path')
3const fse = require('fs-extra')
4import './error'
5import './framework/base'
6
7// 将配置参数写入到package.json中,将发布脚本封装到npm框架包中对应用透明。
8// 通过package.json中的配置信息将其转换为config.sh脚本方便shell中加载使用实现shell与nodejs交互
9let package_json_file_path = path.join(__dirname, './package.json')
10let package_lock_json_file_path = path.join(__dirname, './package-lock.json')
11
12// 必须确保package.json和package-lock.json同时存在保持版本一致性
13xassert(fse.existsSync(package_json_file_path))
14xassert(fse.existsSync(package_lock_json_file_path))
15
16function upgrade_patch_version(file_path: string): string {
17 let cfg = fse.readJsonSync(file_path)
18 xassert(cfg && cfg.version && /(\d+)\.(\d+)\.(\d+)/.test(cfg.version))
19 let list: any = /(\d+)\.(\d+)\.(\d+)/.exec(cfg.version)
20 cfg.version = `${list[1]}.${list[2]}.${parseInt(list[3]) + 1}`
21 fse.writeJSONSync(file_path, cfg, {spaces: 2})
22 return cfg.version
23}
24
25// 保持事务更新一致性
26const v1 = upgrade_patch_version(package_json_file_path)
27const v2 = upgrade_patch_version(package_lock_json_file_path)
28xassert(v1 === v2)
29
30fse.writeFileSync(path.join(__dirname, './__version__'), v1 + '\r\n')