drizzle-auto 1.0.13 → 1.0.15

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 +61 -20
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5,6 +5,33 @@ const path = require("path");
5
5
  const chokidar = require("chokidar");
6
6
  const { spawn } = require("child_process");
7
7
 
8
+ /* =========================
9
+ šŸŽØ TERMINAL COLORS (PRO)
10
+ ========================= */
11
+ const C = {
12
+ reset: "\x1b[0m",
13
+ bold: "\x1b[1m",
14
+ dim: "\x1b[2m",
15
+
16
+ cyan: "\x1b[36m",
17
+ green: "\x1b[32m",
18
+ yellow: "\x1b[33m",
19
+ red: "\x1b[31m",
20
+ magenta: "\x1b[35m",
21
+ blue: "\x1b[34m",
22
+ gray: "\x1b[90m"
23
+ };
24
+
25
+ const ui = {
26
+ title: m => console.log(`\n${C.bold}${C.magenta}ā—† ${m}${C.reset}`),
27
+ info: m => console.log(`${C.cyan}ā—${C.reset} ${m}`),
28
+ watch: m => console.log(`${C.blue}šŸ‘€${C.reset} ${m}`),
29
+ ok: m => console.log(`${C.green}āœ”${C.reset} ${m}`),
30
+ warn: m => console.log(`${C.yellow}ā–²${C.reset} ${m}`),
31
+ err: m => console.log(`${C.red}āœ–${C.reset} ${m}`),
32
+ dim: m => console.log(`${C.gray}${m}${C.reset}`)
33
+ };
34
+
8
35
  /* =========================
9
36
  🧭 PROJECT ROOT
10
37
  ========================= */
@@ -16,13 +43,16 @@ const PKG = path.join(ROOT, "package.json");
16
43
  ========================= */
17
44
  function injectScript() {
18
45
  if (!fs.existsSync(PKG)) return;
46
+
19
47
  const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
20
48
  pkg.scripts ||= {};
21
49
 
22
50
  if (!pkg.scripts.tea) {
23
51
  pkg.scripts.tea = "drizzle-auto";
24
52
  fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
25
- console.log("ā˜• Script added → npm run tea");
53
+ ui.ok("Script injected → npm run tea");
54
+ } else {
55
+ ui.dim("Script already exists → tea");
26
56
  }
27
57
  }
28
58
 
@@ -30,38 +60,43 @@ function injectScript() {
30
60
  šŸ” DRIZZLE DETECTOR
31
61
  ========================= */
32
62
  function detectDrizzle() {
33
- const configs = ["js","mjs","ts","mts"]
34
- .map(e => `drizzle.config.${e}`)
63
+ const config = ["js", "mjs", "ts", "mts"]
64
+ .map(ext => `drizzle.config.${ext}`)
35
65
  .find(f => fs.existsSync(path.join(ROOT, f)));
36
66
 
37
- if (!configs) {
38
- console.log("āš ļø No drizzle.config found");
67
+ if (!config) {
68
+ ui.warn("No drizzle.config found");
39
69
  return null;
40
70
  }
41
71
 
42
72
  let schemaPath = null;
73
+
43
74
  try {
44
- const content = fs.readFileSync(path.join(ROOT, configs), "utf8");
75
+ const content = fs.readFileSync(path.join(ROOT, config), "utf8");
45
76
  const match = content.match(/schema:\s*["'](.+?)["']/);
46
77
  if (match) schemaPath = path.join(ROOT, match[1]);
47
78
  } catch {}
48
79
 
49
80
  if (schemaPath && !fs.existsSync(schemaPath)) {
50
- console.log("āŒ Schema file missing");
81
+ ui.err("Schema file missing");
51
82
  return null;
52
83
  }
53
84
 
54
- return { config: configs, schema: schemaPath };
85
+ ui.ok(`Detected ${config}`);
86
+ return true;
55
87
  }
56
88
 
57
89
  /* =========================
58
90
  āš™ļø SAFE COMMAND RUNNER
59
91
  ========================= */
60
92
  function run(cmd) {
61
- return new Promise((resolve) => {
93
+ return new Promise(resolve => {
62
94
  let failed = false;
63
95
 
64
- const p = spawn("npx", cmd, { shell: true });
96
+ const p = spawn("npx", cmd, {
97
+ shell: true,
98
+ stdio: ["ignore", "pipe", "pipe"]
99
+ });
65
100
 
66
101
  p.stdout.on("data", d => process.stdout.write(d));
67
102
  p.stderr.on("data", d => {
@@ -69,14 +104,12 @@ function run(cmd) {
69
104
  process.stderr.write(d);
70
105
  });
71
106
 
72
- p.on("close", code => {
73
- resolve(code === 0 && !failed);
74
- });
107
+ p.on("close", code => resolve(code === 0 && !failed));
75
108
  });
76
109
  }
77
110
 
78
111
  /* =========================
79
- šŸ” PIPELINE (NON-KILLING)
112
+ šŸ” PIPELINE (SERVER SAFE)
80
113
  ========================= */
81
114
  let busy = false;
82
115
 
@@ -84,35 +117,43 @@ async function pipeline(trigger) {
84
117
  if (busy) return;
85
118
  busy = true;
86
119
 
87
- console.log(`\n⚔ Trigger → ${trigger}`);
120
+ ui.watch(`Trigger → ${trigger}`);
88
121
 
89
- const drizzle = detectDrizzle();
90
- if (!drizzle) {
122
+ if (!detectDrizzle()) {
91
123
  busy = false;
92
124
  return;
93
125
  }
94
126
 
127
+ ui.info("Running drizzle-kit generate...");
95
128
  const genOK = await run(["drizzle-kit", "generate"]);
129
+
96
130
  if (!genOK) {
97
- console.log("šŸ›‘ Generate failed — pipeline paused");
131
+ ui.err("Generate failed — pipeline stopped");
98
132
  busy = false;
99
133
  return;
100
134
  }
101
135
 
136
+ ui.ok("Generate successful");
137
+
138
+ ui.info("Running drizzle-kit push...");
102
139
  const pushOK = await run(["drizzle-kit", "push"]);
140
+
103
141
  if (!pushOK) {
104
- console.log("šŸ›‘ Push failed — server still running");
142
+ ui.warn("Push failed — server still running");
105
143
  busy = false;
106
144
  return;
107
145
  }
108
146
 
109
- console.log("✨ Drizzle fully synced");
147
+ ui.ok("Drizzle fully synced ✨");
110
148
  busy = false;
111
149
  }
112
150
 
113
151
  /* =========================
114
152
  šŸ‘€ WATCHER (ALWAYS ALIVE)
115
153
  ========================= */
154
+ ui.title("DrizzlePulse — Server Start");
155
+ ui.dim(`Root → ${ROOT}`);
156
+
116
157
  injectScript();
117
158
  pipeline("Initial");
118
159
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "bin": {
5
5
  "drizzle-auto": "index.js"
6
6
  },