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.
- package/index.js +14 -44
- 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
|
|
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.
|
|
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
|
|
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 (
|
|
108
|
+
log('Next-Auto-Builder Active (Ask on file change)', 'info');
|
|
129
109
|
|
|
130
110
|
// ================================
|
|
131
|
-
// ๐
|
|
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 ||
|
|
136
|
-
|
|
137
|
-
// ๐ฅ FIRST BUILD โ AUTO
|
|
138
|
-
if (!hasBuiltOnce) {
|
|
139
|
-
runProductionBuild();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
115
|
+
if (isBuilding || asking) return;
|
|
142
116
|
|
|
143
|
-
|
|
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
|
-
|
|
121
|
+
asking = false;
|
|
149
122
|
|
|
150
123
|
if (answer.trim().toLowerCase() === 'y') {
|
|
151
124
|
runProductionBuild();
|
|
152
125
|
} else {
|
|
153
|
-
log('Build skipped.
|
|
126
|
+
log('Build skipped. Watching...', 'info');
|
|
154
127
|
}
|
|
155
128
|
});
|
|
156
129
|
});
|
|
157
130
|
|
|
158
|
-
//
|
|
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
|
-
|
|
137
|
+
asking = false;
|
|
168
138
|
});
|