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