drizzle-auto 1.1.8 → 1.1.10
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 +31 -98
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ const path = require("path");
|
|
|
6
6
|
const fs = require("fs");
|
|
7
7
|
|
|
8
8
|
/* =============================================================
|
|
9
|
-
🎨 NEON-PULSE UI CORE
|
|
9
|
+
🎨 NEON-PULSE UI CORE (Same as Next)
|
|
10
10
|
============================================================= */
|
|
11
11
|
const T = {
|
|
12
12
|
reset: "\x1b[0m",
|
|
@@ -38,162 +38,95 @@ function startLoading(msg) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function stopLoading() {
|
|
41
|
-
if (spinInterval) {
|
|
42
|
-
clearInterval(spinInterval);
|
|
43
|
-
spinInterval = null;
|
|
44
|
-
process.stdout.write("\r\x1b[K"); // Clear line
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/* =============================================================
|
|
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
|
-
}
|
|
41
|
+
if (spinInterval) { clearInterval(spinInterval); spinInterval = null; process.stdout.write("\r\x1b[K"); }
|
|
61
42
|
}
|
|
62
|
-
injectScript();
|
|
63
43
|
|
|
64
|
-
/*
|
|
44
|
+
/* =========================
|
|
65
45
|
🔍 ALL FILES DRIZZLE DETECTOR
|
|
66
|
-
|
|
46
|
+
========================= */
|
|
67
47
|
function findDrizzleConfig(root) {
|
|
68
48
|
const exts = ["js","mjs","ts","mts","cjs"];
|
|
69
49
|
const files = [];
|
|
70
|
-
|
|
71
50
|
function walk(dir) {
|
|
72
51
|
fs.readdirSync(dir, { withFileTypes: true }).forEach(file => {
|
|
73
52
|
const full = path.join(dir, file.name);
|
|
74
|
-
if (file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name))
|
|
75
|
-
|
|
76
|
-
} else if (file.isFile() && exts.some(ext => file.name === `drizzle.config.${ext}`)) {
|
|
77
|
-
files.push(full);
|
|
78
|
-
}
|
|
53
|
+
if (file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) walk(full);
|
|
54
|
+
else if (file.isFile() && exts.some(ext => file.name === `drizzle.config.${ext}`)) files.push(full);
|
|
79
55
|
});
|
|
80
56
|
}
|
|
81
|
-
|
|
82
57
|
walk(root);
|
|
83
58
|
return files;
|
|
84
59
|
}
|
|
85
60
|
|
|
86
61
|
function justifyStructure() {
|
|
87
|
-
const
|
|
88
|
-
const configs = findDrizzleConfig(root);
|
|
62
|
+
const configs = findDrizzleConfig(process.cwd());
|
|
89
63
|
if (configs.length === 0) return { ok: false, msg: "Missing drizzle.config.*" };
|
|
90
|
-
|
|
91
64
|
for (const configPath of configs) {
|
|
92
65
|
try {
|
|
93
66
|
const content = fs.readFileSync(configPath, "utf8");
|
|
94
67
|
const schemaMatch = content.match(/schema:\s*["'](.+?)["']/);
|
|
95
68
|
if (schemaMatch && schemaMatch[1]) {
|
|
96
69
|
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
|
-
}
|
|
70
|
+
if (!fs.existsSync(schemaFull)) return { ok: false, msg: `Schema not found: ${schemaMatch[1]}` };
|
|
100
71
|
}
|
|
101
|
-
} catch
|
|
102
|
-
return { ok: false, msg: `Config parse error in ${configPath}` };
|
|
103
|
-
}
|
|
72
|
+
} catch { return { ok: false, msg: `Config parse error in ${configPath}` }; }
|
|
104
73
|
}
|
|
105
|
-
|
|
106
74
|
return { ok: true, config: configs };
|
|
107
75
|
}
|
|
108
76
|
|
|
109
|
-
/*
|
|
77
|
+
/* =========================
|
|
110
78
|
⚙️ SAFE STEP RUNNER
|
|
111
|
-
|
|
79
|
+
========================= */
|
|
112
80
|
function runStep(args, label) {
|
|
113
|
-
return new Promise(
|
|
81
|
+
return new Promise(resolve => {
|
|
114
82
|
startLoading(`${T.pink}${label}${T.reset}`);
|
|
115
83
|
let localErr = false;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
child.stdout.on("data", (data) => {
|
|
84
|
+
const child = spawn("npx", args, { shell: true, stdio: ["inherit","pipe","pipe"] });
|
|
85
|
+
child.stdout.on("data", data => {
|
|
120
86
|
const out = data.toString();
|
|
121
|
-
if (!out.includes('Pulling schema')) {
|
|
122
|
-
stopLoading();
|
|
123
|
-
process.stdout.write(`${T.gray}${out}${T.reset}`);
|
|
124
|
-
}
|
|
87
|
+
if (!out.includes('Pulling schema')) { stopLoading(); process.stdout.write(`${T.gray}${out}${T.reset}`); }
|
|
125
88
|
if (/error|failed|ENOTFOUND/i.test(out)) localErr = true;
|
|
126
89
|
});
|
|
127
|
-
|
|
128
|
-
child.
|
|
129
|
-
stopLoading();
|
|
130
|
-
process.stderr.write(`${T.red}${T.bold}✖ ${data}${T.reset}`);
|
|
131
|
-
localErr = true;
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
child.on("close", (code) => {
|
|
135
|
-
stopLoading();
|
|
136
|
-
resolve(code === 0 && !localErr);
|
|
137
|
-
});
|
|
90
|
+
child.stderr.on("data", data => { stopLoading(); process.stderr.write(`${T.red}${T.bold}✖ ${data}${T.reset}`); localErr = true; });
|
|
91
|
+
child.on("close", code => { stopLoading(); resolve(code === 0 && !localErr); });
|
|
138
92
|
});
|
|
139
93
|
}
|
|
140
94
|
|
|
141
|
-
/*
|
|
95
|
+
/* =========================
|
|
142
96
|
🔁 ENGINE WORKFLOW
|
|
143
|
-
|
|
97
|
+
========================= */
|
|
144
98
|
let isRunning = false;
|
|
145
|
-
let hasError = false;
|
|
146
99
|
|
|
147
100
|
async function triggerEngine(event) {
|
|
148
101
|
if (isRunning) return;
|
|
149
102
|
isRunning = true;
|
|
150
103
|
|
|
151
104
|
const audit = justifyStructure();
|
|
152
|
-
if (!audit.ok) {
|
|
153
|
-
console.log(`${T.red}${T.bold}🛑 CRITICAL FAILURE:${T.reset} ${audit.msg}`);
|
|
154
|
-
hasError = true; isRunning = false; return;
|
|
155
|
-
}
|
|
105
|
+
if (!audit.ok) { console.log(`${T.red}${T.bold}🛑 CRITICAL FAILURE:${T.reset} ${audit.msg}`); isRunning=false; return; }
|
|
156
106
|
|
|
157
107
|
const steps = [
|
|
158
|
-
{ name: "
|
|
159
|
-
{ name: "
|
|
160
|
-
{ name: "
|
|
108
|
+
{ name: "Build Check", args:["drizzle-kit","check"] },
|
|
109
|
+
{ name: "Generate Migrations", args:["drizzle-kit","generate"] },
|
|
110
|
+
{ name: "Push Database", args:["drizzle-kit","push"] }
|
|
161
111
|
];
|
|
162
112
|
|
|
163
113
|
for (const step of steps) {
|
|
164
114
|
const success = await runStep(step.args, step.name);
|
|
165
|
-
if (!success) {
|
|
166
|
-
console.log(`\n${T.red}${T.bold}✖ PIPELINE CRASHED AT [${step.name.toUpperCase()}]${T.reset}`);
|
|
167
|
-
hasError = true; isRunning = false; return;
|
|
168
|
-
}
|
|
115
|
+
if (!success) { console.log(`\n${T.red}${T.bold}✖ PIPELINE CRASHED AT [${step.name.toUpperCase()}]${T.reset}`); isRunning=false; return; }
|
|
169
116
|
}
|
|
170
117
|
|
|
171
|
-
hasError = false;
|
|
172
118
|
console.log(`\n${T.lime}${T.bold}✔ SYSTEM JUSTIFIED & SYNCED${T.reset}`);
|
|
173
119
|
console.log(`${T.gray}Waiting for next server-side change...${T.reset}\n`);
|
|
174
120
|
isRunning = false;
|
|
175
121
|
}
|
|
176
122
|
|
|
177
|
-
/*
|
|
178
|
-
👀 WATCHER &
|
|
179
|
-
|
|
180
|
-
chokidar.watch(".", {
|
|
181
|
-
|
|
182
|
-
ignoreInitial: true,
|
|
183
|
-
usePolling: true,
|
|
184
|
-
interval: 300
|
|
185
|
-
}).on("all", (e, f) => triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
|
|
123
|
+
/* =========================
|
|
124
|
+
👀 WATCHER & CRASH PROTECTION
|
|
125
|
+
========================= */
|
|
126
|
+
chokidar.watch(".", { ignored:[/node_modules/, /\.git/, /\.next/, /dist/], ignoreInitial:true, usePolling:true, interval:300 })
|
|
127
|
+
.on("all",(e,f)=>triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
|
|
186
128
|
|
|
187
129
|
triggerEngine("Initial Audit");
|
|
188
130
|
|
|
189
|
-
process.on("uncaughtException", (err)
|
|
190
|
-
|
|
191
|
-
console.log(`\n${T.red}${T.bold}🛡️ PROTECTIVE SHIELD:${T.reset} ${err.message}`);
|
|
192
|
-
isRunning = false;
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
process.on("SIGINT", () => {
|
|
196
|
-
stopLoading();
|
|
197
|
-
console.log(`\n${T.yellow}Shutting down Drizzle-Auto...${T.reset}`);
|
|
198
|
-
process.exit();
|
|
199
|
-
});
|
|
131
|
+
process.on("uncaughtException",(err)=>{ stopLoading(); console.log(`\n${T.red}${T.bold}🛡️ PROTECTIVE SHIELD:${T.reset} ${err.message}`); isRunning=false; });
|
|
132
|
+
process.on("SIGINT",()=>{ stopLoading(); console.log(`\n${T.yellow}Shutting down Drizzle-Auto...${T.reset}`); process.exit(); });
|