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

Commit 3c6eaca

Browse files
committed
Implemented up to running yarn start
1 parent 60d46c8 commit 3c6eaca

File tree

7 files changed

+95
-11
lines changed

7 files changed

+95
-11
lines changed

assets/chrome-vscode-intersection.png

10.3 KB
Loading

assets/file-explorer-icons.png

-1.46 KB
Binary file not shown.

index.js

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ const { mouse, up, down, left, right, Point, straightTo, screen, imageResource,
22
const { switchDesktop, checkIfAppIsOpen } = require('./utils/helpers');
33
require('@nut-tree/template-matcher'); // for image search functionality
44
const notifier = require('node-notifier');
5+
require('dotenv').config();
56

67
// String
78
// notifier.notify('Message');
89

910
// 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;
1113
// console.log('Project chosen:', project_chosen);
1214

1315

1416
// Settings configs
1517
screen.config.resourceDirectory = "./assets";
1618
screen.config.autoHighlight = true;
1719
// screen.config.highlightDurationMs = 3000;
18-
keyboard.config.autoDelayMs = 100;
20+
keyboard.config.autoDelayMs = 50;
1921

2022
(async () => {
2123

@@ -36,7 +38,7 @@ keyboard.config.autoDelayMs = 100;
3638
// Check to make sure github desktop is open
3739
await sleep(2000);
3840
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")
4042

4143

4244
// Step 3: Open project folder using its shortcut with win + r
@@ -47,16 +49,88 @@ keyboard.config.autoDelayMs = 100;
4749
// Check to make sure Windows Search is open
4850
if (await checkIfAppIsOpen(['run'])) console.log("Run dialog opened successfully")
4951
await sleep(1000);
50-
await keyboard.type(project_chosen || 'cause');
52+
await keyboard.type(project_chosen);
5153
await keyboard.type(Key.Enter);
5254

5355
// 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+
}
5684

5785
// 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);
58113

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);
60134

61135

62136

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"dependencies": {
77
"@nut-tree/nut-js": "^2.1.1",
88
"@nut-tree/template-matcher": "^1.0.1",
9+
"dotenv": "^16.0.1",
910
"node-notifier": "^10.0.1"
1011
}
1112
}

setup_web_project.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ echo Your Projects:
44
echo 1. Cause
55
echo 2. Adkasa
66
echo 3. Polymorph
7+
echo 4. MZPEM
78

89
echo.
910

@@ -13,7 +14,7 @@ set /p PROJECT="Select a Project to open: "
1314

1415
echo You selected: %PROJECT%
1516

16-
if %PROJECT% GTR 3 (
17+
if %PROJECT% GTR 4 (
1718
echo Invalid choice!
1819
pause
1920
exit
@@ -33,6 +34,7 @@ cd "A:/A_SOURCE/Local/Web Dev/R HEMI/Web_project_setup_node"
3334
if %PROJECT%==1 node index.js cause
3435
if %PROJECT%==2 node index.js adkasa
3536
if %PROJECT%==3 node index.js polymorph
37+
if %PROJECT%==4 node index.js mzpem
3638

3739
echo.
3840
@REM pause

utils/helpers.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,23 @@ exports.switchDesktop = ({ left = false, right = false }) => {
99
}
1010

1111
exports.checkIfAppIsOpen = async (appNames = []) => {
12+
let isOpen = false;
1213
const time_start = Date.now();
1314
const timeout = 15000; // Stop operation after 15 seconds
1415

1516
while (true) {
1617
const windowRef = await getActiveWindow();
1718
const [title, region] = await Promise.all([windowRef.title, windowRef.region]);
18-
console.log(title);
19+
// console.log(title);
1920
for (const name of appNames) {
20-
if (title.toLocaleLowerCase().includes(name)) {
21+
if (title.toLocaleLowerCase().includes(name.toLocaleLowerCase())) {
22+
isOpen = true;
2123
return true;
2224
}
25+
if ((appNames.indexOf(name) === appNames.length - 1) && !isOpen) return false;
2326
}
2427
await sleep(1000);
2528
const time_stop = Date.now();
2629
if ((time_stop - time_start) * 1000 > timeout) break;
2730
}
28-
return false;
2931
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ dom-walk@^0.1.0:
692692
resolved "https://registry.yarnpkg.com/dom-walk/-/dom-walk-0.1.2.tgz#0c548bef048f4d1f2a97249002236060daa3fd84"
693693
integrity sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==
694694

695+
dotenv@^16.0.1:
696+
version "16.0.1"
697+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.1.tgz#8f8f9d94876c35dac989876a5d3a82a267fdce1d"
698+
integrity sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==
699+
695700
duplexer2@~0.1.4:
696701
version "0.1.4"
697702
resolved "https://registry.yarnpkg.com/duplexer2/-/duplexer2-0.1.4.tgz#8b12dab878c0d69e3e7891051662a32fc6bddcc1"

0 commit comments

Comments
 (0)