|
1 | 1 |
|
2 | 2 | import { OS, SpawnStatus } from 'codify-schemas'; |
3 | 3 | import os from 'node:os'; |
| 4 | +import fs from 'node:fs' |
4 | 5 | import path from 'node:path'; |
5 | 6 |
|
6 | 7 | import { PluginInitOrchestrator } from '../common/initialize-plugins.js'; |
@@ -71,9 +72,12 @@ export const TestOrchestrator = { |
71 | 72 | // Add symlinks to the bind mount locations. |
72 | 73 | await spawn(`tart exec ${vmName} sudo ln -s /Volumes/My\\ Shared\\ Files/codify-lib/bin/codify /usr/local/bin/codify`, { interactive: true }); |
73 | 74 | await spawn(`tart exec ${vmName} ln -s /Volumes/My\\ Shared\\ Files/codify-config/${path.basename(initializationResult.project.codifyFiles[0])} /Users/admin/codify.jsonc`, { interactive: true }); |
74 | | - // await spawn(`sshpass -p "admin" scp -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${initializationResult.project.codifyFiles[0]} admin@${ip}:~/codify.jsonc`, { interactive: true }); |
75 | 75 |
|
| 76 | + // Launch terminal and run codify apply |
76 | 77 | await (args.vmOs === OS.Darwin ? spawn(`tart exec ${vmName} osascript -e "tell application \\"Terminal\\" to do script \\"cd ~ && codify apply\\""`, { interactive: true }) : spawn(`tart exec ${vmName} gnome-terminal -- bash -c "cd ~/ && codify apply"`, { interactive: true })); |
| 78 | + |
| 79 | + this.watchAndSyncFileChanges(initializationResult.project.codifyFiles[0], ip); |
| 80 | + |
77 | 81 | } catch (error) { |
78 | 82 | ctx.log(`Error copying files to VM: ${error}`); |
79 | 83 | } |
@@ -148,5 +152,28 @@ export const TestOrchestrator = { |
148 | 152 |
|
149 | 153 | await sleep(1000); |
150 | 154 | } |
| 155 | + }, |
| 156 | + |
| 157 | + watchAndSyncFileChanges(filePath: string, ip: string): void { |
| 158 | + const watcher = fs.watch(filePath, { persistent: false }, async (eventType) => { |
| 159 | + if (eventType === 'change') { |
| 160 | + ctx.log('Config file changed, syncing to VM...'); |
| 161 | + try { |
| 162 | + // Copy the updated config file to the VM |
| 163 | + // This command will fail but it causes the bind mount to update for some reason. (seems like a bug in Tart). Leave this here for now. |
| 164 | + await spawn(`sshpass -p "admin" scp -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${filePath} admin@${ip}:~/codify.jsonc`, { interactive: true }); |
| 165 | + // ctx.log('Config file synced successfully'); |
| 166 | + } catch (error) { |
| 167 | + // ctx.log(`Error syncing config file: ${error}`); |
| 168 | + } |
| 169 | + } |
| 170 | + }); |
| 171 | + |
| 172 | + // Clean up the watcher when the process finishes |
| 173 | + const cleanupWatcher = () => { |
| 174 | + watcher.close(); |
| 175 | + }; |
| 176 | + |
| 177 | + process.once('exit', cleanupWatcher); |
151 | 178 | } |
152 | 179 | }; |
0 commit comments