drizzle-auto 1.0.21 → 1.0.23

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 +41 -63
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,43 +6,29 @@ const chokidar = require("chokidar");
6
6
  const { spawn } = require("child_process");
7
7
 
8
8
  /* =========================
9
- 🎨 COLORS & SPINNER
9
+ 🧭 PROJECT ROOT
10
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
- let colorIndex = 0;
15
-
16
- function rainbow(text) {
17
- return text.split("").map(c => `${COLORS[colorIndex++ % COLORS.length]}${c}`).join("") + RESET;
18
- }
19
-
20
- const SPINNER = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
21
- let spinIndex = 0;
22
- let spinnerInterval;
23
-
24
- function startSpinner(text) {
25
- stopSpinner();
26
- spinnerInterval = setInterval(() => {
27
- process.stdout.write(`\r${COLORS[colorIndex++ % COLORS.length]}${SPINNER[spinIndex++ % SPINNER.length]} ${text}${RESET}`);
28
- }, 80);
29
- }
30
- function stopSpinner() {
31
- if (spinnerInterval) clearInterval(spinnerInterval);
32
- spinnerInterval = null;
33
- process.stdout.write("\r\x1b[K");
34
- }
11
+ const ROOT = process.cwd();
12
+ const PKG = path.join(ROOT, "package.json");
35
13
 
36
14
  /* =========================
37
- 🧭 USER PROJECT ROOT
15
+ 🎨 COLOR HELPERS
38
16
  ========================= */
39
- const ROOT = process.env.INIT_CWD || process.cwd();
40
- const PKG = path.join(ROOT, "package.json");
17
+ const colors = {
18
+ reset: "\x1b[0m",
19
+ bright: "\x1b[1m",
20
+ red: "\x1b[31m",
21
+ green: "\x1b[32m",
22
+ yellow: "\x1b[33m",
23
+ blue: "\x1b[34m",
24
+ magenta: "\x1b[35m",
25
+ cyan: "\x1b[36m",
26
+ };
41
27
 
42
28
  /* =========================
43
- 🧩 INJECT TEA SCRIPT
29
+ 🧩 SCRIPT INJECTOR
44
30
  ========================= */
