drizzle-auto 1.0.0
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 +166 -0
- package/package.json +14 -0
package/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const chokidar = require("chokidar");
|
|
4
|
+
const { spawn } = require("child_process");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
|
|
8
|
+
/* =======================
|
|
9
|
+
🎨 NeonPulse Color Core
|
|
10
|
+
======================= */
|
|
11
|
+
const PALETTE = ["\x1b[31m", "\x1b[32m", "\x1b[33m", "\x1b[34m", "\x1b[35m", "\x1b[36m"];
|
|
12
|
+
const RESET = "\x1b[0m";
|
|
13
|
+
const BOLD = "\x1b[1m";
|
|
14
|
+
const DIM = "\x1b[90m";
|
|
15
|
+
|
|
16
|
+
let colorIndex = 0;
|
|
17
|
+
const nextColor = () => PALETTE[colorIndex++ % PALETTE.length];
|
|
18
|
+
const rainbow = (text) =>
|
|
19
|
+
text.split("").map((c) => `${nextColor()}${c}`).join("") + RESET;
|
|
20
|
+
|
|
21
|
+
/* =======================
|
|
22
|
+
⏳ Neon Spinner
|
|
23
|
+
======================= */
|
|
24
|
+
const spinnerFrames = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
|
|
25
|
+
let spinIndex = 0;
|
|
26
|
+
let spinnerInterval;
|
|
27
|
+
|
|
28
|
+
function startSpinner(text) {
|
|
29
|
+
stopSpinner();
|
|
30
|
+
spinnerInterval = setInterval(() => {
|
|
31
|
+
process.stdout.write(
|
|
32
|
+
`\r${nextColor()}${spinnerFrames[spinIndex++ % spinnerFrames.length]} ${text}${RESET}`
|
|
33
|
+
);
|
|
34
|
+
}, 80);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function stopSpinner() {
|
|
38
|
+
if (spinnerInterval) {
|
|
39
|
+
clearInterval(spinnerInterval);
|
|
40
|
+
spinnerInterval = null;
|
|
41
|
+
process.stdout.write("\r\x1b[K");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* =======================
|
|
46
|
+
🧠 Infra Audit
|
|
47
|
+
======================= */
|
|
48
|
+
console.clear();
|
|
49
|
+
console.log(BOLD + rainbow("🚀 Drizzle-Auto // Neon Infra Sync"));
|
|
50
|
+
|
|
51
|
+
let isRunning = false;
|
|
52
|
+
let hasActiveError = false;
|
|
53
|
+
|
|
54
|
+
function auditInfra() {
|
|
55
|
+
const root = process.cwd();
|
|
56
|
+
const results = [];
|
|
57
|
+
|
|
58
|
+
const configName = ["ts","js","mjs","mts"]
|
|
59
|
+
.map(ext => `drizzle.config.${ext}`)
|
|
60
|
+
.find(f => fs.existsSync(path.join(root, f)));
|
|
61
|
+
|
|
62
|
+
results.push({ name: "Drizzle Config", ok: !!configName });
|
|
63
|
+
|
|
64
|
+
if (configName) {
|
|
65
|
+
try {
|
|
66
|
+
const cfg = fs.readFileSync(path.join(root, configName), "utf8");
|
|
67
|
+
const match = cfg.match(/schema:\s*["'](.+?)["']/);
|
|
68
|
+
if (match) {
|
|
69
|
+
results.push({
|
|
70
|
+
name: `Schema (${match[1]})`,
|
|
71
|
+
ok: fs.existsSync(path.join(root, match[1]))
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
results.push({ name: "Schema Path", ok: false });
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
results.push({ name: "Config Read", ok: false });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
results.push({ name: ".env", ok: fs.existsSync(path.join(root, ".env")) });
|
|
82
|
+
results.push({ name: "node_modules", ok: fs.existsSync(path.join(root, "node_modules")) });
|
|
83
|
+
|
|
84
|
+
const missing = results.filter(r => !r.ok).map(r => r.name);
|
|
85
|
+
return { ok: missing.length === 0, missing };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* =======================
|
|
89
|
+
⚙️ Runner
|
|
90
|
+
======================= */
|
|
91
|
+
function run(cmd) {
|
|
92
|
+
return new Promise((resolve) => {
|
|
93
|
+
let failed = false;
|
|
94
|
+
startSpinner(`npx ${cmd.join(" ")}`);
|
|
95
|
+
|
|
96
|
+
const p = spawn("npx", cmd, { shell: true });
|
|
97
|
+
|
|
98
|
+
p.stdout.on("data", d => {
|
|
99
|
+
stopSpinner();
|
|
100
|
+
process.stdout.write(DIM + d.toString() + RESET);
|
|
101
|
+
if (/error|failed/i.test(d)) failed = true;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
p.stderr.on("data", d => {
|
|
105
|
+
stopSpinner();
|
|
106
|
+
process.stderr.write("\x1b[31m" + d + RESET);
|
|
107
|
+
failed = true;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
p.on("close", code => resolve(code === 0 && !failed));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function workflow(trigger) {
|
|
115
|
+
if (isRunning) return;
|
|
116
|
+
isRunning = true;
|
|
117
|
+
|
|
118
|
+
if (!hasActiveError) console.clear();
|
|
119
|
+
console.log(`\n${nextColor()}⚡ ${trigger}${RESET}`);
|
|
120
|
+
|
|
121
|
+
const audit = auditInfra();
|
|
122
|
+
if (!audit.ok) {
|
|
123
|
+
console.log("\n\x1b[31m❌ Infra not ready\x1b[0m");
|
|
124
|
+
audit.missing.forEach(m => console.log(DIM + "• " + m + RESET));
|
|
125
|
+
hasActiveError = true;
|
|
126
|
+
isRunning = false;
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (const step of [
|
|
131
|
+
["drizzle-kit", "check"],
|
|
132
|
+
["drizzle-kit", "generate"],
|
|
133
|
+
["drizzle-kit", "push"],
|
|
134
|
+
]) {
|
|
135
|
+
if (!(await run(step))) {
|
|
136
|
+
console.log("\n\x1b[31m💀 Pipeline crashed\x1b[0m");
|
|
137
|
+
hasActiveError = true;
|
|
138
|
+
isRunning = false;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
hasActiveError = false;
|
|
144
|
+
console.log("\n\x1b[32m✨ Drizzle synced\x1b[0m");
|
|
145
|
+
setTimeout(() => (isRunning = false), 1200);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/* =======================
|
|
149
|
+
👀 Watcher
|
|
150
|
+
======================= */
|
|
151
|
+
chokidar
|
|
152
|
+
.watch(".", {
|
|
153
|
+
ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
|
|
154
|
+
ignoreInitial: true,
|
|
155
|
+
usePolling: true,
|
|
156
|
+
interval: 300,
|
|
157
|
+
})
|
|
158
|
+
.on("all", (e, f) => workflow(`${e.toUpperCase()} → ${path.basename(f)}`));
|
|
159
|
+
|
|
160
|
+
workflow("Initial Audit");
|
|
161
|
+
|
|
162
|
+
process.on("uncaughtException", (err) => {
|
|
163
|
+
stopSpinner();
|
|
164
|
+
console.log("\x1b[31m🔥 Crash:\x1b[0m", err.message);
|
|
165
|
+
isRunning = false;
|
|
166
|
+
});
|