stockhub-sms 1.0.0 → 1.1.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/stockhub.js +78 -34
  2. package/package.json +1 -1
  3. package/setup.js +36 -13
package/bin/stockhub.js CHANGED
@@ -1,44 +1,88 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const { execSync } = require('child_process');
4
+ const readline = require('readline');
4
5
  const path = require('path');
5
6
  const fs = require('fs');
6
7
 
7
- const ROOT = path.resolve(__dirname, '..');
8
- const BACKEND_DIR = path.join(ROOT, 'backend-project');
9
- const FRONTEND_DIR = path.join(ROOT, 'frontend-project');
10
-
11
- const commands = {
12
- setup: () => {
13
- require(path.join(ROOT, 'setup.js'));
14
- },
15
- install: () => {
16
- console.log('Installing backend dependencies...');
17
- execSync('npm install', { cwd: BACKEND_DIR, stdio: 'inherit' });
18
- console.log('Installing frontend dependencies...');
19
- execSync('npm install', { cwd: FRONTEND_DIR, stdio: 'inherit' });
20
- console.log('Done.');
21
- },
22
- start: () => {
23
- execSync('node server.js', { cwd: BACKEND_DIR, stdio: 'inherit' });
24
- },
25
- build: () => {
26
- execSync('npm run build', { cwd: FRONTEND_DIR, stdio: 'inherit' });
27
- }
28
- };
8
+ const PACKAGE_DIR = path.resolve(__dirname, '..');
9
+ const TARGET_DIR = process.cwd();
10
+ const BACKEND_DIR = path.join(TARGET_DIR, 'backend-project');
11
+ const FRONTEND_DIR = path.join(TARGET_DIR, 'frontend-project');
12
+
13
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
14
+
15
+ function ask(q) {
16
+ return new Promise(r => rl.question(q, r));
17
+ }
29
18
 
30
19
  const arg = process.argv[2];
20
+ const isHelp = arg === '--help' || arg === '-h' || arg === 'help';
31
21
 
