2021-04-19 17:15:21 +03:00
|
|
|
#!/usr/bin/env node
|
2022-08-28 21:13:21 +03:00
|
|
|
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
|
2021-04-19 17:15:21 +03:00
|
|
|
// 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
|
2022-02-10 23:23:10 +03:00
|
|
|
keep the `../tooling/cli/metadata.json` up to date with other version bumps. Long term
|
2021-04-19 17:15:21 +03:00
|
|
|
we should look to find a more "rusty way" to import / "pin" a version value in our cli.rs
|
|
|
|
rust binaries.
|
|
|
|
*/
|
|
|
|
|
2022-02-10 23:23:10 +03:00
|
|
|
const {
|
|
|
|
readFileSync,
|
|
|
|
writeFileSync
|
|
|
|
} = require('fs')
|
2021-04-19 17:15:21 +03:00
|
|
|
|
2021-07-04 01:48:04 +03:00
|
|
|
const packageNickname = process.argv[2]
|
2022-02-11 02:08:54 +03:00
|
|
|
const filePath = packageNickname === 'cli.js' ? `../../../tooling/cli/metadata.json` : `../../tooling/cli/metadata.json`
|
2021-07-04 01:48:04 +03:00
|
|
|
const bump = process.argv[3]
|
2022-06-15 19:53:44 +03:00
|
|
|
let index = null
|
|
|
|
|
|
|
|
switch (bump) {
|
|
|
|
case 'major':
|
|
|
|
index = 0;
|
|
|
|
break;
|
|
|
|
case 'minor':
|
|
|
|
index = 1;
|
|
|
|
break;
|
|
|
|
case 'patch':
|
|
|
|
index = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new Error('unexpected bump ' + bump)
|
2021-04-19 17:15:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const inc = (version) => {
|
2022-02-10 22:46:30 +03:00
|
|
|
const v = version.split('.')
|
2022-06-15 19:53:44 +03:00
|
|
|
const n = v[index]
|
|
|
|
v[index] = String(Number(n) + 1)
|
2022-02-10 22:46:30 +03:00
|
|
|
return v.join('.')
|
2021-07-04 01:48:04 +03:00
|
|
|
}
|
2021-04-19 17:15:21 +03:00
|
|
|
|
|
|
|
// read file into js object
|
2021-07-04 01:48:04 +03:00
|
|
|
const metadata = JSON.parse(readFileSync(filePath, 'utf-8'))
|
2021-04-19 17:15:21 +03:00
|
|
|
|
|
|
|
// set field version
|
2021-07-04 01:48:04 +03:00
|
|
|
let version
|
|
|
|
if (packageNickname === 'cli.js') {
|
|
|
|
version = inc(metadata[packageNickname].version)
|
|
|
|
metadata[packageNickname].version = version
|
2021-04-19 17:15:21 +03:00
|
|
|
} else {
|
2021-07-04 01:48:04 +03:00
|
|
|
version = inc(metadata[packageNickname])
|
|
|
|
metadata[packageNickname] = version
|
2021-04-19 17:15:21 +03:00
|
|
|
}
|
|
|
|
|
2021-07-04 01:48:04 +03:00
|
|
|
writeFileSync(filePath, JSON.stringify(metadata, null, 2) + '\n')
|
|
|
|
console.log(`wrote ${version} for ${packageNickname} into metadata.json`)
|
|
|
|
console.dir(metadata)
|