mirror of
https://github.com/dralkh/spaceforge.git
synced 2026-07-22 06:45:03 +00:00
JS/TS: - Replace builtin-modules with node:module (esbuild.config.mjs) - Replace fs-extra with native fs (install.js), remove from deps - Fix createEl deprecation: use createDiv/createSpan - Remove unnecessary type assertions, fix unsafe casts - Bind event handlers with arrow functions CSS: - Remove all !important declarations (~30 instances) — replace with chained selectors (.class.class) for equal specificity - Merge all duplicate selectors across 7 CSS files (~50+ instances) - Convert 3-digit hex to 6-digit format (_variables.css) - Fix duplicate CSS properties (overflow-y in mcq.css) - Delete leftover display:none suppression rule in calendar.css Meta: - Bump version to 1.0.5 - Update minAppVersion to 1.8.7 - Add versions.json entry for 1.0.5
91 lines
No EOL
2.5 KiB
JavaScript
91 lines
No EOL
2.5 KiB
JavaScript
const fs = require('fs');
|
|
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.mkdirSync(pluginDir, { recursive: true });
|
|
|
|
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.copyFileSync(sourcePath, destPath);
|
|
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);
|
|
});
|
|
} |