drizzle-auto 1.0.11 → 1.0.12
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 +106 -122
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -5,150 +5,134 @@ const path = require("path");
|
|
|
5
5
|
const chokidar = require("chokidar");
|
|
6
6
|
const { spawn } = require("child_process");
|
|
7
7
|
|
|
8
|
-
/*
|
|
8
|
+
/* ======================
|
|
9
|
+
🌈 NEON CORE
|
|
10
|
+
====================== */
|
|
9
11
|
const COLORS = ["\x1b[31m","\x1b[32m","\x1b[33m","\x1b[34m","\x1b[35m","\x1b[36m"];
|
|
10
12
|
const RESET = "\x1b[0m";
|
|
11
13
|
const DIM = "\x1b[90m";
|
|
12
|
-
let
|
|
13
|
-
const
|
|
14
|
+
let c = 0;
|
|
15
|
+
const color = () => COLORS[c++ % COLORS.length];
|
|
16
|
+
const rainbow = t => t.split("").map(x => color()+x).join("")+RESET;
|
|
14
17
|
|
|
15
|
-
/*
|
|
18
|
+
/* ======================
|
|
19
|
+
⏳ SPINNER
|
|
20
|
+
====================== */
|
|
16
21
|
const FRAMES = ["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
let i=0, spin;
|
|
23
|
+
const start = txt => {
|
|
24
|
+
stop();
|
|
25
|
+
spin = setInterval(()=>{
|
|
26
|
+
process.stdout.write(`\r${color()}${FRAMES[i++%FRAMES.length]} ${txt}${RESET}`);
|
|
27
|
+
},80);
|
|
28
|
+
};
|
|
29
|
+
const stop = ()=>{ if(spin){ clearInterval(spin); spin=null; process.stdout.write("\r\x1b[K"); }};
|
|
30
|
+
|
|
31
|
+
/* ======================
|
|
32
|
+
📦 ROOT + SCRIPT INJECT
|
|
33
|
+
====================== */
|
|
34
|
+
const ROOT = process.env.INIT_CWD || process.cwd();
|
|
35
|
+
const PKG = path.join(ROOT,"package.json");
|
|
36
|
+
|
|
37
|
+
function injectTea(){
|
|
38
|
+
if(!fs.existsSync(PKG)) return;
|
|
39
|
+
const pkg = JSON.parse(fs.readFileSync(PKG,"utf8"));
|
|
40
|
+
pkg.scripts ||= {};
|
|
41
|
+
if(!pkg.scripts.tea){
|
|
42
|
+
pkg.scripts.tea = "drizzle-auto";
|
|
43
|
+
fs.writeFileSync(PKG, JSON.stringify(pkg,null,2));
|
|
44
|
+
console.log(color()+"⚡ script added → npm run tea"+RESET);
|
|
32
45
|
}
|
|
33
46
|
}
|
|
34
47
|
|
|
35
|
-
/*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const pkg = JSON.parse(fs.readFileSync(PKG_PATH, "utf8"));
|
|
43
|
-
pkg.scripts = pkg.scripts || {};
|
|
44
|
-
|
|
45
|
-
// ফিক্স: সরাসরি node index.js চালানো নিশ্চিত করা
|
|
46
|
-
if (!pkg.scripts.tea) {
|
|
47
|
-
pkg.scripts.tea = "node index.js";
|
|
48
|
-
fs.writeFileSync(PKG_PATH, JSON.stringify(pkg, null, 2));
|
|
49
|
-
console.log(`\x1b[32m⚡ tea script added → npm run tea\x1b[0m`);
|
|
50
|
-
}
|
|
51
|
-
} catch (e) {
|
|
52
|
-
console.error("❌ Could not update package.json");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
48
|
+
/* ======================
|
|
49
|
+
🧠 DRIZZLE SCAN
|
|
50
|
+
====================== */
|
|
51
|
+
function audit(){
|
|
52
|
+
const exts = ["js","ts","mjs","mts"];
|
|
53
|
+
const cfg = exts.map(e=>`drizzle.config.${e}`)
|
|
54
|
+
.find(f=>fs.existsSync(path.join(ROOT,f)));
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
function auditInfra() {
|
|
58
|
-
const results = [];
|
|
59
|
-
const configFile = ["ts","js","mjs","mts"].map(ext => `drizzle.config.${ext}`)
|
|
60
|
-
.find(f => fs.existsSync(path.join(PROJECT_ROOT, f)));
|
|
61
|
-
|
|
62
|
-
results.push({ name: "Drizzle Config", ok: !!configFile });
|
|
63
|
-
results.push({ name: ".env", ok: fs.existsSync(path.join(PROJECT_ROOT, ".env")) });
|
|
64
|
-
results.push({ name: "node_modules", ok: fs.existsSync(path.join(PROJECT_ROOT, "node_modules")) });
|
|
65
|
-
|
|
66
|
-
const missing = results.filter(r => !r.ok).map(r => r.name);
|
|
67
|
-
return { ok: missing.length === 0, missing };
|
|
68
|
-
}
|
|
56
|
+
if(!cfg) return fail("Drizzle config not found");
|
|
69
57
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return
|
|
73
|
-
let failed = false;
|
|
74
|
-
startSpinner(`npx ${cmd.join(" ")}`);
|
|
75
|
-
const p = spawn("npx", cmd, { shell: true, cwd: PROJECT_ROOT });
|
|
76
|
-
|
|
77
|
-
p.stdout.on("data", d => {
|
|
78
|
-
stopSpinner();
|
|
79
|
-
process.stdout.write(DIM + d.toString() + RESET);
|
|
80
|
-
if (/error|failed/i.test(d)) failed = true;
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
p.stderr.on("data", d => {
|
|
84
|
-
stopSpinner();
|
|
85
|
-
process.stderr.write("\x1b[31m" + d + RESET);
|
|
86
|
-
failed = true;
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
p.on("close", code => resolve(code === 0 && !failed));
|
|
90
|
-
});
|
|
91
|
-
}
|
|
58
|
+
const txt = fs.readFileSync(path.join(ROOT,cfg),"utf8");
|
|
59
|
+
const m = txt.match(/schema:\s*["'](.+?)["']/);
|
|
60
|
+
if(!m) return fail("Schema path missing");
|
|
92
61
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
let hasError = false;
|
|
62
|
+
if(!fs.existsSync(path.join(ROOT,m[1])))
|
|
63
|
+
return fail(`Schema not found → ${m[1]}`);
|
|
96
64
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
running = true;
|
|
65
|
+
if(!fs.existsSync(path.join(ROOT,".env")))
|
|
66
|
+
return fail(".env missing");
|
|
100
67
|
|
|
101
|
-
if
|
|
102
|
-
|
|
68
|
+
if(!fs.existsSync(path.join(ROOT,"node_modules")))
|
|
69
|
+
return fail("node_modules missing");
|
|
70
|
+
|
|
71
|
+
return { ok:true };
|
|
72
|
+
}
|
|
103
73
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
74
|
+
const fail = m => ({ ok:false, msg:m });
|
|
75
|
+
|
|
76
|
+
/* ======================
|
|
77
|
+
⚙️ RUNNER
|
|
78
|
+
====================== */
|
|
79
|
+
const run = cmd => new Promise(res=>{
|
|
80
|
+
start("npx "+cmd.join(" "));
|
|
81
|
+
const p = spawn("npx", cmd, { stdio:"inherit", shell:true });
|
|
82
|
+
p.on("close", code=>{
|
|
83
|
+
stop();
|
|
84
|
+
res(code===0);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
/* ======================
|
|
89
|
+
🚀 PIPELINE
|
|
90
|
+
====================== */
|
|
91
|
+
let busy=false;
|
|
92
|
+
async function pipeline(trigger){
|
|
93
|
+
if(busy) return;
|
|
94
|
+
busy=true;
|
|
95
|
+
|
|
96
|
+
console.clear();
|
|
97
|
+
console.log(rainbow("🔥 DrizzlePulse — Server Start"));
|
|
98
|
+
console.log(DIM+"Trigger → "+trigger+RESET+"\n");
|
|
99
|
+
|
|
100
|
+
const a = audit();
|
|
101
|
+
if(!a.ok){
|
|
102
|
+
console.log("\x1b[31m❌ "+a.msg+RESET);
|
|
103
|
+
busy=false;
|
|
110
104
|
return;
|
|
111
105
|
}
|
|
112
106
|
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
for (const step of steps) {
|
|
119
|
-
if (!(await runCmd(step))) {
|
|
120
|
-
console.log("\n\x1b[31m💀 Pipeline crashed\x1b[0m");
|
|
121
|
-
hasError = true;
|
|
122
|
-
running = false;
|
|
107
|
+
for(const step of [["drizzle-kit","generate"],["drizzle-kit","push"]]){
|
|
108
|
+
if(!(await run(step))){
|
|
109
|
+
console.log("\n\x1b[31m💀 Pipeline crashed"+RESET);
|
|
110
|
+
busy=false;
|
|
123
111
|
return;
|
|
124
112
|
}
|
|
125
113
|
}
|
|
126
114
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
setTimeout(() => { running = false; }, 1000);
|
|
115
|
+
console.log("\n\x1b[32m✨ Drizzle synced successfully"+RESET);
|
|
116
|
+
busy=false;
|
|
130
117
|
}
|
|
131
118
|
|
|
132
|
-
/*
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
119
|
+
/* ======================
|
|
120
|
+
👀 WATCH MODE (SERVER)
|
|
121
|
+
====================== */
|
|
122
|
+
injectTea();
|
|
123
|
+
pipeline("initial");
|
|
124
|
+
|
|
125
|
+
chokidar.watch(ROOT,{
|
|
126
|
+
ignored:[/node_modules/,/\.git/,/\.next/,/dist/],
|
|
127
|
+
ignoreInitial:true,
|
|
128
|
+
usePolling:true,
|
|
129
|
+
interval:300
|
|
130
|
+
}).on("all",(e,f)=>{
|
|
131
|
+
if(f) pipeline(`${e.toUpperCase()} → ${path.basename(f)}`);
|
|
138
132
|
});
|
|
139
133
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
/* ======================= 🚀 Init ======================= */
|
|
147
|
-
addTeaScript();
|
|
148
|
-
workflow("Initial Audit");
|
|
149
|
-
|
|
150
|
-
process.on("uncaughtException", err => {
|
|
151
|
-
stopSpinner();
|
|
152
|
-
console.log("\x1b[31m🔥 Crash:\x1b[0m", err.message);
|
|
153
|
-
running = false;
|
|
154
|
-
});
|
|
134
|
+
process.on("uncaughtException",e=>{
|
|
135
|
+
stop();
|
|
136
|
+
console.log("\x1b[31m🔥 Crash:",e.message,RESET);
|
|
137
|
+
busy=false;
|
|
138
|
+
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-auto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"bin": {
|
|
5
5
|
"drizzle-auto": "index.js"
|
|
6
6
|
},
|
|
7
7
|
"scripts": {
|
|
8
|
-
"postinstall": "node index.js --postinstall"
|
|
8
|
+
"postinstall": "node index.js --postinstall",
|
|
9
|
+
"tea": "node index.js"
|
|
9
10
|
},
|
|
10
11
|
"dependencies": {
|
|
11
12
|
"chokidar": "^5.0.0",
|