next-auto-build 1.1.9 → 1.2.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.
- package/index.js +44 -18
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -54,27 +54,34 @@ function log(message, type = 'info') {
|
|
|
54
54
|
success: '🎉',
|
|
55
55
|
error: '👾',
|
|
56
56
|
build: '🚧',
|
|
57
|
-
ask: '❓'
|
|
57
|
+
ask: '❓',
|
|
58
|
+
key: '⌨️'
|
|
58
59
|
};
|
|
59
60
|
console.log(`${icons[type] || '•'} [${new Date().toLocaleTimeString()}] ${message}`);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
// ================================
|
|
63
|
-
// ⌨️ Readline
|
|
64
|
+
// ⌨️ Readline (GLOBAL HOTKEY MODE)
|
|
64
65
|
// ================================
|
|
65
66
|
const rl = readline.createInterface({
|
|
66
67
|
input: process.stdin,
|
|
67
68
|
output: process.stdout
|
|
68
69
|
});
|
|
69
70
|
|
|
71
|
+
process.stdin.setRawMode(true);
|
|
72
|
+
process.stdin.resume();
|
|
73
|
+
|
|
70
74
|
// ================================
|
|
71
|
-
// 🏗️ Build
|
|
75
|
+
// 🏗️ Build State
|
|
72
76
|
// ================================
|
|
73
77
|
let isBuilding = false;
|
|
74
78
|
let waitingForAnswer = false;
|
|
75
79
|
let hasBuiltOnce = false;
|
|
76
80
|
|
|
77
|
-
|
|
81
|
+
// ================================
|
|
82
|
+
// 🏗️ Production Build
|
|
83
|
+
// ================================
|
|
84
|
+
function runProductionBuild(reason = 'manual') {
|
|
78
85
|
if (isBuilding) return;
|
|
79
86
|
|
|
80
87
|
if (!fs.existsSync(nextBin)) {
|
|
@@ -83,8 +90,10 @@ function runProductionBuild() {
|
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
isBuilding = true;
|
|
93
|
+
waitingForAnswer = false;
|
|
94
|
+
|
|
86
95
|
console.clear();
|
|
87
|
-
log(
|
|
96
|
+
log(`Starting Production Build (${reason})...`, 'build');
|
|
88
97
|
|
|
89
98
|
const build = spawn(nextBin, ['build', '--webpack'], {
|
|
90
99
|
stdio: 'inherit',
|
|
@@ -101,7 +110,7 @@ function runProductionBuild() {
|
|
|
101
110
|
log('Build Failed! Fix errors to retry.', 'error');
|
|
102
111
|
}
|
|
103
112
|
|
|
104
|
-
log('Watching for file changes...', 'info');
|
|
113
|
+
log('Watching for file changes... (press "y" to rebuild, "q" to quit)', 'info');
|
|
105
114
|
});
|
|
106
115
|
}
|
|
107
116
|
|
|
@@ -125,22 +134,16 @@ const watcher = chokidar.watch('.', {
|
|
|
125
134
|
interval: 300
|
|
126
135
|
});
|
|
127
136
|
|
|
128
|
-
log('Next-Auto-Builder Active (
|
|
137
|
+
log('Next-Auto-Builder Active (Hotkey Mode Enabled)', 'info');
|
|
129
138
|
|
|
130
139
|
// ================================
|
|
131
|
-
// 👀 Watcher
|
|
140
|
+
// 👀 File Watcher
|
|
132
141
|
// ================================
|
|
133
142
|
watcher.on('all', (event, filePath) => {
|
|
134
143
|
if (filePath.includes('.next')) return;
|
|
135
144
|
if (isBuilding || waitingForAnswer) return;
|
|
136
145
|
|
|
137
|
-
//
|
|
138
|
-
if (!hasBuiltOnce) {
|
|
139
|
-
runProductionBuild();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// ❓ AFTER FIRST BUILD → ASK
|
|
146
|
+
// First build already done → ASK
|
|
144
147
|
waitingForAnswer = true;
|
|
145
148
|
log(`File changed: ${filePath}`, 'ask');
|
|
146
149
|
|
|
@@ -148,15 +151,38 @@ watcher.on('all', (event, filePath) => {
|
|
|
148
151
|
waitingForAnswer = false;
|
|
149
152
|
|
|
150
153
|
if (answer.trim().toLowerCase() === 'y') {
|
|
151
|
-
runProductionBuild();
|
|
154
|
+
runProductionBuild('file-change');
|
|
152
155
|
} else {
|
|
153
156
|
log('Build skipped. Waiting for next change...', 'info');
|
|
154
157
|
}
|
|
155
158
|
});
|
|
156
159
|
});
|
|
157
160
|
|
|
158
|
-
//
|
|
159
|
-
|
|
161
|
+
// ================================
|
|
162
|
+
// ⌨️ GLOBAL KEY HANDLER
|
|
163
|
+
// ================================
|
|
164
|
+
process.stdin.on('data', (key) => {
|
|
165
|
+
const k = key.toString().trim().toLowerCase();
|
|
166
|
+
|
|
167
|
+
if (k === 'y') {
|
|
168
|
+
log('Hotkey "y" pressed → rebuilding', 'key');
|
|
169
|
+
runProductionBuild('hotkey');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (k === 'q') {
|
|
173
|
+
log('Exiting watcher. Bye 👋', 'info');
|
|
174
|
+
process.exit(0);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (key[0] === 3) {
|
|
178
|
+
process.exit(); // Ctrl+C
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// ================================
|
|
183
|
+
// 🚀 First Build (AUTO)
|
|
184
|
+
// ================================
|
|
185
|
+
runProductionBuild('initial');
|
|
160
186
|
|
|
161
187
|
// ================================
|
|
162
188
|
// 🧯 Safety
|