Skip to content

Commit

Permalink
C3: Update remaining dev and deployment scripts (cloudflare#5187)
Browse files Browse the repository at this point in the history
* C3: Update name of build script in Angular template

* Align dev and deploy script names across framework templates

* Move testFlags out of runtime path into framework e2e tests

* changeset

* revise changeset
  • Loading branch information
jculvey authored Mar 8, 2024
1 parent 96e4e16 commit 8e9faf2
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-jobs-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

Aligns most `webFramework` templates to use `dev` and `deploy` instead of `pages:dev` and `pages:deploy` in package scripts.
33 changes: 28 additions & 5 deletions packages/create-cloudflare/e2e-tests/frameworks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ type FrameworkTestConfig = RunnerConfig & {
route: string;
expectedText: string;
};
flags?: string[];
};

const { name: pm, npx } = detectPackageManager();

// These are ordered based on speed and reliability for ease of debugging
const frameworkTests: Record<string, FrameworkTestConfig> = {
astro: {
Expand All @@ -75,6 +78,15 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
route: "/test",
expectedText: "C3_TEST",
},
flags: [
"--skip-houston",
"--no-install",
"--no-git",
"--template",
"blog",
"--typescript",
"strict",
],
},
docusaurus: {
unsupportedPms: ["bun"],
Expand All @@ -85,6 +97,7 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
route: "/",
expectedText: "Dinosaurs are cool",
},
flags: [`--package-manager`, pm],
},
angular: {
testCommitMessage: true,
Expand All @@ -93,6 +106,7 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
route: "/",
expectedText: "Congratulations! Your app is running.",
},
flags: ["--style", "sass"],
},
gatsby: {
unsupportedPms: ["bun", "pnpm"],
Expand Down Expand Up @@ -166,6 +180,7 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
route: "/test",
expectedText: "C3_TEST",
},
flags: ["--typescript", "--no-install", "--no-git-init"],
},
next: {
promptHandlers: [
Expand All @@ -180,6 +195,16 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
route: "/",
expectedText: "Create Next App",
},
flags: [
"--typescript",
"--no-install",
"--eslint",
"--tailwind",
"--src-dir",
"--app",
"--import-alias",
"@/*",
],
},
nuxt: {
testCommitMessage: true,
Expand Down Expand Up @@ -269,6 +294,7 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
route: "/",
expectedText: "Vite App",
},
flags: ["--ts"],
},
};

