drizzle-auto 1.1.20 β†’ 1.1.22

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 +60 -85
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * 🌟 Drizzle-Auto v2 - Strict Config Edition
5
- * πŸ”Ή Watches your project and auto-runs drizzle-kit steps
6
- * πŸ”Ή Accepts only: drizzle.config.js / ts / mjs / cjs
7
- * πŸ”Ή Fully server-style logging
8
- * πŸ”Ή Neon-pulse colored UI with emojis
4
+ * 🌟 Drizzle-Auto v2 - Postinstall Safe
5
+ * πŸ”Ή Injects "tea" script
6
+ * πŸ”Ή Detects strict config (.js/.ts/.mjs/.cjs)
7
+ * πŸ”Ή Won’t run watcher/server during npm install
9
8
  */
10
9
 
11
10
  const chokidar = require("chokidar");
@@ -13,27 +12,22 @@ const { spawn } = require("child_process");
13
12
  const path = require("path");
14
13
  const fs = require("fs");
15
14
 
16
- /* =============================================================
17
- 🎨 NEON-PULSE UI COLORS
18
- ============================================================= */
15
+ // Optional: load ts-node if .ts config exists
16
+ try { require("ts-node").register({ transpileOnly: true }); } catch(e){}
17
+
18
+ // ---------------------- COLORS ----------------------
19
19
  const T = {
20
20
  reset: "\x1b[0m",
21
21
  bold: "\x1b[1m",
22
- italic: "\x1b[3m",
23
- underline: "\x1b[4m",
24
22
  cyan: "\x1b[38;5;51m",
25
23
  pink: "\x1b[38;5;201m",
26
24
  lime: "\x1b[38;5;118m",
27
25
  yellow: "\x1b[38;5;226m",
28
26
  red: "\x1b[38;5;196m",
29
27
  gray: "\x1b[38;5;244m",
30
- magenta: "\x1b[38;5;201m",
31
- bg_dark: "\x1b[48;5;234m"
32
28
  };
33
29
 
34
- /* =============================================================
35
- ⏳ SPINNER
36
- ============================================================= */
30
+ // ---------------------- SPINNER ----------------------
37
31
  const frames = ["β ‹","β ™","β Ή","β Έ","β Ό","β ΄","β ¦","β §","β ‡","⠏"];
38
32
  let spinIdx = 0, spinInterval;
39
33
 
