Skip to content

Commit

Permalink
feat: Update Angular template to version 19 (#6960)
Browse files Browse the repository at this point in the history
* feat: Update Angular template to version 19

This prerelease version 19 includes several developer experience (DX) improvements:
- Introduces a new server routing API
- Portable with no Node.js dependencies
- Supports a "neutral" output format

* fix formatting

---------

Co-authored-by: Peter Bacon Darwin <pbacondarwin@cloudflare.com>
  • Loading branch information
alan-agius4 and petebacondarwin authored Nov 21, 2024
1 parent c9da28b commit 3e52c7c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 77 deletions.
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
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"];
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",
process: "node ./tools/copy-files.mjs",
deploy: `${npm} run build && wrangler pages deploy dist/cloudflare`,
},
}),
Expand Down
34 changes: 0 additions & 34 deletions packages/create-cloudflare/templates/angular/templates/server.ts

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.

0 comments on commit 3e52c7c

Please sign in to comment.