@microtronics/studio-cli 0.9.1 → 0.11.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,264 @@
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 package_1.Package.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
+ //# sourceMappingURL=apm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../src/package/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAIhC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AA4CrC,yBAAiB,OAAO,CAAC;IACxB;;;;OAIG;IACH,SAAsB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAQ9E;IAED;;;;OAIG;IACH,SAAsB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO;;;;SA2B7D;IAED;;;;;;;OAOG;IACH,SAAsB,cAAc,CACnC,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,OAAO,EACX,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,OAAO,EAAE,UAAU,EACnB,GAAG,GAAE,OAAO,CAAC,GAA4B,iBAUzC;CACD"}
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Library = void 0;
4
+ const vscode_uri_1 = require("vscode-uri");
5
+ const helper_1 = require("../helper");
6
+ var convertBlobToString = helper_1.Helper.convertBlobToString;
7
+ const minimatch_1 = require("minimatch");
8
+ const registryAPI_1 = require("../registryAPI");
9
+ const manifest_1 = require("../manifest");
10
+ const package_1 = require("./package");
11
+ const globals_1 = require("../globals");
12
+ const pako = require('pako');
13
+ const tarball = require('tarballjs');
14
+ const STUDIO_IGNORE_FILE = '.studioignore';
15
+ //see original list: https://github.com/microsoft/vscode-vsce/blob/main/src/package.ts#L1603
16
+ const defaultIgnore = [
17
+ '.vscodeignore',
18
+ 'package-lock.json',
19
+ 'npm-debug.log',
20
+ 'yarn.lock',
21
+ 'yarn-error.log',
22
+ 'npm-shrinkwrap.json',
23
+ '.editorconfig',
24
+ '.npmrc',
25
+ '.yarnrc',
26
+ '.gitattributes',
27
+ '*.todo',
28
+ 'tslint.yaml',
29
+ '.eslintrc*',
30
+ '.babelrc*',
31
+ '.prettierrc*',
32
+ '.cz-config.js',
33
+ '.commitlintrc*',
34
+ 'webpack.config.js',
35
+ 'ISSUE_TEMPLATE.md',
36
+ 'CONTRIBUTING.md',
37
+ 'PULL_REQUEST_TEMPLATE.md',
38
+ 'CODE_OF_CONDUCT.md',
39
+ '.github',
40
+ '.travis.yml',
41
+ 'appveyor.yml',
42
+ '**/.git',
43
+ '**/.git/**',
44
+ '**/*.vsix',
45
+ '**/.DS_Store',
46
+ '**/*.vsixmanifest',
47
+ '**/.vscode-test/**',
48
+ '**/.vscode-test-web/**'
49
+ ];
50
+ defaultIgnore.push(...['**/.studio/**', '**/node_modules/**', STUDIO_IGNORE_FILE]);
51
+ const MINIMATCH_OPTIONS = { dot: true };
52
+ var Library;
53
+ (function (Library) {
54
+ /**
55
+ * Creates the library.tar.gz archive content
56
+ * @param cwd
57
+ * @param fs
58
+ */
59
+ async function createArchive(cwd, fs) {
60
+ const tar = new tarball.TarWriter();
61
+ const filesToPack = await getFilesForArchive(cwd, fs);
62
+ filesToPack.forEach(file => {
63
+ tar.addFileArrayBuffer(file.name, file.data);
64
+ });
65
+ const tarBuffer = await tar.write();
66
+ return pako.gzip(tarBuffer);
67
+ }
68
+ Library.createArchive = createArchive;
69
+ /**
70
+ * Reads the project directory and returns all files that will be packed within the library.tar.gz
71
+ * @param cwd
72
+ * @param fs
73
+ */
74
+ async function getFilesForArchive(cwd, fs) {
75
+ const files = [];
76
+ const { ignore, negate } = await getIgnoreNegateList(cwd, fs);
77
+ const allFiles = await fs.findFiles(cwd, '**/*');
78
+ const filteredFiles = allFiles.filter(({ path }) => {
79
+ const relativePath = path.slice(cwd.path.length + 1);
80
+ return (!ignore.some(i => (0, minimatch_1.minimatch)(relativePath, i, MINIMATCH_OPTIONS)) ||
81
+ negate.some(i => (0, minimatch_1.minimatch)(relativePath, i.slice(1), MINIMATCH_OPTIONS)));
82
+ });
83
+ for (const fileUri of filteredFiles) {
84
+ const relativePath = fileUri.path.slice(cwd.path.length + 1);
85
+ const [stat, blob] = await Promise.all([fs.stat(fileUri), fs.readFile(fileUri)]);
86
+ if (stat) {
87
+ files.push({
88
+ name: relativePath,
89
+ data: blob,
90
+ modifyTime: new Date(stat.mtime)
91
+ });
92
+ }
93
+ }
94
+ return files;
95
+ }
96
+ Library.getFilesForArchive = getFilesForArchive;
97
+ /**
98
+ * Publish new library package to the registry
99
+ * @param cwd
100
+ * @param fs
101
+ * @param token
102
+ * @param archive
103
+ * @param env
104
+ */
105
+ async function publishPackage(cwd, fs, token, archive, env = globals_1.Globals.ENV.production) {
106
+ const { publisher, name, version } = await manifest_1.Manifest.read(cwd, fs);
107
+ const files = {
108
+ 'CHANGELOG.md': await package_1.Package.getChangelogFile(cwd, fs),
109
+ 'README.md': await package_1.Package.getReadmeFile(cwd, fs, name),
110
+ 'library.tar.gz': archive,
111
+ 'studio.json': await manifest_1.Manifest.readAsBlob(cwd, fs)
112
+ };
113
+ return await registryAPI_1.Registry.publishLibraryVersion(token, publisher, name, version, files, env);
114
+ }
115
+ Library.publishPackage = publishPackage;
116
+ })(Library || (exports.Library = Library = {}));
117
+ /**
118
+ * Parse the studioignore file and returns a list of ignore files and negations
119
+ * @param cwd
120
+ * @param fs
121
+ */
122
+ async function getIgnoreNegateList(cwd, fs) {
123
+ const notIgnored = ['!studio.json', `!README.md`];
124
+ // this code is mostly from https://github.com/microsoft/vscode-vsce/blob/main/src/package.ts#L1681
125
+ const ignoreFile = await getIgnoreFile(cwd, fs);
126
+ // Parse raw ignore by splitting output into lines and filtering out empty lines and comments
127
+ const filteredIgnore = ignoreFile
128
+ .split(/[\n\r]/)
129
+ .map(s => s.trim())
130
+ .filter(s => !!s)
131
+ .filter(i => !/^\s*#/.test(i));
132
+ // Add '/**' to possible folders
133
+ const folderAgnosticIgnore = [
134
+ ...filteredIgnore,
135
+ ...filteredIgnore.filter(i => !/(^|\/)[^/]*\*[^/]*$/.test(i)).map(i => (/\/$/.test(i) ? `${i}**` : `${i}/**`))
136
+ ];
137
+ // Combine with default ignore list
138
+ const combinedIgnoreList = [...defaultIgnore, ...folderAgnosticIgnore, ...notIgnored];
139
+ // Split into ignore and negate list
140
+ const [ignore, negate] = combinedIgnoreList.reduce((r, e) => (!/^\s*!/.test(e) ? [[...r[0], e], r[1]] : [r[0], [...r[1], e]]), [[], []]);
141
+ return {
142
+ ignore,
143
+ negate
144
+ };
145
+ }
146
+ /**
147
+ * Reads the .studioignore file if exist
148
+ * @param cwd
149
+ * @param fs
150
+ */
151
+ async function getIgnoreFile(cwd, fs) {
152
+ const ignoreFilePath = vscode_uri_1.Utils.joinPath(cwd, STUDIO_IGNORE_FILE);
153
+ const exists = await fs.stat(cwd);
154
+ if (exists) {
155
+ const ignoreFile = await fs.readFile(ignoreFilePath);
156
+ return convertBlobToString(ignoreFile);
157
+ }
158
+ else {
159
+ return '';
160
+ }
161
+ }
162
+ //# sourceMappingURL=library.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;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,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,OAAO,CAC5B,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,iBAQzC;IAED;;;;;;;;OAQG;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,iBAqBzC;IAED;;;;;;;OAOG;IACH,SAAsB,cAAc,CACnC,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,OAAO,EACX,KAAK,EAAE,QAAQ,CAAC,SAAS,EACzB,GAAG,GAAE,OAAO,CAAC,GAA4B,iBAazC;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;IAED;;;;OAIG;IACH,SAAsB,wBAAwB,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,iBAwBpG;CACD"}
@@ -0,0 +1,219 @@
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
+ const library_1 = require("./library");
16
+ var Package;
17
+ (function (Package) {
18
+ /**
19
+ * Build the whole project or only a specific part
20
+ * @param cwd
21
+ * @param fs
22
+ * @param apmPart - choose a specific part that should be build
23
+ */
24
+ async function buildAll(cwd, fs, apmPart) {
25
+ if (!apmPart || apmPart === apm_1.APM.Part.dde) {
26
+ await buildDDE(cwd, fs);
27
+ }
28
+ if (!apmPart || apmPart === apm_1.APM.Part.dlo) {
29
+ await buildDLO(cwd, fs);
30
+ }
31
+ if (!apmPart || apmPart === apm_1.APM.Part.pov) {
32
+ await scriptRunner_1.Shell.tryBuildPov(cwd, fs);
33
+ }
34
+ if (!apmPart || apmPart === apm_1.APM.Part.blo) {
35
+ await scriptRunner_1.Shell.tryBuildBlo(cwd, fs);
36
+ }
37
+ console.log('DONE');
38
+ }
39
+ Package.buildAll = buildAll;
40
+ /**
41
+ * Trigger the release based on the manifest settings
42
+ * @param cwd
43
+ * @param fs
44
+ * @param token
45
+ * @param releasePhase
46
+ * @param env
47
+ */
48
+ async function release(cwd, fs, token, releasePhase, env = globals_1.Globals.ENV.production) {
49
+ const manifest = await manifest_1.Manifest.read(cwd, fs);
50
+ if (manifest_1.Manifest.isLibraryProject(manifest)) {
51
+ await releaseLibrary(cwd, fs, token, env);
52
+ }
53
+ else {
54
+ await releaseAPM(cwd, fs, token, releasePhase, env);
55
+ }
56
+ }
57
+ Package.release = release;
58
+ /**
59
+ * Publish an application model tag
60
+ * @param cwd
61
+ * @param fs
62
+ * @param manifest
63
+ * @param token
64
+ * @param releasePhase
65
+ * @param env
66
+ */
67
+ async function releaseAPM(cwd, fs, token, releasePhase, env = globals_1.Globals.ENV.production) {
68
+ if (!Object.values(apm_1.APM.TagPhase).includes(releasePhase)) {
69
+ throw new Error(`ReleasePhase: ${releasePhase} is not a valid release phase`);
70
+ }
71
+ await manifest_1.Manifest.validateManifest(cwd, fs, null, env);
72
+ const application = await apm_1.APM.validateAccess(cwd, fs, token, false, env);
73
+ if (!application) {
74
+ return;
75
+ }
76
+ // build the complete project
77
+ await buildAll(cwd, fs);
78
+ // update the store apm with the actual name/description/...
79
+ await apm_1.APM.updateProfile(cwd, fs, token, env);
80
+ const tagContent = await apm_1.APM.createTag(cwd, fs, releasePhase);
81
+ const newTag = await apm_1.APM.publishTag(cwd, fs, token, tagContent, env);
82
+ console.log(`Tag "${newTag.version}" with phase "${newTag.phase}" published!`);
83
+ }
84
+ Package.releaseAPM = releaseAPM;
85
+ /**
86
+ * Publish a library project
87
+ * @param cwd
88
+ * @param fs
89
+ * @param manifest
90
+ * @param token
91
+ * @param env
92
+ */
93
+ async function releaseLibrary(cwd, fs, token, env = globals_1.Globals.ENV.production) {
94
+ const manifest = await manifest_1.Manifest.read(cwd, fs);
95
+ await manifest_1.Manifest.validateManifest(cwd, fs, manifest, env);
96
+ await validateSpecificSettings(token, manifest);
97
+ // build the complete project
98
+ await buildAll(cwd, fs);
99
+ const archive = await library_1.Library.createArchive(cwd, fs);
100
+ await library_1.Library.publishPackage(cwd, fs, token, archive, env);
101
+ console.log(`Library "${manifest.publisher}/${manifest.name}" with version "${manifest.version}" published!`);
102
+ }
103
+ Package.releaseLibrary = releaseLibrary;
104
+ /**
105
+ * Read the projects README.md file
106
+ * validates if the file content is the initial content
107
+ * @param cwd
108
+ * @param fs
109
+ * @param projectName
110
+ */
111
+ async function getReadmeFile(cwd, fs, projectName) {
112
+ let fileBlob = undefined;
113
+ try {
114
+ fileBlob = await fs.readFile(vscode_uri_1.Utils.joinPath(cwd, 'README.md'));
115
+ }
116
+ catch (e) {
117
+ throw new Error('Could not find "README.md". "README.md" is required for publishing.');
118
+ }
119
+ const README_STRING = convertBlobToString(fileBlob);
120
+ if (README_STRING === defaultFiles_1.DefaultFiles.readme(projectName)) {
121
+ throw new Error('"README.md" matches the default template. Please write a brief project description.');
122
+ }
123
+ return fileBlob;
124
+ }
125
+ Package.getReadmeFile = getReadmeFile;
126
+ /**
127
+ * Read the projects CHANGELOG.md file
128
+ * validates if the file content is the initial content
129
+ * @param cwd
130
+ * @param fs
131
+ */
132
+ async function getChangelogFile(cwd, fs) {
133
+ let fileBlob = undefined;
134
+ try {
135
+ fileBlob = await fs.readFile(vscode_uri_1.Utils.joinPath(cwd, 'CHANGELOG.md'));
136
+ }
137
+ catch (e) {
138
+ throw new Error('Could not find "CHANGELOG.md". "CHANGELOG.md" is required for publishing.');
139
+ }
140
+ const CHANGELOG_STRING = convertBlobToString(fileBlob);
141
+ if (CHANGELOG_STRING === defaultFiles_1.DefaultFiles.changelog) {
142
+ throw new Error('"CHANGELOG.md" matches the default template.');
143
+ }
144
+ return fileBlob;
145
+ }
146
+ Package.getChangelogFile = getChangelogFile;
147
+ /**
148
+ * Validate manifest settings that are required for the APM
149
+ * @param token
150
+ * @param manifest
151
+ */
152
+ async function validateSpecificSettings(token, manifest) {
153
+ const { name, publisher, description, registry } = manifest;
154
+ const invalidName = await manifest_1.Manifest.validateProjectName(name);
155
+ if (invalidName) {
156
+ throw new Error(`name: ${invalidName}`);
157
+ }
158
+ const invalidDescription = await manifest_1.Manifest.validateDescription(description);
159
+ if (invalidDescription) {
160
+ throw new Error(`description: ${invalidDescription}`);
161
+ }
162
+ const invalidPublisher = (await manifest_1.Manifest.validatePublisherId(publisher)) || (await manifest_1.Manifest.validatePublisherOnline(token, publisher));
163
+ if (invalidPublisher) {
164
+ throw new Error(`publisher: ${invalidPublisher}`);
165
+ }
166
+ // only validate if the project is not a library project
167
+ if (!manifest_1.Manifest.isLibraryProject(manifest)) {
168
+ const invalidBackends = await manifest_1.Manifest.validateRegistryAllowedBackends(registry?.allowedBackends);
169
+ if (invalidBackends) {
170
+ throw new Error(`registry: ${invalidBackends}`);
171
+ }
172
+ }
173
+ }
174
+ Package.validateSpecificSettings = validateSpecificSettings;
175
+ })(Package || (exports.Package = Package = {}));
176
+ /**
177
+ * Generates all needed files out of the dde declaration
178
+ * @param cwd
179
+ * @param fs
180
+ */
181
+ async function buildDDE(cwd, fs) {
182
+ const result = await dde_1.DDE.compileDDE(cwd, fs);
183
+ result.diagnostics.forEach(diagnostic => {
184
+ const message = `${diagnostic.file.path}: ${diagnostic.message}`;
185
+ if (diagnostic.level === 'error') {
186
+ console.error(message);
187
+ }
188
+ else if (diagnostic.level === 'warning') {
189
+ console.warn(message);
190
+ }
191
+ else {
192
+ console.log(message);
193
+ }
194
+ });
195
+ trowIfDiagnosticsHaveError(apm_1.APM.Part.dde, result.diagnostics);
196
+ if (result.ddeJSON) {
197
+ await dde_1.DDE.exportMyDatanetXML(cwd, fs, result.ddeJSON);
198
+ await dde_1.DDE.exportHistoryJson(cwd, fs, result.ddeJSON);
199
+ await dde_1.DDE.exportOpenApi(cwd, fs, result.ddeJSON);
200
+ await dde_1.DDE.exportAutoDloFiles(cwd, fs, result.ddeJSON);
201
+ await dlo_1.DLO.exportDloConfig(cwd, fs);
202
+ }
203
+ else {
204
+ throw new Error('Project has errors!');
205
+ }
206
+ }
207
+ async function buildDLO(cwd, fs) {
208
+ const compiler = new compiler_1.DloCompiler();
209
+ const { diagnostics } = await compiler.compile(cwd, fs);
210
+ trowIfDiagnosticsHaveError(apm_1.APM.Part.dlo, diagnostics);
211
+ }
212
+ function trowIfDiagnosticsHaveError(apmPart, diagnostics) {
213
+ diagnostics.forEach(diagnostic => {
214
+ if (diagnostic.level === 'error') {
215
+ throw new Error(`APM part '${apmPart}' has errors. Aborted.`);
216
+ }
217
+ });
218
+ }
219
+ //# 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;AAKv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