drizzle-auto 1.1.1 β†’ 1.1.3

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 +78 -104
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,176 +6,150 @@ const chokidar = require("chokidar");
6
6
  const { spawn } = require("child_process");
7
7
 
8
8
  /* =========================
9
- 🎨 COLORS (clean & pro)
9
+ 🎨 COLORS (PRO ONLY)
10
10
  ========================= */
11
11
  const C = {
12
12
  reset: "\x1b[0m",
13
- dim: "\x1b[2m",
14
13
  bold: "\x1b[1m",
15
14
  cyan: "\x1b[36m",
16
15
  green: "\x1b[32m",
17
16
  yellow: "\x1b[33m",
18
17
  red: "\x1b[31m",
19
18
  magenta: "\x1b[35m",
20
- };
21
-
22
- const log = {
23
- info: (m) => console.log(`${C.cyan}β„Ή ${m}${C.reset}`),
24
- ok: (m) => console.log(`${C.green}βœ“ ${m}${C.reset}`),
25
- warn: (m) => console.log(`${C.yellow}⚠ ${m}${C.reset}`),
26
- err: (m) => console.log(`${C.red}βœ— ${m}${C.reset}`),
27
- trig: (m) => console.log(`${C.magenta}⚑ ${m}${C.reset}`),
19
+ dim: "\x1b[2m",
28
20
  };
29
21
 
30
22
  /* =========================
31
- 🧭 PROJECT ROOT
23
+ 🧭 ROOT
32
24
  ========================= */
33
25
  const ROOT = process.cwd();
34
26
  const PKG = path.join(ROOT, "package.json");
35
27
 
36
28
  /* =========================
37
- 🧩 SCRIPT INJECTOR
29
+ β˜• ADD tea SCRIPT
38
30
  ========================= */
