@halospv3/hce.shared-config
Version:
Automate commit message quality, changelogs, and CI/CD releases. Exports a semantic-release shareable configuration deserialized from this package's '.releaserc.yml'. Shared resources for .NET projects are also distributed with this package.
85 lines (79 loc) • 4.38 kB
JavaScript
;
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
const node_child_process = require('node:child_process');
const MSBuildProjectProperties = require('./MSBuildProjectProperties.cjs');
/**
* All pre-defined properties of {@link MSBuildProjectProperties} except FullPath
*/
const MSBuildProjectPreDefinedProperties = Object.keys(new MSBuildProjectProperties.MSBuildProjectProperties('', false)).filter(p => p !== 'FullPath');
/** @todo Experimental and may be removed in a later release.
* A cache for your evaluated MSBuild Projects.
*/
const MSBuildEvaluatedProjects = [];
class MSBuildProject {
Properties;
/**
*
* @param fullPath The full path of the .NET MSBuild project file.
* @param customProperties MSBuild properties to evaluate in addition to those pre-defined in {@link MSBuildProjectProperties}
*/
constructor(fullPath, customProperties) {
// super();
this.Properties = MSBuildProject.evaluateProperties(fullPath, customProperties ?? []);
}
/**
*
* `dotnet msbuild src -getProperty:TargetFramework -getProperty:TargetFrameworks -getProperty:RuntimeIdentifiers -getProperty:IsTrimmable`
*
* ...produces...
*
* ```json
* {
* "Properties": {
* "TargetFramework": "net6.0",
* "TargetFrameworks": "",
* "RuntimeIdentifiers": "win7-x64;win7-x86;win-arm64;linux-x64;linux-arm64",
* "IsTrimmable": "true",
* }
* }
* ```
*
* ...which can can be parsed like...
* ```js
* var ridArray = JSON.parse(out).Properties.RuntimeIdentifiers.split(';');
* ```
*/
static evaluateProperties(fullPath, properties) {
const evaluatedProps = new MSBuildProjectProperties.MSBuildProjectProperties(fullPath);
// if a default prop isn't in properties, add it
const defaultProps = MSBuildProjectPreDefinedProperties;
for (const defaultProp of defaultProps) {
if (!properties.includes(defaultProp)) properties.push(defaultProp);
}
const getPropArgs = properties.map(propName => `-getProperty:${propName}`);
// should return a single value OR string-encoded JSON object with 'Properties' object-type property.
const out = node_child_process.execFileSync('dotnet', ['msbuild', evaluatedProps.FullPath, ...getPropArgs], {
encoding: 'utf8',
stdio: 'pipe'
}).trim();
if (out.startsWith('MSBUILD : error')) throw new Error(out);
let props;
if (out.startsWith('{')) {
const obj = JSON.parse(out);
if ("Properties" in obj && typeof obj.Properties === 'object' && obj.Properties !== null) props = obj.Properties;else throw new Error('When evaluating properties with MSBuild, "Properties" could not be found in the deserialized JSON object...\n' + JSON.stringify(obj));
} else {
props = {
[properties[0]]: out.trim()
};
}
return _objectSpread(_objectSpread({}, evaluatedProps), props);
}
}
exports.MSBuildEvaluatedProjects = MSBuildEvaluatedProjects;
exports.MSBuildProject = MSBuildProject;
exports.MSBuildProjectPreDefinedProperties = MSBuildProjectPreDefinedProperties;
//# sourceMappingURL=MSBuildProject.cjs.map