Skip to content

Commit

Permalink
Change signature of loadLocalGarden to return warnings.
Browse files Browse the repository at this point in the history
Part of #39.
  • Loading branch information
jkomoros committed Jul 8, 2023
1 parent 8e16e5c commit 7e57a16
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tools/garden/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const main = async (opts : CLIOptions) => {
if (opts.profile) {
overrides['profile'] = opts.profile;
}
const garden = await loadLocalGarden(overrides);
const [garden] = await loadLocalGarden(overrides);
const seedID = opts.seed || '';
const options = garden.optionsForID(seedID);
if (options.length == 0) {
Expand Down
8 changes: 5 additions & 3 deletions tools/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,19 @@ export const loadEnvironment = (overrides? : EnvironmentData) : EnvironmentData
});
};

export const loadLocalGarden = (overrides? : EnvironmentData) : Garden => {
export const loadLocalGarden = (overrides? : EnvironmentData) : [garden: Garden, warnings: Error[] | null] => {
const env = loadEnvironment(overrides);
const profile = new ProfileFilesystem();
const garden = new Garden(env, profile);
const warnings : Error[] = [];
for (const file of fs.readdirSync(SEEDS_DIRECTORY)) {
if (!file.endsWith('.json')) continue;
const filePath = path.join(SEEDS_DIRECTORY, file);
const data = fs.readFileSync(filePath).toString();
const json = JSON.parse(data);
//TODO: typecheck. Also, why does this pass typechecking?
garden.plantSeedPacket(filePath, json);
const localWarnings = garden.plantSeedPacket(filePath, json);
if (localWarnings) warnings.push(...localWarnings);
}
return garden;
return [garden, warnings.length ? warnings : null];
};

0 comments on commit 7e57a16

Please sign in to comment.