drizzle-auto 1.0.12 → 1.0.14

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 +87 -98
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,133 +6,122 @@ const chokidar = require("chokidar");
6
6
  const { spawn } = require("child_process");
7
7
 
8
8
  /* ======================
9
- 🌈 NEON CORE
9
+ 🎨 COLOR SYSTEM
10
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;
11
+ const c = {
12
+ reset: "\x1b[0m",
13
+ cyan: "\x1b[36m",
14
+ green: "\x1b[32m",
15
+ yellow: "\x1b[33m",
16
+ red: "\x1b[31m",
17
+ gray: "\x1b[90m",
18
+ bold: "\x1b[1m"
19
+ };
20
+
21
+ const log = {
22
+ sys: m => console.log(`${c.cyan}●${c.reset} ${m}`),
23
+ ok: m => console.log(`${c.green}✔${c.reset} ${m}`),
24
+ warn: m => console.log(`${c.yellow}▲${c.reset} ${m}`),
25
+ err: m => console.log(`${c.red}✖${c.reset} ${m}`),
26
+ info: m => console.log(`${c.gray}${m}${c.reset}`)
27
+ };
17
28
 
18
29
  /* ======================
19
- SPINNER
30
+ 📍 PROJECT ROOT
20
31
  ====================== */
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"); }};
32
+ const ROOT = process.cwd();
33
+ const PKG = path.join(ROOT, "package.json");
30
34
 
31
35
  /* ======================
32
- 📦 ROOT + SCRIPT INJECT
36
+ ADD tea SCRIPT
33
37
  ====================== */
34
- const ROOT = process.env.INIT_CWD || process.cwd();
35
- const PKG = path.join(ROOT,"package.json");
38
+ function addTeaScript() {
39
+ if (!fs.existsSync(PKG)) {
40
+ log.err("package.json not found");
41
+ return;
42
+ }
36
43
 
37
- function injectTea(){
38
- if(!fs.existsSync(PKG)) return;
39
- const pkg = JSON.parse(fs.readFileSync(PKG,"utf8"));
44
+ const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
40
45
  pkg.scripts ||= {};
41
- if(!pkg.scripts.tea){
46
+
47
+ if (!pkg.scripts.tea) {
42
48
  pkg.scripts.tea = "drizzle-auto";
43
- fs.writeFileSync(PKG, JSON.stringify(pkg,null,2));
44
- console.log(color()+" script added → npm run tea"+RESET);
49
+ fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
50
+ log.ok("Script added → pnpm run tea");
51
+ } else {
52
+ log.info("Script already exists");
45
53
  }
46
54
  }
47
55
 
48
56
  /* ======================
49
- 🧠 DRIZZLE SCAN
57
+ 🔍 DRIZZLE CONFIG SCAN
50
58
  ====================== */
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 };
59
+ function findDrizzleConfig() {
60
+ const exts = ["js", "mjs", "ts", "mts"];
61
+ return exts.find(ext =>
62
+ fs.existsSync(path.join(ROOT, `drizzle.config.${ext}`))
63
+ );
72
64
  }
73
65
 
74
- const fail = m => ({ ok:false, msg:m });
75
-
76
66
  /* ======================
77
- ⚙️ RUNNER
67
+ ⚙️ SAFE COMMAND RUNNER
78
68
  ====================== */
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);
69
+ function run(cmd) {
70
+ return new Promise(resolve => {
71
+ const p = spawn("npx", cmd, { stdio: "inherit", shell: true });
72
+ p.on("close", code => resolve(code === 0));
85
73
  });
86
- });
74
+ }
87
75
 
88
76
  /* ======================
89
- 🚀 PIPELINE
77
+ 🔁 PIPELINE
90
78
  ====================== */
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;
79
+ let running = false;
80
+
81
+ async function pipeline(reason) {
82
+ if (running) return;
83
+ running = true;
84
+
85
+ log.sys(`Triggered by ${reason}`);
86
+
87
+ if (!findDrizzleConfig()) {
88
+ log.warn("No drizzle.config found (js/mjs/ts/mts)");
89
+ running = false;
104
90
  return;
105
91
  }
106
92
 
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
- }
93
+ log.sys("Running drizzle generate...");
94
+ if (!(await run(["drizzle-kit", "generate"]))) {
95
+ log.err("Generate failed — waiting for fix");
96
+ running = false;
97
+ return;
98
+ }
99
+
100
+ log.sys("Running drizzle push...");
101
+ if (!(await run(["drizzle-kit", "push"]))) {
102
+ log.err("Push failed — waiting for fix");
103
+ running = false;
104
+ return;
113
105
  }
114
106
 
115
- console.log("\n\x1b[32m✨ Drizzle synced successfully"+RESET);
116
- busy=false;
107
+ log.ok("Database synced successfully");
108
+ running = false;
117
109
  }
118
110
 
119
111
  /* ======================
120
- 👀 WATCH MODE (SERVER)
112
+ 🚀 START
121
113
  ====================== */
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
- });
114
+ console.log(`
115
+ ${c.bold}${c.cyan}Drizzle Auto${c.reset}
116
+ ${c.gray}Server-side watcher initialized${c.reset}
117
+ `);
118
+
119
+ addTeaScript();
120
+ pipeline("startup");
121
+
122
+ chokidar.watch(ROOT, {
123
+ ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
124
+ ignoreInitial: true
125
+ }).on("change", file =>
126
+ pipeline(path.basename(file))
127
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "bin": {
5
5
  "drizzle-auto": "index.js"
6
6
  },