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.
Files changed (2) hide show
  1. package/index.js +61 -70
  2. 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
- const init = process.env.INIT_CWD;
28
- if (init && fs.existsSync(path.join(init, "package.json"))) return init;
29
- let cwd = process.cwd();
30
- if (cwd.includes("node_modules")) cwd = cwd.split(`node_modules${path.sep}`)[0];
31
- return cwd;
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
- if (!fs.existsSync(pkgPath)) return;
42
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
43
- pkg.scripts ||= {};
44
- if (!pkg.scripts.auto) {
45
- pkg.scripts.auto = "next-auto-build";
46
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
47
- console.log(`${T.lime}Script injected → npm run auto${T.reset}`);
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
- if (!fs.existsSync(filePath)) return null;
56
- const content = fs.readFileSync(filePath, "utf8");
57
- return crypto.createHash("md5").update(content).digest("hex");
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
- const currentHash = getFileHash(changedFile) || changedFile;
65
- const flagPath = path.join(projectRoot, `.next-auto-${Buffer.from(changedFile).toString('hex')}`);
66
- const lastHash = fs.existsSync(flagPath) ? fs.readFileSync(flagPath, "utf8") : null;
67
-
68
- if (currentHash === lastHash) return;
69
- fs.writeFileSync(flagPath, currentHash);
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
- spawn("node", [__filename, "--postinstall"], { stdio: "inherit", shell: true, cwd: projectRoot });
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
- addAutoScript();
76
- process.exit(0);
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
- if (running) return;
87
- if (!fs.existsSync(nextBin)) {
88
- console.log(`${T.red}${T.bold}✖ Next.js not found.${T.reset}`);
89
- return;
90
- }
91
- running = true;
92
- console.log(`${T.blue}⠋${T.reset} ${T.bold}Building Next.js Project...${T.reset}`);
93
-
94
- const p = spawn(nextBin, ["build", "--webpack"], { stdio: "inherit", shell: true });
95
- p.on("close", (code) => {
96
- running = false;
97
- if (code === 0) {
98
- console.log(`${T.lime}${T.bold}✔ SYSTEM JUSTIFIED & SYNCED${T.reset}\n`);
99
- } else {
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
- ignored: ["/node_modules/", "/.next/", "/.git/", "**/*.log"],
115
- ignoreInitial: true,
116
- usePolling: true,
117
- interval: 300
105
+ ignored: ["/node_modules/", "/.next/", "/.git/", "**/*.log"],
106
+ ignoreInitial: true,
107
+ usePolling: true,
108
+ interval: 300
118
109
  }).on("all", (event, filePath) => {
119
- if (!filePath) return;
120
- console.log(`${T.gray}${T.italic}→ Change in: ${path.basename(filePath)}${T.reset}`);
121
- runAutoAction(filePath);
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-auto-build",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Auto production build watcher for Next.js (adds auto script automatically)",
5
5
  "author": "Pavel Ahmmed Hridoy",
6
6
  "license": "MIT",