@kumologica/sdk 3.0.0-alpha4

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.
Files changed (76) hide show
  1. package/README.md +52 -0
  2. package/bin/kl.js +2 -0
  3. package/cli/KumologicaError.js +17 -0
  4. package/cli/cli.js +7 -0
  5. package/cli/commands/build-commands/aws.js +49 -0
  6. package/cli/commands/build-commands/azure.js +43 -0
  7. package/cli/commands/build-commands/kumohub.js +49 -0
  8. package/cli/commands/build.js +6 -0
  9. package/cli/commands/create-commands/create-project-iteratively.js +49 -0
  10. package/cli/commands/create-commands/index.js +5 -0
  11. package/cli/commands/create.js +66 -0
  12. package/cli/commands/deploy-commands/kumohub.js +114 -0
  13. package/cli/commands/deploy.js +6 -0
  14. package/cli/commands/doc-commands/html.js +60 -0
  15. package/cli/commands/doc.js +6 -0
  16. package/cli/commands/export-commands/cloudformation.js +371 -0
  17. package/cli/commands/export-commands/serverless.js +164 -0
  18. package/cli/commands/export-commands/terraform-commands/aws.js +193 -0
  19. package/cli/commands/export-commands/terraform-commands/azure.js +148 -0
  20. package/cli/commands/export-commands/terraform.js +6 -0
  21. package/cli/commands/export-commands/utils/validator.js +195 -0
  22. package/cli/commands/export.js +6 -0
  23. package/cli/commands/list-templates.js +24 -0
  24. package/cli/commands/open.js +53 -0
  25. package/cli/commands/start.js +165 -0
  26. package/cli/commands/test/TestSuiteRunner.js +76 -0
  27. package/cli/commands/test.js +123 -0
  28. package/cli/utils/download-template-from-repo.js +346 -0
  29. package/cli/utils/download-test.js +12 -0
  30. package/cli/utils/download.js +119 -0
  31. package/cli/utils/fs/copy-dir-contents-sync.js +15 -0
  32. package/cli/utils/fs/create-zip-file.js +39 -0
  33. package/cli/utils/fs/dir-exists-sync.js +14 -0
  34. package/cli/utils/fs/dir-exists.js +17 -0
  35. package/cli/utils/fs/file-exists-sync.js +14 -0
  36. package/cli/utils/fs/file-exists.js +12 -0
  37. package/cli/utils/fs/get-tmp-dir-path.js +22 -0
  38. package/cli/utils/fs/parse.js +40 -0
  39. package/cli/utils/fs/read-file-sync.js +11 -0
  40. package/cli/utils/fs/read-file.js +10 -0
  41. package/cli/utils/fs/safe-move-file.js +58 -0
  42. package/cli/utils/fs/walk-dir-sync.js +34 -0
  43. package/cli/utils/fs/write-file-sync.js +31 -0
  44. package/cli/utils/fs/write-file.js +32 -0
  45. package/cli/utils/logger.js +26 -0
  46. package/cli/utils/rename-service.js +49 -0
  47. package/package.json +72 -0
  48. package/src/api/core/comms.js +141 -0
  49. package/src/api/core/context.js +296 -0
  50. package/src/api/core/flows.js +286 -0
  51. package/src/api/core/index.js +29 -0
  52. package/src/api/core/library.js +106 -0
  53. package/src/api/core/nodes.js +476 -0
  54. package/src/api/core/projects.js +426 -0
  55. package/src/api/core/rest/context.js +42 -0
  56. package/src/api/core/rest/flow.js +53 -0
  57. package/src/api/core/rest/flows.js +53 -0
  58. package/src/api/core/rest/index.js +171 -0
  59. package/src/api/core/rest/nodes.js +164 -0
  60. package/src/api/core/rest/util.js +53 -0
  61. package/src/api/core/settings.js +287 -0
  62. package/src/api/tools/base/DesignerTool.js +108 -0
  63. package/src/api/tools/core/flow.js +58 -0
  64. package/src/api/tools/core/index.js +18 -0
  65. package/src/api/tools/core/node.js +77 -0
  66. package/src/api/tools/debugger/index.js +193 -0
  67. package/src/api/tools/filemanager/index.js +127 -0
  68. package/src/api/tools/git/index.js +103 -0
  69. package/src/api/tools/index.js +13 -0
  70. package/src/api/tools/test/index.js +56 -0
  71. package/src/api/tools/test/lib/TestCaseRunner.js +105 -0
  72. package/src/api/tools/test/lib/fixtures/example3-flow.json +148 -0
  73. package/src/api/tools/test/lib/fixtures/package.json +6 -0
  74. package/src/api/tools/test/lib/fixtures/s3-event.js +43 -0
  75. package/src/api/tools/test/lib/reporters/index.js +120 -0
  76. package/src/server/DesignerServer.js +141 -0
@@ -0,0 +1,193 @@
1
+ const { exp } = require('@kumologica/builder');
2
+
3
+ exports.command = 'aws';
4
+ exports.desc = `Export terraform.tf.json file to deploy kumologica flow into AWS using terraform framework"`;
5
+
6
+ exports.builder = {
7
+ "flow-file-name": {
8
+ describe: "The name of kumologica flow file.\n Auto search if not provided.",
9
+ type: 'string',
10
+ alias: 'f',
11
+ nargs: 1
12
+ },
13
+ "lambda-name": {
14
+ describe: "The name of lambda function,\n default to flow name",
15
+ type: 'string',
16
+ alias: 'l',
17
+ nargs: 1
18
+ },
19
+ "zip-file-name": {
20
+ describe: "The name of zip file of built lambda",
21
+ demandOption: "The name of zip file is required.",
22
+ type: 'string',
23
+ alias: 'z',
24
+ nargs: 1
25
+ },
26
+ "role-name": {
27
+ describe: "The name of lambda role, default to {lambda-name}-role",
28
+ type: 'string',
29
+ alias: 'o',
30
+ nargs: 1
31
+ },
32
+ "bucket-name": {
33
+ describe: "The name of bucket where zipped lambda is loaded from",
34
+ type: 'string',
35
+ alias: 'b',
36
+ nargs: 1
37
+ },
38
+ timeout: {
39
+ describe: "The time in seconds flow lambda is allowed to run, default: 3, max: 900",
40
+ type: 'number',
41
+ alias: 't',
42
+ nargs: 1
43
+ },
44
+ "memory-size": {
45
+ describe: "The amount of memory allocated to function, default 128 (MB), value must be multiple of 64 (MB)",
46
+ type: 'number',
47
+ alias: 'm',
48
+ nargs: 1
49
+ },
50
+ description: {
51
+ describe: "The description of a function",
52
+ type: 'string',
53
+ alias: 'd',
54
+ nargs: 1
55
+ },
56
+ environment: {
57
+ describe: `Environment variables, JSON Syntax: '{"Variables": {"string": "string" ...}'}`,
58
+ type: 'string',
59
+ alias: 'e',
60
+ nargs: 1
61
+ },
62
+ tags: {
63
+ describe: 'Tags, JSON Syntax:{"string": "string" ...}',
64
+ type: 'string',
65
+ alias: 'g',
66
+ nargs: 1
67
+ },
68
+ "tracing-config": {
69
+ describe: 'X-Ray config, JSON Syntax: {"Mode": "Active"|"PassThrough"} ',
70
+ type: 'string',
71
+ alias: 'x',
72
+ nargs: 1
73
+ },
74
+ "kms-key-arn": {
75
+ describe: "The ARN of KMS key to encrypt env variables",
76
+ type: 'string',
77
+ alias: 'k',
78
+ nargs: 1
79
+ },
80
+ "vpc-config": {
81
+ describe: 'The list of security groups and subnets of VPC, JSON syntax: { "SubnetIds": ["string", ...],"SecurityGroupIds": ["string", ...]}',
82
+ type: 'string',
83
+ alias: 'v',
84
+ nargs: 1
85
+ },
86
+ runtime: {
87
+ describe: "The runtime, only nodejs runtimes allowed: nodejs|nodejs4.3|nodejs6.10|nodejs8.10|nodejs10.x|nodejs12.x|...",
88
+ type: 'string',
89
+ alias: 'r',
90
+ nargs: 1
91
+ },
92
+ "dead-letter-config": {
93
+ describe: 'The arn of the dead letter queue or topic JSON Syntax: {"TargetArn": "string"}',
94
+ type: 'string',
95
+ alias: 'q',
96
+ nargs: 1
97
+ },
98
+ "file-system-configs": {
99
+ describe: 'AWS EFS config details, JSON Syntax: [{"Arn": "string","LocalMountPath": "string"} ...]',
100
+ type: 'string',
101
+ alias: 's',
102
+ nargs: 1
103
+ }
104
+ }
105
+
106
+ function display(argv) {
107
+ console.log(`\nBuilding aws lambda artefacts with following parameters: \n`);
108
+ console.log('flow-file-name: %s', argv["flow-file-name"]||'');
109
+ console.log('zip-file-name: %s', argv["zip-file-name"]||'');
110
+ console.log('lambda-name: %s', argv["lambda-name"]||'');
111
+ console.log('role-name: %s', argv["role-name"]||'');
112
+ console.log('bucket-name: %s', argv["bucket-name"]);
113
+ console.log('timeout: %s', argv.timeout||'');
114
+ console.log('memory-size: %s', argv["memory-size"]||'');
115
+ console.log('description: %s', argv.decription||'');
116
+ console.log('environment: %s', argv.environment||'');
117
+ console.log('tags: %s', argv["tags"]||'');
118
+ console.log('tracing-config: %s', argv["tracing-config"]||'');
119
+ console.log('kms-key-arn: %s', argv["kms-key-arn"]||'');
120
+ console.log('vpc-config: %s', argv["vpc-config"]||'');
121
+ console.log('runtime: %s', argv.runtime||'');
122
+ console.log('dead-letter-config: %s', argv["dead-letter-config"]||'');
123
+ console.log('file-system-configs: %s', argv["file-system-configs"]||'');
124
+ }
125
+
126
+ function validateNotEmpty(name, v) {
127
+ if (!v) {
128
+ throw new Error (`Validation error: parameter '${name}' can not be empty`);
129
+ }
130
+ }
131
+
132
+ function validateJson(name, s) {
133
+
134
+ if (typeof s !== 'string') {
135
+ throw new Error (`Validation error: parameter '${name}' value is not string: '${s}'`);
136
+ }
137
+
138
+ let type;
139
+ try {
140
+ const result = JSON.parse(s);
141
+ type = Object.prototype.toString.call(result);
142
+ } catch (e) {
143
+ throw new Error (`Validation error: parameter '${name}': ${e.message}`);
144
+ }
145
+
146
+ if (!(type === '[object Object]' || type === '[object Array]')) {
147
+ throw new Error (`Validation error: parameter '${name}' value is not in JSON format: '${s}'`);
148
+ }
149
+
150
+ console.log(`Parameter ${name} is valid`);
151
+ }
152
+
153
+ function validate(argv) {
154
+
155
+ validateNotEmpty('bucket-name', argv["bucket-name"]);
156
+
157
+ if (argv.environment) {
158
+ validateJson("environment", argv.environment);
159
+ }
160
+ if (argv.tags) {
161
+ validateJson("tags", argv.tags);
162
+ }
163
+ if (argv["tracing-config"]) {
164
+ validateJson("tracing-config", argv["tracing-config"]);
165
+ }
166
+ if (argv["vpc-config"]) {
167
+ validateJson("vpc-config", argv["vpc-config"]);
168
+ }
169
+ if (argv["dead-letter-config"]) {
170
+ validateJson("dead-letter-config", argv["dead-letter-config"]);
171
+ }
172
+ if (argv["file-system-configs"]) {
173
+ validateJson("file-system-configs", argv["file-system-configs"]);
174
+ }
175
+ if (argv.runtime) {
176
+ if (!argv.runtime.startsWith("nodejs")) {
177
+ throw new Error (`Validation error: parameter 'runtime' must be one of supported nodejs values: nodejs|nodejs4.3|nodejs6.10|nodejs8.10|nodejs10.x|nodejs12.x|...`);
178
+ }
179
+ }
180
+ }
181
+
182
+ exports.handler = function (argv) {
183
+ display(argv);
184
+
185
+ try {
186
+ validate(argv);
187
+ exp('terraform', 'aws', argv);
188
+
189
+ } catch (e) {
190
+ console.log(`${e.message}`);
191
+ process.exit(1);
192
+ }
193
+ }
@@ -0,0 +1,148 @@
1
+ const { exp } = require('@kumologica/builder');
2
+
3
+ exports.command = 'azure';
4
+ exports.desc = "Export template.tf.json file to deploy kumologica flow into Azure using terraform framework.\nThe template.tf.json file is placed in deploy subdirectory.";
5
+
6
+ exports.builder = {
7
+ "project-directory": {
8
+ describe: "The root directory where kumologica project is located.\n Default to current process directory if not provided.",
9
+ type: 'string',
10
+ nargs: 1
11
+ },
12
+ "flow-file-name": {
13
+ describe: "The name of kumologica flow file.\n Auto search if not provided.",
14
+ type: 'string',
15
+ alias: 'f',
16
+ nargs: 1
17
+ },
18
+ "azure-application-name": {
19
+ describe: "The name of azure application,\n default to flow name",
20
+ type: 'string',
21
+ alias: 'a',
22
+ nargs: 1
23
+ },
24
+ "azure-function-name": {
25
+ describe: "The name of azure function,\n default to flow name",
26
+ type: 'string',
27
+ nargs: 1
28
+ },
29
+ "zip-file-name": {
30
+ describe: "The name of zip file with built azure function",
31
+ demandOption: "The name of zip file is required.",
32
+ type: 'string',
33
+ alias: 'z',
34
+ nargs: 1
35
+ },
36
+ "os-type": {
37
+ describe: "The operating system for function, either linux or windows. Value ignored if service-plan-id is provided.",
38
+ type: 'string',
39
+ alias: 's',
40
+ nargs: 1
41
+ },
42
+ "hosting-plan": {
43
+ describe: "The hosting plan for function, either consumption or premium. Value ignored if service-plan-id is provided.",
44
+ type: 'string',
45
+ alias: 'h',
46
+ nargs: 1
47
+ },
48
+ "location": {
49
+ describe: "The location (region) where function should be installed",
50
+ demandOption: "The location is required.",
51
+ type: 'string',
52
+ alias: 'l',
53
+ nargs: 1
54
+ },
55
+ "resource-group-name": {
56
+ describe: "The resource group name the function should be part of. New resource group: {azure-application-name}-group will be created if resource group name not provided.",
57
+ type: 'string',
58
+ alias: 'g',
59
+ nargs: 1
60
+ },
61
+ "service-plan-id": {
62
+ describe: "The service plan id used by function. New service plan: {azure-application-name}-service-plan will be created if service plan id not provided.",
63
+ type: 'string',
64
+ alias: 'p',
65
+ nargs: 1
66
+ },
67
+ tags: {
68
+ describe: `Tags, JSON format wrapped in '': '{"name": "value" ...}'`,
69
+ type: 'string',
70
+ alias: 't',
71
+ nargs: 1
72
+ },
73
+ environment: {
74
+ describe: `Environment variables, JSON format wrapped in '': '{"name": "value" ...}'`,
75
+ type: 'string',
76
+ alias: 'e',
77
+ nargs: 1
78
+ }
79
+ }
80
+
81
+ function display(argv) {
82
+ console.log(`\nBuilding terraform script for azure function with following parameters: \n`);
83
+ console.log('project-directory: %s', argv["project-directory"] || '');
84
+ console.log('azure-application-name: %s', argv["azure-application-name"]||'');
85
+ console.log('azure-function-name: %s', argv["azure-function-name"] || '');
86
+ console.log('flow-file-name: %s', argv["flow-file-name"]||'');
87
+ console.log('zip-file-name: %s', argv["zip-file-name"]||'');
88
+ console.log('os-type: %s', argv["os-type"]||'');
89
+ console.log('location: %s', argv["location"]||'');
90
+ console.log('resource-group-name: %s', argv["resource-group-name"]||'');
91
+ console.log('service-plan-id: %s', argv["service-plan-id"]||'');
92
+ console.log('hosting-plan: %s', argv["hosting-plan"]||'');
93
+ console.log('tags: %s', argv["tags"]||'');
94
+ console.log('environment: %s', argv["environment"]||'');
95
+ }
96
+
97
+
98
+ function validateJson(name, s) {
99
+
100
+ if (typeof s !== 'string') {
101
+ throw new Error (`Validation error: parameter '${name}' value is not string: '${s}'`);
102
+ }
103
+
104
+ let type;
105
+ try {
106
+ const result = JSON.parse(s);
107
+ type = Object.prototype.toString.call(result);
108
+ } catch (e) {
109
+ throw new Error (`Validation error: parameter '${name}': ${e.message}`);
110
+ }
111
+
112
+ if (!(type === '[object Object]' || type === '[object Array]')) {
113
+ throw new Error (`Validation error: parameter '${name}' value is not in JSON format: '${s}'`);
114
+ }
115
+
116
+ console.log(`Parameter ${name} is valid`);
117
+ }
118
+
119
+ function validate(argv) {
120
+
121
+ if (argv.tags) {
122
+ validateJson("tags", argv.tags);
123
+ }
124
+ if (argv.environment) {
125
+ validateJson("environment", argv.environment);
126
+ }
127
+ if (!argv["service-plan-id"]) {
128
+ if (!argv["hosting-plan"]) {
129
+ throw new Error("hosting-plan parameter is required when service-plan-id is not provided.");
130
+ }
131
+ if (!argv["os-type"]) {
132
+ throw new Error("os-type parameter is required when service-plan-id is not provided.");
133
+ }
134
+ }
135
+ }
136
+
137
+ exports.handler = function (argv) {
138
+ display(argv);
139
+
140
+ try {
141
+ validate(argv);
142
+ exp('terraform', 'azure', argv);
143
+
144
+ } catch (e) {
145
+ console.log(`${e.message}`);
146
+ process.exit(1);
147
+ }
148
+ }
@@ -0,0 +1,6 @@
1
+ exports.command = 'terraform <platform>'
2
+ exports.desc = 'Export terraform scripts for kumologica flow'
3
+ exports.builder = function (yargs) {
4
+ return yargs.commandDir('terraform-commands')
5
+ }
6
+ exports.handler = function (argv) {}
@@ -0,0 +1,195 @@
1
+ const triggersSchema = {
2
+ "definitions": {},
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "$id": "https://example.com/object1616988234.json",
5
+ "title": "Root",
6
+ "type": "array",
7
+ "default": [],
8
+ "items":{
9
+ "$id": "#root/items",
10
+ "title": "Items",
11
+ "type": "object",
12
+ "properties": {
13
+ "event": {
14
+ "$id": "#root/items/event",
15
+ "title": "Event",
16
+ "type": "object",
17
+ "required": [
18
+ "expression"
19
+ ],
20
+ additionalProperties: false,
21
+ "properties": {
22
+ "expression": {
23
+ "$id": "#root/items/event/expression",
24
+ "title": "Cron/Schedule Expression",
25
+ "type": "string"
26
+ },
27
+ "name": {
28
+ "$id": "#root/items/event/name",
29
+ "title": "Event name",
30
+ "type": "string"
31
+ },
32
+ "reference": {
33
+ "$id": "#root/items/event/reference",
34
+ "title": "Event Listener reference",
35
+ "type": "string"
36
+ }
37
+ }
38
+ },
39
+ "partnerEvent": {
40
+ "$id": "#root/items/partnerEvent",
41
+ "title": "Partner Event",
42
+ "type": "object",
43
+ "required": [
44
+ "partnerEventBusName"
45
+ ],
46
+ additionalProperties: false,
47
+ "properties": {
48
+ "partnerEventBusName": {
49
+ "$id": "#root/items/partnerEvent/partnerEventBusName",
50
+ "title": "Partner Event Bus Name",
51
+ "type": "string"
52
+ },
53
+ "detailType": {
54
+ "$id": "#root/items/partnerEvent/detailType",
55
+ "title": "detail-type of the partner event",
56
+ "type": "string"
57
+ },
58
+ "name": {
59
+ "$id": "#root/items/partnerEvent/name",
60
+ "title": "Name of the Rule for the event",
61
+ "type": "string"
62
+ }
63
+ }
64
+ },
65
+ "sqs": {
66
+ "$id": "#root/items/sqs",
67
+ "title": "Sqs",
68
+ "type": "object",
69
+ "required": [
70
+ "queueArn"
71
+ ],
72
+ additionalProperties: false,
73
+ "properties": {
74
+ "queueArn": {
75
+ "$id": "#root/items/sqs/queueArn",
76
+ "title": "Queuearn",
77
+ "type": "string",
78
+ "pattern": "^.*$"
79
+ },
80
+ "batchSize": {
81
+ "$id": "#root/items/sqs/batchSize",
82
+ "title": "Batchsize",
83
+ "type": "integer"
84
+ }
85
+ }
86
+ },
87
+ "sns": {
88
+ "$id": "#root/items/sns",
89
+ "title": "Sns",
90
+ "type": "object",
91
+ "required": [
92
+ "topicArn"
93
+ ],
94
+ additionalProperties: false,
95
+ "properties": {
96
+ "topicArn": {
97
+ "$id": "#root/items/sns/topicArn",
98
+ "title": "Topicarn",
99
+ "type": "string",
100
+ "pattern": "^.*$"
101
+ }
102
+ }
103
+ },
104
+ "api": {
105
+ "$id": "#root/items/api",
106
+ "title": "Api",
107
+ "type": "object",
108
+ required: [],
109
+ additionalProperties: false,
110
+ required: ["apiId"],
111
+ "properties": {
112
+ "apiId": {
113
+ "$id": "#root/items/api/apiId",
114
+ "title": "ApiId",
115
+ "type": "string",
116
+ "pattern": "^.*$"
117
+ },
118
+ "apiName": {
119
+ "$id": "#root/items/api/apiName",
120
+ "title": "ApiName",
121
+ "type": "string",
122
+ "pattern": "^.*$"
123
+ },
124
+ "stage": {
125
+ "$id": "#root/items/api/stage",
126
+ "title": "Stage",
127
+ "type": "string",
128
+ "pattern": "^.*$"
129
+ },
130
+ "parentId": {
131
+ "$id": "#root/items/api/parentId",
132
+ "title": "Parentid",
133
+ "type": "string",
134
+ "pattern": "^.*$"
135
+ },
136
+ "resource": {
137
+ "$id": "#root/items/api/resource",
138
+ "title": "Resource",
139
+ "type": "string",
140
+ "pattern": "^.*$"
141
+ },
142
+ "authorizerId": {
143
+ "$id": "#root/items/api/authorizerId",
144
+ "title": "Authorizerid",
145
+ "type": "string",
146
+ "pattern": "^.*$"
147
+ },
148
+ "authorizerType": {
149
+ "$id": "#root/items/api/authorizerType",
150
+ "title": "AuthorizerType",
151
+ "type": "string",
152
+ "pattern": "^.*$"
153
+ },
154
+ "apiKeyRequired": {
155
+ "$id": "#root/items/api/apiKeyRequired",
156
+ "title": "ApiKeyRequired",
157
+ "type": "boolean"
158
+ },
159
+ "scopes": {
160
+ "$id": "#root/items/api/scopes",
161
+ "title": "Scopes",
162
+ "type": "array",
163
+ "items":{
164
+ "$id": "#root/items/api/scopes/items",
165
+ "title": "Items",
166
+ "type": "string",
167
+ "pattern": "^.*$"
168
+ }
169
+ }
170
+ }
171
+ }
172
+
173
+ }
174
+ }
175
+ };
176
+
177
+ function validate(type, obj) {
178
+ var Ajv = require('ajv');
179
+ var ajv = new Ajv({allErrors: true});
180
+ let valid = false;
181
+
182
+ switch(type) {
183
+ case 'triggers':
184
+ valid = ajv.validate(triggersSchema, obj);
185
+ break;
186
+ }
187
+
188
+ if (!valid) {
189
+ throw new Error(`JSON schema validation errors: ${JSON.stringify(ajv.errors)}`);
190
+ }
191
+ }
192
+
193
+ module.exports = {
194
+ validate
195
+ }
@@ -0,0 +1,6 @@
1
+ exports.command = 'export <language>'
2
+ exports.desc = 'Export deployment scripts for kumologica flow'
3
+ exports.builder = function (yargs) {
4
+ return yargs.commandDir('export-commands')
5
+ }
6
+ exports.handler = function (argv) {}
@@ -0,0 +1,24 @@
1
+ const { listAvailableTemplates } = require('../utils/download-template-from-repo');
2
+ const { logNotice, logError, logInfo } = require('../utils/logger');
3
+
4
+ exports.command = 'list-templates'
5
+ exports.desc = 'List of available templates'
6
+ exports.handler = async function (argv) {
7
+ try {
8
+ logInfo('List of available templates:');
9
+ let templates = await readerFriendly(listAvailableTemplates())
10
+ logNotice(templates);
11
+ }catch(e){
12
+ logError(e.message);
13
+ }
14
+ }
15
+
16
+ // Utils
17
+ async function readerFriendly(templates) {
18
+ let result = [];
19
+ templates = await templates;
20
+ templates.forEach(t => {
21
+ result.push(`"${t}"`);
22
+ });
23
+ return result.join(',')
24
+ }
@@ -0,0 +1,53 @@
1
+ const path = require('path');
2
+ const { logError } = require('../utils/logger');
3
+
4
+ const rootPath = path.join(__dirname, '..', '..',);
5
+
6
+ function startElectron(projectDir) {
7
+ console.debug(`Project directory: ${projectDir}`);
8
+ console.debug(`Root directory: ${rootPath}`);
9
+ let electronPath = process.env["KUMOLOGICA_ELECTRON_PATH"] || path.join(rootPath, "node_modules", ".bin", "electron");
10
+ console.debug(`Electron path: ${electronPath}`);
11
+
12
+ const { spawn } = require("child_process");
13
+ const e = spawn(electronPath,
14
+ ['.', projectDir],
15
+ {
16
+ cwd: rootPath,
17
+ shell: true,
18
+ env: {
19
+ ELECTRON_RUN_AS_NODE: 1,
20
+ NODE_VERSION: "18.16.0"
21
+ }
22
+ });
23
+
24
+ e.stdout.on("data", data => {
25
+ console.log(data.toString().trim());
26
+ });
27
+
28
+ e.stderr.on("data", data => {
29
+ logError(data.toString().trim());
30
+ });
31
+
32
+ e.on('error', (error) => {
33
+ console.log(`==> ${error.message}`);
34
+ });
35
+
36
+ e.on("close", code => {
37
+ console.log(`exited with code ${code}`);
38
+ });
39
+ }
40
+
41
+ exports.command = "open [project_directory]"
42
+ exports.builder = (yargs) => {
43
+ yargs.positional(`project_directory`, {
44
+ type: 'string',
45
+ describe: 'Path to a valid kumologica project. (Optional)'
46
+ })
47
+ }
48
+
49
+ exports.desc = 'Open Kumologica Designer'
50
+ exports.handler = ({ project_directory }) => {
51
+ let projectDir = project_directory? path.resolve(project_directory): undefined ;
52
+ startElectron(projectDir);
53
+ }