UNPKG

@storm-software/config-tools

Version:

A package containing various utilities to support custom workspace configurations and environment management for Storm Software projects, including configuration file handling, environment variable management, and logging utilities.

48 lines (45 loc) 1.31 kB
import { writeError } from "./chunk-XHJNCOIU.js"; // 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; } function modifyCargoNestedTable(toml, section, key, value) { toml[section] ??= {}; toml[section][key] = TOML.Section(value); } export { parseCargoTomlWithTree, parseCargoToml, stringifyCargoToml, modifyCargoTable, modifyCargoNestedTable };