Skip to content

Commit a488e65

Browse files
Broccohansl
authored andcommitted
fix(@schematics/angular): Use existing universal app if it exists.
Fixes #295
1 parent 7de45c2 commit a488e65

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/schematics/angular/app-shell/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ function getServerModulePath(host: Tree, app: AppConfig): string | null {
6666

6767
function addUniversalApp(options: AppShellOptions): Rule {
6868
return (host: Tree, context: SchematicContext) => {
69+
const config = getConfig(host);
70+
const appConfig = getAppFromConfig(config, options.universalApp);
71+
72+
if (appConfig && appConfig.platform === 'server') {
73+
return host;
74+
} else if (appConfig && appConfig.platform !== 'server') {
75+
throw new SchematicsException(
76+
`Invalid platform for universal app (${options.universalApp}), value must be "server".`);
77+
}
78+
6979
// Copy options.
7080
const universalOptions = {
7181
...options,

packages/schematics/angular/app-shell/index_spec.ts

+17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ describe('App Shell Schematic', () => {
5050
expect(file).toBeDefined();
5151
});
5252

53+
it('should use an existing universal app', () => {
54+
const universalOptions = {
55+
name: defaultOptions.universalApp,
56+
};
57+
58+
let tree: Tree = schematicRunner.runSchematic('universal', universalOptions, appTree);
59+
const filePath = '/.angular-cli.json';
60+
let content = tree.read(filePath) || new Buffer('');
61+
let config = JSON.parse(content.toString());
62+
const appCount = config.apps.length;
63+
64+
tree = schematicRunner.runSchematic('appShell', defaultOptions, tree);
65+
content = tree.read(filePath) || new Buffer('');
66+
config = JSON.parse(content.toString());
67+
expect(config.apps.length).toBe(appCount);
68+
});
69+
5370
it('should add app shell configuration', () => {
5471
const tree = schematicRunner.runSchematic('appShell', defaultOptions, appTree);
5572
const filePath = '/.angular-cli.json';

0 commit comments

Comments
 (0)