drizzle-auto 1.0.9 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +9 -164
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,175 +1,20 @@
1
1
  #!/usr/bin/env node
2
-
3
2
  const fs = require("fs");
4
3
  const path = require("path");
5
- const chokidar = require("chokidar");
6
- const { spawn } = require("child_process");
7
4
 
8
- /* =======================
9
- 🎨 NeonPulse Colors
10
- ======================= */
11
- const COLORS = ["\x1b[31m","\x1b[32m","\x1b[33m","\x1b[34m","\x1b[35m","\x1b[36m"];
12
- const RESET = "\x1b[0m";
13
- const BOLD = "\x1b[1m";
14
- const DIM = "\x1b[90m";
15
- let colorIndex = 0;
16
- const nextColor = () => COLORS[colorIndex++ % COLORS.length];
17
- const rainbow = text => text.split("").map(c => `${nextColor()}${c}`).join("") + RESET;
5
+ const projectRoot = process.env.INIT_CWD || process.cwd();
6
+ const pkgPath = path.join(projectRoot, "package.json");
18
7
 
19
- /* =======================
20
- Spinner
21
- ======================= */
22
- const FRAMES = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
23
- let spinIndex = 0;
24
- let spinnerInterval = null;
25
- function startSpinner(msg) {
26
- stopSpinner();
27
- spinnerInterval = setInterval(() => {
28
- process.stdout.write(`\r${nextColor()}${FRAMES[spinIndex++ % FRAMES.length]} ${msg}${RESET}`);
29
- }, 80);
30
- }
31
- function stopSpinner() {
32
- if (spinnerInterval) {
33
- clearInterval(spinnerInterval);
34
- spinnerInterval = null;
35
- process.stdout.write("\r\x1b[K");
36
- }
37
- }
38
-
39
- /* =======================
40
- 🧠 Project Root + Package.json
41
- ======================= */
42
- const PROJECT_ROOT = process.env.INIT_CWD || process.cwd();
43
- const PKG_PATH = path.join(PROJECT_ROOT, "package.json");
44
-
45
- function addTeaScript() {
46
- if (!fs.existsSync(PKG_PATH)) return;
47
- const pkg = JSON.parse(fs.readFileSync(PKG_PATH, "utf8"));
8
+ function injectTeaScript() {
9
+ if (!fs.existsSync(pkgPath)) return;
10
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
48
11
  pkg.scripts ||= {};
49
12
  if (!pkg.scripts.tea) {
50
13
  pkg.scripts.tea = "drizzle-auto";
51
- fs.writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
52
- console.log(`⚡ tea script added → npm run tea`);
53
- }
54
- }
55
-
56
- /* =======================
57
- 🧪 Infra Audit
58
- ======================= */
59
- function auditInfra() {
60
- const results = [];
61
-
62
- // Drizzle config
63
- const configFile = ["ts","js","mjs","mts"].map(ext => `drizzle.config.${ext}`)
64
- .find(f => fs.existsSync(path.join(PROJECT_ROOT, f)));
65
- results.push({ name: "Drizzle Config", ok: !!configFile });
66
-
67
- // Schema path
68
- if (configFile) {
69
- try {
70
- const cfg = fs.readFileSync(path.join(PROJECT_ROOT, configFile), "utf8");
71
- const match = cfg.match(/schema:\s*["'](.+?)["']/);
72
- if (match) {
73
- results.push({
74
- name: `Schema (${match[1]})`,
75
- ok: fs.existsSync(path.join(PROJECT_ROOT, match[1]))
76
- });
77
- } else results.push({ name: "Schema Path", ok: false });
78
- } catch {
79
- results.push({ name: "Config Readable", ok: false });
80
- }
14
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
15
+ console.log("⚡ tea script injected → npm run tea");
81
16
  }
82
-
83
- // Essentials
84
- results.push({ name: ".env", ok: fs.existsSync(path.join(PROJECT_ROOT, ".env")) });
85
- results.push({ name: "node_modules", ok: fs.existsSync(path.join(PROJECT_ROOT, "node_modules")) });
86
-
87
- const missing = results.filter(r => !r.ok).map(r => r.name);
88
- return { ok: missing.length === 0, missing };
89
17
  }
90
18
 
91
- /* =======================
92
- ⚡ Run npx command
93
- ======================= */
94
- function runCmd(cmd) {
95
- return new Promise(resolve => {
96
- let failed = false;
97
- startSpinner(`npx ${cmd.join(" ")}`);
98
- const p = spawn("npx", cmd, { shell: true });
99
- p.stdout.on("data", d => {
100
- stopSpinner();
101
- process.stdout.write(DIM + d.toString() + RESET);
102
- if (/error|failed/i.test(d)) failed = true;
103
- });
104
- p.stderr.on("data", d => {
105
- stopSpinner();
106
- process.stderr.write("\x1b[31m" + d + RESET);
107
- failed = true;
108
- });
109
- p.on("close", code => resolve(code === 0 && !failed));
110
- });
111
- }
112
-
113
- /* =======================
114
- 🏁 Workflow
115
- ======================= */
116
- let running = false;
117
- let hasError = false;
118
-
119
- async function workflow(trigger) {
120
- if (running) return;
121
- running = true;
122
-
123
- if (!hasError) console.clear();
124
- console.log(`\n${nextColor()}⚡ Trigger → ${trigger}${RESET}`);
125
-
126
- const audit = auditInfra();
127
- if (!audit.ok) {
128
- console.log("\n\x1b[31m❌ Infra not ready\x1b[0m");
129
- audit.missing.forEach(m => console.log(DIM + "• " + m + RESET));
130
- hasError = true;
131
- running = false;
132
- return;
133
- }
134
-
135
- const steps = [
136
- ["drizzle-kit", "check"],
137
- ["drizzle-kit", "generate"],
138
- ["drizzle-kit", "push"]
139
- ];
140
-
141
- for (const step of steps) {
142
- if (!(await runCmd(step))) {
143
- console.log("\n\x1b[31m💀 Pipeline crashed\x1b[0m");
144
- hasError = true;
145
- running = false;
146
- return;
147
- }
148
- }
149
-
150
- hasError = false;
151
- console.log("\n\x1b[32m✨ Drizzle synced\x1b[0m");
152
- setTimeout(() => running = false, 1000);
153
- }
154
-
155
- /* =======================
156
- 👀 Watcher
157
- ======================= */
158
- chokidar.watch(PROJECT_ROOT, {
159
- ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
160
- ignoreInitial: true,
161
- usePolling: true,
162
- interval: 300
163
- }).on("all", (e, f) => workflow(`${e.toUpperCase()} → ${path.basename(f)}`));
164
-
165
- /* =======================
166
- 🚀 Init
167
- ======================= */
168
- addTeaScript(); // inject tea script automatically
169
- workflow("Initial Audit");
170
-
171
- process.on("uncaughtException", err => {
172
- stopSpinner();
173
- console.log("\x1b[31m🔥 Crash:\x1b[0m", err.message);
174
- running = false;
175
- });
19
+ // run immediately on load
20
+ injectTeaScript();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "bin": {
5
5
  "drizzle-auto": "index.js"
6
6
  },