drizzle-auto 1.0.3 → 1.0.5
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 +46 -152
- package/package.json +12 -4
package/index.js
CHANGED
|
@@ -1,166 +1,60 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const chokidar = require("chokidar");
|
|
4
|
-
const { spawn } = require("child_process");
|
|
5
|
-
const path = require("path");
|
|
6
3
|
const fs = require("fs");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/* =======================
|
|
22
|
-
⏳ Neon Spinner
|
|
23
|
-
======================= */
|
|
24
|
-
const spinnerFrames = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
|
|
25
|
-
let spinIndex = 0;
|
|
26
|
-
let spinnerInterval;
|
|
27
|
-
|
|
28
|
-
function startSpinner(text) {
|
|
29
|
-
stopSpinner();
|
|
30
|
-
spinnerInterval = setInterval(() => {
|
|
31
|
-
process.stdout.write(
|
|
32
|
-
`\r${nextColor()}${spinnerFrames[spinIndex++ % spinnerFrames.length]} ${text}${RESET}`
|
|
33
|
-
);
|
|
34
|
-
}, 80);
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const chokidar = require("chokidar");
|
|
6
|
+
const spawn = require("cross-spawn");
|
|
7
|
+
|
|
8
|
+
/* =========================
|
|
9
|
+
🧠 Detect target project root
|
|
10
|
+
========================= */
|
|
11
|
+
function getProjectRoot() {
|
|
12
|
+
const init = process.env.INIT_CWD;
|
|
13
|
+
if (init && fs.existsSync(path.join(init, "package.json"))) return init;
|
|
14
|
+
let cwd = process.cwd();
|
|
15
|
+
if (cwd.includes("node_modules")) cwd = cwd.split(`node_modules${path.sep}`)[0];
|
|
16
|
+
return cwd;
|
|
35
17
|
}
|
|
36
18
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
19
|
+
const projectRoot = getProjectRoot();
|
|
20
|
+
const pkgPath = path.join(projectRoot, "package.json");
|
|
21
|
+
|
|
22
|
+
/* =========================
|
|
23
|
+
✍️ Inject "tea" script
|
|
24
|
+
========================= */
|
|
25
|
+
function injectTeaScript() {
|
|
26
|
+
if (!fs.existsSync(pkgPath)) return;
|
|
27
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
28
|
+
pkg.scripts ||= {};
|
|
29
|
+
if (!pkg.scripts.tea) {
|
|
30
|
+
pkg.scripts.tea = "drizzle-auto";
|
|
31
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
32
|
+
console.log("⚡ Script injected → npm run tea");
|
|
42
33
|
}
|
|
43
34
|
}
|
|
44
35
|
|
|
45
|
-
/*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let isRunning = false;
|
|
52
|
-
let hasActiveError = false;
|
|
53
|
-
|
|
54
|
-
function auditInfra() {
|
|
55
|
-
const root = process.cwd();
|
|
56
|
-
const results = [];
|
|
57
|
-
|
|
58
|
-
const configName = ["ts","js","mjs","mts"]
|
|
59
|
-
.map(ext => `drizzle.config.${ext}`)
|
|
60
|
-
.find(f => fs.existsSync(path.join(root, f)));
|
|
61
|
-
|
|
62
|
-
results.push({ name: "Drizzle Config", ok: !!configName });
|
|
63
|
-
|
|
64
|
-
if (configName) {
|
|
65
|
-
try {
|
|
66
|
-
const cfg = fs.readFileSync(path.join(root, configName), "utf8");
|
|
67
|
-
const match = cfg.match(/schema:\s*["'](.+?)["']/);
|
|
68
|
-
if (match) {
|
|
69
|
-
results.push({
|
|
70
|
-
name: `Schema (${match[1]})`,
|
|
71
|
-
ok: fs.existsSync(path.join(root, match[1]))
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
results.push({ name: "Schema Path", ok: false });
|
|
75
|
-
}
|
|
76
|
-
} catch {
|
|
77
|
-
results.push({ name: "Config Read", ok: false });
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
results.push({ name: ".env", ok: fs.existsSync(path.join(root, ".env")) });
|
|
82
|
-
results.push({ name: "node_modules", ok: fs.existsSync(path.join(root, "node_modules")) });
|
|
83
|
-
|
|
84
|
-
const missing = results.filter(r => !r.ok).map(r => r.name);
|
|
85
|
-
return { ok: missing.length === 0, missing };
|
|
36
|
+
/* =========================
|
|
37
|
+
👀 Postinstall trigger
|
|
38
|
+
========================= */
|
|
39
|
+
if (process.argv.includes("--postinstall")) {
|
|
40
|
+
injectTeaScript();
|
|
41
|
+
process.exit(0);
|
|
86
42
|
}
|
|
87
43
|
|
|
88
|
-
/*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return new Promise((resolve) => {
|
|
93
|
-
let failed = false;
|
|
94
|
-
startSpinner(`npx ${cmd.join(" ")}`);
|
|
95
|
-
|
|
96
|
-
const p = spawn("npx", cmd, { shell: true });
|
|
97
|
-
|
|
98
|
-
p.stdout.on("data", d => {
|
|
99
|
-
stopSpinner();
|
|
100
|
-
process.stdout.write(DIM + d.toString() + RESET);
|
|
101
|
-
if (/error|failed/i.test(d)) failed = true;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
p.stderr.on("data", d => {
|
|
105
|
-
stopSpinner();
|
|
106
|
-
process.stderr.write("\x1b[31m" + d + RESET);
|
|
107
|
-
failed = true;
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
p.on("close", code => resolve(code === 0 && !failed));
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async function workflow(trigger) {
|
|
115
|
-
if (isRunning) return;
|
|
116
|
-
isRunning = true;
|
|
117
|
-
|
|
118
|
-
if (!hasActiveError) console.clear();
|
|
119
|
-
console.log(`\n${nextColor()}⚡ ${trigger}${RESET}`);
|
|
44
|
+
/* =========================
|
|
45
|
+
🚀 Watcher / Drizzle Auto Logic
|
|
46
|
+
========================= */
|
|
47
|
+
let running = false;
|
|
120
48
|
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
for (const step of [
|
|
131
|
-
["drizzle-kit", "check"],
|
|
132
|
-
["drizzle-kit", "generate"],
|
|
133
|
-
["drizzle-kit", "push"],
|
|
134
|
-
]) {
|
|
135
|
-
if (!(await run(step))) {
|
|
136
|
-
console.log("\n\x1b[31m💀 Pipeline crashed\x1b[0m");
|
|
137
|
-
hasActiveError = true;
|
|
138
|
-
isRunning = false;
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
hasActiveError = false;
|
|
144
|
-
console.log("\n\x1b[32m✨ Drizzle synced\x1b[0m");
|
|
145
|
-
setTimeout(() => (isRunning = false), 1200);
|
|
49
|
+
function run(cmd) {
|
|
50
|
+
if (running) return;
|
|
51
|
+
running = true;
|
|
52
|
+
console.clear();
|
|
53
|
+
console.log("🚀 Running Drizzle Pipeline...");
|
|
54
|
+
const p = spawn("npx", cmd, { stdio: "inherit", shell: true });
|
|
55
|
+
p.on("close", () => (running = false));
|
|
146
56
|
}
|
|
147
57
|
|
|
148
|
-
/* =======================
|
|
149
|
-
👀 Watcher
|
|
150
|
-
======================= */
|
|
151
58
|
chokidar
|
|
152
|
-
.watch(
|
|
153
|
-
|
|
154
|
-
ignoreInitial: true,
|
|
155
|
-
usePolling: true,
|
|
156
|
-
interval: 300,
|
|
157
|
-
})
|
|
158
|
-
.on("all", (e, f) => workflow(`${e.toUpperCase()} → ${path.basename(f)}`));
|
|
159
|
-
|
|
160
|
-
workflow("Initial Audit");
|
|
161
|
-
|
|
162
|
-
process.on("uncaughtException", (err) => {
|
|
163
|
-
stopSpinner();
|
|
164
|
-
console.log("\x1b[31m🔥 Crash:\x1b[0m", err.message);
|
|
165
|
-
isRunning = false;
|
|
166
|
-
});
|
|
59
|
+
.watch(projectRoot, { ignored: /node_modules|\.git|\.next/, ignoreInitial: true })
|
|
60
|
+
.on("all", () => run(["drizzle-kit", "check", "generate", "push"]));
|
package/package.json
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-auto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Auto Drizzle sync with tea script injection",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"bin": {
|
|
6
7
|
"drizzle-auto": "index.js"
|
|
7
8
|
},
|
|
8
9
|
"scripts": {
|
|
9
|
-
"
|
|
10
|
+
"postinstall": "node index.js --postinstall"
|
|
10
11
|
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"keywords": ["drizzle", "automation", "nextjs", "watcher", "tea"],
|
|
16
|
+
"author": "Pavel Ahmmed Hridoy",
|
|
17
|
+
"license": "MIT",
|
|
11
18
|
"dependencies": {
|
|
12
|
-
"chokidar": "^4.0.1"
|
|
19
|
+
"chokidar": "^4.0.1",
|
|
20
|
+
"cross-spawn": "^7.0.6"
|
|
13
21
|
}
|
|
14
|
-
}
|
|
22
|
+
}
|