2021-12-20 06:10:46 +01:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
import fs from 'fs-extra';
|
|
|
|
import semver from 'semver';
|
|
|
|
import yargs from 'yargs';
|
|
|
|
import { hideBin } from 'yargs/helpers';
|
|
|
|
|
2023-06-08 11:31:03 +02:00
|
|
|
const repository = 'saluu/darkness-dependent-vision';
|
2023-06-21 20:15:19 +02:00
|
|
|
const giteaURL = 'https://git2.f3l.de';
|
2022-02-08 21:36:26 +01:00
|
|
|
|
2023-06-21 20:15:19 +02:00
|
|
|
const getLicenseURL = (version) => `${giteaURL}/${repository}/raw/tag/${version}/LICENSE.md`;
|
|
|
|
const getReadmeURL = (version) => `${giteaURL}/${repository}/raw/tag/${version}/README.md`;
|
|
|
|
const getChangelogURL = (version) => `${giteaURL}/${repository}/releases/tag/${version}`;
|
2021-12-20 06:10:46 +01:00
|
|
|
const getDownloadURL = (version) =>
|
2023-06-21 20:15:19 +02:00
|
|
|
`${giteaURL}/${repository}/releases/download/${version}/darkness-dependent-vision.zip`;
|
2021-12-20 06:10:46 +01:00
|
|
|
|
2022-02-01 13:11:13 +01:00
|
|
|
const manifestPath = 'module.json';
|
|
|
|
|
2021-12-20 06:10:46 +01:00
|
|
|
/**
|
|
|
|
* Get the contents of the manifest file as object.
|
2022-02-01 13:11:13 +01:00
|
|
|
* @returns {unknown} An object describing the manifest
|
2021-12-20 06:10:46 +01:00
|
|
|
*/
|
|
|
|
function getManifest() {
|
|
|
|
if (fs.existsSync(manifestPath)) {
|
2022-02-01 13:11:13 +01:00
|
|
|
return fs.readJSONSync(manifestPath);
|
2021-12-20 06:10:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the target version based on on the current version and the argument passed as release.
|
|
|
|
* @param {string} currentVersion The current version
|
|
|
|
* @param {semver.ReleaseType | string} release Either a semver release type or a valid semver version
|
|
|
|
* @returns {string | null} The target version
|
|
|
|
*/
|
|
|
|
function getTargetVersion(currentVersion, release) {
|
|
|
|
if (['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].includes(release)) {
|
|
|
|
return semver.inc(currentVersion, release);
|
|
|
|
} else {
|
|
|
|
return semver.valid(release);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update version and download URL.
|
|
|
|
* @param {semver.ReleaseType | string} release Either a semver release type or a valid semver version
|
|
|
|
*/
|
|
|
|
function bumpVersion(release) {
|
|
|
|
if (!release) {
|
|
|
|
throw new Error('Missing release type');
|
|
|
|
}
|
|
|
|
|
|
|
|
const packageJson = fs.readJSONSync('package.json');
|
|
|
|
const manifest = getManifest();
|
|
|
|
if (!manifest) throw new Error('Manifest JSON not found');
|
|
|
|
|
|
|
|
const currentVersion = packageJson.version;
|
|
|
|
const targetVersion = getTargetVersion(currentVersion, release);
|
|
|
|
|
|
|
|
if (!targetVersion) {
|
|
|
|
throw new Error('Incorrect version arguments');
|
|
|
|
}
|
|
|
|
if (targetVersion === currentVersion) {
|
|
|
|
throw new Error('Target version is identical to current version');
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(`Bumping version number to '${targetVersion}'`);
|
|
|
|
packageJson.version = targetVersion;
|
2023-06-13 01:09:51 +02:00
|
|
|
fs.writeJSONSync('package.json', packageJson, { spaces: 2 });
|
2022-02-08 21:36:26 +01:00
|
|
|
manifest.license = getLicenseURL(targetVersion);
|
|
|
|
manifest.readme = getReadmeURL(targetVersion);
|
|
|
|
manifest.changelog = getChangelogURL(targetVersion);
|
2022-02-01 13:11:13 +01:00
|
|
|
manifest.version = targetVersion;
|
|
|
|
manifest.download = getDownloadURL(targetVersion);
|
2023-06-13 01:09:51 +02:00
|
|
|
fs.writeJSONSync(manifestPath, manifest, { spaces: 2 });
|
2021-12-20 06:10:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const argv = yargs(hideBin(process.argv)).usage('Usage: $0').option('release', {
|
|
|
|
alias: 'r',
|
|
|
|
type: 'string',
|
|
|
|
demandOption: true,
|
|
|
|
description: 'Either a semver release type or a valid semver version',
|
|
|
|
}).argv;
|
|
|
|
const release = argv.r;
|
|
|
|
bumpVersion(release);
|