UNPKG

@storm-software/workspace-tools

Version:

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

43 lines (40 loc) 1.17 kB
import { writeError } from "./chunk-5AXTWPT3.mjs"; // ../config-tools/src/utilities/toml.ts import TOML from "@ltd/j-toml"; function parseCargoTomlWithTree(tree, projectRoot, projectName) { const cargoTomlString = tree.read(`${projectRoot}/Cargo.toml`)?.toString(); if (!cargoTomlString) { writeError(`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 TOML.parse(cargoString, { x: { comment: true } }); } function stringifyCargoToml(cargoToml) { const tomlString = TOML.stringify(cargoToml, { newlineAround: "section" }); if (Array.isArray(tomlString)) { return tomlString.join("\n"); } return tomlString; } function modifyCargoTable(toml, section, key, value) { toml[section] ??= TOML.Section({}); toml[section][key] = typeof value === "object" && !Array.isArray(value) ? TOML.inline(value) : typeof value === "function" ? value() : value; } export { parseCargoTomlWithTree, parseCargoToml, stringifyCargoToml, modifyCargoTable };