drizzle-auto 1.0.14 → 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 +60 -79
- package/package.json +9 -3
package/index.js
CHANGED
|
@@ -5,41 +5,31 @@ const path = require("path");
|
|
|
5
5
|
const chokidar = require("chokidar");
|
|
6
6
|
const { spawn } = require("child_process");
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
const ROOT = process.cwd();
|
|
9
|
+
const PKG = path.join(ROOT, "package.json");
|
|
10
|
+
|
|
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",
|
|
16
18
|
red: "\x1b[31m",
|
|
17
|
-
|
|
18
|
-
bold: "\x1b[1m"
|
|
19
|
+
dim: "\x1b[90m"
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
const log = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
warn: m => console.log(`${
|
|
25
|
-
err: m => console.log(`${
|
|
26
|
-
|
|
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}`)
|
|
27
28
|
};
|
|
28
29
|
|
|
29
|
-
/*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const ROOT = process.cwd();
|
|
33
|
-
const PKG = path.join(ROOT, "package.json");
|
|
34
|
-
|
|
35
|
-
/* ======================
|
|
36
|
-
☕ ADD tea SCRIPT
|
|
37
|
-
====================== */
|
|
38
|
-
function addTeaScript() {
|
|
39
|
-
if (!fs.existsSync(PKG)) {
|
|
40
|
-
log.err("package.json not found");
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
30
|
+
/* ================= SCRIPT INJECT ================= */
|
|
31
|
+
function injectScript() {
|
|
32
|
+
if (!fs.existsSync(PKG)) return;
|
|
43
33
|
|
|
44
34
|
const pkg = JSON.parse(fs.readFileSync(PKG, "utf8"));
|
|
45
35
|
pkg.scripts ||= {};
|
|
@@ -47,81 +37,72 @@ function addTeaScript() {
|
|
|
47
37
|
if (!pkg.scripts.tea) {
|
|
48
38
|
pkg.scripts.tea = "drizzle-auto";
|
|
49
39
|
fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2));
|
|
50
|
-
log.ok("
|
|
51
|
-
} else {
|
|
52
|
-
log.info("Script already exists");
|
|
40
|
+
log.ok("Added script → npm run tea");
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
43
|
|
|
56
|
-
/*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const exts = ["js", "mjs", "ts", "mts"];
|
|
61
|
-
return exts.find(ext =>
|
|
62
|
-
fs.existsSync(path.join(ROOT, `drizzle.config.${ext}`))
|
|
63
|
-
);
|
|
44
|
+
/* ================= DRIZZLE DETECT ================= */
|
|
45
|
+
function hasDrizzle() {
|
|
46
|
+
return ["js", "mjs", "ts", "mts"]
|
|
47
|
+
.some(e => fs.existsSync(path.join(ROOT, `drizzle.config.${e}`)));
|
|
64
48
|
}
|
|
65
49
|
|
|
66
|
-
/*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
p.on("
|
|
50
|
+
/* ================= RUNNER ================= */
|
|
51
|
+
function run(args) {
|
|
52
|
+
return new Promise(res => {
|
|
53
|
+
const p = spawn("npx", args, { shell: true });
|
|
54
|
+
let fail = false;
|
|
55
|
+
|
|
56
|
+
p.stdout.on("data", d => process.stdout.write(d));
|
|
57
|
+
p.stderr.on("data", d => {
|
|
58
|
+
fail = true;
|
|
59
|
+
process.stderr.write(d);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
p.on("close", c => res(c === 0 && !fail));
|
|
73
63
|
});
|
|
74
64
|
}
|
|
75
65
|
|
|
76
|
-
/*
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
async function pipeline(reason) {
|
|
82
|
-
if (running) return;
|
|
83
|
-
running = true;
|
|
66
|
+
/* ================= PIPELINE ================= */
|
|
67
|
+
let busy = false;
|
|
68
|
+
async function pipeline(trigger) {
|
|
69
|
+
if (busy) return;
|
|
70
|
+
busy = true;
|
|
84
71
|
|
|
85
|
-
log.
|
|
72
|
+
log.info(`Trigger → ${trigger}`);
|
|
86
73
|
|
|
87
|
-
if (!
|
|
88
|
-
log.warn("No drizzle
|
|
89
|
-
|
|
74
|
+
if (!hasDrizzle()) {
|
|
75
|
+
log.warn("No drizzle config found");
|
|
76
|
+
busy = false;
|
|
90
77
|
return;
|
|
91
78
|
}
|
|
92
79
|
|
|
93
|
-
log.sys("Running drizzle generate...");
|
|
94
80
|
if (!(await run(["drizzle-kit", "generate"]))) {
|
|
95
|
-
log.err("Generate failed —
|
|
96
|
-
|
|
81
|
+
log.err("Generate failed — stopping");
|
|
82
|
+
busy = false;
|
|
97
83
|
return;
|
|
98
84
|
}
|
|
99
85
|
|
|
100
|
-
log.sys("Running drizzle push...");
|
|
101
86
|
if (!(await run(["drizzle-kit", "push"]))) {
|
|
102
|
-
log.
|
|
103
|
-
|
|
87
|
+
log.warn("Push failed — server alive");
|
|
88
|
+
busy = false;
|
|
104
89
|
return;
|
|
105
90
|
}
|
|
106
91
|
|
|
107
|
-
log.ok("
|
|
108
|
-
|
|
92
|
+
log.ok("Drizzle synced ✨");
|
|
93
|
+
busy = false;
|
|
109
94
|
}
|
|
110
95
|
|
|
111
|
-
/*
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
${c.gray}Server-side watcher initialized${c.reset}
|
|
117
|
-
`);
|
|
96
|
+
/* ================= ENTRY ================= */
|
|
97
|
+
if (process.argv.includes("--inject")) {
|
|
98
|
+
injectScript();
|
|
99
|
+
process.exit(0);
|
|
100
|
+
}
|
|
118
101
|
|
|
119
|
-
|
|
120
|
-
pipeline("
|
|
102
|
+
injectScript();
|
|
103
|
+
pipeline("Initial");
|
|
121
104
|
|
|
122
105
|
chokidar.watch(ROOT, {
|
|
123
106
|
ignored: [/node_modules/, /\.git/, /\.next/, /dist/],
|
|
124
107
|
ignoreInitial: true
|
|
125
|
-
}).on("
|
|
126
|
-
pipeline(path.basename(file))
|
|
127
|
-
);
|
|
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
|
+
}
|