drizzle-auto 1.1.22 β†’ 1.1.23

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