UNPKG

dotnet-solution

Version:
116 lines (93 loc) 4.43 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _childTypes = require('./childTypes'); var _childTypes2 = _interopRequireDefault(_childTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var SolutionWriter = function () { function SolutionWriter() { _classCallCheck(this, SolutionWriter); } _createClass(SolutionWriter, [{ key: 'write', value: function write(solution) { var lines = []; var append = function append(line) { return lines.push(line); }; append('Microsoft Visual Studio Solution File, Format Version 12.00'); append('# Visual Studio 14'); append('VisualStudioVersion = 14.0.25420.1'); append('MinimumVisualStudioVersion = 10.0.40219.1'); this.appendChildren(append, solution); append('Global'); this.appendConfigurations(append, solution); this.appendPlatforms(append, solution); this.appendProperties(append, solution); this.appendNesting(append, solution); append('EndGlobal'); append(''); return lines; } }, { key: 'appendChildren', value: function appendChildren(append, solution) { solution.getChildren().forEach(function (x) { append('Project("{' + x.type + '}") = "' + x.name + '", "' + x.path + '", "{' + x.id + '}"'); append('EndProject'); }); } }, { key: 'appendConfigurations', value: function appendConfigurations(append, solution) { append(' GlobalSection(SolutionConfigurationPlatforms) = preSolution'); solution.getConfigurations().forEach(function (config) { return append('\t\t' + config + ' = ' + config); }); append(' EndGlobalSection'); } }, { key: 'appendProperties', value: function appendProperties(append, solution) { append(' GlobalSection(SolutionProperties) = preSolution'); append(' HideSolutionNode = FALSE'); append(' EndGlobalSection'); } }, { key: 'appendPlatforms', value: function appendPlatforms(append, solution) { append('\tGlobalSection(ProjectConfigurationPlatforms) = postSolution'); solution.getChildren().filter(function (child) { return child.type === _childTypes2.default.project; }).forEach(function (project) { solution.getConfigurations().forEach(function (config) { append('\t\t{' + project.id + '}.' + config + '.ActiveCfg = ' + config); append('\t\t{' + project.id + '}.' + config + '.Build.0 = ' + config); }); }); append(' EndGlobalSection'); } }, { key: 'appendNesting', value: function appendNesting(append, solution) { append(' GlobalSection(NestedProjects) = preSolution'); var reducer = function reducer(result, child) { var _Object$assign; return Object.assign(result, (_Object$assign = {}, _defineProperty(_Object$assign, child.id, child.id), _defineProperty(_Object$assign, child.name, child.id), _Object$assign)); }; var relationships = solution.getChildren().reduce(reducer, {}); solution.getChildren().filter(function (child) { return child.parent && relationships[child.parent]; }).forEach(function (child) { append('\t\t{' + child.id + '} = {' + relationships[child.parent] + '}'); }); append(' EndGlobalSection'); } }]); return SolutionWriter; }(); exports.default = SolutionWriter;