Monorepo for Aesthetic.Computer aesthetic.computer
at main 40 lines 1.3 kB view raw
1import { watch, existsSync, unlink } from 'fs'; 2import { exec, execSync } from 'child_process'; 3import { join } from 'path'; 4import { homedir } from 'os'; 5 6// Resolve the file path to handle the '~' character 7const dirPath = join(homedir(), 'aesthetic-computer/ssl-dev'); 8const filePath = join(dirPath, '.ssl'); 9 10// Get the path to fish dynamically 11const fishPath = 'fish'; 12 13const command = `${fishPath} ${join(homedir(), 'aesthetic-computer/ssl-dev/ssl-install.fish')} --install-only`; 14 15watch(dirPath, (eventType, filename) => { 16 if (eventType === 'rename' && filename === '.ssl') { 17 // Check if the .ssl file exists 18 if (existsSync(filePath)) { 19 exec(command, { shell: true }, (err, stdout, stderr) => { 20 if (err) { 21 console.error(`Error executing command: ${err.message}`); 22 console.error(`stderr: ${stderr}`); 23 return; 24 } 25 console.log(`Command output: ${stdout}`); 26 27 // Remove the .ssl file 28 unlink(filePath, (err) => { 29 if (err) { 30 console.error(`Error removing file: ${err.message}`); 31 return; 32 } 33 console.log(`File ${filePath} removed successfully.`); 34 }); 35 }); 36 } 37 } 38}); 39 40console.log(`Watching for .ssl file creation in ${dirPath}`);