drizzle-auto 1.0.21 → 1.0.22

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