drizzle-auto 1.0.23 ā 1.0.24
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 +25 -31
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -12,97 +12,90 @@ const ROOT = process.cwd();
|
|
|
12
12
|
const PKG = path.join(ROOT, "package.json");
|
|
13
13
|
|
|
14
14
|
/* =========================
|
|
15
|
-
šØ
|
|
15
|
+
šØ COLORS
|
|
16
16
|
========================= */
|
|
17
17
|
const colors = {
|
|
18
18
|
reset: "\x1b[0m",
|
|
19
|
-
bright: "\x1b[1m",
|
|
20
19
|
red: "\x1b[31m",
|
|
21
20
|
green: "\x1b[32m",
|
|
22
21
|
yellow: "\x1b[33m",
|
|
23
|
-
blue: "\x1b[34m",
|
|
24
|
-
magenta: "\x1b[35m",
|
|
25
22
|
cyan: "\x1b[36m",
|
|
23
|
+
magenta: "\x1b[35m",
|
|
26
24
|
};
|
|
27
25
|
|
|
28
26
|
/* =========================
|
|
29
27
|
š§© SCRIPT INJECTOR
|
|
30
28
|
========================= */
|
|
31
|
-
function
|
|
29
|
+
function injectTeaScript() {
|
|
32
30
|
if (!fs.existsSync(PKG)) return;
|
|
33
31
|
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
34
32
|
pkg.scripts ||= {};
|
|
35
|
-
|
|
36
33
|
if (!pkg.scripts.tea) {
|
|
37
34
|
pkg.scripts.tea = "drizzle-auto";
|
|
38
35
|
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
39
|
-
console.log(`${colors.cyan}ā
|
|
36
|
+
console.log(`${colors.cyan}ā Added npm run tea${colors.reset}`);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
/* =========================
|
|
44
|
-
š DRIZZLE
|
|
41
|
+
š DRIZZLE CONFIG DETECTION
|
|
45
42
|
========================= */
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!configs) {
|
|
43
|
+
function findDrizzleConfig() {
|
|
44
|
+
const files = ["drizzle.config.js","drizzle.config.mjs","drizzle.config.ts","drizzle.config.mts"];
|
|
45
|
+
const found = files.map(f => path.join(ROOT, f)).find(fs.existsSync);
|
|
46
|
+
if (!found) {
|
|
52
47
|
console.log(`${colors.yellow}ā ļø No drizzle.config found${colors.reset}`);
|
|
53
48
|
return null;
|
|
54
49
|
}
|
|
55
50
|
|
|
56
|
-
let
|
|
51
|
+
let schema = null;
|
|
57
52
|
try {
|
|
58
|
-
const content = fs.readFileSync(
|
|
53
|
+
const content = fs.readFileSync(found, "utf8");
|
|
59
54
|
const match = content.match(/schema:\s*["'](.+?)["']/);
|
|
60
|
-
if (match)
|
|
55
|
+
if (match) schema = path.join(ROOT, match[1]);
|
|
61
56
|
} catch {}
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
console.log(`${colors.red}ā Schema file missing${colors.reset}`);
|
|
57
|
+
|
|
58
|
+
if (schema && !fs.existsSync(schema)) {
|
|
59
|
+
console.log(`${colors.red}ā Schema file missing: ${schema}${colors.reset}`);
|
|
65
60
|
return null;
|
|
66
61
|
}
|
|
67
62
|
|
|
68
|
-
return { config:
|
|
63
|
+
return { config: found, schema };
|
|
69
64
|
}
|
|
70
65
|
|
|
71
66
|
/* =========================
|
|
72
|
-
āļø SAFE
|
|
67
|
+
āļø SAFE RUNNER
|
|
73
68
|
========================= */
|
|
74
69
|
function run(cmd) {
|
|
75
|
-
return new Promise(
|
|
70
|
+
return new Promise(resolve => {
|
|
76
71
|
let failed = false;
|
|
77
72
|
const p = spawn("npx", cmd, { shell: true });
|
|
78
|
-
|
|
79
73
|
p.stdout.on("data", d => process.stdout.write(`${colors.green}${d}${colors.reset}`));
|
|
80
74
|
p.stderr.on("data", d => {
|
|
81
75
|
failed = true;
|
|
82
76
|
process.stderr.write(`${colors.red}${d}${colors.reset}`);
|
|
83
77
|
});
|
|
84
|
-
|
|
85
78
|
p.on("close", code => resolve(code === 0 && !failed));
|
|
86
79
|
});
|
|
87
80
|
}
|
|
88
81
|
|
|
89
82
|
/* =========================
|
|
90
|
-
š PIPELINE
|
|
83
|
+
š PIPELINE
|
|
91
84
|
========================= */
|
|
92
85
|
let busy = false;
|
|
93
86
|
|
|
94
87
|
async function pipeline(trigger) {
|
|
95
88
|
if (busy) return;
|
|
96
89
|
busy = true;
|
|
97
|
-
|
|
98
90
|
console.log(`${colors.magenta}\nā” Trigger ā ${trigger}${colors.reset}`);
|
|
99
91
|
|
|
100
|
-
const drizzle =
|
|
92
|
+
const drizzle = findDrizzleConfig();
|
|
101
93
|
if (!drizzle) {
|
|
102
94
|
busy = false;
|
|
103
95
|
return;
|
|
104
96
|
}
|
|
105
97
|
|
|
98
|
+
// 1ļøā£ Generate
|
|
106
99
|
const genOK = await run(["drizzle-kit", "generate"]);
|
|
107
100
|
if (!genOK) {
|
|
108
101
|
console.log(`${colors.red}š Generate failed ā pipeline paused${colors.reset}`);
|
|
@@ -110,6 +103,7 @@ async function pipeline(trigger) {
|
|
|
110
103
|
return;
|
|
111
104
|
}
|
|
112
105
|
|
|
106
|
+
// 2ļøā£ Push
|
|
113
107
|
const pushOK = await run(["drizzle-kit", "push"]);
|
|
114
108
|
if (!pushOK) {
|
|
115
109
|
console.log(`${colors.red}š Push failed ā server still running${colors.reset}`);
|
|
@@ -122,9 +116,9 @@ async function pipeline(trigger) {
|
|
|
122
116
|
}
|
|
123
117
|
|
|
124
118
|
/* =========================
|
|
125
|
-
š WATCHER
|
|
119
|
+
š WATCHER
|
|
126
120
|
========================= */
|
|
127
|
-
|
|
121
|
+
injectTeaScript();
|
|
128
122
|
pipeline("Initial");
|
|
129
123
|
|
|
130
124
|
chokidar.watch(ROOT, {
|
|
@@ -132,4 +126,4 @@ chokidar.watch(ROOT, {
|
|
|
132
126
|
ignoreInitial: true,
|
|
133
127
|
usePolling: true,
|
|
134
128
|
interval: 300
|
|
135
|
-
}).on("all", (_, file) => pipeline(
|
|
129
|
+
}).on("all", (_, file) => pipeline(file));
|