drizzle-auto 1.1.11 → 1.1.13
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 +79 -118
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,153 +6,114 @@ const path = require("path");
|
|
|
6
6
|
const fs = require("fs");
|
|
7
7
|
|
|
8
8
|
/* =============================================================
|
|
9
|
-
🎨
|
|
10
|
-
============================================================= */
|
|
9
|
+
🎨 UI CORE (Universal ANSI)
|
|
10
|
+
============================================================= */
|
|
11
11
|
const T = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
reset: "\x1b[0m",
|
|
13
|
+
bold: "\x1b[1m",
|
|
14
|
+
cyan: "\x1b[38;5;51m",
|
|
15
|
+
pink: "\x1b[38;5;201m",
|
|
16
|
+
lime: "\x1b[38;5;118m",
|
|
17
|
+
yellow: "\x1b[38;5;226m",
|
|
18
|
+
red: "\x1b[38;5;196m",
|
|
19
|
+
gray: "\x1b[38;5;244m"
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
/* =============================================================
|
|
23
|
+
⏳ SPINNER
|
|
24
|
+
============================================================= */
|
|
22
25
|
const frames = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
|
|
23
|
-
let spinIdx = 0
|
|
26
|
+
let spinIdx = 0;
|
|
27
|
+
let spinInterval;
|
|
24
28
|
|
|
25
29
|
function startLoading(msg) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
stopLoading();
|
|
31
|
+
spinInterval = setInterval(() => {
|
|
32
|
+
process.stdout.write(`\r${T.cyan}${frames[spinIdx++ % frames.length]}${T.reset} ${T.bold}${msg}${T.reset} `);
|
|
33
|
+
}, 80);
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
function stopLoading() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/* =============================================================
|
|
41
|
-
🧩 AUTO SCRIPT INJECTOR
|
|
42
|
-
============================================================= */
|
|
43
|
-
const PKG = path.join(process.cwd(), "package.json");
|
|
44
|
-
function injectScript() {
|
|
45
|
-
if (!fs.existsSync(PKG)) return;
|
|
46
|
-
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
47
|
-
pkg.scripts ||= {};
|
|
48
|
-
if (!pkg.scripts.tea) {
|
|
49
|
-
pkg.scripts.tea = "drizzle-auto";
|
|
50
|
-
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
51
|
-
console.log(`${T.lime}⚡ Script added → npm run tea${T.reset}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
injectScript();
|
|
55
|
-
|
|
56
|
-
/* =============================================================
|
|
57
|
-
🔍 DRIZZLE DETECTOR
|
|
58
|
-
============================================================= */
|
|
59
|
-
function findDrizzleConfig(root) {
|
|
60
|
-
const exts = ["js","mjs","ts","mts","cjs"];
|
|
61
|
-
const files = [];
|
|
62
|
-
function walk(dir) {
|
|
63
|
-
fs.readdirSync(dir, { withFileTypes: true }).forEach(file => {
|
|
64
|
-
const full = path.join(dir, file.name);
|
|
65
|
-
if (file.isDirectory() && !/node_modules|.git|.next|dist/.test(file.name)) walk(full);
|
|
66
|
-
else if (file.isFile() && exts.some(ext => file.name === `drizzle.config.${ext}`)) files.push(full);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
walk(root);
|
|
70
|
-
return files;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function justifyStructure() {
|
|
74
|
-
const root = process.cwd();
|
|
75
|
-
const configs = findDrizzleConfig(root);
|
|
76
|
-
return configs.length === 0 ? { ok: false, msg: "Missing drizzle.config.*" } : { ok: true };
|
|
37
|
+
if (spinInterval) {
|
|
38
|
+
clearInterval(spinInterval);
|
|
39
|
+
spinInterval = null;
|
|
40
|
+
process.stdout.write("\r\x1b[K");
|
|
41
|
+
}
|
|
77
42
|
}
|
|
78
43
|
|
|
79
44
|
/* =============================================================
|
|
80
|
-
⚙️ SAFE STEP RUNNER
|
|
81
|
-
============================================================= */
|
|
45
|
+
⚙️ SAFE STEP RUNNER
|
|
46
|
+
============================================================= */
|
|
82
47
|
function runStep(args, label) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
48
|
+
return new Promise((resolve) => {
|
|
49
|
+
startLoading(`${T.pink}${label}${T.reset}`);
|
|
50
|
+
|
|
51
|
+
const child = spawn("npx", args, {
|
|
52
|
+
shell: true,
|
|
53
|
+
stdio: ["inherit", "pipe", "pipe"]
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
child.stdout.on("data", (data) => {
|
|
57
|
+
const out = data.toString();
|
|
58
|
+
if (!out.includes('Pulling')) {
|
|
59
|
+
stopLoading();
|
|
60
|
+
process.stdout.write(`${T.gray}${out}${T.reset}`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
child.on("close", (code) => {
|
|
65
|
+
stopLoading();
|
|
66
|
+
resolve(code === 0);
|
|
67
|
+
});
|
|
100
68
|
});
|
|
101
|
-
});
|
|
102
69
|
}
|
|
103
70
|
|
|
104
71
|
/* =============================================================
|
|
105
|
-
🔁 ENGINE WORKFLOW
|
|
106
|
-
============================================================= */
|
|
72
|
+
🔁 ENGINE WORKFLOW
|
|
73
|
+
============================================================= */
|
|
107
74
|
let isRunning = false;
|
|
108
75
|
|
|
109
76
|
async function triggerEngine() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const success = await runStep(step.args, step.name);
|
|
127
|
-
if (!success) {
|
|
128
|
-
console.log(`\n${T.red}${T.bold}✖ PIPELINE CRASHED AT [${step.name.toUpperCase()}]${T.reset}`);
|
|
129
|
-
isRunning = false; return;
|
|
77
|
+
if (isRunning) return;
|
|
78
|
+
isRunning = true;
|
|
79
|
+
|
|
80
|
+
const steps = [
|
|
81
|
+
{ name: "Checking Integrity", args: ["drizzle-kit", "check"] },
|
|
82
|
+
{ name: "Generating Migrations", args: ["drizzle-kit", "generate"] },
|
|
83
|
+
{ name: "Pushing to Database", args: ["drizzle-kit", "push"] }
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
for (const step of steps) {
|
|
87
|
+
const success = await runStep(step.args, step.name);
|
|
88
|
+
if (!success) {
|
|
89
|
+
console.log(`\n${T.red}${T.bold}✖ PIPELINE HALTED AT [${step.name.toUpperCase()}]${T.reset}`);
|
|
90
|
+
isRunning = false;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
130
93
|
}
|
|
131
|
-
}
|
|
132
94
|
|
|
133
|
-
|
|
134
|
-
|
|
95
|
+
console.log(`\n${T.lime}${T.bold}✔ DATABASE SYNCED${T.reset}`);
|
|
96
|
+
isRunning = false;
|
|
135
97
|
}
|
|
136
98
|
|
|
137
99
|
/* =============================================================
|
|
138
|
-
👀 WATCHER
|
|
139
|
-
============================================================= */
|
|
100
|
+
👀 WATCHER
|
|
101
|
+
============================================================= */
|
|
140
102
|
chokidar.watch(".", {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}).on("all", (
|
|
146
|
-
|
|
147
|
-
|
|
103
|
+
ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
|
|
104
|
+
ignoreInitial: true,
|
|
105
|
+
usePolling: true,
|
|
106
|
+
interval: 500
|
|
107
|
+
}).on("all", (event, file) => {
|
|
108
|
+
if (file.includes("schema") || file.includes("drizzle.config")) {
|
|
109
|
+
triggerEngine();
|
|
110
|
+
}
|
|
148
111
|
});
|
|
149
112
|
|
|
150
|
-
|
|
151
|
-
console.log(`${T.cyan}${T.bold}⚡ NEON-BLUE WATCHER ACTIVE [DRIZZLE]${T.reset}\n`);
|
|
113
|
+
// Initial run
|
|
152
114
|
triggerEngine();
|
|
153
115
|
|
|
154
116
|
process.on("SIGINT", () => {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
process.exit();
|
|
117
|
+
stopLoading();
|
|
118
|
+
process.exit();
|
|
158
119
|
});
|