Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update Angular template to version 19 #6960

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cool-experts-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": minor
---

Update Angular template to version 19
petebacondarwin marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion packages/create-cloudflare/src/frameworks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"create-astro": "4.10.0",
"create-analog": "1.8.1",
"@angular/create": "18.2.11",
"@angular/create": "19.0.0",
"create-docusaurus": "3.6.1",
"create-hono": "0.14.2",
"create-next-app": "14.2.5",
Expand Down
22 changes: 18 additions & 4 deletions packages/create-cloudflare/templates/angular/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import type { C3Context } from "types";
const { npm } = detectPackageManager();

const generate = async (ctx: C3Context) => {
await runFrameworkGenerator(ctx, [ctx.project.name, "--ssr"]);
await runFrameworkGenerator(ctx, [
ctx.project.name,
"--ssr",
"--server-routing" /** Dev Preview API */,
]);
logRaw("");
};

Expand Down Expand Up @@ -50,12 +54,21 @@ async function updateAppCode() {
writeFile(resolve(appConfigPath), newAppConfig);
s.stop(`${brandColor(`updated`)} ${dim(appConfigPath)}`);

// Update an app server routes file to:
const appServerRoutesPath = "src/app/app.routes.server.ts";
const appRoutes = readFile(resolve(appServerRoutesPath));
const newAppRoutes = appRoutes.replace(
"RenderMode.Prerender",
"RenderMode.Server",
);
writeFile(resolve(appServerRoutesPath), newAppRoutes);
s.stop(`${brandColor(`updated`)} ${dim(appServerRoutesPath)}`);

// Remove unwanted dependencies
s.start(`Updating package.json`);
const packageJsonPath = resolve("package.json");
const packageManifest = readJSON(packageJsonPath);

delete packageManifest["dependencies"]["@angular/ssr"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

delete packageManifest["dependencies"]["express"];
delete packageManifest["devDependencies"]["@types/express"];

Expand All @@ -70,6 +83,8 @@ function updateAngularJson(ctx: C3Context) {
// Update builder
const architectSection = angularJson.projects[ctx.project.name].architect;
architectSection.build.options.outputPath = "dist";
architectSection.build.options.outputMode = "server";
architectSection.build.options.ssr.experimentalPlatform = "neutral";
architectSection.build.options.assets.push("src/_routes.json");

writeFile(resolve("angular.json"), JSON.stringify(angularJson, null, 2));
Expand All @@ -93,8 +108,7 @@ const config: TemplateConfig = {
scripts: {
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

process: "node ./tools/copy-files.mjs",
deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
},
}),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AngularAppEngine, createRequestHandler } from '@angular/ssr';

const angularApp = new AngularAppEngine();

/**
* This is a request handler used by the Angular CLI (dev-server and during build).
*/
export const reqHandler = createRequestHandler(async (req) => {
const res = await angularApp.render(req);

return res ?? new Response('Page not found.', { status: 404 });
});


export default { fetch: reqHandler };

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// Copy the files over so that they can be uploaded by the pages publish command.
import fs from "node:fs";
import { join } from "node:path";
import { client, cloudflare, ssr, worker } from "./paths.mjs";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

const root = resolve(fileURLToPath(import.meta.url), "../../");
const client = resolve(root, "dist/browser");
const ssr = resolve(root, "dist/server");
const cloudflare = resolve(root, "dist/cloudflare");
const worker = resolve(cloudflare, "_worker.js");

fs.cpSync(client, cloudflare, { recursive: true });
fs.cpSync(ssr, worker, { recursive: true });
Expand Down

This file was deleted.

Loading