@balcnix/fast-deploy 1.0.1 → 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 +124 -51
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -1,3 +1,4 @@
1
+ cat << 'EOF' > /mnt/master1/fast-deploy/bin/cli.js
1
2
  #!/usr/bin/env node
2
3
 
3
4
  const fs = require('fs');
@@ -18,12 +19,10 @@ if (command !== 'deploy') {
18
19
  process.exit(1);
19
20
  }
20
21
 
21
- // Run shell commands silently
22
22
  function runCmd(cmd) {
23
23
  execSync(cmd, { cwd, stdio: 'pipe' });
24
24
  }
25
25
 
26
- // Detect whether python3 or python is available on the machine
27
26
  function getSystemPython() {
28
27
  try {
29
28
  execSync('python3 --version', { stdio: 'pipe' });
@@ -38,7 +37,6 @@ function getSystemPython() {
38
37
  }
39
38
  }
40
39
 
41
- // Wait for Enter key press
42
40
  function waitForEnter() {
43
41
  return new Promise((resolve) => {
44
42
  const rl = readline.createInterface({
@@ -55,74 +53,156 @@ function waitForEnter() {
55
53
  });
56
54
  }
57
55
 
58
- // Scan .js / .ts files for external npm packages & ESM syntax
59
56
  function scanNodeProject(dir) {
60
57
  const deps = new Set();
58
+ const importedLocals = new Set();
59
+ const rootJsFiles = [];
61
60
  let usesESM = false;
62
61
  const ignoreDirs = new Set(['node_modules', '.git', 'dist', 'build', 'venv', '.venv']);
63
62
 
64
- function walk(currentDir) {
63
+ function walk(currentDir, isRoot = false) {
65
64
  for (const item of fs.readdirSync(currentDir)) {
66
65
  if (ignoreDirs.has(item) || item.startsWith('.')) continue;
67
66
  const fullPath = path.join(currentDir, item);
68
67
  if (fs.statSync(fullPath).isDirectory()) {
69
- walk(fullPath);
68
+ walk(fullPath, false);
70
69
  } else if (item.endsWith('.js') || item.endsWith('.ts')) {
70
+ if (isRoot && item.endsWith('.js')) rootJsFiles.push({ name: item, fullPath });
71
+
71
72
  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;
73
+ if (/^\s*(?:import\s+|export\s+)/m.test(content)) usesESM = true;
74
+
75
+ const regex = /(?:require\(|from\s+|import\s+)['"]([^'"]+)['"]/g;
76
76
  let match;
77
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);
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
+ }
82
86
  }
83
87
  }
84
88
  }
85
89
  }
86
- walk(dir);
87
- return { deps: Array.from(deps), usesESM };
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 };
88
111
  }
89
112
 
90
- // Scan .py files for external pip packages
91
- function scanPythonDeps(dir) {
92
- const deps = new Set();
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
+
93
129
  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'
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'
99
136
  ]);
137
+
100
138
  const ignoreDirs = new Set(['venv', '.venv', '__pycache__', '.git', 'node_modules']);
101
139
 
102
- function walk(currentDir) {
140
+ function walk(currentDir, isRoot = false) {
103
141
  for (const item of fs.readdirSync(currentDir)) {
104
142
  if (ignoreDirs.has(item) || item.startsWith('.')) continue;
105
143
  const fullPath = path.join(currentDir, item);
106
144
  if (fs.statSync(fullPath).isDirectory()) {
107
- walk(fullPath);
145
+ localModules.add(item);
146
+ walk(fullPath, false);
108
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
+
109
152
  const content = fs.readFileSync(fullPath, 'utf8');
110
153
  const regex = /^\s*(?:import|from)\s+([a-zA-Z0-9_]+)/gm;
111
154
  let match;
112
155
  while ((match = regex.exec(content)) !== null) {
113
156
  const mod = match[1];
114
- if (!stdLib.has(mod)) deps.add(mod);
157
+ rawImports.add(mod);
158
+ importedLocals.add(mod);
115
159
  }
116
160
  }
117
161
  }
118
162
  }
119
- walk(dir);
120
- return Array.from(deps);
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 };
121
199
  }
