2020-09-04 17:22:15 +09:00
|
|
|
import { join } from 'path'
|
|
|
|
|
|
|
|
import chalk from 'chalk'
|
2021-08-07 01:22:53 +09:00
|
|
|
import { Command, Option } from 'clipanion'
|
2020-09-04 17:22:15 +09:00
|
|
|
|
|
|
|
import { getNapiConfig } from './consts'
|
|
|
|
import { debugFactory } from './debug'
|
|
|
|
import { spawn } from './spawn'
|
|
|
|
import { updatePackageJson } from './update-package'
|
|
|
|
|
|
|
|
const debug = debugFactory('version')
|
|
|
|
|
|
|
|
export class VersionCommand extends Command {
|
2020-12-23 23:43:43 +09:00
|
|
|
static usage = Command.Usage({
|
|
|
|
description: 'Update versions in created npm dir',
|
|
|
|
})
|
|
|
|
|
2021-08-07 01:22:53 +09:00
|
|
|
static paths = [['version']]
|
|
|
|
|
2020-09-08 10:21:59 +09:00
|
|
|
static async updatePackageJson(prefix: string, configFileName?: string) {
|
2020-10-15 21:16:52 +09:00
|
|
|
const { version, platforms } = getNapiConfig(configFileName)
|
|
|
|
for (const platformDetail of platforms) {
|
|
|
|
const pkgDir = join(process.cwd(), prefix, platformDetail.platformArchABI)
|
2020-09-04 17:22:15 +09:00
|
|
|
debug(
|
|
|
|
`Update version to ${chalk.greenBright(
|
|
|
|
version,
|
|
|
|
)} in [${chalk.yellowBright(pkgDir)}]`,
|
|
|
|
)
|
|
|
|
await updatePackageJson(join(pkgDir, 'package.json'), {
|
|
|
|
version,
|
|
|
|
})
|
|
|
|
}
|
2020-09-08 10:21:59 +09:00
|
|
|
}
|
|
|
|
|
2021-08-07 01:22:53 +09:00
|
|
|
prefix = Option.String(`-p,--prefix`, 'npm')
|
2020-09-08 10:21:59 +09:00
|
|
|
|
2021-08-07 01:22:53 +09:00
|
|
|
configFileName?: string = Option.String('-c,--config')
|
2020-09-08 10:21:59 +09:00
|
|
|
|
|
|
|
async execute() {
|
|
|
|
await VersionCommand.updatePackageJson(this.prefix, this.configFileName)
|
2020-09-04 17:22:15 +09:00
|
|
|
await spawn('git add .')
|
|
|
|
}
|
|
|
|
}
|