drizzle-auto 1.0.15 → 1.0.16
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 +45 -104
- package/package.json +9 -3
package/index.js
CHANGED
|
@@ -5,42 +5,29 @@ const path = require("path");
|
|
|
5
5
|
const chokidar = require("chokidar");
|
|
6
6
|
const { spawn } = require("child_process");
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
========================= */
|
|
11
|
-
const C = {
|
|
12
|
-
reset: "\x1b[0m",
|
|
13
|
-
bold: "\x1b[1m",
|
|
14
|
-
dim: "\x1b[2m",
|
|
8
|
+
const ROOT = process.cwd();
|
|
9
|
+
const PKG = path.join(ROOT, "package.json");
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
/* ================= COLORS ================= */
|
|
12
|
+
const C = {
|
|
13
|
+
r: "\x1b[0m",
|
|
14
|
+
g: "\x1b[32m",
|
|
15
|
+
y: "\x1b[33m",
|
|
16
|
+
c: "\x1b[36m",
|
|
17
|
+
b: "\x1b[1m",
|
|
19
18
|
red: "\x1b[31m",
|
|
20
|
-
|
|
21
|
-
blue: "\x1b[34m",
|
|
22
|
-
gray: "\x1b[90m"
|
|
19
|
+
dim: "\x1b[90m"
|
|
23
20
|
};
|
|
24
21
|
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
info:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
err: m => console.log(`${C.red}✖${C.reset} ${m}`),
|
|
32
|
-
dim: m => console.log(`${C.gray}${m}${C.reset}`)
|
|
22
|
+
const log = {
|
|
23
|
+
ok: m => console.log(`${C.g}✔${C.r} ${m}`),
|
|
24
|
+
info: m => console.log(`${C.c}●${C.r} ${m}`),
|
|
25
|
+
warn: m => console.log(`${C.y}▲${C.r} ${m}`),
|
|
26
|
+
err: m => console.log(`${C.red}✖${C.r} ${m}`),
|
|
27
|
+
dim: m => console.log(`${C.dim}${m}${C.r}`)
|
|
33
28
|
};
|
|
34
29
|
|
|
35
|
-
/*
|
|
36
|
-
🧭 PROJECT ROOT
|
|
37
|
-
========================= */
|
|
38
|
-
const ROOT = process.cwd();
|
|
39
|
-
const PKG = path.join(ROOT, "package.json");
|
|
40
|
-
|
|
41
|
-
/* =========================
|
|
42
|
-
🧩 SCRIPT INJECTOR
|
|
43
|
-
========================= */
|
|
30
|
+
/* ================= SCRIPT INJECT ================= */
|
|
44
31
|
function injectScript() {
|
|
45
32
|
if (!fs.existsSync(PKG)) return;
|
|
46
33
|
|
|
@@ -50,118 +37,72 @@ function injectScript() {
|
|
|
50
37
|
if (!pkg.scripts.tea) {
|
|
51
38
|
pkg.scripts.tea = "drizzle-auto";
|
|
52
39
|
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
53
|
-
|
|
54
|
-
} else {
|
|
55
|
-
ui.dim("Script already exists → tea");
|
|
40
|
+
log.ok("Added script → npm run tea");
|
|
56
41
|
}
|
|
57
42
|
}
|
|
58
43
|
|
|
59
|
-
/*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const config = ["js", "mjs", "ts", "mts"]
|
|
64
|
-
.map(ext => `drizzle.config.${ext}`)
|
|
65
|
-
.find(f => fs.existsSync(path.join(ROOT, f)));
|
|
66
|
-
|
|
67
|
-
if (!config) {
|
|
68
|
-
ui.warn("No drizzle.config found");
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let schemaPath = null;
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const content = fs.readFileSync(path.join(ROOT, config), "utf8");
|
|
76
|
-
const match = content.match(/schema:\s*["'](.+?)["']/);
|
|
77
|
-
if (match) schemaPath = path.join(ROOT, match[1]);
|
|
78
|
-
} catch {}
|
|
79
|
-
|
|
80
|
-
if (schemaPath && !fs.existsSync(schemaPath)) {
|
|
81
|
-
ui.err("Schema file missing");
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
ui.ok(`Detected ${config}`);
|
|
86
|
-
return true;
|
|
44
|
+
/* ================= DRIZZLE DETECT ================= */
|
|
45
|
+
function hasDrizzle() {
|
|
46
|
+
return ["js", "mjs", "ts", "mts"]
|
|
47
|
+
.some(e => fs.existsSync(path.join(ROOT, `drizzle.config.${e}`)));
|
|
87
48
|
}
|
|
88
49
|
|
|
89
|
-
/*
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
let failed = false;
|
|
95
|
-
|
|
96
|
-
const p = spawn("npx", cmd, {
|
|
97
|
-
shell: true,
|
|
98
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
99
|
-
});
|
|
50
|
+
/* ================= RUNNER ================= */
|
|
51
|
+
function run(args) {
|
|
52
|
+
return new Promise(res => {
|
|
53
|
+
const p = spawn("npx", args, { shell: true });
|
|
54
|
+
let fail = false;
|
|
100
55
|
|
|
101
56
|
p.stdout.on("data", d => process.stdout.write(d));
|
|
102
57
|
p.stderr.on("data", d => {
|
|
103
|
-
|
|
58
|
+
fail = true;
|
|
104
59
|
process.stderr.write(d);
|
|
105
60
|
});
|
|
106
61
|
|
|
107
|
-
p.on("close",
|
|
62
|
+
p.on("close", c => res(c === 0 && !fail));
|
|
108
63
|
});
|
|
109
64
|
}
|
|
110
65
|
|
|
111
|
-
/*
|
|
112
|
-
🔁 PIPELINE (SERVER SAFE)
|
|
113
|
-
========================= */
|
|
66
|
+
/* ================= PIPELINE ================= */
|
|
114
67
|
let busy = false;
|
|
115
|
-
|
|
116
68
|
async function pipeline(trigger) {
|
|
117
69
|
if (busy) return;
|
|
118
70
|
busy = true;
|
|
119
71
|
|
|
120
|
-
|
|
72
|
+
log.info(`Trigger → ${trigger}`);
|
|
121
73
|
|
|
122
|
-
if (!
|
|
74
|
+
if (!hasDrizzle()) {
|
|
75
|
+
log.warn("No drizzle config found");
|
|
123
76
|
busy = false;
|
|
124
77
|
return;
|
|
125
78
|
}
|
|
126
79
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!genOK) {
|
|
131
|
-
ui.err("Generate failed — pipeline stopped");
|
|
80
|
+
if (!(await run(["drizzle-kit", "generate"]))) {
|
|
81
|
+
log.err("Generate failed — stopping");
|
|
132
82
|
busy = false;
|
|
133
83
|
return;
|
|
134
84
|
}
|
|
135
85
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
ui.info("Running drizzle-kit push...");
|
|
139
|
-
const pushOK = await run(["drizzle-kit", "push"]);
|
|
140
|
-
|
|
141
|
-
if (!pushOK) {
|
|
142
|
-
ui.warn("Push failed — server still running");
|
|
86
|
+
if (!(await run(["drizzle-kit", "push"]))) {
|
|
87
|
+
log.warn("Push failed — server alive");
|
|
143
88
|
busy = false;
|
|
144
89
|
return;
|
|
145
90
|
}
|
|
146
91
|
|
|
147
|
-
|
|
92
|
+
log.ok("Drizzle synced ✨");
|
|
148
93
|
busy = false;
|
|
149
94
|
}
|
|
150
95
|
|
|
151
|
-
/*
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
96
|
+
/* ================= ENTRY ================= */
|
|
97
|
+
if (process.argv.includes("--inject")) {
|
|
98
|
+
injectScript();
|
|
99
|
+
process.exit(0);
|
|
100
|
+
}
|
|
156
101
|
|
|
157
102
|
injectScript();
|
|
158
103
|
pipeline("Initial");
|
|
159
104
|
|
|
160
105
|
chokidar.watch(ROOT, {
|
|
161
106
|
ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
|
|
162
|
-
ignoreInitial: true
|
|
163
|
-
|
|
164
|
-
interval: 300
|
|
165
|
-
}).on("all", (_, file) => {
|
|
166
|
-
pipeline(path.basename(file));
|
|
167
|
-
});
|
|
107
|
+
ignoreInitial: true
|
|
108
|
+
}).on("all", (_, f) => pipeline(path.basename(f)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-auto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "pavel ahmmed hridoy",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "index.js",
|
|
4
9
|
"bin": {
|
|
5
10
|
"drizzle-auto": "index.js"
|
|
6
11
|
},
|
|
@@ -11,5 +16,6 @@
|
|
|
11
16
|
"dependencies": {
|
|
12
17
|
"chokidar": "^5.0.0",
|
|
13
18
|
"cross-spawn": "^7.0.6"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {}
|
|
21
|
+
}
|