next-auto-build 1.0.7 → 1.0.9
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 +78 -81
- package/package.json +5 -1
package/index.js
CHANGED
|
@@ -1,115 +1,112 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const chokidar = require('chokidar');
|
|
4
|
-
const spawn = require('cross-spawn');
|
|
5
|
-
const path = require('path');
|
|
6
3
|
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { spawn } = require('cross-spawn');
|
|
6
|
+
const chokidar = require('chokidar');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/* ===============================
|
|
9
|
+
🌍 Detect Target Project Root
|
|
10
|
+
================================= */
|
|
9
11
|
function getProjectRoot() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return initCwd;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// fallback (rare case)
|
|
20
|
-
let root = process.cwd();
|
|
21
|
-
if (root.includes('node_modules')) {
|
|
22
|
-
root = root.split(`${path.sep}node_modules`)[0];
|
|
23
|
-
}
|
|
24
|
-
return root;
|
|
12
|
+
// INIT_CWD is automatically set by npm/pnpm/yarn during install
|
|
13
|
+
const initCwd = process.env.INIT_CWD;
|
|
14
|
+
if (initCwd && fs.existsSync(path.join(initCwd, 'package.json'))) {
|
|
15
|
+
return initCwd;
|
|
16
|
+
}
|
|
17
|
+
return process.cwd(); // fallback
|
|
25
18
|
}
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// ১. অটো-স্ক্রিপ্ট ইনজেক্টর (FIXED PATH)
|
|
20
|
+
/* ===============================
|
|
21
|
+
🤖 Auto Script Injector
|
|
22
|
+
================================= */
|
|
31
23
|
function addAutoScript() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} catch (err) { /* সাইলেন্ট এরর */ }
|
|
24
|
+
const projectRoot = getProjectRoot();
|
|
25
|
+
const pkgPath = path.join(projectRoot, 'package.json');
|
|
26
|
+
|
|
27
|
+
if (!fs.existsSync(pkgPath)) return;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
31
|
+
if (!pkg.scripts) pkg.scripts = {};
|
|
32
|
+
if (!pkg.scripts.auto) {
|
|
33
|
+
pkg.scripts.auto = "next-auto"; // inject script
|
|
34
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
35
|
+
console.log('\x1b[32m%s\x1b[0m', '🤖 [next-auto-build] Success: "auto" script added to package.json');
|
|
45
36
|
}
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error('👾 Failed to update package.json:', err.message);
|
|
39
|
+
}
|
|
46
40
|
}
|
|
47
41
|
|
|
48
|
-
|
|
42
|
+
/* ===============================
|
|
43
|
+
⚙️ Production Build Function
|
|
44
|
+
================================= */
|
|
45
|
+
let isBuilding = false;
|
|
46
|
+
const nextBin = path.resolve(getProjectRoot(), 'node_modules', '.bin', 'next');
|
|
47
|
+
|
|
49
48
|
function log(message, type = 'info') {
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const icons = { info: '🤖', success: '🎉', error: '👾', build: '🚧' };
|
|
50
|
+
console.log(`${icons[type] || '•'} [${new Date().toLocaleTimeString()}] ${message}`);
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
// ৩. প্রোডাকশন বিল্ড লজিক
|
|
55
|
-
let isBuilding = false;
|
|
56
53
|
function runProductionBuild() {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
log('Waiting for ANY file change to rebuild...', 'info');
|
|
80
|
-
});
|
|
54
|
+
if (isBuilding) return;
|
|
55
|
+
if (!fs.existsSync(nextBin)) {
|
|
56
|
+
log('Next.js binary not found. Run install first.', 'error');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
isBuilding = true;
|
|
61
|
+
console.clear();
|
|
62
|
+
log('Starting Production Build (Global Monitor Mode)...', 'build');
|
|
63
|
+
|
|
64
|
+
const build = spawn(nextBin, ['build', '--webpack'], {
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
shell: true
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
build.on('close', (code) => {
|
|
70
|
+
isBuilding = false;
|
|
71
|
+
if (code === 0) log('Production Build Completed Successfully!', 'success');
|
|
72
|
+
else log('Build Failed! Fix errors to retry.', 'error');
|
|
73
|
+
log('Waiting for any file change to rebuild...', 'info');
|
|
74
|
+
});
|
|
81
75
|
}
|
|
82
76
|
|
|
83
|
-
|
|
77
|
+
/* ===============================
|
|
78
|
+
🏁 Main Execution
|
|
79
|
+
================================= */
|
|
84
80
|
const args = process.argv.slice(2);
|
|
85
81
|
|
|
82
|
+
// Postinstall hook: inject script automatically
|
|
86
83
|
if (args.includes('--postinstall')) {
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
addAutoScript();
|
|
85
|
+
process.exit(0);
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
//
|
|
88
|
+
// Run manually: add script + watcher
|
|
92
89
|
addAutoScript();
|
|
93
90
|
|
|
94
|
-
const watcher = chokidar.watch('.', {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
const watcher = chokidar.watch('.', {
|
|
92
|
+
ignored: ['**/node_modules/**', '**/.next/**', '**/.git/**', '**/*.log'],
|
|
93
|
+
persistent: true,
|
|
94
|
+
ignoreInitial: true,
|
|
95
|
+
usePolling: true,
|
|
96
|
+
interval: 300
|
|
100
97
|
});
|
|
101
98
|
|
|
102
99
|
log('Next-Auto-Builder Active (Production Mode Only)', 'info');
|
|
103
100
|
|
|
104
101
|
watcher.on('all', (event, filePath) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
if (filePath.includes('.next')) return;
|
|
103
|
+
log(`File Event [${event}]: ${filePath}`, 'info');
|
|
104
|
+
runProductionBuild();
|
|
108
105
|
});
|
|
109
106
|
|
|
110
107
|
runProductionBuild();
|
|
111
108
|
|
|
112
109
|
process.on('uncaughtException', (err) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
110
|
+
log(`System Error: ${err.message}`, 'error');
|
|
111
|
+
isBuilding = false;
|
|
112
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-auto-build",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Auto-injects 'auto' script for Next.js projects and manages builds",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Pavel Ahmmed Hridoy",
|
|
7
|
+
"type": "commonjs",
|
|
4
8
|
"main": "index.js",
|
|
5
9
|
"bin": {
|
|
6
10
|
"next-auto": "./index.js"
|