-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatch-dev.js
More file actions
executable file
·55 lines (44 loc) · 1.4 KB
/
watch-dev.js
File metadata and controls
executable file
·55 lines (44 loc) · 1.4 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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
console.log('🔄 Watching for changes and auto-installing globally...');
console.log('Press Ctrl+C to stop\n');
let isInstalling = false;
function installGlobally() {
if (isInstalling) return;
isInstalling = true;
console.log('📦 Installing CLI globally...');
exec('npm link', (error, stdout, stderr) => {
if (error) {
console.error('❌ Installation failed:', error);
} else {
console.log('✅ CLI installed globally! Use "obsidian" command to test.');
}
isInstalling = false;
});
}
// Watch src directory for changes
const srcDir = path.join(__dirname, 'src');
const packageJsonPath = path.join(__dirname, 'package.json');
// Initial installation
installGlobally();
// Watch src directory
if (fs.existsSync(srcDir)) {
fs.watch(srcDir, { recursive: true }, (eventType, filename) => {
if (filename && filename.endsWith('.js')) {
console.log(`🔄 Detected change in ${filename}`);
setTimeout(installGlobally, 100); // Debounce
}
});
}
// Watch package.json
fs.watch(packageJsonPath, (eventType) => {
console.log('🔄 Detected change in package.json');
setTimeout(installGlobally, 100); // Debounce
});
// Keep process alive
process.on('SIGINT', () => {
console.log('\n👋 Stopping file watcher...');
process.exit(0);
});