-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.js
64 lines (64 loc) · 1.67 KB
/
dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require("fs");
const path = require("path");
const c = require("ansi-colors");
const { execSync } = require("child_process");
const manifest = require("./manifest.json");
c.theme({
danger: c.red,
dark: c.dim.gray,
disabled: c.gray,
em: c.italic,
heading: c.bold.underline,
info: c.cyan,
muted: c.dim,
primary: c.blue,
strong: c.bold,
success: c.green.bold,
underline: c.underline,
warning: c.yellow.underline,
});
require("dotenv").config();
let vaultDev = process.env.VAULT_DEV || "";
const args = process.argv.slice(2);
if (args.length > 0 && args[0] === "--prod") {
vaultDev = process.env.VAULT || "";
}
let msg =
vaultDev.trim().length > 0 ? `-v ${c.underline.bold.blue(vaultDev)}` : "";
const cmd = vaultDev.trim().length > 0 ? `-v ${vaultDev}` : "";
if (vaultDev.trim().length > 0) {
const pluginDir = path.join(
vaultDev,
".obsidian",
"plugins",
manifest.id,
".hotreload"
);
if (!fs.existsSync(pluginDir)) {
console.log(
`${c.danger.bold("❌")} ${c.danger(
".hotreload file not found. Creating it..."
)}`
);
fs.writeFile(pluginDir, "", (err) => {
if (err) {
console.error(err);
}
});
// eslint-disable-next-line @typescript-eslint/no-empty-function
setTimeout(function () {}, 1000);
console.log(`✔️ ${c.success(".hotreload file created.")}`);
console.log();
}
}
const styleSheet = "--with-stylesheet src/styles.css";
const command = `obsidian-plugin dev ${styleSheet} src/main.ts ${cmd}`;
console.log(
c.info.italic(
`${c.bold(">")} obsidian-plugin dev ${c.dark.underline(
styleSheet
)} src/main.ts ${msg}`
)
);
execSync(command, { stdio: "inherit" });