napi-rs/cli/src/api/version.ts
forehal a781a4f27e feat(cli): brand new cli tool with both cli and programmatical usage (#1492)
BREAKING CHANGE: requires node >= 16 and some cli options have been renamed
2023-04-06 11:04:53 +08:00

26 lines
812 B
TypeScript

import { join, resolve } from 'path'
import { applyDefaultVersionOptions, VersionOptions } from '../def/version.js'
import {
readNapiConfig,
debugFactory,
updatePackageJson,
} from '../utils/index.js'
const debug = debugFactory('version')
export async function version(userOptions: VersionOptions) {
const options = applyDefaultVersionOptions(userOptions)
const packageJsonPath = resolve(options.cwd, options.packageJsonPath)
const config = await readNapiConfig(packageJsonPath)
for (const target of config.targets) {
const pkgDir = resolve(options.cwd, options.npmDir, target.platformArchABI)
debug(`Update version to %i in [%i]`, config.packageJson.version, pkgDir)
await updatePackageJson(join(pkgDir, 'package.json'), {
version: config.packageJson.version,
})
}
}