Skip to content

Commit

Permalink
Merge pull request #99 from faraplay/versionNumbering
Browse files Browse the repository at this point in the history
New revision number algorithm
  • Loading branch information
OctoNezd authored Jan 5, 2024
2 parents 32daae7 + cbbbef0 commit 29aeb10
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@ const webpack = require("webpack");
const GenerateJsonPlugin = require("generate-json-webpack-plugin");
const TerserWebpackPlugin = require("terser-webpack-plugin");
const path = require("path");

function getNextRevisionNumber(version) {
// get a list of tags with the specified version number (but with any revision number)
const existingVersions = require("child_process")
.execSync(`git tag -l ${version}.*`)
.toString()
.split("\n");
const revisionNumbers = existingVersions
.map((fullVersion) =>
parseInt(
fullVersion.slice(version.length + 1) // +1 for the dot after the version number
)
)
.filter((revision) => !isNaN(revision) && revision >= 0);
// this will be the maximum number in the array, or -1 if the array is empty.
// (actually it also returns -1 if all numbers are <= -1, but we filtered the array so that
// all entries are nonnegative integers.)
const latestRevision = revisionNumbers.reduce((prev, cur) => Math.max(prev, cur), -1);
const nextRevision = latestRevision + 1;
if (!Number.isSafeInteger(nextRevision)) {
throw new Error(`Next revision number ${nextRevision} is not a safe integer!`)
}
return nextRevision;
}

const version = require("./package.json").version;
ver_offset = 1;
const revision =
parseInt(
require("child_process")
.execSync("git rev-list --all --count")
.toString()
.trim()
.slice(0, 7)
) + ver_offset;
const fullVersion = version + "." + revision;
const fullVersion = `${version}.${getNextRevisionNumber(version)}`;

const manifest = {
manifest_version: 2,
Expand All @@ -40,7 +56,7 @@ const manifest = {
id: "[email protected]",
strict_min_version: "113.0",
},
gecko_android: {}
gecko_android: {},
},
};
const userScriptBanner = `// ==UserScript==
Expand Down

0 comments on commit 29aeb10

Please sign in to comment.