drizzle-auto 1.0.11 → 1.0.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 +87 -115
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -5,150 +5,122 @@ const path = require("path");
|
|
|
5
5
|
const chokidar = require("chokidar");
|
|
6
6
|
const { spawn } = require("child_process");
|
|
7
7
|
|
|
8
|
-
/*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function stopSpinner() {
|
|
28
|
-
if (spinnerInterval) {
|
|
29
|
-
clearInterval(spinnerInterval);
|
|
30
|
-
spinnerInterval = null;
|
|
31
|
-
process.stdout.write("\r\x1b[K");
|
|
8
|
+
/* =========================
|
|
9
|
+
🧭 PROJECT ROOT
|
|
10
|
+
========================= */
|
|
11
|
+
const ROOT = process.cwd();
|
|
12
|
+
const PKG = path.join(ROOT, "package.json");
|
|
13
|
+
|
|
14
|
+
/* =========================
|
|
15
|
+
🧩 SCRIPT INJECTOR
|
|
16
|
+
========================= */
|
|
17
|
+
function injectScript() {
|
|
18
|
+
if (!fs.existsSync(PKG)) return;
|
|
19
|
+
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
20
|
+
pkg.scripts ||= {};
|
|
21
|
+
|
|
22
|
+
if (!pkg.scripts.tea) {
|
|
23
|
+
pkg.scripts.tea = "drizzle-auto";
|
|
24
|
+
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
25
|
+
console.log("☕ Script added → npm run tea");
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
28
|
|
|
35
|
-
/*
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
/* =========================
|
|
30
|
+
🔍 DRIZZLE DETECTOR
|
|
31
|
+
========================= */
|
|
32
|
+
function detectDrizzle() {
|
|
33
|
+
const configs = ["js","mjs","ts","mts"]
|
|
34
|
+
.map(e => `drizzle.config.${e}`)
|
|
35
|
+
.find(f => fs.existsSync(path.join(ROOT, f)));
|
|
36
|
+
|
|
37
|
+
if (!configs) {
|
|
38
|
+
console.log("⚠️ No drizzle.config found");
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
if (!fs.existsSync(PKG_PATH)) return;
|
|
42
|
+
let schemaPath = null;
|
|
41
43
|
try {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
} catch (e) {
|
|
52
|
-
console.error("❌ Could not update package.json");
|
|
44
|
+
const content = fs.readFileSync(path.join(ROOT, configs), "utf8");
|
|
45
|
+
const match = content.match(/schema:\s*["'](.+?)["']/);
|
|
46
|
+
if (match) schemaPath = path.join(ROOT, match[1]);
|
|
47
|
+
} catch {}
|
|
48
|
+
|
|
49
|
+
if (schemaPath && !fs.existsSync(schemaPath)) {
|
|
50
|
+
console.log("❌ Schema file missing");
|
|
51
|
+
return null;
|
|
53
52
|
}
|
|
54
|
-
}
|
|
55
53
|
|
|
56
|
-
|
|
57
|
-
function auditInfra() {
|
|
58
|
-
const results = [];
|
|
59
|
-
const configFile = ["ts","js","mjs","mts"].map(ext => `drizzle.config.${ext}`)
|
|
60
|
-
.find(f => fs.existsSync(path.join(PROJECT_ROOT, f)));
|
|
61
|
-
|
|
62
|
-
results.push({ name: "Drizzle Config", ok: !!configFile });
|
|
63
|
-
results.push({ name: ".env", ok: fs.existsSync(path.join(PROJECT_ROOT, ".env")) });
|
|
64
|
-
results.push({ name: "node_modules", ok: fs.existsSync(path.join(PROJECT_ROOT, "node_modules")) });
|
|
65
|
-
|
|
66
|
-
const missing = results.filter(r => !r.ok).map(r => r.name);
|
|
67
|
-
return { ok: missing.length === 0, missing };
|
|
54
|
+
return { config: configs, schema: schemaPath };
|
|
68
55
|
}
|
|
69
56
|
|
|
70
|
-
/*
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
/* =========================
|
|
58
|
+
⚙️ SAFE COMMAND RUNNER
|
|
59
|
+
========================= */
|
|
60
|
+
function run(cmd) {
|
|
61
|
+
return new Promise((resolve) => {
|
|
73
62
|
let failed = false;
|
|
74
|
-
startSpinner(`npx ${cmd.join(" ")}`);
|
|
75
|
-
const p = spawn("npx", cmd, { shell: true, cwd: PROJECT_ROOT });
|
|
76
63
|
|
|
77
|
-
p
|
|
78
|
-
stopSpinner();
|
|
79
|
-
process.stdout.write(DIM + d.toString() + RESET);
|
|
80
|
-
if (/error|failed/i.test(d)) failed = true;
|
|
81
|
-
});
|
|
64
|
+
const p = spawn("npx", cmd, { shell: true });
|
|
82
65
|
|
|
66
|
+
p.stdout.on("data", d => process.stdout.write(d));
|
|
83
67
|
p.stderr.on("data", d => {
|
|
84
|
-
stopSpinner();
|
|
85
|
-
process.stderr.write("\x1b[31m" + d + RESET);
|
|
86
68
|
failed = true;
|
|
69
|
+
process.stderr.write(d);
|
|
87
70
|
});
|
|
88
71
|
|
|
89
|
-
p.on("close", code =>
|
|
72
|
+
p.on("close", code => {
|
|
73
|
+
resolve(code === 0 && !failed);
|
|
74
|
+
});
|
|
90
75
|
});
|
|
91
76
|
}
|
|
92
77
|
|
|
93
|
-
/*
|
|
94
|
-
|
|
95
|
-
|
|
78
|
+
/* =========================
|
|
79
|
+
🔁 PIPELINE (NON-KILLING)
|
|
80
|
+
========================= */
|
|
81
|
+
let busy = false;
|
|
96
82
|
|
|
97
|
-
async function
|
|
98
|
-
if (
|
|
99
|
-
|
|
83
|
+
async function pipeline(trigger) {
|
|
84
|
+
if (busy) return;
|
|
85
|
+
busy = true;
|
|
100
86
|
|
|
101
|
-
|
|
102
|
-
console.log(`\n${nextColor()}⚡ Trigger → ${trigger}${RESET}`);
|
|
87
|
+
console.log(`\n⚡ Trigger → ${trigger}`);
|
|
103
88
|
|
|
104
|
-
const
|
|
105
|
-
if (!
|
|
106
|
-
|
|
107
|
-
audit.missing.forEach(m => console.log(DIM + "• " + m + RESET));
|
|
108
|
-
hasError = true;
|
|
109
|
-
running = false;
|
|
89
|
+
const drizzle = detectDrizzle();
|
|
90
|
+
if (!drizzle) {
|
|
91
|
+
busy = false;
|
|
110
92
|
return;
|
|
111
93
|
}
|
|
112
94
|
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
for (const step of steps) {
|
|
119
|
-
if (!(await runCmd(step))) {
|
|
120
|
-
console.log("\n\x1b[31m💀 Pipeline crashed\x1b[0m");
|
|
121
|
-
hasError = true;
|
|
122
|
-
running = false;
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
95
|
+
const genOK = await run(["drizzle-kit", "generate"]);
|
|
96
|
+
if (!genOK) {
|
|
97
|
+
console.log("🛑 Generate failed — pipeline paused");
|
|
98
|
+
busy = false;
|
|
99
|
+
return;
|
|
125
100
|
}
|
|
126
101
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
102
|
+
const pushOK = await run(["drizzle-kit", "push"]);
|
|
103
|
+
if (!pushOK) {
|
|
104
|
+
console.log("🛑 Push failed — server still running");
|
|
105
|
+
busy = false;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
console.log("✨ Drizzle fully synced");
|
|
110
|
+
busy = false;
|
|
130
111
|
}
|
|
131
112
|
|
|
132
|
-
/*
|
|
133
|
-
|
|
134
|
-
|
|
113
|
+
/* =========================
|
|
114
|
+
👀 WATCHER (ALWAYS ALIVE)
|
|
115
|
+
========================= */
|
|
116
|
+
injectScript();
|
|
117
|
+
pipeline("Initial");
|
|
118
|
+
|
|
119
|
+
chokidar.watch(ROOT, {
|
|
120
|
+
ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
|
|
135
121
|
ignoreInitial: true,
|
|
136
122
|
usePolling: true,
|
|
137
123
|
interval: 300
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (file.includes("schema") || file.endsWith(".ts") || file.endsWith(".js")) {
|
|
142
|
-
workflow(`${event.toUpperCase()} → ${path.basename(file)}`);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
/* ======================= 🚀 Init ======================= */
|
|
147
|
-
addTeaScript();
|
|
148
|
-
workflow("Initial Audit");
|
|
149
|
-
|
|
150
|
-
process.on("uncaughtException", err => {
|
|
151
|
-
stopSpinner();
|
|
152
|
-
console.log("\x1b[31m🔥 Crash:\x1b[0m", err.message);
|
|
153
|
-
running = false;
|
|
154
|
-
});
|
|
124
|
+
}).on("all", (_, file) => {
|
|
125
|
+
pipeline(path.basename(file));
|
|
126
|
+
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-auto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"bin": {
|
|
5
5
|
"drizzle-auto": "index.js"
|
|
6
6
|
},
|
|
7
7
|
"scripts": {
|
|
8
|
-
"postinstall": "node index.js --postinstall"
|
|
8
|
+
"postinstall": "node index.js --postinstall",
|
|
9
|
+
"tea": "node index.js"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
12
|
"chokidar": "^5.0.0",
|