profoundjs 6.0.3 → 6.0.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.
@@ -1,4 +1,6 @@
1
1
 
2
+ "use strict";
3
+
2
4
  const child_process = require("child_process");
3
5
  const path = require("path");
4
6
 
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ /*
4
+ This script outputs the configuration file location.
5
+ It's used by Profound Installer
6
+
7
+ Any changes to the behavior may require changes to the "install_info.json" file or Profound Installer.
8
+
9
+ */
10
+
11
+ require("dotenv").config();
12
+ const iutils = require("./install_utils.js");
13
+
14
+ process.stdout.write(iutils.getConfigPath());
@@ -127,7 +127,25 @@
127
127
  }
128
128
  ],
129
129
  "commands": {
130
- "validate": "node complete_install.js --silent --validate",
131
- "install": "node complete_install.js --silent"
130
+ "config_file": {
131
+ "command": "node getConfigPath.js",
132
+ "cwd": "setup"
133
+ },
134
+ "install": {
135
+ "command": "node completeInstall.js --silent",
136
+ "cwd": "setup"
137
+ },
138
+ "install_validate": {
139
+ "command": "node completeInstall.js --silent --validate",
140
+ "cwd": "setup"
141
+ },
142
+ "remove": {
143
+ "command": "node removeExtraComponents.js --silent",
144
+ "cwd": "setup"
145
+ },
146
+ "remove_report": {
147
+ "command": "node removeExtraComponents.js --dry-run",
148
+ "cwd": "setup"
149
+ }
132
150
  }
133
151
  }
@@ -12,7 +12,7 @@
12
12
  "profoundui"
13
13
  ],
14
14
  "dependencies": {
15
- "profoundjs": "^6.0.3"
15
+ "profoundjs": "^6.0.4"
16
16
  },
