Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 9ebb943

Browse files
authored
feat(express-engine): add option to skip Universal schematic (#1059)
1 parent a8e7292 commit 9ebb943

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

modules/express-engine/schematics/install/index.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,14 @@ describe('Universal Schematic', () => {
5050
expect(schematicRunner.tasks[0].name).toBe('node-package');
5151
expect((schematicRunner.tasks[0].options as {command: string}).command).toBe('install');
5252
});
53+
54+
it('should not add Universal files', () => {
55+
const noUniversal = Object.assign({}, defaultOptions);
56+
noUniversal.skipUniversal = true;
57+
58+
const tree = schematicRunner.runSchematic('ng-add', noUniversal, appTree);
59+
const filePath = '/src/server.main.ts';
60+
const contents = tree.readContent(filePath);
61+
expect(contents).toMatch('');
62+
});
5363
});

modules/express-engine/schematics/install/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ function updateConfigFile(options: UniversalOptions): Rule {
8787
]
8888
}
8989
};
90+
91+
// We have to check if the project config has a server target, because
92+
// if the Universal step in this schematic isn't run, it can't be guaranteed
93+
// to exist
94+
if (!clientProject.architect.server) {
95+
return;
96+
}
97+
9098
clientProject.architect.server.configurations = serverConfig;
9199

92100
const workspacePath = getWorkspacePath(host);
@@ -118,7 +126,8 @@ export default function (options: UniversalOptions): Rule {
118126
]);
119127

120128
return chain([
121-
externalSchematic('@schematics/angular', 'universal', options),
129+
options.skipUniversal ?
130+
noop() : externalSchematic('@schematics/angular', 'universal', options),
122131
updateConfigFile(options),
123132
mergeWith(rootSource),
124133
addDependenciesAndScripts(options),

modules/express-engine/schematics/install/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
"description": "Skip adding Express server file.",
7373
"type": "boolean",
7474
"default": false
75+
},
76+
"skipUniversal": {
77+
"description": "Skip the Angular Universal schematic",
78+
"type": "boolean",
79+
"default": false
7580
}
7681
},
7782
"required": [

modules/express-engine/schematics/install/schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ export interface Schema {
5959
* Skip adding Express server file.
6060
*/
6161
skipServer?: boolean;
62+
/**
63+
* Skip the Angular Universal schematic
64+
*/
65+
skipUniversal?: boolean;
6266
}

0 commit comments

Comments
 (0)