Skip to content

Commit

Permalink
add commit message to deployment without git
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Aug 16, 2023
1 parent e9c832c commit a5e1aea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
27 changes: 21 additions & 6 deletions packages/create-cloudflare/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import {
import { inputPrompt, processArgument, spinner } from "helpers/interactive";
import { detectPackageManager } from "helpers/packages";
import { poll } from "helpers/poll";
import { version as wranglerVersion } from "wrangler/package.json";
import { version } from "../package.json";
import { C3_DEFAULTS } from "./cli";
import type { C3Args, PagesGeneratorContext } from "types";
import { version as wranglerVersion } from "wrangler/package.json";

const { npm } = detectPackageManager();

Expand Down Expand Up @@ -90,15 +90,28 @@ export const runDeploy = async (ctx: PagesGeneratorContext) => {
return;
}

const deployCmd = `${npm} run ${
ctx.framework?.config.deployCommand ?? "deploy"
}`;
const baseDeployCmd = [
npm,
"run",
ctx.framework?.config.deployCommand ?? "deploy",
];

const insideGitRepo = await isInsideGitRepo(ctx.project.path);

const deployCmd = [
...baseDeployCmd,
// Important: the following assumes that all framework deploy commands terminate with `wrangler pages deploy`
ctx.framework?.commitMessage && !insideGitRepo
? `--commit-message="${ctx.framework.commitMessage}"`
: "",
];

const result = await runCommand(deployCmd, {
silent: true,
cwd: ctx.project.path,
env: { CLOUDFLARE_ACCOUNT_ID: ctx.account.id, NODE_ENV: "production" },
startText: `Deploying your application`,
doneText: `${brandColor("deployed")} ${dim(`via \`${deployCmd}\``)}`,
doneText: `${brandColor("deployed")} ${dim(`via \`${baseDeployCmd}\``)}`,
});

const deployedUrlRegex = /https:\/\/.+\.(pages|workers)\.dev/;
Expand Down Expand Up @@ -300,7 +313,9 @@ const createCommitMessage = async (ctx: PagesGeneratorContext) => {
.map(({ key, value }) => ` ${key} = ${value}`)
.join("\n")}\n`;

return `${header}\n\n${body}\n`;
ctx.framework.commitMessage = `${header}\n\n${body}\n`;

return ctx.framework.commitMessage;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/helpers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const runCommand = async (
opts: RunOptions = {}
): Promise<string> => {
if (typeof command === "string") {
command = command.trim().replace(/\s+/g, ` `).split(" ");
command = command.trim().replace(/\s+/g, " ").split(" ");
}

return printAsyncStatus({
Expand Down
1 change: 1 addition & 0 deletions packages/create-cloudflare/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type PagesGeneratorContext = {
framework?: {
name: string;
config: FrameworkConfig;
commitMessage?: string;
};
project: {
name: string;
Expand Down

0 comments on commit a5e1aea

Please sign in to comment.