drizzle-auto 1.0.9 → 1.0.11

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 +40 -61
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -5,29 +5,25 @@ const path = require("path");
5
5
  const chokidar = require("chokidar");
6
6
  const { spawn } = require("child_process");
7
7
 
8
- /* =======================
9
- 🎨 NeonPulse Colors
10
- ======================= */
8
+ /* ======================= 🎨 NeonPulse Colors ======================= */
11
9
  const COLORS = ["\x1b[31m","\x1b[32m","\x1b[33m","\x1b[34m","\x1b[35m","\x1b[36m"];
12
10
  const RESET = "\x1b[0m";
13
- const BOLD = "\x1b[1m";
14
11
  const DIM = "\x1b[90m";
15
12
  let colorIndex = 0;
16
13
  const nextColor = () => COLORS[colorIndex++ % COLORS.length];
17
- const rainbow = text => text.split("").map(c => `${nextColor()}${c}`).join("") + RESET;
18
14
 
19
- /* =======================
20
- ⏳ Spinner
21
- ======================= */
15
+ /* ======================= ⏳ Spinner ======================= */
22
16
  const FRAMES = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
23
17
  let spinIndex = 0;
24
18
  let spinnerInterval = null;
19
+
25
20
  function startSpinner(msg) {
26
21
  stopSpinner();
27
22
  spinnerInterval = setInterval(() => {
28
23
  process.stdout.write(`\r${nextColor()}${FRAMES[spinIndex++ % FRAMES.length]} ${msg}${RESET}`);
29
24
  }, 80);
30
25
  }
