generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathprepare_demo_vault.mjs
38 lines (31 loc) · 1.15 KB
/
prepare_demo_vault.mjs
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
import fs from 'fs';
import path from 'path';
function main() {
/**
* This script ensures the plugin artifacts are symlinked into the demo vault.
* Such that you can test your build in the demo vault.
*/
const main_js = path.resolve("main.js");
const srcPaths = ["manifest.json", "styles.css", main_js].map((p) => path.resolve(p));
const outputFolder = "demo_vault/.obsidian/plugins/copilot-auto-completion";
if (!fs.existsSync(main_js)) {
fs.writeFileSync(main_js, '');
}
for (const srcPath of srcPaths) {
const targetPath = path.resolve(outputFolder, path.basename(srcPath));
if (!fs.existsSync(srcPath)) {
throw new Error(`File ${srcPath} does not exist.
Please make sure the file exists and run this script from the root of the repository.`
);
}
if (fs.existsSync(targetPath)) {
fs.unlinkSync(targetPath);
}
try {
fs.symlinkSync(srcPath, targetPath);
} catch (error) {
throw new Error(`Failed to create symlink from ${srcPath} to ${targetPath}. Error: ${error}`);
}
}
}
main();