Skip to content

Commit 790f08c

Browse files
fix error in ci
1 parent 233999e commit 790f08c

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codesandbox/sdk",
3-
"version": "2.0.0-rc.11-debug.2",
3+
"version": "2.0.0",
44
"description": "The CodeSandbox SDK",
55
"author": "CodeSandbox",
66
"license": "MIT",

src/bin/commands/build.ts

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -329,47 +329,58 @@ export const buildCommand: yargs.CommandModule<
329329
}
330330
});
331331

332-
const results = await Promise.allSettled(tasks);
333-
334-
const failedSandboxes = templateData.sandboxes.filter(
335-
(_, index) => results[index].status === "rejected"
336-
);
337-
338-
if (!argv.ci && failedSandboxes.length > 0) {
339-
spinner.start(`\n${spinnerMessages.join("\n")}`);
332+
if (argv.ci) {
333+
try {
334+
await Promise.all(tasks);
335+
} catch {
336+
spinner.fail(`\n${spinnerMessages.join("\n")}`);
337+
process.exit(1);
338+
}
339+
} else {
340+
const results = await Promise.allSettled(tasks);
340341

341-
await waitForEnter(
342-
`\nThere was an issue preparing the sandboxes. Verify ${failedSandboxes
343-
.map((sandbox) => sandbox.id)
344-
.join(", ")} and press ENTER to create snapshot...\n`
342+
const failedSandboxes = templateData.sandboxes.filter(
343+
(_, index) => results[index].status === "rejected"
345344
);
346345

347-
failedSandboxes.forEach(({ id }) => {
348-
updateSpinnerMessage(
349-
templateData.sandboxes.findIndex((sandbox) => sandbox.id === id),
350-
"Creating snapshot..."
346+
if (failedSandboxes.length > 0) {
347+
spinner.start(
348+
`\n${spinnerMessages.join(
349+
"\n"
350+
)}\n\nThere was an issue preparing the sandboxes. Verify ${failedSandboxes
351+
.map((sandbox) => sandbox.id)
352+
.join(", ")} and press ENTER to create snapshot...\n`
351353
);
352-
});
353354

354-
spinner.start(`\n${spinnerMessages.join("\n")}`);
355+
await waitForEnter();
355356

356-
await Promise.all(
357-
failedSandboxes.map(async ({ id }) => {
358-
await sdk.sandboxes.hibernate(id);
359-
360-
spinner.start(
361-
updateSpinnerMessage(
362-
templateData.sandboxes.findIndex(
363-
(sandbox) => sandbox.id === id
364-
),
365-
"Snapshot created"
366-
)
357+
failedSandboxes.forEach(({ id }) => {
358+
updateSpinnerMessage(
359+
templateData.sandboxes.findIndex((sandbox) => sandbox.id === id),
360+
"Creating snapshot..."
367361
);
368-
})
369-
);
370-
spinner.succeed(`\n${spinnerMessages.join("\n")}`);
371-
} else {
372-
spinner.succeed(`\n${spinnerMessages.join("\n")}`);
362+
});
363+
364+
spinner.start(`\n${spinnerMessages.join("\n")}`);
365+
366+
await Promise.all(
367+
failedSandboxes.map(async ({ id }) => {
368+
await sdk.sandboxes.hibernate(id);
369+
370+
spinner.start(
371+
updateSpinnerMessage(
372+
templateData.sandboxes.findIndex(
373+
(sandbox) => sandbox.id === id
374+
),
375+
"Snapshot created"
376+
)
377+
);
378+
})
379+
);
380+
spinner.succeed(`\n${spinnerMessages.join("\n")}`);
381+
} else {
382+
spinner.succeed(`\n${spinnerMessages.join("\n")}`);
383+
}
373384
}
374385

375386
if (alias) {
@@ -392,10 +403,6 @@ export const buildCommand: yargs.CommandModule<
392403

393404
console.log("Template created: " + templateData.tag);
394405

395-
if (argv.ci && failedSandboxes.length > 0) {
396-
process.exit(1);
397-
}
398-
399406
process.exit(0);
400407
} catch (error) {
401408
console.error(error);
@@ -410,14 +417,14 @@ function withCustomError<T extends Promise<any>>(promise: T, message: string) {
410417
});
411418
}
412419

413-
function waitForEnter(message: string) {
420+
function waitForEnter() {
414421
const rl = readline.createInterface({
415422
input: process.stdin,
416423
output: process.stdout,
417424
});
418425

419426
return new Promise<void>((resolve) => {
420-
rl.question(message, () => {
427+
rl.question("", () => {
421428
rl.close();
422429
resolve();
423430
});

0 commit comments

Comments
 (0)