fix: using chokidar instead of npm-watch (issue #4)

This commit is contained in:
Amadou Ada DIENE
2021-07-31 14:49:31 +02:00
parent 5c11822d09
commit 2feedcefc5
17 changed files with 457 additions and 1199 deletions

View File

@@ -0,0 +1,46 @@
#!/usr/bin/env node
const spawn = require('child_process').spawn;
const chokidar = require('chokidar');
const kill = require('tree-kill');
const path = require('path');
class ElectronForgeRunner {
constructor() {
this.__init__();
}
__init__ = () => {
this.args = process.argv;
this.command = this.args[2];
this.cwd = process.cwd();
this.watchPaths = [
path.join(this.cwd, '/workspaces/electron-app/**/*.ts'),
path.join(this.cwd, '/workspaces/shared-lib/.dist/**/*.ts'),
];
this.ignoredPaths = '**/node_modules/*';
this.startWatching();
this.reload();
};
reload = () => {
if (this.childProcess) kill(this.childProcess.pid);
this.childProcess = spawn('npm run start:electron-app:once', [], {
shell: true,
stdio: 'inherit',
});
};
startWatching = () => {
chokidar
.watch(this.watchPaths, {
ignored: this.ignoredPaths,
ignoreInitial: true,
})
.on('all', (event, path) => {
this.reload();
});
};
}
new ElectronForgeRunner();