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 15.3 kB
{"version":3,"file":"MSBuildProjectProperties.mjs","names":[],"sources":["../../src/dotnet/MSBuildProjectProperties.ts"],"sourcesContent":["import { strictEqual } from 'node:assert/strict';\nimport { existsSync } from 'node:fs';\n// eslint-disable-next-line unicorn/import-style\nimport * as node_path from 'node:path';\nimport { CaseInsensitiveMap } from '../CaseInsensitiveMap.ts';\nimport type { BaseClass, ClassLike } from '../utils/reflection.ts';\n\n/**\n * Known properties. Additional properties may be added upon request.\n *\n * todo: add Reserved properties, Well-Known properties, Common properties, and more. Maybe as sub classes.\n * See:\n * - {@link https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-reserved-and-well-known-properties?view=vs-2022 MSBuild Reserved and Well-known Properties}\n * - {@link https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2022 Common MSBuild project properties}\n * - {@link https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props Microsoft.NET.Sdk}\n * - {@link https://learn.microsoft.com/en-us/aspnet/core/razor-pages/web-sdk?view=aspnetcore-8.0&toc=%2Fdotnet%2Fnavigate%2Ftools-diagnostics%2Ftoc.json&bc=%2Fdotnet%2Fbreadcrumb%2Ftoc.json#properties Microsoft.NET.Sdk.Web}\n * - {@link https://learn.microsoft.com/en-us/aspnet/core/razor-pages/sdk?view=aspnetcore-8.0&toc=%2Fdotnet%2Fnavigate%2Ftools-diagnostics%2Ftoc.json&bc=%2Fdotnet%2Fbreadcrumb%2Ftoc.json Microsoft.NET.Sdk.Razor}\n * - {@link https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props-desktop Microsoft.NET.Sdk.Desktop}\n */\nexport class MSBuildProjectProperties {\n // #region static\n\n /**\n * Resolve the given path if it is not absolute. If the path exists, it is returned. Else, an Error is thrown.\n * @param path The full file path of an MSBuild project.\n * @returns The absolute path to the MSBuild project file.\n * @throws {Error} if the path cannot be resolved to an existing file.\n */\n static GetFullPath(path: string): string {\n if (!node_path.isAbsolute(path))\n path = node_path.resolve(path);\n if (!existsSync(path))\n throw new Error(`${node_path.basename(path)} could not be found at \"${path}\"`);\n return path;\n }\n\n /**\n * Note: This method may remove elements from {@link properties}.\\\n * Try to get an element from {@link properties} by its {@link key}.\n * If an element is found, it is removed and the value of the element is returned.\n * Otherwise, `undefined` is returned.\n * @param properties The CaseInsensitiveMap of properties passed to the constructor.\n * @param key The key of the property to get from {@link properties}\n * @returns If found, the value of the `[string, string]` tuple found in {@link properties}. Else, `undefined`.\n */\n protected static getAndForget(\n properties: CaseInsensitiveMap<string, string>,\n key: string,\n ): string | undefined {\n const v: string | undefined = properties.get(key);\n if (v !== undefined)\n properties.delete(key);\n return v;\n }\n\n // #endregion static\n // #endregion static\n\n // #region private\n private _msbuildProjectFullPath: string | undefined;\n private _artifactsPath: string | undefined;\n private _assemblyName: string | undefined;\n private _baseIntermediateOutputPath: string | undefined;\n private _baseOutputPath: string | undefined;\n private _description: string | undefined;\n private _intermediateOutputPath: string | undefined;\n private _outDir: string | undefined;\n private _outputPath: string | undefined;\n private _runtimeIdentifier: string | undefined;\n private _runtimeIdentifiers: string | undefined;\n private _targetFramework: string | undefined;\n private _targetFrameworks: string | undefined;\n private _useArtifactsOutput: string | undefined;\n private _version: string | undefined;\n private _versionPrefix: string | undefined;\n private _versionSuffix: string | undefined;\n // #endregion private\n\n constructor(\n msbuildProjectFullPath: string,\n properties: CaseInsensitiveMap<string, string>,\n ) {\n // runtime type checks\n strictEqual(\n typeof msbuildProjectFullPath,\n 'string',\n new TypeError(\n `msbuildProjectFullPath should be a string, not ${typeof msbuildProjectFullPath}!`,\n ),\n );\n strictEqual(\n properties instanceof CaseInsensitiveMap,\n true,\n `arg 'properties' should be instanceof ${CaseInsensitiveMap.name}`,\n );\n strictEqual(\n properties.keys().every((v): v is string => typeof v === 'string'),\n true,\n 'all keys in arg \\'properties\\' should be strings',\n );\n\n this._msbuildProjectFullPath = MPP.GetFullPath(msbuildProjectFullPath);\n this._assemblyName = MPP.getAndForget(properties, 'AssemblyName');\n this._artifactsPath = MPP.getAndForget(properties, 'ArtifactsPath');\n this._description = MPP.getAndForget(properties, 'Description');\n this._outputPath = MPP.getAndForget(properties, 'OutputPath');\n this._runtimeIdentifier = MPP.getAndForget(properties, 'RuntimeIdentifier');\n this._runtimeIdentifiers = MPP.getAndForget(\n properties,\n 'RuntimeIdentifiers',\n );\n this._targetFramework = MPP.getAndForget(properties, 'TargetFramework');\n this._targetFrameworks = MPP.getAndForget(properties, 'TargetFrameworks');\n this._useArtifactsOutput = MPP.getAndForget(properties, 'UseArtifactsOutput');\n this._version = MPP.getAndForget(properties, 'Version');\n this._versionPrefix = MPP.getAndForget(properties, 'VersionPrefix');\n this._versionSuffix = MPP.getAndForget(properties, 'VersionSuffix');\n // rest\n for (const key of properties.keys()) {\n const value = MPP.getAndForget(properties, key);\n if (value !== undefined) {\n Object.defineProperty(this, key, {\n value: value,\n writable: false,\n enumerable: true,\n configurable: true,\n });\n }\n }\n }\n\n get MSBuildProjectFullPath(): string {\n return this._msbuildProjectFullPath ??= '';\n }\n\n /**\n * @returns If set, enables {@link UseArtifactsOutput} and overrides the\n * default artifacts output path.\n */\n get ArtifactsPath(): string {\n return this._artifactsPath ??= '';\n }\n\n /**\n * @returns The name of the assembly.\n *\n * Default: {@link https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-reserved-and-well-known-properties#:~:text=MSBuildProjectDirectory,-Reserved MSBuildProjectDirectory}\n */\n get AssemblyName(): string {\n return this._assemblyName ??= '';\n }\n\n /**\n * @returns The top-level folder where all configuration-specific intermediate output\n * folders are created. The default value is `obj\\`.\n * @example\n * ```xml\n * <BaseIntermediateOutputPath>c:\\xyz\\obj\\</BaseIntermediateOutputPath>\n * ```\n */\n get BaseIntermediateOutputPath(): string {\n return this._baseIntermediateOutputPath ??= '';\n }\n\n /**\n * @returns The base path for the output file.\n * If it's set, MSBuild uses `OutputPath = $(BaseOutputPath)\\$(Configuration)\\`.\n * @example ```xml\n * <BaseOutputPath>c:\\xyz\\bin\\</BaseOutputPath>\n * ```\n */\n get BaseOutputPath(): string {\n return this._baseOutputPath ??= '';\n }\n\n /**\n * A long description for the assembly.\n * If {@link NugetProperties.PackageDescription} is not specified, then this property is also used as the description of the package.\n * @returns The value of the `Description` property.\n */\n get Description(): string {\n return this._description ??= '';\n }\n\n /**\n * @returns The full intermediate output path as derived from\n * {@link BaseIntermediateOutputPath}, if no path is specified.\n * @example \"obj\\\\debug\\\\\"\n * @deprecated Typo; Use {@link IntermediateOutputPath}\n */\n get IntermediateOutput(): string {\n return this._intermediateOutputPath ??= '';\n }\n\n /**\n * @returns The full intermediate output path as derived from\n * {@link BaseIntermediateOutputPath}, if no path is specified.\n * @example \"obj\\\\debug\\\\\"\n */\n get IntermediateOutputPath(): string {\n return this._intermediateOutputPath ??= '';\n }\n\n /**\n * @returns The final output location for the project or solution.\n * When you build a solution, OutDir can be used to gather multiple project outputs in one location.\n * In addition, OutDir is included in AssemblySearchPaths used for resolving references.\n * @example\n * `bin/Debug`\n */\n get OutDir(): string {\n return this._outDir ??= '';\n }\n\n /**\n * @returns The path to the output directory, relative to the project\n * directory.\n * @example\n * `bin/Debug`\n * /// non-AnyCPU builds\n * `bin/Debug/${Platform}`\n */\n get OutputPath(): string {\n return this._outputPath ??= '';\n }\n\n /**\n * Set Version -OR- VersionPrefix.\n * @returns The value of the `Version` property.\n *\n * Default: `\"1.0.0\"`\n */\n get Version(): string {\n return this._version ??= '1.0.0';\n }\n\n /**\n * Set Version -OR- VersionPrefix.\\\n * Setting {@link NugetProperties.PackageVersion} overwrites {@link VersionPrefix}\n * @returns The MAJOR.MINOR.PATCH string of the version.\n * @see {@link VersionSuffix}\n */\n get VersionPrefix(): string {\n return this._versionPrefix ??= '';\n }\n\n /**\n * The effect of this property on the package version depends on the values of the Version and VersionPrefix properties, as shown in the following table:\n * | Properties with values | Package version |\n * | ---------------------- | --------------- |\n * | None | 1.0.0 |\n * | Version | $(Version) |\n * | VersionPrefix only | $(VersionPrefix) |\n * | VersionSuffix only | 1.0.0-$(VersionSuffix) |\n * | VersionPrefix and VersionSuffix | $(VersionPrefix)-$(VersionSuffix) |\n * \\\n * Setting {@link PackageVersion} overwrites {@link VersionSuffix}\n * @returns The string appended to the end of the MAJOR.MINOR.PATCH semver string (i.e. {@link VersionPrefix})\n */\n get VersionSuffix(): string {\n return this._versionSuffix ??= '';\n }\n\n /**\n * @returns The {@link https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#targetframework Target Framework}\n * @see\n * https://learn.microsoft.com/en-us/nuget/reference/target-frameworks#supported-frameworks\n * https://learn.microsoft.com/en-us/dotnet/standard/frameworks\n */\n get TargetFramework(): string {\n return this._targetFramework ??= '';\n }\n\n /**\n * @returns The {@link https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#targetframeworks Target Frameworks} (plural)\n * @see\n * https://learn.microsoft.com/en-us/nuget/reference/target-frameworks#supported-frameworks\n * https://learn.microsoft.com/en-us/dotnet/standard/frameworks\n */\n get TargetFrameworks(): string {\n return this._targetFrameworks ??= '';\n }\n\n /**\n * @returns When `\"true\"`; obj, bin, publish, and package output paths are\n * nested under a single directory.\n *\n * You can use {@link ArtifactsPath} to set the artifacts path and implicitly\n * enable this property.\n *\n * Default: \"$(MSBuildThisFileDirectory)artifacts\"\n */\n get UseArtifactsOutput(): string {\n return this._useArtifactsOutput ??= '';\n }\n\n /**\n * @returns\n * > The {@link https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#runtimeidentifier `Runtime Identifier`} property lets you specify a single runtime\n * > identifier (RID) for the project. The RID enables publishing a\n * > self-contained deployment.\n * @see\n * https://learn.microsoft.com/en-us/dotnet/core/rid-catalog\n */\n get RuntimeIdentifier(): string {\n return this._runtimeIdentifier ??= '';\n }\n\n /**\n * @returns\n * > The {@link https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#runtimeidentifiers `RuntimeIdentifiers`} property lets you specify a\n * > semicolon-delimited list of runtime identifiers (RIDs) for the project.\n * > Use this property if you need to publish for multiple runtimes.\n * > `RuntimeIdentifiers` is used at restore time to ensure the right assets\n * > are in the graph.\n * @see\n * https://learn.microsoft.com/en-us/dotnet/core/rid-catalog\n */\n get RuntimeIdentifiers(): string {\n return this._runtimeIdentifiers ??= '';\n }\n}\n\nconst MPP = MSBuildProjectProperties;\nexport type Class_MSBPP = ClassLike<BaseClass<typeof MSBuildProjectProperties & {\n // @ts-expect-error Property 'getAndForget' is protected and only accessible within class 'MSBuildProjectProperties' and its subclasses. ts(2445)\n getAndForget: ProtectedMember<typeof MSBuildProjectProperties.getAndForget>;\n}>>;\n\ntype ProtectedMember<T> = T;\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,IAAa,2BAAb,MAAsC;;;;;;;CASpC,OAAO,YAAY,MAAsB;EACvC,IAAI,CAAC,UAAU,WAAW,IAAI,GAC5B,OAAO,UAAU,QAAQ,IAAI;EAC/B,IAAI,CAAC,WAAW,IAAI,GAClB,MAAM,IAAI,MAAM,GAAG,UAAU,SAAS,IAAI,EAAE,0BAA0B,KAAK,EAAE;EAC/E,OAAO;CACT;;;;;;;;;;CAWA,OAAiB,aACf,YACA,KACoB;EACpB,MAAM,IAAwB,WAAW,IAAI,GAAG;EAChD,IAAI,MAAM,KAAA,GACR,WAAW,OAAO,GAAG;EACvB,OAAO;CACT;CAMA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA,YACE,wBACA,YACA;EAEA,YACE,OAAO,wBACP,0BACA,IAAI,UACF,kDAAkD,OAAO,uBAAuB,EAClF,CACF;EACA,YACE,sBAAsB,oBACtB,MACA,yCAAyC,mBAAmB,MAC9D;EACA,YACE,WAAW,KAAK,CAAC,C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