UNPKG

@halospv3/hce.shared-config

Version:

Automate commit message quality, changelogs, and CI/CD releases. Its `main` entry point is a Semantic Release config. Functions and classes are exposed for customization. An ESLint config, a Commitlint config, and addl. resources for .NET projects are als

43 lines (42 loc) 2.07 kB
import { NugetRegistryInfo, getGithubOutput } from "./NugetRegistryInfo.mjs"; import * as console from "node:console"; import esMain from "es-main"; //#region src/dotnet/IsNextVersionAlreadyPublished.cli.ts /** * @returns if successful * @throws {Error} if... * - {@link process.argv} does not include... * - `--packageId [string]` * - `--source [string]` * - Value of `await getGithubOutput())['new-release-version']`... * - is not a valid Version * - already exists at `source` */ async function main() { const arguments_ = process.argv.slice(2); const options = { packageId: void 0, source: void 0 }; for (let index = 0; index < arguments_.length; index += 2) { const argumentName = arguments_[index]; const argumentValue = arguments_[index + 1]; if (argumentValue !== void 0 && argumentName?.startsWith("--") === true) options[argumentName.slice(2)] = argumentValue; } if (typeof options.packageId !== "string") throw new Error("packageId must be a string"); if (typeof options.source !== "string") throw new Error("source must be a string"); const packageId = options.packageId, source = options.source, versionPattern = /* @__PURE__ */ new RegExp(/\d+\.\d+\.\d+([-+].+)?/); const ghOutput = await getGithubOutput() ?? {}; const matches = versionPattern.exec(ghOutput["new-release-version"] ?? ""); if (matches === null || matches.length === 0) throw new Error("The variable new-release-version is not present in the GITHUB_OUTPUT env file or its value contains invalid characters."); const nextVersion = matches[0]; const isPublished = await NugetRegistryInfo.IsNextVersionAlreadyPublished(source, packageId, nextVersion); if (typeof isPublished !== "boolean") throw new Error("isPublished is not a boolean"); if (isPublished) throw new Error(`${packageId}@${nextVersion} already exists at ${source}.`); console.log(`OK: ${packageId}@${nextVersion} does NOT yet exist at ${source}. Yay.`); return 0; } if (esMain(import.meta)) await main(); //#endregion export {}; //# sourceMappingURL=IsNextVersionAlreadyPublished.cli.mjs.map