-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.js
51 lines (51 loc) · 1.5 KB
/
export.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
/* eslint-disable @typescript-eslint/no-var-requires */
const { Command } = require("commander");
const path = require("path");
const fs = require("fs");
const c = require("ansi-colors");
const dotenv = require("dotenv");
const manifest = require("./manifest.json");
const env = dotenv.config();
const VAULT = env.parsed.VAULT;
if (!VAULT || VAULT.trim().length === 0) {
console.error("Please set VAULT in .env.json");
process.exit(1);
}
const program = new Command();
program
.description("Export plugin to your main vault")
.option("-b, --beta", "Use manifest-beta.json");
program.parse();
const opt = program.opts();
const pluginDir = path.join(VAULT, ".obsidian", "plugins", manifest["id"]);
if (!fs.existsSync(pluginDir)) {
console.log(c.yellow.underline("Creating plugin directory"));
fs.mkdirSync(pluginDir);
}
console.log(
c.blueBright(
`Copying plugin in ${c.underline(pluginDir)} with: ${c.underline(
opt.beta ? "manifest-beta.json" : "manifest.json"
)}`
)
);
fs.copyFileSync("./dist/main.js", path.join(pluginDir, "main.js"));
if (opt.beta && fs.existsSync("./manifest-beta.json")) {
fs.copyFileSync(
"./manifest-beta.json",
path.join(pluginDir, "manifest.json")
);
} else {
fs.copyFileSync(
"./dist/manifest.json",
path.join(pluginDir, "manifest.json")
);
}
if (fs.existsSync("./dist/styles.css")) {
fs.copyFileSync("./dist/styles.css", path.join(pluginDir, "styles.css"));
}
console.log(
c.green(
"✔️ Plugin copied to your main vault. Please reload the plugin to see changes."
)
);