drizzle-auto 1.1.22 β†’ 1.1.24

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 +47 -37
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,18 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
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
4
+ * 🌟 Drizzle-Auto v2 - Fail-Fast Version
5
+ * πŸ”Ή Stops immediately on any error
6
+ * πŸ”Ή Strict config: drizzle.config.js / ts / mjs / cjs
7
+ * πŸ”Ή Watcher disabled on --postinstall
8
+ * πŸ”Ή Full error catching
8
9
  */
9
10
 
10
- const chokidar = require("chokidar");
11
11
  const { spawn } = require("child_process");
12
12
  const path = require("path");
13
13
  const fs = require("fs");
14
14
 
15
- // Optional: load ts-node if .ts config exists
15
+ // Optional TS support
16
16
  try { require("ts-node").register({ transpileOnly: true }); } catch(e){}
17
17
 
18
18
  // ---------------------- COLORS ----------------------
@@ -46,7 +46,7 @@ function stopLoading(){
46
46
  }
47
47
  }
48
48
 
49
- // ---------------------- AUTO SCRIPT INJECTOR ----------------------
49
+ // ---------------------- INJECT "tea" SCRIPT ----------------------
50
50
  const PKG = path.join(process.cwd(), "package.json");
51
51
  function injectScript() {
52
52
  if (!fs.existsSync(PKG)) return;
@@ -106,17 +106,34 @@ function validateSchema(){
106
106
  return { ok:true, config:configs };
107
107
  }
108
108
 
109
+ // ---------------------- RUN SHELL COMMAND ----------------------
110
+ function runCommand(cmd, label){
111
+ return new Promise((resolve, reject) => {
112
+ startLoading(label);
113
+ const child = spawn(cmd, { shell: true, stdio: "inherit" });
114
+ child.on("close", code => {
115
+ stopLoading();
116
+ if(code !== 0) reject(new Error(`${label} failed with exit code ${code}`));
117
+ else resolve();
118
+ });
119
+ child.on("error", err => {
120
+ stopLoading();
121
+ reject(new Error(`${label} failed: ${err.message}`));
122
+ });
123
+ });
124
+ }
125
+
109
126
  // ---------------------- ENGINE ----------------------
110
- let running=false;
111
- async function triggerEngine(event){
127
+ let running = false;
128
+ async function triggerEngine(){
112
129
  if(running) return;
113
- running=true;
130
+ running = true;
114
131
 
115
132
  const audit = validateSchema();
116
133
  if(!audit.ok){
117
134
  console.log(`${T.red}${T.bold}πŸ‘Ύ CRITICAL FAILURE:${T.reset} ${audit.msg}`);
118
- running=false;
119
- return;
135
+ running = false;
136
+ process.exit(1); // <- stop immediately
120
137
  }
121
138
 
122
139
  const steps = [
@@ -125,53 +142,46 @@ async function triggerEngine(event){
125
142
  {name:"Push Database", cmd:"drizzle-kit push"}
126
143
  ];
127
144
 
128
- for(const step of steps){
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
- });
135
- if(!success){
136
- console.log(`\n${T.red}${T.bold}πŸ‘Ύ FAILED AT [${step.name.toUpperCase()}]${T.reset}`);
137
- running=false;
138
- return;
145
+ try {
146
+ for(const step of steps){
147
+ await runCommand(step.cmd, step.name);
139
148
  }
149
+ console.log(`${T.lime}${T.bold}πŸŽ‰ All steps successful!${T.reset}`);
150
+ } catch(err){
151
+ console.log(`${T.red}🚨 ERROR: ${err.message}${T.reset}`);
152
+ process.exit(1); // <- stop immediately on any error
140
153
  }
141
154
 
142
- console.log(`\n${T.lime}${T.bold}πŸŽ‰ All steps successful!${T.reset}`);
143
- running=false;
155
+ running = false;
144
156
  }
145
157
 
146
158
  // ---------------------- WATCHER ----------------------
147
- // Skip watcher during postinstall
148
159
  const skipWatcher = process.argv.includes('--postinstall');
149
160
 
150
161
  if(!skipWatcher){
151
162
  const configsExist = findDrizzleConfig(process.cwd()).length > 0;
152
163
  if(configsExist){
153
- triggerEngine("Initial Audit");
164
+ triggerEngine();
154
165
 
166
+ const chokidar = require("chokidar");
155
167
  chokidar.watch(".",{
156
- ignored:[/node_modules/,/\.git|\.next|dist/],
168
+ ignored:[/node_modules/,/\.git/,/\.next|dist/],
157
169
  ignoreInitial:true,
158
170
  usePolling:true,
159
171
  interval:300
160
- }).on("all",(e,f)=>triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
172
+ }).on("all", (e,f) => triggerEngine());
161
173
  } else {
162
174
  console.log(`${T.yellow}⚠ No strict drizzle.config found. Watcher disabled.${T.reset}`);
163
175
  }
164
176
  }
165
177
 
166
178
  // ---------------------- GLOBAL ERROR HANDLING ----------------------
167
- process.on("uncaughtException",err=>{
168
- stopLoading();
169
- console.log(`\n${T.red}${T.bold}πŸ›‘οΈ ERROR:${T.reset} ${err.message}`);
170
- running=false;
179
+ process.on("uncaughtException", err=>{
180
+ console.log(`${T.red}${T.bold}πŸ›‘οΈ UNCAUGHT ERROR:${T.reset} ${err.message}`);
181
+ process.exit(1); // <- stop immediately
171
182
  });
172
183
 
173
- process.on("SIGINT",()=>{
174
- stopLoading();
175
- console.log(`\n${T.yellow}Shutting down Drizzle-Auto...${T.reset}`);
176
- process.exit();
184
+ process.on("SIGINT", ()=>{
185
+ console.log(`${T.yellow}Shutting down Drizzle-Auto...${T.reset}`);
186
+ process.exit(0);
177
187
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drizzle-auto",
3
- "version": "1.1.22",
3
+ "version": "1.1.24",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "pavel ahmmed hridoy",