drizzle-auto 1.0.6 โ†’ 1.0.8

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 +144 -42
  2. package/package.json +2 -16
package/index.js CHANGED
@@ -3,10 +3,44 @@
3
3
  const fs = require("fs");
4
4
  const path = require("path");
5
5
  const chokidar = require("chokidar");
6
- const spawn = require("cross-spawn");
6
+ const { spawn } = require("child_process");
7
7
 
8
8
  /* =========================
9
- ๐Ÿง  Detect project root
9
+ ๐ŸŽจ Neon Colors
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
+ const DIM = "\x1b[90m";
15
+
16
+ let colorIndex = 0;
17
+ const nextColor = () => COLORS[colorIndex++ % COLORS.length];
18
+ const rainbow = (text) => text.split("").map(c => `${nextColor()}${c}`).join("") + RESET;
19
+
20
+ /* =========================
21
+ โณ Neon Spinner
22
+ ========================= */
23
+ const spinnerFrames = ["โ ‹","โ ™","โ น","โ ธ","โ ผ","โ ด","โ ฆ","โ ง","โ ‡","โ "];
24
+ let spinIndex = 0;
25
+ let spinnerInterval;
26
+
27
+ function startSpinner(text) {
28
+ stopSpinner();
29
+ spinnerInterval = setInterval(() => {
30
+ process.stdout.write(`\r${nextColor()}${spinnerFrames[spinIndex++ % spinnerFrames.length]} ${text}${RESET}`);
31
+ }, 80);
32
+ }
33
+
34
+ function stopSpinner() {
35
+ if (spinnerInterval) {
36
+ clearInterval(spinnerInterval);
37
+ spinnerInterval = null;
38
+ process.stdout.write("\r\x1b[K");
39
+ }
40
+ }
41
+
42
+ /* =========================
43
+ ๐Ÿงญ Project Root & Package.json
10
44
  ========================= */
