Skip to content

Commit

Permalink
c3 add final commit to pages projects
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Aug 15, 2023
1 parent 478bed3 commit bc35cd8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .changeset/nasty-dolphins-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"create-cloudflare": minor
---

add final commit when generating Pages projects

before after the user would have completed the creation of a Pages project
they would find the Cloudflare added/modified files uncommitted, instead of
leaving these uncommitted this change adds an extra commit (on top of the
framework specific) which also contains some useful information about the
project
15 changes: 8 additions & 7 deletions packages/create-cloudflare/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,19 @@ export const offerGit = async (ctx: PagesGeneratorContext) => {
}
};

export const gitCommit = async (ctx: PagesGeneratorContext) => {
if (!ctx.args.git) return;
export const gitCommit = async (
ctx: PagesGeneratorContext,
commitMessage = "Initial commit (by Create-Cloudflare CLI)"
) => {
if (!(await isGitInstalled()) || !(await isInsideGitRepo(ctx.project.path)))
return;

await runCommands({
silent: true,
cwd: ctx.project.path,
commands: [
"git add .",
["git", "commit", "-m", "Initial commit (by Create-Cloudflare CLI)"],
],
commands: ["git add .", ["git", "commit", "-m", commitMessage]],
startText: "Committing new files",
doneText: `${brandColor("git")} ${dim(`initial commit`)}`,
doneText: `${brandColor("git")} ${dim(`commit`)}`,
});
};

Expand Down
33 changes: 31 additions & 2 deletions packages/create-cloudflare/src/pages.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#!/usr/bin/env node
import { resolve } from "path";
import { chdir } from "process";
import { FrameworkMap, supportedFramework } from "frameworks/index";
import {
FrameworkMap,
getFrameworkVersion,
supportedFramework,
} from "frameworks/index";
import { crash, endSection, startSection } from "helpers/cli";
import { dim, brandColor } from "helpers/colors";
import { installWrangler, retry, runCommand } from "helpers/command";
import { readJSON, writeFile } from "helpers/files";
import { processArgument, spinner } from "helpers/interactive";
import { detectPackageManager } from "helpers/packages";
import { version } from "../package.json";
import { C3_DEFAULTS } from "./cli";
import {
getProductionBranch,
Expand Down Expand Up @@ -61,7 +66,7 @@ export const runPagesGenerator = async (args: C3Args) => {
}
await updatePackageScripts(ctx);
await offerGit(ctx);
await gitCommit(ctx);
await gitCommit(ctx, generatePagesCommitMessage(ctx));
endSection(`Application configured`);

// Deploy
Expand Down Expand Up @@ -176,3 +181,27 @@ const createProject = async (ctx: PagesGeneratorContext) => {
crash("Failed to create pages project. See output above.");
}
};

const generatePagesCommitMessage = (ctx: PagesGeneratorContext) => {
const header = "Web application initialized by Create-Cloudflare CLI";

const details: { key: string; value: string }[] = [
{ key: "date", value: new Date().toISOString() },
{ key: "create-cloudflare version", value: version },
{ key: "project name", value: ctx.project.name },
];

if (ctx.framework) {
details.push({ key: "framework", value: `${ctx.framework.name}` });
details.push({
key: "framework cli version",
value: `${getFrameworkVersion(ctx)}`,
});
}

const body = `Details:\n${details
.map(({ key, value }) => ` ${key} = ${value}`)
.join("\n")}\n`;

return `${header}\n\n${body}\n`;
};

0 comments on commit bc35cd8

Please sign in to comment.