Skip to content

Commit f01e64f

Browse files
committed
chore(generate): parallelize example generation
Speeds it up by 4 seconds or so
1 parent fb2b2d9 commit f01e64f

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/generate.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,29 @@ export async function generateExamples(logger, state) {
115115

116116
logger.info(`Regenerating ${configs.length} examples...`);
117117

118-
for (const config of configs) {
119-
const cmd = config.exampleMetadata.generating;
120-
const parts = cmd.split(" ");
121-
if (parts[0] === "compas") {
122-
parts[0] = "../../node_modules/.bin/compas";
123-
}
124-
125-
if (state.flags.skipLint && !cmd.includes(" run ")) {
126-
parts.push("--skip-lint");
127-
}
128-
129-
const { exitCode, stdout } = await exec(parts.join(" "), {
130-
cwd: config.exampleMetadata.path,
131-
});
132-
133-
if (exitCode !== 0) {
134-
throw AppError.serverError({
135-
message: "One of the examples failed to generate",
136-
stdout,
137-
path: config.exampleMetadata.path,
118+
await Promise.all(
119+
configs.map(async (config) => {
120+
const cmd = config.exampleMetadata.generating;
121+
const parts = cmd.split(" ");
122+
if (parts[0] === "compas") {
123+
parts[0] = "../../node_modules/.bin/compas";
124+
}
125+
126+
if (state.flags.skipLint && !cmd.includes(" run ")) {
127+
parts.push("--skip-lint");
128+
}
129+
130+
const { exitCode, stdout } = await exec(parts.join(" "), {
131+
cwd: config.exampleMetadata.path,
138132
});
139-
}
140-
}
133+
134+
if (exitCode !== 0) {
135+
throw AppError.serverError({
136+
message: "One of the examples failed to generate",
137+
stdout,
138+
path: config.exampleMetadata.path,
139+
});
140+
}
141+
}),
142+
);
141143
}

0 commit comments

Comments
 (0)