drizzle-auto 1.1.20 → 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 +83 -100
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,39 +1,32 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* 🌟 Drizzle-Auto v2 -
|
|
5
|
-
* 🔹
|
|
6
|
-
* 🔹
|
|
7
|
-
* 🔹
|
|
8
|
-
* 🔹 Neon-pulse colored UI with emojis
|
|
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
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
|
-
const
|
|
12
|
-
const { spawn } = require("child_process");
|
|
10
|
+
const { exec, spawn } = require("child_process");
|
|
13
11
|
const path = require("path");
|
|
14
12
|
const fs = require("fs");
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
// Optional: support TS configs
|
|
15
|
+
try { require("ts-node").register({ transpileOnly: true }); } catch(e){}
|
|
16
|
+
|
|
17
|
+
// ---------------------- COLORS ----------------------
|
|
19
18
|
const T = {
|
|
20
19
|
reset: "\x1b[0m",
|
|
21
20
|
bold: "\x1b[1m",
|
|
22
|
-
italic: "\x1b[3m",
|
|
23
|
-
underline: "\x1b[4m",
|
|
24
21
|
cyan: "\x1b[38;5;51m",
|
|
25
22
|
pink: "\x1b[38;5;201m",
|
|
26
23
|
lime: "\x1b[38;5;118m",
|
|
27
24
|
yellow: "\x1b[38;5;226m",
|
|
28
25
|
red: "\x1b[38;5;196m",
|
|
29
26
|
gray: "\x1b[38;5;244m",
|
|
30
|
-
magenta: "\x1b[38;5;201m",
|
|
31
|
-
bg_dark: "\x1b[48;5;234m"
|
|
32
27
|
};
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
⏳ SPINNER
|
|
36
|
-
============================================================= */
|
|
29
|
+
// ---------------------- SPINNER ----------------------
|
|
37
30
|
const frames = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
|
|
38
31
|
let spinIdx = 0, spinInterval;
|
|
39
32
|
|
|
@@ -47,20 +40,17 @@ function startLoading(msg){
|
|
|
47
40
|
function stopLoading(){
|
|
48
41
|
if(spinInterval){
|
|
49
42
|
clearInterval(spinInterval);
|
|
50
|
-
spinInterval=null;
|
|
43
|
+
spinInterval = null;
|
|
51
44
|
process.stdout.write("\r\x1b[K");
|
|
52
45
|
}
|
|
53
46
|
}
|
|
54
47
|
|
|
55
|
-
|
|
56
|
-
🧩 AUTO SCRIPT INJECTOR
|
|
57
|
-
============================================================= */
|
|
48
|
+
// ---------------------- INJECT "tea" SCRIPT ----------------------
|
|
58
49
|
const PKG = path.join(process.cwd(), "package.json");
|
|
59
50
|
function injectScript() {
|
|
60
51
|
if (!fs.existsSync(PKG)) return;
|
|
61
52
|
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
62
53
|
pkg.scripts ||= {};
|
|
63
|
-
|
|
64
54
|
if (!pkg.scripts.tea) {
|
|
65
55
|
pkg.scripts.tea = "drizzle-auto";
|
|
66
56
|
console.log(`${T.lime}🍵 Script added → npm/yarn/pnpm run tea${T.reset}`);
|
|
@@ -69,9 +59,7 @@ function injectScript() {
|
|
|
69
59
|
}
|
|
70
60
|
injectScript();
|
|
71
61
|
|
|
72
|
-
|
|
73
|
-
🔍 FIND STRICT DRIZZLE CONFIGS
|
|
74
|
-
============================================================= */
|
|
62
|
+
// ---------------------- STRICT CONFIG DETECTION ----------------------
|
|
75
63
|
function findDrizzleConfig(root){
|
|
76
64
|
const allowed = [
|
|
77
65
|
"drizzle.config.js",
|
|
@@ -80,74 +68,71 @@ function findDrizzleConfig(root){
|
|
|
80
68
|
"drizzle.config.cjs"
|
|
81
69
|
];
|
|
82
70
|
const files = [];
|
|
83
|
-
|
|
84
71
|
function walk(dir){
|
|
85
72
|
fs.readdirSync(dir,{withFileTypes:true}).forEach(file=>{
|
|
86
73
|
const full = path.join(dir,file.name);
|
|
87
|
-
if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name))
|
|
88
|
-
|
|
89
|
-
} else if(file.isFile() && allowed.includes(file.name)) {
|
|
90
|
-
files.push(full);
|
|
91
|
-
}
|
|
74
|
+
if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) walk(full);
|
|
75
|
+
else if(file.isFile() && allowed.includes(file.name)) files.push(full);
|
|
92
76
|
});
|
|
93
77
|
}
|
|
94
|
-
|
|
95
78
|
walk(root);
|
|
96
79
|
return files;
|
|
97
80
|
}
|
|
98
81
|
|
|
99
|
-
|
|
100
|
-
🔹 VALIDATE SCHEMA
|
|
101
|
-
============================================================= */
|
|
82
|
+
// ---------------------- VALIDATE SCHEMA ----------------------
|
|
102
83
|
function validateSchema(){
|
|
103
|
-
const
|
|
104
|
-
const configs = findDrizzleConfig(root);
|
|
105
|
-
|
|
84
|
+
const configs = findDrizzleConfig(process.cwd());
|
|
106
85
|
if(configs.length === 0)
|
|
107
|
-
return { ok:false, msg:"Missing
|
|
86
|
+
return { ok:false, msg:"Missing strict drizzle.config.js / ts / mjs / cjs" };
|
|
108
87
|
|
|
109
88
|
for(const cfg of configs){
|
|
110
89
|
try {
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
90
|
+
let schemaPath;
|
|
91
|
+
const mod = require(cfg);
|
|
92
|
+
schemaPath = mod.default?.schema || mod.schema;
|
|
93
|
+
|
|
94
|
+
if(!schemaPath) continue;
|
|
95
|
+
|
|
96
|
+
const schemaFull = path.resolve(path.dirname(cfg), schemaPath);
|
|
97
|
+
if(!fs.existsSync(schemaFull))
|
|
98
|
+
return { ok:false, msg:`Schema not found: ${schemaPath} in ${cfg}` };
|
|
99
|
+
|
|
118
100
|
} catch(e){
|
|
119
|
-
return { ok:false, msg:`Config parse error in ${cfg}` };
|
|
101
|
+
return { ok:false, msg:`Config parse error in ${cfg}: ${e.message}` };
|
|
120
102
|
}
|
|
121
103
|
}
|
|
122
104
|
|
|
123
105
|
return { ok:true, config:configs };
|
|
124
106
|
}
|
|
125
107
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
});
|
|
135
122
|
});
|
|
136
123
|
}
|
|
137
124
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
let running=false;
|
|
142
|
-
async function triggerEngine(event){
|
|
125
|
+
// ---------------------- ENGINE ----------------------
|
|
126
|
+
let running = false;
|
|
127
|
+
async function triggerEngine(){
|
|
143
128
|
if(running) return;
|
|
144
|
-
running=true;
|
|
129
|
+
running = true;
|
|
145
130
|
|
|
146
131
|
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;
|
|
132
|
+
if(!audit.ok){
|
|
133
|
+
console.log(`${T.red}${T.bold}👾 CRITICAL FAILURE:${T.reset} ${audit.msg}`);
|
|
134
|
+
running = false;
|
|
135
|
+
return;
|
|
151
136
|
}
|
|
152
137
|
|
|
153
138
|
const steps = [
|
|
@@ -156,47 +141,45 @@ async function triggerEngine(event){
|
|
|
156
141
|
{name:"Push Database", cmd:"drizzle-kit push"}
|
|
157
142
|
];
|
|
158
143
|
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
console.log(`\n${T.red}${T.bold}👾 FAILED AT [${step.name.toUpperCase()}]${T.reset}`);
|
|
163
|
-
running=false; return;
|
|
144
|
+
try {
|
|
145
|
+
for(const step of steps){
|
|
146
|
+
await runCommand(step.cmd, step.name);
|
|
164
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}`);
|
|
165
151
|
}
|
|
166
152
|
|
|
167
|
-
|
|
168
|
-
console.log(`${T.gray}Waiting for changes...${T.reset}\n`);
|
|
169
|
-
running=false;
|
|
153
|
+
running = false;
|
|
170
154
|
}
|
|
171
155
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
156
|
+
// ---------------------- WATCHER ----------------------
|
|
157
|
+
const skipWatcher = process.argv.includes('--postinstall');
|
|
158
|
+
|
|
159
|
+
if(!skipWatcher){
|
|
160
|
+
const configsExist = findDrizzleConfig(process.cwd()).length > 0;
|
|
161
|
+
if(configsExist){
|
|
162
|
+
triggerEngine();
|
|
163
|
+
|
|
164
|
+
const chokidar = require("chokidar");
|
|
165
|
+
chokidar.watch(".",{
|
|
166
|
+
ignored:[/node_modules/,/\.git/,/\.next|dist/],
|
|
167
|
+
ignoreInitial:true,
|
|
168
|
+
usePolling:true,
|
|
169
|
+
interval:300
|
|
170
|
+
}).on("all", (e,f) => triggerEngine());
|
|
171
|
+
} else {
|
|
172
|
+
console.log(`${T.yellow}⚠ No strict drizzle.config found. Watcher disabled.${T.reset}`);
|
|
173
|
+
}
|
|
187
174
|
}
|
|
188
175
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
stopLoading();
|
|
194
|
-
console.log(`\n${T.red}${T.bold}🛡️ ERROR:${T.reset} ${err.message}`);
|
|
195
|
-
running=false;
|
|
176
|
+
// ---------------------- GLOBAL ERROR HANDLING ----------------------
|
|
177
|
+
process.on("uncaughtException", err=>{
|
|
178
|
+
console.log(`${T.red}${T.bold}🛡️ ERROR:${T.reset} ${err.message}`);
|
|
179
|
+
running = false;
|
|
196
180
|
});
|
|
197
181
|
|
|
198
|
-
process.on("SIGINT",()=>{
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
process.exit();
|
|
182
|
+
process.on("SIGINT", ()=>{
|
|
183
|
+
console.log(`${T.yellow}Shutting down Drizzle-Auto...${T.reset}`);
|
|
184
|
+
process.exit(0);
|
|
202
185
|
});
|