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