drizzle-auto 1.0.18 → 1.0.20

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 +80 -97
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -11,86 +11,69 @@ const { spawn } = require("child_process");
11
11
  const ROOT = process.cwd();
12
12
  const PKG = path.join(ROOT, "package.json");
13
13
 
14
- /* =========================
15
- šŸŽØ COLORS
16
- ========================= */
17
- const C = {
18
- reset: "\x1b[0m",
19
- green: "\x1b[32m",
20
- yellow: "\x1b[33m",
21
- cyan: "\x1b[36m",
22
- red: "\x1b[31m",
23
- bold: "\x1b[1m",
24
- dim: "\x1b[90m"
25
- };
26
-
27
- const log = {
28
- ok: (m) => console.log(`${C.green}āœ”${C.reset} ${m}`),
29
- info: (m) => console.log(`${C.cyan}ā—${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.dim}${m}${C.reset}`)
33
- };
34
-
35
14
  /* =========================
36
15
  🧩 SCRIPT INJECTOR
37
16
  ========================= */
38
17
  function injectScript() {
39
- if (!fs.existsSync(PKG)) return;
40
- const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
41
- pkg.scripts ||= {};
42
-
43
- if (!pkg.scripts.tea) {
44
- pkg.scripts.tea = "drizzle-auto";
45
- fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
46
- log.ok("Script added → npm run tea");
47
- }
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
+ }
48
27
  }
49
28
 
50
29
  /* =========================
51
30
  šŸ” DRIZZLE DETECTOR
52
31
  ========================= */
53
32
  function detectDrizzle() {
54
- const configs = ["js", "mjs", "ts", "mts"]
55
- .map(ext => `drizzle.config.${ext}`)
56
- .find(f => fs.existsSync(path.join(ROOT, f)));
57
-
58
- if (!configs) {
59
- log.warn("No drizzle.config found");
60
- return null;
61
- }
62
-
63
- let schemaPath = null;
64
- try {
65
- const content = fs.readFileSync(path.join(ROOT, configs), "utf8");
66
- const match = content.match(/schema:\s*['"](.+?)['"]/);
67
- if (match) schemaPath = path.join(ROOT, match[1]);
68
- } catch {}
69
-
70
- if (schemaPath && !fs.existsSync(schemaPath)) {
71
- log.err("Schema file missing");
72
- return null;
73
- }
74
-
75
- return { config: configs, schema: schemaPath };
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
+ }
41
+
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;
52
+ }
53
+
54
+ return { config: configs, schema: schemaPath };
76
55
  }
77
56
 
78
57
  /* =========================
79
58
  āš™ļø SAFE COMMAND RUNNER
80
59
  ========================= */
81
60
  function run(cmd) {
82
- return new Promise(resolve => {
83
- let failed = false;
84
- const p = spawn("npx", cmd, { shell: true });
85
-
86
- p.stdout.on("data", d => process.stdout.write(d));
87
- p.stderr.on("data", d => {
88
- failed = true;
89
- process.stderr.write(d);
90
- });
91
-
92
- p.on("close", code => resolve(code === 0 && !failed));
93
- });
61
+ return new Promise((resolve) => {
62
+ let failed = false;
63
+
64
+ const p = spawn("npx", cmd, { shell: true });
65
+
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
+ });
94
77
  }
95
78
 
96
79
  /* =========================
@@ -99,33 +82,33 @@ function run(cmd) {
99
82
  let busy = false;
100
83
 
101
84
  async function pipeline(trigger) {
102
- if (busy) return;
103
- busy = true;
104
-
105
- log.info(`Trigger → ${trigger}`);
106
-
107
- const drizzle = detectDrizzle();
108
- if (!drizzle) {
109
- busy = false;
110
- return;
111
- }
112
-
113
- const genOK = await run(["drizzle-kit", "generate"]);
114
- if (!genOK) {
115
- log.err("Generate failed — pipeline paused");
116
- busy = false;
117
- return;
118
- }
119
-
120
- const pushOK = await run(["drizzle-kit", "push"]);
121
- if (!pushOK) {
122
- log.warn("Push failed — server still running");
123
- busy = false;
124
- return;
125
- }
126
-
127
- log.ok("✨ Drizzle fully synced");
128
- 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;
108
+ }
109
+
110
+ console.log("✨ Drizzle fully synced");
111
+ busy = false;
129
112
  }
130
113
 
131
114
  /* =========================
@@ -135,10 +118,10 @@ injectScript();
135
118
  pipeline("Initial");
136
119
 
137
120
  chokidar.watch(ROOT, {
138
- ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
139
- ignoreInitial: true,
140
- usePolling: true,
141
- interval: 300
121
+ ignored: [/node_modules/, /.git/, /.next/, /dist/],
122
+ ignoreInitial: true,
123
+ usePolling: true,
124
+ interval: 300
142
125
  }).on("all", (_, file) => {
143
- pipeline(path.basename(file));
144
- });
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.18",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",