next-auto-build 1.1.1 → 1.1.2
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 +61 -70
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,74 +6,70 @@ const chokidar = require("chokidar");
|
|
|
6
6
|
const spawn = require("cross-spawn");
|
|
7
7
|
const crypto = require("crypto");
|
|
8
8
|
|
|
9
|
-
/* =============================================================
|
|
10
|
-
🎨 CYBER-BLUE UI CORE (Unified Brand)
|
|
11
|
-
============================================================= */
|
|
12
|
-
const T = {
|
|
13
|
-
reset: "\x1b[0m",
|
|
14
|
-
bold: "\x1b[1m",
|
|
15
|
-
italic: "\x1b[3m",
|
|
16
|
-
cyan: "\x1b[38;5;51m", // Header
|
|
17
|
-
blue: "\x1b[38;5;33m", // Active
|
|
18
|
-
lime: "\x1b[38;5;118m", // Success
|
|
19
|
-
red: "\x1b[38;5;196m", // Error
|
|
20
|
-
gray: "\x1b[38;5;244m" // Paths
|
|
21
|
-
};
|
|
22
|
-
|
|
23
9
|
/* =========================
|
|
24
10
|
🧠 PROJECT ROOT DETECTOR
|
|
25
11
|
========================= */
|
|
26
12
|
function getProjectRoot() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
13
|
+
const init = process.env.INIT_CWD;
|
|
14
|
+
if (init && fs.existsSync(path.join(init, "package.json"))) return init;
|
|
15
|
+
let cwd = process.cwd();
|
|
16
|
+
if (cwd.includes("node_modules")) cwd = cwd.split(node_modules${path.sep})[0];
|
|
17
|
+
return cwd;
|
|
32
18
|
}
|
|
33
19
|
|
|
34
20
|
const projectRoot = getProjectRoot();
|
|
35
21
|
const pkgPath = path.join(projectRoot, "package.json");
|
|
22
|
+
const POST_FLAG = path.join(projectRoot, ".next-auto-postinstalled");
|
|
36
23
|
|
|
37
24
|
/* =========================
|
|
38
25
|
✍️ AUTO SCRIPT INJECTOR
|
|
39
26
|
========================= */
|
|
40
27
|
function addAutoScript() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
28
|
+
if (!fs.existsSync(pkgPath)) return;
|
|
29
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
30
|
+
pkg.scripts ||= {};
|
|
31
|
+
if (!pkg.scripts.auto) {
|
|
32
|
+
pkg.scripts.auto = "next-auto-build";
|
|
33
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
34
|
+
console.log("⚡ auto script injected → npm run auto");
|
|
35
|
+
}
|
|
49
36
|
}
|
|
50
37
|
|
|
51
38
|
/* =========================
|
|
52
39
|
🖇 HELPER: HASH FILE CONTENT
|
|
53
40
|
========================= */
|
|
54
41
|
function getFileHash(filePath) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
42
|
+
if (!fs.existsSync(filePath)) return null;
|
|
43
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
44
|
+
return crypto.createHash("md5").update(content).digest("hex");
|
|
58
45
|
}
|
|
59
46
|
|
|
60
47
|
/* =========================
|
|
61
|
-
🤖 AUTO POSTINSTALL
|
|
48
|
+
🤖 AUTO POSTINSTALL / AUTO ACTION
|
|
62
49
|
========================= */
|
|
63
50
|
function runAutoAction(changedFile) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
51
|
+
const currentHash = getFileHash(changedFile) || changedFile;
|
|
52
|
+
const flagPath = path.join(projectRoot, .next-auto-${Buffer.from(changedFile).toString('hex')});
|
|
53
|
+
|
|
54
|
+
const lastHash = fs.existsSync(flagPath) ? fs.readFileSync(flagPath, "utf8") : null;
|
|
55
|
+
if (currentHash === lastHash) return; // already processed
|
|
56
|
+
|
|
57
|
+
fs.writeFileSync(flagPath, currentHash); // save new hash
|
|
70
58
|
|
|
71
|
-
|
|
59
|
+
// Run self postinstall / auto logic
|
|
60
|
+
spawn(
|
|
61
|
+
"node",
|
|
62
|
+
[__filename, "--postinstall"],
|
|
63
|
+
{ stdio: "inherit", shell: true, cwd: projectRoot }
|
|
64
|
+
);
|
|
72
65
|
}
|
|
73
66
|
|
|
67
|
+
/* =========================
|
|
68
|
+
📦 POSTINSTALL MODE
|
|
69
|
+
========================= */
|
|
74
70
|
if (process.argv.includes("--postinstall")) {
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
addAutoScript();
|
|
72
|
+
process.exit(0);
|
|
77
73
|
}
|
|
78
74
|
|
|
79
75
|
/* =========================
|
|
@@ -83,43 +79,38 @@ const nextBin = path.join(projectRoot, "node_modules", ".bin", "next");
|
|
|
83
79
|
let running = false;
|
|
84
80
|
|
|
85
81
|
function build() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
console.log(`${T.red}${T.bold}✖ PIPELINE CRASHED AT [BUILD]${T.reset}\n`);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
82
|
+
if (running) return;
|
|
83
|
+
if (!fs.existsSync(nextBin)) {
|
|
84
|
+
console.log("❌ Next.js not found. Install next first.");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
running = true;
|
|
88
|
+
console.clear();
|
|
89
|
+
console.log("🚧 Production build running...");
|
|
90
|
+
const p = spawn(nextBin, ["build", "--webpack"], { stdio: "inherit", shell: true });
|
|
91
|
+
p.on("close", (code) => {
|
|
92
|
+
running = false;
|
|
93
|
+
if (code === 0) console.log("✅ Build success. Watching...");
|
|
94
|
+
else console.log("💥 Build failed. Fix & save.");
|
|
95
|
+
});
|
|
103
96
|
}
|
|
104
97
|
|
|
105
98
|
/* =========================
|
|
106
|
-
👀 INIT EVERYTHING
|
|
99
|
+
👀 INIT EVERYTHING AUTOMATICALLY
|
|
107
100
|
========================= */
|
|
108
|
-
console.clear();
|
|
109
|
-
console.log(`${T.cyan}${T.bold}⚡ NEON-BLUE WATCHER ACTIVE [NEXT]${T.reset}\n`);
|
|
110
101
|
addAutoScript();
|
|
111
|
-
runAutoAction(pkgPath);
|
|
102
|
+
runAutoAction(pkgPath); // first time run
|
|
112
103
|
|
|
113
104
|
chokidar.watch(projectRoot, {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
ignored: ["/node_modules/", "/.next/", "/.git/", "**/*.log"],
|
|
106
|
+
ignoreInitial: true,
|
|
107
|
+
usePolling: true,
|
|
108
|
+
interval: 300
|
|
118
109
|
}).on("all", (event, filePath) => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
build();
|
|
110
|
+
if (!filePath) return;
|
|
111
|
+
runAutoAction(filePath); // react to ANY file change
|
|
112
|
+
build();
|
|
123
113
|
});
|
|
124
114
|
|
|
125
|
-
build
|
|
115
|
+
// start first build
|
|
116
|
+
build();
|