Skip to content

Commit aa50cc5

Browse files
kt3ksatyarohith
authored andcommitted
feat(deploy): add --dry-run option
1 parent 0facdda commit aa50cc5

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

deployctl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const args = parseArgs(Deno.args, {
4040
"prod",
4141
"static",
4242
"version",
43+
"dry-run",
4344
],
4445
string: [
4546
"project",

src/subcommands/deploy.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ OPTIONS:
3434
--prod Create a production deployment (default is preview deployment)
3535
-p, --project=NAME The project to deploy to
3636
--token=TOKEN The API token to use (defaults to DENO_DEPLOY_TOKEN env var)
37+
--dry-run Dry run the deployment process.
3738
`;
3839

3940
export interface Args {
@@ -45,6 +46,7 @@ export interface Args {
4546
token: string | null;
4647
project: string | null;
4748
importMap: string | null;
49+
dryRun: boolean;
4850
}
4951

5052
// deno-lint-ignore no-explicit-any
@@ -58,6 +60,7 @@ export default async function (rawArgs: Record<string, any>): Promise<void> {
5860
importMap: rawArgs["import-map"] ? String(rawArgs["import-map"]) : null,
5961
exclude: rawArgs.exclude?.split(","),
6062
include: rawArgs.include?.split(","),
63+
dryRun: !!rawArgs["dry-run"],
6164
};
6265
const entrypoint: string | null = typeof rawArgs._[0] === "string"
6366
? rawArgs._[0]
@@ -96,6 +99,7 @@ export default async function (rawArgs: Record<string, any>): Promise<void> {
9699
project: args.project,
97100
include: args.include?.map((pattern) => normalize(pattern)),
98101
exclude: args.exclude?.map((pattern) => normalize(pattern)),
102+
dryRun: args.dryRun,
99103
};
100104

101105
await deploy(opts);
@@ -110,9 +114,13 @@ interface DeployOpts {
110114
include?: string[];
111115
token: string;
112116
project: string;
117+
dryRun: boolean;
113118
}
114119

115120
async function deploy(opts: DeployOpts): Promise<void> {
121+
if (opts.dryRun) {
122+
wait("").start().info("Performing dry run of deployment");
123+
}
116124
const projectSpinner = wait("Fetching project information...").start();
117125
const api = API.fromToken(opts.token);
118126
const project = await api.getProject(opts.project);
@@ -148,11 +156,7 @@ async function deploy(opts: DeployOpts): Promise<void> {
148156
undefined;
149157

150158
if (opts.static) {
151-
console.log(
152-
` %cℹ %cUploading all files from the current dir (${cwd})`,
153-
"color: yellow",
154-
"color: inherit",
155-
);
159+
wait("").start().info(`Uploading all files from the current dir (${cwd})`);
156160
const assetSpinner = wait("Finding static assets...").start();
157161
const assets = new Map<string, string>();
158162
const entries = await walk(cwd, cwd, assets, {
@@ -180,14 +184,19 @@ async function deploy(opts: DeployOpts): Promise<void> {
180184
uploadSpinner.succeed("No new assets to upload.");
181185
uploadSpinner = null;
182186
} else {
183-
uploadSpinner.text = `Uploading ${files.length} asset${
187+
uploadSpinner.text = `${files.length} asset${
184188
files.length === 1 ? "" : "s"
185-
}... (0%)`;
189+
} to upload.`;
186190
}
187191

188192
manifest = { entries };
189193
}
190194

195+
if (opts.dryRun) {
196+
uploadSpinner?.succeed(uploadSpinner?.text);
197+
return;
198+
}
199+
191200
let deploySpinner: Spinner | null = null;
192201
const req = {
193202
url: url.href,

0 commit comments

Comments
 (0)