forked from vrtmrz/obsidian-livesync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-plugin.mjs
More file actions
45 lines (38 loc) · 1.47 KB
/
install-plugin.mjs
File metadata and controls
45 lines (38 loc) · 1.47 KB
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
import fs from 'fs';
import path from 'path';
// Configuration
const SOURCE_DIR = './dist';
// Default to the path used in recent commands, but allow override via env var
const TARGET_DIR = process.env.OBSIDIAN_PLUGIN_DIR || "E:\\FATUR\\master\\.obsidian\\plugins\\just-sync";
if (!fs.existsSync(SOURCE_DIR)) {
console.error(`Error: Source directory ${SOURCE_DIR} does not exist. Run 'npm run build' first.`);
process.exit(1);
}
if (!fs.existsSync(TARGET_DIR)) {
console.log(`Creating target directory: ${TARGET_DIR}`);
try {
fs.mkdirSync(TARGET_DIR, { recursive: true });
} catch (err) {
console.error(`Error creating directory: ${err.message}`);
process.exit(1);
}
}
console.log(`Deploying plugin from ${SOURCE_DIR} to ${TARGET_DIR}...`);
try {
const files = fs.readdirSync(SOURCE_DIR);
let copiedCount = 0;
for (const file of files) {
const srcPath = path.join(SOURCE_DIR, file);
const destPath = path.join(TARGET_DIR, file);
// Only copy files, skip directories if any (dist shouldn't have nested dirs usually)
if (fs.statSync(srcPath).isFile()) {
fs.copyFileSync(srcPath, destPath);
console.log(` -> Copied ${file}`);
copiedCount++;
}
}
console.log(`Successfully deployed ${copiedCount} files.`);
} catch (err) {
console.error(`Deployment failed: ${err.message}`);
process.exit(1);
}