profoundjs 6.3.0 → 6.4.0

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.
@@ -316,7 +316,7 @@ Valid arguments for --silent mode:
316
316
  if (config.connectorLibrary !== undefined) {
317
317
  setupArgs.push("--ibmi-connector-library");
318
318
  }
319
- if (svrname) {
319
+ if (svrname) {
320
320
  setupArgs.push("--ibmi-instance=" + svrname);
321
321
  if (autostart) {
322
322
  setupArgs.push("--ibmi-instance-autostart");
@@ -427,6 +427,25 @@ function validateName(name) {
427
427
  return true;
428
428
  }
429
429
 
430
+ function validateLibrary(name) {
431
+ const err = validateName(name);
432
+ if (err === true) {
433
+ if (iutils.libraryExists(name)) return "Library " + name.toUpperCase() + " already exists. Please use a different name.";
434
+ }
435
+ else return err;
436
+ return true;
437
+ }
438
+
439
+ function validateServer(name) {
440
+ const err = validateName(name);
441
+ if (err === true) {
442
+ const exists = iutils.getIBMiInstances().some(el => el.name === name.toUpperCase());
443
+ if (exists) return "Server Instance " + name.toUpperCase() + " already exists. Please use a different name.";
444
+ }
445
+ else return err;
446
+ return true;
447
+ }
448
+
430
449
  function validateIASP(name) {
431
450
  const error = iutils.validateIBMiIASP(name);
432
451
  if (error) {
@@ -804,9 +823,15 @@ function validate(question, answer) {
804
823
  else if (question.id === "puiInstance") {
805
824
  validator = validatePUIInstance;
806
825
  }
826
+ else if (question.id === "connectorLibrary") {
827
+ validator = validateLibrary;
828
+ }
807
829
  else if (question.id === "connectorIASP") {
808
830
  validator = validateIASP;
809
831
  }
832
+ else if (question.id === "strtcpsvr_svrname") {
833
+ validator = validateServer;
834
+ }
810
835
  else if (question.type === "boolean") {
811
836
  validator = validateYesNo;
812
837
  }
@@ -5,6 +5,7 @@
5
5
  Utilities for PJS install/setup process.
6
6
  */
7
7
 
8
+ const child_process = require("child_process");
8
9
  const fs = require("fs");
9
10
  const os = require("os");
10
11
  const path = require("path");
@@ -24,6 +25,7 @@ exports.getConfigPath = function() {
24
25
 
25
26
  exports.getDeployDir = function() {
26
27
  const dirParts = __dirname.split(path.sep);
28
+ // eslint-disable-next-line no-empty
27
29
  while (dirParts.length > 0 && dirParts.pop() !== "node_modules") {};
28
30
  if (dirParts.length > 0) {
29
31
  return dirParts.join(path.sep);
@@ -121,6 +123,33 @@ exports.isIBMi = function() {
121
123
  return (os.platform() === "os400" || (os.platform() === "aix" && os.type() === "OS400"));
122
124
  };
123
125
 
126
+ exports.libraryExists = function(name) {
127
+ if (typeof name !== "string" || name.trim() === "") {
128
+ throw new Error("Library name is required.");
129
+ }
130
+ if (!exports.isIBMi()) {
131
+ throw new Error("This function is not valid on this platform.");
132
+ }
133
+ let exists;
134
+ try {
135
+ child_process.execSync(
136
+ `/usr/bin/system 'qsys/chkobj obj(${name.trim()}) objtype(*lib) aut(*none)'`,
137
+ {
138
+ shell: "/QOpenSys/usr/bin/qsh",
139
+ stdio: ["ignore", "pipe", "pipe"]
140
+ }
141
+ );
142
+ exists = true;
143
+ }
144
+ catch (error) {
145
+ if (!Buffer.isBuffer(error.stderr) || !error.stderr.toString().startsWith("CPF9801")) {
146
+ throw error;
147
+ }
148
+ exists = false;
149
+ }
150
+ return exists;
151
+ };
152
+
124
153
  if (exports.getDeployDir()) {
125
154
  require("dotenv").config(
126
155
  {
Binary file
@@ -0,0 +1,84 @@
1
+
2
+ module.exports = {
3
+
4
+ name: "Math-Operation",
5
+
6
+ // The title that is displayed for this sample plugin on the plugin selection
7
+ text: "Math Operation",
8
+
9
+ // The plugin category that the sample plugin will be placed into.
10
+ // A category will be created if the category name does not currently exist
11
+ category: "Sample User Plugins",
12
+
13
+ // The help text that is displayed when the help icon is clicked on this plugin's menu
14
+ help: `This plugin does a math operation set by the user for 2 different numbers from 2 widget sources`,
15
+
16
+ // Specifies if the plugin is a client-side or server-side step. A plugin is server-side by default.
17
+ clientSide: true,
18
+
19
+ context: "rdf",
20
+
21
+ // An array used to generate the plugin questions and assign values set by the user.
22
+ questions: [
23
+
24
+ {
25
+ id: "firstNumber",
26
+ text: "ID of Widget containing the first number",
27
+ required: true,
28
+ insertDynamic: true,
29
+ dynamicSource: "widgets"
30
+ },
31
+
32
+ {
33
+ id: "secondNumber",
34
+ text: "ID of Widget containing the second number",
35
+ required: true,
36
+ insertDynamic: true,
37
+ dynamicSource: "widgets"
38
+ },
39
+
40
+ {
41
+ id: "operation",
42
+ text: "Math operation",
43
+ required: true,
44
+ type: "dropdown",
45
+ source: ["+","-","*","/"],
46
+ required: true
47
+ },
48
+
49
+ {
50
+ id: "result",
51
+ text: "ID of Widget where result will be stored",
52
+ required: true,
53
+ insertDynamic: true,
54
+ dynamicSource: "widgets"
55
+ }
56
+ ],
57
+
58
+ // This is where code is generated for the plugin once the questions are answered.
59
+ // You can also see this code via the "convert to code" plugin icon.
60
+ generator: function(answers) {
61
+
62
+ let result = 0;
63
+ let code = "";
64
+
65
+ switch (answers["operation"]) {
66
+
67
+ case "+":
68
+ code = 'pui.set( "' + answers.result + '", parseInt( pui.get("' + answers.firstNumber + '") ) + parseInt( pui.get("' + answers.secondNumber + '") ) );';
69
+ break;
70
+ case "-":
71
+ code = 'pui.set( "' + answers.result + '", parseInt( pui.get("' + answers.firstNumber + '") ) - parseInt( pui.get("' + answers.secondNumber + '") ) );';
72
+ break;
73
+ case "*":
74
+ code = 'pui.set( "' + answers.result + '", parseInt( pui.get("' + answers.firstNumber + '") ) * parseInt( pui.get("' + answers.secondNumber + '") ) );';
75
+ break;
76
+ case "/":
77
+ code = 'pui.set( "' + answers.result + '", parseInt( pui.get("' + answers.firstNumber + '") ) / parseInt( pui.get("' + answers.secondNumber + '") ) );';
78
+ break;
79
+
80
+ }
81
+
82
+ return code;
83
+ }
84
+ }
package/setup/setup.js CHANGED
@@ -253,6 +253,15 @@ let SILENT_MODE = false;
253
253
  log("Creating modules directory.");
254
254
  fs.mkdirSync(path.join(deployDir, "modules"));
255
255
  }
256
+
257
+ // Create plugins directory.
258
+ if (directoryExists(path.join(deployDir, "plugins"))) {
259
+ log("plugins directory exists.");
260
+ }
261
+ else {
262
+ log("Creating plugins directory.");
263
+ fs.mkdirSync(path.join(deployDir, "plugins"));
264
+ }
256
265
 
257
266
  // Grant PROFOUNDJS user all permissions to modules directory tree.
258
267
  if (IBMi) {
@@ -280,6 +289,15 @@ let SILENT_MODE = false;
280
289
  log("Creating puidnlexit.js.");
281
290
  copyFile(path.join(__dirname, "modules", "puidnlexit.js"), path.join(deployDir, "modules"), "utf8");
282
291
  }
292
+
293
+ // Create mathoperation.js.
294
+ if (fileExists(path.join(deployDir, "plugins", "mathoperation.js"))) {
295
+ log("mathoperation.js file exists.");
296
+ }
297
+ else {
298
+ log("Creating mathoperation.js.");
299
+ copyFile(path.join(__dirname, "plugins", "mathoperation.js"), path.join(deployDir, "plugins"), "utf8");
300
+ }
283
301
 
284
302
  // Create samples directory.
285
303
  if (directoryExists(path.join(deployDir, "modules", "pjssamples"))) {