dotnet-solution
Version:
dotnet solution file model
99 lines (78 loc) • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
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 _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
function Solution() {
var _this = this;
if (!this instanceof Solution) {
return new Solution();
}
var children = [];
var configurations = ['Debug|Any CPU', 'Release|Any CPU'];
var scrubType = function scrubType(child) {
var type = child.type,
scrubbed = _objectWithoutProperties(child, ['type']);
return scrubbed;
};
var addChild = function addChild(item, type) {
return children.push(Object.assign({}, item, { type: type }));
};
var removeChild = function removeChild(idOrName, type) {
var index = children.findIndex(function (child) {
return child.type === type && (child.id === idOrName || child.name === idOrName);
});
if (index >= 0) {
children.splice(index, 1);
}
};
this.addFolder = function (folder) {
return addChild(folder, _childTypes2.default.folder);
};
this.addProject = function (project) {
return addChild(project, _childTypes2.default.project);
};
this.addConfiguration = function (config) {
return configurations.push(config);
};
this.getFolders = function () {
return _this.getChildren(_childTypes2.default.folder).map(scrubType);
};
this.getProjects = function () {
return _this.getChildren(_childTypes2.default.project).map(scrubType);
};
this.getConfigurations = function () {
return configurations;
};
this.removeFolder = function (idOrName) {
return removeChild(idOrName, _childTypes2.default.folder);
};
this.removeProject = function (idOrName) {
return removeChild(idOrName, _childTypes2.default.project);
};
this.removeConfiguration = function (config) {
var index = configurations.indexOf(config);
if (index >= 0) {
configurations.splice(index, 1);
}
};
this.getChildren = function (childType) {
var reducer = function reducer(o, child) {
var _Object$assign;
return Object.assign(o, (_Object$assign = {}, _defineProperty(_Object$assign, child.id, child.name), _defineProperty(_Object$assign, child.name, child.name), _Object$assign));
};
var nameOf = children.reduce(reducer, {});
return children.filter(function (child) {
return !childType || child.type === childType;
}).map(function (project) {
return Object.assign({}, project, {
parent: nameOf[project.parent]
});
});
};
}
exports.default = Solution;