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