next-auto-build 1.1.9 โ†’ 1.2.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/index.js +14 -44
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -11,7 +11,6 @@ const readline = require('readline');
11
11
  // ================================
12
12
  function getProjectRoot() {
13
13
  const initCwd = process.env.INIT_CWD;
14
-
15
14
  if (initCwd && fs.existsSync(path.join(initCwd, 'package.json'))) {
16
15
  return initCwd;
17
16
  }
@@ -36,11 +35,9 @@ function addAutoScript() {
36
35
  try {
37
36
  const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
38
37
  if (!pkg.scripts) pkg.scripts = {};
39
-
40
38
  if (!pkg.scripts.auto) {
41
39
  pkg.scripts.auto = 'next-auto-build';
42
40
  fs.writeFileSync(packageJsonPath, JSON.stringify(pkg, null, 2));
43
- console.log('\x1b[32m%s\x1b[0m', '๐Ÿค– [next-auto-build] "auto" script added');
44
41
  }
45
42
  } catch {}
46
43
  }
@@ -49,13 +46,7 @@ function addAutoScript() {
49
46
  // ๐Ÿงพ Logger
50
47
  // ================================
51
48
  function log(message, type = 'info') {
52
- const icons = {
53
- info: '๐Ÿค–',
54
- success: '๐ŸŽ‰',
55
- error: '๐Ÿ‘พ',
56
- build: '๐Ÿšง',
57
- ask: 'โ“'
58
- };
49
+ const icons = { info: '๐Ÿค–', success: '๐ŸŽ‰', error: '๐Ÿ‘พ', build: '๐Ÿšง', ask: 'โ“' };
59
50
  console.log(`${icons[type] || 'โ€ข'} [${new Date().toLocaleTimeString()}] ${message}`);
60
51
  }
61
52
 
@@ -71,14 +62,13 @@ const rl = readline.createInterface({
71
62
  // ๐Ÿ—๏ธ Build Logic
72
63
  // ================================
73
64
  let isBuilding = false;
74
- let waitingForAnswer = false;
75
- let hasBuiltOnce = false;
65
+ let asking = false;
76
66
 
77
67
  function runProductionBuild() {
78
68
  if (isBuilding) return;
79
69
 
80
70
  if (!fs.existsSync(nextBin)) {
81
- log('Next.js binary not found. Please install dependencies first.', 'error');
71
+ log('Next.js binary not found. Run install first.', 'error');
82
72
  return;
83
73
  }
84
74
 
@@ -93,28 +83,18 @@ function runProductionBuild() {
93
83
 
94
84
  build.on('close', (code) => {
95
85
  isBuilding = false;
96
- hasBuiltOnce = true;
97
-
98
86
  if (code === 0) {
99
87
  log('Production Build Completed Successfully!', 'success');
100
88
  } else {
101
- log('Build Failed! Fix errors to retry.', 'error');
89
+ log('Build Failed! Fix errors.', 'error');
102
90
  }
103
-
104
- log('Watching for file changes...', 'info');
91
+ log('Waiting for file changes...', 'info');
105
92
  });
106
93
  }
107
94
 
108
95
  // ================================
109
96
  // ๐Ÿš€ Init
110
97
  // ================================
111
- const args = process.argv.slice(2);
112
-
113
- if (args.includes('--postinstall')) {
114
- addAutoScript();
115
- process.exit(0);
116
- }
117
-
118
98
  addAutoScript();
119
99
 
120
100
  const watcher = chokidar.watch('.', {
@@ -125,44 +105,34 @@ const watcher = chokidar.watch('.', {
125
105
  interval: 300
126
106
  });
127
107
 
128
- log('Next-Auto-Builder Active (First build auto, later manual)', 'info');
108
+ log('Next-Auto-Builder Active (Ask on file change)', 'info');
129
109
 
130
110
  // ================================
131
- // ๐Ÿ‘€ Watcher
111
+ // ๐Ÿ‘€ ASK ON FILE CHANGE (THIS IS THE KEY)
132
112
  // ================================
133
113
  watcher.on('all', (event, filePath) => {
134
114
  if (filePath.includes('.next')) return;
135
- if (isBuilding || waitingForAnswer) return;
136
-
137
- // ๐Ÿ”ฅ FIRST BUILD โ†’ AUTO
138
- if (!hasBuiltOnce) {
139
- runProductionBuild();
140
- return;
141
- }
115
+ if (isBuilding || asking) return;
142
116
 
143
- // โ“ AFTER FIRST BUILD โ†’ ASK
144
- waitingForAnswer = true;
117
+ asking = true;
145
118
  log(`File changed: ${filePath}`, 'ask');
146
119
 
147
120
  rl.question('โšก Build now? (y/n): ', (answer) => {
148
- waitingForAnswer = false;
121
+ asking = false;
149
122
 
150
123
  if (answer.trim().toLowerCase() === 'y') {
151
124
  runProductionBuild();
152
125
  } else {
153
- log('Build skipped. Waiting for next change...', 'info');
126
+ log('Build skipped. Watching...', 'info');
154
127
  }
155
128
  });
156
129
  });
157
130
 
158
- // ๐Ÿš€ Run first build immediately
159
- runProductionBuild();
131
+ // โŒ NO AUTO BUILD ON START
132
+ // runProductionBuild(); <-- intentionally removed
160
133
 
161
- // ================================
162
- // ๐Ÿงฏ Safety
163
- // ================================
164
134
  process.on('uncaughtException', (err) => {
165
135
  log(`System Error: ${err.message}`, 'error');
166
136
  isBuilding = false;
167
- waitingForAnswer = false;
137
+ asking = false;
168
138
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-auto-build",
3
- "version": "1.1.9",
3
+ "version": "1.2.1",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "next-auto": "./index.js"