kourou 0.26.2 → 0.27.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.
- package/README.md +1 -1
- package/lib/commands/sdk/execute.d.ts +1 -0
- package/lib/commands/sdk/execute.js +21 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
3
4
|
const command_1 = require("@oclif/command");
|
|
4
5
|
const lodash_1 = require("lodash");
|
|
5
6
|
const editor_1 = require("../../support/editor");
|
|
6
7
|
const common_1 = require("../../common");
|
|
7
8
|
const kuzzle_1 = require("../../support/kuzzle");
|
|
9
|
+
const typescript_1 = (0, tslib_1.__importDefault)(require("typescript"));
|
|
10
|
+
const node_vm_1 = (0, tslib_1.__importDefault)(require("node:vm"));
|
|
8
11
|
class SdkExecute extends common_1.Kommand {
|
|
9
12
|
constructor() {
|
|
10
13
|
super(...arguments);
|
|
@@ -12,25 +15,36 @@ class SdkExecute extends common_1.Kommand {
|
|
|
12
15
|
}
|
|
13
16
|
async beforeConnect() {
|
|
14
17
|
this.code = this.stdin || this.args.code || "// paste your code here";
|
|
18
|
+
try {
|
|
19
|
+
node_vm_1.default.runInContext(this.code, node_vm_1.default.createContext({}));
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
if (e.name === "SyntaxError") {
|
|
23
|
+
const result = typescript_1.default.transpileModule(this.code, { compilerOptions: { module: typescript_1.default.ModuleKind.CommonJS } });
|
|
24
|
+
this.code = result.outputText;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
15
27
|
if (this.haveSubscription) {
|
|
16
28
|
this.sdkOptions.protocol = "ws";
|
|
17
29
|
}
|
|
18
30
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
throw new Error("No code provided.");
|
|
22
|
-
}
|
|
23
|
-
let userError = null;
|
|
24
|
-
const variables = (this.flags.var || [])
|
|
31
|
+
getVariables() {
|
|
32
|
+
return (this.flags.var || [])
|
|
25
33
|
.map((nameValue) => {
|
|
26
34
|
const [name, value] = nameValue.split("=");
|
|
27
35
|
return ` let ${name} = ${value};`;
|
|
28
36
|
})
|
|
29
37
|
.join("\n");
|
|
38
|
+
}
|
|
39
|
+
async runSafe() {
|
|
40
|
+
if ((0, lodash_1.isEmpty)(this.code)) {
|
|
41
|
+
throw new Error("No code provided.");
|
|
42
|
+
}
|
|
43
|
+
let userError = null;
|
|
30
44
|
this.code = `
|
|
31
45
|
(async () => {
|
|
32
46
|
try {
|
|
33
|
-
${
|
|
47
|
+
${this.getVariables()}
|
|
34
48
|
${this.code}
|
|
35
49
|
}
|
|
36
50
|
catch (error) {
|