Skip to content

Commit

Permalink
move framework commit message generation inside gitCommit
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Aug 15, 2023
1 parent bc35cd8 commit 68474ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
35 changes: 31 additions & 4 deletions packages/create-cloudflare/src/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { existsSync, mkdirSync, readdirSync } from "fs";
import { basename, dirname, resolve } from "path";
import { chdir } from "process";
import { getFrameworkVersion } from "frameworks/index";
import {
crash,
endSection,
Expand All @@ -23,6 +24,7 @@ import {
import { inputPrompt, processArgument, spinner } from "helpers/interactive";
import { detectPackageManager } from "helpers/packages";
import { poll } from "helpers/poll";
import { version } from "../package.json";
import { C3_DEFAULTS } from "./cli";
import type { C3Args, PagesGeneratorContext } from "types";

Expand Down Expand Up @@ -249,13 +251,14 @@ export const offerGit = async (ctx: PagesGeneratorContext) => {
}
};

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

const commitMessage =
generateFrameworkCommitMessage(ctx) ??
"Initial commit (by Create-Cloudflare CLI)";

await runCommands({
silent: true,
cwd: ctx.project.path,
Expand All @@ -265,6 +268,30 @@ export const gitCommit = async (
});
};

const generateFrameworkCommitMessage = (ctx: PagesGeneratorContext) => {
if (!ctx.framework) return;

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 },
];

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`;
};

/**
* Check whether git is available on the user's machine.
*/
Expand Down
33 changes: 2 additions & 31 deletions packages/create-cloudflare/src/pages.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/usr/bin/env node
import { resolve } from "path";
import { chdir } from "process";
import {
FrameworkMap,
getFrameworkVersion,
supportedFramework,
} from "frameworks/index";
import { FrameworkMap, 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 @@ -66,7 +61,7 @@ export const runPagesGenerator = async (args: C3Args) => {
}
await updatePackageScripts(ctx);
await offerGit(ctx);
await gitCommit(ctx, generatePagesCommitMessage(ctx));
await gitCommit(ctx);
endSection(`Application configured`);

// Deploy
Expand Down Expand Up @@ -181,27 +176,3 @@ 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 68474ca

Please sign in to comment.