drizzle-auto 1.0.15 → 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 +80 -120
  2. package/package.json +9 -3
package/index.js CHANGED
@@ -6,162 +6,122 @@ const chokidar = require("chokidar");
6
6
  const { spawn } = require("child_process");
7
7
 
8
8
  /* =========================
9
- šŸŽØ TERMINAL COLORS (PRO)
10
- ========================= */
11
- const C = {
12
- reset: "\x1b[0m",
13
- bold: "\x1b[1m",
14
- dim: "\x1b[2m",
15
-
16
- cyan: "\x1b[36m",
17
- green: "\x1b[32m",
18
- yellow: "\x1b[33m",
19
- red: "\x1b[31m",
20
- magenta: "\x1b[35m",
21
- blue: "\x1b[34m",
22
- gray: "\x1b[90m"
23
- };
24
-
25
- const ui = {
26
- title: m => console.log(`\n${C.bold}${C.magenta}ā—† ${m}${C.reset}`),
27
- info: m => console.log(`${C.cyan}ā—${C.reset} ${m}`),
28
- watch: m => console.log(`${C.blue}šŸ‘€${C.reset} ${m}`),
29
- ok: m => console.log(`${C.green}āœ”${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.gray}${m}${C.reset}`)
33
- };
34
-
35
- /* =========================
36
- 🧭 PROJECT ROOT
9
+ 🧭 PROJECT ROOT
37
10
  ========================= */
38
11
  const ROOT = process.cwd();
39
12
  const PKG = path.join(ROOT, "package.json");
40
13
 
41
14
  /* =========================
42
- 🧩 SCRIPT INJECTOR
15
+ 🧩 SCRIPT INJECTOR
43
16
  ========================= */
44
17
  function injectScript() {
45
- if (!fs.existsSync(PKG)) return;
46
-
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
- ui.ok("Script injected → npm run tea");
54
- } else {
55
- ui.dim("Script already exists → tea");
56
- }
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
+ }
57
27
  }
58
28
 
59
29
  /* =========================
60
- šŸ” DRIZZLE DETECTOR
30
+ šŸ” DRIZZLE DETECTOR
61
31
  ========================= */
62
32
  function detectDrizzle() {
63
- const config = ["js", "mjs", "ts", "mts"]
64
- .map(ext => `drizzle.config.${ext}`)
65
- .find(f => fs.existsSync(path.join(ROOT, f)));
66
-
67
- if (!config) {
68
- ui.warn("No drizzle.config found");
69
- return null;
70
- }
71
-
72
- let schemaPath = null;
73
-
74
- try {
75
- const content = fs.readFileSync(path.join(ROOT, config), "utf8");
76
- const match = content.match(/schema:\s*["'](.+?)["']/);
77
- if (match) schemaPath = path.join(ROOT, match[1]);
78
- } catch {}
79
-
80
- if (schemaPath && !fs.existsSync(schemaPath)) {
81
- ui.err("Schema file missing");
82
- return null;
83
- }
84
-
85
- ui.ok(`Detected ${config}`);
86
- return true;
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 };
87
55
  }
88
56
 
89
57
  /* =========================
90
- āš™ļø SAFE COMMAND RUNNER
58
+ āš™ļø SAFE COMMAND RUNNER
91
59
  ========================= */
92
60
  function run(cmd) {
93
- return new Promise(resolve => {
94
- let failed = false;
95
-
96
- const p = spawn("npx", cmd, {
97
- shell: true,
98
- stdio: ["ignore", "pipe", "pipe"]
99
- });
100
-
101
- p.stdout.on("data", d => process.stdout.write(d));
102
- p.stderr.on("data", d => {
103
- failed = true;
104
- process.stderr.write(d);
105
- });
106
-
107
- p.on("close", code => resolve(code === 0 && !failed));
108
- });
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
+ });
109
77
  }
110
78
 
111
79
  /* =========================
112
- šŸ” PIPELINE (SERVER SAFE)
80
+ šŸ” PIPELINE (NON-KILLING)
113
81
  ========================= */
114
82
  let busy = false;
115
83
 
116
84
  async function pipeline(trigger) {
117
- if (busy) return;
118
- busy = true;
119
-
120
- ui.watch(`Trigger → ${trigger}`);
121
-
122
- if (!detectDrizzle()) {
123
- busy = false;
124
- return;
125
- }
85
+ if (busy) return;
86
+ busy = true;
126
87
 
127
- ui.info("Running drizzle-kit generate...");
128
- const genOK = await run(["drizzle-kit", "generate"]);
88
+ console.log(\n⚔ Trigger → ${trigger});
129
89
 
130
- if (!genOK) {
131
- ui.err("Generate failed — pipeline stopped");
132
- busy = false;
133
- return;
134
- }
135
-
136
- ui.ok("Generate successful");
90
+ const drizzle = detectDrizzle();
91
+ if (!drizzle) {
92
+ busy = false;
93
+ return;
94
+ }
137
95
 
138
- ui.info("Running drizzle-kit push...");
139
- const pushOK = await run(["drizzle-kit", "push"]);
96
+ const genOK = await run(["drizzle-kit", "generate"]);
97
+ if (!genOK) {
98
+ console.log("šŸ›‘ Generate failed — pipeline paused");
99
+ busy = false;
100
+ return;
101
+ }
140
102
 
141
- if (!pushOK) {
142
- ui.warn("Push failed — server still running");
143
- busy = false;
144
- return;
145
- }
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
+ }
146
109
 
147
- ui.ok("Drizzle fully synced ✨");
148
- busy = false;
110
+ console.log("✨ Drizzle fully synced");
111
+ busy = false;
149
112
  }
150
113
 
151
114
  /* =========================
152
- šŸ‘€ WATCHER (ALWAYS ALIVE)
115
+ šŸ‘€ WATCHER (ALWAYS ALIVE)
153
116
  ========================= */
154
- ui.title("DrizzlePulse — Server Start");
155
- ui.dim(`Root → ${ROOT}`);
156
-
157
117
  injectScript();
158
118
  pipeline("Initial");
159
119
 
160
120
  chokidar.watch(ROOT, {
161
- ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
162
- ignoreInitial: true,
163
- usePolling: true,
164
- interval: 300
121
+ ignored: [/node_modules/, /.git/, /.next/, /dist/],
122
+ ignoreInitial: true,
123
+ usePolling: true,
124
+ interval: 300
165
125
  }).on("all", (_, file) => {
166
- pipeline(path.basename(file));
126
+ pipeline(path.basename(file));
167
127
  });
package/package.json CHANGED
@@ -1,6 +1,11 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
+ "description": "",
5
+ "license": "ISC",
6
+ "author": "pavel ahmmed hridoy",
7
+ "type": "commonjs",
8
+ "main": "index.js",
4
9
  "bin": {
5
10
  "drizzle-auto": "index.js"
6
11
  },
@@ -11,5 +16,6 @@
11
16
  "dependencies": {
12
17
  "chokidar": "^5.0.0",
13
18
  "cross-spawn": "^7.0.6"
14
- }
15
- }
19
+ },
20
+ "devDependencies": {}
21
+ }