45
- function injectTea() {
31
+ function injectScript() {
46
32
  if (!fs.existsSync(PKG)) return;
47
33
  const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
48
34
  pkg.scripts ||= {};
@@ -50,26 +36,20 @@ function injectTea() {
50
36
  if (!pkg.scripts.tea) {
51
37
  pkg.scripts.tea = "drizzle-auto";
52
38
  fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
53
- console.log(rainbow("☕ Script injected → npm run tea"));
39
+ console.log(`${colors.cyan}☕ Script added → npm run tea${colors.reset}`);
54
40
  }
55
41
  }
56
42
 
57
- // Run injection only on install
58
- if (process.argv.includes("--postinstall")) {
59
- injectTea();
60
- process.exit(0);
61
- }
62
-
63
43
  /* =========================
64
- 🔍 DETECT DRIZZLE CONFIG
44
+ 🔍 DRIZZLE DETECTOR
65
45
  ========================= */
66
46
  function detectDrizzle() {
67
47
  const configs = ["js","mjs","ts","mts"]
68
- .map(e => `drizzle.config.${e}`)
48
+ .map(e => `drizzle.config.${e}`) // ✅ Fixed
69
49
  .find(f => fs.existsSync(path.join(ROOT, f)));
70
50
 
71
51
  if (!configs) {
72
- console.log(rainbow("⚠️ No drizzle.config found"));
52
+ console.log(`${colors.yellow}⚠️ No drizzle.config found${colors.reset}`);
73
53
  return null;
74
54
  }
75
55
 
@@ -81,7 +61,7 @@ function detectDrizzle() {
81
61
  } catch {}
82
62
 
83
63
  if (schemaPath && !fs.existsSync(schemaPath)) {
84
- console.log(rainbow("❌ Schema file missing"));
64
+ console.log(`${colors.red}❌ Schema file missing${colors.reset}`);
85
65
  return null;
86
66
  }
87
67
 
@@ -92,14 +72,16 @@ function detectDrizzle() {
92
72
  ⚙️ SAFE COMMAND RUNNER
93
73
  ========================= */
94
74
  function run(cmd) {
95
- return new Promise(resolve => {
75
+ return new Promise((resolve) => {
96
76
  let failed = false;
97
- startSpinner(`npx ${cmd.join(" ")}`);
98
-
99
77
  const p = spawn("npx", cmd, { shell: true });
100
78
 
101
- p.stdout.on("data", d => { stopSpinner(); process.stdout.write(d); });
102
- p.stderr.on("data", d => { stopSpinner(); process.stderr.write(d); failed = true; });
79
+ p.stdout.on("data", d => process.stdout.write(`${colors.green}${d}${colors.reset}`));
80
+ p.stderr.on("data", d => {
81
+ failed = true;
82
+ process.stderr.write(`${colors.red}${d}${colors.reset}`);
83
+ });
84
+
103
85
  p.on("close", code => resolve(code === 0 && !failed));
104
86
  });
105
87
  }
@@ -108,37 +90,41 @@ function run(cmd) {
108
90
  🔁 PIPELINE (NON-KILLING)
109
91
  ========================= */
110
92
  let busy = false;
93
+
111
94
  async function pipeline(trigger) {
112
95
  if (busy) return;
113
96
  busy = true;
114
97
 
115
- console.log(`\n${BOLD}${rainbow("⚡ Trigger →")} ${trigger}${RESET}`);
98
+ console.log(`${colors.magenta}\n⚡ Trigger → ${trigger}${colors.reset}`);
116
99
 
117
100
  const drizzle = detectDrizzle();
118
- if (!drizzle) { busy = false; return; }
101
+ if (!drizzle) {
102
+ busy = false;
103
+ return;
104
+ }
119
105
 
120
- const genOK = await run(["drizzle-kit","generate"]);
106
+ const genOK = await run(["drizzle-kit", "generate"]);
121
107
  if (!genOK) {
122
- console.log(rainbow("🛑 Generate failed — pipeline paused"));
108
+ console.log(`${colors.red}🛑 Generate failed — pipeline paused${colors.reset}`);
123
109
  busy = false;
124
110
  return;
125
111
  }
126
112
 
127
- const pushOK = await run(["drizzle-kit","push"]);
113
+ const pushOK = await run(["drizzle-kit", "push"]);
128
114
  if (!pushOK) {
129
- console.log(rainbow("🛑 Push failed — server still running"));
115
+ console.log(`${colors.red}🛑 Push failed — server still running${colors.reset}`);
130
116
  busy = false;
131
117
  return;
132
118
  }
133
119
 
134
- console.log(rainbow("✨ Drizzle fully synced"));
120
+ console.log(`${colors.cyan}✨ Drizzle fully synced${colors.reset}`);
135
121
  busy = false;
136
122
  }
137
123
 
138
124
  /* =========================
139
125
  👀 WATCHER (ALWAYS ALIVE)
140
126
  ========================= */
141
- injectTea(); // ensure script is added
127
+ injectScript();
142
128
  pipeline("Initial");
143
129
 
144
130
  chokidar.watch(ROOT, {
@@ -146,12 +132,4 @@ chokidar.watch(ROOT, {
146
132
  ignoreInitial: true,
147
133
  usePolling: true,
148
134
  interval: 300
149
- }).on("all", (_, file) => pipeline(path.basename(file)));
150
-
151
- /* =========================
152
- 💥 CRASH HANDLER
153
- ========================= */
154
- process.on("uncaughtException", e => {
155
- stopSpinner();
156
- console.log(rainbow("🔥 Crash:"), e.message);
157
- });
135
+ }).on("all", (_, file) => pipeline(path.basename(file)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",