@microtronics/studio-cli 0.9.1 → 0.10.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.
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.APM = void 0;
4
+ const vscode_uri_1 = require("vscode-uri");
5
+ const manifest_1 = require("../manifest");
6
+ const defaultFiles_1 = require("../defaultFiles");
7
+ const helper_1 = require("../helper");
8
+ var bufferToBase64 = helper_1.Helper.bufferToBase64;
9
+ const package_1 = require("./package");
10
+ const registryAPI_1 = require("../registryAPI");
11
+ var APM;
12
+ (function (APM) {
13
+ let TagPhase;
14
+ (function (TagPhase) {
15
+ /*alpha='alpha',
16
+ beta='beta',
17
+ rc='rc',*/
18
+ TagPhase["release"] = "release";
19
+ TagPhase["stage"] = "stage";
20
+ TagPhase["passive"] = "passive";
21
+ TagPhase["withdrawn"] = "withdrawn";
22
+ })(TagPhase = APM.TagPhase || (APM.TagPhase = {}));
23
+ /**
24
+ * The APM parts that are predefined
25
+ */
26
+ let Part;
27
+ (function (Part) {
28
+ Part["dde"] = "dde";
29
+ Part["dlo"] = "dlo";
30
+ Part["pov"] = "pov";
31
+ Part["blo"] = "blo";
32
+ })(Part = APM.Part || (APM.Part = {}));
33
+ /**
34
+ * Create new release tag
35
+ * @param cwd
36
+ * @param fs
37
+ * @param phase
38
+ */
39
+ async function createTag(cwd, fs, phase) {
40
+ const manifest = await manifest_1.Manifest.read(cwd, fs);
41
+ const { version, description, name, pov, engines, blo, publisher } = manifest;
42
+ const tagHeader = {
43
+ name: name,
44
+ abstract: description,
45
+ phase: phase,
46
+ author: publisher || '',
47
+ pov_location: manifest_1.Manifest.PovLocation.embedded,
48
+ version: version,
49
+ required_be: engines?.backend,
50
+ required_hwfw: engines?.hwfw?.join(';'),
51
+ required_productcode: engines?.productId?.join(';'),
52
+ blo_level: blo?.accessLevel || manifest_1.Manifest.BloAccessLevel.restricted
53
+ };
54
+ if (pov && pov.details) {
55
+ tagHeader.pov_location = manifest_1.Manifest.PovLocation.pure;
56
+ }
57
+ return await createBuffer(cwd, fs, manifest, tagHeader);
58
+ }
59
+ APM.createTag = createTag;
60
+ /**
61
+ * Create new dev tag.
62
+ * @param cwd
63
+ * @param fs
64
+ */
65
+ async function createDevTag(cwd, fs) {
66
+ const manifest = await manifest_1.Manifest.read(cwd, fs);
67
+ const { publisher, name, engines, blo } = manifest;
68
+ const apmTagHeader = {
69
+ name: name,
70
+ author: publisher || '',
71
+ abstract: '',
72
+ blo_level: blo?.accessLevel || manifest_1.Manifest.BloAccessLevel.restricted,
73
+ pip_id: '',
74
+ pov_details_lowlevel: false,
75
+ pov_location: manifest_1.Manifest.PovLocation.embedded,
76
+ required_be: engines?.backend,
77
+ required_hwfw: engines?.hwfw?.join(';'),
78
+ required_productcode: engines?.productId?.join(';'),
79
+ blo_autostart: false
80
+ };
81
+ if (manifest.pov?.details) {
82
+ apmTagHeader.pov_location = manifest_1.Manifest.PovLocation.pure;
83
+ }
84
+ return createBuffer(cwd, fs, manifest, apmTagHeader);
85
+ }
86
+ APM.createDevTag = createDevTag;
87
+ /**
88
+ * create FormData object that can be pushed to the store
89
+ * @private
90
+ * @param cwd
91
+ * @param fs
92
+ * @param manifest
93
+ * @param tagHeader
94
+ */
95
+ async function createBuffer(cwd, fs, manifest, tagHeader) {
96
+ const apmBuffer = new FormData();
97
+ apmBuffer.append('tag', JSON.stringify(tagHeader));
98
+ const xmlBlob = new Blob([await fs.readFile(vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.ddeXmlPath))]);
99
+ apmBuffer.append('bin/dde/xml', xmlBlob);
100
+ const amxBlob = new Blob([await fs.readFile(vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.mainAmxPath))]);
101
+ apmBuffer.append('bin/dlo/amx', amxBlob);
102
+ if (manifest.icon) {
103
+ const appIcon = await fs.readFile(vscode_uri_1.Utils.joinPath(cwd, manifest.icon));
104
+ const base64 = bufferToBase64(appIcon);
105
+ apmBuffer.append('previews/00.png', new Blob([`data:image/png;base64,${base64}`]));
106
+ }
107
+ // only validate readme and changelog if the current apm is bundled for a store release
108
+ if (Object.hasOwn(tagHeader, 'phase')) {
109
+ const readme = await package_1.Package.getReadmeFile(cwd, fs, tagHeader.name);
110
+ const changelog = await package_1.Package.getChangelogFile(cwd, fs);
111
+ apmBuffer.append(`previews/README.md`, new Blob([readme]));
112
+ apmBuffer.append(`previews/CHANGELOG.md`, new Blob([changelog]));
113
+ }
114
+ // handle pov binaries
115
+ if (manifest.pov?.details) {
116
+ // get files in details dir
117
+ await insertRelativePathFilesToBuffer(cwd, fs, apmBuffer, defaultFiles_1.DefaultFiles.filePaths.dist.povDetailsPath, 'bin/pov/details');
118
+ //site list not supported yet -> add an empty index.html
119
+ const emptyIndexHtml = new TextEncoder().encode(`<!DOCTYPE html><html lang="en">`);
120
+ apmBuffer.append('bin/pov/list/index.html', new Blob([emptyIndexHtml]));
121
+ }
122
+ // handle dfiles
123
+ const availableDfiles = await fs.findFiles(cwd, `${defaultFiles_1.DefaultFiles.filePaths.dist.dfilesPath}/*`);
124
+ for (const fileName of availableDfiles) {
125
+ const dfileBlob = new Blob([await fs.readFile(fileName)]);
126
+ apmBuffer.append(`bin/dfiles/${vscode_uri_1.Utils.basename(fileName)}`, dfileBlob);
127
+ }
128
+ // handle blo files
129
+ if (manifest.blo) {
130
+ // get files in blo dir
131
+ await insertRelativePathFilesToBuffer(cwd, fs, apmBuffer, defaultFiles_1.DefaultFiles.filePaths.dist.bloPath, 'bin/blo');
132
+ }
133
+ await addAdditionalFiles(cwd, fs, apmBuffer);
134
+ return apmBuffer;
135
+ }
136
+ APM.createBuffer = createBuffer;
137
+ /**
138
+ * Validate if the current user has access to the apm
139
+ */
140
+ async function validateAccess(cwd, fs, token, preventCreation, env) {
141
+ const manifest = await manifest_1.Manifest.read(cwd, fs);
142
+ if (!preventCreation) {
143
+ // throws if the specific setting is invalid
144
+ await validateSpecificSettings(token, manifest);
145
+ }
146
+ const { registry } = manifest;
147
+ let applicationId = registry?.id;
148
+ if (!applicationId && !preventCreation) {
149
+ applicationId = await registerNew(cwd, fs, token, manifest, env);
150
+ }
151
+ if (applicationId) {
152
+ const { publisher } = manifest;
153
+ if (!publisher) {
154
+ return null;
155
+ }
156
+ return {
157
+ id: applicationId,
158
+ ...(await registryAPI_1.Registry.getExistingApplication(token, publisher, applicationId, env))
159
+ };
160
+ }
161
+ return null;
162
+ }
163
+ APM.validateAccess = validateAccess;
164
+ /**
165
+ *
166
+ * @param cwd
167
+ * @param fs
168
+ * @param token
169
+ * @param manifest
170
+ * @param env
171
+ */
172
+ async function registerNew(cwd, fs, token, manifest, env) {
173
+ // only myDatanet -> ONE support not needed.
174
+ const backendTarget = 'myDatanet';
175
+ const { publisher, name, description, registry } = manifest;
176
+ const newApplication = {
177
+ name: name,
178
+ targetSystem: backendTarget,
179
+ description: description || '',
180
+ allowedBackends: registry?.allowedBackends ?? null
181
+ };
182
+ // create new application
183
+ const projectId = await registryAPI_1.Registry.createNewApplication(token, publisher, newApplication, env);
184
+ if (!projectId) {
185
+ throw new Error('Failed to initialize application');
186
+ }
187
+ manifest.registry = {
188
+ id: projectId,
189
+ allowedBackends: newApplication.allowedBackends,
190
+ target: backendTarget
191
+ };
192
+ // write the updated manifest to disk
193
+ await manifest_1.Manifest.write(cwd, fs, manifest);
194
+ return projectId;
195
+ }
196
+ APM.registerNew = registerNew;
197
+ /**
198
+ * Update the APM profile
199
+ * - allowedBackends, description and name will be upated
200
+ * @param cwd
201
+ * @param fs
202
+ * @param token
203
+ * @param env
204
+ */
205
+ async function updateProfile(cwd, fs, token, env) {
206
+ const { name, publisher, description, registry } = await manifest_1.Manifest.read(cwd, fs);
207
+ const applicationId = registry?.id;
208
+ await registryAPI_1.Registry.updateExistingApplication(token, publisher, applicationId, {
209
+ // @ts-ignore
210
+ allowedBackends: registry.allowedBackends,
211
+ description: description,
212
+ name: name,
213
+ targetSystem: 'myDatanet'
214
+ }, env);
215
+ }
216
+ APM.updateProfile = updateProfile;
217
+ /**
218
+ * Publish a new version to the store
219
+ * @param cwd
220
+ * @param fs
221
+ * @param token
222
+ * @param apmTag
223
+ * @param env
224
+ */
225
+ async function publishTag(cwd, fs, token, apmTag, env) {
226
+ const { publisher, registry, version } = await manifest_1.Manifest.read(cwd, fs);
227
+ return await registryAPI_1.Registry.publishApplicationVersion(token, publisher, registry?.id, version, apmTag, env);
228
+ }
229
+ APM.publishTag = publishTag;
230
+ })(APM || (exports.APM = APM = {}));
231
+ /**
232
+ * Find files in the given sourcePath and insert it at the correct place within the apmBuffer
233
+ * @param cwd
234
+ * @param fs
235
+ * @param apmBuffer
236
+ * @param sourcePath
237
+ * @param binPath
238
+ */
239
+ async function insertRelativePathFilesToBuffer(cwd, fs, apmBuffer, sourcePath, binPath) {
240
+ const apmPartFiles = await fs.findFiles(cwd, `${sourcePath}/**`);
241
+ for (const apmPartFile of apmPartFiles) {
242
+ const apmDistPath = vscode_uri_1.Utils.joinPath(cwd, sourcePath);
243
+ const relativePath = apmPartFile.path.substring(apmDistPath.path.length + 1);
244
+ const apmFileBlob = new Blob([await fs.readFile(vscode_uri_1.Utils.joinPath(cwd, `${sourcePath}/${relativePath}`))]);
245
+ apmBuffer.append(`${binPath}/${relativePath}`, apmFileBlob);
246
+ }
247
+ }
248
+ /**
249
+ * Add additional files to the apm buffer
250
+ *
251
+ * Files:
252
+ * - mdn_report_template.json
253
+ * @param cwd
254
+ * @param fs
255
+ * @param apmBuffer
256
+ */
257
+ async function addAdditionalFiles(cwd, fs, apmBuffer) {
258
+ const reportTemplate = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.reportTemplate);
259
+ if (await fs.stat(reportTemplate)) {
260
+ const reportTemplateBlob = new Blob([await fs.readFile(reportTemplate)]);
261
+ apmBuffer.append(`bin/pov/mdn_report_template.json`, reportTemplateBlob);
262
+ }
263
+ }
264
+ /**
265
+ * Validate manifest settings that are required for the APM
266
+ * @param token
267
+ * @param manifest
268
+ */
269
+ async function validateSpecificSettings(token, manifest) {
270
+ const { name, publisher, description, registry } = manifest;
271
+ const invalidName = await manifest_1.Manifest.validateProjectName(name);
272
+ if (invalidName) {
273
+ throw new Error(`name: ${invalidName}`);
274
+ }
275
+ const invalidDescription = await manifest_1.Manifest.validateDescription(description);
276
+ if (invalidDescription) {
277
+ throw new Error(`description: ${invalidDescription}`);
278
+ }
279
+ const invalidPublisher = (await manifest_1.Manifest.validatePublisherId(publisher)) || (await manifest_1.Manifest.validatePublisherOnline(token, publisher));
280
+ if (invalidPublisher) {
281
+ throw new Error(`publisher: ${invalidPublisher}`);
282
+ }
283
+ const invalidBackends = await manifest_1.Manifest.validateRegistryAllowedBackends(registry?.allowedBackends);
284
+ if (invalidBackends) {
285
+ throw new Error(`registry: ${invalidBackends}`);
286
+ }
287
+ }
288
+ //# sourceMappingURL=apm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/package/package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAIhC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAK5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,yBAAiB,OAAO,CAAC;IACxB;;;;;OAKG;IACH,SAAsB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,IAAI,iBAgBvE;IAED;;;;;;;OAOG;IACH,SAAsB,UAAU,CAC/B,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,OAAO,EACX,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,YAAY,EAAE,GAAG,CAAC,QAAQ,EAC1B,GAAG,GAAE,OAAO,CAAC,GAA4B,iBAuBzC;IAED;;;;;;OAMG;IACH,SAAsB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAY7E;IAED;;;;;OAKG;IACH,SAAsB,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,uBAY3D;CACD"}
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Package = void 0;
4
+ const vscode_uri_1 = require("vscode-uri");
5
+ const helper_1 = require("../helper");
6
+ const defaultFiles_1 = require("../defaultFiles");
7
+ var convertBlobToString = helper_1.Helper.convertBlobToString;
8
+ const apm_1 = require("./apm");
9
+ const dde_1 = require("../dde/dde");
10
+ const dlo_1 = require("../dlo/dlo");
11
+ const compiler_1 = require("../dlo/compiler");
12
+ const scriptRunner_1 = require("../scriptRunner");
13
+ const manifest_1 = require("../manifest");
14
+ const globals_1 = require("../globals");
15
+ var Package;
16
+ (function (Package) {
17
+ /**
18
+ * Build the whole project or only a specific part
19
+ * @param cwd
20
+ * @param fs
21
+ * @param apmPart - choose a specific part that should be build
22
+ */
23
+ async function buildAll(cwd, fs, apmPart) {
24
+ if (!apmPart || apmPart === apm_1.APM.Part.dde) {
25
+ await buildDDE(cwd, fs);
26
+ }
27
+ if (!apmPart || apmPart === apm_1.APM.Part.dlo) {
28
+ await buildDLO(cwd, fs);
29
+ }
30
+ if (!apmPart || apmPart === apm_1.APM.Part.pov) {
31
+ await scriptRunner_1.Shell.tryBuildPov(cwd, fs);
32
+ }
33
+ if (!apmPart || apmPart === apm_1.APM.Part.blo) {
34
+ await scriptRunner_1.Shell.tryBuildBlo(cwd, fs);
35
+ }
36
+ console.log('DONE');
37
+ }
38
+ Package.buildAll = buildAll;
39
+ /**
40
+ *
41
+ * @param cwd
42
+ * @param fs
43
+ * @param token
44
+ * @param releasePhase
45
+ * @param env
46
+ */
47
+ async function releaseAPM(cwd, fs, token, releasePhase, env = globals_1.Globals.ENV.production) {
48
+ if (!Object.values(apm_1.APM.TagPhase).includes(releasePhase)) {
49
+ throw new Error(`ReleasePhase: ${releasePhase} is not a valid release phase`);
50
+ }
51
+ await manifest_1.Manifest.validateManifest(cwd, fs);
52
+ const application = await apm_1.APM.validateAccess(cwd, fs, token, false, env);
53
+ if (!application) {
54
+ return;
55
+ }
56
+ // todo validate version
57
+ // build the complete project
58
+ await buildAll(cwd, fs);
59
+ // update the store apm with the actual name/description/...
60
+ await apm_1.APM.updateProfile(cwd, fs, token, env);
61
+ const tagContent = await apm_1.APM.createTag(cwd, fs, releasePhase);
62
+ const newTag = await apm_1.APM.publishTag(cwd, fs, token, tagContent, env);
63
+ console.log(`Tag "${newTag.version}" with phase "${newTag.phase}" published!`);
64
+ }
65
+ Package.releaseAPM = releaseAPM;
66
+ /**
67
+ * Read the projects README.md file
68
+ * validates if the file content is the initial content
69
+ * @param cwd
70
+ * @param fs
71
+ * @param projectName
72
+ */
73
+ async function getReadmeFile(cwd, fs, projectName) {
74
+ let fileBlob = undefined;
75
+ try {
76
+ fileBlob = await fs.readFile(vscode_uri_1.Utils.joinPath(cwd, 'README.md'));
77
+ }
78
+ catch (e) {
79
+ throw new Error('Could not find "README.md". "README.md" is required for publishing.');
80
+ }
81
+ const README_STRING = convertBlobToString(fileBlob);
82
+ if (README_STRING === defaultFiles_1.DefaultFiles.readme(projectName)) {
83
+ throw new Error('"README.md" matches the default template. Please write a brief project description.');
84
+ }
85
+ return fileBlob;
86
+ }
87
+ Package.getReadmeFile = getReadmeFile;
88
+ /**
89
+ * Read the projects CHANGELOG.md file
90
+ * validates if the file content is the initial content
91
+ * @param cwd
92
+ * @param fs
93
+ */
94
+ async function getChangelogFile(cwd, fs) {
95
+ let fileBlob = undefined;
96
+ try {
97
+ fileBlob = await fs.readFile(vscode_uri_1.Utils.joinPath(cwd, 'CHANGELOG.md'));
98
+ }
99
+ catch (e) {
100
+ throw new Error('Could not find "CHANGELOG.md". "CHANGELOG.md" is required for publishing.');
101
+ }
102
+ const CHANGELOG_STRING = convertBlobToString(fileBlob);
103
+ if (CHANGELOG_STRING === defaultFiles_1.DefaultFiles.changelog) {
104
+ throw new Error('"CHANGELOG.md" matches the default template.');
105
+ }
106
+ return fileBlob;
107
+ }
108
+ Package.getChangelogFile = getChangelogFile;
109
+ })(Package || (exports.Package = Package = {}));
110
+ /**
111
+ * Generates all needed files out of the dde declaration
112
+ * @param cwd
113
+ * @param fs
114
+ */
115
+ async function buildDDE(cwd, fs) {
116
+ const result = await dde_1.DDE.compileDDE(cwd, fs);
117
+ result.diagnostics.forEach(diagnostic => {
118
+ const message = `${diagnostic.file.path}: ${diagnostic.message}`;
119
+ if (diagnostic.level === 'error') {
120
+ console.error(message);
121
+ }
122
+ else if (diagnostic.level === 'warning') {
123
+ console.warn(message);
124
+ }
125
+ else {
126
+ console.log(message);
127
+ }
128
+ });
129
+ trowIfDiagnosticsHaveError(apm_1.APM.Part.dde, result.diagnostics);
130
+ if (result.ddeJSON) {
131
+ await dde_1.DDE.exportMyDatanetXML(cwd, fs, result.ddeJSON);
132
+ await dde_1.DDE.exportHistoryJson(cwd, fs, result.ddeJSON);
133
+ await dde_1.DDE.exportOpenApi(cwd, fs, result.ddeJSON);
134
+ await dde_1.DDE.exportAutoDloFiles(cwd, fs, result.ddeJSON);
135
+ await dlo_1.DLO.exportDloConfig(cwd, fs);
136
+ }
137
+ else {
138
+ throw new Error('Project has errors!');
139
+ }
140
+ }
141
+ async function buildDLO(cwd, fs) {
142
+ const compiler = new compiler_1.DloCompiler();
143
+ const { diagnostics } = await compiler.compile(cwd, fs);
144
+ trowIfDiagnosticsHaveError(apm_1.APM.Part.dlo, diagnostics);
145
+ }
146
+ function trowIfDiagnosticsHaveError(apmPart, diagnostics) {
147
+ diagnostics.forEach(diagnostic => {
148
+ if (diagnostic.level === 'error') {
149
+ throw new Error(`APM part '${apmPart}' has errors. Aborted.`);
150
+ }
151
+ });
152
+ }
153
+ //# sourceMappingURL=package.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registryAPI.d.ts","sourceRoot":"","sources":["../src/registryAPI.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAS,MAAM,oBAAoB,CAAC;AAKvD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;;cAKnD;AAED,yBAAiB,QAAQ,CAAC;IACzB;;OAEG;IACI,MAAM,SAAS;;KAIrB,CAAC;IAEF,KAAY,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,0BAA0B,CAAC,CAAC;IAC/E,KAAY,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAErE;;;;;OAKG;IACH,SAAsB,iBAAiB,CACtC,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,CAezB;IAED,SAAsB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,GAAE,OAAe,gBAcxG;CACD"}
1
+ {"version":3,"file":"registryAPI.d.ts","sourceRoot":"","sources":["../src/registryAPI.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;;cAKnD;AAED,yBAAiB,QAAQ,CAAC;IACzB,KAAY,SAAS,GAAG,MAAM,GAAG,IAAI,CAAC;IACtC;;OAEG;IACI,MAAM,SAAS;;KAIrB,CAAC;IAEF,KAAY,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,0BAA0B,CAAC,CAAC;IAC/E,KAAY,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAErE;;;;;OAKG;IACH,SAAsB,iBAAiB,CACtC,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,CAezB;IAED,SAAsB,mBAAmB,CAAC,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,GAAE,OAAe,gBAcpG;IAED,KAAY,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,CAAC;IAC3D,SAAsB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAoBnG;IAED,KAAY,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAAC;IAExE,SAAsB,oBAAoB,CACzC,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,iBAAiB,EACjC,GAAG,GAAE,OAAO,CAAC,GAA4B,sCA0BzC;IAED,KAAY,4BAA4B,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,8BAA8B,CAAC,CAAC;IACjG,SAAsB,sBAAsB,CAC3C,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,GAAG,GAAE,OAAO,CAAC,GAA4B,GACvC,OAAO,CAAC,4BAA4B,CAAC,CAkBvC;IAED,SAAsB,yBAAyB,CAC9C,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,kBAAkB,EAAE,iBAAiB,EACrC,GAAG,GAAE,OAAO,CAAC,GAA4B,6BA2BzC;IAED,KAAY,cAAc,GACzB,KAAK,CAAC,oFAAoF,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;IACxJ,SAAsB,yBAAyB,CAC9C,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,QAAQ,EACtB,GAAG,GAAE,OAAO,CAAC,GAA4B,GACvC,OAAO,CAAC,cAAc,CAAC,CA4BzB;CACD"}
@@ -7,7 +7,8 @@ exports.Registry = void 0;
7
7
  exports.buildAuthHeader = buildAuthHeader;
8
8
  require("cross-fetch/polyfill");
9
9
  const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
10
- const { GET } = (0, openapi_fetch_1.default)();
10
+ const globals_1 = require("./globals");
11
+ const { GET, POST, PUT } = (0, openapi_fetch_1.default)();
11
12
  function buildAuthHeader(token) {
12
13
  if (token) {
13
14
  return { authorization: `Bearer ${token}` };
@@ -64,5 +65,143 @@ var Registry;
64
65
  }
65
66
  }
66
67
  Registry.fetchLibraryContent = fetchLibraryContent;
68
+ async function getPublisher(token, publisherId) {
69
+ try {
70
+ const { data, error } = await GET('/publisher/{publisherId}', {
71
+ ...Registry.getAPIUrl(),
72
+ headers: { ...buildAuthHeader(token) },
73
+ params: {
74
+ path: {
75
+ publisherId: publisherId
76
+ }
77
+ }
78
+ });
79
+ if (error) {
80
+ console.error(error);
81
+ return null;
82
+ }
83
+ return data;
84
+ }
85
+ catch (e) {
86
+ console.error(e);
87
+ return null;
88
+ }
89
+ }
90
+ Registry.getPublisher = getPublisher;
91
+ async function createNewApplication(token, publisherId, newApplication, env = globals_1.Globals.ENV.production) {
92
+ try {
93
+ const { data, error } = await POST('/packages/{publisherId}/applications', {
94
+ ...Registry.getAPIUrl(),
95
+ headers: {
96
+ ...buildAuthHeader(token),
97
+ ...headerBasedOnEnv(env)
98
+ },
99
+ params: {
100
+ path: {
101
+ publisherId
102
+ }
103
+ },
104
+ body: {
105
+ ...newApplication
106
+ }
107
+ });
108
+ if (error) {
109
+ throw new Error(error.reason);
110
+ }
111
+ return data.id;
112
+ }
113
+ catch (e) {
114
+ // todo log error
115
+ return null;
116
+ }
117
+ }
118
+ Registry.createNewApplication = createNewApplication;
119
+ async function getExistingApplication(token, publisherId, applicationId, env = globals_1.Globals.ENV.production) {
120
+ const { data, error } = await GET('/publisher/{publisherId}/applications/{applicationId}', {
121
+ ...Registry.getAPIUrl(),
122
+ headers: {
123
+ ...buildAuthHeader(token),
124
+ ...headerBasedOnEnv(env)
125
+ },
126
+ params: {
127
+ path: {
128
+ publisherId,
129
+ applicationId
130
+ }
131
+ }
132
+ });
133
+ if (error) {
134
+ throw new Error(error.reason);
135
+ }
136
+ return data;
137
+ }
138
+ Registry.getExistingApplication = getExistingApplication;
139
+ async function updateExistingApplication(token, publisherId, applicationId, updatedApplication, env = globals_1.Globals.ENV.production) {
140
+ try {
141
+ const { error } = await PUT(`/packages/{publisherId}/applications/{applicationId}`, {
142
+ ...Registry.getAPIUrl(),
143
+ headers: {
144
+ ...buildAuthHeader(token),
145
+ ...headerBasedOnEnv(env)
146
+ },
147
+ params: {
148
+ path: {
149
+ publisherId,
150
+ applicationId
151
+ }
152
+ },
153
+ body: {
154
+ ...updatedApplication
155
+ }
156
+ });
157
+ if (error) {
158
+ throw new Error(error.reason);
159
+ }
160
+ return;
161
+ }
162
+ catch (e) {
163
+ // todo log error
164
+ return null;
165
+ }
166
+ }
167
+ Registry.updateExistingApplication = updateExistingApplication;
168
+ async function publishApplicationVersion(token, publisherId, applicationId, version, apmTagBuffer, env = globals_1.Globals.ENV.production) {
169
+ const { data, error } = await POST('/packages/{publisherId}/applications/{applicationId}/versions/{applicationVersion}', {
170
+ ...Registry.getAPIUrl(),
171
+ headers: {
172
+ ...buildAuthHeader(token),
173
+ ...headerBasedOnEnv(env)
174
+ },
175
+ params: {
176
+ path: {
177
+ publisherId,
178
+ applicationId,
179
+ applicationVersion: version
180
+ }
181
+ },
182
+ // @ts-ignore
183
+ body: {},
184
+ bodySerializer() {
185
+ return apmTagBuffer;
186
+ }
187
+ });
188
+ if (error) {
189
+ //@ts-ignore
190
+ throw new Error(error.reason || error.err || error);
191
+ }
192
+ return data;
193
+ }
194
+ Registry.publishApplicationVersion = publishApplicationVersion;
67
195
  })(Registry || (exports.Registry = Registry = {}));
