@balcnix/fast-deploy 1.0.0 → 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.
Files changed (2) hide show
  1. package/bin/cli.js +52 -121
  2. package/package.json +4 -3
package/bin/cli.js CHANGED
@@ -1,129 +1,29 @@
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
-
15
- if (command !== 'deploy') {
16
- console.log(chalk.red('\n✖ Unknown command. ') + chalk.white('Usage: ') + chalk.cyan('balcnix deploy\n'));
17
- process.exit(1);
18
- }
19
-
20
- // Run shell commands silently
21
- function runCmd(cmd) {
22
- execSync(cmd, { cwd, stdio: 'pipe' });
23
- }
24
-
25
- // Wait for Enter key press
26
- function waitForEnter() {
27
- return new Promise((resolve) => {
28
- const rl = readline.createInterface({
29
- input: process.stdin,
30
- output: process.stdout,
31
- });
32
- rl.question(
33
- chalk.bgGreen.black.bold('\n PRESS ENTER ') + chalk.green(' to launch project console... '),
34
- () => {
35
- rl.close();
36
- resolve();
37
- }
38
- );
39
- });
40
- }
41
-
42
- // Scan .js / .ts files for external npm packages
43
- function scanNodeDeps(dir) {
44
- const deps = new Set();
45
- const ignoreDirs = new Set(['node_modules', '.git', 'dist', 'build']);
46
-
47
- function walk(currentDir) {
48
- for (const item of fs.readdirSync(currentDir)) {
49
- if (ignoreDirs.has(item) || item.startsWith('.')) continue;
50
- const fullPath = path.join(currentDir, item);
51
- if (fs.statSync(fullPath).isDirectory()) {
52
- walk(fullPath);
53
- } else if (item.endsWith('.js') || item.endsWith('.ts')) {
54
- const content = fs.readFileSync(fullPath, 'utf8');
55
- const regex = /(?:require\(|from\s+|import\s+)['"]([^'"./][^'"]*)['"]/g;
56
- let match;
57
- while ((match = regex.exec(content)) !== null) {
58
- let pkg = match[1];
59
- pkg = pkg.startsWith('@') ? pkg.split('/').slice(0, 2).join('/') : pkg.split('/')[0];
60
- const clean = pkg.replace(/^node:/, '');
61
- if (!builtinModules.includes(clean)) deps.add(pkg);
62
- }
63
- }
64
- }
65
- }
66
- walk(dir);
67
- return Array.from(deps);
68
- }
69
-
70
- // Scan .py files for external pip packages
71
- function scanPythonDeps(dir) {
72
- const deps = new Set();
73
- const stdLib = new Set([
74
- 'os', 'sys', 'json', 'math', 'time', 'datetime', 're', 'random', 'pathlib',
75
- 'subprocess', 'threading', 'asyncio', 'typing', 'collections', 'itertools',
76
- 'functools', 'urllib', 'http', 'sqlite3', 'csv', 'logging', 'unittest', 'shutil'
77
- ]);
78
- const ignoreDirs = new Set(['venv', '.venv', '__pycache__', '.git']);
79
-
80
- function walk(currentDir) {
81
- for (const item of fs.readdirSync(currentDir)) {
82
- if (ignoreDirs.has(item) || item.startsWith('.')) continue;
83
- const fullPath = path.join(currentDir, item);
84
- if (fs.statSync(fullPath).isDirectory()) {
85
- walk(fullPath);
86
- } else if (item.endsWith('.py')) {
87
- const content = fs.readFileSync(fullPath, 'utf8');
88
- const regex = /^\s*(?:import|from)\s+([a-zA-Z0-9_]+)/gm;
89
- let match;
90
- while ((match = regex.exec(content)) !== null) {
91
- const mod = match[1];
92
- if (!stdLib.has(mod)) deps.add(mod);
93
- }
94
- }
95
- }
96
- }
97
- walk(dir);
98
- return Array.from(deps);
99
- }
100
-
101
1
  async function deploy() {
102
2
  const startTime = Date.now();
103
3
  console.clear();
104
- console.log(chalk.bold.white('\n> balcnix deploy\n'));
4
+ console.log(chalk.bold.white('\n> balcnix deploy ') + chalk.gray('v1.0.2\n'));
105
5
 
106
6
  const spinner = ora({ text: 'Fetching & scanning project files...', color: 'cyan' }).start();
107
- await new Promise((r) => setTimeout(r, 400));
7
+ await new Promise((r) => setTimeout(r, 350));
108
8
 
109
9
  const files = fs.readdirSync(cwd);
110
- spinner.succeed(chalk.gray(`Scanned ${files.length} items in directory`));
10
+ spinner.succeed(chalk.gray(`Scanned ${files.length} items in ${path.basename(cwd)}`));
111
11
 
112
12
  let stack = '';
113
13
  let startCmd = '';
14
+ let entryDisplay = '';
114
15
  let pkgCount = 0;
16
+ let envNote = 'default';
115
17
 
116
18
  try {
117
19
  // ================= NODE.JS =================
118
20
  if (files.includes('package.json') || files.some((f) => f.endsWith('.js') || f.endsWith('.ts'))) {
119
21
  stack = 'Node.js';
120
- const entryFile =
121
- files.find((f) => ['index.js', 'app.js', 'server.js', 'main.js'].includes(f)) ||
122
- files.find((f) => f.endsWith('.js'));
22
+ const { deps: detected, usesESM, entryFile } = scanNodeProject(cwd);
23
+ entryDisplay = entryFile;
123
24
 
124
25
  if (!files.includes('package.json')) {
125
26
  spinner.start('No package.json found. Scanning imports & building...');
126
- const detected = scanNodeDeps(cwd);
127
27
  pkgCount = detected.length;
128
28
 
129
29
  runCmd('npm init -y');
@@ -133,6 +33,10 @@ async function deploy() {
133
33
  pkgData.main = entryFile;
134
34
  pkgData.scripts = { start: `node ${entryFile}` };
135
35
  }
36
+ if (usesESM) {
37
+ pkgData.type = 'module';
38
+ envNote = 'ES Modules';
39
+ }
136
40
  fs.writeFileSync(pkgPath, JSON.stringify(pkgData, null, 2));
137
41
  spinner.succeed(chalk.green(`Built package.json (${pkgCount} dependencies detected)`));
138
42
 
@@ -146,6 +50,7 @@ async function deploy() {
146
50
  runCmd('npm install');
147
51
  const pkgData = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
148
52
  pkgCount = Object.keys(pkgData.dependencies || {}).length;
53
+ if (pkgData.main) entryDisplay = pkgData.main;
149
54
  spinner.succeed(chalk.green('Dependencies installed'));
150
55
  }
151
56
 
@@ -153,36 +58,56 @@ async function deploy() {
153
58
  startCmd =
154
59
  finalPkg.scripts && finalPkg.scripts.start
155
60
  ? 'npm start'
156
- : `node ${finalPkg.main || entryFile || 'index.js'}`;
61
+ : `node ${finalPkg.main || entryFile}`;
157
62
 
158
63
  // ================= PYTHON =================
159
64
  } else if (files.includes('requirements.txt') || files.some((f) => f.endsWith('.py'))) {
160
65
  stack = 'Python';
161
- const pyEntry =
162
- files.find((f) => ['main.py', 'app.py', 'run.py'].includes(f)) ||
163
- files.find((f) => f.endsWith('.py'));
66
+ const sysPython = getSystemPython();
67
+ const { deps: detected, entryFile } = scanPythonProject(cwd);
68
+ entryDisplay = entryFile;
164
69
 
165
70
  if (!files.includes('requirements.txt')) {
166
71
  spinner.start('No requirements.txt found. Scanning imports & building...');
167
- const detected = scanPythonDeps(cwd);
168
72
  pkgCount = detected.length;
169
73
  fs.writeFileSync(path.join(cwd, 'requirements.txt'), detected.join('\n'));
170
- spinner.succeed(chalk.green(`Built requirements.txt (${pkgCount} packages detected)`));
74
+ spinner.succeed(chalk.green(`Built requirements.txt (${pkgCount} packages: ${detected.join(', ') || 'none'})`));
171
75
  } else {
172
- const reqs = fs.readFileSync(path.join(cwd, 'requirements.txt'), 'utf8').split('\n').filter(Boolean);
76
+ const reqs = fs.readFileSync(path.join(cwd, 'requirements.txt'), 'utf8')
77
+ .split('\n')
78
+ .map((l) => l.trim())
79
+ .filter((l) => l && !l.startsWith('#'));
173
80
  pkgCount = reqs.length;
174
81
  }
175
82
 
83
+ const venvDir = path.join(cwd, '.venv');
84
+ const venvPython = isWin
85
+ ? path.join(venvDir, 'Scripts', 'python.exe')
86
+ : path.join(venvDir, 'bin', 'python');
87
+ const venvPip = isWin
88
+ ? path.join(venvDir, 'Scripts', 'pip.exe')
89
+ : path.join(venvDir, 'bin', 'pip');
90
+
176
91
  if (pkgCount > 0) {
177
- spinner.start('Downloading Python dependencies...');
178
- runCmd('pip install -r requirements.txt');
179
- spinner.succeed(chalk.green('Python environment ready'));
92
+ if (!fs.existsSync(venvDir)) {
93
+ spinner.start('Creating isolated Python virtual environment (.venv)...');
94
+ runCmd(`${sysPython} -m venv .venv`);
95
+ spinner.succeed(chalk.green('Virtual environment ready (.venv)'));
96
+ }
97
+ spinner.start(`Installing ${pkgCount} Python package(s)...`);
98
+ runCmd(`"${venvPip}" install -r requirements.txt`);
99
+ spinner.succeed(chalk.green('Python dependencies installed'));
100
+ envNote = '.venv isolated';
101
+ startCmd = `"${venvPython}" ${entryFile}`;
102
+ } else {
103
+ envNote = sysPython;
104
+ startCmd = `${sysPython} ${entryFile}`;
180
105
  }
181
- startCmd = `python ${pyEntry}`;
182
106
 
183
107
  // ================= RUST =================
184
108
  } else if (files.includes('Cargo.toml') || files.some((f) => f.endsWith('.rs'))) {
185
109
  stack = 'Rust';
110
+ entryDisplay = 'src/main.rs';
186
111
  if (!files.includes('Cargo.toml')) {
187
112
  spinner.start('No Cargo.toml found. Initializing Rust project...');
188
113
  runCmd('cargo init');
@@ -191,6 +116,7 @@ async function deploy() {
191
116
  spinner.start('Fetching crates & compiling Rust...');
192
117
  runCmd('cargo build');
193
118
  spinner.succeed(chalk.green('Rust build complete'));
119
+ envNote = 'cargo';
194
120
  startCmd = 'cargo run';
195
121
 
196
122
  // ================= UNSUPPORTED =================
@@ -203,21 +129,25 @@ async function deploy() {
203
129
  // Sleek Dashboard Summary
204
130
  console.log(chalk.green.bold(`\n> Ready in ${elapsed}s → `) + chalk.white(path.basename(cwd)));
205
131
  console.log(chalk.gray('──────────────────────────────────────────────'));
206
- console.log(`${chalk.gray('stack')} ${chalk.cyan(stack)}`);
132
+ console.log(`${chalk.gray('stack')} ${chalk.cyan(stack)} ${chalk.gray(`(${envNote})`)}`);
133
+ console.log(`${chalk.gray('entry')} ${chalk.magenta(entryDisplay)}`);
207
134
  console.log(`${chalk.gray('packages')} ${chalk.white(pkgCount + ' synced')}`);
208
- console.log(`${chalk.gray('command')} ${chalk.yellow(startCmd)}`);
209
135
  console.log(`${chalk.gray('status')} ${chalk.green('100% ready')}`);
210
136
  console.log(chalk.gray('──────────────────────────────────────────────'));
211
137
 
212
138
  // Wait for Enter, then drop into live project console
213
139
  await waitForEnter();
214
140
  console.clear();
215
- console.log(chalk.gray(`Launching "${startCmd}" in ${cwd}...\n`));
141
+ console.log(chalk.gray(`Launching ${entryDisplay} in ${cwd}...\n`));
216
142
 
217
143
  const child = spawn(startCmd, { cwd, stdio: 'inherit', shell: true });
218
144
  child.on('error', (err) => {
219
145
  console.error(chalk.red.bold('\n✖ Process Error: ') + err.message);
220
146
  });
147
+ child.on('exit', (code) => {
148
+ const color = code === 0 ? chalk.gray : chalk.red;
149
+ console.log(color(`\n[balcnix] Process exited with code ${code ?? 0}\n`));
150
+ });
221
151
 
222
152
  } catch (err) {
223
153
  spinner.fail(chalk.red.bold('Deployment failed'));
@@ -230,3 +160,4 @@ async function deploy() {
230
160
  }
231
161
 
232
162
  deploy();
163
+
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@balcnix/fast-deploy",
3
- "version": "1.0.0",
4
- "description": "Universal dependency installer and project runner",
3
+ "version": "1.0.2",
4
+ "description": "Fast universal dependency builder, installer, and runner",
5
5
  "main": "bin/cli.js",
6
6
  "bin": {
7
7
  "balcnix": "bin/cli.js"
8
8
  },
9
9
  "preferGlobal": true,
10
10
  "files": [
11
- "bin/"
11
+ "bin/",
12
+ "README.md"
12
13
  ],
13
14
  "dependencies": {
14
15
  "chalk": "^4.1.2",