drizzle-auto 1.1.11 → 1.1.13

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 +79 -118
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -6,153 +6,114 @@ const path = require("path");
6
6
  const fs = require("fs");
7
7
 
8
8
  /* =============================================================
9
- 🎨 CYBER-BLUE UI CORE (Unified Brand)
10
- ============================================================= */
9
+ 🎨 UI CORE (Universal ANSI)
10
+ ============================================================= */
11
11
  const T = {
12
- reset: "\x1b[0m",
13
- bold: "\x1b[1m",
14
- italic: "\x1b[3m",
15
- cyan: "\x1b[38;5;51m",
16
- blue: "\x1b[38;5;33m",
17
- lime: "\x1b[38;5;118m",
18
- red: "\x1b[38;5;196m",
19
- gray: "\x1b[38;5;244m"
12
+ reset: "\x1b[0m",
13
+ bold: "\x1b[1m",
14
+ cyan: "\x1b[38;5;51m",
15
+ pink: "\x1b[38;5;201m",
16
+ lime: "\x1b[38;5;118m",
17
+ yellow: "\x1b[38;5;226m",
18
+ red: "\x1b[38;5;196m",
19
+ gray: "\x1b[38;5;244m"
20
20
  };
21
21
 
22
+ /* =============================================================
23
+ ⏳ SPINNER
24
+ ============================================================= */
22
25
  const frames = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
23
- let spinIdx = 0, spinInterval;
26
+ let spinIdx = 0;
27
+ let spinInterval;
24
28
 
25
29
  function startLoading(msg) {
26
- stopLoading();
27
- spinInterval = setInterval(() => {
28
- process.stdout.write(`\r${T.blue}${frames[spinIdx++ % frames.length]}${T.reset} ${T.bold}${msg}${T.reset} `);
29
- }, 80);
30
+ stopLoading();
31
+ spinInterval = setInterval(() => {
32
+ process.stdout.write(`\r${T.cyan}${frames[spinIdx++ % frames.length]}${T.reset} ${T.bold}${msg}${T.reset} `);
33
+ }, 80);
30
34
  }
31
35
 
32
36
  function stopLoading() {
33
- if (spinInterval) {
34
- clearInterval(spinInterval);
35
- spinInterval = null;
36
- process.stdout.write("\r\x1b[K");
37
- }
38
- }
39
-
40
- /* =============================================================
41
- 🧩 AUTO SCRIPT INJECTOR
42
- ============================================================= */
43
- const PKG = path.join(process.cwd(), "package.json");
44
- function injectScript() {
45
- if (!fs.existsSync(PKG)) return;
46
- const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
47
- pkg.scripts ||= {};
48
- if (!pkg.scripts.tea) {
49
- pkg.scripts.tea = "drizzle-auto";
50
- fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
51
- console.log(`${T.lime}⚡ Script added → npm run tea${T.reset}`);
52
- }
53
- }
54
- injectScript();
55
-
56
- /* =============================================================
57
- 🔍 DRIZZLE DETECTOR
58
- ============================================================= */
59
- function findDrizzleConfig(root) {
60
- const exts = ["js","mjs","ts","mts","cjs"];
61
- const files = [];
62
- function walk(dir) {
63
- fs.readdirSync(dir, { withFileTypes: true }).forEach(file => {
64
- const full = path.join(dir, file.name);
65
- if (file.isDirectory() && !/node_modules|.git|.next|dist/.test(file.name)) walk(full);
66
- else if (file.isFile() && exts.some(ext => file.name === `drizzle.config.${ext}`)) files.push(full);
67
- });
68
- }
69
- walk(root);
70
- return files;
71
- }
72
-
73
- function justifyStructure() {
74
- const root = process.cwd();
75
- const configs = findDrizzleConfig(root);
76
- return configs.length === 0 ? { ok: false, msg: "Missing drizzle.config.*" } : { ok: true };
37
+ if (spinInterval) {
38
+ clearInterval(spinInterval);
39
+ spinInterval = null;
40
+ process.stdout.write("\r\x1b[K");
41
+ }
77
42
  }
78
43
 
