@kapeta/local-cluster-service 0.14.0 → 0.14.1
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,10 @@
|
|
1
|
+
## [0.14.1](https://github.com/kapetacom/local-cluster-service/compare/v0.14.0...v0.14.1) (2023-08-07)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* 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))
|
7
|
+
|
1
8
|
# [0.14.0](https://github.com/kapetacom/local-cluster-service/compare/v0.13.0...v0.14.0) (2023-08-05)
|
2
9
|
|
3
10
|
|
@@ -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
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
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://')) {
|
@@ -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
|
-
|
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
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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://')) {
|
package/package.json
CHANGED
package/src/assetManager.ts
CHANGED
@@ -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
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
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) {
|