196
+ /**
197
+ * inject the X-Semver header for application based requests
198
+ * with this header the semver versioning is required
199
+ * @param env
200
+ */
201
+ function headerBasedOnEnv(env) {
202
+ if (env === globals_1.Globals.ENV.lucky) {
203
+ return { 'X-Semver': 'true' };
204
+ }
205
+ return {};
206
+ }
68
207
  //# sourceMappingURL=registryAPI.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scriptRunner.d.ts","sourceRoot":"","sources":["../src/scriptRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAI/B,yBAAiB,KAAK,CAAC;IACtB;;;;OAIG;IACH,SAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,iBAgBtD;IAED;;;;OAIG;IACH,SAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,iBAgBtD;CACD"}
1
+ {"version":3,"file":"scriptRunner.d.ts","sourceRoot":"","sources":["../src/scriptRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAK/B,yBAAiB,KAAK,CAAC;IACtB;;;;OAIG;IACH,SAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,iBAgBtD;IAED;;;;OAIG;IACH,SAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,iBAgBtD;CACD"}
@@ -27,6 +27,7 @@ exports.Shell = void 0;
27
27
  const vscode_uri_1 = require("vscode-uri");
28
28
  const manifest_1 = require("./manifest");
29
29
  const child_process = __importStar(require("node:child_process"));
30
+ const apm_1 = require("./package/apm");
30
31
  var Shell;
31
32
  (function (Shell) {
32
33
  /**
@@ -45,7 +46,7 @@ var Shell;
45
46
  }
46
47
  catch (e) {
47
48
  if (e.code) {
48
- throw new Error('Build POV failed');
49
+ throw new Error(`APM part '${apm_1.APM.Part.pov}' has errors. Aborted.`);
49
50
  }
50
51
  else {
51
52
  throw e;
@@ -70,7 +71,7 @@ var Shell;
70
71
  }
71
72
  catch (e) {
72
73
  if (e.code) {
73
- throw new Error('Build BLO failed');
74
+ throw new Error(`APM part '${apm_1.APM.Part.blo}' has errors. Aborted.`);
74
75
  }
75
76
  else {
76
77
  throw e;