200
+ cat << 'EOF' >> /mnt/master1/fast-deploy/bin/cli.js
201
+
122
202
  async function deploy() {
123
203
  const startTime = Date.now();
124
204
  console.clear();
125
- console.log(chalk.bold.white('\n> balcnix deploy ') + chalk.gray('v1.0.1\n'));
205
+ console.log(chalk.bold.white('\n> balcnix deploy ') + chalk.gray('v1.0.3\n'));
126
206
 
127
207
  const spinner = ora({ text: 'Fetching & scanning project files...', color: 'cyan' }).start();
128
208
  await new Promise((r) => setTimeout(r, 350));
@@ -132,20 +212,18 @@ async function deploy() {
132
212
 
133
213
  let stack = '';
134
214
  let startCmd = '';
215
+ let entryDisplay = '';
135
216
  let pkgCount = 0;
136
217
  let envNote = 'default';
137
218
 
138
219
  try {
139
- // ================= NODE.JS =================
140
220
  if (files.includes('package.json') || files.some((f) => f.endsWith('.js') || f.endsWith('.ts'))) {
141
221
  stack = 'Node.js';
142
- const entryFile =
143
- files.find((f) => ['index.js', 'app.js', 'server.js', 'main.js'].includes(f)) ||
144
- files.find((f) => f.endsWith('.js'));
222
+ const { deps: detected, usesESM, entryFile } = scanNodeProject(cwd);
223
+ entryDisplay = entryFile;
145
224
 
146
225
  if (!files.includes('package.json')) {
147
226
  spinner.start('No package.json found. Scanning imports & building...');
148
- const { deps: detected, usesESM } = scanNodeProject(cwd);
149
227
  pkgCount = detected.length;
150
228
 
151
229
  runCmd('npm init -y');
@@ -172,6 +250,7 @@ async function deploy() {
172
250
  runCmd('npm install');
173
251
  const pkgData = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
174
252
  pkgCount = Object.keys(pkgData.dependencies || {}).length;
253
+ if (pkgData.main) entryDisplay = pkgData.main;
175
254
  spinner.succeed(chalk.green('Dependencies installed'));
176
255
  }
177
256
 
@@ -179,22 +258,19 @@ async function deploy() {
179
258
  startCmd =
180
259
  finalPkg.scripts && finalPkg.scripts.start
181
260
  ? 'npm start'
182
- : `node ${finalPkg.main || entryFile || 'index.js'}`;
261
+ : `node ${finalPkg.main || entryFile}`;
183
262
 
184
- // ================= PYTHON =================
185
263
  } else if (files.includes('requirements.txt') || files.some((f) => f.endsWith('.py'))) {
186
264
  stack = 'Python';
187
265
  const sysPython = getSystemPython();
188
- const pyEntry =
189
- files.find((f) => ['main.py', 'app.py', 'run.py', 'ai.py'].includes(f)) ||
190
- files.find((f) => f.endsWith('.py'));
266
+ const { deps: detected, entryFile } = scanPythonProject(cwd);
267
+ entryDisplay = entryFile;
191
268
 
192
269
  if (!files.includes('requirements.txt')) {
193
270
  spinner.start('No requirements.txt found. Scanning imports & building...');
194
- const detected = scanPythonDeps(cwd);
195
271
  pkgCount = detected.length;
196
272
  fs.writeFileSync(path.join(cwd, 'requirements.txt'), detected.join('\n'));
197
- spinner.succeed(chalk.green(`Built requirements.txt (${pkgCount} packages detected)`));
273
+ spinner.succeed(chalk.green(`Built requirements.txt (${pkgCount} packages: ${detected.join(', ') || 'none'})`));
198
274
  } else {
199
275
  const reqs = fs.readFileSync(path.join(cwd, 'requirements.txt'), 'utf8')
200
276
  .split('\n')
@@ -203,7 +279,6 @@ async function deploy() {
203
279
  pkgCount = reqs.length;
204
280
  }
205
281
 
206
- // Create/use isolated .venv so Fedora/Ubuntu never throws externally-managed-environment error
207
282
  const venvDir = path.join(cwd, '.venv');
208
283
  const venvPython = isWin
209
284
  ? path.join(venvDir, 'Scripts', 'python.exe')
@@ -222,15 +297,15 @@ async function deploy() {
222
297
  runCmd(`"${venvPip}" install -r requirements.txt`);
223
298
  spinner.succeed(chalk.green('Python dependencies installed'));
224
299
  envNote = '.venv isolated';
225
- startCmd = `"${venvPython}" ${pyEntry}`;
300
+ startCmd = `"${venvPython}" ${entryFile}`;
226
301
  } else {
227
302
  envNote = sysPython;
228
- startCmd = `${sysPython} ${pyEntry}`;
303
+ startCmd = `${sysPython} ${entryFile}`;
229
304
  }
230
305
 
231
- // ================= RUST =================
232
306
  } else if (files.includes('Cargo.toml') || files.some((f) => f.endsWith('.rs'))) {
233
307
  stack = 'Rust';
308
+ entryDisplay = 'src/main.rs';
234
309
  if (!files.includes('Cargo.toml')) {
235
310
  spinner.start('No Cargo.toml found. Initializing Rust project...');
236
311
  runCmd('cargo init');
@@ -242,26 +317,23 @@ async function deploy() {
242
317
  envNote = 'cargo';
243
318
  startCmd = 'cargo run';
244
319
 
245
- // ================= UNSUPPORTED =================
246
320
  } else {
247
321
  throw new Error('No supported project files (.js, .ts, .py, .rs) found in this directory.');
248
322
  }
249
323
 
250
324
  const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
251
325
 
252
- // Sleek Dashboard Summary
253
326
  console.log(chalk.green.bold(`\n> Ready in ${elapsed}s → `) + chalk.white(path.basename(cwd)));
254
327
  console.log(chalk.gray('──────────────────────────────────────────────'));
255
328
  console.log(`${chalk.gray('stack')} ${chalk.cyan(stack)} ${chalk.gray(`(${envNote})`)}`);
329
+ console.log(`${chalk.gray('entry')} ${chalk.magenta(entryDisplay)}`);
256
330
  console.log(`${chalk.gray('packages')} ${chalk.white(pkgCount + ' synced')}`);
257
- console.log(`${chalk.gray('command')} ${chalk.yellow(path.basename(startCmd.replace(/"/g, '')))}`);
258
331
  console.log(`${chalk.gray('status')} ${chalk.green('100% ready')}`);
259
332
  console.log(chalk.gray('──────────────────────────────────────────────'));
260
333
 
261
- // Wait for Enter, then drop into live project console
262
334
  await waitForEnter();
263
335
  console.clear();
264
- console.log(chalk.gray(`Launching project in ${cwd}...\n`));
336
+ console.log(chalk.gray(`Launching ${entryDisplay} in ${cwd}...\n`));
265
337
 
266
338
  const child = spawn(startCmd, { cwd, stdio: 'inherit', shell: true });
267
339
  child.on('error', (err) => {
@@ -283,3 +355,4 @@ async function deploy() {
283
355
  }
284
356
 
285
357
  deploy();
358
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balcnix/fast-deploy",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Fast universal dependency builder, installer, and runner",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {