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 CHANGED
@@ -27,7 +27,7 @@ $ npm install -g kourou
27
27
  $ kourou COMMAND
28
28
  running command...
29
29
  $ kourou (-v|--version|version)
30
- kourou/0.26.2 darwin-arm64 node-v18.17.1
30
+ kourou/0.27.0 darwin-arm64 node-v18.17.1
31
31
  $ kourou --help [COMMAND]
32
32
  USAGE
33
33
  $ kourou COMMAND
@@ -25,6 +25,7 @@ declare class SdkExecute extends Kommand {
25
25
  private code;
26
26
  static readStdin: boolean;
27
27
  beforeConnect(): Promise<void>;
28
+ getVariables(): any;
28
29
  runSafe(): Promise<void>;
29
30
  get haveSubscription(): boolean;
30
31
  }
@@ -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
- async runSafe() {
20
- if ((0, lodash_1.isEmpty)(this.code)) {
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
- ${variables}
47
+ ${this.getVariables()}
34
48
  ${this.code}
35
49
  }
36
50
  catch (error) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kourou",
3
3
  "description": "The CLI that helps you manage your Kuzzle instances",
4
- "version": "0.26.2",
4
+ "version": "0.27.0",
5
5
  "author": "The Kuzzle Team <support@kuzzle.io>",
6
6
  "bin": {
7
7
  "kourou": "./bin/run"