UNPKG

gulp-msbuild

Version:

msbuild plugin for gulp. Inspired by grunt-msbuild.

104 lines (103 loc) 4.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MSBuildCommandBuilder = void 0; const lodash_1 = require("lodash"); const msbuild_finder_1 = require("./msbuild-finder"); const path_1 = __importDefault(require("path")); class MSBuildCommandBuilder { constructor() { } buildArguments(options) { var _a; let args = []; args.push("/target:" + ((_a = options.targets) !== null && _a !== void 0 ? _a : ["Rebuild"]).join(";")); args.push("/verbosity:" + options.verbosity); if (options.toolsVersion) { const versionNumber = parseFloat(options.toolsVersion); let version; if (isNaN(versionNumber)) { version = "4.0"; } else if (versionNumber > 15) { version = "Current"; } else { version = versionNumber.toFixed(1); } args.push("/toolsversion:" + version); } if (options.nologo) { args.push("/nologo"); } if (options.fileLoggerParameters) { args.push("/flp:" + options.fileLoggerParameters); } if (options.consoleLoggerParameters) { args.push("/clp:" + options.consoleLoggerParameters); } if (options.loggerParameters) { args.push("/logger:" + options.loggerParameters); } // xbuild does not support the `maxcpucount` argument and throws if provided if (options.maxcpucount != undefined && options.maxcpucount >= 0 && options.msbuildPath !== 'xbuild') { if (options.maxcpucount === 0) { args.push('/maxcpucount'); } else { args.push('/maxcpucount:' + options.maxcpucount); } } if (options.nodeReuse === false) { args.push('/nodeReuse:False'); } if (options.configuration) { options.properties = Object.assign({ Configuration: options.configuration }, options.properties); } if (options.solutionPlatform) { options.properties = Object.assign({ Platform: options.solutionPlatform }, options.properties); } if (options.emitPublishedFiles) { options.properties = Object.assign({ DeployOnBuild: "true", DeployDefaultTarget: options.deployDefaultTarget, WebPublishMethod: options.webPublishMethod, DeleteExistingFiles: options.deleteExistingFiles, _FindDependencies: options.findDependencies, PublishUrl: options.publishDirectory }, options.properties); } for (let property in options.properties) { args.push('/property:' + property + '=' + options.properties[property]); } if (options.customArgs) { args = args.concat(options.customArgs); } return args; } construct(file, options) { var _a, _b; if (!options || Object.keys(options).length <= 0) { throw new Error(`No options specified in MSBuildOptions`); } if (!options.msbuildPath) { const msbuildFinder = new msbuild_finder_1.MSBuildFinder(options); const version = msbuildFinder.findVersion(); if (version != null) { if (version[0] != null) { options.msbuildPath = (_a = version[0]) !== null && _a !== void 0 ? _a : ''; options.toolsVersion = (_b = version[1]) !== null && _b !== void 0 ? _b : '4.0'; } else throw new Error(`Invalid version`); } else throw new Error(`Invalid version`); } const newOptions = (0, lodash_1.cloneDeep)(options); Object.keys(newOptions.properties).forEach(function (prop) { const context = { file: file }; newOptions.properties[prop] = (0, lodash_1.template)(newOptions.properties[prop])(context); }); const args = this.buildArguments(newOptions); return { executable: path_1.default.normalize(options.msbuildPath), args: [file.path].concat(args) }; } } exports.MSBuildCommandBuilder = MSBuildCommandBuilder;