11
45
  function getProjectRoot() {
12
46
  const init = process.env.INIT_CWD;
@@ -20,7 +54,7 @@ const projectRoot = getProjectRoot();
20
54
  const pkgPath = path.join(projectRoot, "package.json");
21
55
 
22
56
  /* =========================
23
- โœ๏ธ Inject "tea" script
57
+ โœ๏ธ Auto Inject Script "tea"
24
58
  ========================= */
25
59
  function injectTeaScript() {
26
60
  if (!fs.existsSync(pkgPath)) return;
@@ -29,60 +63,128 @@ function injectTeaScript() {
29
63
  if (!pkg.scripts.tea) {
30
64
  pkg.scripts.tea = "drizzle-auto";
31
65
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
32
- console.log("โšก Script injected โ†’ npm run tea");
66
+ console.log("โšก tea script injected โ†’ npm run tea");
33
67
  }
34
68
  }
35
69
 
36
70
  /* =========================
37
- ๐Ÿš€ Run Drizzle pipeline
71
+ ๐Ÿงช Infrastructure Audit
38
72
  ========================= */
39
- let running = false;
40
-
41
- function runPipeline() {
42
- if (running) return;
43
- running = true;
44
- console.clear();
45
- console.log("๐Ÿš€ Drizzle Pipeline starting...");
46
-
47
- const p = spawn("npx", ["drizzle-kit", "check", "generate", "push"], {
48
- stdio: "inherit",
49
- shell: true,
50
- cwd: projectRoot,
51
- });
73
+ function auditInfra() {
74
+ const results = [];
75
+ const configFile = ["ts","js","mjs","mts"].map(ext => `drizzle.config.${ext}`)
76
+ .find(f => fs.existsSync(path.join(projectRoot, f)));
77
+ results.push({ name: "Drizzle Config", ok: !!configFile });
78
+
79
+ if (configFile) {
80
+ try {
81
+ const content = fs.readFileSync(path.join(projectRoot, configFile), "utf-8");
82
+ const match = content.match(/schema:\s*["'](.+?)["']/);
83
+ if (match) {
84
+ const schemaPath = path.join(projectRoot, match[1]);
85
+ results.push({ name: `Schema (${match[1]})`, ok: fs.existsSync(schemaPath) });
86
+ } else {
87
+ results.push({ name: "Schema Path", ok: false });
88
+ }
89
+ } catch {
90
+ results.push({ name: "Config Read", ok: false });
91
+ }
92
+ }
93
+
94
+ results.push({ name: ".env", ok: fs.existsSync(path.join(projectRoot, ".env")) });
95
+ results.push({ name: "node_modules", ok: fs.existsSync(path.join(projectRoot, "node_modules")) });
96
+
97
+ const missing = results.filter(r => !r.ok).map(r => r.name);
98
+ return { ok: missing.length === 0, missing };
99
+ }
100
+
101
+ /* =========================
102
+ โš™๏ธ Run NPX Command
103
+ ========================= */
104
+ function runStep(cmd) {
105
+ return new Promise((resolve) => {
106
+ let failed = false;
107
+ startSpinner(`npx ${cmd.join(" ")}`);
108
+ const p = spawn("npx", cmd, { shell: true });
52
109
 
53
- p.on("close", (code) => {
54
- running = false;
55
- if (code === 0) console.log("โœ… Drizzle synced!");
56
- else console.log("โŒ Drizzle pipeline failed. Fix errors & save files.");
110
+ p.stdout.on("data", d => {
111
+ stopSpinner();
112
+ process.stdout.write(DIM + d.toString() + RESET);
113
+ if (/error|failed/i.test(d)) failed = true;
114
+ });
115
+
116
+ p.stderr.on("data", d => {
117
+ stopSpinner();
118
+ process.stderr.write("\x1b[31m" + d + RESET);
119
+ failed = true;
120
+ });
121
+
122
+ p.on("close", code => resolve(code === 0 && !failed));
57
123
  });
58
124
  }
59
125
 
60
126
  /* =========================
61
- ๐Ÿ‘€ Postinstall / Auto inject
127
+ ๐Ÿš€ Main Workflow
62
128
  ========================= */
63
- if (process.argv.includes("--postinstall")) {
129
+ let isRunning = false;
130
+ let hasError = false;
131
+
132
+ async function workflow(trigger) {
133
+ if (isRunning) return;
134
+ isRunning = true;
135
+
136
+ if (!hasError) console.clear();
137
+ console.log(`\n${nextColor()}โšก ${trigger}${RESET}`);
138
+
139
+ const audit = auditInfra();
140
+ if (!audit.ok) {
141
+ console.log("\n\x1b[31mโŒ Infra not ready\x1b[0m");
142
+ audit.missing.forEach(m => console.log(DIM + "โ€ข " + m + RESET));
143
+ hasError = true;
144
+ isRunning = false;
145
+ return;
146
+ }
147
+
148
+ const steps = [
149
+ ["drizzle-kit", "check"],
150
+ ["drizzle-kit", "generate"],
151
+ ["drizzle-kit", "push"]
152
+ ];
153
+
154
+ for (const s of steps) {
155
+ if (!(await runStep(s))) {
156
+ console.log("\n\x1b[31m๐Ÿ’€ Pipeline crashed\x1b[0m");
157
+ hasError = true;
158
+ isRunning = false;
159
+ return;
160
+ }
161
+ }
162
+
163
+ hasError = false;
164
+ console.log("\n\x1b[32mโœจ Drizzle synced\x1b[0m");
165
+ setTimeout(() => (isRunning = false), 1200);
166
+ }
167
+
168
+ /* =========================
169
+ ๐Ÿ‘€ Watcher
170
+ ========================= */
171
+ chokidar.watch(projectRoot, {
172
+ ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
173
+ ignoreInitial: true,
174
+ usePolling: true,
175
+ interval: 300
176
+ }).on("all", (e, f) => workflow(`${e.toUpperCase()} โ†’ ${f ? path.basename(f) : ""}`));
177
+
178
+ /* =========================
179
+ ๐Ÿ›  Postinstall Mode
180
+ ========================= */
181
+ if (process.argv.includes("--postinstall") || process.env.npm_config_argv) {
64
182
  injectTeaScript();
65
- runPipeline(); // first run after install
66
183
  process.exit(0);
67
184
  }
68
185
 
69
186
  /* =========================
70
- ๐Ÿ‘€ Watcher
187
+ ๐ŸŒŸ Init
71
188
  ========================= */
72
189
  injectTeaScript();
73
- runPipeline(); // first run immediately when running npx drizzle-auto
74
-
75
- chokidar
76
- .watch(projectRoot, {
77
- ignored: /node_modules|\.git|\.next/,
78
- ignoreInitial: true,
79
- })
80
- .on("all", (event, filePath) => {
81
- console.log(`โšก File changed โ†’ ${filePath}`);
82
- runPipeline();
83
- });
84
-
85
- process.on("uncaughtException", (err) => {
86
- console.log("\x1b[31m๐Ÿ”ฅ Crash:\x1b[0m", err.message);
87
- running = false;
88
- });
190
+ workflow("Initial Audit");
package/package.json CHANGED
@@ -1,28 +1,14 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.6",
4
- "description": "Auto Drizzle sync with tea script injection",
5
- "main": "index.js",
3
+ "version": "1.0.8",
6
4
  "bin": {
7
5
  "drizzle-auto": "index.js"
8
6
  },
9
7
  "scripts": {
10
8
  "postinstall": "node index.js --postinstall"
11
9
  },
12
- "publishConfig": {
13
- "access": "public"
14
- },
15
- "keywords": [
16
- "drizzle",
17
- "automation",
18
- "nextjs",
19
- "watcher",
20
- "tea"
21
- ],
22
- "author": "Pavel Ahmmed Hridoy",
23
- "license": "MIT",
24
10
  "dependencies": {
25
11
  "chokidar": "^4.0.1",
26
12
  "cross-spawn": "^7.0.6"
27
13
  }
28
- }
14
+ }