Skip to content

Commit 1e5405e

Browse files
committed
fix(mcl/json): Add writeJsonFile function that ensures that parent dirs are created as needed
1 parent 0496211 commit 1e5405e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/mcl/src/src/mcl/commands/deploy_spec.d

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ module mcl.commands.deploy_spec;
22

33
import std.algorithm : filter;
44
import std.logger : infof, warningf;
5-
import std.file : exists, readText;
5+
import std.file : exists;
66
import std.path : buildPath;
7-
import std.file : writeFile = write;
8-
import std.json : parseJSON, JSONOptions;
97

108
import mcl.utils.process : spawnProcessInline;
119
import mcl.utils.path : resultDir;
12-
import mcl.utils.env : parseEnv;
1310
import mcl.utils.cachix : cachixNixStoreUrl, DeploySpec, createMachineDeploySpec;
1411
import mcl.utils.tui : bold;
15-
import mcl.utils.json : toJSON, fromJSON, tryDeserializeFromJsonFile;
12+
import mcl.utils.json : tryDeserializeFromJsonFile, writeJsonFile;
1613

17-
import mcl.commands.ci_matrix : flakeAttr, params, Params, nixEvalJobs, SupportedSystem;
14+
import mcl.commands.ci_matrix : flakeAttr, params, nixEvalJobs, SupportedSystem;
1815

1916
export void deploy_spec()
2017
{
@@ -42,7 +39,7 @@ export void deploy_spec()
4239
throw new Exception("Some Nixos configurations are not in cachix. Please cache them first.");
4340

4441
spec = nixosConfigs.createMachineDeploySpec();
45-
writeFile(deploySpecFile, spec.toJSON.toPrettyString(JSONOptions.doNotEscapeSlashes));
42+
writeJsonFile(spec, deploySpecFile);
4643
}
4744
else
4845
{

packages/mcl/src/src/mcl/utils/json.d

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,12 @@ T tryDeserializeFromJsonFile(T)(string path)
330330
.fromJSON!T()
331331
.tryGet("Error deserializing %s. JSON: \n%s".format(T.stringof.bold, json.toPrettyString().bold));
332332
}
333+
334+
void writeJsonFile(T)(in T value, const(char)[] path)
335+
{
336+
import std.path : dirName;
337+
import std.file : mkdirRecurse, writeFile = write;
338+
auto json = value.toJSON.toPrettyString(JSONOptions.doNotEscapeSlashes);
339+
mkdirRecurse(path.dirName);
340+
writeFile(path, json);
341+
}

0 commit comments

Comments
 (0)