Expand Down Expand Up @@ -315,7 +341,7 @@ describe.concurrent(`E2E: Web frameworks`, () => {
const projectName = getName(framework);
const frameworkConfig = frameworkMap[framework as FrameworkName];

const { argv, promptHandlers, verifyDeploy } =
const { promptHandlers, verifyDeploy, flags } =
frameworkTests[framework];

if (!verifyDeploy) {
Expand All @@ -332,7 +358,7 @@ describe.concurrent(`E2E: Web frameworks`, () => {
projectPath,
logStream,
{
argv: [...(argv ?? [])],
argv: [...(flags ? ["--", ...flags] : [])],
promptHandlers,
}
);
Expand Down Expand Up @@ -463,7 +489,6 @@ const verifyDevScript = async (
// Run the devserver on a random port to avoid colliding with other tests
const TEST_PORT = Math.ceil(Math.random() * 1000) + 20000;

const { name: pm } = detectPackageManager();
const proc = spawnWithLogging(
[
pm,
Expand Down Expand Up @@ -519,8 +544,6 @@ const verifyBuildScript = async (

const { outputDir, script, route, expectedText } = verifyBuild;

const { name: pm, npx } = detectPackageManager();

// Run the `build-cf-types` script to generate types for bindings in fixture
const buildTypesProc = spawnWithLogging(
[pm, "run", "build-cf-types"],
Expand Down
5 changes: 0 additions & 5 deletions packages/create-cloudflare/src/helpers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ export const runFrameworkGenerator = async (ctx: C3Context, args: string[]) => {
// newline
logRaw("");

if (process.env.VITEST) {
const flags = ctx.template.testFlags ?? [];
cmd.push(...flags);
}

await runCommand(cmd, { env });
};

Expand Down
2 changes: 0 additions & 2 deletions packages/create-cloudflare/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export type TemplateConfig = {
ctx: C3Context
) => Promise<Record<string, string | object>>;

/** An array of flags that will be added to the call to the framework cli during tests.*/
testFlags?: string[];
/** An array of compatibility flags to be specified when deploying to pages or workers.*/
compatibilityFlags?: string[];

Expand Down
11 changes: 5 additions & 6 deletions packages/create-cloudflare/templates/angular/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,18 @@ const config: TemplateConfig = {
copyFiles: {
path: "./templates",
},
devScript: "start",
deployScript: "deploy",
generate,
configure,
transformPackageJson: async () => ({
scripts: {
start: `${npm} run pages:build && wrangler pages dev dist/cloudflare ${await compatDateFlag()} --experimental-local`,
start: `${npm} run build && wrangler pages dev dist/cloudflare ${await compatDateFlag()} --experimental-local`,
build: `ng build && ${npm} run process`,
process:
"node ./tools/copy-files.mjs && node ./tools/alter-polyfills.mjs",
"pages:build": `ng build && ${npm} run process`,
deploy: `${npm} run pages:build && wrangler pages deploy dist/cloudflare`,
deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
},
}),
deployScript: "deploy",
devScript: "start",
testFlags: ["--style", "sass"],
};
export default config;
9 changes: 0 additions & 9 deletions packages/create-cloudflare/templates/astro/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,5 @@ const config: TemplateConfig = {
...(usesTypescript(ctx) && { "build-cf-types": `wrangler types` }),
},
}),
testFlags: [
"--skip-houston",
"--no-install",
"--no-git",
"--template",
"blog",
"--typescript",
"strict",
],
};
export default config;
7 changes: 3 additions & 4 deletions packages/create-cloudflare/templates/docusaurus/c3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { runFrameworkGenerator } from "helpers/command";
import { compatDateFlag } from "helpers/files";
import { detectPackageManager } from "helpers/packages";
import type { TemplateConfig } from "../../src/templates";
import type { C3Context } from "types";
Expand All @@ -18,10 +17,10 @@ const config: TemplateConfig = {
generate,
transformPackageJson: async () => ({
scripts: {
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 3000 -- ${npm} run start`,
"pages:deploy": `${npm} run build && wrangler pages deploy ./build`,
deploy: `${npm} run build && wrangler pages deploy ./build`,
},
}),
testFlags: [`--package-manager`, npm],
devScript: "start",
deployScript: "deploy",
};
export default config;
8 changes: 5 additions & 3 deletions packages/create-cloudflare/templates/gatsby/c3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { inputPrompt } from "@cloudflare/cli/interactive";
import { runFrameworkGenerator } from "helpers/command";
import { compatDateFlag } from "helpers/files";
import { detectPackageManager } from "helpers/packages";
import type { TemplateConfig } from "../../src/templates";
import type { C3Context } from "types";
Expand Down Expand Up @@ -38,9 +37,12 @@ const config: TemplateConfig = {
generate,
transformPackageJson: async () => ({
scripts: {
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 8000 -- ${npm} run develop`,
"pages:deploy": `${npm} run build && wrangler pages deploy ./public`,
deploy: `${npm} run build && wrangler pages deploy ./public`,
preview: `${npm} run build && wrangler pages dev ./public`,
},
}),
devScript: "develop",
deployScript: "deploy",
previewScript: "preview",
};
export default config;
16 changes: 3 additions & 13 deletions packages/create-cloudflare/templates/next/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ export default {
id: "next",
platform: "pages",
displayName: "Next",
devScript: "dev",
previewScript: "preview",
deployScript: "deploy",
generate,
configure,
copyFiles: {
Expand Down Expand Up @@ -212,15 +209,8 @@ export default {
},
};
},
testFlags: [
"--typescript",
"--no-install",
"--eslint",
"--tailwind",
"--src-dir",
"--app",
"--import-alias",
"@/*",
],
devScript: "dev",
previewScript: "preview",
deployScript: "deploy",
compatibilityFlags: ["nodejs_compat"],
} as TemplateConfig;
5 changes: 3 additions & 2 deletions packages/create-cloudflare/templates/nuxt/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ const config: TemplateConfig = {
copyFiles: {
path: "./templates",
},
devScript: "dev",
deployScript: "deploy",
generate,
configure,
transformPackageJson: async () => ({
Expand All @@ -128,5 +126,8 @@ const config: TemplateConfig = {
"build-cf-types": `wrangler types`,
},
}),
devScript: "dev",
deployScript: "deploy",
previewScript: "preview",
};
export default config;
5 changes: 3 additions & 2 deletions packages/create-cloudflare/templates/qwik/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ const config: TemplateConfig = {
copyFiles: {
path: "./templates",
},
devScript: "dev",
deployScript: "deploy",
generate,
configure,
transformPackageJson: async () => ({
Expand All @@ -141,5 +139,8 @@ const config: TemplateConfig = {
"build-cf-types": `wrangler types`,
},
}),
devScript: "dev",
deployScript: "deploy",
previewScript: "preview",
};
export default config;
8 changes: 5 additions & 3 deletions packages/create-cloudflare/templates/react/c3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { logRaw } from "@cloudflare/cli";
import { runFrameworkGenerator } from "helpers/command";
import { compatDateFlag } from "helpers/files";
import { detectPackageManager } from "helpers/packages";
import type { TemplateConfig } from "../../src/templates";
import type { C3Context } from "types";
Expand All @@ -21,9 +20,12 @@ const config: TemplateConfig = {
generate,
transformPackageJson: async () => ({
scripts: {
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --port 3000 -- ${npm} start`,
"pages:deploy": `${npm} run build && wrangler pages deploy ./build`,
deploy: `${npm} run build && wrangler pages deploy ./build`,
preview: `${npm} run build && wrangler pages dev ./build`,
},
}),
devScript: "dev",
deployScript: "deploy",
previewScript: "preview",
};
export default config;
1 change: 0 additions & 1 deletion packages/create-cloudflare/templates/remix/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ const config: TemplateConfig = {
devScript: "dev",
deployScript: "deploy",
previewScript: "preview",
testFlags: ["--typescript", "--no-install", "--no-git-init"],
};
export default config;
2 changes: 1 addition & 1 deletion packages/create-cloudflare/templates/solid/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ const config: TemplateConfig = {
deploy: `${npm} run build && wrangler pages deploy ./dist`,
},
}),
compatibilityFlags: ["nodejs_compat"],
devScript: "dev",
deployScript: "deploy",
previewScript: "preview",
compatibilityFlags: ["nodejs_compat"],
};
export default config;
9 changes: 5 additions & 4 deletions packages/create-cloudflare/templates/vue/c3.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { runFrameworkGenerator } from "helpers/command";
import { compatDateFlag } from "helpers/files";
import { detectPackageManager } from "helpers/packages";
import type { TemplateConfig } from "../../src/templates";
import type { C3Context } from "types";
Expand All @@ -18,10 +17,12 @@ const config: TemplateConfig = {
generate,
transformPackageJson: async () => ({
scripts: {
"pages:dev": `wrangler pages dev ${await compatDateFlag()} --proxy 5173 -- ${npm} run dev`,
"pages:deploy": `${npm} run build && wrangler pages deploy ./dist`,
deploy: `${npm} run build && wrangler pages deploy ./dist`,
preview: `${npm} run build && wrangler pages dev ./dist`,
},
}),
testFlags: ["--ts"],
devScript: "dev",
deployScript: "deploy",
previewScript: "preview",
};
export default config;

0 comments on commit 8e9faf2

Please sign in to comment.