79
44
  /* =============================================================
80
- ⚙️ SAFE STEP RUNNER
81
- ============================================================= */
45
+ ⚙️ SAFE STEP RUNNER
46
+ ============================================================= */
82
47
  function runStep(args, label) {
83
- return new Promise((resolve) => {
84
- startLoading(label);
85
- let localErr = false;
86
- const child = spawn("npx", args, { shell: true, stdio: ["inherit", "pipe", "pipe"] });
87
-
88
- child.stdout.on("data", (data) => {
89
- const out = data.toString();
90
- if (!out.includes('Pulling schema')) {
91
- stopLoading();
92
- process.stdout.write(`${T.gray}${out}${T.reset}`);
93
- }
94
- if (/error|failed/i.test(out)) localErr = true;
95
- });
96
-
97
- child.on("close", (code) => {
98
- stopLoading();
99
- resolve(code === 0 && !localErr);
48
+ return new Promise((resolve) => {
49
+ startLoading(`${T.pink}${label}${T.reset}`);
50
+
51
+ const child = spawn("npx", args, {
52
+ shell: true,
53
+ stdio: ["inherit", "pipe", "pipe"]
54
+ });
55
+
56
+ child.stdout.on("data", (data) => {
57
+ const out = data.toString();
58
+ if (!out.includes('Pulling')) {
59
+ stopLoading();
60
+ process.stdout.write(`${T.gray}${out}${T.reset}`);
61
+ }
62
+ });
63
+
64
+ child.on("close", (code) => {
65
+ stopLoading();
66
+ resolve(code === 0);
67
+ });
100
68
  });
101
- });
102
69
  }
103
70
 
104
71
  /* =============================================================
105
- 🔁 ENGINE WORKFLOW
106
- ============================================================= */
72
+ 🔁 ENGINE WORKFLOW
73
+ ============================================================= */
107
74
  let isRunning = false;
108
75
 
109
76
  async function triggerEngine() {
110
- if (isRunning) return;
111
- isRunning = true;
112
-
113
- const audit = justifyStructure();
114
- if (!audit.ok) {
115
- console.log(`${T.red}${T.bold}✖ CRITICAL FAILURE:${T.reset} ${audit.msg}`);
116
- isRunning = false; return;
117
- }
118
-
119
- const steps = [
120
- { name: "Checking Integrity", args: ["drizzle-kit", "check"] },
121
- { name: "Generating Schema", args: ["drizzle-kit", "generate"] },
122
- { name: "Pushing to Database", args: ["drizzle-kit", "push"] }
123
- ];
124
-
125
- for (const step of steps) {
126
- const success = await runStep(step.args, step.name);
127
- if (!success) {
128
- console.log(`\n${T.red}${T.bold}✖ PIPELINE CRASHED AT [${step.name.toUpperCase()}]${T.reset}`);
129
- isRunning = false; return;
77
+ if (isRunning) return;
78
+ isRunning = true;
79
+
80
+ const steps = [
81
+ { name: "Checking Integrity", args: ["drizzle-kit", "check"] },
82
+ { name: "Generating Migrations", args: ["drizzle-kit", "generate"] },
83
+ { name: "Pushing to Database", args: ["drizzle-kit", "push"] }
84
+ ];
85
+
86
+ for (const step of steps) {
87
+ const success = await runStep(step.args, step.name);
88
+ if (!success) {
89
+ console.log(`\n${T.red}${T.bold}✖ PIPELINE HALTED AT [${step.name.toUpperCase()}]${T.reset}`);
90
+ isRunning = false;
91
+ return;
92
+ }
130
93
  }
131
- }
132
94
 
133
- console.log(`\n${T.lime}${T.bold}✔ SYSTEM JUSTIFIED & SYNCED${T.reset}\n`);
134
- isRunning = false;
95
+ console.log(`\n${T.lime}${T.bold}✔ DATABASE SYNCED${T.reset}`);
96
+ isRunning = false;
135
97
  }
136
98
 
137
99
  /* =============================================================
138
- 👀 WATCHER
139
- ============================================================= */
100
+ 👀 WATCHER
101
+ ============================================================= */
140
102
  chokidar.watch(".", {
141
- ignored: [/node_modules/, /.git/, /.next/, /dist/],
142
- ignoreInitial: true,
143
- usePolling: true,
144
- interval: 300
145
- }).on("all", (e, f) => {
146
- console.log(`${T.gray}${T.italic}→ Change in: ${path.basename(f)}${T.reset}`);
147
- triggerEngine();
103
+ ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
104
+ ignoreInitial: true,
105
+ usePolling: true,
106
+ interval: 500
107
+ }).on("all", (event, file) => {
108
+ if (file.includes("schema") || file.includes("drizzle.config")) {
109
+ triggerEngine();
110
+ }
148
111
  });
149
112
 
150
- console.clear();
151
- console.log(`${T.cyan}${T.bold}⚡ NEON-BLUE WATCHER ACTIVE [DRIZZLE]${T.reset}\n`);
113
+ // Initial run
152
114
  triggerEngine();
153
115
 
154
116
  process.on("SIGINT", () => {
155
- stopLoading();
156
- console.log(`\n${T.blue}Shutting down...${T.reset}`);
157
- process.exit();
117
+ stopLoading();
118
+ process.exit();
158
119
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",