@storm-software/workspace-tools
Version:
Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.
38 lines (30 loc) • 1.88 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkIHMF6RANjs = require('./chunk-IHMF6RAN.js');
// ../config-tools/src/utilities/toml.ts
var _jtoml = require('@ltd/j-toml'); var _jtoml2 = _interopRequireDefault(_jtoml);
function parseCargoTomlWithTree(tree, projectRoot, projectName) {
const cargoTomlString = _optionalChain([tree, 'access', _ => _.read, 'call', _2 => _2(`${projectRoot}/Cargo.toml`), 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
if (!cargoTomlString) {
_chunkIHMF6RANjs.writeError.call(void 0, `Cannot find a Cargo.toml file in the ${projectName}`);
throw new Error();
}
return parseCargoToml(cargoTomlString);
}
function parseCargoToml(cargoString) {
if (!cargoString) {
throw new Error("Cargo.toml is empty");
}
return _jtoml2.default.parse(cargoString, {
x: { comment: true }
});
}
function stringifyCargoToml(cargoToml) {
const tomlString = _jtoml2.default.stringify(cargoToml, {
newlineAround: "section"
});
if (Array.isArray(tomlString)) {
return tomlString.join("\n");
}
return tomlString;
}
exports.parseCargoTomlWithTree = parseCargoTomlWithTree; exports.parseCargoToml = parseCargoToml; exports.stringifyCargoToml = stringifyCargoToml;