@balcnix/fast-deploy 1.0.0 → 1.0.1

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 +73 -20
  2. package/package.json +4 -3
package/bin/cli.js CHANGED
@@ -11,6 +11,7 @@ const ora = require('ora');
11
11
  const args = process.argv.slice(2);
12
12
  const command = args[0];
13
13
  const cwd = process.cwd();
14
+ const isWin = process.platform === 'win32';
14
15
 
15
16
  if (command !== 'deploy') {
16
17
  console.log(chalk.red('\n✖ Unknown command. ') + chalk.white('Usage: ') + chalk.cyan('balcnix deploy\n'));
@@ -22,6 +23,21 @@ function runCmd(cmd) {
22
23
  execSync(cmd, { cwd, stdio: 'pipe' });
23
24
  }
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
+
25
41
  // Wait for Enter key press
26
42
  function waitForEnter() {
27
43
  return new Promise((resolve) => {
@@ -39,10 +55,11 @@ function waitForEnter() {
39
55
  });
40
56
  }
41
57
 
42
- // Scan .js / .ts files for external npm packages
43
- function scanNodeDeps(dir) {
58
+ // Scan .js / .ts files for external npm packages & ESM syntax
59
+ function scanNodeProject(dir) {
44
60
  const deps = new Set();
45
- const ignoreDirs = new Set(['node_modules', '.git', 'dist', 'build']);
61
+ let usesESM = false;
62
+ const ignoreDirs = new Set(['node_modules', '.git', 'dist', 'build', 'venv', '.venv']);
46
63
 
47
64
  function walk(currentDir) {
48
65
  for (const item of fs.readdirSync(currentDir)) {
@@ -52,6 +69,9 @@ function scanNodeDeps(dir) {
52
69
  walk(fullPath);
53
70
  } else if (item.endsWith('.js') || item.endsWith('.ts')) {
54
71
  const content = fs.readFileSync(fullPath, 'utf8');
72
+ if (/^\s*(?:import\s+|export\s+)/m.test(content)) {
73
+ usesESM = true;
74
+ }
55
75
  const regex = /(?:require\(|from\s+|import\s+)['"]([^'"./][^'"]*)['"]/g;
56
76
  let match;
57
77
  while ((match = regex.exec(content)) !== null) {
@@ -64,7 +84,7 @@ function scanNodeDeps(dir) {
64
84
  }
65
85
  }
66
86
  walk(dir);
67
- return Array.from(deps);
87
+ return { deps: Array.from(deps), usesESM };
68
88
  }
69
89
 
70
90
  // Scan .py files for external pip packages
@@ -73,9 +93,11 @@ function scanPythonDeps(dir) {
73
93
  const stdLib = new Set([
74
94
  'os', 'sys', 'json', 'math', 'time', 'datetime', 're', 'random', 'pathlib',
75
95
  'subprocess', 'threading', 'asyncio', 'typing', 'collections', 'itertools',
76
- 'functools', 'urllib', 'http', 'sqlite3', 'csv', 'logging', 'unittest', 'shutil'
96
+ 'functools', 'urllib', 'http', 'sqlite3', 'csv', 'logging', 'unittest',
97
+ 'shutil', 'glob', 'hashlib', 'hmac', 'base64', 'uuid', 'socket', 'ssl',
98
+ 'argparse', 'configparser', 'io', 'tempfile', 'traceback', 'inspect'
77
99
  ]);
78
- const ignoreDirs = new Set(['venv', '.venv', '__pycache__', '.git']);
100
+ const ignoreDirs = new Set(['venv', '.venv', '__pycache__', '.git', 'node_modules']);
79
101
 
80
102
  function walk(currentDir) {
81
103
  for (const item of fs.readdirSync(currentDir)) {
@@ -97,21 +119,21 @@ function scanPythonDeps(dir) {
97
119
  walk(dir);
98
120
  return Array.from(deps);
99
121
  }
100
-
101
122
  async function deploy() {
102
123
  const startTime = Date.now();
103
124
  console.clear();
104
- console.log(chalk.bold.white('\n> balcnix deploy\n'));
125
+ console.log(chalk.bold.white('\n> balcnix deploy ') + chalk.gray('v1.0.1\n'));
105
126
 
106
127
  const spinner = ora({ text: 'Fetching & scanning project files...', color: 'cyan' }).start();
107
- await new Promise((r) => setTimeout(r, 400));
128
+ await new Promise((r) => setTimeout(r, 350));
108
129
 
109
130
  const files = fs.readdirSync(cwd);
110
- spinner.succeed(chalk.gray(`Scanned ${files.length} items in directory`));
131
+ spinner.succeed(chalk.gray(`Scanned ${files.length} items in ${path.basename(cwd)}`));
111
132
 
112
133
  let stack = '';
113
134
  let startCmd = '';
114
135
  let pkgCount = 0;
136
+ let envNote = 'default';
115
137
 
116
138
  try {
117
139
  // ================= NODE.JS =================
@@ -123,7 +145,7 @@ async function deploy() {
123
145
 
124
146
  if (!files.includes('package.json')) {
125
147
  spinner.start('No package.json found. Scanning imports & building...');
126
- const detected = scanNodeDeps(cwd);
148
+ const { deps: detected, usesESM } = scanNodeProject(cwd);
127
149
  pkgCount = detected.length;
128
150
 
129
151
  runCmd('npm init -y');
@@ -133,6 +155,10 @@ async function deploy() {
133
155
  pkgData.main = entryFile;
134
156
  pkgData.scripts = { start: `node ${entryFile}` };
135
157
  }
158
+ if (usesESM) {
159
+ pkgData.type = 'module';
160
+ envNote = 'ES Modules';
161
+ }
136
162
  fs.writeFileSync(pkgPath, JSON.stringify(pkgData, null, 2));
137
163
  spinner.succeed(chalk.green(`Built package.json (${pkgCount} dependencies detected)`));
138
164
 
@@ -158,8 +184,9 @@ async function deploy() {
158
184
  // ================= PYTHON =================
159
185
  } else if (files.includes('requirements.txt') || files.some((f) => f.endsWith('.py'))) {
160
186
  stack = 'Python';
187
+ const sysPython = getSystemPython();
161
188
  const pyEntry =
162
- files.find((f) => ['main.py', 'app.py', 'run.py'].includes(f)) ||
189
+ files.find((f) => ['main.py', 'app.py', 'run.py', 'ai.py'].includes(f)) ||
163
190
  files.find((f) => f.endsWith('.py'));
164
191
 
165
192
  if (!files.includes('requirements.txt')) {
@@ -169,16 +196,37 @@ async function deploy() {
169
196
  fs.writeFileSync(path.join(cwd, 'requirements.txt'), detected.join('\n'));
170
197
  spinner.succeed(chalk.green(`Built requirements.txt (${pkgCount} packages detected)`));
171
198
  } else {
172
- const reqs = fs.readFileSync(path.join(cwd, 'requirements.txt'), 'utf8').split('\n').filter(Boolean);
199
+ const reqs = fs.readFileSync(path.join(cwd, 'requirements.txt'), 'utf8')
200
+ .split('\n')
201
+ .map((l) => l.trim())
202
+ .filter((l) => l && !l.startsWith('#'));
173
203
  pkgCount = reqs.length;
174
204
  }
175
205
 
206
+ // Create/use isolated .venv so Fedora/Ubuntu never throws externally-managed-environment error
207
+ const venvDir = path.join(cwd, '.venv');
208
+ const venvPython = isWin
209
+ ? path.join(venvDir, 'Scripts', 'python.exe')
210
+ : path.join(venvDir, 'bin', 'python');
211
+ const venvPip = isWin
212
+ ? path.join(venvDir, 'Scripts', 'pip.exe')
213
+ : path.join(venvDir, 'bin', 'pip');
214
+
176
215
  if (pkgCount > 0) {
177
- spinner.start('Downloading Python dependencies...');
178
- runCmd('pip install -r requirements.txt');
179
- spinner.succeed(chalk.green('Python environment ready'));
216
+ if (!fs.existsSync(venvDir)) {
217
+ spinner.start('Creating isolated Python virtual environment (.venv)...');
218
+ runCmd(`${sysPython} -m venv .venv`);
219
+ spinner.succeed(chalk.green('Virtual environment ready (.venv)'));
220
+ }
221
+ spinner.start(`Installing ${pkgCount} Python package(s)...`);
222
+ runCmd(`"${venvPip}" install -r requirements.txt`);
223
+ spinner.succeed(chalk.green('Python dependencies installed'));
224
+ envNote = '.venv isolated';
225
+ startCmd = `"${venvPython}" ${pyEntry}`;
226
+ } else {
227
+ envNote = sysPython;
228
+ startCmd = `${sysPython} ${pyEntry}`;
180
229
  }
181
- startCmd = `python ${pyEntry}`;
182
230
 
183
231
  // ================= RUST =================
184
232
  } else if (files.includes('Cargo.toml') || files.some((f) => f.endsWith('.rs'))) {
@@ -191,6 +239,7 @@ async function deploy() {
191
239
  spinner.start('Fetching crates & compiling Rust...');
192
240
  runCmd('cargo build');
193
241
  spinner.succeed(chalk.green('Rust build complete'));
242
+ envNote = 'cargo';
194
243
  startCmd = 'cargo run';
195
244
 
196
245
  // ================= UNSUPPORTED =================
@@ -203,21 +252,25 @@ async function deploy() {
203
252
  // Sleek Dashboard Summary
204
253
  console.log(chalk.green.bold(`\n> Ready in ${elapsed}s → `) + chalk.white(path.basename(cwd)));
205
254
  console.log(chalk.gray('──────────────────────────────────────────────'));
206
- console.log(`${chalk.gray('stack')} ${chalk.cyan(stack)}`);
255
+ console.log(`${chalk.gray('stack')} ${chalk.cyan(stack)} ${chalk.gray(`(${envNote})`)}`);
207
256
  console.log(`${chalk.gray('packages')} ${chalk.white(pkgCount + ' synced')}`);
208
- console.log(`${chalk.gray('command')} ${chalk.yellow(startCmd)}`);
257
+ console.log(`${chalk.gray('command')} ${chalk.yellow(path.basename(startCmd.replace(/"/g, '')))}`);
209
258
  console.log(`${chalk.gray('status')} ${chalk.green('100% ready')}`);
210
259
  console.log(chalk.gray('──────────────────────────────────────────────'));
211
260
 
212
261
  // Wait for Enter, then drop into live project console
213
262
  await waitForEnter();
214
263
  console.clear();
215
- console.log(chalk.gray(`Launching "${startCmd}" in ${cwd}...\n`));
264
+ console.log(chalk.gray(`Launching project in ${cwd}...\n`));
216
265
 
217
266
  const child = spawn(startCmd, { cwd, stdio: 'inherit', shell: true });
218
267
  child.on('error', (err) => {
219
268
  console.error(chalk.red.bold('\n✖ Process Error: ') + err.message);
220
269
  });
270
+ child.on('exit', (code) => {
271
+ const color = code === 0 ? chalk.gray : chalk.red;
272
+ console.log(color(`\n[balcnix] Process exited with code ${code ?? 0}\n`));
273
+ });
221
274
 
222
275
  } catch (err) {
223
276
  spinner.fail(chalk.red.bold('Deployment failed'));
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.1",
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",