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

1 lines 3.38 kB
{"version":3,"file":"IsNextVersionAlreadyPublished.cli.mjs","names":[],"sources":["../../src/dotnet/IsNextVersionAlreadyPublished.cli.ts"],"sourcesContent":["import * as console from 'node:console';\nimport { NugetRegistryInfo, getGithubOutput } from './NugetRegistryInfo.ts';\nimport esMain from 'es-main';\n\n/**\n * @returns if successful\n * @throws {Error} if...\n * - {@link process.argv} does not include...\n * - `--packageId [string]`\n * - `--source [string]`\n * - Value of `await getGithubOutput())['new-release-version']`...\n * - is not a valid Version\n * - already exists at `source`\n */\nasync function main(): Promise<0> {\n const arguments_ = process.argv.slice(2);\n // Parse command-line arguments - https://stackoverflow.com/a/76298476/14894786\n const options: {\n packageId: string | undefined;\n source: string | undefined;\n } & Record<string, string | undefined> = { packageId: undefined, source: undefined };\n for (let index = 0; index < arguments_.length; index += 2) {\n const argumentName = arguments_[index];\n const argumentValue = arguments_[index + 1];\n if (argumentValue !== undefined && argumentName?.startsWith('--') === true) {\n options[argumentName.slice(2)] = argumentValue;\n }\n }\n\n if (typeof options.packageId !== 'string')\n throw new Error('packageId must be a string');\n if (typeof options.source !== 'string')\n throw new Error('source must be a string');\n\n const packageId = options.packageId,\n source = options.source,\n versionPattern = new RegExp(/\\d+\\.\\d+\\.\\d+([-+].+)?/);\n const ghOutput = await getGithubOutput() ?? {};\n const matches = versionPattern.exec(ghOutput['new-release-version'] ?? '');\n if (matches === null || matches.length === 0)\n throw new Error(\n 'The variable new-release-version is not present in the GITHUB_OUTPUT env file or its value contains invalid characters.',\n );\n\n const nextVersion = matches[0];\n const isPublished = await NugetRegistryInfo.IsNextVersionAlreadyPublished(\n source,\n packageId,\n nextVersion,\n );\n\n if (typeof isPublished !== 'boolean')\n throw new Error('isPublished is not a boolean');\n if (isPublished)\n throw new Error(`${packageId}@${nextVersion} already exists at ${source}.`);\n console.log(`OK: ${packageId}@${nextVersion} does NOT yet exist at ${source}. Yay.`);\n\n return 0;\n}\n\nif (esMain(import.meta))\n await main();\n"],"mappings":";;;;;;;;;;;;;;AAcA,eAAe,OAAmB;CAChC,MAAM,aAAa,QAAQ,KAAK,MAAM,CAAC;CAEvC,MAAM,UAGmC;EAAE,WAAW,KAAA;EAAW,QAAQ,KAAA;CAAU;CACnF,KAAK,IAAI,QAAQ,GAAG,QAAQ,WAAW,QAAQ,SAAS,GAAG;EACzD,MAAM,eAAe,WAAW;EAChC,MAAM,gBAAgB,WAAW,QAAQ;EACzC,IAAI,kBAAkB,KAAA,KAAa,cAAc,WAAW,IAAI,MAAM,MACpE,QAAQ,aAAa,MAAM,CAAC,KAAK;CAErC;CAEA,IAAI,OAAO,QAAQ,cAAc,UAC/B,MAAM,IAAI,MAAM,4BAA4B;CAC9C,IAAI,OAAO,QAAQ,WAAW,UAC5B,MAAM,IAAI,MAAM,yBAAyB;CAE3C,MAAM,YAAY,QAAQ,WACxB,SAAS,QAAQ,QACjB,iCAAiB,IAAI,OAAO,wBAAwB;CACtD,MAAM,WAAW,MAAM,gBAAgB,KAAK,CAAC;CAC7C,MAAM,UAAU,eAAe,KAAK,SAAS,0BAA0B,EAAE;CACzE,IAAI,YAAY,QAAQ,QAAQ,WAAW,GACzC,MAAM,IAAI,MACR,yHACF;CAEF,MAAM,cAAc,QAAQ;CAC5B,MAAM,cAAc,MAAM,kBAAkB,8BAC1C,QACA,WACA,WACF;CAEA,IAAI,OAAO,gBAAgB,WACzB,MAAM,IAAI,MAAM,8BAA8B;CAChD,IAAI,aACF,MAAM,IAAI,MAAM,GAAG,UAAU,GAAG,YAAY,qBAAqB,OAAO,EAAE;CAC5E,QAAQ,IAAI,OAAO,UAAU,GAAG,YAAY,yBAAyB,OAAO,OAAO;CAEnF,OAAO;AACT;AAEA,IAAI,OAAO,OAAO,IAAI,GACpB,MAAM,KAAK"}