@@ -2,20 +2,22 @@ const { mouse, up, down, left, right, Point, straightTo, screen, imageResource,
2
2
const { switchDesktop, checkIfAppIsOpen } = require ( './utils/helpers' ) ;
3
3
require ( '@nut-tree/template-matcher' ) ; // for image search functionality
4
4
const notifier = require ( 'node-notifier' ) ;
5
+ require ( 'dotenv' ) . config ( ) ;
5
6
6
7
// String
7
8
// notifier.notify('Message');
8
9
9
10
// Object
10
- const project_chosen = process . argv . slice ( 2 ) [ 0 ] ;
11
+ const default_project = 'cause' ;
12
+ const project_chosen = process . argv . slice ( 2 ) [ 0 ] || default_project ;
11
13
// console.log('Project chosen:', project_chosen);
12
14
13
15
14
16
// Settings configs
15
17
screen . config . resourceDirectory = "./assets" ;
16
18
screen . config . autoHighlight = true ;
17
19
// screen.config.highlightDurationMs = 3000;
18
- keyboard . config . autoDelayMs = 100 ;
20
+ keyboard . config . autoDelayMs = 50 ;
19
21
20
22
( async ( ) => {
21
23
@@ -36,7 +38,7 @@ keyboard.config.autoDelayMs = 100;
36
38
// Check to make sure github desktop is open
37
39
await sleep ( 2000 ) ;
38
40
if ( await checkIfAppIsOpen ( [ 'github' , 'desktop' ] ) === true ) console . log ( "Github desktop opened successfully" )
39
- else console . log ( "There was a problem opening github desktop" )
41
+ else console . error ( "There was a problem opening github desktop" )
40
42
41
43
42
44
// Step 3: Open project folder using its shortcut with win + r
@@ -47,16 +49,88 @@ keyboard.config.autoDelayMs = 100;
47
49
// Check to make sure Windows Search is open
48
50
if ( await checkIfAppIsOpen ( [ 'run' ] ) ) console . log ( "Run dialog opened successfully" )
49
51
await sleep ( 1000 ) ;
50
- await keyboard . type ( project_chosen || 'cause' ) ;
52
+ await keyboard . type ( project_chosen ) ;
51
53
await keyboard . type ( Key . Enter ) ;
52
54
53
55
// Check to make sure file explorer opened
54
- await sleep ( 1000 ) ;
55
- if ( await checkIfAppIsOpen ( [ 'file explorer' ] ) ) console . log ( 'file explorer opened successfully' )
56
+
57
+ // Helper function to prevent repetition
58
+ const logHelper = async ( path ) => {
59
+ await sleep ( 1000 ) ;
60
+ if ( await checkIfAppIsOpen ( [ path ] ) === true ) console . log ( `${ project_chosen } folder opened successfully` )
61
+ else console . error ( `There was a problem opening ${ project_chosen } folder` ) ;
62
+ }
63
+
64
+ switch ( project_chosen ) {
65
+ case 'cause' :
66
+ logHelper ( process . env . CAUSE_PATH ) ;
67
+ break ;
68
+
69
+ case 'adkasa' :
70
+ logHelper ( process . env . ADKASA_PATH ) ;
71
+ break ;
72
+
73
+ case 'polymorph' :
74
+ logHelper ( process . env . POLYMORPH_PATH ) ;
75
+ break ;
76
+
77
+ case 'mzpem' :
78
+ logHelper ( process . env . MZPEM_PATH ) ;
79
+ break ;
80
+
81
+ default :
82
+ throw new Error ( "Project chosen is not valid!" ) ;
83
+ }
56
84
57
85
// Step 4: Right-click to open vscode
86
+ await sleep ( 1000 ) ;
87
+ await keyboard . type ( Key . LeftShift , Key . F10 ) ;
88
+ await sleep ( 1000 ) ;
89
+ await keyboard . type ( Key . I ) ;
90
+
91
+ // Check if VSCode is open
92
+ await sleep ( 1000 ) ;
93
+ if ( await checkIfAppIsOpen ( [ 'visual' , 'studio' , 'code' ] ) === true ) console . log ( "VSCode opened successfully" ) ;
94
+ else console . error ( "There was a problem opening VSCode" ) ;
95
+
96
+ // Step 5: Open Chrome
97
+ await sleep ( 1000 ) ;
98
+ await keyboard . type ( Key . LeftSuper ) ;
99
+ await sleep ( 1000 ) ;
100
+ await keyboard . type ( 'chrome' ) ;
101
+ await keyboard . type ( Key . Enter ) ;
102
+
103
+ // Check if Chrome is open
104
+ await sleep ( 1000 ) ;
105
+ if ( await checkIfAppIsOpen ( [ 'google' , 'chrome' ] ) === true ) console . log ( "Google Chrome opened successfully" ) ;
106
+ else console . error ( "There was a problem opening Google Chrome" ) ;
107
+
108
+ // Step 6: Snap Chrome to left side of screen
109
+ await sleep ( 1000 ) ;
110
+ await keyboard . type ( Key . LeftSuper , Key . Left ) ;
111
+ await sleep ( 500 ) ;
112
+ await keyboard . type ( Key . LeftSuper , Key . Left ) ;
58
113
59
- keyboard . type ( Key . LeftShift , Key . F10 ) ;
114
+ // Step 7: Press Enter to keep VSCode on right side of screen
115
+ await sleep ( 1000 ) ;
116
+ await keyboard . type ( Key . Enter ) ;
117
+
118
+ // Step 8: Locate intersection of Chrome and VSCode and drag to reduce Chrome to smallest width
119
+ try {
120
+ const location = await screen . waitFor ( imageResource ( 'chrome-vscode-intersection.png' ) , 7000 , 1000 ) ;
121
+ await mouse . move ( straightTo ( centerOf ( location ) ) ) ;
122
+ await mouse . move ( right ( 3 ) ) ;
123
+ await mouse . drag ( left ( 550 ) ) ;
124
+ } catch ( error ) {
125
+ console . error ( error ) ;
126
+ }
127
+
128
+ // Step 9: Open VSCode terminal and type yarn start
129
+ await sleep ( 1000 ) ;
130
+ await keyboard . type ( Key . LeftControl , Key . Grave ) ;
131
+ await sleep ( 1000 ) ;
132
+ await keyboard . type ( "yarn start" ) ;
133
+ await keyboard . type ( Key . Enter ) ;
60
134
61
135
62
136
0 commit comments