next-auto-build 1.1.7 → 1.1.8

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/index.js +79 -39
  2. package/package.json +3 -8
package/index.js CHANGED
@@ -4,19 +4,18 @@ const chokidar = require('chokidar');
4
4
  const spawn = require('cross-spawn');
5
5
  const path = require('path');
6
6
  const fs = require('fs');
7
+ const readline = require('readline');
7
8
 
8
- // প্রোজেক্ট রুট খুঁজে বের করার উন্নত লজিক (pnpm ও Termux ফ্রেন্ডলি)
9
+ // ================================
10
+ // 🔍 Project Root Detection
11
+ // ================================
9
12
  function getProjectRoot() {
10
13
  const initCwd = process.env.INIT_CWD;
11
14
 
12
- if (
13
- initCwd &&
14
- fs.existsSync(path.join(initCwd, 'package.json'))
15
- ) {
15
+ if (initCwd && fs.existsSync(path.join(initCwd, 'package.json'))) {
16
16
  return initCwd;
17
17
  }
18
18
 
19
- // fallback (rare case)
20
19
  let root = process.cwd();
21
20
  if (root.includes('node_modules')) {
22
21
  root = root.split(`${path.sep}node_modules`)[0];
@@ -27,60 +26,85 @@ function getProjectRoot() {
27
26
  const projectRoot = getProjectRoot();
28
27
  const nextBin = path.resolve(projectRoot, 'node_modules', '.bin', 'next');
29
28
 
30
- // ১. অটো-স্ক্রিপ্ট ইনজেক্টর (FIXED PATH)
29
+ // ================================
30
+ // 🤖 Auto Script Injector
31
+ // ================================
31
32
  function addAutoScript() {
32
33
  const packageJsonPath = path.join(projectRoot, 'package.json');
33
-
34
- if (fs.existsSync(packageJsonPath)) {
35
- try {
36
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
37
- if (!packageJson.scripts) packageJson.scripts = {};
38
-
39
- if (!packageJson.scripts.auto) {
40
- packageJson.scripts.auto = "next-auto-build";
41
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
42
- console.log('\x1b[32m%s\x1b[0m', '🤖 [next-auto-build] Success: "auto" script added to your package.json');
43
- }
44
- } catch (err) { /* সাইলেন্ট এরর */ }
45
- }
34
+
35
+ if (!fs.existsSync(packageJsonPath)) return;
36
+
37
+ try {
38
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
39
+ if (!pkg.scripts) pkg.scripts = {};
40
+
41
+ if (!pkg.scripts.auto) {
42
+ pkg.scripts.auto = 'next-auto-build';
43
+ fs.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2));
44
+ console.log('\x1b[32m%s\x1b[0m', '🤖 [next-auto-build] "auto" script added');
45
+ }
46
+ } catch (_) {}
46
47
  }
47
48
 
48
- // ২. কাস্টম লগ সিস্টেম
49
+ // ================================
50
+ // 🧾 Logger
51
+ // ================================
49
52
  function log(message, type = 'info') {
50
- const icons = { info: '🤖', success: '🎉', error: '👾', build: '🚧' };
53
+ const icons = {
54
+ info: '🤖',
55
+ success: '🎉',
56
+ error: '👾',
57
+ build: '🚧',
58
+ ask: '❓'
59
+ };
51
60
  console.log(`${icons[type] || '•'} [${new Date().toLocaleTimeString()}] ${message}`);
52
61
  }
53
62
 
54
- // ৩. প্রোডাকশন বিল্ড লজিক
63
+ // ================================
64
+ // ⌨️ Readline (Ask Before Build)
65
+ // ================================
66
+ const rl = readline.createInterface({
67
+ input: process.stdin,
68
+ output: process.stdout
69
+ });
70
+
55
71
  let isBuilding = false;
72
+ let waitingForAnswer = false;
73
+
74
+ // ================================
75
+ // 🏗️ Production Build
76
+ // ================================
56
77
  function runProductionBuild() {
57
78
  if (isBuilding) return;
79
+
58
80
  if (!fs.existsSync(nextBin)) {
59
- log('Next.js binary not found. Please run install first.', 'error');
81
+ log('Next.js binary not found. Run install first.', 'error');
60
82
  return;
61
83
  }
62
84
 
63
85
  isBuilding = true;
64
86
  console.clear();
65
- log('Starting Production Build (Global Monitor Mode)...', 'build');
87
+ log('Starting Production Build...', 'build');
66
88
 
67
89
  const build = spawn(nextBin, ['build', '--webpack'], {
68
- stdio: 'inherit',
69
- shell: true
70
- });
90
+ stdio: 'inherit',
91
+ shell: true
92
+ });
71
93
 
72
94
  build.on('close', (code) => {
73
95
  isBuilding = false;
74
96
  if (code === 0) {
75
- log('Production Build Completed Successfully!', 'success');
97
+ log('Build completed successfully!', 'success');
76
98
  } else {
77
- log('Build Failed! Fix errors to retry.', 'error');
99
+ log('Build failed. Fix errors and try again.', 'error');
78
100
  }
79
- log('Waiting for ANY file change to rebuild...', 'info');
101
+ log('Watching for file changes...', 'info');
80
102
  });
81
103
  }
