drizzle-auto 1.1.16 → 1.1.18
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 +88 -105
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* 🌟 Drizzle-Auto v2 - Server Style / Multi-Package Manager
|
|
5
|
+
* 🔹 Watches your project and auto-runs drizzle-kit steps
|
|
6
|
+
* 🔹 Works with npm, yarn, pnpm, bun, npx
|
|
7
|
+
* 🔹 Fully server-style logging
|
|
8
|
+
* 🔹 Neon-pulse colored UI with emojis
|
|
9
|
+
*/
|
|
10
|
+
|
|
3
11
|
const chokidar = require("chokidar");
|
|
4
12
|
const { spawn } = require("child_process");
|
|
5
13
|
const path = require("path");
|
|
6
14
|
const fs = require("fs");
|
|
7
15
|
|
|
8
16
|
/* =============================================================
|
|
9
|
-
🎨 NEON-PULSE UI
|
|
17
|
+
🎨 NEON-PULSE UI COLORS
|
|
10
18
|
============================================================= */
|
|
11
19
|
const T = {
|
|
12
20
|
reset: "\x1b[0m",
|
|
@@ -24,24 +32,23 @@ const T = {
|
|
|
24
32
|
};
|
|
25
33
|
|
|
26
34
|
/* =============================================================
|
|
27
|
-
⏳ SPINNER
|
|
35
|
+
⏳ SPINNER
|
|
28
36
|
============================================================= */
|
|
29
37
|
const frames = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
|
|
30
|
-
let spinIdx = 0;
|
|
31
|
-
let spinInterval;
|
|
38
|
+
let spinIdx = 0, spinInterval;
|
|
32
39
|
|
|
33
|
-
function startLoading(msg)
|
|
40
|
+
function startLoading(msg){
|
|
34
41
|
stopLoading();
|
|
35
|
-
spinInterval = setInterval(()
|
|
42
|
+
spinInterval = setInterval(()=>{
|
|
36
43
|
process.stdout.write(`\r${T.cyan}${frames[spinIdx++ % frames.length]}${T.reset} ${T.bold}${msg}${T.reset} `);
|
|
37
44
|
}, 80);
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
function stopLoading()
|
|
41
|
-
if
|
|
47
|
+
function stopLoading(){
|
|
48
|
+
if(spinInterval){
|
|
42
49
|
clearInterval(spinInterval);
|
|
43
|
-
spinInterval
|
|
44
|
-
process.stdout.write("\r\x1b[K");
|
|
50
|
+
spinInterval=null;
|
|
51
|
+
process.stdout.write("\r\x1b[K");
|
|
45
52
|
}
|
|
46
53
|
}
|
|
47
54
|
|
|
@@ -53,146 +60,122 @@ function injectScript() {
|
|
|
53
60
|
if (!fs.existsSync(PKG)) return;
|
|
54
61
|
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
55
62
|
pkg.scripts ||= {};
|
|
63
|
+
|
|
64
|
+
// Add both scripts if missing
|
|
65
|
+
if (!pkg.scripts.drizzle) {
|
|
66
|
+
pkg.scripts.drizzle = "drizzle-auto";
|
|
67
|
+
console.log(`${T.lime}☕ Script added → npm/yarn/pnpm run drizzle${T.reset}`);
|
|
68
|
+
}
|
|
56
69
|
if (!pkg.scripts.tea) {
|
|
57
70
|
pkg.scripts.tea = "drizzle-auto";
|
|
58
|
-
|
|
59
|
-
console.log(`${T.lime}☕ Script added → npm run tea${T.reset}`);
|
|
71
|
+
console.log(`${T.lime}🍵 Script added → npm/yarn/pnpm run tea${T.reset}`);
|
|
60
72
|
}
|
|
73
|
+
|
|
74
|
+
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
61
75
|
}
|
|
62
76
|
injectScript();
|
|
63
77
|
|
|
64
78
|
/* =============================================================
|
|
65
|
-
🔍
|
|
79
|
+
🔍 FIND DRIZZLE CONFIGS
|
|
66
80
|
============================================================= */
|
|
67
|
-
function findDrizzleConfig(root)
|
|
68
|
-
const exts
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) {
|
|
75
|
-
walk(full);
|
|
76
|
-
} else if (file.isFile() && exts.some(ext => file.name === `drizzle.config.${ext}`)) {
|
|
77
|
-
files.push(full);
|
|
78
|
-
}
|
|
81
|
+
function findDrizzleConfig(root){
|
|
82
|
+
const exts=["js","ts","cjs","mjs","mts"], files=[];
|
|
83
|
+
function walk(dir){
|
|
84
|
+
fs.readdirSync(dir,{withFileTypes:true}).forEach(file=>{
|
|
85
|
+
const full = path.join(dir,file.name);
|
|
86
|
+
if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) walk(full);
|
|
87
|
+
else if(file.isFile() && exts.some(ext=>file.name===`drizzle.config.${ext}`)) files.push(full);
|
|
79
88
|
});
|
|
80
89
|
}
|
|
81
|
-
|
|
82
90
|
walk(root);
|
|
83
91
|
return files;
|
|
84
92
|
}
|
|
85
93
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
94
|
+
/* =============================================================
|
|
95
|
+
🔹 VALIDATE SCHEMA
|
|
96
|
+
============================================================= */
|
|
97
|
+
function validateSchema(){
|
|
98
|
+
const root=process.cwd();
|
|
99
|
+
const configs=findDrizzleConfig(root);
|
|
100
|
+
if(configs.length===0) return {ok:false,msg:"Missing drizzle.config.*"};
|
|
101
|
+
|
|
102
|
+
for(const cfg of configs){
|
|
103
|
+
try{
|
|
104
|
+
const content = fs.readFileSync(cfg,"utf8");
|
|
105
|
+
const match = content.match(/schema:\s*["'](.+?)["']/);
|
|
106
|
+
if(match && match[1]){
|
|
107
|
+
const schemaFull = path.resolve(path.dirname(cfg), match[1]);
|
|
108
|
+
if(!fs.existsSync(schemaFull)) return {ok:false,msg:`Schema not found: ${match[1]} in ${cfg}`};
|
|
100
109
|
}
|
|
101
|
-
}
|
|
102
|
-
return { ok: false, msg: `Config parse error in ${configPath}` };
|
|
103
|
-
}
|
|
110
|
+
}catch(e){ return {ok:false,msg:`Config parse error in ${cfg}`}; }
|
|
104
111
|
}
|
|
105
|
-
|
|
106
|
-
return { ok: true, config: configs };
|
|
112
|
+
return {ok:true,config:configs};
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
/* =============================================================
|
|
110
|
-
⚙️
|
|
116
|
+
⚙️ SERVER-STYLE RUNNER (WORKS WITH ANY PM)
|
|
111
117
|
============================================================= */
|
|
112
|
-
function
|
|
113
|
-
return new Promise(
|
|
118
|
+
function runCommandServerStyle(cmd,label){
|
|
119
|
+
return new Promise(resolve=>{
|
|
114
120
|
startLoading(`${T.pink}${label}${T.reset}`);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
child.stdout.on("data", (data) => {
|
|
120
|
-
const out = data.toString();
|
|
121
|
-
if (!out.includes('Pulling schema')) {
|
|
122
|
-
stopLoading();
|
|
123
|
-
process.stdout.write(`${T.gray}${out}${T.reset}`);
|
|
124
|
-
}
|
|
125
|
-
if (/error|failed|ENOTFOUND/i.test(out)) localErr = true;
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
child.stderr.on("data", (data) => {
|
|
129
|
-
stopLoading();
|
|
130
|
-
process.stderr.write(`${T.red}${T.bold}✖ ${data}${T.reset}`);
|
|
131
|
-
localErr = true;
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
child.on("close", (code) => {
|
|
135
|
-
stopLoading();
|
|
136
|
-
resolve(code === 0 && !localErr);
|
|
137
|
-
});
|
|
121
|
+
const child = spawn(cmd,{shell:true,stdio:"inherit"}); // Server-style
|
|
122
|
+
child.on("close",code=>{ stopLoading(); resolve(code===0); });
|
|
123
|
+
child.on("error",err=>{ stopLoading(); console.log(`${T.red}✖ ${label} Error: ${err.message}${T.reset}`); resolve(false); });
|
|
138
124
|
});
|
|
139
125
|
}
|
|
140
126
|
|
|
141
127
|
/* =============================================================
|
|
142
128
|
🔁 ENGINE WORKFLOW
|
|
143
129
|
============================================================= */
|
|
144
|
-
let
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (isRunning) return;
|
|
149
|
-
isRunning = true;
|
|
130
|
+
let running=false;
|
|
131
|
+
async function triggerEngine(event){
|
|
132
|
+
if(running) return;
|
|
133
|
+
running=true;
|
|
150
134
|
|
|
151
|
-
const audit =
|
|
152
|
-
if
|
|
153
|
-
console.log(`${T.red}${T.bold}👾 CRITICAL FAILURE:${T.reset} ${audit.msg}`);
|
|
154
|
-
hasError = true; isRunning = false; return;
|
|
155
|
-
}
|
|
135
|
+
const audit = validateSchema();
|
|
136
|
+
if(!audit.ok){ console.log(`${T.red}${T.bold}👾 CRITICAL FAILURE:${T.reset} ${audit.msg}`); running=false; return; }
|
|
156
137
|
|
|
157
138
|
const steps = [
|
|
158
|
-
{
|
|
159
|
-
{
|
|
160
|
-
{
|
|
139
|
+
{name:"Integrity Check", cmd:"drizzle-kit check"},
|
|
140
|
+
{name:"Generate Migration", cmd:"drizzle-kit generate"},
|
|
141
|
+
{name:"Push Database", cmd:"drizzle-kit push"}
|
|
161
142
|
];
|
|
162
143
|
|
|
163
|
-
for
|
|
164
|
-
const success = await
|
|
165
|
-
if
|
|
166
|
-
console.log(`\n${T.red}${T.bold}👾
|
|
167
|
-
|
|
144
|
+
for(const step of steps){
|
|
145
|
+
const success = await runCommandServerStyle(step.cmd,step.name);
|
|
146
|
+
if(!success){
|
|
147
|
+
console.log(`\n${T.red}${T.bold}👾 FAILED AT [${step.name.toUpperCase()}]${T.reset}`);
|
|
148
|
+
running=false; return;
|
|
168
149
|
}
|
|
169
150
|
}
|
|
170
151
|
|
|
171
|
-
|
|
172
|
-
console.log(
|
|
173
|
-
|
|
174
|
-
isRunning = false;
|
|
152
|
+
console.log(`\n${T.lime}${T.bold}🎉 All steps successful!${T.reset}`);
|
|
153
|
+
console.log(`${T.gray}Waiting for changes...${T.reset}\n`);
|
|
154
|
+
running=false;
|
|
175
155
|
}
|
|
176
156
|
|
|
177
157
|
/* =============================================================
|
|
178
|
-
👀 WATCHER
|
|
158
|
+
👀 WATCHER
|
|
179
159
|
============================================================= */
|
|
180
|
-
chokidar.watch(".",
|
|
181
|
-
ignored:
|
|
182
|
-
ignoreInitial:
|
|
183
|
-
usePolling:
|
|
184
|
-
interval:
|
|
185
|
-
}).on("all",
|
|
160
|
+
chokidar.watch(".",{
|
|
161
|
+
ignored:[/node_modules/,/\.git/,/\.next/,/dist/],
|
|
162
|
+
ignoreInitial:true,
|
|
163
|
+
usePolling:true,
|
|
164
|
+
interval:300
|
|
165
|
+
}).on("all",(e,f)=>triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
|
|
186
166
|
|
|
187
167
|
triggerEngine("Initial Audit");
|
|
188
168
|
|
|
189
|
-
|
|
169
|
+
/* =============================================================
|
|
170
|
+
🚨 GLOBAL ERROR HANDLING
|
|
171
|
+
============================================================= */
|
|
172
|
+
process.on("uncaughtException",err=>{
|
|
190
173
|
stopLoading();
|
|
191
|
-
console.log(`\n${T.red}${T.bold}🛡️
|
|
192
|
-
|
|
174
|
+
console.log(`\n${T.red}${T.bold}🛡️ ERROR:${T.reset} ${err.message}`);
|
|
175
|
+
running=false;
|
|
193
176
|
});
|
|
194
177
|
|
|
195
|
-
process.on("SIGINT",
|
|
178
|
+
process.on("SIGINT",()=>{
|
|
196
179
|
stopLoading();
|
|
197
180
|
console.log(`\n${T.yellow}Shutting down Drizzle-Auto...${T.reset}`);
|
|
198
181
|
process.exit();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-auto",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "pavel ahmmed hridoy",
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"postinstall": "node index.js --postinstall",
|
|
14
|
-
"tea": "node index.js"
|
|
14
|
+
"tea": "node index.js",
|
|
15
|
+
"drizzle": "drizzle-auto"
|
|
15
16
|
},
|
|
16
17
|
"dependencies": {
|
|
17
18
|
"chokidar": "^5.0.0",
|
|
18
19
|
"cross-spawn": "^7.0.6"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {}
|
|
21
|
-
}
|
|
22
|
+
}
|