2021-04-19 17:15:21 +03:00
|
|
|
#!/usr/bin/env node
|
2023-02-19 16:17:49 +03:00
|
|
|
// Copyright 2019-2023 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-09-18 15:16:35 +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-09-18 15:16:35 +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':
|
2022-09-18 15:16:35 +03:00
|
|
|
index = 0
|
|
|
|
break
|
2022-06-15 19:53:44 +03:00
|
|
|
case 'minor':
|
2022-09-18 15:16:35 +03:00
|
|
|
index = 1
|
|
|
|
break
|
2022-06-15 19:53:44 +03:00
|
|
|
case 'patch':
|
2022-09-18 15:16:35 +03:00
|
|
|
index = 2
|
|
|
|
break
|
2022-06-15 19:53:44 +03:00
|
|
|
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-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
|
|
|
|
}
|
|
|
|
}
|
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)
|