@balcnix/fast-deploy 1.0.2 → 1.0.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.
Files changed (2) hide show
  1. package/bin/cli.js +202 -7
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -1,7 +1,208 @@
1
+ cat << 'EOF' > /mnt/master1/fast-deploy/bin/cli.js
2
+ #!/usr/bin/env node
3
+
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { execSync, spawn } = require('child_process');
7
+ const { builtinModules } = require('module');
8
+ const readline = require('readline');
9
+ const chalk = require('chalk');
10
+ const ora = require('ora');
11
+
12
+ const args = process.argv.slice(2);
13
+ const command = args[0];
14
+ const cwd = process.cwd();
15
+ const isWin = process.platform === 'win32';
16
+
17
+ if (command !== 'deploy') {
18
+ console.log(chalk.red('\n✖ Unknown command. ') + chalk.white('Usage: ') + chalk.cyan('balcnix deploy\n'));
19
+ process.exit(1);
20
+ }
21
+
22
+ function runCmd(cmd) {
23
+ execSync(cmd, { cwd, stdio: 'pipe' });
24
+ }
25
+
26
+ function getSystemPython() {
27
+ try {
28
+ execSync('python3 --version', { stdio: 'pipe' });
29
+ return 'python3';
30
+ } catch {
31
+ try {
32
+ execSync('python --version', { stdio: 'pipe' });
33
+ return 'python';
34
+ } catch {
35
+ throw new Error('Python is not installed on this system.');
36
+ }
37
+ }
38
+ }
39
+
40
+ function waitForEnter() {
41
+ return new Promise((resolve) => {
42
+ const rl = readline.createInterface({
43
+ input: process.stdin,
44
+ output: process.stdout,
45
+ });
46
+ rl.question(
47
+ chalk.bgGreen.black.bold('\n PRESS ENTER ') + chalk.green(' to launch project console... '),
48
+ () => {
49
+ rl.close();
50
+ resolve();
51
+ }
52
+ );
53
+ });
54
+ }
55
+
56
+ function scanNodeProject(dir) {
57
+ const deps = new Set();
58
+ const importedLocals = new Set();
59
+ const rootJsFiles = [];
60
+ let usesESM = false;
61
+ const ignoreDirs = new Set(['node_modules', '.git', 'dist', 'build', 'venv', '.venv']);
62
+
63
+ function walk(currentDir, isRoot = false) {
64
+ for (const item of fs.readdirSync(currentDir)) {
65
+ if (ignoreDirs.has(item) || item.startsWith('.')) continue;
66
+ const fullPath = path.join(currentDir, item);
67
+ if (fs.statSync(fullPath).isDirectory()) {
68
+ walk(fullPath, false);
69
+ } else if (item.endsWith('.js') || item.endsWith('.ts')) {
70
+ if (isRoot && item.endsWith('.js')) rootJsFiles.push({ name: item, fullPath });
71
+
72
+ const content = fs.readFileSync(fullPath, 'utf8');
73
+ if (/^\s*(?:import\s+|export\s+)/m.test(content)) usesESM = true;
74
+
75
+ const regex = /(?:require\(|from\s+|import\s+)['"]([^'"]+)['"]/g;
76
+ let match;
77
+ while ((match = regex.exec(content)) !== null) {
78
+ const target = match[1];
79
+ if (target.startsWith('.')) {
80
+ importedLocals.add(path.basename(target).replace(/\.(js|ts)$/, ''));
81
+ } else {
82
+ let pkg = target.startsWith('@') ? target.split('/').slice(0, 2).join('/') : target.split('/')[0];
83
+ const clean = pkg.replace(/^node:/, '');
84
+ if (!builtinModules.includes(clean)) deps.add(pkg);
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ walk(dir, true);
91
+
92
+ let bestEntry = rootJsFiles[0]?.name || 'index.js';
93
+ let bestScore = -999;
94
+
95
+ for (const file of rootJsFiles) {
96
+ let score = 0;
97
+ const base = file.name.replace(/\.js$/, '');
98
+ const content = fs.readFileSync(file.fullPath, 'utf8');
99
+
100
+ if (!importedLocals.has(base)) score += 50;
101
+ if (['index.js', 'app.js', 'server.js', 'main.js', 'bot.js'].includes(file.name)) score += 30;
102
+ if (/\.listen\(|\.login\(|createServer\(|express\(\)/.test(content)) score += 25;
103
+
104
+ if (score > bestScore) {
105
+ bestScore = score;
106
+ bestEntry = file.name;
107
+ }
108
+ }
109
+
110
+ return { deps: Array.from(deps), usesESM, entryFile: bestEntry };
111
+ }
112
+
113
+ function scanPythonProject(dir) {
114
+ const rawImports = new Set();
115
+ const localModules = new Set();
116
+ const importedLocals = new Set();
117
+ const rootPyFiles = [];
118
+
119
+ const pypiMap = {
120
+ discord: 'discord.py',
121
+ PIL: 'Pillow',
122
+ cv2: 'opencv-python',
123
+ yaml: 'PyYAML',
124
+ bs4: 'beautifulsoup4',
125
+ dotenv: 'python-dotenv',
126
+ sklearn: 'scikit-learn'
127
+ };
128
+
129
+ const stdLib = new Set([
130
+ '__future__', 'os', 'sys', 'json', 'math', 'time', 'datetime', 're', 'random',
131
+ 'pathlib', 'subprocess', 'threading', 'asyncio', 'typing', 'collections',
132
+ 'itertools', 'functools', 'urllib', 'http', 'sqlite3', 'csv', 'logging',
133
+ 'unittest', 'shutil', 'glob', 'hashlib', 'hmac', 'base64', 'uuid', 'socket',
134
+ 'ssl', 'argparse', 'configparser', 'io', 'tempfile', 'traceback', 'inspect',
135
+ 'dataclasses', 'enum', 'abc', 'contextlib', 'copy', 'pprint', 'string', 'textwrap'
136
+ ]);
137
+
138
+ const ignoreDirs = new Set(['venv', '.venv', '__pycache__', '.git', 'node_modules']);
139
+
140
+ function walk(currentDir, isRoot = false) {
141
+ for (const item of fs.readdirSync(currentDir)) {
142
+ if (ignoreDirs.has(item) || item.startsWith('.')) continue;
143
+ const fullPath = path.join(currentDir, item);
144
+ if (fs.statSync(fullPath).isDirectory()) {
145
+ localModules.add(item);
146
+ walk(fullPath, false);
147
+ } else if (item.endsWith('.py')) {
148
+ const modName = item.replace(/\.py$/, '');
149
+ localModules.add(modName);
150
+ if (isRoot) rootPyFiles.push({ name: item, modName, fullPath });
151
+
152
+ const content = fs.readFileSync(fullPath, 'utf8');
153
+ const regex = /^\s*(?:import|from)\s+([a-zA-Z0-9_]+)/gm;
154
+ let match;
155
+ while ((match = regex.exec(content)) !== null) {
156
+ const mod = match[1];
157
+ rawImports.add(mod);
158
+ importedLocals.add(mod);
159
+ }
160
+ }
161
+ }
162
+ }
163
+ walk(dir, true);
164
+
165
+ const externalDeps = [];
166
+ for (const mod of rawImports) {
167
+ if (!stdLib.has(mod) && !localModules.has(mod)) {
168
+ externalDeps.push(pypiMap[mod] || mod);
169
+ }
170
+ }
171
+
172
+ let bestEntry = rootPyFiles[0]?.name || 'main.py';
173
+ let bestScore = -999;
174
+
175
+ for (const file of rootPyFiles) {
176
+ let score = 0;
177
+ const content = fs.readFileSync(file.fullPath, 'utf8');
178
+
179
+ if (!importedLocals.has(file.modName)) score += 60;
180
+ if (/if\s+__name__\s*==\s*['"]__main__['"]/.test(content)) score += 50;
181
+ if (/\b(?:bot|client|app|uvicorn)\.run\(|asyncio\.run\(/.test(content)) score += 40;
182
+ if (['main.py', 'bot.py', 'app.py', 'run.py', 'start.py', 'index.py'].includes(file.name)) score += 20;
183
+
184
+ let localImportCount = 0;
185
+ for (const loc of localModules) {
186
+ if (loc !== file.modName && new RegExp(`(?:from|import)\\s+${loc}\\b`).test(content)) {
187
+ localImportCount++;
188
+ }
189
+ }
190
+ score += localImportCount * 10;
191
+
192
+ if (score > bestScore) {
193
+ bestScore = score;
194
+ bestEntry = file.name;
195
+ }
196
+ }
197
+
198
+ return { deps: externalDeps, entryFile: bestEntry };
199
+ }
200
+ cat << 'EOF' >> /mnt/master1/fast-deploy/bin/cli.js
201
+
1
202
  async function deploy() {
2
203
  const startTime = Date.now();
3
204
  console.clear();
4
- console.log(chalk.bold.white('\n> balcnix deploy ') + chalk.gray('v1.0.2\n'));
205
+ console.log(chalk.bold.white('\n> balcnix deploy ') + chalk.gray('v1.0.3\n'));
5
206
 
6
207
  const spinner = ora({ text: 'Fetching & scanning project files...', color: 'cyan' }).start();
7
208
  await new Promise((r) => setTimeout(r, 350));
@@ -16,7 +217,6 @@ async function deploy() {
16
217
  let envNote = 'default';
17
218
 
18
219
  try {
19
- // ================= NODE.JS =================
20
220
  if (files.includes('package.json') || files.some((f) => f.endsWith('.js') || f.endsWith('.ts'))) {
21
221
  stack = 'Node.js';
22
222
  const { deps: detected, usesESM, entryFile } = scanNodeProject(cwd);
@@ -60,7 +260,6 @@ async function deploy() {
60
260
  ? 'npm start'
61
261
  : `node ${finalPkg.main || entryFile}`;
62
262
 
63
- // ================= PYTHON =================
64
263
  } else if (files.includes('requirements.txt') || files.some((f) => f.endsWith('.py'))) {
65
264
  stack = 'Python';
66
265
  const sysPython = getSystemPython();
@@ -104,7 +303,6 @@ async function deploy() {
104
303
  startCmd = `${sysPython} ${entryFile}`;
105
304
  }
106
305
 
107
- // ================= RUST =================
108
306
  } else if (files.includes('Cargo.toml') || files.some((f) => f.endsWith('.rs'))) {
109
307
  stack = 'Rust';
110
308
  entryDisplay = 'src/main.rs';
@@ -119,14 +317,12 @@ async function deploy() {
119
317
  envNote = 'cargo';
120
318
  startCmd = 'cargo run';
121
319
 
122
- // ================= UNSUPPORTED =================
123
320
  } else {
124
321
  throw new Error('No supported project files (.js, .ts, .py, .rs) found in this directory.');
125
322
  }
126
323
 
127
324
  const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
128
325
 
129
- // Sleek Dashboard Summary
130
326
  console.log(chalk.green.bold(`\n> Ready in ${elapsed}s → `) + chalk.white(path.basename(cwd)));
131
327
  console.log(chalk.gray('──────────────────────────────────────────────'));
132
328
  console.log(`${chalk.gray('stack')} ${chalk.cyan(stack)} ${chalk.gray(`(${envNote})`)}`);
@@ -135,7 +331,6 @@ async function deploy() {
135
331
  console.log(`${chalk.gray('status')} ${chalk.green('100% ready')}`);
136
332
  console.log(chalk.gray('──────────────────────────────────────────────'));
137
333
 
138
- // Wait for Enter, then drop into live project console
139
334
  await waitForEnter();
140
335
  console.clear();
141
336
  console.log(chalk.gray(`Launching ${entryDisplay} in ${cwd}...\n`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balcnix/fast-deploy",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Fast universal dependency builder, installer, and runner",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {