drizzle-auto 1.1.0 โ 1.1.2
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 -76
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,28 +6,29 @@ const chokidar = require("chokidar");
|
|
|
6
6
|
const { spawn } = require("child_process");
|
|
7
7
|
|
|
8
8
|
/* =========================
|
|
9
|
-
|
|
9
|
+
๐จ COLORS (CLEAN + PRO)
|
|
10
10
|
========================= */
|
|
11
11
|
const C = {
|
|
12
12
|
reset: "\x1b[0m",
|
|
13
|
-
|
|
13
|
+
dim: "\x1b[2m",
|
|
14
14
|
cyan: "\x1b[36m",
|
|
15
15
|
green: "\x1b[32m",
|
|
16
16
|
yellow: "\x1b[33m",
|
|
17
17
|
red: "\x1b[31m",
|
|
18
|
-
|
|
18
|
+
magenta: "\x1b[35m",
|
|
19
|
+
bold: "\x1b[1m",
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
/* =========================
|
|
22
|
-
|
|
23
|
+
๐งญ PROJECT ROOT
|
|
23
24
|
========================= */
|
|
24
25
|
const ROOT = process.cwd();
|
|
25
26
|
const PKG = path.join(ROOT, "package.json");
|
|
26
27
|
|
|
27
28
|
/* =========================
|
|
28
|
-
|
|
29
|
+
๐งฉ SCRIPT INJECTOR (REAL FIX)
|
|
29
30
|
========================= */
|
|
30
|
-
function
|
|
31
|
+
function injectTeaScript() {
|
|
31
32
|
if (!fs.existsSync(PKG)) return;
|
|
32
33
|
|
|
33
34
|
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
@@ -36,115 +37,126 @@ function injectTea() {
|
|
|
36
37
|
if (!pkg.scripts.tea) {
|
|
37
38
|
pkg.scripts.tea = "drizzle-auto";
|
|
38
39
|
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
39
|
-
console.log(
|
|
40
|
+
console.log(
|
|
41
|
+
`${C.green}โ Added script:${C.reset} ${C.bold}npm run tea${C.reset}`
|
|
42
|
+
);
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
/* =========================
|
|
44
|
-
|
|
47
|
+
๐ FIND DRIZZLE CONFIG (ANYWHERE)
|
|
45
48
|
========================= */
|
|
46
|
-
function walk(dir, results = []) {
|
|
47
|
-
for (const file of fs.readdirSync(dir)) {
|
|
48
|
-
const p = path.join(dir, file);
|
|
49
|
-
if (p.includes("node_modules") || p.includes(".git")) continue;
|
|
50
|
-
|
|
51
|
-
const stat = fs.statSync(p);
|
|
52
|
-
if (stat.isDirectory()) walk(p, results);
|
|
53
|
-
else results.push(p);
|
|
54
|
-
}
|
|
55
|
-
return results;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
49
|
function findDrizzleConfig() {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
50
|
+
const exts = ["js", "mjs", "cjs", "ts", "mts"];
|
|
51
|
+
let found = null;
|
|
52
|
+
|
|
53
|
+
function walk(dir) {
|
|
54
|
+
if (found) return;
|
|
55
|
+
for (const file of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
56
|
+
if (file.name === "node_modules" || file.name.startsWith(".")) continue;
|
|
57
|
+
const full = path.join(dir, file.name);
|
|
58
|
+
|
|
59
|
+
if (file.isDirectory()) walk(full);
|
|
60
|
+
else {
|
|
61
|
+
for (const e of exts) {
|
|
62
|
+
if (file.name === `drizzle.config.${e}`) {
|
|
63
|
+
found = full;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
75
68
|
}
|
|
76
|
-
} catch {}
|
|
77
|
-
|
|
78
|
-
if (schemaPath && !fs.existsSync(schemaPath)) {
|
|
79
|
-
console.log(`${C.red}โ Schema missing: ${schemaPath}${C.reset}`);
|
|
80
|
-
return null;
|
|
81
69
|
}
|
|
82
70
|
|
|
83
|
-
|
|
84
|
-
return
|
|
71
|
+
walk(ROOT);
|
|
72
|
+
return found;
|
|
85
73
|
}
|
|
86
74
|
|
|
87
75
|
/* =========================
|
|
88
|
-
|
|
76
|
+
๐งช VALIDATE SCHEMA EXISTS
|
|
89
77
|
========================= */
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
78
|
+
function validateConfig(configPath) {
|
|
79
|
+
try {
|
|
80
|
+
const txt = fs.readFileSync(configPath, "utf8");
|
|
81
|
+
const m = txt.match(/schema:\s*["'](.+?)["']/);
|
|
82
|
+
if (!m) return true;
|
|
83
|
+
|
|
84
|
+
const schemaPath = path.resolve(path.dirname(configPath), m[1]);
|
|
85
|
+
return fs.existsSync(schemaPath);
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
94
90
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
/* =========================
|
|
92
|
+
โ๏ธ SAFE RUNNER (NO SERVER KILL)
|
|
93
|
+
========================= */
|
|
94
|
+
function run(cmd, args) {
|
|
95
|
+
return new Promise((resolve) => {
|
|
96
|
+
const p = spawn(cmd, args, {
|
|
97
|
+
stdio: "inherit",
|
|
98
|
+
shell: false,
|
|
101
99
|
});
|
|
102
100
|
|
|
103
|
-
p.on("close", code => resolve(code === 0
|
|
101
|
+
p.on("close", (code) => resolve(code === 0));
|
|
104
102
|
});
|
|
105
103
|
}
|
|
106
104
|
|
|
107
105
|
/* =========================
|
|
108
|
-
|
|
106
|
+
๐ PIPELINE (SERVER SAFE)
|
|
109
107
|
========================= */
|
|
110
|
-
let
|
|
108
|
+
let busy = false;
|
|
111
109
|
|
|
112
110
|
async function pipeline(trigger) {
|
|
113
|
-
if (
|
|
114
|
-
|
|
111
|
+
if (busy) return;
|
|
112
|
+
busy = true;
|
|
115
113
|
|
|
116
|
-
console.log(
|
|
114
|
+
console.log(
|
|
115
|
+
`\n${C.cyan}โก Trigger โ${C.reset} ${C.bold}${trigger}${C.reset}`
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const config = findDrizzleConfig();
|
|
119
|
+
if (!config) {
|
|
120
|
+
console.log(`${C.yellow}โ No drizzle.config found${C.reset}`);
|
|
121
|
+
busy = false;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
117
124
|
|
|
118
|
-
if (!
|
|
119
|
-
|
|
125
|
+
if (!validateConfig(config)) {
|
|
126
|
+
console.log(`${C.red}โ Schema path invalid${C.reset}`);
|
|
127
|
+
busy = false;
|
|
120
128
|
return;
|
|
121
129
|
}
|
|
122
130
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
131
|
+
console.log(`${C.magenta}โถ drizzle-kit generate${C.reset}`);
|
|
132
|
+
const genOK = await run("npx", ["drizzle-kit", "generate"]);
|
|
133
|
+
if (!genOK) {
|
|
134
|
+
console.log(`${C.red}๐ Generate failed โ watcher alive${C.reset}`);
|
|
135
|
+
busy = false;
|
|
126
136
|
return;
|
|
127
137
|
}
|
|
128
138
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
console.log(`${C.magenta}โถ drizzle-kit push${C.reset}`);
|
|
140
|
+
const pushOK = await run("npx", ["drizzle-kit", "push"]);
|
|
141
|
+
if (!pushOK) {
|
|
142
|
+
console.log(`${C.red}๐ Push failed โ watcher alive${C.reset}`);
|
|
143
|
+
busy = false;
|
|
132
144
|
return;
|
|
133
145
|
}
|
|
134
146
|
|
|
135
|
-
console.log(`${C.green}โจ Drizzle synced${C.reset}`);
|
|
136
|
-
|
|
147
|
+
console.log(`${C.green}โจ Drizzle fully synced${C.reset}`);
|
|
148
|
+
busy = false;
|
|
137
149
|
}
|
|
138
150
|
|
|
139
151
|
/* =========================
|
|
140
|
-
|
|
152
|
+
๐ WATCH EVERYTHING
|
|
141
153
|
========================= */
|
|
142
|
-
|
|
143
|
-
pipeline("
|
|
154
|
+
injectTeaScript();
|
|
155
|
+
pipeline("Initial");
|
|
144
156
|
|
|
145
157
|
chokidar.watch(ROOT, {
|
|
146
158
|
ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
|
|
147
159
|
ignoreInitial: true,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
})
|
|
160
|
+
}).on("all", (_, file) => {
|
|
161
|
+
pipeline(path.relative(ROOT, file));
|
|
162
|
+
});
|