@schematics/angular 19.0.0-next.9 → 19.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app-shell/index.js +71 -74
- package/app-shell/schema.d.ts +4 -0
- package/app-shell/schema.json +5 -0
- package/application/files/module-files/src/app/app.component.spec.ts.template +4 -2
- package/application/files/module-files/src/app/app.component.ts.template +2 -1
- package/application/files/module-files/src/app/app.module.ts.template +2 -2
- package/application/files/module-files/src/main.ts.template +1 -2
- package/application/files/standalone-files/src/app/app.component.spec.ts.template +4 -2
- package/application/files/standalone-files/src/app/app.component.ts.template +0 -1
- package/application/files/standalone-files/src/app/app.config.ts.template +2 -2
- package/application/index.js +3 -2
- package/application/schema.d.ts +9 -0
- package/application/schema.json +9 -0
- package/collection.json +2 -2
- package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template +3 -2
- package/component/index.js +1 -0
- package/config/files/.browserslistrc.template +1 -0
- package/directive/files/__name@dasherize@if-flat__/__name@dasherize__.directive.ts.template +2 -2
- package/directive/index.js +1 -0
- package/library/files/README.md.template +49 -10
- package/ng-new/index.js +2 -0
- package/ng-new/schema.d.ts +9 -0
- package/ng-new/schema.json +9 -0
- package/package.json +3 -3
- package/pipe/files/__name@dasherize@if-flat__/__name@dasherize__.pipe.ts.template +2 -2
- package/server/files/application-builder/ngmodule-src/app/app.module.server.ts.template +13 -0
- package/server/files/application-builder/ngmodule-src/app/app.routes.server.ts.template +8 -0
- package/server/files/application-builder/standalone-src/app/app.config.server.ts.template +14 -0
- package/server/files/application-builder/standalone-src/app/app.routes.server.ts.template +8 -0
- package/server/files/server-builder/ngmodule-src/main.server.ts.template +1 -0
- package/server/files/server-builder/standalone-src/main.server.ts.template +7 -0
- package/server/index.js +16 -6
- package/server/schema.d.ts +5 -0
- package/server/schema.json +4 -0
- package/service-worker/files/ngsw-config.json.template +1 -0
- package/ssr/files/application-builder/server.ts.template +57 -42
- package/ssr/files/application-builder-common-engine/server.ts.template +65 -0
- package/ssr/files/server-builder/server.ts.template +1 -1
- package/ssr/index.js +20 -18
- package/ssr/schema.d.ts +5 -0
- package/ssr/schema.json +6 -0
- package/utility/latest-versions/package.json +1 -1
- package/utility/latest-versions.js +2 -2
- package/utility/workspace-models.d.ts +1 -1
- package/utility/workspace-models.js +1 -1
- package/workspace/files/README.md.template +41 -9
- /package/server/files/{src → application-builder/ngmodule-src}/main.server.ts.template +0 -0
- /package/server/files/{standalone-src → application-builder/standalone-src}/main.server.ts.template +0 -0
- /package/server/files/{src → server-builder/ngmodule-src}/app/app.module.server.ts.template +0 -0
- /package/server/files/{root → server-builder/root}/tsconfig.server.json.template +0 -0
- /package/server/files/{standalone-src → server-builder/standalone-src}/app/app.config.server.ts.template +0 -0
package/app-shell/index.js
CHANGED
|
@@ -106,59 +106,6 @@ function validateProject(mainPath) {
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
|
-
function addAppShellConfigToWorkspace(options) {
|
|
110
|
-
return (host, context) => {
|
|
111
|
-
return (0, workspace_1.updateWorkspace)((workspace) => {
|
|
112
|
-
const project = workspace.projects.get(options.project);
|
|
113
|
-
if (!project) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const buildTarget = project.targets.get('build');
|
|
117
|
-
if (buildTarget?.builder === workspace_models_1.Builders.Application) {
|
|
118
|
-
// Application builder configuration.
|
|
119
|
-
const prodConfig = buildTarget.configurations?.production;
|
|
120
|
-
if (!prodConfig) {
|
|
121
|
-
throw new schematics_1.SchematicsException(`A "production" configuration is not defined for the "build" builder.`);
|
|
122
|
-
}
|
|
123
|
-
prodConfig.appShell = true;
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
// Webpack based builders configuration.
|
|
127
|
-
// Validation of targets is handled already in the main function.
|
|
128
|
-
// Duplicate keys means that we have configurations in both server and build builders.
|
|
129
|
-
const serverConfigKeys = project.targets.get('server')?.configurations ?? {};
|
|
130
|
-
const buildConfigKeys = project.targets.get('build')?.configurations ?? {};
|
|
131
|
-
const configurationNames = Object.keys({
|
|
132
|
-
...serverConfigKeys,
|
|
133
|
-
...buildConfigKeys,
|
|
134
|
-
});
|
|
135
|
-
const configurations = {};
|
|
136
|
-
for (const key of configurationNames) {
|
|
137
|
-
if (!serverConfigKeys[key]) {
|
|
138
|
-
context.logger.warn(`Skipped adding "${key}" configuration to "app-shell" target as it's missing from "server" target.`);
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
if (!buildConfigKeys[key]) {
|
|
142
|
-
context.logger.warn(`Skipped adding "${key}" configuration to "app-shell" target as it's missing from "build" target.`);
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
configurations[key] = {
|
|
146
|
-
browserTarget: `${options.project}:build:${key}`,
|
|
147
|
-
serverTarget: `${options.project}:server:${key}`,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
project.targets.add({
|
|
151
|
-
name: 'app-shell',
|
|
152
|
-
builder: workspace_models_1.Builders.AppShell,
|
|
153
|
-
defaultConfiguration: configurations['production'] ? 'production' : undefined,
|
|
154
|
-
options: {
|
|
155
|
-
route: APP_SHELL_ROUTE,
|
|
156
|
-
},
|
|
157
|
-
configurations,
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
109
|
function addRouterModule(mainPath) {
|
|
163
110
|
return (host) => {
|
|
164
111
|
const modulePath = (0, ng_ast_utils_1.getAppModulePath)(host, mainPath);
|
|
@@ -184,6 +131,24 @@ function getMetadataProperty(metadata, propertyName) {
|
|
|
184
131
|
})[0];
|
|
185
132
|
return property;
|
|
186
133
|
}
|
|
134
|
+
function addAppShellConfigToWorkspace(options) {
|
|
135
|
+
return (0, workspace_1.updateWorkspace)((workspace) => {
|
|
136
|
+
const project = workspace.projects.get(options.project);
|
|
137
|
+
if (!project) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const buildTarget = project.targets.get('build');
|
|
141
|
+
if (buildTarget?.builder === workspace_models_1.Builders.Application ||
|
|
142
|
+
buildTarget?.builder === workspace_models_1.Builders.BuildApplication) {
|
|
143
|
+
// Application builder configuration.
|
|
144
|
+
const prodConfig = buildTarget.configurations?.production;
|
|
145
|
+
if (!prodConfig) {
|
|
146
|
+
throw new schematics_1.SchematicsException(`A "production" configuration is not defined for the "build" builder.`);
|
|
147
|
+
}
|
|
148
|
+
prodConfig.appShell = true;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
187
152
|
function addServerRoutes(options) {
|
|
188
153
|
return async (host) => {
|
|
189
154
|
// The workspace gets updated so this needs to be reloaded
|
|
@@ -237,13 +202,12 @@ function addStandaloneServerRoute(options) {
|
|
|
237
202
|
if (!host.exists(configFilePath)) {
|
|
238
203
|
throw new schematics_1.SchematicsException(`Cannot find "${configFilePath}".`);
|
|
239
204
|
}
|
|
205
|
+
const recorder = host.beginUpdate(configFilePath);
|
|
240
206
|
let configSourceFile = getSourceFile(host, configFilePath);
|
|
241
207
|
if (!(0, ast_utils_1.isImported)(configSourceFile, 'ROUTES', '@angular/router')) {
|
|
242
208
|
const routesChange = (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'ROUTES', '@angular/router');
|
|
243
|
-
const recorder = host.beginUpdate(configFilePath);
|
|
244
209
|
if (routesChange) {
|
|
245
210
|
(0, change_1.applyToUpdateRecorder)(recorder, [routesChange]);
|
|
246
|
-
host.commitUpdate(recorder);
|
|
247
211
|
}
|
|
248
212
|
}
|
|
249
213
|
configSourceFile = getSourceFile(host, configFilePath);
|
|
@@ -252,29 +216,59 @@ function addStandaloneServerRoute(options) {
|
|
|
252
216
|
throw new schematics_1.SchematicsException(`Cannot find the "providers" configuration in "${configFilePath}".`);
|
|
253
217
|
}
|
|
254
218
|
// Add route to providers literal.
|
|
255
|
-
const newProvidersLiteral = typescript_1.default.factory.updateArrayLiteralExpression(providersLiteral, [
|
|
256
|
-
...providersLiteral.elements,
|
|
257
|
-
typescript_1.default.factory.createObjectLiteralExpression([
|
|
258
|
-
typescript_1.default.factory.createPropertyAssignment('provide', typescript_1.default.factory.createIdentifier('ROUTES')),
|
|
259
|
-
typescript_1.default.factory.createPropertyAssignment('multi', typescript_1.default.factory.createIdentifier('true')),
|
|
260
|
-
typescript_1.default.factory.createPropertyAssignment('useValue', typescript_1.default.factory.createArrayLiteralExpression([
|
|
261
|
-
typescript_1.default.factory.createObjectLiteralExpression([
|
|
262
|
-
typescript_1.default.factory.createPropertyAssignment('path', typescript_1.default.factory.createIdentifier(`'${APP_SHELL_ROUTE}'`)),
|
|
263
|
-
typescript_1.default.factory.createPropertyAssignment('component', typescript_1.default.factory.createIdentifier('AppShellComponent')),
|
|
264
|
-
], true),
|
|
265
|
-
], true)),
|
|
266
|
-
], true),
|
|
267
|
-
]);
|
|
268
|
-
const recorder = host.beginUpdate(configFilePath);
|
|
269
219
|
recorder.remove(providersLiteral.getStart(), providersLiteral.getWidth());
|
|
270
|
-
const
|
|
271
|
-
|
|
220
|
+
const updatedProvidersString = [
|
|
221
|
+
...providersLiteral.elements.map((element) => ' ' + element.getText()),
|
|
222
|
+
` {
|
|
223
|
+
provide: ROUTES,
|
|
224
|
+
multi: true,
|
|
225
|
+
useValue: [{
|
|
226
|
+
path: '${APP_SHELL_ROUTE}',
|
|
227
|
+
component: AppShellComponent
|
|
228
|
+
}]
|
|
229
|
+
}\n `,
|
|
230
|
+
];
|
|
231
|
+
recorder.insertRight(providersLiteral.getStart(), `[\n${updatedProvidersString.join(',\n')}]`);
|
|
272
232
|
// Add AppShellComponent import
|
|
273
233
|
const appShellImportChange = (0, ast_utils_1.insertImport)(configSourceFile, configFilePath, 'AppShellComponent', './app-shell/app-shell.component');
|
|
274
234
|
(0, change_1.applyToUpdateRecorder)(recorder, [appShellImportChange]);
|
|
275
235
|
host.commitUpdate(recorder);
|
|
276
236
|
};
|
|
277
237
|
}
|
|
238
|
+
function addServerRoutingConfig(options) {
|
|
239
|
+
return async (host) => {
|
|
240
|
+
const workspace = await (0, workspace_1.getWorkspace)(host);
|
|
241
|
+
const project = workspace.projects.get(options.project);
|
|
242
|
+
if (!project) {
|
|
243
|
+
throw new schematics_1.SchematicsException(`Project name "${options.project}" doesn't not exist.`);
|
|
244
|
+
}
|
|
245
|
+
const configFilePath = (0, posix_1.join)(project.sourceRoot ?? 'src', 'app/app.routes.server.ts');
|
|
246
|
+
if (!host.exists(configFilePath)) {
|
|
247
|
+
throw new schematics_1.SchematicsException(`Cannot find "${configFilePath}".`);
|
|
248
|
+
}
|
|
249
|
+
const sourceFile = getSourceFile(host, configFilePath);
|
|
250
|
+
const nodes = (0, ast_utils_1.getSourceNodes)(sourceFile);
|
|
251
|
+
// Find the serverRoutes variable declaration
|
|
252
|
+
const serverRoutesNode = nodes.find((node) => typescript_1.default.isVariableDeclaration(node) &&
|
|
253
|
+
node.initializer &&
|
|
254
|
+
typescript_1.default.isArrayLiteralExpression(node.initializer) &&
|
|
255
|
+
node.type &&
|
|
256
|
+
typescript_1.default.isArrayTypeNode(node.type) &&
|
|
257
|
+
node.type.getText().includes('ServerRoute'));
|
|
258
|
+
if (!serverRoutesNode) {
|
|
259
|
+
throw new schematics_1.SchematicsException(`Cannot find the "ServerRoute" configuration in "${configFilePath}".`);
|
|
260
|
+
}
|
|
261
|
+
const recorder = host.beginUpdate(configFilePath);
|
|
262
|
+
const arrayLiteral = serverRoutesNode.initializer;
|
|
263
|
+
const firstElementPosition = arrayLiteral.elements[0]?.getStart() ?? arrayLiteral.getStart() + 1;
|
|
264
|
+
const newRouteString = `{
|
|
265
|
+
path: '${APP_SHELL_ROUTE}',
|
|
266
|
+
renderMode: RenderMode.AppShell
|
|
267
|
+
},\n`;
|
|
268
|
+
recorder.insertLeft(firstElementPosition, newRouteString);
|
|
269
|
+
host.commitUpdate(recorder);
|
|
270
|
+
};
|
|
271
|
+
}
|
|
278
272
|
function default_1(options) {
|
|
279
273
|
return async (tree) => {
|
|
280
274
|
const browserEntryPoint = await (0, util_1.getMainFilePath)(tree, options.project);
|
|
@@ -282,9 +276,12 @@ function default_1(options) {
|
|
|
282
276
|
return (0, schematics_1.chain)([
|
|
283
277
|
validateProject(browserEntryPoint),
|
|
284
278
|
(0, schematics_1.schematic)('server', options),
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
279
|
+
...(isStandalone
|
|
280
|
+
? [addStandaloneServerRoute(options)]
|
|
281
|
+
: [addRouterModule(browserEntryPoint), addServerRoutes(options)]),
|
|
282
|
+
options.serverRouting
|
|
283
|
+
? addServerRoutingConfig(options)
|
|
284
|
+
: addAppShellConfigToWorkspace(options),
|
|
288
285
|
(0, schematics_1.schematic)('component', {
|
|
289
286
|
name: 'app-shell',
|
|
290
287
|
module: 'app.module.server.ts',
|
package/app-shell/schema.d.ts
CHANGED
package/app-shell/schema.json
CHANGED
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
"$default": {
|
|
13
13
|
"$source": "projectName"
|
|
14
14
|
}
|
|
15
|
+
},
|
|
16
|
+
"serverRouting": {
|
|
17
|
+
"description": "Creates a server application using the Server Routing API (Developer Preview).",
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"default": false
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
"required": ["project"]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
<% if(experimentalZoneless) { %>import { provideExperimentalZonelessChangeDetection } from '@angular/core';
|
|
2
|
+
<% } %>import { TestBed } from '@angular/core/testing';<% if (routing) { %>
|
|
2
3
|
import { RouterModule } from '@angular/router';<% } %>
|
|
3
4
|
import { AppComponent } from './app.component';
|
|
4
5
|
|
|
@@ -10,7 +11,8 @@ describe('AppComponent', () => {
|
|
|
10
11
|
],<% } %>
|
|
11
12
|
declarations: [
|
|
12
13
|
AppComponent
|
|
13
|
-
]
|
|
14
|
+
],<% if(experimentalZoneless) { %>
|
|
15
|
+
providers: [provideExperimentalZonelessChangeDetection()]<% } %>
|
|
14
16
|
}).compileComponents();
|
|
15
17
|
});
|
|
16
18
|
|
|
@@ -9,7 +9,8 @@ import { Component } from '@angular/core';
|
|
|
9
9
|
%><router-outlet /><%
|
|
10
10
|
} %>
|
|
11
11
|
`,<% } else { %>
|
|
12
|
-
templateUrl: './app.component.html',<% }
|
|
12
|
+
templateUrl: './app.component.html',<% } %>
|
|
13
|
+
standalone: false,<% if(inlineStyle) { %>
|
|
13
14
|
styles: []<% } else { %>
|
|
14
15
|
styleUrl: './app.component.<%= style %>'<% } %>
|
|
15
16
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NgModule } from '@angular/core';
|
|
1
|
+
import { NgModule<% if(experimentalZoneless) { %>, provideExperimentalZonelessChangeDetection<% } %> } from '@angular/core';
|
|
2
2
|
import { BrowserModule } from '@angular/platform-browser';
|
|
3
3
|
<% if (routing) { %>
|
|
4
4
|
import { AppRoutingModule } from './app-routing.module';<% } %>
|
|
@@ -12,7 +12,7 @@ import { AppComponent } from './app.component';
|
|
|
12
12
|
BrowserModule<% if (routing) { %>,
|
|
13
13
|
AppRoutingModule<% } %>
|
|
14
14
|
],
|
|
15
|
-
providers: [],
|
|
15
|
+
providers: [<% if (experimentalZoneless) { %>provideExperimentalZonelessChangeDetection()<% } %>],
|
|
16
16
|
bootstrap: [AppComponent]
|
|
17
17
|
})
|
|
18
18
|
export class AppModule { }
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
<% if(!!viewEncapsulation) { %>import { ViewEncapsulation } from '@angular/core';
|
|
2
2
|
<% }%>import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
|
3
|
-
|
|
4
3
|
import { AppModule } from './app/app.module';
|
|
5
4
|
|
|
6
5
|
platformBrowserDynamic().bootstrapModule(AppModule, {
|
|
7
|
-
ngZoneEventCoalescing: true
|
|
6
|
+
<% if(!experimentalZoneless) { %>ngZoneEventCoalescing: true,<% } %><% if(!!viewEncapsulation) { %>
|
|
8
7
|
defaultEncapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } %>
|
|
9
8
|
})
|
|
10
9
|
.catch(err => console.error(err));
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
<% if(experimentalZoneless) { %>import { provideExperimentalZonelessChangeDetection } from '@angular/core';
|
|
2
|
+
<% } %>import { TestBed } from '@angular/core/testing';
|
|
2
3
|
import { AppComponent } from './app.component';
|
|
3
4
|
|
|
4
5
|
describe('AppComponent', () => {
|
|
5
6
|
beforeEach(async () => {
|
|
6
7
|
await TestBed.configureTestingModule({
|
|
7
|
-
imports: [AppComponent]
|
|
8
|
+
imports: [AppComponent],<% if(experimentalZoneless) { %>
|
|
9
|
+
providers: [provideExperimentalZonelessChangeDetection()]<% } %>
|
|
8
10
|
}).compileComponents();
|
|
9
11
|
});
|
|
10
12
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';<% if (routing) { %>
|
|
1
|
+
import { ApplicationConfig, <% if(!experimentalZoneless) { %>provideZoneChangeDetection<% } else { %>provideExperimentalZonelessChangeDetection<% } %> } from '@angular/core';<% if (routing) { %>
|
|
2
2
|
import { provideRouter } from '@angular/router';
|
|
3
3
|
|
|
4
4
|
import { routes } from './app.routes';<% } %>
|
|
5
5
|
|
|
6
6
|
export const appConfig: ApplicationConfig = {
|
|
7
|
-
providers: [provideZoneChangeDetection({ eventCoalescing: true })<% if (routing) {
|
|
7
|
+
providers: [<% if(experimentalZoneless) { %>provideExperimentalZonelessChangeDetection()<% } else { %>provideZoneChangeDetection({ eventCoalescing: true })<% } %><% if (routing) {%>, provideRouter(routes)<% } %>]
|
|
8
8
|
};
|
package/application/index.js
CHANGED
|
@@ -78,6 +78,7 @@ function default_1(options) {
|
|
|
78
78
|
options.ssr
|
|
79
79
|
? (0, schematics_1.schematic)('ssr', {
|
|
80
80
|
project: options.name,
|
|
81
|
+
serverRouting: options.serverRouting,
|
|
81
82
|
skipInstall: true,
|
|
82
83
|
})
|
|
83
84
|
: (0, schematics_1.noop)(),
|
|
@@ -198,7 +199,7 @@ function addAppToWorkspaceFile(options, appDir, folderName) {
|
|
|
198
199
|
outputPath: `dist/${folderName}`,
|
|
199
200
|
index: `${sourceRoot}/index.html`,
|
|
200
201
|
browser: `${sourceRoot}/main.ts`,
|
|
201
|
-
polyfills: ['zone.js'],
|
|
202
|
+
polyfills: options.experimentalZoneless ? [] : ['zone.js'],
|
|
202
203
|
tsConfig: `${projectRoot}tsconfig.app.json`,
|
|
203
204
|
inlineStyleLanguage,
|
|
204
205
|
assets: [{ 'glob': '**/*', 'input': `${projectRoot}public` }],
|
|
@@ -238,7 +239,7 @@ function addAppToWorkspaceFile(options, appDir, folderName) {
|
|
|
238
239
|
: {
|
|
239
240
|
builder: workspace_models_1.Builders.Karma,
|
|
240
241
|
options: {
|
|
241
|
-
polyfills: ['zone.js', 'zone.js/testing'],
|
|
242
|
+
polyfills: options.experimentalZoneless ? [] : ['zone.js', 'zone.js/testing'],
|
|
242
243
|
tsConfig: `${projectRoot}tsconfig.spec.json`,
|
|
243
244
|
inlineStyleLanguage,
|
|
244
245
|
assets: [{ 'glob': '**/*', 'input': `${projectRoot}public` }],
|
package/application/schema.d.ts
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* Generates a new basic application definition in the "projects" subfolder of the workspace.
|
|
3
3
|
*/
|
|
4
4
|
export interface Schema {
|
|
5
|
+
/**
|
|
6
|
+
* Create an application that does not utilize zone.js.
|
|
7
|
+
*/
|
|
8
|
+
experimentalZoneless?: boolean;
|
|
5
9
|
/**
|
|
6
10
|
* Include styles inline in the root component.ts file. Only CSS styles can be included
|
|
7
11
|
* inline. Default is false, meaning that an external styles file is created and referenced
|
|
@@ -34,6 +38,11 @@ export interface Schema {
|
|
|
34
38
|
* Creates an application with routing enabled.
|
|
35
39
|
*/
|
|
36
40
|
routing?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a server application using the Server Routing and App Engine APIs (Developer
|
|
43
|
+
* Preview).
|
|
44
|
+
*/
|
|
45
|
+
serverRouting?: boolean;
|
|
37
46
|
/**
|
|
38
47
|
* Skip installing dependency packages.
|
|
39
48
|
*/
|
package/application/schema.json
CHANGED
|
@@ -117,6 +117,15 @@
|
|
|
117
117
|
"type": "boolean",
|
|
118
118
|
"default": false,
|
|
119
119
|
"x-user-analytics": "ep.ng_ssr"
|
|
120
|
+
},
|
|
121
|
+
"serverRouting": {
|
|
122
|
+
"description": "Creates a server application using the Server Routing and App Engine APIs (Developer Preview).",
|
|
123
|
+
"type": "boolean"
|
|
124
|
+
},
|
|
125
|
+
"experimentalZoneless": {
|
|
126
|
+
"description": "Create an application that does not utilize zone.js.",
|
|
127
|
+
"type": "boolean",
|
|
128
|
+
"default": false
|
|
120
129
|
}
|
|
121
130
|
},
|
|
122
131
|
"required": ["name"]
|
package/collection.json
CHANGED
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"schema": "./application/schema.json",
|
|
24
24
|
"description": "Create an Angular application."
|
|
25
25
|
},
|
|
26
|
-
"e2e": {
|
|
26
|
+
"private-e2e": {
|
|
27
27
|
"factory": "./e2e",
|
|
28
28
|
"schema": "./e2e/schema.json",
|
|
29
|
-
"description": "
|
|
29
|
+
"description": "PRIVATE API - Do not use.",
|
|
30
30
|
"hidden": true
|
|
31
31
|
},
|
|
32
32
|
"class": {
|
package/component/files/__name@dasherize@if-flat__/__name@dasherize__.__type@dasherize__.ts.template
CHANGED
|
@@ -2,8 +2,9 @@ import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%
|
|
|
2
2
|
|
|
3
3
|
@Component({<% if(!skipSelector) {%>
|
|
4
4
|
selector: '<%= selector %>',<%}%><% if(standalone) {%>
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
imports: [],<%} else { %>
|
|
6
|
+
standalone: false,
|
|
7
|
+
<% }%><% if(inlineTemplate) { %>
|
|
7
8
|
template: `
|
|
8
9
|
<p>
|
|
9
10
|
<%= dasherize(name) %> works!
|
package/component/index.js
CHANGED
|
@@ -42,6 +42,7 @@ function default_1(options) {
|
|
|
42
42
|
options.selector =
|
|
43
43
|
options.selector || buildSelector(options, (project && project.prefix) || '');
|
|
44
44
|
(0, validation_1.validateHtmlSelector)(options.selector);
|
|
45
|
+
(0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
|
|
45
46
|
const skipStyleFile = options.inlineStyle || options.style === schema_1.Style.None;
|
|
46
47
|
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
47
48
|
options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Directive } from '@angular/core';
|
|
2
2
|
|
|
3
3
|
@Directive({
|
|
4
|
-
selector: '[<%= selector %>]'<% if(standalone) {%>,
|
|
5
|
-
standalone:
|
|
4
|
+
selector: '[<%= selector %>]'<% if(!standalone) {%>,
|
|
5
|
+
standalone: false<%}%>
|
|
6
6
|
})
|
|
7
7
|
export class <%= classify(name) %>Directive {
|
|
8
8
|
|
package/directive/index.js
CHANGED
|
@@ -40,6 +40,7 @@ function default_1(options) {
|
|
|
40
40
|
options.path = parsedPath.path;
|
|
41
41
|
options.selector = options.selector || buildSelector(options, project.prefix || '');
|
|
42
42
|
(0, validation_1.validateHtmlSelector)(options.selector);
|
|
43
|
+
(0, validation_1.validateClassName)(schematics_1.strings.classify(options.name));
|
|
43
44
|
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [
|
|
44
45
|
options.skipTests ? (0, schematics_1.filter)((path) => !path.endsWith('.spec.ts.template')) : (0, schematics_1.noop)(),
|
|
45
46
|
(0, schematics_1.applyTemplates)({
|
|
@@ -1,24 +1,63 @@
|
|
|
1
1
|
# <%= classify(name) %>
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version <%= angularLatestVersion %>.
|
|
4
4
|
|
|
5
5
|
## Code scaffolding
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
> Note: Don't forget to add `--project <%= name %>` or else it will be added to the default project in your `angular.json` file.
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build <%= name %>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/<%= dasherize(name) %>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
17
42
|
|
|
18
43
|
## Running unit tests
|
|
19
44
|
|
|
20
|
-
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
21
60
|
|
|
22
|
-
##
|
|
61
|
+
## Additional Resources
|
|
23
62
|
|
|
24
|
-
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
package/ng-new/index.js
CHANGED
|
@@ -40,6 +40,8 @@ function default_1(options) {
|
|
|
40
40
|
minimal: options.minimal,
|
|
41
41
|
standalone: options.standalone,
|
|
42
42
|
ssr: options.ssr,
|
|
43
|
+
serverRouting: options.serverRouting,
|
|
44
|
+
experimentalZoneless: options.experimentalZoneless,
|
|
43
45
|
};
|
|
44
46
|
return (0, schematics_1.chain)([
|
|
45
47
|
(0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.empty)(), [
|
package/ng-new/schema.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ export interface Schema {
|
|
|
16
16
|
* The directory name to create the workspace in.
|
|
17
17
|
*/
|
|
18
18
|
directory?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Create an application that does not utilize zone.js.
|
|
21
|
+
*/
|
|
22
|
+
experimentalZoneless?: boolean;
|
|
19
23
|
/**
|
|
20
24
|
* Include styles inline in the component TS file. By default, an external styles file is
|
|
21
25
|
* created and referenced in the component TypeScript file.
|
|
@@ -50,6 +54,11 @@ export interface Schema {
|
|
|
50
54
|
* Enable routing in the initial project.
|
|
51
55
|
*/
|
|
52
56
|
routing?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a server application using the Server Routing and App Engine APIs (Developer
|
|
59
|
+
* Preview).
|
|
60
|
+
*/
|
|
61
|
+
serverRouting?: boolean;
|
|
53
62
|
/**
|
|
54
63
|
* Do not initialize a git repository.
|
|
55
64
|
*/
|
package/ng-new/schema.json
CHANGED
|
@@ -138,6 +138,15 @@
|
|
|
138
138
|
"description": "Creates an application with Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering) enabled.",
|
|
139
139
|
"type": "boolean",
|
|
140
140
|
"x-user-analytics": "ep.ng_ssr"
|
|
141
|
+
},
|
|
142
|
+
"serverRouting": {
|
|
143
|
+
"description": "Creates a server application using the Server Routing and App Engine APIs (Developer Preview).",
|
|
144
|
+
"type": "boolean"
|
|
145
|
+
},
|
|
146
|
+
"experimentalZoneless": {
|
|
147
|
+
"description": "Create an application that does not utilize zone.js.",
|
|
148
|
+
"type": "boolean",
|
|
149
|
+
"default": false
|
|
141
150
|
}
|
|
142
151
|
},
|
|
143
152
|
"required": ["name", "version"]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schematics/angular",
|
|
3
|
-
"version": "19.0.0-
|
|
3
|
+
"version": "19.0.0-rc.0",
|
|
4
4
|
"description": "Schematics specific to Angular",
|
|
5
5
|
"homepage": "https://github.com/angular/angular-cli",
|
|
6
6
|
"keywords": [
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"schematics": "./collection.json",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@angular-devkit/core": "19.0.0-
|
|
26
|
-
"@angular-devkit/schematics": "19.0.0-
|
|
25
|
+
"@angular-devkit/core": "19.0.0-rc.0",
|
|
26
|
+
"@angular-devkit/schematics": "19.0.0-rc.0",
|
|
27
27
|
"jsonc-parser": "3.3.1"
|
|
28
28
|
},
|
|
29
29
|
"packageManager": "yarn@4.5.0",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
2
|
|
|
3
3
|
@Pipe({
|
|
4
|
-
name: '<%= camelize(name) %>'<% if(standalone) {%>,
|
|
5
|
-
standalone:
|
|
4
|
+
name: '<%= camelize(name) %>'<% if(!standalone) {%>,
|
|
5
|
+
standalone: false<%}%>
|
|
6
6
|
})
|
|
7
7
|
export class <%= classify(name) %>Pipe implements PipeTransform {
|
|
8
8
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { ServerModule } from '@angular/platform-server';<% if(serverRouting) { %>
|
|
3
|
+
import { provideServerRoutesConfig } from '@angular/ssr';<% } %>
|
|
4
|
+
import { AppComponent } from './app.component';
|
|
5
|
+
import { AppModule } from './app.module';<% if(serverRouting) { %>
|
|
6
|
+
import { serverRoutes } from './app.routes.server';<% } %>
|
|
7
|
+
|
|
8
|
+
@NgModule({
|
|
9
|
+
imports: [AppModule, ServerModule],<% if(serverRouting) { %>
|
|
10
|
+
providers: [provideServerRoutesConfig(serverRoutes)],<% } %>
|
|
11
|
+
bootstrap: [AppComponent],
|
|
12
|
+
})
|
|
13
|
+
export class AppServerModule {}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { mergeApplicationConfig, ApplicationConfig } from '@angular/core';
|
|
2
|
+
import { provideServerRendering } from '@angular/platform-server';<% if(serverRouting) { %>
|
|
3
|
+
import { provideServerRoutesConfig } from '@angular/ssr';<% } %>
|
|
4
|
+
import { appConfig } from './app.config';<% if(serverRouting) { %>
|
|
5
|
+
import { serverRoutes } from './app.routes.server';<% } %>
|
|
6
|
+
|
|
7
|
+
const serverConfig: ApplicationConfig = {
|
|
8
|
+
providers: [
|
|
9
|
+
provideServerRendering(),<% if(serverRouting) { %>
|
|
10
|
+
provideServerRoutesConfig(serverRoutes)<% } %>
|
|
11
|
+
]
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const config = mergeApplicationConfig(appConfig, serverConfig);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AppServerModule as default } from './app/app.module.server';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { bootstrapApplication } from '@angular/platform-browser';
|
|
2
|
+
import { AppComponent } from './app/app.component';
|
|
3
|
+
import { config } from './app/app.config.server';
|
|
4
|
+
|
|
5
|
+
const bootstrap = () => bootstrapApplication(AppComponent, config);
|
|
6
|
+
|
|
7
|
+
export default bootstrap;
|
package/server/index.js
CHANGED
|
@@ -83,11 +83,14 @@ function updateConfigFileApplicationBuilder(options) {
|
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
85
|
const buildTarget = project.targets.get('build');
|
|
86
|
-
if (buildTarget
|
|
87
|
-
|
|
86
|
+
if (!buildTarget) {
|
|
87
|
+
return;
|
|
88
88
|
}
|
|
89
89
|
buildTarget.options ??= {};
|
|
90
90
|
buildTarget.options['server'] = node_path_1.posix.join(project.sourceRoot ?? node_path_1.posix.join(project.root, 'src'), serverMainEntryName);
|
|
91
|
+
if (options.serverRouting) {
|
|
92
|
+
buildTarget.options['outputMode'] = 'static';
|
|
93
|
+
}
|
|
91
94
|
});
|
|
92
95
|
}
|
|
93
96
|
function updateTsConfigFile(tsConfigPath) {
|
|
@@ -137,7 +140,8 @@ function default_1(options) {
|
|
|
137
140
|
if (!clientBuildTarget) {
|
|
138
141
|
throw (0, project_targets_1.targetBuildNotFoundError)();
|
|
139
142
|
}
|
|
140
|
-
const isUsingApplicationBuilder = clientBuildTarget.builder === workspace_models_1.Builders.Application
|
|
143
|
+
const isUsingApplicationBuilder = clientBuildTarget.builder === workspace_models_1.Builders.Application ||
|
|
144
|
+
clientBuildTarget.builder === workspace_models_1.Builders.BuildApplication;
|
|
141
145
|
if (clientProject.targets.has('server') ||
|
|
142
146
|
(isUsingApplicationBuilder && clientBuildTarget.options?.server !== undefined)) {
|
|
143
147
|
// Server has already been added.
|
|
@@ -146,12 +150,18 @@ function default_1(options) {
|
|
|
146
150
|
const clientBuildOptions = clientBuildTarget.options;
|
|
147
151
|
const browserEntryPoint = await (0, util_1.getMainFilePath)(host, options.project);
|
|
148
152
|
const isStandalone = (0, ng_ast_utils_1.isStandaloneApp)(host, browserEntryPoint);
|
|
149
|
-
const
|
|
153
|
+
const sourceRoot = clientProject.sourceRoot ?? (0, core_1.join)((0, core_1.normalize)(clientProject.root), 'src');
|
|
154
|
+
let filesUrl = `./files/${isUsingApplicationBuilder ? 'application-builder/' : 'server-builder/'}`;
|
|
155
|
+
filesUrl += isStandalone ? 'standalone-src' : 'ngmodule-src';
|
|
156
|
+
const templateSource = (0, schematics_1.apply)((0, schematics_1.url)(filesUrl), [
|
|
157
|
+
options.serverRouting
|
|
158
|
+
? (0, schematics_1.noop)()
|
|
159
|
+
: (0, schematics_1.filter)((path) => !path.endsWith('app.routes.server.ts.template')),
|
|
150
160
|
(0, schematics_1.applyTemplates)({
|
|
151
161
|
...schematics_1.strings,
|
|
152
162
|
...options,
|
|
153
163
|
}),
|
|
154
|
-
(0, schematics_1.move)(
|
|
164
|
+
(0, schematics_1.move)(sourceRoot),
|
|
155
165
|
]);
|
|
156
166
|
const clientTsConfig = (0, core_1.normalize)(clientBuildOptions.tsConfig);
|
|
157
167
|
const tsConfigExtends = (0, core_1.basename)(clientTsConfig);
|
|
@@ -164,7 +174,7 @@ function default_1(options) {
|
|
|
164
174
|
updateTsConfigFile(clientBuildOptions.tsConfig),
|
|
165
175
|
]
|
|
166
176
|
: [
|
|
167
|
-
(0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files/root'), [
|
|
177
|
+
(0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files/server-builder/root'), [
|
|
168
178
|
(0, schematics_1.applyTemplates)({
|
|
169
179
|
...schematics_1.strings,
|
|
170
180
|
...options,
|
package/server/schema.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ export interface Schema {
|
|
|
6
6
|
* The name of the project.
|
|
7
7
|
*/
|
|
8
8
|
project: string;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a server application using the Server Routing and App Engine APIs (Developer
|
|
11
|
+
* Preview).
|
|
12
|
+
*/
|
|
13
|
+
serverRouting?: boolean;
|
|
9
14
|
/**
|
|
10
15
|
* Do not install packages for dependencies.
|
|
11
16
|
*/
|
package/server/schema.json
CHANGED
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"description": "Do not install packages for dependencies.",
|
|
18
18
|
"type": "boolean",
|
|
19
19
|
"default": false
|
|
20
|
+
},
|
|
21
|
+
"serverRouting": {
|
|
22
|
+
"description": "Creates a server application using the Server Routing and App Engine APIs (Developer Preview).",
|
|
23
|
+
"type": "boolean"
|
|
20
24
|
}
|
|
21
25
|
},
|
|
22
26
|
"required": ["project"]
|
|
@@ -1,57 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
AngularNodeAppEngine,
|
|
3
|
+
createNodeRequestHandler,
|
|
4
|
+
isMainModule,
|
|
5
|
+
writeResponseToNodeResponse,
|
|
6
|
+
} from '@angular/ssr/node';
|
|
3
7
|
import express from 'express';
|
|
8
|
+
import { dirname, resolve } from 'node:path';
|
|
4
9
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { dirname, join, resolve } from 'node:path';
|
|
6
|
-
import <% if (isStandalone) { %>bootstrap<% } else { %>AppServerModule<% } %> from './src/main.server';
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const server = express();
|
|
11
|
-
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const browserDistFolder = resolve(serverDistFolder, '../<%= browserDistDirectory %>');
|
|
13
|
-
const indexHtml = join(serverDistFolder, 'index.server.html');
|
|
11
|
+
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const browserDistFolder = resolve(serverDistFolder, '../<%= browserDistDirectory %>');
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
const app = express();
|
|
15
|
+
const angularApp = new AngularNodeAppEngine();
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Example Express Rest API endpoints can be defined here.
|
|
19
|
+
* Uncomment and define endpoints as necessary.
|
|
20
|
+
*
|
|
21
|
+
* Example:
|
|
22
|
+
* ```ts
|
|
23
|
+
* app.get('/api/**', (req, res) => {
|
|
24
|
+
* // Handle API request
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
19
28
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Serve static files from /<%= browserDistDirectory %>
|
|
31
|
+
*/
|
|
32
|
+
app.get(
|
|
33
|
+
'**',
|
|
34
|
+
express.static(browserDistFolder, {
|
|
24
35
|
maxAge: '1y',
|
|
25
36
|
index: 'index.html',
|
|
26
|
-
|
|
37
|
+
setHeaders: (res) => {
|
|
38
|
+
const headers = angularApp.getPrerenderHeaders(res.req);
|
|
39
|
+
for (const [key, value] of headers) {
|
|
40
|
+
res.setHeader(key, value);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
27
45
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Handle all other requests by rendering the Angular application.
|
|
48
|
+
*/
|
|
49
|
+
app.get('**', (req, res, next) => {
|
|
50
|
+
angularApp
|
|
51
|
+
.render(req)
|
|
52
|
+
.then((response) =>
|
|
53
|
+
response ? writeResponseToNodeResponse(response, res) : next(),
|
|
54
|
+
)
|
|
55
|
+
.catch(next);
|
|
56
|
+
});
|
|
31
57
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
publicPath: browserDistFolder,
|
|
38
|
-
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
|
|
39
|
-
})
|
|
40
|
-
.then((html) => res.send(html))
|
|
41
|
-
.catch((err) => next(err));
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return server;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function run(): void {
|
|
58
|
+
/**
|
|
59
|
+
* Start the server if this module is the main entry point.
|
|
60
|
+
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
|
|
61
|
+
*/
|
|
62
|
+
if (isMainModule(import.meta.url)) {
|
|
48
63
|
const port = process.env['PORT'] || 4000;
|
|
49
|
-
|
|
50
|
-
// Start up the Node server
|
|
51
|
-
const server = app();
|
|
52
|
-
server.listen(port, () => {
|
|
64
|
+
app.listen(port, () => {
|
|
53
65
|
console.log(`Node Express server listening on http://localhost:${port}`);
|
|
54
66
|
});
|
|
55
67
|
}
|
|
56
68
|
|
|
57
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The request handler used by the Angular CLI (dev-server and during build).
|
|
71
|
+
*/
|
|
72
|
+
export const reqHandler = createNodeRequestHandler(app);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { APP_BASE_HREF } from '@angular/common';
|
|
2
|
+
import { CommonEngine, isMainModule } from '@angular/ssr/node';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import <% if (isStandalone) { %>bootstrap<% } else { %>AppServerModule<% } %> from './main.server';
|
|
7
|
+
|
|
8
|
+
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const browserDistFolder = resolve(serverDistFolder, '../<%= browserDistDirectory %>');
|
|
10
|
+
const indexHtml = join(serverDistFolder, 'index.server.html');
|
|
11
|
+
|
|
12
|
+
const app = express();
|
|
13
|
+
const commonEngine = new CommonEngine();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Example Express Rest API endpoints can be defined here.
|
|
17
|
+
* Uncomment and define endpoints as necessary.
|
|
18
|
+
*
|
|
19
|
+
* Example:
|
|
20
|
+
* ```ts
|
|
21
|
+
* app.get('/api/**', (req, res) => {
|
|
22
|
+
* // Handle API request
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Serve static files from /<%= browserDistDirectory %>
|
|
29
|
+
*/
|
|
30
|
+
app.get(
|
|
31
|
+
'**',
|
|
32
|
+
express.static(browserDistFolder, {
|
|
33
|
+
maxAge: '1y',
|
|
34
|
+
index: 'index.html'
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Handle all other requests by rendering the Angular application.
|
|
40
|
+
*/
|
|
41
|
+
app.get('**', (req, res, next) => {
|
|
42
|
+
const { protocol, originalUrl, baseUrl, headers } = req;
|
|
43
|
+
|
|
44
|
+
commonEngine
|
|
45
|
+
.render({
|
|
46
|
+
<% if (isStandalone) { %>bootstrap<% } else { %>bootstrap: AppServerModule<% } %>,
|
|
47
|
+
documentFilePath: indexHtml,
|
|
48
|
+
url: `${protocol}://${headers.host}${originalUrl}`,
|
|
49
|
+
publicPath: browserDistFolder,
|
|
50
|
+
providers: [{ provide: APP_BASE_HREF, useValue: baseUrl }],
|
|
51
|
+
})
|
|
52
|
+
.then((html) => res.send(html))
|
|
53
|
+
.catch((err) => next(err));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Start the server if this module is the main entry point.
|
|
58
|
+
* The server listens on the port defined by the `PORT` environment variable, or defaults to 4000.
|
|
59
|
+
*/
|
|
60
|
+
if (isMainModule(import.meta.url)) {
|
|
61
|
+
const port = process.env['PORT'] || 4000;
|
|
62
|
+
app.listen(port, () => {
|
|
63
|
+
console.log(`Node Express server listening on http://localhost:${port}`);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -5,7 +5,7 @@ import { CommonEngine } from '@angular/ssr/node';
|
|
|
5
5
|
import * as express from 'express';
|
|
6
6
|
import { existsSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
-
import <% if (isStandalone) { %>bootstrap<% } else { %>AppServerModule<% } %> from './
|
|
8
|
+
import <% if (isStandalone) { %>bootstrap<% } else { %>AppServerModule<% } %> from './main.server';
|
|
9
9
|
|
|
10
10
|
// The Express app is exported so that it can be used by serverless Functions.
|
|
11
11
|
export function app(): express.Express {
|
package/ssr/index.js
CHANGED
|
@@ -108,15 +108,14 @@ function updateApplicationBuilderTsConfigRule(options) {
|
|
|
108
108
|
// No tsconfig path
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
111
|
+
const json = new json_file_1.JSONFile(host, tsConfigPath);
|
|
112
|
+
const filesPath = ['files'];
|
|
113
|
+
const files = new Set(json.get(filesPath) ?? []);
|
|
114
|
+
files.add('src/server.ts');
|
|
115
|
+
json.modify(filesPath, [...files]);
|
|
117
116
|
};
|
|
118
117
|
}
|
|
119
|
-
function updateApplicationBuilderWorkspaceConfigRule(
|
|
118
|
+
function updateApplicationBuilderWorkspaceConfigRule(projectSourceRoot, options, { logger }) {
|
|
120
119
|
return (0, utility_1.updateWorkspace)((workspace) => {
|
|
121
120
|
const buildTarget = workspace.projects.get(options.project)?.targets.get('build');
|
|
122
121
|
if (!buildTarget) {
|
|
@@ -140,14 +139,15 @@ function updateApplicationBuilderWorkspaceConfigRule(projectRoot, options, { log
|
|
|
140
139
|
buildTarget.options = {
|
|
141
140
|
...buildTarget.options,
|
|
142
141
|
outputPath,
|
|
143
|
-
|
|
142
|
+
outputMode: options.serverRouting ? 'server' : undefined,
|
|
143
|
+
prerender: options.serverRouting ? undefined : true,
|
|
144
144
|
ssr: {
|
|
145
|
-
entry: (0, core_1.join)((0, core_1.normalize)(
|
|
145
|
+
entry: (0, core_1.join)((0, core_1.normalize)(projectSourceRoot), 'server.ts'),
|
|
146
146
|
},
|
|
147
147
|
};
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
|
-
function updateWebpackBuilderWorkspaceConfigRule(options) {
|
|
150
|
+
function updateWebpackBuilderWorkspaceConfigRule(projectSourceRoot, options) {
|
|
151
151
|
return (0, utility_1.updateWorkspace)((workspace) => {
|
|
152
152
|
const projectName = options.project;
|
|
153
153
|
const project = workspace.projects.get(projectName);
|
|
@@ -156,7 +156,7 @@ function updateWebpackBuilderWorkspaceConfigRule(options) {
|
|
|
156
156
|
}
|
|
157
157
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
158
158
|
const serverTarget = project.targets.get('server');
|
|
159
|
-
(serverTarget.options ??= {}).main =
|
|
159
|
+
(serverTarget.options ??= {}).main = node_path_1.posix.join(projectSourceRoot, 'server.ts');
|
|
160
160
|
const serveSSRTarget = project.targets.get(SERVE_SSR_TARGET_NAME);
|
|
161
161
|
if (serveSSRTarget) {
|
|
162
162
|
return;
|
|
@@ -216,7 +216,7 @@ function updateWebpackBuilderServerTsConfigRule(options) {
|
|
|
216
216
|
}
|
|
217
217
|
const tsConfig = new json_file_1.JSONFile(host, tsConfigPath);
|
|
218
218
|
const filesAstNode = tsConfig.get(['files']);
|
|
219
|
-
const serverFilePath = 'server.ts';
|
|
219
|
+
const serverFilePath = 'src/server.ts';
|
|
220
220
|
if (Array.isArray(filesAstNode) && !filesAstNode.some(({ text }) => text === serverFilePath)) {
|
|
221
221
|
tsConfig.modify(['files'], [...filesAstNode, serverFilePath]);
|
|
222
222
|
}
|
|
@@ -242,7 +242,7 @@ function addDependencies({ skipInstall }, isUsingApplicationBuilder) {
|
|
|
242
242
|
}
|
|
243
243
|
return (0, schematics_1.chain)(rules);
|
|
244
244
|
}
|
|
245
|
-
function addServerFile(options, isStandalone) {
|
|
245
|
+
function addServerFile(projectSourceRoot, options, isStandalone) {
|
|
246
246
|
return async (host) => {
|
|
247
247
|
const projectName = options.project;
|
|
248
248
|
const workspace = await (0, utility_1.readWorkspace)(host);
|
|
@@ -254,14 +254,15 @@ function addServerFile(options, isStandalone) {
|
|
|
254
254
|
const browserDistDirectory = isUsingApplicationBuilder
|
|
255
255
|
? (await getApplicationBuilderOutputPaths(host, projectName)).browser
|
|
256
256
|
: await getLegacyOutputPaths(host, projectName, 'build');
|
|
257
|
-
|
|
257
|
+
const applicationBuilderFiles = 'application-builder' + (options.serverRouting ? '' : '-common-engine');
|
|
258
|
+
return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)(`./files/${isUsingApplicationBuilder ? applicationBuilderFiles : 'server-builder'}`), [
|
|
258
259
|
(0, schematics_1.applyTemplates)({
|
|
259
260
|
...core_1.strings,
|
|
260
261
|
...options,
|
|
261
262
|
browserDistDirectory,
|
|
262
263
|
isStandalone,
|
|
263
264
|
}),
|
|
264
|
-
(0, schematics_1.move)(
|
|
265
|
+
(0, schematics_1.move)(projectSourceRoot),
|
|
265
266
|
]));
|
|
266
267
|
};
|
|
267
268
|
}
|
|
@@ -275,6 +276,7 @@ function default_1(options) {
|
|
|
275
276
|
throw (0, project_targets_1.targetBuildNotFoundError)();
|
|
276
277
|
}
|
|
277
278
|
const isUsingApplicationBuilder = usingApplicationBuilder(clientProject);
|
|
279
|
+
const sourceRoot = clientProject.sourceRoot ?? node_path_1.posix.join(clientProject.root, 'src');
|
|
278
280
|
return (0, schematics_1.chain)([
|
|
279
281
|
(0, schematics_1.schematic)('server', {
|
|
280
282
|
...options,
|
|
@@ -282,14 +284,14 @@ function default_1(options) {
|
|
|
282
284
|
}),
|
|
283
285
|
...(isUsingApplicationBuilder
|
|
284
286
|
? [
|
|
285
|
-
updateApplicationBuilderWorkspaceConfigRule(
|
|
287
|
+
updateApplicationBuilderWorkspaceConfigRule(sourceRoot, options, context),
|
|
286
288
|
updateApplicationBuilderTsConfigRule(options),
|
|
287
289
|
]
|
|
288
290
|
: [
|
|
289
291
|
updateWebpackBuilderServerTsConfigRule(options),
|
|
290
|
-
updateWebpackBuilderWorkspaceConfigRule(options),
|
|
292
|
+
updateWebpackBuilderWorkspaceConfigRule(sourceRoot, options),
|
|
291
293
|
]),
|
|
292
|
-
addServerFile(options, isStandalone),
|
|
294
|
+
addServerFile(sourceRoot, options, isStandalone),
|
|
293
295
|
addScriptsRule(options, isUsingApplicationBuilder),
|
|
294
296
|
addDependencies(options, isUsingApplicationBuilder),
|
|
295
297
|
]);
|
package/ssr/schema.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export interface Schema {
|
|
|
3
3
|
* The name of the project.
|
|
4
4
|
*/
|
|
5
5
|
project: string;
|
|
6
|
+
/**
|
|
7
|
+
* Creates a server application using the Server Routing and App Engine APIs (Developer
|
|
8
|
+
* Preview).
|
|
9
|
+
*/
|
|
10
|
+
serverRouting?: boolean;
|
|
6
11
|
/**
|
|
7
12
|
* Skip installing dependency packages.
|
|
8
13
|
*/
|
package/ssr/schema.json
CHANGED
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
"description": "Skip installing dependency packages.",
|
|
16
16
|
"type": "boolean",
|
|
17
17
|
"default": false
|
|
18
|
+
},
|
|
19
|
+
"serverRouting": {
|
|
20
|
+
"description": "Creates a server application using the Server Routing and App Engine APIs (Developer Preview).",
|
|
21
|
+
"x-prompt": "Would you like to use the Server Routing and App Engine APIs (Developer Preview) for this server application?",
|
|
22
|
+
"type": "boolean",
|
|
23
|
+
"default": false
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
"required": ["project"],
|
|
@@ -15,6 +15,6 @@ exports.latestVersions = {
|
|
|
15
15
|
...dependencies,
|
|
16
16
|
// As Angular CLI works with same minor versions of Angular Framework, a tilde match for the current
|
|
17
17
|
Angular: dependencies['@angular/core'],
|
|
18
|
-
DevkitBuildAngular: '^19.0.0-
|
|
19
|
-
AngularSSR: '^19.0.0-
|
|
18
|
+
DevkitBuildAngular: '^19.0.0-rc.0',
|
|
19
|
+
AngularSSR: '^19.0.0-rc.0',
|
|
20
20
|
};
|
|
@@ -28,7 +28,7 @@ export declare enum Builders {
|
|
|
28
28
|
NgPackagr = "@angular-devkit/build-angular:ng-packagr",
|
|
29
29
|
DevServer = "@angular-devkit/build-angular:dev-server",
|
|
30
30
|
ExtractI18n = "@angular-devkit/build-angular:extract-i18n",
|
|
31
|
-
Protractor = "@angular-devkit/build-angular:protractor",
|
|
31
|
+
Protractor = "@angular-devkit/build-angular:private-protractor",
|
|
32
32
|
BuildApplication = "@angular/build:application"
|
|
33
33
|
}
|
|
34
34
|
export interface FileReplacements {
|
|
@@ -33,6 +33,6 @@ var Builders;
|
|
|
33
33
|
Builders["NgPackagr"] = "@angular-devkit/build-angular:ng-packagr";
|
|
34
34
|
Builders["DevServer"] = "@angular-devkit/build-angular:dev-server";
|
|
35
35
|
Builders["ExtractI18n"] = "@angular-devkit/build-angular:extract-i18n";
|
|
36
|
-
Builders["Protractor"] = "@angular-devkit/build-angular:protractor";
|
|
36
|
+
Builders["Protractor"] = "@angular-devkit/build-angular:private-protractor";
|
|
37
37
|
Builders["BuildApplication"] = "@angular/build:application";
|
|
38
38
|
})(Builders || (exports.Builders = Builders = {}));
|
|
@@ -1,27 +1,59 @@
|
|
|
1
1
|
# <%= utils.classify(name) %>
|
|
2
2
|
|
|
3
|
-
This project was generated
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version <%= version %>.
|
|
4
4
|
|
|
5
5
|
## Development server
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
To start a local development server, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng serve
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Once the server is running, open your browser and navigate to `http://localhost:4200/`. The application will automatically reload whenever you modify any of the source files.
|
|
8
14
|
|
|
9
15
|
## Code scaffolding
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
ng generate component component-name
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
ng generate --help
|
|
27
|
+
```
|
|
12
28
|
|
|
13
|
-
##
|
|
29
|
+
## Building
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
To build the project run:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
ng build
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This will compile your project and store the build artifacts in the `dist/` directory. By default, the production build optimizes your application for performance and speed.
|
|
16
38
|
|
|
17
39
|
## Running unit tests
|
|
18
40
|
|
|
19
|
-
|
|
41
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
ng test
|
|
45
|
+
```
|
|
20
46
|
|
|
21
47
|
## Running end-to-end tests
|
|
22
48
|
|
|
23
|
-
|
|
49
|
+
For end-to-end (e2e) testing, run:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
ng e2e
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
24
56
|
|
|
25
|
-
##
|
|
57
|
+
## Additional Resources
|
|
26
58
|
|
|
27
|
-
|
|
59
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
File without changes
|
/package/server/files/{standalone-src → application-builder/standalone-src}/main.server.ts.template
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|