olly-molly 0.1.2 ā 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +131 -85
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -4,102 +4,148 @@ const { spawn, execSync } = require('child_process');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const os = require('os');
|
|
7
|
+
const https = require('https');
|
|
7
8
|
|
|
8
9
|
const APP_NAME = 'olly-molly';
|
|
9
|
-
const
|
|
10
|
+
const REPO = 'ruucm/olly-molly';
|
|
10
11
|
const APP_DIR = path.join(os.homedir(), '.olly-molly');
|
|
12
|
+
const TARBALL_URL = `https://github.com/${REPO}/archive/refs/heads/main.tar.gz`;
|
|
11
13
|
|
|
12
14
|
console.log('\nš Olly Molly - Your AI Development Team\n');
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
function downloadAndExtract(url, destDir) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const tempFile = path.join(os.tmpdir(), 'olly-molly.tar.gz');
|
|
19
|
+
const file = fs.createWriteStream(tempFile);
|
|
20
|
+
|
|
21
|
+
console.log('š„ Downloading...');
|
|
22
|
+
|
|
23
|
+
const download = (downloadUrl) => {
|
|
24
|
+
https.get(downloadUrl, (response) => {
|
|
25
|
+
// Handle redirects
|
|
26
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
27
|
+
download(response.headers.location);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (response.statusCode !== 200) {
|
|
32
|
+
reject(new Error(`Download failed: ${response.statusCode}`));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
response.pipe(file);
|
|
37
|
+
file.on('finish', () => {
|
|
38
|
+
file.close();
|
|
39
|
+
|
|
40
|
+
console.log('š¦ Extracting...');
|
|
41
|
+
|
|
42
|
+
// Create dest directory
|
|
43
|
+
if (!fs.existsSync(destDir)) {
|
|
44
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Extract tarball
|
|
48
|
+
try {
|
|
49
|
+
execSync(`tar -xzf "${tempFile}" -C "${destDir}" --strip-components=1`, {
|
|
50
|
+
stdio: 'pipe'
|
|
51
|
+
});
|
|
52
|
+
fs.unlinkSync(tempFile);
|
|
53
|
+
resolve();
|
|
54
|
+
} catch (err) {
|
|
55
|
+
reject(err);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}).on('error', reject);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
download(url);
|
|
62
|
+
});
|
|
25
63
|
}
|
|
26
64
|
|
|
27
|
-
|
|
28
|
-
const args = process.argv.slice(2);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
// Clear build cache after update
|
|
37
|
-
const nextDir = path.join(APP_DIR, '.next');
|
|
38
|
-
if (fs.existsSync(nextDir)) {
|
|
39
|
-
fs.rmSync(nextDir, { recursive: true, force: true });
|
|
65
|
+
async function main() {
|
|
66
|
+
const args = process.argv.slice(2);
|
|
67
|
+
|
|
68
|
+
// Update flag
|
|
69
|
+
if (args.includes('--update') || args.includes('-u')) {
|
|
70
|
+
console.log('š Updating Olly Molly...\n');
|
|
71
|
+
if (fs.existsSync(APP_DIR)) {
|
|
72
|
+
fs.rmSync(APP_DIR, { recursive: true, force: true });
|
|
40
73
|
}
|
|
41
|
-
console.log('ā
Updated! Rebuilding...\n');
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error('ā ļø Update failed, continuing with current version');
|
|
44
74
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
process.exit(1);
|
|
75
|
+
|
|
76
|
+
// Download if not exists
|
|
77
|
+
if (!fs.existsSync(APP_DIR)) {
|
|
78
|
+
console.log('š¦ First run - downloading Olly Molly...\n');
|
|
79
|
+
try {
|
|
80
|
+
await downloadAndExtract(TARBALL_URL, APP_DIR);
|
|
81
|
+
console.log('ā
Downloaded!\n');
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('ā Download failed:', error.message);
|
|
84
|
+
console.error('\n Make sure the repository is public at:');
|
|
85
|
+
console.error(` https://github.com/${REPO}\n`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
59
88
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
89
|
+
|
|
90
|
+
// Install dependencies if needed
|
|
91
|
+
const nodeModulesPath = path.join(APP_DIR, 'node_modules');
|
|
92
|
+
if (!fs.existsSync(nodeModulesPath)) {
|
|
93
|
+
console.log('š¦ Installing dependencies (first time only)...\n');
|
|
94
|
+
try {
|
|
95
|
+
execSync('npm install --production', {
|
|
96
|
+
cwd: APP_DIR,
|
|
97
|
+
stdio: 'inherit'
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error('ā Failed to install dependencies');
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Build if needed
|
|
106
|
+
const nextPath = path.join(APP_DIR, '.next');
|
|
107
|
+
if (!fs.existsSync(nextPath)) {
|
|
108
|
+
console.log('šØ Building app (first time only)...\n');
|
|
109
|
+
try {
|
|
110
|
+
execSync('npm run build', {
|
|
111
|
+
cwd: APP_DIR,
|
|
112
|
+
stdio: 'inherit'
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
console.error('ā Failed to build');
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
74
118
|
}
|
|
119
|
+
|
|
120
|
+
console.log('\nš Starting on http://localhost:1234\n');
|
|
121
|
+
console.log(' Press Ctrl+C to stop');
|
|
122
|
+
console.log(' Run "npx olly-molly -u" to update\n');
|
|
123
|
+
|
|
124
|
+
// Start the server
|
|
125
|
+
const server = spawn('npm', ['run', 'start', '--', '--port', '1234'], {
|
|
126
|
+
cwd: APP_DIR,
|
|
127
|
+
stdio: 'inherit',
|
|
128
|
+
shell: true
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
server.on('error', (error) => {
|
|
132
|
+
console.error('ā Failed to start:', error.message);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
server.on('close', (code) => {
|
|
137
|
+
process.exit(code || 0);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Graceful shutdown
|
|
141
|
+
process.on('SIGINT', () => {
|
|
142
|
+
console.log('\nš Bye!');
|
|
143
|
+
server.kill('SIGINT');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
process.on('SIGTERM', () => {
|
|
147
|
+
server.kill('SIGTERM');
|
|
148
|
+
});
|
|
75
149
|
}
|
|
76
150
|
|
|
77
|
-
console.
|
|
78
|
-
console.log(' Press Ctrl+C to stop');
|
|
79
|
-
console.log(' Run "npx olly-molly --update" to get latest version\n');
|
|
80
|
-
|
|
81
|
-
// Start the server
|
|
82
|
-
const server = spawn('npm', ['run', 'start', '--', '--port', '1234'], {
|
|
83
|
-
cwd: APP_DIR,
|
|
84
|
-
stdio: 'inherit',
|
|
85
|
-
shell: true
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
server.on('error', (error) => {
|
|
89
|
-
console.error('ā Failed to start:', error.message);
|
|
90
|
-
process.exit(1);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
server.on('close', (code) => {
|
|
94
|
-
process.exit(code || 0);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Graceful shutdown
|
|
98
|
-
process.on('SIGINT', () => {
|
|
99
|
-
console.log('\nš Bye!');
|
|
100
|
-
server.kill('SIGINT');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
process.on('SIGTERM', () => {
|
|
104
|
-
server.kill('SIGTERM');
|
|
105
|
-
});
|
|
151
|
+
main().catch(console.error);
|