UNPKG

@storm-software/workspace-tools

Version:

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

56 lines (53 loc) 1.61 kB
import { __name } from "./chunk-2BPV2XV2.mjs"; // src/utils/toml.ts import TOML from "@ltd/j-toml"; import { logger } from "@nx/devkit"; function parseCargoTomlWithTree(tree, projectRoot, projectName) { const cargoTomlString = tree.read(`${projectRoot}/Cargo.toml`)?.toString(); if (!cargoTomlString) { logger.error(`Cannot find a Cargo.toml file in the ${projectName}`); throw new Error(); } return parseCargoToml(cargoTomlString); } __name(parseCargoTomlWithTree, "parseCargoTomlWithTree"); function parseCargoToml(cargoString) { if (!cargoString) { throw new Error("Cargo.toml is empty"); } return TOML.parse(cargoString, { x: { comment: true } }); } __name(parseCargoToml, "parseCargoToml"); function stringifyCargoToml(cargoToml) { const tomlString = TOML.stringify(cargoToml, { newlineAround: "section" }); if (Array.isArray(tomlString)) { return tomlString.join("\n"); } return tomlString; } __name(stringifyCargoToml, "stringifyCargoToml"); 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; } __name(modifyCargoTable, "modifyCargoTable"); function modifyCargoNestedTable(toml, section, key, value) { toml[section] ??= {}; toml[section][key] = TOML.Section(value); } __name(modifyCargoNestedTable, "modifyCargoNestedTable"); export { parseCargoTomlWithTree, parseCargoToml, stringifyCargoToml, modifyCargoTable, modifyCargoNestedTable };