-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulate.js
43 lines (36 loc) · 1.02 KB
/
emulate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env node
const dotenv = require('dotenv');
const paths = require('./paths');
const path = require('path');
const fs = require('fs-extra');
const fork = require('child_process').fork;
dotenv.config({
path: paths.configFilePath
});
let imageIndex = 1;
let timer = null;
/**
* copy a test image over to trigger the watchfile
*/
function copyImage() {
const source = path.join( __dirname, 'devAssets', imageIndex + '.jpg' );
fs.copy( source, process.env.imageFilePath, {}, err => {
if( err ) console.error( 'error copying image', err );
});
imageIndex = imageIndex === 10 ? 1 : imageIndex + 1;
}
/**
* fork the process and
*/
const workerProcess = fork( path.join( __dirname, 'server.js' ) );
// listen for message to start timer
workerProcess.on( 'message', async( data ) => {
if( data === 'start timer' ) {
timer = setInterval( copyImage, 5*1000 );
}
});
// exit the app if the worker exits so nodemon can restart
workerProcess.on( 'close', code => {
clearInterval( timer );
process.exit(1);
});