tauri/.scripts/covector/sync-cli-metadata.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
2023-02-19 16:17:49 +03:00
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/*
This script is solely intended to be run as part of the `covector version` step to
keep the `../tooling/cli/metadata.json` up to date with other version bumps. Long term
we should look to find a more "rusty way" to import / "pin" a version value in our tauri-cli
rust binaries.
*/
const { readFileSync, writeFileSync } = require('fs')
const packageNickname = process.argv[2]
const filePath =
packageNickname === '@tauri-apps/cli'
? `../../../tooling/cli/metadata.json`
: `../../tooling/cli/metadata.json`
const bump = process.argv[3]
2022-06-15 19:53:44 +03:00
let index = null
switch (bump) {
case 'major':
index = 0
break
2022-06-15 19:53:44 +03:00
case 'minor':
index = 1
break
2022-06-15 19:53:44 +03:00
case 'patch':
index = 2
break
2022-06-15 19:53:44 +03:00
default:
throw new Error('unexpected bump ' + bump)
}
const inc = (version) => {
const v = version.split('.')
2022-09-15 20:51:42 +03:00
for (let i = 0; i < v.length; i++) {
if (i === index) {
v[i] = String(Number(v[i]) + 1)
} else if (i > index) {
v[i] = 0
}
}
return v.join('.')
}
// read file into js object
const metadata = JSON.parse(readFileSync(filePath, 'utf-8'))
// set field version
let version
if (packageNickname === '@tauri-apps/cli') {
version = inc(metadata['cli.js'].version)
metadata['cli.js'].version = version
} else {
version = inc(metadata[packageNickname])
metadata[packageNickname] = version
}
writeFileSync(filePath, JSON.stringify(metadata, null, 2) + '\n')
console.log(`wrote ${version} for ${packageNickname} into metadata.json`)
console.dir(metadata)