26
+
31
27
  function stopSpinner() {
32
28
  if (spinnerInterval) {
33
29
  clearInterval(spinnerInterval);
@@ -36,51 +32,34 @@ function stopSpinner() {
36
32
  }
37
33
  }
38
34
 
39
- /* =======================
40
- 🧠 Project Root + Package.json
41
- ======================= */
42
- const PROJECT_ROOT = process.env.INIT_CWD || process.cwd();
35
+ /* ======================= 🧠 Project Root + Package.json ======================= */
36
+ const PROJECT_ROOT = process.cwd();
43
37
  const PKG_PATH = path.join(PROJECT_ROOT, "package.json");
44
38
 
45
39
  function addTeaScript() {
46
40
  if (!fs.existsSync(PKG_PATH)) return;
47
- const pkg = JSON.parse(fs.readFileSync(PKG_PATH, "utf8"));
48
- pkg.scripts ||= {};
49
- if (!pkg.scripts.tea) {
50
- pkg.scripts.tea = "drizzle-auto";
51
- fs.writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
52
- console.log(`⚡ tea script added → npm run tea`);
41
+ try {
42
+ const pkg = JSON.parse(fs.readFileSync(PKG_PATH, "utf8"));
43
+ pkg.scripts = pkg.scripts || {};
44
+
45
+ // ফিক্স: সরাসরি node index.js চালানো নিশ্চিত করা
46
+ if (!pkg.scripts.tea) {
47
+ pkg.scripts.tea = "node index.js";
48
+ fs.writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
49
+ console.log(`\x1b[32m⚡ tea script added → npm run tea\x1b[0m`);
50
+ }
51
+ } catch (e) {
52
+ console.error("❌ Could not update package.json");
53
53
  }
54
54
  }
55
55
 
56
- /* =======================
57
- 🧪 Infra Audit
58
- ======================= */
56
+ /* ======================= 🧪 Infra Audit ======================= */
59
57
  function auditInfra() {
60
58
  const results = [];
61
-
62
- // Drizzle config
63
59
  const configFile = ["ts","js","mjs","mts"].map(ext => `drizzle.config.${ext}`)
64
60
  .find(f => fs.existsSync(path.join(PROJECT_ROOT, f)));
61
+
65
62
  results.push({ name: "Drizzle Config", ok: !!configFile });
66
-
67
- // Schema path
68
- if (configFile) {
69
- try {
70
- const cfg = fs.readFileSync(path.join(PROJECT_ROOT, configFile), "utf8");
71
- const match = cfg.match(/schema:\s*["'](.+?)["']/);
72
- if (match) {
73
- results.push({
74
- name: `Schema (${match[1]})`,
75
- ok: fs.existsSync(path.join(PROJECT_ROOT, match[1]))
76
- });
77
- } else results.push({ name: "Schema Path", ok: false });
78
- } catch {
79
- results.push({ name: "Config Readable", ok: false });
80
- }
81
- }
82
-
83
- // Essentials
84
63
  results.push({ name: ".env", ok: fs.existsSync(path.join(PROJECT_ROOT, ".env")) });
85
64
  results.push({ name: "node_modules", ok: fs.existsSync(path.join(PROJECT_ROOT, "node_modules")) });
86
65
 
@@ -88,31 +67,30 @@ function auditInfra() {
88
67
  return { ok: missing.length === 0, missing };
89
68
  }
90
69
 
91
- /* =======================
92
- ⚡ Run npx command
93
- ======================= */
70
+ /* ======================= ⚡ Run npx command ======================= */
94
71
  function runCmd(cmd) {
95
72
  return new Promise(resolve => {
96
73
  let failed = false;
97
74
  startSpinner(`npx ${cmd.join(" ")}`);
98
- const p = spawn("npx", cmd, { shell: true });
75
+ const p = spawn("npx", cmd, { shell: true, cwd: PROJECT_ROOT });
76
+
99
77
  p.stdout.on("data", d => {
100
78
  stopSpinner();
101
79
  process.stdout.write(DIM + d.toString() + RESET);
102
80
  if (/error|failed/i.test(d)) failed = true;
103
81
  });
82
+
104
83
  p.stderr.on("data", d => {
105
84
  stopSpinner();
106
85
  process.stderr.write("\x1b[31m" + d + RESET);
107
86
  failed = true;
108
87
  });
88
+
109
89
  p.on("close", code => resolve(code === 0 && !failed));
110
90
  });
111
91
  }
112
92
 
113
- /* =======================
114
- 🏁 Workflow
115
- ======================= */
93
+ /* ======================= 🏁 Workflow ======================= */
116
94
  let running = false;
117
95
  let hasError = false;
118
96
 
@@ -133,7 +111,6 @@ async function workflow(trigger) {
133
111
  }
134
112
 
135
113
  const steps = [
136
- ["drizzle-kit", "check"],
137
114
  ["drizzle-kit", "generate"],
138
115
  ["drizzle-kit", "push"]
139
116
  ];
@@ -149,27 +126,29 @@ async function workflow(trigger) {
149
126
 
150
127
  hasError = false;
151
128
  console.log("\n\x1b[32m✨ Drizzle synced\x1b[0m");
152
- setTimeout(() => running = false, 1000);
129
+ setTimeout(() => { running = false; }, 1000);
153
130
  }
154
131
 
155
- /* =======================
156
- 👀 Watcher
157
- ======================= */
158
- chokidar.watch(PROJECT_ROOT, {
159
- ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
132
+ /* ======================= 👀 Watcher ======================= */
133
+ const watcher = chokidar.watch(PROJECT_ROOT, {
134
+ ignored: [/node_modules/, /\.git/, /\.next/, /dist/, /migrations/],
160
135
  ignoreInitial: true,
161
136
  usePolling: true,
162
137
  interval: 300
163
- }).on("all", (e, f) => workflow(`${e.toUpperCase()} → ${path.basename(f)}`));
138
+ });
139
+
140
+ watcher.on("all", (event, file) => {
141
+ if (file.includes("schema") || file.endsWith(".ts") || file.endsWith(".js")) {
142
+ workflow(`${event.toUpperCase()} → ${path.basename(file)}`);
143
+ }
144
+ });
164
145
 
165
- /* =======================
166
- 🚀 Init
167
- ======================= */
168
- addTeaScript(); // inject tea script automatically
146
+ /* ======================= 🚀 Init ======================= */
147
+ addTeaScript();
169
148
  workflow("Initial Audit");
170
149
 
171
150
  process.on("uncaughtException", err => {
172
151
  stopSpinner();
173
152
  console.log("\x1b[31m🔥 Crash:\x1b[0m", err.message);
174
153
  running = false;
175
- });
154
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "bin": {
5
5
  "drizzle-auto": "index.js"
6
6
  },
@@ -8,7 +8,7 @@
8
8
  "postinstall": "node index.js --postinstall"
9
9
  },
10
10
  "dependencies": {
11
- "chokidar": "^4.0.1",
11
+ "chokidar": "^5.0.0",
12
12
  "cross-spawn": "^7.0.6"
13
13
  }
14
14
  }