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.
- package/index.js +47 -37
- 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 -
|
|
5
|
-
* πΉ
|
|
6
|
-
* πΉ
|
|
7
|
-
* πΉ
|
|
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
|
|
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
|
-
// ----------------------
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
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
|
-
|
|
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(
|
|
164
|
+
triggerEngine();
|
|
154
165
|
|
|
166
|
+
const chokidar = require("chokidar");
|
|
155
167
|
chokidar.watch(".",{
|
|
156
|
-
ignored:[/node_modules/,/\.git
|
|
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(
|
|
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
|
-
|
|
169
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
process.exit();
|
|
184
|
+
process.on("SIGINT", ()=>{
|
|
185
|
+
console.log(`${T.yellow}Shutting down Drizzle-Auto...${T.reset}`);
|
|
186
|
+
process.exit(0);
|
|
177
187
|
});
|