drizzle-auto 1.1.6 → 1.1.8
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 +73 -73
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,8 +6,8 @@ const path = require("path");
|
|
|
6
6
|
const fs = require("fs");
|
|
7
7
|
|
|
8
8
|
/* =============================================================
|
|
9
|
-
🎨 NEON-PULSE UI CORE
|
|
10
|
-
|
|
9
|
+
🎨 NEON-PULSE UI CORE
|
|
10
|
+
============================================================= */
|
|
11
11
|
const T = {
|
|
12
12
|
reset: "\x1b[0m",
|
|
13
13
|
bold: "\x1b[1m",
|
|
@@ -19,44 +19,14 @@ const T = {
|
|
|
19
19
|
yellow: "\x1b[38;5;226m",
|
|
20
20
|
red: "\x1b[38;5;196m",
|
|
21
21
|
gray: "\x1b[38;5;244m",
|
|
22
|
+
magenta: "\x1b[38;5;201m",
|
|
22
23
|
bg_dark: "\x1b[48;5;234m"
|
|
23
24
|
};
|
|
24
25
|
|
|
25
|
-
const rainbow = (text) => {
|
|
26
|
-
const colors = [196, 208, 226, 118, 51, 201];
|
|
27
|
-
return text.split('').map((char, i) => `\x1b[38;5;${colors[i % colors.length]}m${char}`).join('') + T.reset;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
26
|
/* =============================================================
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
const PKG = path.join(ROOT, "package.json");
|
|
35
|
-
|
|
36
|
-
function injectTea() {
|
|
37
|
-
if (!fs.existsSync(PKG)) return;
|
|
38
|
-
try {
|
|
39
|
-
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
40
|
-
pkg.scripts ||= {};
|
|
41
|
-
if (!pkg.scripts.tea) {
|
|
42
|
-
pkg.scripts.tea = "drizzle-auto";
|
|
43
|
-
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
44
|
-
console.log(`${T.cyan}☕ Script injected → ${T.bold}npm run tea${T.reset}`);
|
|
45
|
-
} else {
|
|
46
|
-
console.log(`${T.gray}☕ Tea script already exists${T.reset}`);
|
|
47
|
-
}
|
|
48
|
-
} catch (e) {
|
|
49
|
-
console.log(`${T.red}⚠ Failed to inject tea script:${T.reset} ${e.message}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Run injection immediately
|
|
54
|
-
injectTea();
|
|
55
|
-
|
|
56
|
-
/* =============================================================
|
|
57
|
-
⏳ HIGH-FIDELITY SPINNER & LOADING
|
|
58
|
-
============================================================= */
|
|
59
|
-
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
27
|
+
⏳ SPINNER & LOADING
|
|
28
|
+
============================================================= */
|
|
29
|
+
const frames = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
|
|
60
30
|
let spinIdx = 0;
|
|
61
31
|
let spinInterval;
|
|
62
32
|
|
|
@@ -71,39 +41,74 @@ function stopLoading() {
|
|
|
71
41
|
if (spinInterval) {
|
|
72
42
|
clearInterval(spinInterval);
|
|
73
43
|
spinInterval = null;
|
|
74
|
-
process.stdout.write("\r\x1b[K"); // Clear
|
|
44
|
+
process.stdout.write("\r\x1b[K"); // Clear line
|
|
75
45
|
}
|
|
76
46
|
}
|
|
77
47
|
|
|
78
48
|
/* =============================================================
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
49
|
+
🧩 AUTO SCRIPT INJECTOR
|
|
50
|
+
============================================================= */
|
|
51
|
+
const PKG = path.join(process.cwd(), "package.json");
|
|
52
|
+
function injectScript() {
|
|
53
|
+
if (!fs.existsSync(PKG)) return;
|
|
54
|
+
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
55
|
+
pkg.scripts ||= {};
|
|
56
|
+
if (!pkg.scripts.tea) {
|
|
57
|
+
pkg.scripts.tea = "drizzle-auto";
|
|
58
|
+
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
59
|
+
console.log(`${T.lime}☕ Script added → npm run tea${T.reset}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
injectScript();
|
|
63
|
+
|
|
64
|
+
/* =============================================================
|
|
65
|
+
🔍 ALL FILES DRIZZLE DETECTOR
|
|
66
|
+
============================================================= */
|
|
67
|
+
function findDrizzleConfig(root) {
|
|
68
|
+
const exts = ["js","mjs","ts","mts","cjs"];
|
|
69
|
+
const files = [];
|
|
70
|
+
|
|
71
|
+
function walk(dir) {
|
|
72
|
+
fs.readdirSync(dir, { withFileTypes: true }).forEach(file => {
|
|
73
|
+
const full = path.join(dir, file.name);
|
|
74
|
+
if (file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) {
|
|
75
|
+
walk(full);
|
|
76
|
+
} else if (file.isFile() && exts.some(ext => file.name === `drizzle.config.${ext}`)) {
|
|
77
|
+
files.push(full);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
walk(root);
|
|
83
|
+
return files;
|
|
84
|
+
}
|
|
83
85
|
|
|
84
|
-
// Dynamic File Justification
|
|
85
86
|
function justifyStructure() {
|
|
86
87
|
const root = process.cwd();
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
const configs = findDrizzleConfig(root);
|
|
89
|
+
if (configs.length === 0) return { ok: false, msg: "Missing drizzle.config.*" };
|
|
90
|
+
|
|
91
|
+
for (const configPath of configs) {
|
|
92
|
+
try {
|
|
93
|
+
const content = fs.readFileSync(configPath, "utf8");
|
|
94
|
+
const schemaMatch = content.match(/schema:\s*["'](.+?)["']/);
|
|
95
|
+
if (schemaMatch && schemaMatch[1]) {
|
|
96
|
+
const schemaFull = path.resolve(path.dirname(configPath), schemaMatch[1]);
|
|
97
|
+
if (!fs.existsSync(schemaFull)) {
|
|
98
|
+
return { ok: false, msg: `Schema not found: ${schemaMatch[1]} in ${configPath}` };
|
|
99
|
+
}
|
|
99
100
|
}
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return { ok: false, msg: `Config parse error in ${configPath}` };
|
|
100
103
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return { ok: true, config };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { ok: true, config: configs };
|
|
104
107
|
}
|
|
105
108
|
|
|
106
|
-
|
|
109
|
+
/* =============================================================
|
|
110
|
+
⚙️ SAFE STEP RUNNER
|
|
111
|
+
============================================================= */
|
|
107
112
|
function runStep(args, label) {
|
|
108
113
|
return new Promise((resolve) => {
|
|
109
114
|
startLoading(`${T.pink}${label}${T.reset}`);
|
|
@@ -134,24 +139,21 @@ function runStep(args, label) {
|
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
/* =============================================================
|
|
137
|
-
🔁
|
|
138
|
-
|
|
142
|
+
🔁 ENGINE WORKFLOW
|
|
143
|
+
============================================================= */
|
|
144
|
+
let isRunning = false;
|
|
145
|
+
let hasError = false;
|
|
146
|
+
|
|
139
147
|
async function triggerEngine(event) {
|
|
140
148
|
if (isRunning) return;
|
|
141
149
|
isRunning = true;
|
|
142
150
|
|
|
143
|
-
if (!hasError) console.clear();
|
|
144
|
-
console.log(`\n${T.bg_dark} ${rainbow(" DRIZZLE-AUTO v2026 ")} ${T.reset}`);
|
|
145
|
-
console.log(`${T.pink}●${T.reset} ${T.bold}Event:${T.reset} ${T.cyan}${event}${T.reset}\n`);
|
|
146
|
-
|
|
147
|
-
// Step 2: Infrastructure Audit
|
|
148
151
|
const audit = justifyStructure();
|
|
149
152
|
if (!audit.ok) {
|
|
150
153
|
console.log(`${T.red}${T.bold}🛑 CRITICAL FAILURE:${T.reset} ${audit.msg}`);
|
|
151
154
|
hasError = true; isRunning = false; return;
|
|
152
155
|
}
|
|
153
156
|
|
|
154
|
-
// Step 3-5: Execution Chain
|
|
155
157
|
const steps = [
|
|
156
158
|
{ name: "Confirming Integrity", args: ["drizzle-kit", "check"] },
|
|
157
159
|
{ name: "Generating Migrations", args: ["drizzle-kit", "generate"] },
|
|
@@ -173,8 +175,8 @@ async function triggerEngine(event) {
|
|
|
173
175
|
}
|
|
174
176
|
|
|
175
177
|
/* =============================================================
|
|
176
|
-
👀
|
|
177
|
-
|
|
178
|
+
👀 WATCHER & GLOBAL CRASH PROTECTION
|
|
179
|
+
============================================================= */
|
|
178
180
|
chokidar.watch(".", {
|
|
179
181
|
ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
|
|
180
182
|
ignoreInitial: true,
|
|
@@ -182,10 +184,8 @@ chokidar.watch(".", {
|
|
|
182
184
|
interval: 300
|
|
183
185
|
}).on("all", (e, f) => triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
|
|
184
186
|
|
|
185
|
-
// Initial Ignition
|
|
186
187
|
triggerEngine("Initial Audit");
|
|
187
188
|
|
|
188
|
-
// Global Crash Protection
|
|
189
189
|
process.on("uncaughtException", (err) => {
|
|
190
190
|
stopLoading();
|
|
191
191
|
console.log(`\n${T.red}${T.bold}🛡️ PROTECTIVE SHIELD:${T.reset} ${err.message}`);
|
|
@@ -193,7 +193,7 @@ process.on("uncaughtException", (err) => {
|
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
process.on("SIGINT", () => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
stopLoading();
|
|
197
|
+
console.log(`\n${T.yellow}Shutting down Drizzle-Auto...${T.reset}`);
|
|
198
|
+
process.exit();
|
|
199
199
|
});
|