39
- function injectScript() {
31
+ function injectTea() {
40
32
  if (!fs.existsSync(PKG)) return;
41
-
42
33
  const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
43
34
  pkg.scripts ||= {};
44
35
 
45
36
  if (!pkg.scripts.tea) {
46
37
  pkg.scripts.tea = "drizzle-auto";
47
38
  fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
48
- log.ok("Added script β†’ npm run tea");
39
+ console.log(`${C.green}β˜• Added:${C.reset} npm run tea`);
49
40
  }
50
41
  }
51
42
 
52
43
  /* =========================
53
- πŸ” FIND DRIZZLE CONFIG
54
- (js | mjs | ts | mts)
44
+ πŸ” FIND drizzle.config.*
55
45
  ========================= */
56
- function findDrizzleConfig() {
57
- const exts = ["js", "mjs", "ts", "mts"];
58
- for (const e of exts) {
59
- const p = path.join(ROOT, `drizzle.config.${e}`);
60
- if (fs.existsSync(p)) return p;
61
- }
62
- return null;
46
+ function findConfig() {
47
+ const exts = ["js", "mjs", "cjs", "ts", "mts"];
48
+ let found = null;
49
+
50
+ (function walk(dir) {
51
+ if (found) return;
52
+ for (const f of fs.readdirSync(dir, { withFileTypes: true })) {
53
+ if (f.name === "node_modules" || f.name.startsWith(".")) continue;
54
+ const p = path.join(dir, f.name);
55
+ if (f.isDirectory()) walk(p);
56
+ else {
57
+ for (const e of exts) {
58
+ if (f.name === `drizzle.config.${e}`) {
59
+ found = p;
60
+ return;
61
+ }
62
+ }
63
+ }
64
+ }
65
+ })(ROOT);
66
+
67
+ return found;
63
68
  }
64
69
 
65
70
  /* =========================
66
- πŸ”Ž FILE FILTER (ALL TYPES)
71
+ βš™οΈ SAFE RUNNER (ERROR AWARE)
67
72
  ========================= */
68
- const WATCH_EXTS = [
69
- ".js", ".mjs", ".cjs",
70
- ".ts", ".mts",
71
- ".jsx", ".tsx",
72
- ".sql"
73
- ];
74
-
75
- function isValidFile(file) {
76
- return WATCH_EXTS.includes(path.extname(file));
77
- }
78
-
79
- /* =========================
80
- βš™οΈ SAFE SPAWN (NO SHELL)
81
- ========================= */
82
- function exec(cmd, args = []) {
73
+ function run(cmd, args) {
83
74
  return new Promise((resolve) => {
84
- const p = spawn(cmd, args, { stdio: "inherit" });
75
+ let stderr = "";
76
+
77
+ const p = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
85
78
 
86
- p.on("error", (e) => {
87
- log.err(`Process error: ${e.message}`);
88
- resolve(false);
79
+ p.stdout.on("data", d => process.stdout.write(d));
80
+ p.stderr.on("data", d => {
81
+ stderr += d.toString();
82
+ process.stderr.write(d);
89
83
  });
90
84
 
91
85
  p.on("close", (code) => {
92
- resolve(code === 0);
86
+ resolve({ ok: code === 0, stderr });
93
87
  });
94
88
  });
95
89
  }
96
90
 
97
91
  /* =========================
98
- πŸ›‘οΈ CRASH PROTECTION
92
+ πŸ” PIPELINE (NO LIES)
99
93
  ========================= */
100
- process.on("uncaughtException", (e) => {
101
- log.err(`Crash prevented: ${e.message}`);
102
- });
103
- process.on("unhandledRejection", (e) => {
104
- log.err(`Promise rejected: ${e}`);
105
- });
106
-
107
- /* =========================
108
- πŸ” PIPELINE (DEV SAFE)
109
- ========================= */
110
- let running = false;
111
- let lastPush = 0;
112
-
113
- const DEV_MODE = process.argv.includes("--dev");
114
- const PUSH_COOLDOWN = DEV_MODE ? 120_000 : 30_000; // safer in dev
94
+ let busy = false;
115
95
 
116
96
  async function pipeline(trigger) {
117
- if (running) return;
118
- running = true;
97
+ if (busy) return;
98
+ busy = true;
119
99
 
120
- log.trig(`Trigger β†’ ${trigger}`);
100
+ console.log(`\n${C.cyan}⚑ Trigger β†’${C.reset} ${trigger}`);
121
101
 
122
- const config = findDrizzleConfig();
102
+ const config = findConfig();
123
103
  if (!config) {
124
- log.warn("No drizzle.config found");
125
- running = false;
126
- return;
127
- }
128
-
129
- log.info("Running drizzle generate…");
130
- const gen = await exec("npx", ["drizzle-kit", "generate"]);
131
- if (!gen) {
132
- log.err("Generate failed β€” watching continues");
133
- running = false;
104
+ console.log(`${C.yellow}⚠ No drizzle.config found${C.reset}`);
105
+ busy = false;
134
106
  return;
135
107
  }
136
108
 
137
- const now = Date.now();
138
- if (now - lastPush < PUSH_COOLDOWN) {
139
- log.warn("Push skipped (cooldown)");
140
- running = false;
109
+ console.log(`${C.magenta}β–Ά drizzle-kit generate${C.reset}`);
110
+ const gen = await run("npx", ["drizzle-kit", "generate"]);
111
+ if (!gen.ok) {
112
+ console.log(`${C.red}πŸ›‘ Generate failed β€” watcher alive${C.reset}`);
113
+ busy = false;
141
114
  return;
142
115
  }
143
116
 
144
- log.info("Running drizzle push…");
145
- lastPush = now;
146
-
147
- const push = await exec("npx", ["drizzle-kit", "push"]);
148
- if (!push) {
149
- log.err("Push failed β€” DB untouched, server alive");
150
- running = false;
117
+ console.log(`${C.magenta}β–Ά drizzle-kit push${C.reset}`);
118
+ const push = await run("npx", ["drizzle-kit", "push"]);
119
+
120
+ if (!push.ok) {
121
+ console.log(`\n${C.red}${C.bold}🚨 PUSH FAILED${C.reset}`);
122
+
123
+ if (
124
+ push.stderr.includes("ENOTFOUND") ||
125
+ push.stderr.includes("websocket")
126
+ ) {
127
+ console.log(
128
+ `${C.yellow}⚠ Neon / network issue detected${C.reset}\n` +
129
+ `${C.dim}β€’ Check internet\n` +
130
+ `β€’ Check DATABASE_URL\n` +
131
+ `β€’ Neon endpoint may be sleeping${C.reset}`
132
+ );
133
+ }
134
+
135
+ console.log(`${C.dim}Watcher still running. Server NOT stopped.${C.reset}`);
136
+ busy = false;
151
137
  return;
152
138
  }
153
139
 
154
- log.ok("Drizzle fully synced");
155
- running = false;
140
+ console.log(`${C.green}✨ Drizzle fully synced${C.reset}`);
141
+ busy = false;
156
142
  }
157
143
 
158
144
  /* =========================
159
- πŸ‘€ WATCHER (ALL FILES)
145
+ πŸ‘€ WATCH EVERYTHING
160
146
  ========================= */
161
- injectScript();
147
+ injectTea();
162
148
  pipeline("Initial");
163
149
 
164
- log.info(`Watching files (${DEV_MODE ? "DEV MODE" : "SAFE MODE"})…`);
165
-
166
150
  chokidar.watch(ROOT, {
167
- ignored: [
168
- /node_modules/,
169
- /\.git/,
170
- /\.next/,
171
- /dist/,
172
- /build/
173
- ],
151
+ ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
174
152
  ignoreInitial: true,
175
- usePolling: true,
176
- interval: 300,
177
153
  }).on("all", (_, file) => {
178
- if (isValidFile(file)) {
179
- pipeline(path.relative(ROOT, file));
180
- }
154
+ pipeline(path.relative(ROOT, file));
181
155
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",