drizzle-auto 1.1.18 → 1.1.20
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 +44 -24
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* 🌟 Drizzle-Auto v2 -
|
|
4
|
+
* 🌟 Drizzle-Auto v2 - Strict Config Edition
|
|
5
5
|
* 🔹 Watches your project and auto-runs drizzle-kit steps
|
|
6
|
-
* 🔹
|
|
6
|
+
* 🔹 Accepts only: drizzle.config.js / ts / mjs / cjs
|
|
7
7
|
* 🔹 Fully server-style logging
|
|
8
8
|
* 🔹 Neon-pulse colored UI with emojis
|
|
9
9
|
*/
|
|
@@ -61,32 +61,37 @@ function injectScript() {
|
|
|
61
61
|
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
62
62
|
pkg.scripts ||= {};
|
|
63
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
|
-
}
|
|
69
64
|
if (!pkg.scripts.tea) {
|
|
70
65
|
pkg.scripts.tea = "drizzle-auto";
|
|
71
66
|
console.log(`${T.lime}🍵 Script added → npm/yarn/pnpm run tea${T.reset}`);
|
|
67
|
+
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
72
68
|
}
|
|
73
|
-
|
|
74
|
-
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
75
69
|
}
|
|
76
70
|
injectScript();
|
|
77
71
|
|
|
78
72
|
/* =============================================================
|
|
79
|
-
🔍 FIND DRIZZLE CONFIGS
|
|
73
|
+
🔍 FIND STRICT DRIZZLE CONFIGS
|
|
80
74
|
============================================================= */
|
|
81
75
|
function findDrizzleConfig(root){
|
|
82
|
-
const
|
|
76
|
+
const allowed = [
|
|
77
|
+
"drizzle.config.js",
|
|
78
|
+
"drizzle.config.ts",
|
|
79
|
+
"drizzle.config.mjs",
|
|
80
|
+
"drizzle.config.cjs"
|
|
81
|
+
];
|
|
82
|
+
const files = [];
|
|
83
|
+
|
|
83
84
|
function walk(dir){
|
|
84
85
|
fs.readdirSync(dir,{withFileTypes:true}).forEach(file=>{
|
|
85
86
|
const full = path.join(dir,file.name);
|
|
86
|
-
if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name))
|
|
87
|
-
|
|
87
|
+
if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) {
|
|
88
|
+
walk(full);
|
|
89
|
+
} else if(file.isFile() && allowed.includes(file.name)) {
|
|
90
|
+
files.push(full);
|
|
91
|
+
}
|
|
88
92
|
});
|
|
89
93
|
}
|
|
94
|
+
|
|
90
95
|
walk(root);
|
|
91
96
|
return files;
|
|
92
97
|
}
|
|
@@ -95,30 +100,36 @@ function findDrizzleConfig(root){
|
|
|
95
100
|
🔹 VALIDATE SCHEMA
|
|
96
101
|
============================================================= */
|
|
97
102
|
function validateSchema(){
|
|
98
|
-
const root=process.cwd();
|
|
99
|
-
const configs=findDrizzleConfig(root);
|
|
100
|
-
|
|
103
|
+
const root = process.cwd();
|
|
104
|
+
const configs = findDrizzleConfig(root);
|
|
105
|
+
|
|
106
|
+
if(configs.length === 0)
|
|
107
|
+
return { ok:false, msg:"Missing exact drizzle.config.js / ts / mjs / cjs" };
|
|
101
108
|
|
|
102
109
|
for(const cfg of configs){
|
|
103
|
-
try{
|
|
110
|
+
try {
|
|
104
111
|
const content = fs.readFileSync(cfg,"utf8");
|
|
105
112
|
const match = content.match(/schema:\s*["'](.+?)["']/);
|
|
106
113
|
if(match && match[1]){
|
|
107
114
|
const schemaFull = path.resolve(path.dirname(cfg), match[1]);
|
|
108
|
-
if(!fs.existsSync(schemaFull))
|
|
115
|
+
if(!fs.existsSync(schemaFull))
|
|
116
|
+
return { ok:false, msg:`Schema not found: ${match[1]} in ${cfg}` };
|
|
109
117
|
}
|
|
110
|
-
}catch(e){
|
|
118
|
+
} catch(e){
|
|
119
|
+
return { ok:false, msg:`Config parse error in ${cfg}` };
|
|
120
|
+
}
|
|
111
121
|
}
|
|
112
|
-
|
|
122
|
+
|
|
123
|
+
return { ok:true, config:configs };
|
|
113
124
|
}
|
|
114
125
|
|
|
115
126
|
/* =============================================================
|
|
116
|
-
⚙️ SERVER-STYLE RUNNER
|
|
127
|
+
⚙️ SERVER-STYLE RUNNER
|
|
117
128
|
============================================================= */
|
|
118
129
|
function runCommandServerStyle(cmd,label){
|
|
119
130
|
return new Promise(resolve=>{
|
|
120
131
|
startLoading(`${T.pink}${label}${T.reset}`);
|
|
121
|
-
const child = spawn(cmd,{shell:true,stdio:"inherit"});
|
|
132
|
+
const child = spawn(cmd,{shell:true,stdio:"inherit"});
|
|
122
133
|
child.on("close",code=>{ stopLoading(); resolve(code===0); });
|
|
123
134
|
child.on("error",err=>{ stopLoading(); console.log(`${T.red}✖ ${label} Error: ${err.message}${T.reset}`); resolve(false); });
|
|
124
135
|
});
|
|
@@ -133,7 +144,11 @@ async function triggerEngine(event){
|
|
|
133
144
|
running=true;
|
|
134
145
|
|
|
135
146
|
const audit = validateSchema();
|
|
136
|
-
if(!audit.ok){
|
|
147
|
+
if(!audit.ok){
|
|
148
|
+
console.log(`${T.red}${T.bold}👾 CRITICAL FAILURE:${T.reset} ${audit.msg}`);
|
|
149
|
+
running=false;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
137
152
|
|
|
138
153
|
const steps = [
|
|
139
154
|
{name:"Integrity Check", cmd:"drizzle-kit check"},
|
|
@@ -164,7 +179,12 @@ chokidar.watch(".",{
|
|
|
164
179
|
interval:300
|
|
165
180
|
}).on("all",(e,f)=>triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
|
|
166
181
|
|
|
167
|
-
|
|
182
|
+
// Only trigger if config exists
|
|
183
|
+
if(findDrizzleConfig(process.cwd()).length > 0){
|
|
184
|
+
triggerEngine("Initial Audit");
|
|
185
|
+
} else {
|
|
186
|
+
console.log(`${T.yellow}⚠ No strict drizzle.config found. Skipping initial audit.${T.reset}`);
|
|
187
|
+
}
|
|
168
188
|
|
|
169
189
|
/* =============================================================
|
|
170
190
|
🚨 GLOBAL ERROR HANDLING
|