Skip to content

Commit 73dbb8f

Browse files
committed
feat(cli): add --parallel option to push + display timings
1 parent dc00a13 commit 73dbb8f

File tree

4 files changed

+316
-245
lines changed

4 files changed

+316
-245
lines changed

cli/conf.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface SyncOptions {
2222
excludes?: string[];
2323
defaultTs?: "bun" | "deno";
2424
codebases?: Codebase[];
25+
parallel?: number;
2526
}
2627

2728
export interface Codebase {

cli/script.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,12 @@ export async function handleFile(
193193
bundleContent = execSync(
194194
codebase.customBundler + " " + path
195195
).toString();
196-
log.info("Custom bundler executed");
196+
log.info("Custom bundler executed for " + path);
197197
} else {
198198
const esbuild = await import("npm:esbuild");
199199

200-
log.info(`Starting building the bundle for ${path}`);
200+
log.info(`Started bundling ${path} ...`);
201+
const startTime = performance.now();
201202
const out = await esbuild.build({
202203
entryPoints: [path],
203204
format: "cjs",
@@ -210,19 +211,20 @@ export async function handleFile(
210211
packages: "bundle",
211212
target: "node20.15.1",
212213
});
214+
const endTime = performance.now();
213215
bundleContent = out.outputFiles[0].text;
214216
log.info(
215-
"Bundle size: " + (bundleContent.length / 1024).toFixed(0) + "kB"
217+
`Finished bundling ${path}: ${(bundleContent.length / 1024).toFixed(0)}kB (${(endTime - startTime).toFixed(0)}ms)`
216218
);
217219
}
218220
if (Array.isArray(codebase.assets) && codebase.assets.length > 0) {
219221
const archiveNpm = await import("npm:@ayonli/jsext/archive");
220-
221222
log.info(
222-
`Using the following asset configuration: ${JSON.stringify(
223+
`Using the following asset configuration for ${path}: ${JSON.stringify(
223224
codebase.assets
224225
)}`
225226
);
227+
const startTime = performance.now();
226228
const tarball = new archiveNpm.Tarball();
227229
tarball.append(
228230
new File([bundleContent], "main.js", { type: "text/plain" })
@@ -233,10 +235,10 @@ export async function handleFile(
233235
const file = new File([blob], asset.to);
234236
tarball.append(file);
235237
}
236-
log.info("Tarball size: " + (tarball.size / 1024).toFixed(0) + "kB");
238+
const endTime = performance.now();
239+
log.info(`Finished creating tarball for ${path}: ${(tarball.size / 1024).toFixed(0)}kB (${(endTime - startTime).toFixed(0)}ms)`);
237240
bundleContent = tarball;
238241
}
239-
log.info(`Finished building the bundle for ${path}`);
240242
}
241243
let typed =
242244
opts?.skipScriptsMetadata ? undefined :
@@ -364,24 +366,23 @@ export async function handleFile(
364366
}
365367
}
366368

367-
log.info(
368-
colors.yellow.bold(`Creating script with a parent ${remotePath}`)
369-
);
369+
370+
log.info(`Updating script ${remotePath} ...`);
370371
const body = {
371372
...requestBodyCommon,
372373
parent_hash: remote.hash,
373374
};
374-
await createScript(bundleContent, workspaceId, body, workspace);
375+
const execTime = await createScript(bundleContent, workspaceId, body, workspace);
376+
log.info(colors.yellow.bold(`Updated script ${remotePath} (${execTime.toFixed(0)}ms)`));
375377
} else {
376-
log.info(
377-
colors.yellow.bold(`Creating script without parent ${remotePath}`)
378-
);
379-
378+
log.info(`Creating new script ${remotePath} ...`);
380379
const body = {
381380
...requestBodyCommon,
382381
parent_hash: undefined,
383382
};
384-
await createScript(bundleContent, workspaceId, body, workspace);
383+
const execTime = await createScript(bundleContent, workspaceId, body, workspace);
384+
log.info(colors.yellow.bold(`Created new script ${remotePath} (${execTime.toFixed(0)}ms)`));
385+
385386
}
386387
return true;
387388
}
@@ -416,7 +417,8 @@ async function createScript(
416417
workspaceId: string,
417418
body: NewScript,
418419
workspace: Workspace
419-
) {
420+
): Promise<number> {
421+
const start = performance.now();
420422
if (!bundleContent) {
421423
try {
422424
// no parent hash
@@ -427,7 +429,7 @@ async function createScript(
427429
} catch (e: any) {
428430
throw Error(
429431
`Script creation for ${body.path} with parent ${body.parent_hash
430-
} was not successful: ${e.body ?? e.message}`
432+
} was not successful: ${e.body ?? e.message} `
431433
);
432434
}
433435
} else {
@@ -447,16 +449,17 @@ async function createScript(
447449
"/scripts/create_snapshot";
448450
const req = await fetch(url, {
449451
method: "POST",
450-
headers: { Authorization: `Bearer ${workspace.token}` },
452+
headers: { Authorization: `Bearer ${workspace.token} ` },
451453
body: form,
452454
});
453455
if (req.status != 201) {
454456
throw Error(
455457
`Script snapshot creation was not successful: ${req.status} - ${req.statusText
456-
} - ${await req.text()}`
458+
} - ${await req.text()} `
457459
);
458460
}
459461
}
462+
return performance.now() - start;
460463
}
461464

462465
export async function findContentFile(filePath: string) {
@@ -868,7 +871,7 @@ async function generateMetadata(
868871
} & SyncOptions,
869872
scriptPath: string | undefined
870873
) {
871-
log.info("This command only works for workspace scripts, for flows inline scripts use `wmill flow generate-locks`");
874+
log.info("This command only works for workspace scripts, for flows inline scripts use `wmill flow generate - locks`");
872875
if (scriptPath == "") {
873876
scriptPath = undefined;
874877
}
@@ -924,7 +927,7 @@ async function generateMetadata(
924927
);
925928
if (candidate) {
926929
hasAny = true;
927-
log.info(colors.green(`+ ${candidate}`));
930+
log.info(colors.green(`+ ${candidate} `));
928931
}
929932
}
930933
if (hasAny) {
@@ -987,7 +990,7 @@ const command = new Command()
987990
.action(bootstrap as any)
988991
.command(
989992
"generate-metadata",
990-
"re-generate the metadata file updating the lock and the script schema (for flows, use `wmill flow generate-locks`)"
993+
"re-generate the metadata file updating the lock and the script schema (for flows, use `wmill flow generate - locks`)"
991994
)
992995
.arguments("[script:file]")
993996
.option("--yes", "Skip confirmation prompt")

0 commit comments

Comments
 (0)