drizzle-auto 1.0.20 → 1.0.21

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