Skip to content

Commit 55590ad

Browse files
1 parent 0cf6295 commit 55590ad

File tree

6 files changed

+392
-21
lines changed

6 files changed

+392
-21
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"build:backend": "cd src/backend && rollup --config rollup.config.js",
2424
"dev": "npm run start",
2525
"build": "npm run build:frontend && npm run build:backend",
26-
"postinstall": "node scripts/installBashIfWindows.js && node scripts/postinstall.js"
26+
"postinstall": "node scripts/postinstall.js"
2727
},
2828
"keywords": [
2929
"cli",
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/bin/sh
2+
set -e
3+
4+
goal="Refactor installBashIfWindows function"
5+
6+
# Plan:
7+
# 1. Create a new directory for the function.
8+
# 2. Move and refactor the function.
9+
# 3. Update the postinstall script to use the function.
10+
# 4. Update package.json.
11+
# 5. Remove the old file from Git.
12+
13+
echo "Plan:"
14+
echo "1. Create a new directory for the function."
15+
echo "2. Move and refactor the function."
16+
echo "3. Update the postinstall script to use the function."
17+
echo "4. Update package.json."
18+
echo "5. Remove the old file from Git."
19+
20+
# Step 1: Create the new directory
21+
mkdir -p scripts/postinstall
22+
23+
# Step 2: Refactor and move the installBashIfWindows function
24+
cat > scripts/postinstall/installBashIfWindows.js << 'EOF'
25+
import { execSync } from 'child_process';
26+
import readline from 'readline';
27+
28+
export async function installBashIfWindows() {
29+
if (process.platform !== 'win32') {
30+
console.log("Not on Windows, skipping bash installation check.");
31+
return;
32+
}
33+
34+
try {
35+
execSync('where bash', { stdio: 'ignore' });
36+
console.log("Bash found in PATH. No installation needed.");
37+
} catch (err) {
38+
console.log("\nWe need Git Bash on Windows to execute changesets generated by the LLM.\n");
39+
console.log("Bash was not found on this system.\n");
40+
41+
const rl = readline.createInterface({
42+
input: process.stdin,
43+
output: process.stdout
44+
});
45+
46+
const question = `
47+
Choose one of the following options to install Git Bash:
48+
1) winget
49+
2) choco
50+
3) Install manually
51+
Enter your choice (1,2 or 3): `;
52+
53+
rl.question(question, (answer) => {
54+
rl.close();
55+
if (answer === '1') {
56+
try {
57+
console.log("\nAttempting to install Git (with Bash) via winget...\n");
58+
execSync('winget install --id Git.Git -e --source winget', { stdio: 'inherit' });
59+
console.log("\nGit (with Bash) installed successfully via winget!\n");
60+
} catch (e) {
61+
console.log("\nFailed to install Git via winget. You may try the other options.\n");
62+
process.exit(1);
63+
}
64+
} else if (answer === '2') {
65+
try {
66+
console.log("\nAttempting to install Git (with Bash) via choco...\n");
67+
execSync('choco install git -y', { stdio: 'inherit' });
68+
console.log("\nGit (with Bash) installed successfully via choco!\n");
69+
} catch (e) {
70+
console.log("\nFailed to install Git via choco. You may try the other options.\n");
71+
process.exit(1);
72+
}
73+
} else {
74+
console.log("\nPlease install Git for Windows manually from: https://git-scm.com/download/win");
75+
console.log("Once Git is installed, 'bash' should be in your PATH.\n");
76+
process.exit(1);
77+
}
78+
});
79+
}
80+
}
81+
EOF
82+
83+
echo "Refactored and moved installBashIfWindows function."
84+
85+
# Step 3: Update the postinstall script
86+
cat > scripts/postinstall.js << 'EOF'
87+
import { installBashIfWindows } from './postinstall/installBashIfWindows.js';
88+
import { execSync } from 'child_process';
89+
90+
export async function validateNodePty() {
91+
try {
92+
console.log('Validating prebuilt binaries for node-pty...');
93+
execSync('node -e "require(\'@homebridge/node-pty-prebuilt-multiarch\')"', { stdio: 'inherit' });
94+
console.log('Validation successful.');
95+
} catch (error) {
96+
console.error('Validation failed. Please check your setup.');
97+
process.exit(1);
98+
}
99+
}
100+
101+
await installBashIfWindows();
102+
await validateNodePty();
103+
EOF
104+
105+
echo "Updated postinstall script to use the refactored function."
106+
107+
# Step 4: Update package.json
108+
jq '.scripts.postinstall = "node scripts/postinstall.js"' package.json > package.json.tmp && mv package.json.tmp package.json
109+
110+
echo "Updated package.json to use the new postinstall script."
111+
112+
# Step 5: Remove the old file from Git
113+
git rm scripts/installBashIfWindows.js
114+
115+
echo "Removed the old installBashIfWindows.js file from Git."
116+
117+
# Completion
118+
echo "\033[32mDone: $goal\033[0m\n"
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
You are a senior software developer, you code like Donald Knuth.
2+
3+
# Task
4+
5+
Implement the following feature!
6+
7+
- Create a plan!
8+
- Create new files when needed!
9+
10+
Requirements:
11+
12+
The install script fails to decide correctly if it runs directly or not because differences in paths:
13+
14+
file:///C:/work/tmp/Junior/scripts/installBashIfWindows.js vs file://C:\work\tmp\Junior\scripts\installBashIfWindows.js
15+
16+
Remove this check, the file should only export the fn, not run it. Instead, move it to a newly created scripts/postinstall/ dir and import it from the postinstall script. Also update package.json accordingly.
17+
18+
19+
## Project Specifics
20+
21+
- Every js file should *only export a single function or signal*! eg.: in createGitRepo.js: export function createGitRepo ( ....
22+
- Use *ES6 imports*!
23+
- Prefer *async/await* over promises!
24+
- The frontend uses *Solidjs* and Tailwind, edit .jsx files accordingly!
25+
26+
Write concise, self-documenting and idiomatic ES6 code!
27+
28+
# Output Format
29+
30+
Encode and enclose your results as ./change.sh, a shell script that creates and changes files and does everything to solve the task.
31+
Avoid using sed. Always heredoc full files.
32+
33+
OS: Debian
34+
35+
36+
Installed tools: npm, jq
37+
38+
39+
40+
41+
EXAMPLE START
42+
```sh
43+
#!/bin/sh
44+
set -e
45+
goal=[Task description, max 9 words]
46+
echo "Plan:"
47+
echo "1. [...]"
48+
49+
# Always provide the complete contents for the modified files without omitting any parts!
50+
cat > x.js << EOF
51+
let i = 1
52+
console.log(\`i: \${i}\`)
53+
EOF
54+
echo "\033[32mDone: $goal\033[0m\n"
55+
```
56+
EXAMPLE END
57+
58+
Before starting, check if you need more files or info to solve the task.
59+
60+
If the task is not clear:
61+
62+
EXAMPLE START
63+
I need more information to solve the task. [Description of the missing info]
64+
EXAMPLE END
65+
66+
Do not edit files not provided in the working set!
67+
If you need more files:
68+
69+
EXAMPLE START
70+
`filepath1` is needed to solve the task but is not in the working set.
71+
EXAMPLE END
72+
73+
# Working set
74+
75+
package.json:
76+
```
77+
{
78+
"name": "@aijunior/dev",
79+
"version": "0.3.22",
80+
"description": "Your AI Contributor which codes itself",
81+
"type": "module",
82+
"main": "src/main.js",
83+
"bin": {
84+
"junior": "dist/bin/web.js",
85+
"junior-web": "dist/bin/web.js",
86+
"junior-cli": "dist/bin/cli.js",
87+
"junior-init": "dist/bin/init.js",
88+
"junior-rollback": "dist/bin/rollback.js",
89+
"junior-news": "dist/bin/readGitHistoryToMd.js"
90+
},
91+
"scripts": {
92+
"cli": "node scripts/cli.js",
93+
"start": "node scripts/dev.js",
94+
"update-logo": "node ./scripts/updateLogo.js",
95+
"clear-branches": "node ./scripts/clearBranchesCommand.js $@",
96+
"test": "cypress open",
97+
"rollback": "node scripts/junior-rollback.js",
98+
"build:frontend": "cd ./src/frontend/ && vite build --emptyOutDir",
99+
"build:backend": "cd src/backend && rollup --config rollup.config.js",
100+
"dev": "npm run start",
101+
"build": "npm run build:frontend && npm run build:backend",
102+
"postinstall": "node scripts/installBashIfWindows.js && node scripts/postinstall.js"
103+
},
104+
"keywords": [
105+
"cli",
106+
"uppercase"
107+
],
108+
"author": "",
109+
"license": "MIT",
110+
"dependencies": {
111+
"@homebridge/node-pty-prebuilt-multiarch": "^0.11.14",
112+
"@types/js-yaml": "^4.0.5",
113+
"autoprefixer": "^10.4.14",
114+
"chatgpt": "^5.2.4",
115+
"cors": "^2.8.5",
116+
"ejs": "^3.1.9",
117+
"express": "^4.18.2",
118+
"highlight.js": "^11.8.0",
119+
"js-yaml": "^4.1.0",
120+
"markdown-it": "^13.0.1",
121+
"marked": "^5.1.0",
122+
"sanitize-filename": "^1.6.3",
123+
"sharp": "^0.32.4",
124+
"simple-git": "^3.19.1",
125+
"solid-js": "^1.7.7",
126+
"tailwindcss": "^3.3.3",
127+
"ws": "^8.13.0",
128+
"xterm": "^5.3.0"
129+
},
130+
"directories": {
131+
"doc": "docs"
132+
},
133+
"repository": {
134+
"type": "git",
135+
"url": "git+https://github.com/tisztamo/Junior.git"
136+
},
137+
"bugs": {
138+
"url": "https://github.com/tisztamo/Junior/issues"
139+
},
140+
"homepage": "https://github.com/tisztamo/Junior#readme",
141+
"devDependencies": {
142+
"@rollup/plugin-node-resolve": "^15.2.3",
143+
"postcss": "^8.4.26",
144+
"postcss-nested": "^6.0.1",
145+
"rollup-plugin-preserve-shebang": "^1.0.1",
146+
"vite": "^4",
147+
"vite-plugin-solid": "^2"
148+
},
149+
"files": [
150+
"dist/",
151+
"prompt/",
152+
"scripts/"
153+
]
154+
}
155+
156+
```
157+
scripts/installBashIfWindows.js:
158+
```
159+
import { execSync } from 'child_process';
160+
import readline from 'readline';
161+
162+
function installBashIfWindows() {
163+
if (process.platform !== 'win32') {
164+
console.log("Not on Windows, skipping bash installation check.");
165+
return;
166+
}
167+
168+
// Try "where bash"
169+
try {
170+
execSync('where bash', { stdio: 'ignore' });
171+
console.log("Bash found in PATH. No installation needed.");
172+
} catch (err) {
173+
// We did not find bash -> prompt user
174+
console.log("\nWe need Git Bash on Windows to execute changesets generated by the LLM.\n");
175+
console.log("Bash was not found on this system.\n");
176+
177+
const rl = readline.createInterface({
178+
input: process.stdin,
179+
output: process.stdout
180+
});
181+
182+
const question = `
183+
Choose one of the following options to install Git Bash:
184+
1) winget
185+
2) choco
186+
3) Install manually
187+
Enter your choice (1,2 or 3): `;
188+
189+
rl.question(question, (answer) => {
190+
rl.close();
191+
if (answer === '1') {
192+
// Try winget install
193+
console.log("\nAttempting to install Git (with Bash) via winget...\n");
194+
try {
195+
execSync('winget install --id Git.Git -e --source winget', { stdio: 'inherit' });
196+
console.log("\nGit (with Bash) installed successfully via winget!\n");
197+
} catch (e) {
198+
console.log("\nFailed to install Git via winget. You may try the other options.\n");
199+
process.exit(1);
200+
}
201+
} else if (answer === '2') {
202+
// Try choco install
203+
console.log("\nAttempting to install Git (with Bash) via choco...\n");
204+
try {
205+
execSync('choco install git -y', { stdio: 'inherit' });
206+
console.log("\nGit (with Bash) installed successfully via choco!\n");
207+
} catch (e) {
208+
console.log("\nFailed to install Git via choco. You may try the other options.\n");
209+
process.exit(1);
210+
}
211+
} else {
212+
// Manual instructions
213+
console.log("\nPlease install Git for Windows manually from: https://git-scm.com/download/win");
214+
console.log("Once Git is installed, 'bash' should be in your PATH.\n");
215+
process.exit(1);
216+
}
217+
});
218+
}
219+
}
220+
221+
// If called directly
222+
if (import.meta.url === `file://${process.argv[1]}`) {
223+
installBashIfWindows();
224+
}
225+
226+
export { installBashIfWindows };
227+
228+
```
229+
scripts/postinstall.js:
230+
```
231+
import { execSync } from 'child_process';
232+
233+
/**
234+
* Validates the prebuilt binaries for node-pty-prebuilt-multiarch.
235+
* Exits the process if validation fails.
236+
*/
237+
export async function validateNodePty() {
238+
try {
239+
console.log('Validating prebuilt binaries for node-pty...');
240+
execSync('node -e "require(\'@homebridge/node-pty-prebuilt-multiarch\')"', { stdio: 'inherit' });
241+
console.log('Validation successful.');
242+
} catch (error) {
243+
console.error('Validation failed. Please check your setup.');
244+
process.exit(1);
245+
}
246+
}
247+
248+
validateNodePty();
249+
250+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
task: prompt\task\feature\implement.md
2+
attention:
3+
- package.json
4+
- scripts/installBashIfWindows.js
5+
- scripts/postinstall.js
6+
requirements: >-
7+
The install script fails to decide correctly if it runs directly or not
8+
because differences in paths:
9+
10+
11+
file:///C:/work/tmp/Junior/scripts/installBashIfWindows.js vs
12+
file://C:\work\tmp\Junior\scripts\installBashIfWindows.js
13+
14+
15+
Remove this check, the file should only export the fn, not run it. Instead,
16+
move it to a newly created scripts/postinstall/ dir and import it from the
17+
postinstall script. Also update package.json accordingly.

0 commit comments

Comments
 (0)