drizzle-auto 1.1.19 → 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 -20
- 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,28 +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
64
|
if (!pkg.scripts.tea) {
|
|
66
65
|
pkg.scripts.tea = "drizzle-auto";
|
|
67
66
|
console.log(`${T.lime}🍵 Script added → npm/yarn/pnpm run tea${T.reset}`);
|
|
67
|
+
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
71
69
|
}
|
|
72
70
|
injectScript();
|
|
73
71
|
|
|
74
72
|
/* =============================================================
|
|
75
|
-
🔍 FIND DRIZZLE CONFIGS
|
|
73
|
+
🔍 FIND STRICT DRIZZLE CONFIGS
|
|
76
74
|
============================================================= */
|
|
77
75
|
function findDrizzleConfig(root){
|
|
78
|
-
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
|
+
|
|
79
84
|
function walk(dir){
|
|
80
85
|
fs.readdirSync(dir,{withFileTypes:true}).forEach(file=>{
|
|
81
86
|
const full = path.join(dir,file.name);
|
|
82
|
-
if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name))
|
|
83
|
-
|
|
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
|
+
}
|
|
84
92
|
});
|
|
85
93
|
}
|
|
94
|
+
|
|
86
95
|
walk(root);
|
|
87
96
|
return files;
|
|
88
97
|
}
|
|
@@ -91,30 +100,36 @@ function findDrizzleConfig(root){
|
|
|
91
100
|
🔹 VALIDATE SCHEMA
|
|
92
101
|
============================================================= */
|
|
93
102
|
function validateSchema(){
|
|
94
|
-
const root=process.cwd();
|
|
95
|
-
const configs=findDrizzleConfig(root);
|
|
96
|
-
|
|
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" };
|
|
97
108
|
|
|
98
109
|
for(const cfg of configs){
|
|
99
|
-
try{
|
|
110
|
+
try {
|
|
100
111
|
const content = fs.readFileSync(cfg,"utf8");
|
|
101
112
|
const match = content.match(/schema:\s*["'](.+?)["']/);
|
|
102
113
|
if(match && match[1]){
|
|
103
114
|
const schemaFull = path.resolve(path.dirname(cfg), match[1]);
|
|
104
|
-
if(!fs.existsSync(schemaFull))
|
|
115
|
+
if(!fs.existsSync(schemaFull))
|
|
116
|
+
return { ok:false, msg:`Schema not found: ${match[1]} in ${cfg}` };
|
|
105
117
|
}
|
|
106
|
-
}catch(e){
|
|
118
|
+
} catch(e){
|
|
119
|
+
return { ok:false, msg:`Config parse error in ${cfg}` };
|
|
120
|
+
}
|
|
107
121
|
}
|
|
108
|
-
|
|
122
|
+
|
|
123
|
+
return { ok:true, config:configs };
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
/* =============================================================
|
|
112
|
-
⚙️ SERVER-STYLE RUNNER
|
|
127
|
+
⚙️ SERVER-STYLE RUNNER
|
|
113
128
|
============================================================= */
|
|
114
129
|
function runCommandServerStyle(cmd,label){
|
|
115
130
|
return new Promise(resolve=>{
|
|
116
131
|
startLoading(`${T.pink}${label}${T.reset}`);
|
|
117
|
-
const child = spawn(cmd,{shell:true,stdio:"inherit"});
|
|
132
|
+
const child = spawn(cmd,{shell:true,stdio:"inherit"});
|
|
118
133
|
child.on("close",code=>{ stopLoading(); resolve(code===0); });
|
|
119
134
|
child.on("error",err=>{ stopLoading(); console.log(`${T.red}✖ ${label} Error: ${err.message}${T.reset}`); resolve(false); });
|
|
120
135
|
});
|
|
@@ -129,7 +144,11 @@ async function triggerEngine(event){
|
|
|
129
144
|
running=true;
|
|
130
145
|
|
|
131
146
|
const audit = validateSchema();
|
|
132
|
-
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
|
+
}
|
|
133
152
|
|
|
134
153
|
const steps = [
|
|
135
154
|
{name:"Integrity Check", cmd:"drizzle-kit check"},
|
|
@@ -160,7 +179,12 @@ chokidar.watch(".",{
|
|
|
160
179
|
interval:300
|
|
161
180
|
}).on("all",(e,f)=>triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
|
|
162
181
|
|
|
163
|
-
|
|
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
|
+
}
|
|
164
188
|
|
|
165
189
|
/* =============================================================
|
|
166
190
|
🚨 GLOBAL ERROR HANDLING
|