drizzle-auto 1.0.22 → 1.0.24

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