drizzle-auto 1.1.19 β 1.1.22
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 +75 -76
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
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 - Postinstall Safe
|
|
5
|
+
* πΉ Injects "tea" script
|
|
6
|
+
* πΉ Detects strict config (.js/.ts/.mjs/.cjs)
|
|
7
|
+
* πΉ Wonβt run watcher/server during npm install
|
|
9
8
|
*/
|
|
10
9
|
|
|
11
10
|
const chokidar = require("chokidar");
|
|
@@ -13,27 +12,22 @@ const { spawn } = require("child_process");
|
|
|
13
12
|
const path = require("path");
|
|
14
13
|
const fs = require("fs");
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
// Optional: load ts-node if .ts config exists
|
|
16
|
+
try { require("ts-node").register({ transpileOnly: true }); } catch(e){}
|
|
17
|
+
|
|
18
|
+
// ---------------------- COLORS ----------------------
|
|
19
19
|
const T = {
|
|
20
20
|
reset: "\x1b[0m",
|
|
21
21
|
bold: "\x1b[1m",
|
|
22
|
-
italic: "\x1b[3m",
|
|
23
|
-
underline: "\x1b[4m",
|
|
24
22
|
cyan: "\x1b[38;5;51m",
|
|
25
23
|
pink: "\x1b[38;5;201m",
|
|
26
24
|
lime: "\x1b[38;5;118m",
|
|
27
25
|
yellow: "\x1b[38;5;226m",
|
|
28
26
|
red: "\x1b[38;5;196m",
|
|
29
27
|
gray: "\x1b[38;5;244m",
|
|
30
|
-
magenta: "\x1b[38;5;201m",
|
|
31
|
-
bg_dark: "\x1b[48;5;234m"
|
|
32
28
|
};
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
β³ SPINNER
|
|
36
|
-
============================================================= */
|
|
30
|
+
// ---------------------- SPINNER ----------------------
|
|
37
31
|
const frames = ["β ","β ","β Ή","β Έ","β Ό","β ΄","β ¦","β §","β ","β "];
|
|
38
32
|
let spinIdx = 0, spinInterval;
|
|
39
33
|
|
|
@@ -47,89 +41,83 @@ function startLoading(msg){
|
|
|
47
41
|
function stopLoading(){
|
|
48
42
|
if(spinInterval){
|
|
49
43
|
clearInterval(spinInterval);
|
|
50
|
-
spinInterval=null;
|
|
44
|
+
spinInterval = null;
|
|
51
45
|
process.stdout.write("\r\x1b[K");
|
|
52
46
|
}
|
|
53
47
|
}
|
|
54
48
|
|
|
55
|
-
|
|
56
|
-
π§© AUTO SCRIPT INJECTOR
|
|
57
|
-
============================================================= */
|
|
49
|
+
// ---------------------- AUTO SCRIPT INJECTOR ----------------------
|
|
58
50
|
const PKG = path.join(process.cwd(), "package.json");
|
|
59
51
|
function injectScript() {
|
|
60
52
|
if (!fs.existsSync(PKG)) return;
|
|
61
53
|
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
62
54
|
pkg.scripts ||= {};
|
|
63
|
-
|
|
64
|
-
// Add both scripts if missing
|
|
65
55
|
if (!pkg.scripts.tea) {
|
|
66
56
|
pkg.scripts.tea = "drizzle-auto";
|
|
67
57
|
console.log(`${T.lime}π΅ Script added β npm/yarn/pnpm run tea${T.reset}`);
|
|
58
|
+
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
68
59
|
}
|
|
69
|
-
|
|
70
|
-
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
71
60
|
}
|
|
72
61
|
injectScript();
|
|
73
62
|
|
|
74
|
-
|
|
75
|
-
π FIND DRIZZLE CONFIGS
|
|
76
|
-
============================================================= */
|
|
63
|
+
// ---------------------- STRICT CONFIG DETECTION ----------------------
|
|
77
64
|
function findDrizzleConfig(root){
|
|
78
|
-
const
|
|
65
|
+
const allowed = [
|
|
66
|
+
"drizzle.config.js",
|
|
67
|
+
"drizzle.config.ts",
|
|
68
|
+
"drizzle.config.mjs",
|
|
69
|
+
"drizzle.config.cjs"
|
|
70
|
+
];
|
|
71
|
+
const files = [];
|
|
79
72
|
function walk(dir){
|
|
80
73
|
fs.readdirSync(dir,{withFileTypes:true}).forEach(file=>{
|
|
81
74
|
const full = path.join(dir,file.name);
|
|
82
75
|
if(file.isDirectory() && !/node_modules|\.git|\.next|dist/.test(file.name)) walk(full);
|
|
83
|
-
else if(file.isFile() &&
|
|
76
|
+
else if(file.isFile() && allowed.includes(file.name)) files.push(full);
|
|
84
77
|
});
|
|
85
78
|
}
|
|
86
79
|
walk(root);
|
|
87
80
|
return files;
|
|
88
81
|
}
|
|
89
82
|
|
|
90
|
-
|
|
91
|
-
πΉ VALIDATE SCHEMA
|
|
92
|
-
============================================================= */
|
|
83
|
+
// ---------------------- VALIDATE SCHEMA ----------------------
|
|
93
84
|
function validateSchema(){
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
const configs = findDrizzleConfig(process.cwd());
|
|
86
|
+
if(configs.length === 0)
|
|
87
|
+
return { ok:false, msg:"Missing strict drizzle.config.js / ts / mjs / cjs" };
|
|
97
88
|
|
|
98
89
|
for(const cfg of configs){
|
|
99
|
-
try{
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
90
|
+
try {
|
|
91
|
+
let schemaPath;
|
|
92
|
+
const mod = require(cfg);
|
|
93
|
+
schemaPath = mod.default?.schema || mod.schema;
|
|
94
|
+
|
|
95
|
+
if(!schemaPath) continue;
|
|
96
|
+
|
|
97
|
+
const schemaFull = path.resolve(path.dirname(cfg), schemaPath);
|
|
98
|
+
if(!fs.existsSync(schemaFull))
|
|
99
|
+
return { ok:false, msg:`Schema not found: ${schemaPath} in ${cfg}` };
|
|
100
|
+
|
|
101
|
+
} catch(e){
|
|
102
|
+
return { ok:false, msg:`Config parse error in ${cfg}: ${e.message}` };
|
|
103
|
+
}
|
|
107
104
|
}
|
|
108
|
-
return {ok:true,config:configs};
|
|
109
|
-
}
|
|
110
105
|
|
|
111
|
-
|
|
112
|
-
βοΈ SERVER-STYLE RUNNER (WORKS WITH ANY PM)
|
|
113
|
-
============================================================= */
|
|
114
|
-
function runCommandServerStyle(cmd,label){
|
|
115
|
-
return new Promise(resolve=>{
|
|
116
|
-
startLoading(`${T.pink}${label}${T.reset}`);
|
|
117
|
-
const child = spawn(cmd,{shell:true,stdio:"inherit"}); // Server-style
|
|
118
|
-
child.on("close",code=>{ stopLoading(); resolve(code===0); });
|
|
119
|
-
child.on("error",err=>{ stopLoading(); console.log(`${T.red}β ${label} Error: ${err.message}${T.reset}`); resolve(false); });
|
|
120
|
-
});
|
|
106
|
+
return { ok:true, config:configs };
|
|
121
107
|
}
|
|
122
108
|
|
|
123
|
-
|
|
124
|
-
π ENGINE WORKFLOW
|
|
125
|
-
============================================================= */
|
|
109
|
+
// ---------------------- ENGINE ----------------------
|
|
126
110
|
let running=false;
|
|
127
111
|
async function triggerEngine(event){
|
|
128
112
|
if(running) return;
|
|
129
113
|
running=true;
|
|
130
114
|
|
|
131
115
|
const audit = validateSchema();
|
|
132
|
-
if(!audit.ok){
|
|
116
|
+
if(!audit.ok){
|
|
117
|
+
console.log(`${T.red}${T.bold}πΎ CRITICAL FAILURE:${T.reset} ${audit.msg}`);
|
|
118
|
+
running=false;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
133
121
|
|
|
134
122
|
const steps = [
|
|
135
123
|
{name:"Integrity Check", cmd:"drizzle-kit check"},
|
|
@@ -138,33 +126,44 @@ async function triggerEngine(event){
|
|
|
138
126
|
];
|
|
139
127
|
|
|
140
128
|
for(const step of steps){
|
|
141
|
-
const success = await
|
|
129
|
+
const success = await new Promise(resolve=>{
|
|
130
|
+
startLoading(step.name);
|
|
131
|
+
const child = spawn(step.cmd,{shell:true,stdio:"inherit"});
|
|
132
|
+
child.on("close",code=>{ stopLoading(); resolve(code===0); });
|
|
133
|
+
child.on("error",err=>{ stopLoading(); console.log(`${T.red}β ${step.name} Error: ${err.message}${T.reset}`); resolve(false); });
|
|
134
|
+
});
|
|
142
135
|
if(!success){
|
|
143
136
|
console.log(`\n${T.red}${T.bold}πΎ FAILED AT [${step.name.toUpperCase()}]${T.reset}`);
|
|
144
|
-
running=false;
|
|
137
|
+
running=false;
|
|
138
|
+
return;
|
|
145
139
|
}
|
|
146
140
|
}
|
|
147
141
|
|
|
148
142
|
console.log(`\n${T.lime}${T.bold}π All steps successful!${T.reset}`);
|
|
149
|
-
console.log(`${T.gray}Waiting for changes...${T.reset}\n`);
|
|
150
143
|
running=false;
|
|
151
144
|
}
|
|
152
145
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
146
|
+
// ---------------------- WATCHER ----------------------
|
|
147
|
+
// Skip watcher during postinstall
|
|
148
|
+
const skipWatcher = process.argv.includes('--postinstall');
|
|
149
|
+
|
|
150
|
+
if(!skipWatcher){
|
|
151
|
+
const configsExist = findDrizzleConfig(process.cwd()).length > 0;
|
|
152
|
+
if(configsExist){
|
|
153
|
+
triggerEngine("Initial Audit");
|
|
154
|
+
|
|
155
|
+
chokidar.watch(".",{
|
|
156
|
+
ignored:[/node_modules/,/\.git|\.next|dist/],
|
|
157
|
+
ignoreInitial:true,
|
|
158
|
+
usePolling:true,
|
|
159
|
+
interval:300
|
|
160
|
+
}).on("all",(e,f)=>triggerEngine(`${e.toUpperCase()} -> ${path.basename(f)}`));
|
|
161
|
+
} else {
|
|
162
|
+
console.log(`${T.yellow}β No strict drizzle.config found. Watcher disabled.${T.reset}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// ---------------------- GLOBAL ERROR HANDLING ----------------------
|
|
168
167
|
process.on("uncaughtException",err=>{
|
|
169
168
|
stopLoading();
|
|
170
169
|
console.log(`\n${T.red}${T.bold}π‘οΈ ERROR:${T.reset} ${err.message}`);
|