This repository was archived by the owner on Apr 4, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
packages/schematics/angular/universal Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -161,6 +161,22 @@ function addDependencies(): Rule {
161
161
} ;
162
162
}
163
163
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
+
164
180
export default function ( options : UniversalOptions ) : Rule {
165
181
return ( host : Tree , context : SchematicContext ) => {
166
182
const templateSource = apply ( url ( './files' ) , [
@@ -177,6 +193,7 @@ export default function (options: UniversalOptions): Rule {
177
193
updateConfigFile ( options ) ,
178
194
wrapBootstrapCall ( options ) ,
179
195
addServerTransition ( options ) ,
196
+ updateGitignore ( options ) ,
180
197
] ) ( host , context ) ;
181
198
} ;
182
199
}
Original file line number Diff line number Diff line change @@ -104,4 +104,14 @@ describe('Universal Schematic', () => {
104
104
const contents = tree . read ( filePath ) ;
105
105
expect ( contents ) . toMatch ( / d o c u m e n t .a d d E v e n t L i s t e n e r \( ' D O M C o n t e n t L o a d e d ' , \( \) = > { / ) ;
106
106
} ) ;
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
+ } ) ;
107
117
} ) ;
You can’t perform that action at this time.
0 commit comments