backend-manager 3.2.179 → 3.2.180

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "3.2.179",
3
+ "version": "3.2.180",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -1,6 +1,7 @@
1
1
  const powertools = require('node-powertools');
2
2
  const yargs = require('yargs/yargs');
3
3
  const { hideBin } = require('yargs/helpers');
4
+ const chalk = require('chalk');
4
5
 
5
6
  function ServerManager(command, options) {
6
7
  const self = this;
@@ -26,20 +27,23 @@ ServerManager.prototype.monitor = function (command, options) {
26
27
  options.log = options.log === undefined ? true : options.log;
27
28
 
28
29
  // Log
29
- console.log('Starting server...', command);
30
+ log(`Starting server (command=${command})`);
30
31
 
31
32
  // Start the server
32
33
  await powertools.execute(command, options, (serverProcess) => {
33
34
  serverProcess.on('exit', (code) => {
35
+ const string = `(code=${code}, timestamp=${new Date().toISOString()})`;
34
36
  if (code !== 0) {
35
- console.log('Server crashed. Restarting...');
37
+ error(`Server crashed (${string})`);
38
+ error(`Restarting in 1 second...`);
36
39
 
37
40
  // Restart the server
38
41
  setTimeout(function () {
42
+ error(`Restarting server...`);
39
43
  self.monitor();
40
44
  }, 1000);
41
45
  } else {
42
- console.log('Server stopped manually.');
46
+ log(`Server stopped safely (${string})`);
43
47
  }
44
48
  });
45
49
  })
@@ -48,6 +52,14 @@ ServerManager.prototype.monitor = function (command, options) {
48
52
  });
49
53
  };
50
54
 
55
+ function log() {
56
+ console.log(chalk.blue('[ServerManager]:'), ...arguments);
57
+ }
58
+
59
+ function error() {
60
+ console.error(chalk.red('[ServerManager]:'), ...arguments);
61
+ }
62
+
51
63
  // Check if the script is run directly from the command line
52
64
  if (require.main === module) {
53
65
  const manager = new ServerManager();