drizzle-auto 1.0.10 → 1.0.12

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 +128 -10
  2. package/package.json +4 -3
package/index.js CHANGED
@@ -1,20 +1,138 @@
1
1
  #!/usr/bin/env node
2
+
2
3
  const fs = require("fs");
3
4
  const path = require("path");
5
+ const chokidar = require("chokidar");
6
+ const { spawn } = require("child_process");
7
+
8
+ /* ======================
9
+ 🌈 NEON CORE
10
+ ====================== */
11
+ const COLORS = ["\x1b[31m","\x1b[32m","\x1b[33m","\x1b[34m","\x1b[35m","\x1b[36m"];
12
+ const RESET = "\x1b[0m";
13
+ const DIM = "\x1b[90m";
14
+ let c = 0;
15
+ const color = () => COLORS[c++ % COLORS.length];
16
+ const rainbow = t => t.split("").map(x => color()+x).join("")+RESET;
17
+
18
+ /* ======================
19
+ ⏳ SPINNER
20
+ ====================== */
21
+ const FRAMES = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
22
+ let i=0, spin;
23
+ const start = txt => {
24
+ stop();
25
+ spin = setInterval(()=>{
26
+ process.stdout.write(`\r${color()}${FRAMES[i++%FRAMES.length]} ${txt}${RESET}`);
27
+ },80);
28
+ };
29
+ const stop = ()=>{ if(spin){ clearInterval(spin); spin=null; process.stdout.write("\r\x1b[K"); }};
4
30
 
5
- const projectRoot = process.env.INIT_CWD || process.cwd();
6
- const pkgPath = path.join(projectRoot, "package.json");
31
+ /* ======================
32
+ 📦 ROOT + SCRIPT INJECT
33
+ ====================== */
34
+ const ROOT = process.env.INIT_CWD || process.cwd();
35
+ const PKG = path.join(ROOT,"package.json");
7
36
 
8
- function injectTeaScript() {
9
- if (!fs.existsSync(pkgPath)) return;
10
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
37
+ function injectTea(){
38
+ if(!fs.existsSync(PKG)) return;
39
+ const pkg = JSON.parse(fs.readFileSync(PKG,"utf8"));
11
40
  pkg.scripts ||= {};
12
- if (!pkg.scripts.tea) {
41
+ if(!pkg.scripts.tea){
13
42
  pkg.scripts.tea = "drizzle-auto";
14
- fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
15
- console.log("⚡ tea script injected → npm run tea");
43
+ fs.writeFileSync(PKG, JSON.stringify(pkg,null,2));
44
+ console.log(color()+"⚡ script added → npm run tea"+RESET);
16
45
  }
17
46
  }
18
47
 
19
- // run immediately on load
20
- injectTeaScript();
48
+ /* ======================
49
+ 🧠 DRIZZLE SCAN
50
+ ====================== */
51
+ function audit(){
52
+ const exts = ["js","ts","mjs","mts"];
53
+ const cfg = exts.map(e=>`drizzle.config.${e}`)
54
+ .find(f=>fs.existsSync(path.join(ROOT,f)));
55
+
56
+ if(!cfg) return fail("Drizzle config not found");
57
+
58
+ const txt = fs.readFileSync(path.join(ROOT,cfg),"utf8");
59
+ const m = txt.match(/schema:\s*["'](.+?)["']/);
60
+ if(!m) return fail("Schema path missing");
61
+
62
+ if(!fs.existsSync(path.join(ROOT,m[1])))
63
+ return fail(`Schema not found → ${m[1]}`);
64
+
65
+ if(!fs.existsSync(path.join(ROOT,".env")))
66
+ return fail(".env missing");
67
+
68
+ if(!fs.existsSync(path.join(ROOT,"node_modules")))
69
+ return fail("node_modules missing");
70
+
71
+ return { ok:true };
72
+ }
73
+
74
+ const fail = m => ({ ok:false, msg:m });
75
+
76
+ /* ======================
77
+ ⚙️ RUNNER
78
+ ====================== */
79
+ const run = cmd => new Promise(res=>{
80
+ start("npx "+cmd.join(" "));
81
+ const p = spawn("npx", cmd, { stdio:"inherit", shell:true });
82
+ p.on("close", code=>{
83
+ stop();
84
+ res(code===0);
85
+ });
86
+ });
87
+
88
+ /* ======================
89
+ 🚀 PIPELINE
90
+ ====================== */
91
+ let busy=false;
92
+ async function pipeline(trigger){
93
+ if(busy) return;
94
+ busy=true;
95
+
96
+ console.clear();
97
+ console.log(rainbow("🔥 DrizzlePulse — Server Start"));
98
+ console.log(DIM+"Trigger → "+trigger+RESET+"\n");
99
+
100
+ const a = audit();
101
+ if(!a.ok){
102
+ console.log("\x1b[31m❌ "+a.msg+RESET);
103
+ busy=false;
104
+ return;
105
+ }
106
+
107
+ for(const step of [["drizzle-kit","generate"],["drizzle-kit","push"]]){
108
+ if(!(await run(step))){
109
+ console.log("\n\x1b[31m💀 Pipeline crashed"+RESET);
110
+ busy=false;
111
+ return;
112
+ }
113
+ }
114
+
115
+ console.log("\n\x1b[32m✨ Drizzle synced successfully"+RESET);
116
+ busy=false;
117
+ }
118
+
119
+ /* ======================
120
+ 👀 WATCH MODE (SERVER)
121
+ ====================== */
122
+ injectTea();
123
+ pipeline("initial");
124
+
125
+ chokidar.watch(ROOT,{
126
+ ignored:[/node_modules/,/\.git/,/\.next/,/dist/],
127
+ ignoreInitial:true,
128
+ usePolling:true,
129
+ interval:300
130
+ }).on("all",(e,f)=>{
131
+ if(f) pipeline(`${e.toUpperCase()} → ${path.basename(f)}`);
132
+ });
133
+
134
+ process.on("uncaughtException",e=>{
135
+ stop();
136
+ console.log("\x1b[31m🔥 Crash:",e.message,RESET);
137
+ busy=false;
138
+ });
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
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
- "chokidar": "^4.0.1",
12
+ "chokidar": "^5.0.0",
12
13
  "cross-spawn": "^7.0.6"
13
14
  }
14
15
  }