@balcnix/fast-deploy 1.0.1 → 1.0.2
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 +15 -137
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -1,128 +1,7 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { execSync, spawn } = require('child_process');
|
|
6
|
-
const { builtinModules } = require('module');
|
|
7
|
-
const readline = require('readline');
|
|
8
|
-
const chalk = require('chalk');
|
|
9
|
-
const ora = require('ora');
|
|
10
|
-
|
|
11
|
-
const args = process.argv.slice(2);
|
|
12
|
-
const command = args[0];
|
|
13
|
-
const cwd = process.cwd();
|
|
14
|
-
const isWin = process.platform === 'win32';
|
|
15
|
-
|
|
16
|
-
if (command !== 'deploy') {
|
|
17
|
-
console.log(chalk.red('\n✖ Unknown command. ') + chalk.white('Usage: ') + chalk.cyan('balcnix deploy\n'));
|
|
18
|
-
process.exit(1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Run shell commands silently
|
|
22
|
-
function runCmd(cmd) {
|
|
23
|
-
execSync(cmd, { cwd, stdio: 'pipe' });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Detect whether python3 or python is available on the machine
|
|
27
|
-
function getSystemPython() {
|
|
28
|
-
try {
|
|
29
|
-
execSync('python3 --version', { stdio: 'pipe' });
|
|
30
|
-
return 'python3';
|
|
31
|
-
} catch {
|
|
32
|
-
try {
|
|
33
|
-
execSync('python --version', { stdio: 'pipe' });
|
|
34
|
-
return 'python';
|
|
35
|
-
} catch {
|
|
36
|
-
throw new Error('Python is not installed on this system.');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Wait for Enter key press
|
|
42
|
-
function waitForEnter() {
|
|
43
|
-
return new Promise((resolve) => {
|
|
44
|
-
const rl = readline.createInterface({
|
|
45
|
-
input: process.stdin,
|
|
46
|
-
output: process.stdout,
|
|
47
|
-
});
|
|
48
|
-
rl.question(
|
|
49
|
-
chalk.bgGreen.black.bold('\n PRESS ENTER ') + chalk.green(' to launch project console... '),
|
|
50
|
-
() => {
|
|
51
|
-
rl.close();
|
|
52
|
-
resolve();
|
|
53
|
-
}
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Scan .js / .ts files for external npm packages & ESM syntax
|
|
59
|
-
function scanNodeProject(dir) {
|
|
60
|
-
const deps = new Set();
|
|
61
|
-
let usesESM = false;
|
|
62
|
-
const ignoreDirs = new Set(['node_modules', '.git', 'dist', 'build', 'venv', '.venv']);
|
|
63
|
-
|
|
64
|
-
function walk(currentDir) {
|
|
65
|
-
for (const item of fs.readdirSync(currentDir)) {
|
|
66
|
-
if (ignoreDirs.has(item) || item.startsWith('.')) continue;
|
|
67
|
-
const fullPath = path.join(currentDir, item);
|
|
68
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
69
|
-
walk(fullPath);
|
|
70
|
-
} else if (item.endsWith('.js') || item.endsWith('.ts')) {
|
|
71
|
-
const content = fs.readFileSync(fullPath, 'utf8');
|
|
72
|
-
if (/^\s*(?:import\s+|export\s+)/m.test(content)) {
|
|
73
|
-
usesESM = true;
|
|
74
|
-
}
|
|
75
|
-
const regex = /(?:require\(|from\s+|import\s+)['"]([^'"./][^'"]*)['"]/g;
|
|
76
|
-
let match;
|
|
77
|
-
while ((match = regex.exec(content)) !== null) {
|
|
78
|
-
let pkg = match[1];
|
|
79
|
-
pkg = pkg.startsWith('@') ? pkg.split('/').slice(0, 2).join('/') : pkg.split('/')[0];
|
|
80
|
-
const clean = pkg.replace(/^node:/, '');
|
|
81
|
-
if (!builtinModules.includes(clean)) deps.add(pkg);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
walk(dir);
|
|
87
|
-
return { deps: Array.from(deps), usesESM };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Scan .py files for external pip packages
|
|
91
|
-
function scanPythonDeps(dir) {
|
|
92
|
-
const deps = new Set();
|
|
93
|
-
const stdLib = new Set([
|
|
94
|
-
'os', 'sys', 'json', 'math', 'time', 'datetime', 're', 'random', 'pathlib',
|
|
95
|
-
'subprocess', 'threading', 'asyncio', 'typing', 'collections', 'itertools',
|
|
96
|
-
'functools', 'urllib', 'http', 'sqlite3', 'csv', 'logging', 'unittest',
|
|
97
|
-
'shutil', 'glob', 'hashlib', 'hmac', 'base64', 'uuid', 'socket', 'ssl',
|
|
98
|
-
'argparse', 'configparser', 'io', 'tempfile', 'traceback', 'inspect'
|
|
99
|
-
]);
|
|
100
|
-
const ignoreDirs = new Set(['venv', '.venv', '__pycache__', '.git', 'node_modules']);
|
|
101
|
-
|
|
102
|
-
function walk(currentDir) {
|
|
103
|
-
for (const item of fs.readdirSync(currentDir)) {
|
|
104
|
-
if (ignoreDirs.has(item) || item.startsWith('.')) continue;
|
|
105
|
-
const fullPath = path.join(currentDir, item);
|
|
106
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
107
|
-
walk(fullPath);
|
|
108
|
-
} else if (item.endsWith('.py')) {
|
|
109
|
-
const content = fs.readFileSync(fullPath, 'utf8');
|
|
110
|
-
const regex = /^\s*(?:import|from)\s+([a-zA-Z0-9_]+)/gm;
|
|
111
|
-
let match;
|
|
112
|
-
while ((match = regex.exec(content)) !== null) {
|
|
113
|
-
const mod = match[1];
|
|
114
|
-
if (!stdLib.has(mod)) deps.add(mod);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
walk(dir);
|
|
120
|
-
return Array.from(deps);
|
|
121
|
-
}
|
|
122
1
|
async function deploy() {
|
|
123
2
|
const startTime = Date.now();
|
|
124
3
|
console.clear();
|
|
125
|
-
console.log(chalk.bold.white('\n> balcnix deploy ') + chalk.gray('v1.0.
|
|
4
|
+
console.log(chalk.bold.white('\n> balcnix deploy ') + chalk.gray('v1.0.2\n'));
|
|
126
5
|
|
|
127
6
|
const spinner = ora({ text: 'Fetching & scanning project files...', color: 'cyan' }).start();
|
|
128
7
|
await new Promise((r) => setTimeout(r, 350));
|
|
@@ -132,6 +11,7 @@ async function deploy() {
|
|
|
132
11
|
|
|
133
12
|
let stack = '';
|
|
134
13
|
let startCmd = '';
|
|
14
|
+
let entryDisplay = '';
|
|
135
15
|
let pkgCount = 0;
|
|
136
16
|
let envNote = 'default';
|
|
137
17
|
|
|
@@ -139,13 +19,11 @@ async function deploy() {
|
|
|
139
19
|
// ================= NODE.JS =================
|
|
140
20
|
if (files.includes('package.json') || files.some((f) => f.endsWith('.js') || f.endsWith('.ts'))) {
|
|
141
21
|
stack = 'Node.js';
|
|
142
|
-
const entryFile =
|
|
143
|
-
|
|
144
|
-
files.find((f) => f.endsWith('.js'));
|
|
22
|
+
const { deps: detected, usesESM, entryFile } = scanNodeProject(cwd);
|
|
23
|
+
entryDisplay = entryFile;
|
|
145
24
|
|
|
146
25
|
if (!files.includes('package.json')) {
|
|
147
26
|
spinner.start('No package.json found. Scanning imports & building...');
|
|
148
|
-
const { deps: detected, usesESM } = scanNodeProject(cwd);
|
|
149
27
|
pkgCount = detected.length;
|
|
150
28
|
|
|
151
29
|
runCmd('npm init -y');
|
|
@@ -172,6 +50,7 @@ async function deploy() {
|
|
|
172
50
|
runCmd('npm install');
|
|
173
51
|
const pkgData = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
|
|
174
52
|
pkgCount = Object.keys(pkgData.dependencies || {}).length;
|
|
53
|
+
if (pkgData.main) entryDisplay = pkgData.main;
|
|
175
54
|
spinner.succeed(chalk.green('Dependencies installed'));
|
|
176
55
|
}
|
|
177
56
|
|
|
@@ -179,22 +58,20 @@ async function deploy() {
|
|
|
179
58
|
startCmd =
|
|
180
59
|
finalPkg.scripts && finalPkg.scripts.start
|
|
181
60
|
? 'npm start'
|
|
182
|
-
: `node ${finalPkg.main || entryFile
|
|
61
|
+
: `node ${finalPkg.main || entryFile}`;
|
|
183
62
|
|
|
184
63
|
// ================= PYTHON =================
|
|
185
64
|
} else if (files.includes('requirements.txt') || files.some((f) => f.endsWith('.py'))) {
|
|
186
65
|
stack = 'Python';
|
|
187
66
|
const sysPython = getSystemPython();
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
files.find((f) => f.endsWith('.py'));
|
|
67
|
+
const { deps: detected, entryFile } = scanPythonProject(cwd);
|
|
68
|
+
entryDisplay = entryFile;
|
|
191
69
|
|
|
192
70
|
if (!files.includes('requirements.txt')) {
|
|
193
71
|
spinner.start('No requirements.txt found. Scanning imports & building...');
|
|
194
|
-
const detected = scanPythonDeps(cwd);
|
|
195
72
|
pkgCount = detected.length;
|
|
196
73
|
fs.writeFileSync(path.join(cwd, 'requirements.txt'), detected.join('\n'));
|
|
197
|
-
spinner.succeed(chalk.green(`Built requirements.txt (${pkgCount} packages detected)`));
|
|
74
|
+
spinner.succeed(chalk.green(`Built requirements.txt (${pkgCount} packages: ${detected.join(', ') || 'none'})`));
|
|
198
75
|
} else {
|
|
199
76
|
const reqs = fs.readFileSync(path.join(cwd, 'requirements.txt'), 'utf8')
|
|
200
77
|
.split('\n')
|
|
@@ -203,7 +80,6 @@ async function deploy() {
|
|
|
203
80
|
pkgCount = reqs.length;
|
|
204
81
|
}
|
|
205
82
|
|
|
206
|
-
// Create/use isolated .venv so Fedora/Ubuntu never throws externally-managed-environment error
|
|
207
83
|
const venvDir = path.join(cwd, '.venv');
|
|
208
84
|
const venvPython = isWin
|
|
209
85
|
? path.join(venvDir, 'Scripts', 'python.exe')
|
|
@@ -222,15 +98,16 @@ async function deploy() {
|
|
|
222
98
|
runCmd(`"${venvPip}" install -r requirements.txt`);
|
|
223
99
|
spinner.succeed(chalk.green('Python dependencies installed'));
|
|
224
100
|
envNote = '.venv isolated';
|
|
225
|
-
startCmd = `"${venvPython}" ${
|
|
101
|
+
startCmd = `"${venvPython}" ${entryFile}`;
|
|
226
102
|
} else {
|
|
227
103
|
envNote = sysPython;
|
|
228
|
-
startCmd = `${sysPython} ${
|
|
104
|
+
startCmd = `${sysPython} ${entryFile}`;
|
|
229
105
|
}
|
|
230
106
|
|
|
231
107
|
// ================= RUST =================
|
|
232
108
|
} else if (files.includes('Cargo.toml') || files.some((f) => f.endsWith('.rs'))) {
|
|
233
109
|
stack = 'Rust';
|
|
110
|
+
entryDisplay = 'src/main.rs';
|
|
234
111
|
if (!files.includes('Cargo.toml')) {
|
|
235
112
|
spinner.start('No Cargo.toml found. Initializing Rust project...');
|
|
236
113
|
runCmd('cargo init');
|
|
@@ -253,15 +130,15 @@ async function deploy() {
|
|
|
253
130
|
console.log(chalk.green.bold(`\n> Ready in ${elapsed}s → `) + chalk.white(path.basename(cwd)));
|
|
254
131
|
console.log(chalk.gray('──────────────────────────────────────────────'));
|
|
255
132
|
console.log(`${chalk.gray('stack')} ${chalk.cyan(stack)} ${chalk.gray(`(${envNote})`)}`);
|
|
133
|
+
console.log(`${chalk.gray('entry')} ${chalk.magenta(entryDisplay)}`);
|
|
256
134
|
console.log(`${chalk.gray('packages')} ${chalk.white(pkgCount + ' synced')}`);
|
|
257
|
-
console.log(`${chalk.gray('command')} ${chalk.yellow(path.basename(startCmd.replace(/"/g, '')))}`);
|
|
258
135
|
console.log(`${chalk.gray('status')} ${chalk.green('100% ready')}`);
|
|
259
136
|
console.log(chalk.gray('──────────────────────────────────────────────'));
|
|
260
137
|
|
|
261
138
|
// Wait for Enter, then drop into live project console
|
|
262
139
|
await waitForEnter();
|
|
263
140
|
console.clear();
|
|
264
|
-
console.log(chalk.gray(`Launching
|
|
141
|
+
console.log(chalk.gray(`Launching ${entryDisplay} in ${cwd}...\n`));
|
|
265
142
|
|
|
266
143
|
const child = spawn(startCmd, { cwd, stdio: 'inherit', shell: true });
|
|
267
144
|
child.on('error', (err) => {
|
|
@@ -283,3 +160,4 @@ async function deploy() {
|
|
|
283
160
|
}
|
|
284
161
|
|
|
285
162
|
deploy();
|
|
163
|
+
|