@kapeta/local-cluster-service 0.14.0 → 0.14.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [0.14.2](https://github.com/kapetacom/local-cluster-service/compare/v0.14.1...v0.14.2) (2023-08-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Use kapeta std lib for child process ([#58](https://github.com/kapetacom/local-cluster-service/issues/58)) ([43254ce](https://github.com/kapetacom/local-cluster-service/commit/43254cef67c86f8260150073d44b5803cd20e527))
7
+
8
+ ## [0.14.1](https://github.com/kapetacom/local-cluster-service/compare/v0.14.0...v0.14.1) (2023-08-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Generate code in the background ([#57](https://github.com/kapetacom/local-cluster-service/issues/57)) ([2e14827](https://github.com/kapetacom/local-cluster-service/commit/2e1482713ee52a19aed8edb9810107f1f340537c))
14
+
1
15
  # [0.14.0](https://github.com/kapetacom/local-cluster-service/compare/v0.13.0...v0.14.0) (2023-08-05)
2
16
 
3
17
 
@@ -25,6 +25,7 @@ declare class AssetManager {
25
25
  getAsset(ref: string, noCache?: boolean, autoFetch?: boolean): Promise<EnrichedAsset | undefined>;
26
26
  createAsset(path: string, yaml: BlockDefinition): Promise<EnrichedAsset[]>;
27
27
  updateAsset(ref: string, yaml: BlockDefinition): Promise<void>;
28
+ private maybeGenerateCode;
28
29
  importFile(filePath: string): Promise<EnrichedAsset[]>;
29
30
  unregisterAsset(ref: string): Promise<void>;
30
31
  installAsset(ref: string): Promise<import("./taskManager").Task<void>[] | undefined>;
@@ -16,6 +16,7 @@ const repositoryManager_1 = require("./repositoryManager");
16
16
  const nodejs_registry_utils_1 = require("@kapeta/nodejs-registry-utils");
17
17
  const definitionsManager_1 = require("./definitionsManager");
18
18
  const utils_1 = require("./utils/utils");
19
+ const taskManager_1 = require("./taskManager");
19
20
  function enrichAsset(asset) {
20
21
  return {
21
22
  ref: `kapeta://${asset.definition.metadata.name}:${asset.version}`,
@@ -109,16 +110,18 @@ class AssetManager {
109
110
  if (!node_fs_1.default.existsSync(dirName)) {
110
111
  fs_extra_1.default.mkdirpSync(dirName);
111
112
  }
113
+ console.log('Wrote to ' + path);
112
114
  node_fs_1.default.writeFileSync(path, yaml_1.default.stringify(yaml));
113
115
  const asset = await this.importFile(path);
114
- if (codeGeneratorManager_1.codeGeneratorManager.canGenerateCode(yaml)) {
115
- await codeGeneratorManager_1.codeGeneratorManager.generate(path, yaml);
116
- }
116
+ console.log('Imported');
117
117
  this.cache.flushAll();
118
+ definitionsManager_1.definitionsManager.clearCache();
119
+ const ref = `kapeta://${yaml.metadata.name}:local`;
120
+ this.maybeGenerateCode(ref, path, yaml);
118
121
  return asset;
119
122
  }
120
123
  async updateAsset(ref, yaml) {
121
- const asset = await this.getAsset(ref, true);
124
+ const asset = await this.getAsset(ref, true, false);
122
125
  if (!asset) {
123
126
  throw new Error('Attempted to update unknown asset: ' + ref);
124
127
  }
@@ -128,14 +131,24 @@ class AssetManager {
128
131
  if (!asset.ymlPath) {
129
132
  throw new Error('Attempted to update corrupted asset: ' + ref);
130
133
  }
134
+ console.log('Wrote to ' + asset.ymlPath);
131
135
  node_fs_1.default.writeFileSync(asset.ymlPath, yaml_1.default.stringify(yaml));
132
136
  this.cache.flushAll();
133
- if (codeGeneratorManager_1.codeGeneratorManager.canGenerateCode(yaml)) {
134
- await codeGeneratorManager_1.codeGeneratorManager.generate(asset.ymlPath, yaml);
135
- }
136
- else {
137
- console.log('Could not generate code for %s', yaml.kind ? yaml.kind : 'unknown yaml');
137
+ definitionsManager_1.definitionsManager.clearCache();
138
+ this.maybeGenerateCode(asset.ref, asset.ymlPath, yaml);
139
+ }
140
+ maybeGenerateCode(ref, ymlPath, block) {
141
+ ref = (0, utils_1.normalizeKapetaUri)(ref);
142
+ if (codeGeneratorManager_1.codeGeneratorManager.canGenerateCode(block)) {
143
+ const assetTitle = block.metadata.title ? block.metadata.title : (0, nodejs_utils_1.parseKapetaUri)(block.metadata.name).name;
144
+ taskManager_1.taskManager.add(`codegen:${ref}`, async () => {
145
+ await codeGeneratorManager_1.codeGeneratorManager.generate(ymlPath, block);
146
+ }, {
147
+ name: `Generating code for ${assetTitle}`,
148
+ });
149
+ return true;
138
150
  }
151
+ return false;
139
152
  }
140
153
  async importFile(filePath) {
141
154
  if (filePath.startsWith('file://')) {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.progressListener = void 0;
4
- const child_process_1 = require("child_process");
4
+ const nodejs_process_1 = require("@kapeta/nodejs-process");
5
5
  const socketManager_1 = require("./socketManager");
6
6
  class ProgressListener {
7
7
  socketManager;
@@ -14,18 +14,15 @@ class ProgressListener {
14
14
  message: `Running command "${command}"`,
15
15
  });
16
16
  return new Promise((resolve, reject) => {
17
- const child = (0, child_process_1.spawn)(command, {
17
+ const child = (0, nodejs_process_1.spawn)(command, [], {
18
18
  cwd: directory ? directory : process.cwd(),
19
19
  detached: true,
20
20
  shell: true,
21
21
  });
22
- child.stdout.on('data', (data) => {
23
- this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.toString() });
22
+ child.onData((data) => {
23
+ this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.line });
24
24
  });
25
- child.stderr.on('data', (data) => {
26
- this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.toString() });
27
- });
28
- child.on('exit', (exit, signal) => {
25
+ child.process.on('exit', (exit, signal) => {
29
26
  if (exit !== 0) {
30
27
  this.socketManager.emit(`install`, 'install:log', {
31
28
  type: 'info',
@@ -41,7 +38,7 @@ class ProgressListener {
41
38
  resolve({ exit, signal });
42
39
  }
43
40
  });
44
- child.on('error', (err) => {
41
+ child.process.on('error', (err) => {
45
42
  this.socketManager.emit(`install`, 'install:log', {
46
43
  type: 'info',
47
44
  message: `"${command}" failed: "${err.message}"`,
@@ -25,6 +25,7 @@ declare class AssetManager {
25
25
  getAsset(ref: string, noCache?: boolean, autoFetch?: boolean): Promise<EnrichedAsset | undefined>;
26
26
  createAsset(path: string, yaml: BlockDefinition): Promise<EnrichedAsset[]>;
27
27
  updateAsset(ref: string, yaml: BlockDefinition): Promise<void>;
28
+ private maybeGenerateCode;
28
29
  importFile(filePath: string): Promise<EnrichedAsset[]>;
29
30
  unregisterAsset(ref: string): Promise<void>;
30
31
  installAsset(ref: string): Promise<import("./taskManager").Task<void>[] | undefined>;
@@ -10,6 +10,7 @@ import { repositoryManager } from './repositoryManager';
10
10
  import { Actions } from '@kapeta/nodejs-registry-utils';
11
11
  import { definitionsManager } from './definitionsManager';
12
12
  import { normalizeKapetaUri } from './utils/utils';
13
+ import { taskManager } from "./taskManager";
13
14
  function enrichAsset(asset) {
14
15
  return {
15
16
  ref: `kapeta://${asset.definition.metadata.name}:${asset.version}`,
@@ -103,16 +104,18 @@ class AssetManager {
103
104
  if (!FS.existsSync(dirName)) {
104
105
  FSExtra.mkdirpSync(dirName);
105
106
  }
107
+ console.log('Wrote to ' + path);
106
108
  FS.writeFileSync(path, YAML.stringify(yaml));
107
109
  const asset = await this.importFile(path);
108
- if (codeGeneratorManager.canGenerateCode(yaml)) {
109
- await codeGeneratorManager.generate(path, yaml);
110
- }
110
+ console.log('Imported');
111
111
  this.cache.flushAll();
112
+ definitionsManager.clearCache();
113
+ const ref = `kapeta://${yaml.metadata.name}:local`;
114
+ this.maybeGenerateCode(ref, path, yaml);
112
115
  return asset;
113
116
  }
114
117
  async updateAsset(ref, yaml) {
115
- const asset = await this.getAsset(ref, true);
118
+ const asset = await this.getAsset(ref, true, false);
116
119
  if (!asset) {
117
120
  throw new Error('Attempted to update unknown asset: ' + ref);
118
121
  }
@@ -122,14 +125,24 @@ class AssetManager {
122
125
  if (!asset.ymlPath) {
123
126
  throw new Error('Attempted to update corrupted asset: ' + ref);
124
127
  }
128
+ console.log('Wrote to ' + asset.ymlPath);
125
129
  FS.writeFileSync(asset.ymlPath, YAML.stringify(yaml));
126
130
  this.cache.flushAll();
127
- if (codeGeneratorManager.canGenerateCode(yaml)) {
128
- await codeGeneratorManager.generate(asset.ymlPath, yaml);
129
- }
130
- else {
131
- console.log('Could not generate code for %s', yaml.kind ? yaml.kind : 'unknown yaml');
131
+ definitionsManager.clearCache();
132
+ this.maybeGenerateCode(asset.ref, asset.ymlPath, yaml);
133
+ }
134
+ maybeGenerateCode(ref, ymlPath, block) {
135
+ ref = normalizeKapetaUri(ref);
136
+ if (codeGeneratorManager.canGenerateCode(block)) {
137
+ const assetTitle = block.metadata.title ? block.metadata.title : parseKapetaUri(block.metadata.name).name;
138
+ taskManager.add(`codegen:${ref}`, async () => {
139
+ await codeGeneratorManager.generate(ymlPath, block);
140
+ }, {
141
+ name: `Generating code for ${assetTitle}`,
142
+ });
143
+ return true;
132
144
  }
145
+ return false;
133
146
  }
134
147
  async importFile(filePath) {
135
148
  if (filePath.startsWith('file://')) {
@@ -1,4 +1,4 @@
1
- import { spawn } from 'child_process';
1
+ import { spawn } from '@kapeta/nodejs-process';
2
2
  import { socketManager } from './socketManager';
3
3
  class ProgressListener {
4
4
  socketManager;
@@ -11,18 +11,15 @@ class ProgressListener {
11
11
  message: `Running command "${command}"`,
12
12
  });
13
13
  return new Promise((resolve, reject) => {
14
- const child = spawn(command, {
14
+ const child = spawn(command, [], {
15
15
  cwd: directory ? directory : process.cwd(),
16
16
  detached: true,
17
17
  shell: true,
18
18
  });
19
- child.stdout.on('data', (data) => {
20
- this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.toString() });
19
+ child.onData((data) => {
20
+ this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.line });
21
21
  });
22
- child.stderr.on('data', (data) => {
23
- this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.toString() });
24
- });
25
- child.on('exit', (exit, signal) => {
22
+ child.process.on('exit', (exit, signal) => {
26
23
  if (exit !== 0) {
27
24
  this.socketManager.emit(`install`, 'install:log', {
28
25
  type: 'info',
@@ -38,7 +35,7 @@ class ProgressListener {
38
35
  resolve({ exit, signal });
39
36
  }
40
37
  });
41
- child.on('error', (err) => {
38
+ child.process.on('error', (err) => {
42
39
  this.socketManager.emit(`install`, 'install:log', {
43
40
  type: 'info',
44
41
  message: `"${command}" failed: "${err.message}"`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -46,6 +46,7 @@
46
46
  "@kapeta/codegen": "<2",
47
47
  "@kapeta/local-cluster-config": ">= 0.2.3 <2",
48
48
  "@kapeta/nodejs-api-client": "<2",
49
+ "@kapeta/nodejs-process": "^1.1.0",
49
50
  "@kapeta/nodejs-registry-utils": "<2",
50
51
  "@kapeta/nodejs-utils": "<2",
51
52
  "@kapeta/schemas": "^0.0.58",
@@ -12,6 +12,7 @@ import { BlockDefinition } from '@kapeta/schemas';
12
12
  import { Actions } from '@kapeta/nodejs-registry-utils';
13
13
  import { definitionsManager } from './definitionsManager';
14
14
  import { normalizeKapetaUri } from './utils/utils';
15
+ import {taskManager} from "./taskManager";
15
16
 
16
17
  export interface EnrichedAsset {
17
18
  ref: string;
@@ -141,19 +142,24 @@ class AssetManager {
141
142
  FSExtra.mkdirpSync(dirName);
142
143
  }
143
144
 
145
+ console.log('Wrote to ' + path);
144
146
  FS.writeFileSync(path, YAML.stringify(yaml));
145
147
 
146
148
  const asset = await this.importFile(path);
149
+ console.log('Imported');
147
150
 
148
- if (codeGeneratorManager.canGenerateCode(yaml)) {
149
- await codeGeneratorManager.generate(path, yaml);
150
- }
151
151
  this.cache.flushAll();
152
+ definitionsManager.clearCache();
153
+
154
+ const ref = `kapeta://${yaml.metadata.name}:local`;
155
+
156
+ this.maybeGenerateCode(ref, path, yaml);
157
+
152
158
  return asset;
153
159
  }
154
160
 
155
161
  async updateAsset(ref: string, yaml: BlockDefinition) {
156
- const asset = await this.getAsset(ref, true);
162
+ const asset = await this.getAsset(ref, true, false);
157
163
  if (!asset) {
158
164
  throw new Error('Attempted to update unknown asset: ' + ref);
159
165
  }
@@ -166,13 +172,26 @@ class AssetManager {
166
172
  throw new Error('Attempted to update corrupted asset: ' + ref);
167
173
  }
168
174
 
175
+ console.log('Wrote to ' + asset.ymlPath);
169
176
  FS.writeFileSync(asset.ymlPath, YAML.stringify(yaml));
170
177
  this.cache.flushAll();
171
- if (codeGeneratorManager.canGenerateCode(yaml)) {
172
- await codeGeneratorManager.generate(asset.ymlPath, yaml);
173
- } else {
174
- console.log('Could not generate code for %s', yaml.kind ? yaml.kind : 'unknown yaml');
178
+ definitionsManager.clearCache();
179
+
180
+ this.maybeGenerateCode(asset.ref, asset.ymlPath, yaml);
181
+ }
182
+
183
+ private maybeGenerateCode(ref:string, ymlPath:string, block: BlockDefinition) {
184
+ ref = normalizeKapetaUri(ref);
185
+ if (codeGeneratorManager.canGenerateCode(block)) {
186
+ const assetTitle = block.metadata.title ? block.metadata.title : parseKapetaUri(block.metadata.name).name;
187
+ taskManager.add(`codegen:${ref}`, async () => {
188
+ await codeGeneratorManager.generate(ymlPath, block);
189
+ },{
190
+ name: `Generating code for ${assetTitle}`,
191
+ });
192
+ return true;
175
193
  }
194
+ return false;
176
195
  }
177
196
 
178
197
  async importFile(filePath: string) {
@@ -1,4 +1,4 @@
1
- import { spawn } from 'child_process';
1
+ import { spawn } from '@kapeta/nodejs-process';
2
2
  import { SocketManager, socketManager } from './socketManager';
3
3
  class ProgressListener {
4
4
  private socketManager: SocketManager;
@@ -14,21 +14,17 @@ class ProgressListener {
14
14
  });
15
15
 
16
16
  return new Promise((resolve, reject) => {
17
- const child = spawn(command, {
17
+ const child = spawn(command, [],{
18
18
  cwd: directory ? directory : process.cwd(),
19
19
  detached: true,
20
20
  shell: true,
21
21
  });
22
22
 
23
- child.stdout.on('data', (data) => {
24
- this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.toString() });
23
+ child.onData((data) => {
24
+ this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.line });
25
25
  });
26
26
 
27
- child.stderr.on('data', (data) => {
28
- this.socketManager.emit(`install`, 'install:log', { type: 'info', message: data.toString() });
29
- });
30
-
31
- child.on('exit', (exit, signal) => {
27
+ child.process.on('exit', (exit, signal) => {
32
28
  if (exit !== 0) {
33
29
  this.socketManager.emit(`install`, 'install:log', {
34
30
  type: 'info',
@@ -44,7 +40,7 @@ class ProgressListener {
44
40
  }
45
41
  });
46
42
 
47
- child.on('error', (err) => {
43
+ child.process.on('error', (err) => {
48
44
  this.socketManager.emit(`install`, 'install:log', {
49
45
  type: 'info',
50
46
  message: `"${command}" failed: "${err.message}"`,