@@ -47,20 +41,17 @@ function startLoading(msg){
47
41
  function stopLoading(){
48
42
  if(spinInterval){
49
43
  clearInterval(spinInterval);
50
- spinInterval=null;
44
+ spinInterval = null;
51
45
  process.stdout.write("\r\x1b[K");
52
46
  }
53
47
  }
54
48
 
55
- /* =============================================================
56
- 🧩 AUTO SCRIPT INJECTOR
57
- ============================================================= */
49
+ // ---------------------- AUTO SCRIPT INJECTOR ----------------------
58
50
  const PKG = path.join(process.cwd(), "package.json");
59
51
  function injectScript() {
60
52
  if (!fs.existsSync(PKG)) return;
61
53
  const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
62
54
  pkg.scripts ||= {};
63
-
64
55
  if (!pkg.scripts.tea) {
65
56
  pkg.scripts.tea = "drizzle-auto";
66
57
  console.log(`${T.lime}🍡 Script added β†’ npm/yarn/pnpm run tea${T.reset}`);
@@ -69,9 +60,7 @@ function injectScript() {
69
60
  }
70
61
  injectScript();
71
62
 
72
- /* =============================================================
73
- πŸ” FIND STRICT DRIZZLE CONFIGS
74
- ============================================================= */
63
+ // ---------------------- STRICT CONFIG DETECTION ----------------------
75
64
  function findDrizzleConfig(root){
76
65
  const allowed = [
77
66
  "drizzle.config.js",
@@ -80,74 +69,54 @@ function findDrizzleConfig(root){
80
69
  "drizzle.config.cjs"
81
70
  ];
82
71
  const files = [];
83
-
84
72
  function walk(dir){
85
73
  fs.readdirSync(dir,{withFileTypes:true}).forEach(file=>{
86
74
  const full = path.join(dir,file.name);
87
- if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) {
88
- walk(full);
89
- } else if(file.isFile() && allowed.includes(file.name)) {
90
- files.push(full);
91
- }
75
+ if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) walk(full);
76
+ else if(file.isFile() && allowed.includes(file.name)) files.push(full);
92
77
  });
93
78
  }
94
-
95
79
  walk(root);
96
80
  return files;
97
81
  }
98
82
 
99
- /* =============================================================
100
- πŸ”Ή VALIDATE SCHEMA
101
- ============================================================= */
83
+ // ---------------------- VALIDATE SCHEMA ----------------------
102
84
  function validateSchema(){
103
- const root = process.cwd();
104
- const configs = findDrizzleConfig(root);
105
-
85
+ const configs = findDrizzleConfig(process.cwd());
106
86
  if(configs.length === 0)
107
- return { ok:false, msg:"Missing exact drizzle.config.js / ts / mjs / cjs" };
87
+ return { ok:false, msg:"Missing strict drizzle.config.js / ts / mjs / cjs" };
108
88
 
109
89
  for(const cfg of configs){
110
90
  try {
111
- const content = fs.readFileSync(cfg,"utf8");
112
- const match = content.match(/schema:\s*["'](.+?)["']/);
113
- if(match && match[1]){
114
- const schemaFull = path.resolve(path.dirname(cfg), match[1]);
115
- if(!fs.existsSync(schemaFull))
116
- return { ok:false, msg:`Schema not found: ${match[1]} in ${cfg}` };
117
- }
91
+ let schemaPath;
92
+ const mod = require(cfg);
93
+ schemaPath = mod.default?.schema || mod.schema;
94
+
95
+ if(!schemaPath) continue;
96
+
97
+ const schemaFull = path.resolve(path.dirname(cfg), schemaPath);
98
+ if(!fs.existsSync(schemaFull))
99
+ return { ok:false, msg:`Schema not found: ${schemaPath} in ${cfg}` };
100
+
118
101
  } catch(e){
119
- return { ok:false, msg:`Config parse error in ${cfg}` };
102
+ return { ok:false, msg:`Config parse error in ${cfg}: ${e.message}` };
120
103
  }
121
104
  }
122
105
 
123
106
  return { ok:true, config:configs };
124
107
  }
125
108
 
126
- /* =============================================================
127
- βš™οΈ SERVER-STYLE RUNNER
128
- ============================================================= */
129
- function runCommandServerStyle(cmd,label){
130
- return new Promise(resolve=>{
131
- startLoading(`${T.pink}${label}${T.reset}`);
132
- const child = spawn(cmd,{shell:true,stdio:"inherit"});
133
- child.on("close",code=>{ stopLoading(); resolve(code===0); });
134
- child.on("error",err=>{ stopLoading(); console.log(`${T.red}βœ– ${label} Error: ${err.message}${T.reset}`); resolve(false); });
135
- });
136
- }
137
-
138
- /* =============================================================
139
- πŸ” ENGINE WORKFLOW
140
- ============================================================= */
109
+ // ---------------------- ENGINE ----------------------
141
110
  let running=false;
142
111
  async function triggerEngine(event){
143
112
  if(running) return;
144
113
  running=true;
145
114
 
146
115
  const audit = validateSchema();
147
- if(!audit.ok){
148
- console.log(`${T.red}${T.bold}πŸ‘Ύ CRITICAL FAILURE:${T.reset} ${audit.msg}`);
149
- running=false;
150
- return;
116
+ if(!audit.ok){
117
+ console.log(`${T.red}${T.bold}πŸ‘Ύ CRITICAL FAILURE:${T.reset} ${audit.msg}`);
118
+ running=false;
119
+ return;
151
120
  }
152
121
 
153
122
  const steps = [
@@ -157,38 +126,44 @@ async function triggerEngine(event){
157
126
  ];
158
127
 
159
128
  for(const step of steps){
160
- const success = await runCommandServerStyle(step.cmd,step.name);
129
+ const success = await new Promise(resolve=>{
130
+ startLoading(step.name);
131
+ const child = spawn(step.cmd,{shell:true,stdio:"inherit"});
132
+ child.on("close",code=>{ stopLoading(); resolve(code===0); });
133
+ child.on("error",err=>{ stopLoading(); console.log(`${T.red}βœ– ${step.name} Error: ${err.message}${T.reset}`); resolve(false); });
134
+ });
161
135
  if(!success){
162
136
  console.log(`\n${T.red}${T.bold}πŸ‘Ύ FAILED AT [${step.name.toUpperCase()}]${T.reset}`);
163
- running=false; return;
137
+ running=false;
138
+ return;
164
139
  }
165
140
  }
166
141
 
167
142
  console.log(`\n${T.lime}${T.bold}πŸŽ‰ All steps successful!${T.reset}`);
168
- console.log(`${T.gray}Waiting for changes...${T.reset}\n`);
169
143
  running=false;
170
144
  }
171
145
 
172
- /* =============================================================
173
- πŸ‘€ WATCHER
174
- ============================================================= */
175
- chokidar.watch(".",{
176
- ignored:[/node_modules/,/\.git/,/\.next/,/dist/],
177
- ignoreInitial:true,
178
- usePolling:true,
179
- interval:300
180
- }).on("all",(e,f)=>triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
181
-
182
- // Only trigger if config exists
183
- if(findDrizzleConfig(process.cwd()).length > 0){
184
- triggerEngine("Initial Audit");
185
- } else {
186
- console.log(`${T.yellow}⚠ No strict drizzle.config found. Skipping initial audit.${T.reset}`);
146
+ // ---------------------- WATCHER ----------------------
147
+ // Skip watcher during postinstall
148
+ const skipWatcher = process.argv.includes('--postinstall');
149
+
150
+ if(!skipWatcher){
151
+ const configsExist = findDrizzleConfig(process.cwd()).length > 0;
152
+ if(configsExist){
153
+ triggerEngine("Initial Audit");
154
+
155
+ chokidar.watch(".",{
156
+ ignored:[/node_modules/,/\.git|\.next|dist/],
157
+ ignoreInitial:true,
158
+ usePolling:true,
159
+ interval:300
160
+ }).on("all",(e,f)=>triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
161
+ } else {
162
+ console.log(`${T.yellow}⚠ No strict drizzle.config found. Watcher disabled.${T.reset}`);
163
+ }
187
164
  }
188
165
 
189
- /* =============================================================
190
- 🚨 GLOBAL ERROR HANDLING
191
- ============================================================= */
166
+ // ---------------------- GLOBAL ERROR HANDLING ----------------------
192
167
  process.on("uncaughtException",err=>{
193
168
  stopLoading();
194
169
  console.log(`\n${T.red}${T.bold}πŸ›‘οΈ ERROR:${T.reset} ${err.message}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.1.20",
3
+ "version": "1.1.22",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",