@storm-software/workspace-tools
Version:
Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.
38 lines (35 loc) • 915 B
JavaScript
import {
writeError
} from "./chunk-MMA4S6LZ.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;
}
export {
parseCargoTomlWithTree,
parseCargoToml,
stringifyCargoToml
};