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

Commit 60d46c8

Browse files
committed
Initial commit
0 parents  commit 60d46c8

File tree

11 files changed

+2252
-0
lines changed

11 files changed

+2252
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Serverless directories
108+
.serverless/
109+
110+
# FuseBox cache
111+
.fusebox/
112+
113+
# DynamoDB Local files
114+
.dynamodb/
115+
116+
# TernJS port file
117+
.tern-port
118+
119+
# Stores VSCode versions used for testing VSCode extensions
120+
.vscode-test
121+
122+
# yarn v2
123+
.yarn/cache
124+
.yarn/unplugged
125+
.yarn/build-state.yml
126+
.yarn/install-state.gz
127+
.pnp.*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 CHR-onicles
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Web_project_setup_script
2+
Script to set up apps I use for web development

assets/file-explorer-icons.png

1.46 KB
Loading

assets/icon.jpg

128 KB
Loading

index.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const { mouse, up, down, left, right, Point, straightTo, screen, imageResource, sleep, getActiveWindow, keyboard, Key, centerOf } = require('@nut-tree/nut-js');
2+
const { switchDesktop, checkIfAppIsOpen } = require('./utils/helpers');
3+
require('@nut-tree/template-matcher'); // for image search functionality
4+
const notifier = require('node-notifier');
5+
6+
// String
7+
// notifier.notify('Message');
8+
9+
// Object
10+
const project_chosen = process.argv.slice(2)[0];
11+
// console.log('Project chosen:', project_chosen);
12+
13+
14+
// Settings configs
15+
screen.config.resourceDirectory = "./assets";
16+
screen.config.autoHighlight = true;
17+
// screen.config.highlightDurationMs = 3000;
18+
keyboard.config.autoDelayMs = 100;
19+
20+
(async () => {
21+
22+
// Step 1: Script starts in desktop 1, so switch to desktop 2
23+
// It seems it can't highlight stuff on the desktops screen when it presses win + tab
24+
// assume we are on first desktop and just move to second desktop
25+
await sleep(1000);
26+
await keyboard.type(Key.LeftControl, Key.LeftSuper, Key.Right);
27+
28+
// Step 2: Open Github Desktop
29+
await sleep(1000);
30+
await keyboard.type(Key.LeftSuper);
31+
await sleep(1000);
32+
await keyboard.type('github',);
33+
await sleep(1000);
34+
await keyboard.type(Key.Enter);
35+
36+
// Check to make sure github desktop is open
37+
await sleep(2000);
38+
if (await checkIfAppIsOpen(['github', 'desktop']) === true) console.log("Github desktop opened successfully")
39+
else console.log("There was a problem opening github desktop")
40+
41+
42+
// Step 3: Open project folder using its shortcut with win + r
43+
await sleep(1000);
44+
await keyboard.type(Key.LeftSuper, Key.R);
45+
await sleep(1000)
46+
47+
// Check to make sure Windows Search is open
48+
if (await checkIfAppIsOpen(['run'])) console.log("Run dialog opened successfully")
49+
await sleep(1000);
50+
await keyboard.type(project_chosen || 'cause');
51+
await keyboard.type(Key.Enter);
52+
53+
// 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+
// Step 4: Right-click to open vscode
58+
59+
keyboard.type(Key.LeftShift, Key.F10);
60+
61+
62+
63+
64+
notifier.notify({
65+
title: "Web Project Setup script",
66+
message: `Setup complete, you're good to go with ${project_chosen}`,
67+
icon: './assets/icon.jpg'
68+
});
69+
})()
70+
71+

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "Web_project_setup_node",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"@nut-tree/nut-js": "^2.1.1",
8+
"@nut-tree/template-matcher": "^1.0.1",
9+
"node-notifier": "^10.0.1"
10+
}
11+
}

setup_web_project.bat

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
@echo off
2+
3+
echo Your Projects:
4+
echo 1. Cause
5+
echo 2. Adkasa
6+
echo 3. Polymorph
7+
8+
echo.
9+
10+
@echo off
11+
set /p PROJECT="Select a Project to open: "
12+
:: /A is for working with numbers
13+
14+
echo You selected: %PROJECT%
15+
16+
if %PROJECT% GTR 3 (
17+
echo Invalid choice!
18+
pause
19+
exit
20+
)
21+
22+
if %PROJECT% LSS 1 (
23+
echo Invalid choice!
24+
pause
25+
exit
26+
)
27+
28+
@echo off
29+
A:
30+
31+
cd "A:/A_SOURCE/Local/Web Dev/R HEMI/Web_project_setup_node"
32+
33+
if %PROJECT%==1 node index.js cause
34+
if %PROJECT%==2 node index.js adkasa
35+
if %PROJECT%==3 node index.js polymorph
36+
37+
echo.
38+
@REM pause

utils/helpers.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { keyboard, Key, sleep, getActiveWindow } = require("@nut-tree/nut-js");
2+
3+
exports.switchDesktop = ({ left = false, right = false }) => {
4+
if (left === false && right === false) throw new Error('Please choose a direction to switch desktop to');
5+
if (left === true && right === true) throw new Error('Cannot switch desktop in both directions');
6+
7+
if (left) keyboard.type(Key.LeftSuper, Key.LeftControl, Key.Left);
8+
if (right) keyboard.type(Key.LeftSuper, Key.LeftControl, Key.Right);
9+
}
10+
11+
exports.checkIfAppIsOpen = async (appNames = []) => {
12+
const time_start = Date.now();
13+
const timeout = 15000; // Stop operation after 15 seconds
14+
15+
while (true) {
16+
const windowRef = await getActiveWindow();
17+
const [title, region] = await Promise.all([windowRef.title, windowRef.region]);
18+
console.log(title);
19+
for (const name of appNames) {
20+
if (title.toLocaleLowerCase().includes(name)) {
21+
return true;
22+
}
23+
}
24+
await sleep(1000);
25+
const time_stop = Date.now();
26+
if ((time_stop - time_start) * 1000 > timeout) break;
27+
}
28+
return false;
29+
}

0 commit comments

Comments
 (0)