rb-homer 1.7.3 → 1.7.4

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/index.js CHANGED
@@ -62,20 +62,21 @@ else if (validCommand(commands.first, "listen", "l") || validCommand(commands.fi
62
62
  if (validCommand(commands.first, "serve", "serve")) {
63
63
  console.log("live reload started");
64
64
 
65
- var server = require('websocket').server;
66
- var http = require('http');
67
- var socket = new server({
68
- httpServer: http.createServer().listen(31415).on('error', function (err) { console.log("Port 31415 is busy, defaulting to rb listen. Maybe you are running rb serve in another instance?"); })
69
- });
70
- var connection = {};
65
+ const WebSocket = require('ws');
66
+ const wss = new WebSocket.Server({ port: 31415 })
67
+ .on('error', function (err) {
68
+ console.log("Port 31415 is busy, defaulting to rb listen. Maybe you are running rb serve in another instance?");
69
+ });
70
+
71
+ let activeConnection = null;
71
72
 
72
- socket.on('request', function (request) {
73
- connection = request.accept(null, request.origin);
73
+ wss.on('connection', function(ws) {
74
+ activeConnection = ws;
74
75
  });
75
76
 
76
77
  global.sendUTF = function () {
77
- if (connection.connected) {
78
- connection.sendUTF("reload");
78
+ if (activeConnection && activeConnection.readyState === WebSocket.OPEN) {
79
+ activeConnection.send("reload");
79
80
  }
80
81
  }
81
82
  }
@@ -291,51 +292,47 @@ else if (validCommand(commands.first, "app", "a") && commands.second) {
291
292
  });
292
293
 
293
294
  function createApp(rbConfigMod) {
294
- var q = require("q");
295
- var deferred = q.defer();
296
- console.log(rbConfigMod);
297
-
298
- fetch("https://api.rambase.net/system/applications/api-operations/100385/instances?$access_token=" + rbConfigMod.access_token,
299
- {
300
- method: "POST",
301
- headers: {
302
- "Content-Type": "application/json"
303
- },
304
- body: JSON.stringify({ parameters: { lookupKey: componentName, description: componentName, namespace:'', contentType: 'component/html5' } })
305
- })
306
- .then(response => {
307
- if (response.status !== 200) {
308
- deferred.reject();
309
- return;
310
- }
311
- return response.json();
312
- })
313
- .then(body => {
314
- if (body && body.operationInstance && body.operationInstance.objectReference && body.operationInstance.objectReference.objectId) {
315
- deferred.resolve({ appNo: body.operationInstance.objectReference.objectId, rbConfigMod: rbConfigMod });
316
- }
317
- else if (body && body.operationInstance && body.operationInstance.systemJob && body.operationInstance.systemJob.objectId > 0) {
318
- console.log("polling...");
319
- pollForStatus(body.operationInstance.operationInstanceLink, deferred);
320
- }
321
- else {
322
- console.log(body.message);
323
- console.log("Error creating component.");
324
- if (body && body.operationInstance.error) {
325
- console.log(body.operationInstance.error.message);
326
- console.log(body.operationInstance.error.stackTrace);
295
+ return new Promise((resolve, reject) => {
296
+ console.log(rbConfigMod);
297
+
298
+ fetch("https://api.rambase.net/system/applications/api-operations/100385/instances?$access_token=" + rbConfigMod.access_token,
299
+ {
300
+ method: "POST",
301
+ headers: {
302
+ "Content-Type": "application/json"
303
+ },
304
+ body: JSON.stringify({ parameters: { lookupKey: componentName, description: componentName, namespace:'', contentType: 'component/html5' } })
305
+ })
306
+ .then(response => {
307
+ if (response.status !== 200) {
308
+ reject();
309
+ return;
327
310
  }
328
- deferred.reject();
329
- }
330
- })
331
- .catch(error => {
332
- console.error('Error:', error);
333
- deferred.reject();
311
+ return response.json();
312
+ })
313
+ .then(body => {
314
+ if (body && body.operationInstance && body.operationInstance.objectReference && body.operationInstance.objectReference.objectId) {
315
+ resolve({ appNo: body.operationInstance.objectReference.objectId, rbConfigMod: rbConfigMod });
316
+ }
317
+ else if (body && body.operationInstance && body.operationInstance.systemJob && body.operationInstance.systemJob.objectId > 0) {
318
+ console.log("polling...");
319
+ pollForStatus(body.operationInstance.operationInstanceLink, resolve, reject);
320
+ }
321
+ else {
322
+ console.log(body.message);
323
+ console.log("Error creating component.");
324
+ if (body && body.operationInstance.error) {
325
+ console.log(body.operationInstance.error.message);
326
+ console.log(body.operationInstance.error.stackTrace);
327
+ }
328
+ reject();
329
+ }
330
+ })
331
+ .catch(error => {
332
+ console.error('Error:', error);
333
+ reject();
334
+ });
334
335
  });
335
-
336
-
337
-
338
- return deferred.promise;
339
336
  }
340
337
  }
341
338
  else if (validCommand(commands.first, "app", "a") && !commands.second) {
@@ -403,7 +400,7 @@ else if (validCommand(commands.first, "run", "run") && !commands.second) {
403
400
  rambaseUrl = "https://www.rambase.net/Default.aspx?target=" + rbConfig.ramBaseName + "&debug=true#/" + compInfo.appName + "/";
404
401
  }
405
402
 
406
- const opn = require('opn');
403
+ const opn = require('open');
407
404
  opn(rambaseUrl).catch(() => {
408
405
  opn(rambaseUrl);
409
406
  });
@@ -415,7 +412,7 @@ else if (validCommand(commands.first, "run", "run") && commands.second) {
415
412
  rambaseUrl = "https://www.rambase.net/Default.aspx?target=" + rbConfig.ramBaseName + "&debug=true#/" + commands.second + "/";
416
413
  }
417
414
 
418
- const opn = require('opn');
415
+ const opn = require('open');
419
416
  opn(rambaseUrl).catch(() => {
420
417
  opn(rambaseUrl);
421
418
  });
@@ -613,7 +610,7 @@ function getComponentNameAndNo(path) {
613
610
 
614
611
  }
615
612
 
616
- async function pollForStatus(link, deferred, firstTimeStamp) {
613
+ async function pollForStatus(link, resolve, reject, firstTimeStamp) {
617
614
  if (!firstTimeStamp) {
618
615
  firstTimeStamp = Date.now();
619
616
  }
@@ -623,22 +620,22 @@ async function pollForStatus(link, deferred, firstTimeStamp) {
623
620
 
624
621
  if (!data || !data.operationInstance || data.operationInstance.error) {
625
622
  console.log(data.operationInstance.error.message, 'Operation Failed');
626
- deferred.reject(data);
623
+ reject(data);
627
624
  }
628
625
  else {
629
626
  const pollStatus = data.operationInstance.status;
630
627
  if (!pollStatus || (pollStatus !== 7 && pollStatus !== 9)) {
631
628
  if ((Date.now() - firstTimeStamp) / 1000 < 120) { //Poll for 2 min
632
629
  // Not finished, poll again
633
- setTimeout(() => pollForStatus(link, deferred), 2000);
630
+ setTimeout(() => pollForStatus(link, resolve, reject, firstTimeStamp), 2000);
634
631
  }
635
632
  else {
636
- deferred.reject();
633
+ reject();
637
634
  }
638
635
  }
639
636
  else if (pollStatus === 9) {
640
637
  // Finished
641
- deferred.resolve({ appNo: data.operationInstance.objectReference.objectId });
638
+ resolve({ appNo: data.operationInstance.objectReference.objectId });
642
639
  }
643
640
  else {
644
641
  console.log("Error creating component.");
@@ -646,12 +643,12 @@ async function pollForStatus(link, deferred, firstTimeStamp) {
646
643
  console.log(data.operationInstance.error.message);
647
644
  console.log(data.operationInstance.error.stackTrace);
648
645
  }
649
- deferred.reject();
646
+ reject();
650
647
  }
651
648
  }
652
649
  } catch (error) {
653
650
  console.log(error.message);
654
- deferred.reject(error);
651
+ reject(error);
655
652
  }
656
653
  }
657
654