drizzle-auto 1.1.2 โ†’ 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 +53 -60
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,104 +6,90 @@ 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",
13
+ bold: "\x1b[1m",
14
14
  cyan: "\x1b[36m",
15
15
  green: "\x1b[32m",
16
16
  yellow: "\x1b[33m",
17
17
  red: "\x1b[31m",
18
18
  magenta: "\x1b[35m",
19
- bold: "\x1b[1m",
19
+ dim: "\x1b[2m",
20
20
  };
21
21
 
22
22
  /* =========================
23
- ๐Ÿงญ PROJECT ROOT
23
+ ๐Ÿงญ ROOT
24
24
  ========================= */
25
25
  const ROOT = process.cwd();
26
26
  const PKG = path.join(ROOT, "package.json");
27
27
 
28
28
  /* =========================
29
- ๐Ÿงฉ SCRIPT INJECTOR (REAL FIX)
29
+ โ˜• ADD tea SCRIPT
30
30
  ========================= */
31
- function injectTeaScript() {
31
+ function injectTea() {
32
32
  if (!fs.existsSync(PKG)) return;
33
-
34
33
  const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
35
34
  pkg.scripts ||= {};
36
35
 
37
36
  if (!pkg.scripts.tea) {
38
37
  pkg.scripts.tea = "drizzle-auto";
39
38
  fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
40
- console.log(
41
- `${C.green}โ˜• Added script:${C.reset} ${C.bold}npm run tea${C.reset}`
42
- );
39
+ console.log(`${C.green}โ˜• Added:${C.reset} npm run tea`);
43
40
  }
44
41
  }
45
42
 
46
43
  /* =========================
47
- ๐Ÿ” FIND DRIZZLE CONFIG (ANYWHERE)
44
+ ๐Ÿ” FIND drizzle.config.*
48
45
  ========================= */
49
- function findDrizzleConfig() {
46
+ function findConfig() {
50
47
  const exts = ["js", "mjs", "cjs", "ts", "mts"];
51
48
  let found = null;
52
49
 
53
- function walk(dir) {
50
+ (function walk(dir) {
54
51
  if (found) return;
55
- for (const file of fs.readdirSync(dir, { withFileTypes: true })) {
56
- if (file.name === "node_modules" || file.name.startsWith(".")) continue;
57
- const full = path.join(dir, file.name);
58
-
59
- if (file.isDirectory()) walk(full);
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);
60
56
  else {
61
57
  for (const e of exts) {
62
- if (file.name === `drizzle.config.${e}`) {
63
- found = full;
58
+ if (f.name === `drizzle.config.${e}`) {
59
+ found = p;
64
60
  return;
65
61
  }
66
62
  }
67
63
  }
68
64
  }
69
- }
65
+ })(ROOT);
70
66
 
71
- walk(ROOT);
72
67
  return found;
73
68
  }
74
69
 
75
70
  /* =========================
76
- ๐Ÿงช VALIDATE SCHEMA EXISTS
77
- ========================= */
78
- function validateConfig(configPath) {
79
- try {
80
- const txt = fs.readFileSync(configPath, "utf8");
81
- const m = txt.match(/schema:\s*["'](.+?)["']/);
82
- if (!m) return true;
83
-
84
- const schemaPath = path.resolve(path.dirname(configPath), m[1]);
85
- return fs.existsSync(schemaPath);
86
- } catch {
87
- return false;
88
- }
89
- }
90
-
91
- /* =========================
92
- โš™๏ธ SAFE RUNNER (NO SERVER KILL)
71
+ โš™๏ธ SAFE RUNNER (ERROR AWARE)
93
72
  ========================= */
94
73
  function run(cmd, args) {
95
74
  return new Promise((resolve) => {
96
- const p = spawn(cmd, args, {
97
- stdio: "inherit",
98
- shell: false,
75
+ let stderr = "";
76
+
77
+ const p = spawn(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
78
+
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);
99
83
  });
100
84
 
101
- p.on("close", (code) => resolve(code === 0));
85
+ p.on("close", (code) => {
86
+ resolve({ ok: code === 0, stderr });
87
+ });
102
88
  });
103
89
  }
104
90
 
105
91
  /* =========================
106
- ๐Ÿ” PIPELINE (SERVER SAFE)
92
+ ๐Ÿ” PIPELINE (NO LIES)
107
93
  ========================= */
108
94
  let busy = false;
109
95
 
@@ -111,35 +97,42 @@ async function pipeline(trigger) {
111
97
  if (busy) return;
112
98
  busy = true;
113
99
 
114
- console.log(
115
- `\n${C.cyan}โšก Trigger โ†’${C.reset} ${C.bold}${trigger}${C.reset}`
116
- );
100
+ console.log(`\n${C.cyan}โšก Trigger โ†’${C.reset} ${trigger}`);
117
101
 
118
- const config = findDrizzleConfig();
102
+ const config = findConfig();
119
103
  if (!config) {
120
104
  console.log(`${C.yellow}โš  No drizzle.config found${C.reset}`);
121
105
  busy = false;
122
106
  return;
123
107
  }
124
108
 
125
- if (!validateConfig(config)) {
126
- console.log(`${C.red}โŒ Schema path invalid${C.reset}`);
127
- busy = false;
128
- return;
129
- }
130
-
131
109
  console.log(`${C.magenta}โ–ถ drizzle-kit generate${C.reset}`);
132
- const genOK = await run("npx", ["drizzle-kit", "generate"]);
133
- if (!genOK) {
110
+ const gen = await run("npx", ["drizzle-kit", "generate"]);
111
+ if (!gen.ok) {
134
112
  console.log(`${C.red}๐Ÿ›‘ Generate failed โ€” watcher alive${C.reset}`);
135
113
  busy = false;
136
114
  return;
137
115
  }
138
116
 
139
117
  console.log(`${C.magenta}โ–ถ drizzle-kit push${C.reset}`);
140
- const pushOK = await run("npx", ["drizzle-kit", "push"]);
141
- if (!pushOK) {
142
- console.log(`${C.red}๐Ÿ›‘ Push failed โ€” watcher alive${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}`);
143
136
  busy = false;
144
137
  return;
145
138
  }
@@ -151,7 +144,7 @@ async function pipeline(trigger) {
151
144
  /* =========================
152
145
  ๐Ÿ‘€ WATCH EVERYTHING
153
146
  ========================= */
154
- injectTeaScript();
147
+ injectTea();
155
148
  pipeline("Initial");
156
149
 
157
150
  chokidar.watch(ROOT, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",