Merge pull request '#6202 myt watcher' (!2377) from 6202-mytWatcher into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #2377
Reviewed-by: Juan Ferrer <juan@verdnatura.es>
This commit is contained in:
Jorge Penadés 2024-05-09 10:50:57 +00:00
commit 03a8dafe47
3 changed files with 28 additions and 1 deletions

24
db/dbWatcher.js Normal file
View File

@ -0,0 +1,24 @@
const fs = require('fs');
const {spawn} = require('child_process');
function watchDatabaseChanges() {
console.log('Watching for changes in db/routines and db/versions');
fs.watch('db', {recursive: true}, (eventType, filename) => {
if (filename.endsWith('.sql')) {
let command;
if (filename.startsWith('routines')) command = 'push';
else if (filename.startsWith('versions')) command = 'run';
if (command) {
const process = spawn('myt', [command]);
process.stdout.on('data', data => console.log(data.toString()));
process.stderr.on('data', data => console.error(`stderr: ${data}`));
process.on('error', error => console.error(`error: ${error.message}`));
process.on('close', () => console.log('Watching for changes in db/routines and db/versions'));
}
}
});
}
if (require.main === module) watchDatabaseChanges();
module.exports = watchDatabaseChanges;

View File

@ -6,6 +6,7 @@ const log = require('fancy-log');
const Myt = require('@verdnatura/myt/myt'); const Myt = require('@verdnatura/myt/myt');
const Run = require('@verdnatura/myt/myt-run'); const Run = require('@verdnatura/myt/myt-run');
const Start = require('@verdnatura/myt/myt-start'); const Start = require('@verdnatura/myt/myt-start');
const watchDatabaseChanges = require('./db/dbWatcher');
// Configuration // Configuration
@ -245,6 +246,7 @@ routes.description = 'Merges all module routes file into one file';
function watch(done) { function watch(done) {
gulp.watch(routeFiles, gulp.series(routes)); gulp.watch(routeFiles, gulp.series(routes));
gulp.watch(localeFiles, gulp.series(locales)); gulp.watch(localeFiles, gulp.series(locales));
watchDatabaseChanges();
done(); done();
} }
watch.description = `Watches for changes in routes and locale files`; watch.description = `Watches for changes in routes and locale files`;

View File

@ -113,7 +113,8 @@
"test:e2e": "node e2e/tests.js", "test:e2e": "node e2e/tests.js",
"test:front": "jest --watch", "test:front": "jest --watch",
"back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back", "back": "nodemon --inspect -w modules ./node_modules/gulp/bin/gulp.js back",
"lint": "eslint ./ --cache --ignore-pattern .gitignore" "lint": "eslint ./ --cache --ignore-pattern .gitignore",
"watch:db": "node ./db/dbWatcher.js"
}, },
"jest": { "jest": {
"projects": [ "projects": [