32
- if (arg && commands[arg]) {
33
- commands[arg]();
34
- } else {
35
- console.log(`
36
- StockHub SMS - Stock Management System
37
-
38
- Usage:
39
- stockhub setup Run interactive setup (auto/manual)
40
- stockhub install Install all dependencies
41
- stockhub start Start the backend server
42
- stockhub build Build frontend for production
43
- `);
22
+ if (isHelp) {
23
+ console.log('\n Usage:\n npx stockhub-sms Interactive menu\n npx stockhub-sms setup Run auto setup\n npx stockhub-sms install Install deps\n npx stockhub-sms start Start backend\n npx stockhub-sms build Build frontend\n');
24
+ process.exit(0);
44
25
  }
26
+
27
+ if (arg && arg !== 'menu') {
28
+ const commands = {
29
+ setup: () => require(path.join(PACKAGE_DIR, 'setup.js')),
30
+ install: () => { console.log('Installing backend dependencies...'); execSync('npm install', { cwd: BACKEND_DIR, stdio: 'inherit' }); console.log('Installing frontend dependencies...'); execSync('npm install', { cwd: FRONTEND_DIR, stdio: 'inherit' }); console.log('Done.'); },
31
+ start: () => execSync('node server.js', { cwd: BACKEND_DIR, stdio: 'inherit' }),
32
+ build: () => execSync('npm run build', { cwd: FRONTEND_DIR, stdio: 'inherit' }),
33
+ };
34
+ if (commands[arg]) return commands[arg]();
35
+ console.log(`Unknown command: ${arg}\nRun: npx stockhub-sms --help`);
36
+ process.exit(1);
37
+ }
38
+
39
+ async function showMenu() {
40
+ console.log('');
41
+ console.log(' =============================================');
42
+ console.log(' StockHub - Stock Management System');
43
+ console.log(' =============================================');
44
+ console.log('');
45
+ console.log(' A web-based Stock Management System');
46
+ console.log(' (Express + React + MongoDB)\n');
47
+
48
+ while (true) {
49
+ console.log(' What would you like to do?\n');
50
+ console.log(' 1) Auto Setup - Install deps + configure .env');
51
+ console.log(' 2) Manual Setup - Show step-by-step instructions');
52
+ console.log(' 3) Install Dependencies Only');
53
+ console.log(' 4) Start Backend Server');
54
+ console.log(' 5) Build Frontend for Production');
55
+ console.log(' 6) Help / Usage');
56
+ console.log(' 0) Exit\n');
57
+
58
+ const choice = (await ask(' Enter your choice [0-6]: ')).trim();
59
+
60
+ if (choice === '1') {
61
+ require(path.join(PACKAGE_DIR, 'setup.js'));
62
+ break;
63
+ } else if (choice === '2') {
64
+ process.env.STOCKHUB_MANUAL = '1';
65
+ require(path.join(PACKAGE_DIR, 'setup.js'));
66
+ break;
67
+ } else if (choice === '3') {
68
+ console.log(''); execSync('npm install', { cwd: BACKEND_DIR, stdio: 'inherit' }); execSync('npm install', { cwd: FRONTEND_DIR, stdio: 'inherit' }); console.log(' Done.\n');
69
+ break;
70
+ } else if (choice === '4') {
71
+ execSync('node server.js', { cwd: BACKEND_DIR, stdio: 'inherit' });
72
+ break;
73
+ } else if (choice === '5') {
74
+ execSync('npm run build', { cwd: FRONTEND_DIR, stdio: 'inherit' }); console.log('');
75
+ break;
76
+ } else if (choice === '6') {
77
+ console.log('\n Usage:\n npx stockhub-sms Interactive menu\n npx stockhub-sms setup Run auto setup\n npx stockhub-sms install Install deps\n npx stockhub-sms start Start backend\n npx stockhub-sms build Build frontend\n');
78
+ break;
79
+ } else if (choice === '0') {
80
+ break;
81
+ } else {
82
+ console.log(' Invalid choice. Try again.\n');
83
+ }
84
+ }
85
+ rl.close();
86
+ }
87
+
88
+ showMenu();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stockhub-sms",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "StockHub - Stock Management System (Express + React + MongoDB)",
5
5
  "main": "backend-project/server.js",
6
6
  "scripts": {
package/setup.js CHANGED
@@ -4,11 +4,10 @@ const fs = require('fs');
4
4
  const path = require('path');
5
5
  const crypto = require('crypto');
6
6
 
7
- const ROOT = __dirname;
8
- const BACKEND_DIR = path.join(ROOT, 'backend-project');
9
- const FRONTEND_DIR = path.join(ROOT, 'frontend-project');
10
- const isInsideNodeModules = ROOT.includes('node_modules' + path.sep + 'stockhub-sms');
11
-
7
+ const PACKAGE_ROOT = __dirname;
8
+ const TARGET_ROOT = process.cwd();
9
+ const BACKEND_DIR = path.join(TARGET_ROOT, 'backend-project');
10
+ const FRONTEND_DIR = path.join(TARGET_ROOT, 'frontend-project');
12
11
  const args = process.argv.slice(2);
13
12
  const isYes = args.includes('--yes') || args.includes('-y');
14
13
 
@@ -17,6 +16,19 @@ const rl = readline.createInterface({
17
16
  output: process.stdout
18
17
  });
19
18
 
19
+ function copyDir(src, dest) {
20
+ if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
21
+ for (const entry of fs.readdirSync(src)) {
22
+ const srcPath = path.join(src, entry);
23
+ const destPath = path.join(dest, entry);
24
+ if (fs.statSync(srcPath).isDirectory()) {
25
+ copyDir(srcPath, destPath);
26
+ } else if (!fs.existsSync(destPath)) {
27
+ fs.copyFileSync(srcPath, destPath);
28
+ }
29
+ }
30
+ }
31
+
20
32
  function printBanner() {
21
33
  console.log('');
22
34
  console.log(' =============================================');
@@ -109,15 +121,26 @@ function printManualInstructions() {
109
121
  }
110
122
 
111
123
  async function main() {
112
- if (isInsideNodeModules && !isYes) {
113
- console.log(' [i] StockHub installed as a dependency.');
114
- console.log(' Run "npx stockhub-sms setup" for interactive setup.\n');
115
- rl.close();
116
- return;
117
- }
118
-
119
124
  printBanner();
120
125
 
126
+ const isScaffold = PACKAGE_ROOT !== TARGET_ROOT;
127
+ if (isScaffold) {
128
+ console.log(` [*] Setting up project in: ${TARGET_ROOT}\n`);
129
+ for (const name of fs.readdirSync(PACKAGE_ROOT)) {
130
+ if (name === 'node_modules' || name === '.git') continue;
131
+ const src = path.join(PACKAGE_ROOT, name);
132
+ const dest = path.join(TARGET_ROOT, name);
133
+ if (!fs.existsSync(dest)) {
134
+ if (fs.statSync(src).isDirectory()) {
135
+ copyDir(src, dest);
136
+ } else {
137
+ fs.copyFileSync(src, dest);
138
+ }
139
+ }
140
+ }
141
+ console.log(' [v] Project files copied\n');
142
+ }
143
+
121
144
  const alreadyInstalled =
122
145
  fs.existsSync(path.join(BACKEND_DIR, 'node_modules')) &&
123
146
  fs.existsSync(path.join(FRONTEND_DIR, 'node_modules'));
@@ -132,7 +155,7 @@ async function main() {
132
155
  }
133
156
  }
134
157
 
135
- const mode = isYes ? 'a' : await ask(' Choose setup mode: (a)uto or (m)anual? [A/m]: ');
158
+ const mode = isYes ? 'a' : process.env.STOCKHUB_MANUAL ? 'm' : await ask(' Choose setup mode: (a)uto or (m)anual? [A/m]: ');
136
159
  rl.close();
137
160
 
138
161
  if (mode === 'm') {