-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
91 lines (74 loc) · 2.48 KB
/
install.js
File metadata and controls
91 lines (74 loc) · 2.48 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const fs = require('fs-extra');
const path = require('path');
const { exec } = require('child_process');
const readline = require('readline');
const projectDir = process.cwd();
// Parse command line arguments
function parseArgs() {
const args = process.argv.slice(2);
const flags = {};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg === '--d' || arg === '--directory') {
flags.directory = args[i + 1];
i++; // Skip next argument as it's the directory value
} else if (arg.startsWith('--d=') || arg.startsWith('--directory=')) {
flags.directory = arg.split('=')[1];
}
}
return flags;
}
function validateDirectory(dirPath) {
if (!fs.existsSync(dirPath) || !fs.statSync(dirPath).isDirectory()) {
console.error(`Error: Directory '${dirPath}' not found.`);
return false;
}
return true;
}
function installPlugin(obsidianPluginsDir) {
if (!validateDirectory(obsidianPluginsDir)) {
process.exit(1);
}
const pluginName = 'spaceforge';
const pluginDir = path.join(obsidianPluginsDir, pluginName);
// Ensure plugin directory exists
fs.ensureDirSync(pluginDir);
console.log('Installing plugin files...');
// Always copy these files (overwrite if exists)
const filesToCopy = ['main.js', 'manifest.json', 'styles.css'];
filesToCopy.forEach(file => {
const sourcePath = path.join(projectDir, file);
const destPath = path.join(pluginDir, file);
if (fs.existsSync(sourcePath)) {
fs.copySync(sourcePath, destPath, { overwrite: true });
console.log(`✓ Copied ${file}`);
} else {
console.log(`⚠ Warning: ${file} not found in project directory`);
}
});
console.log(`\nPlugin installed successfully in '${pluginDir}'!`);
console.log('You may need to restart Obsidian to see the changes.');
}
// Main execution
const flags = parseArgs();
if (flags.directory) {
// Directory provided via command line - skip interactive prompt
console.log(`Using provided directory: ${flags.directory}`);
installPlugin(flags.directory);
} else {
// Interactive mode - prompt user for directory
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter the path to your Obsidian plugins directory: ', (obsidianPluginsDir) => {
installPlugin(obsidianPluginsDir);
rl.close();
});
// Handle Ctrl+C gracefully
rl.on('SIGINT', () => {
console.log('\nInstallation cancelled.');
rl.close();
process.exit(0);
});
}