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