Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 840281b

Browse files
Broccoclydin
authored andcommitted
fix(@schematics/angular): Add universal outDir to gitignore.
Fixes #323
1 parent 49223a5 commit 840281b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

packages/schematics/angular/universal/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,22 @@ function addDependencies(): Rule {
161161
};
162162
}
163163

164+
function updateGitignore(options: UniversalOptions): Rule {
165+
return (host: Tree) => {
166+
const ignorePath = normalize('/.gitignore');
167+
const buffer = host.read(ignorePath);
168+
if (buffer === null) {
169+
// Assumption is made that there is no git repository.
170+
return host;
171+
} else {
172+
const content = buffer.toString();
173+
host.overwrite(ignorePath, `${content}\n${options.outDir}`);
174+
}
175+
176+
return host;
177+
};
178+
}
179+
164180
export default function (options: UniversalOptions): Rule {
165181
return (host: Tree, context: SchematicContext) => {
166182
const templateSource = apply(url('./files'), [
@@ -177,6 +193,7 @@ export default function (options: UniversalOptions): Rule {
177193
updateConfigFile(options),
178194
wrapBootstrapCall(options),
179195
addServerTransition(options),
196+
updateGitignore(options),
180197
])(host, context);
181198
};
182199
}

packages/schematics/angular/universal/index_spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,14 @@ describe('Universal Schematic', () => {
104104
const contents = tree.read(filePath);
105105
expect(contents).toMatch(/document.addEventListener\('DOMContentLoaded', \(\) => {/);
106106
});
107+
108+
it('should update .gitignore with the server outDir', () => {
109+
const outDir = 'my-out-dir';
110+
const options = {...defaultOptions, outDir: outDir};
111+
const tree = schematicRunner.runSchematic('universal', options, appTree);
112+
const filePath = '/.gitignore';
113+
const contents = tree.read(filePath) || new Buffer('');
114+
115+
expect(contents).toMatch(outDir);
116+
});
107117
});

0 commit comments

Comments
 (0)