17
17
  "scripts": {
18
18
  "start": "node start.js"
Binary file
@@ -0,0 +1,204 @@
1
+
2
+ "use strict";
3
+
4
+ /*
5
+ Discovers and removes additional components that exist outside of the package installation directory.
6
+
7
+ It's used by Profound Installer
8
+
9
+ Any changes to the behavior may require changes to the "install_info.json" file or Profound Installer.
10
+ */
11
+ const child_process = require("child_process");
12
+ require("dotenv").config();
13
+ const minimist = require("minimist");
14
+ const iutils = require("./install_utils.js");
15
+ const readline = require("readline");
16
+
17
+ const IBMi = iutils.isIBMi();
18
+
19
+ (async () => {
20
+ try {
21
+
22
+ // Parse arguments.
23
+ const argDefs = {
24
+ alias: {
25
+ "h": "help",
26
+ "d": "dry-run",
27
+ "s": "silent"
28
+ },
29
+ boolean: [
30
+ "h",
31
+ "d",
32
+ "s"
33
+ ],
34
+ unknown: function(arg) {
35
+ console.error("removeExtraComponents.js: Unknown argument:", arg);
36
+ process.exit(1);
37
+ }
38
+ };
39
+ const args = minimist(process.argv.slice(2), argDefs);
40
+
41
+ // Show help and quit, if requested.
42
+ if (args["help"] === true) {
43
+ const HELP = `Usage: node removeExtraComponents.js [OPTION]
44
+ -h, --help Print this help and exit.
45
+ -d, --dry-run Report what items would be removed, without removing them.
46
+ -s, --silent Bypass confirmation prompt.
47
+
48
+ Removes components that exist outside of the package installation directory:
49
+ * IBM i Connector library, based on config setting: "connectorLibrary"
50
+ * IBM i STRTCPSVR instance configuration.
51
+
52
+ This script does not uninstall the package itself.
53
+ It is intended to be used before uninstalling the package via NPM.
54
+ `;
55
+ console.log(HELP);
56
+ process.exit(0);
57
+ }
58
+
59
+ // Get config.
60
+ const deployDir = iutils.getDeployDir();
61
+ if (!deployDir) {
62
+ console.error("removeExtraComponents.js: Can't find deployment directory.");
63
+ process.exit(1);
64
+ }
65
+ const configPath = iutils.getConfigPath();
66
+ let config;
67
+ try {
68
+ config = require(configPath);
69
+ }
70
+ catch (error) {
71
+ console.error("removeExtraComponents.js: Unable to read configuration file: " + configPath);
72
+ console.error("removeExtraComponents.js:", error.message);
73
+ process.exit(1);
74
+ }
75
+
76
+ let connectorLibrary, connectorIASP;
77
+ let instances = [];
78
+ const messages = [];
79
+ if (IBMi) {
80
+ // Get STRTCPSVR instance configs, if any.
81
+ instances = iutils.getIBMiInstances(deployDir);
82
+ for (const instance of instances) {
83
+ messages.push("IBM i STRTCPSVR instance configuration " + instance.name);
84
+ }
85
+
86
+ // Get Connector library details, if any.
87
+ connectorLibrary = config.connectorLibrary;
88
+ connectorIASP = config.connectorIASP;
89
+ if (connectorIASP === undefined) {
90
+ connectorIASP = "*SYSBAS";
91
+ }
92
+ if (connectorLibrary !== undefined) {
93
+ let exists = false;
94
+ try {
95
+ // Determine if library exists.
96
+ // This is a weird way to do it...
97
+ // This allows us to check for the library even if the IASP is not mounted to the IFS and not in the job current ASP group.
98
+ execCL(`qsys/dsplib lib(${connectorLibrary}) aspdev(${connectorIASP}) output(*)`, true);
99
+ exists = true;
100
+ }
101
+ catch (error) {
102
+ let handle = false;
103
+ if (error.stderr) {
104
+ const match = error.stderr.toString().match(/^(CPF.{4}): /);
105
+ if (match) {
106
+ const msgid = match[1];
107
+ handle = (msgid === "CPF2110"); // Library not found.
108
+ }
109
+ }
110
+ if (!handle) {
111
+ throw error;
112
+ }
113
+ }
114
+ if (exists) {
115
+ messages.push("IBM i Connector library " + connectorLibrary + " in ASP device " + connectorIASP);
116
+ }
117
+ else {
118
+ connectorLibrary = connectorIASP = undefined;
119
+ }
120
+ }
121
+ }
122
+
123
+ // Report and quit, if requested.
124
+ if (args["dry-run"] === true) {
125
+ for (const message of messages) {
126
+ console.log(message);
127
+ }
128
+ process.exit(0);
129
+ }
130
+
131
+ if (messages.length === 0) {
132
+ console.log("No additional components to remove.");
133
+ process.exit(0);
134
+ }
135
+
136
+ if (args["silent"] !== true) {
137
+ // Confirm removal.
138
+ console.log("The following items will be removed:\n");
139
+ for (const message of messages) {
140
+ console.log(message);
141
+ }
142
+ let answer = await new Promise(resolve => {
143
+ const readlineInterface = readline.createInterface({
144
+ input: process.stdin,
145
+ output: process.stdout,
146
+ terminal: false
147
+ });
148
+ readlineInterface.question("\nAre you sure you want to proceed (y/n)? ", function(answer) {
149
+ readlineInterface.close();
150
+ resolve(answer);
151
+ });
152
+ });
153
+ answer = answer.trim().toLowerCase();
154
+ if (answer === "") {
155
+ answer = "n";
156
+ }
157
+ if (answer !== "y") {
158
+ console.log("Removal of extra components canceled.");
159
+ process.exit(0);
160
+ }
161
+ }
162
+
163
+ for (const instance of instances) {
164
+ execCL(`QSYS/ENDTCPSVR SERVER(*PJS) INSTANCE(${instance.name})`);
165
+ // This should generally work as shutdown is relatively fast.
166
+ await new Promise(resolve => setTimeout(resolve, 10000));
167
+ exec(`/usr/bin/rm -rf '/profoundjs-base/instances/${instance.name}'`);
168
+ }
169
+ if (connectorLibrary !== undefined) {
170
+ execCL(`qsys/dltlib lib(${connectorLibrary}) aspdev(${connectorIASP})`);
171
+ }
172
+ console.log("Removal of extra components complete.");
173
+ process.stdin.destroy();
174
+
175
+ }
176
+ catch (error) {
177
+ process.stdin.destroy();
178
+ console.error(error);
179
+ process.exit(1);
180
+ }
181
+ })();
182
+
183
+ function execCL(command, quiet) {
184
+ command = `/usr/bin/system '${escapeQuotes(command)}'`;
185
+ return exec(command, quiet);
186
+ function escapeQuotes(input) {
187
+ return input.replace(/'/g, "'\\''");
188
+ }
189
+ }
190
+
191
+ function exec(command, quiet = false) {
192
+ if (quiet !== true) {
193
+ console.log("Executing command:", command);
194
+ }
195
+ const opts = {
196
+ env: {
197
+ QIBM_USE_DESCRIPTOR_STDIO: "Y",
198
+ QIBM_MULTI_THREADED: "N",
199
+ },
200
+ stdio: "pipe",
201
+ windowsHide: true
202
+ };
203
+ return child_process.execSync(command, opts).toString();
204
+ }