drizzle-auto 1.0.22 → 1.0.23
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 +25 -32
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -5,23 +5,26 @@ const path = require("path");
|
|
|
5
5
|
const chokidar = require("chokidar");
|
|
6
6
|
const { spawn } = require("child_process");
|
|
7
7
|
|
|
8
|
-
/* =========================
|
|
9
|
-
🎨 COLOR CONFIG
|
|
10
|
-
========================= */
|
|
11
|
-
const COLORS = ["\x1b[31m","\x1b[32m","\x1b[33m","\x1b[34m","\x1b[35m","\x1b[36m"];
|
|
12
|
-
const RESET = "\x1b[0m";
|
|
13
|
-
const BOLD = "\x1b[1m";
|
|
14
|
-
|
|
15
|
-
let colorIndex = 0;
|
|
16
|
-
const nextColor = () => COLORS[colorIndex++ % COLORS.length];
|
|
17
|
-
const rainbow = text => text.split("").map(c => `${nextColor()}${c}`).join("") + RESET;
|
|
18
|
-
|
|
19
8
|
/* =========================
|
|
20
9
|
🧭 PROJECT ROOT
|
|
21
10
|
========================= */
|
|
22
11
|
const ROOT = process.cwd();
|
|
23
12
|
const PKG = path.join(ROOT, "package.json");
|
|
24
13
|
|
|
14
|
+
/* =========================
|
|
15
|
+
🎨 COLOR HELPERS
|
|
16
|
+
========================= */
|
|
17
|
+
const colors = {
|
|
18
|
+
reset: "\x1b[0m",
|
|
19
|
+
bright: "\x1b[1m",
|
|
20
|
+
red: "\x1b[31m",
|
|
21
|
+
green: "\x1b[32m",
|
|
22
|
+
yellow: "\x1b[33m",
|
|
23
|
+
blue: "\x1b[34m",
|
|
24
|
+
magenta: "\x1b[35m",
|
|
25
|
+
cyan: "\x1b[36m",
|
|
26
|
+
};
|
|
27
|
+
|
|
25
28
|
/* =========================
|
|
26
29
|
🧩 SCRIPT INJECTOR
|
|
27
30
|
========================= */
|
|
@@ -33,7 +36,7 @@ function injectScript() {
|
|
|
33
36
|
if (!pkg.scripts.tea) {
|
|
34
37
|
pkg.scripts.tea = "drizzle-auto";
|
|
35
38
|
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
36
|
-
console.log(
|
|
39
|
+
console.log(`${colors.cyan}☕ Script added → npm run tea${colors.reset}`);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -42,11 +45,11 @@ function injectScript() {
|
|
|
42
45
|
========================= */
|
|
43
46
|
function detectDrizzle() {
|
|
44
47
|
const configs = ["js","mjs","ts","mts"]
|
|
45
|
-
.map(e => `drizzle.config.${e}`)
|
|
48
|
+
.map(e => `drizzle.config.${e}`) // ✅ Fixed
|
|
46
49
|
.find(f => fs.existsSync(path.join(ROOT, f)));
|
|
47
50
|
|
|
48
51
|
if (!configs) {
|
|
49
|
-
console.log(
|
|
52
|
+
console.log(`${colors.yellow}⚠️ No drizzle.config found${colors.reset}`);
|
|
50
53
|
return null;
|
|
51
54
|
}
|
|
52
55
|
|
|
@@ -58,7 +61,7 @@ function detectDrizzle() {
|
|
|
58
61
|
} catch {}
|
|
59
62
|
|
|
60
63
|
if (schemaPath && !fs.existsSync(schemaPath)) {
|
|
61
|
-
console.log(
|
|
64
|
+
console.log(`${colors.red}❌ Schema file missing${colors.reset}`);
|
|
62
65
|
return null;
|
|
63
66
|
}
|
|
64
67
|
|
|
@@ -73,10 +76,10 @@ function run(cmd) {
|
|
|
73
76
|
let failed = false;
|
|
74
77
|
const p = spawn("npx", cmd, { shell: true });
|
|
75
78
|
|
|
76
|
-
p.stdout.on("data", d => process.stdout.write(d));
|
|
79
|
+
p.stdout.on("data", d => process.stdout.write(`${colors.green}${d}${colors.reset}`));
|
|
77
80
|
p.stderr.on("data", d => {
|
|
78
81
|
failed = true;
|
|
79
|
-
process.stderr.write(
|
|
82
|
+
process.stderr.write(`${colors.red}${d}${colors.reset}`);
|
|
80
83
|
});
|
|
81
84
|
|
|
82
85
|
p.on("close", code => resolve(code === 0 && !failed));
|
|
@@ -92,7 +95,7 @@ async function pipeline(trigger) {
|
|
|
92
95
|
if (busy) return;
|
|
93
96
|
busy = true;
|
|
94
97
|
|
|
95
|
-
console.log(
|
|
98
|
+
console.log(`${colors.magenta}\n⚡ Trigger → ${trigger}${colors.reset}`);
|
|
96
99
|
|
|
97
100
|
const drizzle = detectDrizzle();
|
|
98
101
|
if (!drizzle) {
|
|
@@ -102,19 +105,19 @@ async function pipeline(trigger) {
|
|
|
102
105
|
|
|
103
106
|
const genOK = await run(["drizzle-kit", "generate"]);
|
|
104
107
|
if (!genOK) {
|
|
105
|
-
console.log(
|
|
108
|
+
console.log(`${colors.red}🛑 Generate failed — pipeline paused${colors.reset}`);
|
|
106
109
|
busy = false;
|
|
107
110
|
return;
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
const pushOK = await run(["drizzle-kit", "push"]);
|
|
111
114
|
if (!pushOK) {
|
|
112
|
-
console.log(
|
|
115
|
+
console.log(`${colors.red}🛑 Push failed — server still running${colors.reset}`);
|
|
113
116
|
busy = false;
|
|
114
117
|
return;
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
console.log(
|
|
120
|
+
console.log(`${colors.cyan}✨ Drizzle fully synced${colors.reset}`);
|
|
118
121
|
busy = false;
|
|
119
122
|
}
|
|
120
123
|
|
|
@@ -129,14 +132,4 @@ chokidar.watch(ROOT, {
|
|
|
129
132
|
ignoreInitial: true,
|
|
130
133
|
usePolling: true,
|
|
131
134
|
interval: 300
|
|
132
|
-
}).on("all", (_, file) =>
|
|
133
|
-
pipeline(path.basename(file));
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
/* =========================
|
|
137
|
-
🚨 HANDLE CRASHES
|
|
138
|
-
========================= */
|
|
139
|
-
process.on("uncaughtException", (err) => {
|
|
140
|
-
console.log("\x1b[31m🔥 Crash:\x1b[0m", err.message);
|
|
141
|
-
busy = false;
|
|
142
|
-
});
|
|
135
|
+
}).on("all", (_, file) => pipeline(path.basename(file)));
|