UNPKG

@storm-software/workspace-tools

Version:

Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.

56 lines (46 loc) 2.8 kB
"use strict";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 _chunk3GQAWCBQjs = require('./chunk-3GQAWCBQ.js'); // src/utils/toml.ts var _jtoml = require('@ltd/j-toml'); var _jtoml2 = _interopRequireDefault(_jtoml); var _devkit = require('@nx/devkit'); 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) { _devkit.logger.error(`Cannot find a Cargo.toml file in the ${projectName}`); throw new Error(); } return parseCargoToml(cargoTomlString); } _chunk3GQAWCBQjs.__name.call(void 0, parseCargoTomlWithTree, "parseCargoTomlWithTree"); function parseCargoToml(cargoString) { if (!cargoString) { throw new Error("Cargo.toml is empty"); } return _jtoml2.default.parse(cargoString, { x: { comment: true } }); } _chunk3GQAWCBQjs.__name.call(void 0, parseCargoToml, "parseCargoToml"); function stringifyCargoToml(cargoToml) { const tomlString = _jtoml2.default.stringify(cargoToml, { newlineAround: "section" }); if (Array.isArray(tomlString)) { return tomlString.join("\n"); } return tomlString; } _chunk3GQAWCBQjs.__name.call(void 0, stringifyCargoToml, "stringifyCargoToml"); function modifyCargoTable(toml, section, key, value) { toml[section] ??= _jtoml2.default.Section({}); toml[section][key] = typeof value === "object" && !Array.isArray(value) ? _jtoml2.default.inline(value) : typeof value === "function" ? value() : value; } _chunk3GQAWCBQjs.__name.call(void 0, modifyCargoTable, "modifyCargoTable"); function modifyCargoNestedTable(toml, section, key, value) { toml[section] ??= {}; toml[section][key] = _jtoml2.default.Section(value); } _chunk3GQAWCBQjs.__name.call(void 0, modifyCargoNestedTable, "modifyCargoNestedTable"); exports.parseCargoTomlWithTree = parseCargoTomlWithTree; exports.parseCargoToml = parseCargoToml; exports.stringifyCargoToml = stringifyCargoToml; exports.modifyCargoTable = modifyCargoTable; exports.modifyCargoNestedTable = modifyCargoNestedTable;