#!/usr/bin/env node const args = process.argv; const babel = require("@babel/core"); const fs = require('fs'); const gaze = require('gaze'); const nodemon = require('nodemon'); const path = require('path'); // Watch the src and transpile when changed gaze('src/**/*', (err, watcher) => { if (err) { throw err; } watcher.on('changed', sourceFile => { console.log(sourceFile + " has changed"); try { let targetFile = path.relative(__dirname, sourceFile).replace(/\/src\//, '/lib/'); targetFile = path.resolve(__dirname, targetFile); fs.writeFile( targetFile, babel.transformFileSync(sourceFile).code, () => { console.log('Re-running the parse-server...') }, ); } catch (e) { console.error(e.message, e.stack); } }); }); // ignore command and file args.splice(0, 2); try { // Run and watch dist nodemon({ script: 'bin/parse-server', args: args, ext: 'js json', watch: 'lib' }); } catch (e) { console.error(e.message, e.stack); } process.once('SIGINT', () => { process.exit(0); });