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