drizzle-auto 1.0.16 → 1.0.17

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 +96 -77
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5,104 +5,123 @@ const path = require("path");
5
5
  const chokidar = require("chokidar");
6
6
  const { spawn } = require("child_process");
7
7
 
8
+ /* =========================
9
+ 🧭 PROJECT ROOT
10
+ ========================= */
8
11
  const ROOT = process.cwd();
9
12
  const PKG = path.join(ROOT, "package.json");
10
13
 
11
- /* ================= COLORS ================= */
12
- const C = {
13
- r: "\x1b[0m",
14
- g: "\x1b[32m",
15
- y: "\x1b[33m",
16
- c: "\x1b[36m",
17
- b: "\x1b[1m",
18
- red: "\x1b[31m",
19
- dim: "\x1b[90m"
20
- };
21
-
22
- const log = {
23
- ok: m => console.log(`${C.g}āœ”${C.r} ${m}`),
24
- info: m => console.log(`${C.c}ā—${C.r} ${m}`),
25
- warn: m => console.log(`${C.y}ā–²${C.r} ${m}`),
26
- err: m => console.log(`${C.red}āœ–${C.r} ${m}`),
27
- dim: m => console.log(`${C.dim}${m}${C.r}`)
28
- };
29
-
30
- /* ================= SCRIPT INJECT ================= */
14
+ /* =========================
15
+ 🧩 SCRIPT INJECTOR
16
+ ========================= */
31
17
  function injectScript() {
32
- if (!fs.existsSync(PKG)) return;
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");
26
+ }
27
+ }
28
+
29
+ /* =========================
30
+ šŸ” DRIZZLE DETECTOR
31
+ ========================= */
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)));
36
+
37
+ if (!configs) {
38
+ console.log("āš ļø No drizzle.config found");
39
+ return null;
40
+ }
33
41
 
34
- const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
35
- pkg.scripts ||= {};
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 {}
36
48
 
37
- if (!pkg.scripts.tea) {
38
- pkg.scripts.tea = "drizzle-auto";
39
- fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
40
- log.ok("Added script → npm run tea");
41
- }
49
+ if (schemaPath && !fs.existsSync(schemaPath)) {
50
+ console.log("āŒ Schema file missing");
51
+ return null;
42
52
  }
43
53
 
44
- /* ================= DRIZZLE DETECT ================= */
45
- function hasDrizzle() {
46
- return ["js", "mjs", "ts", "mts"]
47
- .some(e => fs.existsSync(path.join(ROOT, `drizzle.config.${e}`)));
54
+ return { config: configs, schema: schemaPath };
48
55
  }
49
56
 
50
- /* ================= RUNNER ================= */
51
- function run(args) {
52
- return new Promise(res => {
53
- const p = spawn("npx", args, { shell: true });
54
- let fail = false;
57
+ /* =========================
58
+ āš™ļø SAFE COMMAND RUNNER
59
+ ========================= */
60
+ function run(cmd) {
61
+ return new Promise((resolve) => {
62
+ let failed = false;
55
63
 
56
- p.stdout.on("data", d => process.stdout.write(d));
57
- p.stderr.on("data", d => {
58
- fail = true;
59
- process.stderr.write(d);
60
- });
64
+ const p = spawn("npx", cmd, { shell: true });
61
65
 
62
- p.on("close", c => res(c === 0 && !fail));
63
- });
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
+ });
64
77
  }
65
78
 
66
- /* ================= PIPELINE ================= */
79
+ /* =========================
80
+ šŸ” PIPELINE (NON-KILLING)
81
+ ========================= */
67
82
  let busy = false;
83
+
68
84
  async function pipeline(trigger) {
69
- if (busy) return;
70
- busy = true;
71
-
72
- log.info(`Trigger → ${trigger}`);
73
-
74
- if (!hasDrizzle()) {
75
- log.warn("No drizzle config found");
76
- busy = false;
77
- return;
78
- }
79
-
80
- if (!(await run(["drizzle-kit", "generate"]))) {
81
- log.err("Generate failed — stopping");
82
- busy = false;
83
- return;
84
- }
85
-
86
- if (!(await run(["drizzle-kit", "push"]))) {
87
- log.warn("Push failed — server alive");
88
- busy = false;
89
- return;
90
- }
91
-
92
- log.ok("Drizzle synced ✨");
93
- busy = false;
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;
94
108
  }
95
109
 
96
- /* ================= ENTRY ================= */
97
- if (process.argv.includes("--inject")) {
98
- injectScript();
99
- process.exit(0);
110
+ console.log("✨ Drizzle fully synced");
111
+ busy = false;
100
112
  }
101
113
 
114
+ /* =========================
115
+ šŸ‘€ WATCHER (ALWAYS ALIVE)
116
+ ========================= */
102
117
  injectScript();
103
118
  pipeline("Initial");
104
119
 
105
120
  chokidar.watch(ROOT, {
106
- ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
107
- ignoreInitial: true
108
- }).on("all", (_, f) => pipeline(path.basename(f)));
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",