@balcnix/fast-deploy 0.0.0-stage → 1.0.0

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 (3) hide show
  1. package/bin/cli.js +232 -0
  2. package/package.json +15 -4
  3. package/README.md +0 -3
package/bin/cli.js ADDED
@@ -0,0 +1,232 @@
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
+ async function deploy() {
102
+ const startTime = Date.now();
103
+ console.clear();
104
+ console.log(chalk.bold.white('\n> balcnix deploy\n'));
105
+
106
+ const spinner = ora({ text: 'Fetching & scanning project files...', color: 'cyan' }).start();
107
+ await new Promise((r) => setTimeout(r, 400));
108
+
109
+ const files = fs.readdirSync(cwd);
110
+ spinner.succeed(chalk.gray(`Scanned ${files.length} items in directory`));
111
+
112
+ let stack = '';
113
+ let startCmd = '';
114
+ let pkgCount = 0;
115
+
116
+ try {
117
+ // ================= NODE.JS =================
118
+ if (files.includes('package.json') || files.some((f) => f.endsWith('.js') || f.endsWith('.ts'))) {
119
+ 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'));
123
+
124
+ if (!files.includes('package.json')) {
125
+ spinner.start('No package.json found. Scanning imports & building...');
126
+ const detected = scanNodeDeps(cwd);
127
+ pkgCount = detected.length;
128
+
129
+ runCmd('npm init -y');
130
+ const pkgPath = path.join(cwd, 'package.json');
131
+ const pkgData = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
132
+ if (entryFile) {
133
+ pkgData.main = entryFile;
134
+ pkgData.scripts = { start: `node ${entryFile}` };
135
+ }
136
+ fs.writeFileSync(pkgPath, JSON.stringify(pkgData, null, 2));
137
+ spinner.succeed(chalk.green(`Built package.json (${pkgCount} dependencies detected)`));
138
+
139
+ if (detected.length > 0) {
140
+ spinner.start(`Downloading packages: ${detected.join(', ')}...`);
141
+ runCmd(`npm install ${detected.join(' ')}`);
142
+ spinner.succeed(chalk.green('All Node.js dependencies installed'));
143
+ }
144
+ } else {
145
+ spinner.start('Downloading dependencies from package.json...');
146
+ runCmd('npm install');
147
+ const pkgData = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
148
+ pkgCount = Object.keys(pkgData.dependencies || {}).length;
149
+ spinner.succeed(chalk.green('Dependencies installed'));
150
+ }
151
+
152
+ const finalPkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8'));
153
+ startCmd =
154
+ finalPkg.scripts && finalPkg.scripts.start
155
+ ? 'npm start'
156
+ : `node ${finalPkg.main || entryFile || 'index.js'}`;
157
+
158
+ // ================= PYTHON =================
159
+ } else if (files.includes('requirements.txt') || files.some((f) => f.endsWith('.py'))) {
160
+ stack = 'Python';
161
+ const pyEntry =
162
+ files.find((f) => ['main.py', 'app.py', 'run.py'].includes(f)) ||
163
+ files.find((f) => f.endsWith('.py'));
164
+
165
+ if (!files.includes('requirements.txt')) {
166
+ spinner.start('No requirements.txt found. Scanning imports & building...');
167
+ const detected = scanPythonDeps(cwd);
168
+ pkgCount = detected.length;
169
+ fs.writeFileSync(path.join(cwd, 'requirements.txt'), detected.join('\n'));
170
+ spinner.succeed(chalk.green(`Built requirements.txt (${pkgCount} packages detected)`));
171
+ } else {
172
+ const reqs = fs.readFileSync(path.join(cwd, 'requirements.txt'), 'utf8').split('\n').filter(Boolean);
173
+ pkgCount = reqs.length;
174
+ }
175
+
176
+ if (pkgCount > 0) {
177
+ spinner.start('Downloading Python dependencies...');
178
+ runCmd('pip install -r requirements.txt');
179
+ spinner.succeed(chalk.green('Python environment ready'));
180
+ }
181
+ startCmd = `python ${pyEntry}`;
182
+
183
+ // ================= RUST =================
184
+ } else if (files.includes('Cargo.toml') || files.some((f) => f.endsWith('.rs'))) {
185
+ stack = 'Rust';
186
+ if (!files.includes('Cargo.toml')) {
187
+ spinner.start('No Cargo.toml found. Initializing Rust project...');
188
+ runCmd('cargo init');
189
+ spinner.succeed(chalk.green('Generated Cargo.toml'));
190
+ }
191
+ spinner.start('Fetching crates & compiling Rust...');
192
+ runCmd('cargo build');
193
+ spinner.succeed(chalk.green('Rust build complete'));
194
+ startCmd = 'cargo run';
195
+
196
+ // ================= UNSUPPORTED =================
197
+ } else {
198
+ throw new Error('No supported project files (.js, .ts, .py, .rs) found in this directory.');
199
+ }
200
+
201
+ const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
202
+
203
+ // Sleek Dashboard Summary
204
+ console.log(chalk.green.bold(`\n> Ready in ${elapsed}s → `) + chalk.white(path.basename(cwd)));
205
+ console.log(chalk.gray('──────────────────────────────────────────────'));
206
+ console.log(`${chalk.gray('stack')} ${chalk.cyan(stack)}`);
207
+ console.log(`${chalk.gray('packages')} ${chalk.white(pkgCount + ' synced')}`);
208
+ console.log(`${chalk.gray('command')} ${chalk.yellow(startCmd)}`);
209
+ console.log(`${chalk.gray('status')} ${chalk.green('100% ready')}`);
210
+ console.log(chalk.gray('──────────────────────────────────────────────'));
211
+
212
+ // Wait for Enter, then drop into live project console
213
+ await waitForEnter();
214
+ console.clear();
215
+ console.log(chalk.gray(`Launching "${startCmd}" in ${cwd}...\n`));
216
+
217
+ const child = spawn(startCmd, { cwd, stdio: 'inherit', shell: true });
218
+ child.on('error', (err) => {
219
+ console.error(chalk.red.bold('\n✖ Process Error: ') + err.message);
220
+ });
221
+
222
+ } catch (err) {
223
+ spinner.fail(chalk.red.bold('Deployment failed'));
224
+ console.error(chalk.bgRed.white.bold('\n ERROR ') + ' ' + chalk.red(err.message));
225
+ if (err.stderr && err.stderr.length > 0) {
226
+ console.error(chalk.gray('\nDetails:\n' + err.stderr.toString().trim()));
227
+ }
228
+ process.exit(1);
229
+ }
230
+ }
231
+
232
+ deploy();
package/package.json CHANGED
@@ -1,6 +1,17 @@
1
1
  {
2
2
  "name": "@balcnix/fast-deploy",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Universal dependency installer and project runner",
5
+ "main": "bin/cli.js",
6
+ "bin": {
7
+ "balcnix": "bin/cli.js"
8
+ },
9
+ "preferGlobal": true,
10
+ "files": [
11
+ "bin/"
12
+ ],
13
+ "dependencies": {
14
+ "chalk": "^4.1.2",
15
+ "ora": "^5.4.1"
16
+ }
17
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.