drizzle-auto 1.0.10 → 1.0.11

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 +147 -13
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,20 +1,154 @@
1
1
  #!/usr/bin/env node
2
+
2
3
  const fs = require("fs");
3
4
  const path = require("path");
5
+ const chokidar = require("chokidar");
6
+ const { spawn } = require("child_process");
7
+
8
+ /* ======================= 🎨 NeonPulse Colors ======================= */
9
+ const COLORS = ["\x1b[31m","\x1b[32m","\x1b[33m","\x1b[34m","\x1b[35m","\x1b[36m"];
10
+ const RESET = "\x1b[0m";
11
+ const DIM = "\x1b[90m";
12
+ let colorIndex = 0;
13
+ const nextColor = () => COLORS[colorIndex++ % COLORS.length];
14
+
15
+ /* ======================= ⏳ Spinner ======================= */
16
+ const FRAMES = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
17
+ let spinIndex = 0;
18
+ let spinnerInterval = null;
19
+
20
+ function startSpinner(msg) {
21
+ stopSpinner();
22
+ spinnerInterval = setInterval(() => {
23
+ process.stdout.write(`\r${nextColor()}${FRAMES[spinIndex++ % FRAMES.length]} ${msg}${RESET}`);
24
+ }, 80);
25
+ }
26
+
27
+ function stopSpinner() {
28
+ if (spinnerInterval) {
29
+ clearInterval(spinnerInterval);
30
+ spinnerInterval = null;
31
+ process.stdout.write("\r\x1b[K");
32
+ }
33
+ }
4
34
 
5
- const projectRoot = process.env.INIT_CWD || process.cwd();
6
- const pkgPath = path.join(projectRoot, "package.json");
7
-
8
- function injectTeaScript() {
9
- if (!fs.existsSync(pkgPath)) return;
10
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
11
- pkg.scripts ||= {};
12
- if (!pkg.scripts.tea) {
13
- pkg.scripts.tea = "drizzle-auto";
14
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
15
- console.log("⚡ tea script injected npm run tea");
35
+ /* ======================= 🧠 Project Root + Package.json ======================= */
36
+ const PROJECT_ROOT = process.cwd();
37
+ const PKG_PATH = path.join(PROJECT_ROOT, "package.json");
38
+
39
+ function addTeaScript() {
40
+ if (!fs.existsSync(PKG_PATH)) return;
41
+ try {
42
+ const pkg = JSON.parse(fs.readFileSync(PKG_PATH, "utf8"));
43
+ pkg.scripts = pkg.scripts || {};
44
+
45
+ // ফিক্স: সরাসরি node index.js চালানো নিশ্চিত করা
46
+ if (!pkg.scripts.tea) {
47
+ pkg.scripts.tea = "node index.js";
48
+ fs.writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
49
+ console.log(`\x1b[32m⚡ tea script added → npm run tea\x1b[0m`);
50
+ }
51
+ } catch (e) {
52
+ console.error("❌ Could not update package.json");
16
53
  }
17
54
  }
18
55
 
19
- // run immediately on load
20
- injectTeaScript();
56
+ /* ======================= 🧪 Infra Audit ======================= */
57
+ function auditInfra() {
58
+ const results = [];
59
+ const configFile = ["ts","js","mjs","mts"].map(ext => `drizzle.config.${ext}`)
60
+ .find(f => fs.existsSync(path.join(PROJECT_ROOT, f)));
61
+
62
+ results.push({ name: "Drizzle Config", ok: !!configFile });
63
+ results.push({ name: ".env", ok: fs.existsSync(path.join(PROJECT_ROOT, ".env")) });
64
+ results.push({ name: "node_modules", ok: fs.existsSync(path.join(PROJECT_ROOT, "node_modules")) });
65
+
66
+ const missing = results.filter(r => !r.ok).map(r => r.name);
67
+ return { ok: missing.length === 0, missing };
68
+ }
69
+
70
+ /* ======================= ⚡ Run npx command ======================= */
71
+ function runCmd(cmd) {
72
+ return new Promise(resolve => {
73
+ let failed = false;
74
+ startSpinner(`npx ${cmd.join(" ")}`);
75
+ const p = spawn("npx", cmd, { shell: true, cwd: PROJECT_ROOT });
76
+
77
+ p.stdout.on("data", d => {
78
+ stopSpinner();
79
+ process.stdout.write(DIM + d.toString() + RESET);
80
+ if (/error|failed/i.test(d)) failed = true;
81
+ });
82
+
83
+ p.stderr.on("data", d => {
84
+ stopSpinner();
85
+ process.stderr.write("\x1b[31m" + d + RESET);
86
+ failed = true;
87
+ });
88
+
89
+ p.on("close", code => resolve(code === 0 && !failed));
90
+ });
91
+ }
92
+
93
+ /* ======================= 🏁 Workflow ======================= */
94
+ let running = false;
95
+ let hasError = false;
96
+
97
+ async function workflow(trigger) {
98
+ if (running) return;
99
+ running = true;
100
+
101
+ if (!hasError) console.clear();
102
+ console.log(`\n${nextColor()}⚡ Trigger → ${trigger}${RESET}`);
103
+
104
+ const audit = auditInfra();
105
+ if (!audit.ok) {
106
+ console.log("\n\x1b[31m❌ Infra not ready\x1b[0m");
107
+ audit.missing.forEach(m => console.log(DIM + "• " + m + RESET));
108
+ hasError = true;
109
+ running = false;
110
+ return;
111
+ }
112
+
113
+ const steps = [
114
+ ["drizzle-kit", "generate"],
115
+ ["drizzle-kit", "push"]
116
+ ];
117
+
118
+ for (const step of steps) {
119
+ if (!(await runCmd(step))) {
120
+ console.log("\n\x1b[31m💀 Pipeline crashed\x1b[0m");
121
+ hasError = true;
122
+ running = false;
123
+ return;
124
+ }
125
+ }
126
+
127
+ hasError = false;
128
+ console.log("\n\x1b[32m✨ Drizzle synced\x1b[0m");
129
+ setTimeout(() => { running = false; }, 1000);
130
+ }
131
+
132
+ /* ======================= 👀 Watcher ======================= */
133
+ const watcher = chokidar.watch(PROJECT_ROOT, {
134
+ ignored: [/node_modules/, /\.git/, /\.next/, /dist/, /migrations/],
135
+ ignoreInitial: true,
136
+ usePolling: true,
137
+ interval: 300
138
+ });
139
+
140
+ watcher.on("all", (event, file) => {
141
+ if (file.includes("schema") || file.endsWith(".ts") || file.endsWith(".js")) {
142
+ workflow(`${event.toUpperCase()} → ${path.basename(file)}`);
143
+ }
144
+ });
145
+
146
+ /* ======================= 🚀 Init ======================= */
147
+ addTeaScript();
148
+ workflow("Initial Audit");
149
+
150
+ process.on("uncaughtException", err => {
151
+ stopSpinner();
152
+ console.log("\x1b[31m🔥 Crash:\x1b[0m", err.message);
153
+ running = false;
154
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "bin": {
5
5
  "drizzle-auto": "index.js"
6
6
  },
@@ -8,7 +8,7 @@
8
8
  "postinstall": "node index.js --postinstall"
9
9
  },
10
10
  "dependencies": {
11
- "chokidar": "^4.0.1",
11
+ "chokidar": "^5.0.0",
12
12
  "cross-spawn": "^7.0.6"
13
13
  }
14
14
  }