Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug log site zip stats #49

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/cli/changelog/@unreleased/pr-49.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Debug log site zip stats
links:
- https://github.com/palantir/osdk-ts/pull/49
30 changes: 25 additions & 5 deletions packages/cli/src/commands/site/deploy/siteDeployCommand.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from "#net";
import archiver from "archiver";
import * as fs from "node:fs";
import path from "node:path";
import { Readable } from "node:stream";
import { ExitProcessError } from "../../../ExitProcessError.js";
import { autoVersion as findAutoVersion } from "../../../util/autoVersion.js";
Expand Down Expand Up @@ -64,15 +65,20 @@ export default async function siteDeployCommand(
);
}

consola.debug(`Using directory for site files: "${path.resolve(directory)}`);
const stat = await fs.promises.stat(directory);
if (!stat.isDirectory()) {
consola.error("Specified path is not a directory");
throw new ExitProcessError(2);
throw new ExitProcessError(
2,
"Specified path exists but is not a directory",
);
}

consola.start("Zippping site files");

consola.start("Zipping site files");
const archive = archiver("zip").directory(directory, false);
logArchiveStats(archive);

consola.start("Uploading site files");
const tokenProvider = () => loadedToken;
const clientCtx = createInternalClientContext(foundryUrl, tokenProvider);
await Promise.all([
Expand All @@ -86,7 +92,6 @@ export default async function siteDeployCommand(
),
archive.finalize(),
]);

consola.success("Upload complete");

if (!uploadOnly) {
Expand All @@ -109,3 +114,18 @@ export default async function siteDeployCommand(
consola.debug("Upload only mode enabled, skipping deployment");
}
}

function logArchiveStats(archive: archiver.Archiver): void {
let archiveStats = { fileCount: 0, bytes: 0 };
archive.on("progress", (progress) => {
archiveStats = {
fileCount: progress.entries.total,
bytes: progress.fs.totalBytes,
};
});
archive.on("finish", () => {
consola.debug(
`Zipped ${archiveStats.fileCount} files and ${archiveStats.bytes} bytes`,
);
});
}
Loading