1
1
const debug = require ( 'debug' ) ( 'add-typescript-to-cypress' )
2
2
const chalk = require ( 'chalk' )
3
+ const terminalBanner = require ( 'terminal-banner' ) . terminalBanner
3
4
const amDependency = require ( 'am-i-a-dependency' ) ( )
5
+
4
6
if ( amDependency ) {
5
- console . log ( 'adding TypeScript plugin to Cypress' )
6
- console . log ( 'current folder' , process . cwd ( ) )
7
+ debug ( 'current folder' , process . cwd ( ) )
7
8
8
9
const fs = require ( 'fs' )
9
10
const path = require ( 'path' )
@@ -17,6 +18,18 @@ if (amDependency) {
17
18
// node_modules/@bahmutov /add-typescript-to-cypress
18
19
const root = path . join ( process . cwd ( ) , '..' , '..' , '..' )
19
20
const cypressFolder = path . join ( root , 'cypress' )
21
+ const pluginsFolder = path . join ( cypressFolder , 'plugins' )
22
+ const ourPreprocessorFilename = path . join (
23
+ pluginsFolder ,
24
+ 'cy-ts-preprocessor.js'
25
+ )
26
+
27
+ if ( fs . existsSync ( ourPreprocessorFilename ) ) {
28
+ debug ( 'found existing file' , ourPreprocessorFilename )
29
+ debug ( 'no need to overwrite again' )
30
+ process . exit ( 0 )
31
+ }
32
+
20
33
if ( ! fs . existsSync ( cypressFolder ) ) {
21
34
console . error ( '⚠️ Cannot find "cypress" folder in %s' , chalk . yellow ( root ) )
22
35
console . error ( 'Please scaffold Cypress folder by opening Cypress once' )
@@ -32,10 +45,14 @@ if (amDependency) {
32
45
}
33
46
34
47
const addPluginFile = ( ) => {
35
- const plugins = path . join ( cypressFolder , 'plugins ')
36
- const pluginsIndex = path . join ( plugins , 'index.js' )
48
+ console . log ( 'copying plugin file ')
49
+ const pluginsIndex = path . join ( pluginsFolder , 'index.js' )
37
50
const sourcePlugin = path . join ( __dirname , 'plugin.js' )
38
51
shell . cp ( sourcePlugin , pluginsIndex )
52
+
53
+ console . log ( 'copying TS preprocessor file' )
54
+ const sourcePreprocessor = path . join ( __dirname , 'cy-ts-preprocessor.js' )
55
+ shell . cp ( sourcePreprocessor , ourPreprocessorFilename )
39
56
}
40
57
41
58
const addTSConfigFile = ( ) => {
@@ -52,6 +69,7 @@ if (amDependency) {
52
69
}
53
70
}
54
71
72
+ terminalBanner ( 'adding TypeScript plugin for Cypress' )
55
73
addPluginFile ( )
56
74
addTSConfigFile ( )
57
75
} else {
0 commit comments