82
104
 
83
- // ৪. মেইন এক্সিকিউশন
105
+ // ================================
106
+ // 🚀 Init
107
+ // ================================
84
108
  const args = process.argv.slice(2);
85
109
 
86
110
  if (args.includes('--postinstall')) {
@@ -88,10 +112,9 @@ if (args.includes('--postinstall')) {
88
112
  process.exit(0);
89
113
  }
90
114
 
91
- // অটো-স্ক্রিপ্ট চেক এবং রান
92
115
  addAutoScript();
93
116
 
94
- const watcher = chokidar.watch('.', {
117
+ const watcher = chokidar.watch('.', {
95
118
  ignored: ['**/node_modules/**', '**/.next/**', '**/.git/**', '**/*.log'],
96
119
  persistent: true,
97
120
  ignoreInitial: true,
@@ -99,17 +122,34 @@ const watcher = chokidar.watch('.', {
99
122
  interval: 300
100
123
  });
101
124
 
102
- log('Next-Auto-Builder Active (Production Mode Only)', 'info');
125
+ log('Next-Auto-Builder Active (Manual Confirm Mode)', 'info');
103
126
 
127
+ // ================================
128
+ // 👀 Watcher Logic (ASK FIRST)
129
+ // ================================
104
130
  watcher.on('all', (event, filePath) => {
105
131
  if (filePath.includes('.next')) return;
106
- log(`File Event [${event}]: ${filePath}`, 'info');
107
- runProductionBuild();
108
- });
132
+ if (isBuilding || waitingForAnswer) return;
133
+
134
+ waitingForAnswer = true;
135
+ log(`File changed: ${filePath}`, 'ask');
136
+
137
+ rl.question('⚡ Build now? (y/n): ', (answer) => {
138
+ waitingForAnswer = false;
109
139
 
110
- runProductionBuild();
140
+ if (answer.trim().toLowerCase() === 'y') {
141
+ runProductionBuild();
142
+ } else {
143
+ log('Build skipped. Waiting for next change...', 'info');
144
+ }
145
+ });
146
+ });
111
147
 
148
+ // ================================
149
+ // 🧯 Safety Net
150
+ // ================================
112
151
  process.on('uncaughtException', (err) => {
113
152
  log(`System Error: ${err.message}`, 'error');
114
153
  isBuilding = false;
154
+ waitingForAnswer = false;
115
155
  });
package/package.json CHANGED
@@ -1,17 +1,12 @@
1
1
  {
2
2
  "name": "next-auto-build",
3
- "version": "1.1.7",
4
- "description": "Auto production build watcher for Next.js (adds auto script automatically)",
5
- "author": "Pavel Ahmmed Hridoy",
6
- "license": "MIT",
7
- "type": "commonjs",
3
+ "version": "1.1.8",
8
4
  "main": "index.js",
9
5
  "bin": {
10
- "next-auto-build": "index.js"
6
+ "next-auto": "./index.js"
11
7
  },
12
8
  "scripts": {
13
- "postinstall": "node index.js --postinstall",
14
- "auto": "next-auto-build"
9
+ "postinstall": "node index.js --postinstall"
15
10
  },
16
11
  "dependencies": {
17
12
  "chokidar": "^4.0.1",