drizzle-auto 1.0.15 ā 1.0.17
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 +80 -120
- package/package.json +9 -3
package/index.js
CHANGED
|
@@ -6,162 +6,122 @@ const chokidar = require("chokidar");
|
|
|
6
6
|
const { spawn } = require("child_process");
|
|
7
7
|
|
|
8
8
|
/* =========================
|
|
9
|
-
|
|
10
|
-
========================= */
|
|
11
|
-
const C = {
|
|
12
|
-
reset: "\x1b[0m",
|
|
13
|
-
bold: "\x1b[1m",
|
|
14
|
-
dim: "\x1b[2m",
|
|
15
|
-
|
|
16
|
-
cyan: "\x1b[36m",
|
|
17
|
-
green: "\x1b[32m",
|
|
18
|
-
yellow: "\x1b[33m",
|
|
19
|
-
red: "\x1b[31m",
|
|
20
|
-
magenta: "\x1b[35m",
|
|
21
|
-
blue: "\x1b[34m",
|
|
22
|
-
gray: "\x1b[90m"
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const ui = {
|
|
26
|
-
title: m => console.log(`\n${C.bold}${C.magenta}ā ${m}${C.reset}`),
|
|
27
|
-
info: m => console.log(`${C.cyan}ā${C.reset} ${m}`),
|
|
28
|
-
watch: m => console.log(`${C.blue}š${C.reset} ${m}`),
|
|
29
|
-
ok: m => console.log(`${C.green}ā${C.reset} ${m}`),
|
|
30
|
-
warn: m => console.log(`${C.yellow}ā²${C.reset} ${m}`),
|
|
31
|
-
err: m => console.log(`${C.red}ā${C.reset} ${m}`),
|
|
32
|
-
dim: m => console.log(`${C.gray}${m}${C.reset}`)
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/* =========================
|
|
36
|
-
š§ PROJECT ROOT
|
|
9
|
+
š§ PROJECT ROOT
|
|
37
10
|
========================= */
|
|
38
11
|
const ROOT = process.cwd();
|
|
39
12
|
const PKG = path.join(ROOT, "package.json");
|
|
40
13
|
|
|
41
14
|
/* =========================
|
|
42
|
-
|
|
15
|
+
š§© SCRIPT INJECTOR
|
|
43
16
|
========================= */
|
|
44
17
|
function injectScript() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
} else {
|
|
55
|
-
ui.dim("Script already exists ā tea");
|
|
56
|
-
}
|
|
18
|
+
if (!fs.existsSync(PKG)) return;
|
|
19
|
+
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
20
|
+
pkg.scripts ||= {};
|
|
21
|
+
|
|
22
|
+
if (!pkg.scripts.tea) {
|
|
23
|
+
pkg.scripts.tea = "drizzle-auto";
|
|
24
|
+
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
25
|
+
console.log("ā Script added ā npm run tea");
|
|
26
|
+
}
|
|
57
27
|
}
|
|
58
28
|
|
|
59
29
|
/* =========================
|
|
60
|
-
|
|
30
|
+
š DRIZZLE DETECTOR
|
|
61
31
|
========================= */
|
|
62
32
|
function detectDrizzle() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
ui.ok(`Detected ${config}`);
|
|
86
|
-
return true;
|
|
33
|
+
const configs = ["js","mjs","ts","mts"]
|
|
34
|
+
.map(e => drizzle.config.${e})
|
|
35
|
+
.find(f => fs.existsSync(path.join(ROOT, f)));
|
|
36
|
+
|
|
37
|
+
if (!configs) {
|
|
38
|
+
console.log("ā ļø No drizzle.config found");
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let schemaPath = null;
|
|
43
|
+
try {
|
|
44
|
+
const content = fs.readFileSync(path.join(ROOT, configs), "utf8");
|
|
45
|
+
const match = content.match(/schema:\s*"'["']/);
|
|
46
|
+
if (match) schemaPath = path.join(ROOT, match[1]);
|
|
47
|
+
} catch {}
|
|
48
|
+
|
|
49
|
+
if (schemaPath && !fs.existsSync(schemaPath)) {
|
|
50
|
+
console.log("ā Schema file missing");
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { config: configs, schema: schemaPath };
|
|
87
55
|
}
|
|
88
56
|
|
|
89
57
|
/* =========================
|
|
90
|
-
|
|
58
|
+
āļø SAFE COMMAND RUNNER
|
|
91
59
|
========================= */
|
|
92
60
|
function run(cmd) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
let failed = false;
|
|
63
|
+
|
|
64
|
+
const p = spawn("npx", cmd, { shell: true });
|
|
65
|
+
|
|
66
|
+
p.stdout.on("data", d => process.stdout.write(d));
|
|
67
|
+
p.stderr.on("data", d => {
|
|
68
|
+
failed = true;
|
|
69
|
+
process.stderr.write(d);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
p.on("close", code => {
|
|
73
|
+
resolve(code === 0 && !failed);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
});
|
|
109
77
|
}
|
|
110
78
|
|
|
111
79
|
/* =========================
|
|
112
|
-
|
|
80
|
+
š PIPELINE (NON-KILLING)
|
|
113
81
|
========================= */
|
|
114
82
|
let busy = false;
|
|
115
83
|
|
|
116
84
|
async function pipeline(trigger) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
ui.watch(`Trigger ā ${trigger}`);
|
|
121
|
-
|
|
122
|
-
if (!detectDrizzle()) {
|
|
123
|
-
busy = false;
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
85
|
+
if (busy) return;
|
|
86
|
+
busy = true;
|
|
126
87
|
|
|
127
|
-
|
|
128
|
-
const genOK = await run(["drizzle-kit", "generate"]);
|
|
88
|
+
console.log(\nā” Trigger ā ${trigger});
|
|
129
89
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
ui.ok("Generate successful");
|
|
90
|
+
const drizzle = detectDrizzle();
|
|
91
|
+
if (!drizzle) {
|
|
92
|
+
busy = false;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
137
95
|
|
|
138
|
-
|
|
139
|
-
|
|
96
|
+
const genOK = await run(["drizzle-kit", "generate"]);
|
|
97
|
+
if (!genOK) {
|
|
98
|
+
console.log("š Generate failed ā pipeline paused");
|
|
99
|
+
busy = false;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
140
102
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
103
|
+
const pushOK = await run(["drizzle-kit", "push"]);
|
|
104
|
+
if (!pushOK) {
|
|
105
|
+
console.log("š Push failed ā server still running");
|
|
106
|
+
busy = false;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
146
109
|
|
|
147
|
-
|
|
148
|
-
|
|
110
|
+
console.log("⨠Drizzle fully synced");
|
|
111
|
+
busy = false;
|
|
149
112
|
}
|
|
150
113
|
|
|
151
114
|
/* =========================
|
|
152
|
-
|
|
115
|
+
š WATCHER (ALWAYS ALIVE)
|
|
153
116
|
========================= */
|
|
154
|
-
ui.title("DrizzlePulse ā Server Start");
|
|
155
|
-
ui.dim(`Root ā ${ROOT}`);
|
|
156
|
-
|
|
157
117
|
injectScript();
|
|
158
118
|
pipeline("Initial");
|
|
159
119
|
|
|
160
120
|
chokidar.watch(ROOT, {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
121
|
+
ignored: [/node_modules/, /.git/, /.next/, /dist/],
|
|
122
|
+
ignoreInitial: true,
|
|
123
|
+
usePolling: true,
|
|
124
|
+
interval: 300
|
|
165
125
|
}).on("all", (_, file) => {
|
|
166
|
-
|
|
126
|
+
pipeline(path.basename(file));
|
|
167
127
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-auto",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
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
|
+
}
|