drizzle-auto 1.0.23 → 1.1.0

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 +68 -53
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,80 +6,98 @@ const chokidar = require("chokidar");
6
6
  const { spawn } = require("child_process");
7
7
 
8
8
  /* =========================
9
- 🧭 PROJECT ROOT
9
+ šŸŽØ COLORS (PRO)
10
10
  ========================= */
11
- const ROOT = process.cwd();
12
- const PKG = path.join(ROOT, "package.json");
13
-
14
- /* =========================
15
- šŸŽØ COLOR HELPERS
16
- ========================= */
17
- const colors = {
11
+ const C = {
18
12
  reset: "\x1b[0m",
19
- bright: "\x1b[1m",
20
- red: "\x1b[31m",
21
- green: "\x1b[32m",
22
- yellow: "\x1b[33m",
23
13
  blue: "\x1b[34m",
24
- magenta: "\x1b[35m",
25
14
  cyan: "\x1b[36m",
15
+ green: "\x1b[32m",
16
+ yellow: "\x1b[33m",
17
+ red: "\x1b[31m",
18
+ dim: "\x1b[90m",
26
19
  };
27
20
 
28
21
  /* =========================
29
- 🧩 SCRIPT INJECTOR
22
+ 🧭 ROOT + PKG
23
+ ========================= */
24
+ const ROOT = process.cwd();
25
+ const PKG = path.join(ROOT, "package.json");
26
+
27
+ /* =========================
28
+ ā˜• SCRIPT INJECTOR
30
29
  ========================= */
31
- function injectScript() {
30
+ function injectTea() {
32
31
  if (!fs.existsSync(PKG)) return;
32
+
33
33
  const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
34
34
  pkg.scripts ||= {};
35
35
 
36
36
  if (!pkg.scripts.tea) {
37
37
  pkg.scripts.tea = "drizzle-auto";
38
38
  fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
39
- console.log(`${colors.cyan}ā˜• Script added → npm run tea${colors.reset}`);
39
+ console.log(`${C.cyan}ā˜• Added script: npm run tea${C.reset}`);
40
40
  }
41
41
  }
42
42
 
43
43
  /* =========================
44
- šŸ” DRIZZLE DETECTOR
44
+ šŸ” RECURSIVE SEARCH
45
45
  ========================= */
46
- function detectDrizzle() {
47
- const configs = ["js","mjs","ts","mts"]
48
- .map(e => `drizzle.config.${e}`) // āœ… Fixed
49
- .find(f => fs.existsSync(path.join(ROOT, f)));
46
+ function walk(dir, results = []) {
47
+ for (const file of fs.readdirSync(dir)) {
48
+ const p = path.join(dir, file);
49
+ if (p.includes("node_modules") || p.includes(".git")) continue;
50
+
51
+ const stat = fs.statSync(p);
52
+ if (stat.isDirectory()) walk(p, results);
53
+ else results.push(p);
54
+ }
55
+ return results;
56
+ }
57
+
58
+ function findDrizzleConfig() {
59
+ const files = walk(ROOT);
60
+ const config = files.find(f =>
61
+ /drizzle\.config\.(js|mjs|ts|mts)$/.test(f)
62
+ );
50
63
 
51
- if (!configs) {
52
- console.log(`${colors.yellow}āš ļø No drizzle.config found${colors.reset}`);
64
+ if (!config) {
65
+ console.log(`${C.yellow}āš ļø drizzle.config not found (anywhere)${C.reset}`);
53
66
  return null;
54
67
  }
55
68
 
56
69
  let schemaPath = null;
57
70
  try {
58
- const content = fs.readFileSync(path.join(ROOT, configs), "utf8");
71
+ const content = fs.readFileSync(config, "utf8");
59
72
  const match = content.match(/schema:\s*["'](.+?)["']/);
60
- if (match) schemaPath = path.join(ROOT, match[1]);
73
+ if (match) {
74
+ schemaPath = path.resolve(path.dirname(config), match[1]);
75
+ }
61
76
  } catch {}
62
77
 
63
78
  if (schemaPath && !fs.existsSync(schemaPath)) {
64
- console.log(`${colors.red}āŒ Schema file missing${colors.reset}`);
79
+ console.log(`${C.red}āŒ Schema missing: ${schemaPath}${C.reset}`);
65
80
  return null;
66
81
  }
67
82
 
68
- return { config: configs, schema: schemaPath };
83
+ console.log(`${C.green}āœ” Drizzle config found${C.reset}`);
84
+ return true;
69
85
  }
70
86
 
71
87
  /* =========================
72
- āš™ļø SAFE COMMAND RUNNER
88
+ āš™ļø COMMAND RUNNER
73
89
  ========================= */
74
90
  function run(cmd) {
75
- return new Promise((resolve) => {
91
+ return new Promise(resolve => {
76
92
  let failed = false;
77
93
  const p = spawn("npx", cmd, { shell: true });
78
94
 
79
- p.stdout.on("data", d => process.stdout.write(`${colors.green}${d}${colors.reset}`));
95
+ p.stdout.on("data", d =>
96
+ process.stdout.write(C.dim + d.toString() + C.reset)
97
+ );
80
98
  p.stderr.on("data", d => {
81
99
  failed = true;
82
- process.stderr.write(`${colors.red}${d}${colors.reset}`);
100
+ process.stderr.write(C.red + d.toString() + C.reset);
83
101
  });
84
102
 
85
103
  p.on("close", code => resolve(code === 0 && !failed));
@@ -87,49 +105,46 @@ function run(cmd) {
87
105
  }
88
106
 
89
107
  /* =========================
90
- šŸ” PIPELINE (NON-KILLING)
108
+ šŸ” PIPELINE (SAFE)
91
109
  ========================= */
92
- let busy = false;
110
+ let running = false;
93
111
 
94
112
  async function pipeline(trigger) {
95
- if (busy) return;
96
- busy = true;
113
+ if (running) return;
114
+ running = true;
97
115
 
98
- console.log(`${colors.magenta}\n⚔ Trigger → ${trigger}${colors.reset}`);
116
+ console.log(`${C.blue}\n⚔ Trigger → ${trigger}${C.reset}`);
99
117
 
100
- const drizzle = detectDrizzle();
101
- if (!drizzle) {
102
- busy = false;
118
+ if (!findDrizzleConfig()) {
119
+ running = false;
103
120
  return;
104
121
  }
105
122
 
106
- const genOK = await run(["drizzle-kit", "generate"]);
107
- if (!genOK) {
108
- console.log(`${colors.red}šŸ›‘ Generate failed — pipeline paused${colors.reset}`);
109
- busy = false;
123
+ if (!(await run(["drizzle-kit", "generate"]))) {
124
+ console.log(`${C.red}šŸ›‘ generate failed (watcher alive)${C.reset}`);
125
+ running = false;
110
126
  return;
111
127
  }
112
128
 
113
- const pushOK = await run(["drizzle-kit", "push"]);
114
- if (!pushOK) {
115
- console.log(`${colors.red}šŸ›‘ Push failed — server still running${colors.reset}`);
116
- busy = false;
129
+ if (!(await run(["drizzle-kit", "push"]))) {
130
+ console.log(`${C.red}šŸ›‘ push failed (watcher alive)${C.reset}`);
131
+ running = false;
117
132
  return;
118
133
  }
119
134
 
120
- console.log(`${colors.cyan}✨ Drizzle fully synced${colors.reset}`);
121
- busy = false;
135
+ console.log(`${C.green}✨ Drizzle synced${C.reset}`);
136
+ running = false;
122
137
  }
123
138
 
124
139
  /* =========================
125
- šŸ‘€ WATCHER (ALWAYS ALIVE)
140
+ šŸ‘€ WATCHER
126
141
  ========================= */
127
- injectScript();
128
- pipeline("Initial");
142
+ injectTea();
143
+ pipeline("initial");
129
144
 
130
145
  chokidar.watch(ROOT, {
131
146
  ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
132
147
  ignoreInitial: true,
133
148
  usePolling: true,
134
- interval: 300
149
+ interval: 300,
135
150
  }).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.23",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",