13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- import path from 'path' ;
17
16
import fs from 'fs' ;
17
+ import path from 'path' ;
18
18
19
- import { prompt } from 'enquirer' ;
20
19
import colors from 'ansi-colors' ;
20
+ import { prompt } from 'enquirer' ;
21
21
import ini from 'ini' ;
22
22
23
- import { executeCommands , createFiles , executeTemplate , Command , languageToFileExtension , getFileExtensionCT } from './utils' ;
24
23
import { type PackageManager , determinePackageManager } from './packageManager' ;
24
+ import { Command , createFiles , executeCommands , executeTemplate , getFileExtensionCT , languageToFileExtension } from './utils' ;
25
25
26
26
export type PromptOptions = {
27
27
testDir : string ,
@@ -271,7 +271,9 @@ export class Generator {
271
271
let gitIgnore = '' ;
272
272
if ( fs . existsSync ( gitIgnorePath ) )
273
273
gitIgnore = fs . readFileSync ( gitIgnorePath , 'utf-8' ) . trimEnd ( ) + '\n' ;
274
- const valuesToAdd = {
274
+
275
+ let thisIsTheFirstLineWeAreAdding = true ;
276
+ const valuesToAdd = {
275
277
'node_modules/' : / ^ n o d e _ m o d u l e s \/ ? / m,
276
278
'/test-results/' : / ^ \/ ? t e s t - r e s u l t s \/ ? $ / m,
277
279
'/playwright-report/' : / ^ \/ p l a y w r i g h t - r e p o r t \/ ? $ / m,
@@ -280,6 +282,11 @@ export class Generator {
280
282
} ;
281
283
Object . entries ( valuesToAdd ) . forEach ( ( [ value , regex ] ) => {
282
284
if ( ! gitIgnore . match ( regex ) ) {
285
+ if ( thisIsTheFirstLineWeAreAdding ) {
286
+ gitIgnore += `\n# Playwright\n` ;
287
+ thisIsTheFirstLineWeAreAdding = false ;
288
+ }
289
+
283
290
gitIgnore += `${ value } \n` ;
284
291
}
285
292
} ) ;
0 commit comments