@microtronics/studio-cli 0.24.1 → 0.26.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
 
2
2
 
3
+ ## 0.26.0 (2025-03-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * implemented generic logger ([46b72a1](https://bitbucket.org/microtronics-core/vscode-studio/commits/46b72a1f5bcf9cfe85e58deb7e69bf3e56aa0875))
9
+ * **studio-cli:** introduced generic logger with chalk as colorization tool ([6593494](https://bitbucket.org/microtronics-core/vscode-studio/commits/65934942e2d30b3dfcc965e798ad8c508bf2ed52))
10
+
11
+ ## 0.25.0 (2025-03-12)
12
+
13
+
14
+ ### Features
15
+
16
+ * **studio-cli:** show update notification after each cli command ([c719fd8](https://bitbucket.org/microtronics-core/vscode-studio/commits/c719fd8ea6a7dda16589764d2ae77f70e006d80a))
17
+
3
18
  ## 0.24.1 (2025-03-12)
4
19
 
5
20
  ## 0.24.0 (2025-03-10)
@@ -115,6 +115,21 @@ declare interface BaseTagHeader {
115
115
  addon_max_sources?: number;
116
116
  }
117
117
 
118
+ /**
119
+ * Builds all parts of the specified project in the given working directory.
120
+ *
121
+ * @param {URI} cwd - The current working directory where the build process will be executed.
122
+ * @param {LocalFS} fs - The local file system instance used for file operations during the build.
123
+ * @param {Logger} logger - Logger instance for logging details during the build process.
124
+ * @param {APM.Part} selectedParts - The project parts to be built.
125
+ * @return A promise that resolves when the build process is complete.
126
+ */
127
+ export declare function build(cwd: URI, fs: LocalFS, logger: Log.Logger, selectedParts?: APM.Part[] | boolean): Promise<{
128
+ [APM.Part.dde]: Diagnostics.File[];
129
+ [APM.Part.dlo]: Diagnostics.File[];
130
+ [APM.Part.dfiles]: Diagnostics.File[];
131
+ }>;
132
+
118
133
  declare interface components {
119
134
  schemas: {
120
135
  /** @default 25 */
@@ -1115,7 +1130,7 @@ export declare namespace DDE {
1115
1130
  * @param fs
1116
1131
  * @param fileName
1117
1132
  */
1118
- export function validate(cwd: URI, fs: LocalFS, fileName?: string): Promise<{
1133
+ export function validate(cwd: URI, fs: LocalFS, logger: Log.Logger, fileName?: string): Promise<{
1119
1134
  manifest: Manifest.Manifest;
1120
1135
  libraryFiles: DDE_Core.LibraryFile[];
1121
1136
  main: {
@@ -1127,9 +1142,10 @@ export declare namespace DDE {
1127
1142
  * Run dde compiler in the given studio directory
1128
1143
  * @param cwd
1129
1144
  * @param fs
1145
+ * @param logger
1130
1146
  * @param fileName
1131
1147
  */
1132
- export function compileDDE(cwd: URI, fs: LocalFS, fileName?: string): Promise<{
1148
+ export function compileDDE(cwd: URI, fs: LocalFS, logger: Log.Logger, fileName?: string): Promise<{
1133
1149
  ddeJSON: DDEJson | null;
1134
1150
  diagnostics: Diagnostics.File[];
1135
1151
  }>;
@@ -1137,8 +1153,9 @@ export declare namespace DDE {
1137
1153
  * Validate a given dde file against the dynamic dde schema
1138
1154
  * @param ddeFilePath
1139
1155
  * @param yaml
1156
+ * @param logger
1140
1157
  */
1141
- export function validateJsonSchema(ddeFilePath: URI, yaml: string): Promise<void>;
1158
+ export function validateJsonSchema(ddeFilePath: URI, yaml: string, logger: Log.Logger): Promise<void>;
1142
1159
  /**
1143
1160
  * Creates and returns a new precompiler instance
1144
1161
  * @param manifest
@@ -1161,13 +1178,13 @@ export declare namespace DDE {
1161
1178
  * @param fs
1162
1179
  * @param ddeJSON
1163
1180
  */
1164
- export function exportMyDatanetXML(cwd: URI, fs: LocalFS, ddeJSON: DDEJson): Promise<void>;
1181
+ export function exportMyDatanetXML(cwd: URI, fs: LocalFS, logger: Log.Logger, ddeJSON: DDEJson): Promise<void>;
1165
1182
  /**
1166
1183
  * Read the correct history.json file from the project
1167
1184
  * @param cwd
1168
1185
  * @param fs
1169
1186
  */
1170
- export function getHistoryJson(cwd: URI, fs: LocalFS): Promise<any>;
1187
+ export function getHistoryJson(cwd: URI, fs: LocalFS, logger: Log.Logger): Promise<any>;
1171
1188
  /**
1172
1189
  * Generate the object for the history.json
1173
1190
  * @param ddeJson
@@ -1181,7 +1198,7 @@ export declare namespace DDE {
1181
1198
  * @param fs
1182
1199
  * @param ddeJSON
1183
1200
  */
1184
- export function exportHistoryJson(cwd: URI, fs: LocalFS, ddeJSON: DDEJson): Promise<void>;
1201
+ export function exportHistoryJson(cwd: URI, fs: LocalFS, logger: Log.Logger, ddeJSON: DDEJson): Promise<void>;
1185
1202
  /**
1186
1203
  * Clean up the .studio/auto/dlo directory
1187
1204
  * @param cwd
@@ -1195,14 +1212,14 @@ export declare namespace DDE {
1195
1212
  * @param fs
1196
1213
  * @param ddeJSON
1197
1214
  */
1198
- export function exportAutoDloFiles(cwd: URI, fs: LocalFS, ddeJSON: DDEJson): Promise<void>;
1215
+ export function exportAutoDloFiles(cwd: URI, fs: LocalFS, logger: Log.Logger, ddeJSON: DDEJson): Promise<void>;
1199
1216
  /**
1200
1217
  * Generate all dde related openapi files
1201
1218
  * @param cwd
1202
1219
  * @param fs
1203
1220
  * @param ddeMap
1204
1221
  */
1205
- export function exportOpenApi(cwd: URI, fs: LocalFS, ddeMap: DDEJson): Promise<void>;
1222
+ export function exportOpenApi(cwd: URI, fs: LocalFS, logger: Log.Logger, ddeMap: DDEJson): Promise<void>;
1206
1223
  /**
1207
1224
  * Generate and export the default.inc file
1208
1225
  * @param cwd
@@ -1690,7 +1707,20 @@ export declare namespace DFILES {
1690
1707
  export interface PropertyList {
1691
1708
  [key: string]: Property;
1692
1709
  }
1693
- export function process(cwd: URI, fs: LocalFS): Promise<Diagnostics.File[]>;
1710
+ export function process(cwd: URI, fs: LocalFS, logger: Log.Logger): Promise<Diagnostics.File[]>;
1711
+ /**
1712
+ * Parses DFILES from the specified directory and aggregates properties, diagnostics, and library files.
1713
+ *
1714
+ * @param {URI} cwd - The current working directory URI.
1715
+ * @param {LocalFS} fs - The local file system instance used for file operations.
1716
+ * @return {Promise<{properties: PropertyList, diagnostics: Diagnostics.File[], libraryFiles: any[]}>}
1717
+ * Resolves to an object containing the aggregated properties, diagnostics, and library files information.
1718
+ */
1719
+ export function parseDfile(cwd: URI, fs: LocalFS): Promise<{
1720
+ properties: PropertyList;
1721
+ diagnostics: Diagnostics.File[];
1722
+ libraryFiles: Dependencies.APMPartLibrary[];
1723
+ }>;
1694
1724
  /**
1695
1725
  *
1696
1726
  * @param fs
@@ -1739,15 +1769,16 @@ export declare namespace DLO {
1739
1769
  * @param cwd
1740
1770
  * @param fs
1741
1771
  */
1742
- export function exportDloConfig(cwd: URI, fs: LocalFS): Promise<void>;
1772
+ export function exportDloConfig(cwd: URI, fs: LocalFS, logger: Log.Logger): Promise<void>;
1743
1773
  }
1744
1774
 
1745
1775
  declare class DloCompiler {
1776
+ private logger;
1746
1777
  private preCompiler;
1747
1778
  private dloCC;
1748
1779
  private stdout;
1749
1780
  private stderr;
1750
- constructor();
1781
+ constructor(logger: Log.Logger);
1751
1782
  private initDloCC;
1752
1783
  private get MEMFS();
1753
1784
  compile(cwd: URI, fs: LocalFS): Promise<{
@@ -2003,6 +2034,18 @@ export declare namespace Helper {
2003
2034
  export function defer(token: string, timeout: number, callback: any): void;
2004
2035
  }
2005
2036
 
2037
+ /**
2038
+ * Installs the specified dependencies or all dependencies if none are provided.
2039
+ *
2040
+ * @param {URI} cwd - The current working directory where the installation process takes place.
2041
+ * @param {LocalFS} fs - The file system interface used for managing files during the installation process.
2042
+ * @param {Globals.ENV} env - The global environment configuration used during the installation.
2043
+ * @param {string|null} apiToken - The API token for authentication, if required, or null if not applicable.
2044
+ * @param {string[]} dependencies - An array of dependency strings in the format "libraryId@version". If empty, all dependencies will be installed.
2045
+ * @return {Promise<void>} A promise that resolves when the installation process completes successfully or logs an error if it fails.
2046
+ */
2047
+ export declare function install(cwd: URI, fs: LocalFS, env: Globals.ENV, apiToken: string | null, dependencies: string[]): Promise<void>;
2048
+
2006
2049
  export declare namespace Library {
2007
2050
  /**
2008
2051
  * Creates the library.tar.gz archive content
@@ -2075,6 +2118,35 @@ declare interface LocalFS {
2075
2118
  copy: (source: URI, target: URI) => Promise<any>;
2076
2119
  }
2077
2120
 
2121
+ export declare namespace Log {
2122
+ export enum LogMessageType {
2123
+ log = 0,
2124
+ done = 1,
2125
+ info = 2,
2126
+ warning = 3,
2127
+ error = 4
2128
+ }
2129
+ const LOG_PREFIX: {
2130
+ 1: string;
2131
+ 0: string;
2132
+ 2: string;
2133
+ 3: string;
2134
+ 4: string;
2135
+ };
2136
+ export class Logger {
2137
+ private _logHandler;
2138
+ constructor(logOutput?: {
2139
+ log: (...args: any[]) => void;
2140
+ });
2141
+ _log(type: LogMessageType, msg: any, ...args: any[]): void;
2142
+ log(msg: any, ...args: any[]): void;
2143
+ error(msg: any, ...args: any[]): void;
2144
+ info(msg: any, ...args: any[]): void;
2145
+ warn(msg: any, ...args: any[]): void;
2146
+ done(msg: any, ...args: any[]): void;
2147
+ }
2148
+ }
2149
+
2078
2150
  export declare namespace Manifest {
2079
2151
  /**
2080
2152
  * The source filename where the information is stored in
@@ -2222,37 +2294,45 @@ export declare namespace Package {
2222
2294
  * Build the whole project or only a specific part
2223
2295
  * @param cwd
2224
2296
  * @param fs
2225
- * @param apmPart - choose a specific part that should be build
2297
+ * @param logger
2298
+ * @param selectedParts - choose a specific part that should be build or if true all parts are build
2226
2299
  */
2227
- export function buildAll(cwd: URI, fs: LocalFS, apmPart?: APM.Part): Promise<void>;
2300
+ export function buildAll(cwd: URI, fs: LocalFS, logger: Log.Logger, selectedParts?: APM.Part[] | boolean): Promise<{
2301
+ [APM.Part.dde]: Diagnostics.File[];
2302
+ [APM.Part.dlo]: Diagnostics.File[];
2303
+ [APM.Part.dfiles]: Diagnostics.File[];
2304
+ }>;
2228
2305
  /**
2229
2306
  * Trigger the release based on the manifest settings
2230
2307
  * @param cwd
2231
2308
  * @param fs
2309
+ * @param logger
2232
2310
  * @param token
2233
2311
  * @param releasePhase
2234
2312
  * @param allowedBackends
2235
2313
  * @param env
2236
2314
  */
2237
- export function release(cwd: URI, fs: LocalFS, token: Registry.AuthToken, releasePhase: APM.TagPhase, allowedBackends: Registry.ApiNewApplication['allowedBackends'], env: Globals.ENV): Promise<void>;
2315
+ export function release(cwd: URI, fs: LocalFS, logger: Log.Logger, token: Registry.AuthToken, releasePhase: APM.TagPhase, allowedBackends: Registry.ApiNewApplication['allowedBackends'], env: Globals.ENV): Promise<void>;
2238
2316
  /**
2239
2317
  * Publish an application model tag
2240
2318
  * @param cwd
2241
2319
  * @param fs
2320
+ * @param logger
2242
2321
  * @param token
2243
2322
  * @param releasePhase
2244
2323
  * @param allowedBackends
2245
2324
  * @param env
2246
2325
  */
2247
- export function releaseAPM(cwd: URI, fs: LocalFS, token: Registry.AuthToken, releasePhase: APM.TagPhase, allowedBackends: Registry.ApiNewApplication['allowedBackends'], env: Globals.ENV): Promise<void>;
2326
+ export function releaseAPM(cwd: URI, fs: LocalFS, logger: Log.Logger, token: Registry.AuthToken, releasePhase: APM.TagPhase, allowedBackends: Registry.ApiNewApplication['allowedBackends'], env: Globals.ENV): Promise<void>;
2248
2327
  /**
2249
2328
  * Publish a library project
2250
2329
  * @param cwd
2251
2330
  * @param fs
2331
+ * @param logger
2252
2332
  * @param token
2253
2333
  * @param env
2254
2334
  */
2255
- export function releaseLibrary(cwd: URI, fs: LocalFS, token: Registry.AuthToken, env: Globals.ENV): Promise<void>;
2335
+ export function releaseLibrary(cwd: URI, fs: LocalFS, logger: Log.Logger, token: Registry.AuthToken, env: Globals.ENV): Promise<void>;
2256
2336
  /**
2257
2337
  * Read the projects README.md file
2258
2338
  * validates if the file content is the initial content
@@ -4480,6 +4560,20 @@ declare interface paths {
4480
4560
  };
4481
4561
  }
4482
4562
 
4563
+ /**
4564
+ * Publishes a package to the registry with the specified settings and configurations.
4565
+ *
4566
+ * @param {URI} cwd - The current working directory of the package.
4567
+ * @param {LocalFS} fs - The file system interface for reading and writing files.
4568
+ * @param {Logger} logger - Logger instance for logging details during the publish process.
4569
+ * @param {Globals.ENV} env - The environment configuration for the publishing process.
4570
+ * @param {string | null} apiToken - The API token for authentication, or null if not applicable.
4571
+ * @param {string | undefined} optsAllowedBackends - A semicolon-separated list of allowed backends, or '*' to allow all, or undefined if not specified.
4572
+ * @param {APM.TagPhase} optsPhase - The release phase tag associated with the package publishing.
4573
+ * @return {Promise<void>} A promise that resolves when the package has been successfully published or rejects with an error if the process fails.
4574
+ */
4575
+ export declare function publish(cwd: URI, fs: LocalFS, logger: Log.Logger, env: Globals.ENV, apiToken: string | null, optsAllowedBackends: string | undefined, optsPhase: APM.TagPhase): Promise<void>;
4576
+
4483
4577
  export declare namespace Registry {
4484
4578
  export type AuthToken = string | null;
4485
4579
  /**
package/out/api.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENV = exports.DFILES = exports.Library = exports.APM = exports.Package = exports.DLO = exports.Globals = exports.DeviceProfiles = exports.DefaultFiles = exports.Diagnostics = exports.Helper = exports.DDE = exports.DDE_Core = exports.Registry = exports.Manifest = exports.Dependencies = void 0;
3
+ exports.Log = exports.ENV = exports.DFILES = exports.Library = exports.APM = exports.Package = exports.DLO = exports.Globals = exports.DeviceProfiles = exports.DefaultFiles = exports.Diagnostics = exports.Helper = exports.DDE = exports.DDE_Core = exports.Registry = exports.Manifest = exports.Dependencies = void 0;
4
+ exports.install = install;
5
+ exports.build = build;
6
+ exports.publish = publish;
4
7
  const dependencies_1 = require("./dependencies");
5
8
  Object.defineProperty(exports, "Dependencies", { enumerable: true, get: function () { return dependencies_1.Dependencies; } });
6
9
  const manifest_1 = require("./manifest");
@@ -33,4 +36,68 @@ const dfiles_1 = require("./dfiles/dfiles");
33
36
  Object.defineProperty(exports, "DFILES", { enumerable: true, get: function () { return dfiles_1.DFILES; } });
34
37
  const dotenv_1 = require("./dotenv");
35
38
  Object.defineProperty(exports, "ENV", { enumerable: true, get: function () { return dotenv_1.ENV; } });
39
+ const log_1 = require("./log");
40
+ Object.defineProperty(exports, "Log", { enumerable: true, get: function () { return log_1.Log; } });
41
+ /**
42
+ * Installs the specified dependencies or all dependencies if none are provided.
43
+ *
44
+ * @param {URI} cwd - The current working directory where the installation process takes place.
45
+ * @param {LocalFS} fs - The file system interface used for managing files during the installation process.
46
+ * @param {Globals.ENV} env - The global environment configuration used during the installation.
47
+ * @param {string|null} apiToken - The API token for authentication, if required, or null if not applicable.
48
+ * @param {string[]} dependencies - An array of dependency strings in the format "libraryId@version". If empty, all dependencies will be installed.
49
+ * @return {Promise<void>} A promise that resolves when the installation process completes successfully or logs an error if it fails.
50
+ */
51
+ async function install(cwd, fs, env, apiToken, dependencies) {
52
+ try {
53
+ if (dependencies.length > 0) {
54
+ for (const dependency of dependencies) {
55
+ const [libraryId, version] = dependency.split('@');
56
+ await dependencies_1.Dependencies.installDependency(cwd, fs, env, apiToken, libraryId, version || null);
57
+ }
58
+ }
59
+ else {
60
+ return await dependencies_1.Dependencies.installDependencies(cwd, fs, env, apiToken);
61
+ }
62
+ }
63
+ catch (e) {
64
+ console.error(e);
65
+ }
66
+ }
67
+ /**
68
+ * Builds all parts of the specified project in the given working directory.
69
+ *
70
+ * @param {URI} cwd - The current working directory where the build process will be executed.
71
+ * @param {LocalFS} fs - The local file system instance used for file operations during the build.
72
+ * @param {Logger} logger - Logger instance for logging details during the build process.
73
+ * @param {APM.Part} selectedParts - The project parts to be built.
74
+ * @return A promise that resolves when the build process is complete.
75
+ */
76
+ async function build(cwd, fs, logger, selectedParts = true) {
77
+ return package_1.Package.buildAll(cwd, fs, logger, selectedParts);
78
+ }
79
+ /**
80
+ * Publishes a package to the registry with the specified settings and configurations.
81
+ *
82
+ * @param {URI} cwd - The current working directory of the package.
83
+ * @param {LocalFS} fs - The file system interface for reading and writing files.
84
+ * @param {Logger} logger - Logger instance for logging details during the publish process.
85
+ * @param {Globals.ENV} env - The environment configuration for the publishing process.
86
+ * @param {string | null} apiToken - The API token for authentication, or null if not applicable.
87
+ * @param {string | undefined} optsAllowedBackends - A semicolon-separated list of allowed backends, or '*' to allow all, or undefined if not specified.
88
+ * @param {APM.TagPhase} optsPhase - The release phase tag associated with the package publishing.
89
+ * @return {Promise<void>} A promise that resolves when the package has been successfully published or rejects with an error if the process fails.
90
+ */
91
+ async function publish(cwd, fs, logger, env, apiToken, optsAllowedBackends, optsPhase) {
92
+ logger.info('Publishing package...');
93
+ let allowedBackends = null;
94
+ if (optsAllowedBackends) {
95
+ allowedBackends = optsAllowedBackends === '*' ? optsAllowedBackends : optsAllowedBackends.split(';');
96
+ const errorMessage = await manifest_1.Manifest.validateRegistryAllowedBackends(allowedBackends);
97
+ if (errorMessage) {
98
+ throw new Error(errorMessage);
99
+ }
100
+ }
101
+ return package_1.Package.release(cwd, fs, logger, apiToken, optsPhase, allowedBackends, env);
102
+ }
36
103
  //# sourceMappingURL=api.js.map
package/out/dde/dde.js CHANGED
@@ -64,16 +64,16 @@ var DDE;
64
64
  * @param fs
65
65
  * @param fileName
66
66
  */
67
- async function validate(cwd, fs, fileName = defaultFiles_1.DefaultFiles.fileNames.mainDDE) {
67
+ async function validate(cwd, fs, logger, fileName = defaultFiles_1.DefaultFiles.fileNames.mainDDE) {
68
68
  const manifest = await manifest_1.Manifest.read(cwd, fs);
69
69
  const allLibraryFiles = await getDependencies(cwd, fs, manifest);
70
70
  for (const libraryFile of allLibraryFiles) {
71
- await validateJsonSchema(libraryFile.path, libraryFile.yaml);
71
+ await validateJsonSchema(libraryFile.path, libraryFile.yaml, logger);
72
72
  }
73
73
  // read project dde
74
74
  const mainDdePath = vscode_uri_1.Utils.joinPath(cwd, exports.DDE_PATH, fileName);
75
75
  const mainDdeYaml = await readYamlFile(mainDdePath, fs);
76
- await validateJsonSchema(mainDdePath, mainDdeYaml);
76
+ await validateJsonSchema(mainDdePath, mainDdeYaml, logger);
77
77
  return {
78
78
  manifest,
79
79
  libraryFiles: allLibraryFiles,
@@ -88,11 +88,12 @@ var DDE;
88
88
  * Run dde compiler in the given studio directory
89
89
  * @param cwd
90
90
  * @param fs
91
+ * @param logger
91
92
  * @param fileName
92
93
  */
93
- async function compileDDE(cwd, fs, fileName = defaultFiles_1.DefaultFiles.fileNames.mainDDE) {
94
- const validated = await validate(cwd, fs, fileName);
95
- const historyJson = await getHistoryJson(cwd, fs);
94
+ async function compileDDE(cwd, fs, logger, fileName = defaultFiles_1.DefaultFiles.fileNames.mainDDE) {
95
+ const validated = await validate(cwd, fs, logger, fileName);
96
+ const historyJson = await getHistoryJson(cwd, fs, logger);
96
97
  const preCompiler = new yamlDdePreCompiler_1.YamlPreCompiler.PreCompiler(validated.manifest, validated.libraryFiles, historyJson);
97
98
  const libraryDiagnostics = preCompiler.parseLibraries();
98
99
  const librariesHaveError = libraryDiagnostics.find(diagnostics => diagnostics.level === 'error');
@@ -115,14 +116,15 @@ var DDE;
115
116
  * Validate a given dde file against the dynamic dde schema
116
117
  * @param ddeFilePath
117
118
  * @param yaml
119
+ * @param logger
118
120
  */
119
- async function validateJsonSchema(ddeFilePath, yaml) {
121
+ async function validateJsonSchema(ddeFilePath, yaml, logger) {
120
122
  const json = (0, yaml_1.parseDocument)(yaml).toJSON();
121
123
  const result = validateDynamicDde(json);
122
124
  if (!result) {
123
125
  const errors = validateDynamicDde.errors || [];
124
126
  const error = new Error(`${vscode_uri_1.Utils.basename(ddeFilePath)} has "${errors.length}" errors"`);
125
- errors.forEach(error => console.error(error));
127
+ errors.forEach(error => logger.error(error));
126
128
  throw error;
127
129
  }
128
130
  }
@@ -154,11 +156,11 @@ var DDE;
154
156
  * @param fs
155
157
  * @param ddeJSON
156
158
  */
157
- async function exportMyDatanetXML(cwd, fs, ddeJSON) {
159
+ async function exportMyDatanetXML(cwd, fs, logger, ddeJSON) {
158
160
  const xml = (0, xml_1.generateXMLFromMap)(ddeJSON);
159
161
  const distFile = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.ddeXmlPath);
160
162
  await fs.writeFile(distFile, xml);
161
- console.log('Generated', defaultFiles_1.DefaultFiles.filePaths.dist.ddeXmlPath);
163
+ logger.log('Generated', defaultFiles_1.DefaultFiles.filePaths.dist.ddeXmlPath);
162
164
  }
163
165
  DDE.exportMyDatanetXML = exportMyDatanetXML;
164
166
  /**
@@ -166,7 +168,7 @@ var DDE;
166
168
  * @param cwd
167
169
  * @param fs
168
170
  */
169
- async function getHistoryJson(cwd, fs) {
171
+ async function getHistoryJson(cwd, fs, logger) {
170
172
  const historyPath = vscode_uri_1.Utils.joinPath(cwd, exports.DDE_PATH, 'history.json');
171
173
  try {
172
174
  const binary = await fs.readFile(historyPath);
@@ -174,7 +176,7 @@ var DDE;
174
176
  return JSON.parse(historyString);
175
177
  }
176
178
  catch (e) {
177
- console.warn('history.json does not exist');
179
+ logger.warn('history.json does not exist');
178
180
  return {};
179
181
  }
180
182
  }
@@ -205,13 +207,13 @@ var DDE;
205
207
  * @param fs
206
208
  * @param ddeJSON
207
209
  */
208
- async function exportHistoryJson(cwd, fs, ddeJSON) {
209
- const currentHistory = await getHistoryJson(cwd, fs);
210
+ async function exportHistoryJson(cwd, fs, logger, ddeJSON) {
211
+ const currentHistory = await getHistoryJson(cwd, fs, logger);
210
212
  const manifest = await manifest_1.Manifest.read(cwd, fs);
211
213
  const newHistory = buildHistoryJson(ddeJSON, currentHistory, manifest);
212
214
  const historyPath = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.historyJson);
213
215
  await fs.writeFile(historyPath, JSON.stringify(newHistory, null, '\t'));
214
- console.log('Generated', defaultFiles_1.DefaultFiles.filePaths.dist.historyJson);
216
+ logger.log('Generated', defaultFiles_1.DefaultFiles.filePaths.dist.historyJson);
215
217
  }
216
218
  DDE.exportHistoryJson = exportHistoryJson;
217
219
  /**
@@ -230,7 +232,7 @@ var DDE;
230
232
  * @param fs
231
233
  * @param ddeJSON
232
234
  */
233
- async function exportAutoDloFiles(cwd, fs, ddeJSON) {
235
+ async function exportAutoDloFiles(cwd, fs, logger, ddeJSON) {
234
236
  await clearAutoDloDir(cwd, fs);
235
237
  const manifest = await manifest_1.Manifest.read(cwd, fs);
236
238
  const dependencies = await getDependencies(cwd, fs, manifest);
@@ -246,7 +248,7 @@ var DDE;
246
248
  const autoIncName = defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoDdeInc.replace('X', dependency.libraryName);
247
249
  const incPath = vscode_uri_1.Utils.joinPath(cwd, autoIncName);
248
250
  if (libraryInc.length) {
249
- console.log(`Generated`, autoIncName);
251
+ logger.log(`Generated`, autoIncName);
250
252
  await fs.writeFile(incPath, libraryInc);
251
253
  }
252
254
  }
@@ -254,16 +256,16 @@ var DDE;
254
256
  const autoUplink = (0, dlo_1.generateAutoUplinkIncFromMap)(ddeJSON, dependencies.map(dep => dep.libraryName));
255
257
  const autoIncPath = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoInc);
256
258
  await fs.writeFile(autoIncPath, autoInc);
257
- console.log(`Generated`, defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoInc);
259
+ logger.log(`Generated`, defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoInc);
258
260
  const autoUplinkIncPath = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoUplinkInc);
259
261
  await fs.writeFile(autoUplinkIncPath, autoUplink);
260
- console.log(`Generated`, defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoUplinkInc);
262
+ logger.log(`Generated`, defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoUplinkInc);
261
263
  const autoDdeAppPath = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoDdeInc.replace('X', 'app'));
262
264
  await fs.writeFile(autoDdeAppPath, [...appDDEInc.globals, ...appDDEInc.helper].join('\n'));
263
- console.log('Generated', defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoDdeInc.replace('X', 'app'));
265
+ logger.log('Generated', defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoDdeInc.replace('X', 'app'));
264
266
  const autoDdeMainPath = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoDdeInc.replace('X', 'main'));
265
267
  await fs.writeFile(autoDdeMainPath, mainDDEInc);
266
- console.log('Generated', defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoDdeInc.replace('X', 'main'));
268
+ logger.log('Generated', defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.autoDdeInc.replace('X', 'main'));
267
269
  await exportDefaultInc(cwd, fs);
268
270
  }
269
271
  DDE.exportAutoDloFiles = exportAutoDloFiles;
@@ -273,7 +275,7 @@ var DDE;
273
275
  * @param fs
274
276
  * @param ddeMap
275
277
  */
276
- async function exportOpenApi(cwd, fs, ddeMap) {
278
+ async function exportOpenApi(cwd, fs, logger, ddeMap) {
277
279
  const manifest = await manifest_1.Manifest.read(cwd, fs);
278
280
  const isLibrary = manifest_1.Manifest.isLibrary(manifest);
279
281
  // remove previous api description:
@@ -281,14 +283,14 @@ var DDE;
281
283
  await fs.rm(previousOpenAPIFileName).catch(() => { });
282
284
  const appPath = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.ddeApi);
283
285
  await fs.writeFile(appPath, (0, api_1.generateAPIFromMap)(ddeMap, manifest));
284
- console.log(`Generated`, defaultFiles_1.DefaultFiles.filePaths.dist.ddeApi);
286
+ logger.log(`Generated`, defaultFiles_1.DefaultFiles.filePaths.dist.ddeApi);
285
287
  // generate the api description for the library part of the project
286
288
  if (isLibrary) {
287
289
  const libPath = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.ddeApiPath, `${manifest.name}.yaml`);
288
290
  const content = (0, api_1.generateAPIFromMap)(ddeMap, manifest, manifest.name);
289
291
  if (content.length) {
290
292
  await fs.writeFile(libPath, content);
291
- console.log(`Generated`, defaultFiles_1.DefaultFiles.filePaths.dist.ddeApiPath + `${manifest.name}.yaml`);
293
+ logger.log(`Generated`, defaultFiles_1.DefaultFiles.filePaths.dist.ddeApiPath + `${manifest.name}.yaml`);
292
294
  }
293
295
  }
294
296
  }
@@ -29,18 +29,8 @@ var DFILES;
29
29
  Force["up"] = "up";
30
30
  Force["off"] = "off";
31
31
  })(Force = DFILES.Force || (DFILES.Force = {}));
32
- async function process(cwd, fs) {
33
- const allProperties = {};
34
- const allDiagnostics = [];
35
- const libraryFiles = await dependencies_1.Dependencies.getApmPartDependencies(cwd, fs, apm_1.APM.Part.dfiles);
36
- for (const library of libraryFiles) {
37
- const { properties, diagnostics } = await parseYamlFile(fs, library.path, library.name);
38
- Object.assign(allProperties, properties);
39
- allDiagnostics.push(...diagnostics);
40
- }
41
- const { properties, diagnostics } = await parseYamlFile(fs, vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dfiles.mainDFILES), null);
42
- Object.assign(allProperties, properties);
43
- allDiagnostics.push(...diagnostics);
32
+ async function process(cwd, fs, logger) {
33
+ const { properties, diagnostics, libraryFiles } = await parseDfile(cwd, fs);
44
34
  const distDir = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.dfilesPath);
45
35
  // clear dist directory beforehand
46
36
  if (await fs.stat(distDir)) {
@@ -48,18 +38,45 @@ var DFILES;
48
38
  }
49
39
  // copy all files to dist directory
50
40
  // copy all files to the dist directory
51
- for (const [dfileName, dfileInfo] of Object.entries(allProperties)) {
41
+ for (const [dfileName, dfileInfo] of Object.entries(properties)) {
52
42
  await copyDfilesToDist(cwd, fs, dfileName, dfileInfo, libraryFiles);
53
43
  }
54
44
  // do not write the properties file if there aren't any dfiles
55
- if (!Object.keys(allProperties).length) {
56
- return allDiagnostics;
45
+ if (!Object.keys(properties).length) {
46
+ return diagnostics;
57
47
  }
58
- console.log(`${Object.keys(allProperties).length} dfiles processed.`);
59
- await fs.writeFile(vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.dfilesProperties), JSON.stringify(allProperties, null, '\t'));
60
- return allDiagnostics;
48
+ logger.done(`${Object.keys(properties).length} dfiles processed.`);
49
+ await fs.writeFile(vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.dfilesProperties), JSON.stringify(properties, null, '\t'));
50
+ return diagnostics;
61
51
  }
62
52
  DFILES.process = process;
53
+ /**
54
+ * Parses DFILES from the specified directory and aggregates properties, diagnostics, and library files.
55
+ *
56
+ * @param {URI} cwd - The current working directory URI.
57
+ * @param {LocalFS} fs - The local file system instance used for file operations.
58
+ * @return {Promise<{properties: PropertyList, diagnostics: Diagnostics.File[], libraryFiles: any[]}>}
59
+ * Resolves to an object containing the aggregated properties, diagnostics, and library files information.
60
+ */
61
+ async function parseDfile(cwd, fs) {
62
+ const allDiagnostics = [];
63
+ const allProperties = {};
64
+ const libraryFiles = await dependencies_1.Dependencies.getApmPartDependencies(cwd, fs, apm_1.APM.Part.dfiles);
65
+ for (const library of libraryFiles) {
66
+ const { properties, diagnostics } = await parseYamlFile(fs, library.path, library.name);
67
+ Object.assign(allProperties, properties);
68
+ allDiagnostics.push(...diagnostics);
69
+ }
70
+ const { properties, diagnostics } = await parseYamlFile(fs, vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dfiles.mainDFILES), null);
71
+ Object.assign(allProperties, properties);
72
+ allDiagnostics.push(...diagnostics);
73
+ return {
74
+ properties: allProperties,
75
+ diagnostics: allDiagnostics,
76
+ libraryFiles: libraryFiles
77
+ };
78
+ }
79
+ DFILES.parseDfile = parseDfile;
63
80
  /**
64
81
  *
65
82
  * @param fs
@@ -37,11 +37,13 @@ var convertBlobToStringArray = helper_1.Helper.convertBlobToStringArray;
37
37
  const apm_1 = require("../package/apm");
38
38
  const DLO_MODULE = require('./dlocc.js');
39
39
  class DloCompiler {
40
+ logger;
40
41
  preCompiler = new preCompiler_1.DloPreCompiler();
41
42
  dloCC;
42
43
  stdout = [];
43
44
  stderr = [];
44
- constructor() {
45
+ constructor(logger) {
46
+ this.logger = logger;
45
47
  this.dloCC = null;
46
48
  }
47
49
  async initDloCC(noExit = false) {
@@ -50,11 +52,11 @@ class DloCompiler {
50
52
  this.dloCC = await DLO_MODULE({
51
53
  noExitRuntime: noExit,
52
54
  print: (data) => {
53
- console.log(data);
55
+ this.logger.log(data);
54
56
  this.stdout.push(data);
55
57
  },
56
58
  printErr: (err) => {
57
- console.error(err);
59
+ this.logger.error(err);
58
60
  this.stderr.push(err);
59
61
  this.stdout.push(err);
60
62
  }
package/out/dlo/dlo.js CHANGED
@@ -20,11 +20,11 @@ var DLO;
20
20
  * @param cwd
21
21
  * @param fs
22
22
  */
23
- async function exportDloConfig(cwd, fs) {
23
+ async function exportDloConfig(cwd, fs, logger) {
24
24
  const manifest = await manifest_1.Manifest.read(cwd, fs);
25
25
  const cfgData = await (0, compiler_1.generateConfigFile)(cwd, fs, manifest);
26
26
  await fs.writeFile(cfgData.path, cfgData.data);
27
- console.log('Generated', defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.cfg);
27
+ logger.log('Generated', defaultFiles_1.DefaultFiles.filePaths.studio.auto.dlo.cfg);
28
28
  }
29
29
  DLO.exportDloConfig = exportDloConfig;
30
30
  })(DLO || (exports.DLO = DLO = {}));
package/out/log.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Log = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ var Log;
9
+ (function (Log) {
10
+ let LogMessageType;
11
+ (function (LogMessageType) {
12
+ LogMessageType[LogMessageType["log"] = 0] = "log";
13
+ LogMessageType[LogMessageType["done"] = 1] = "done";
14
+ LogMessageType[LogMessageType["info"] = 2] = "info";
15
+ LogMessageType[LogMessageType["warning"] = 3] = "warning";
16
+ LogMessageType[LogMessageType["error"] = 4] = "error";
17
+ })(LogMessageType = Log.LogMessageType || (Log.LogMessageType = {}));
18
+ Log.LOG_PREFIX = {
19
+ [LogMessageType.done]: chalk_1.default.bgGreen.black(' DONE '),
20
+ [LogMessageType.log]: '',
21
+ [LogMessageType.info]: chalk_1.default.bgBlueBright.black(' INFO '),
22
+ [LogMessageType.warning]: chalk_1.default.bgYellow.black(' WARNING '),
23
+ [LogMessageType.error]: chalk_1.default.bgRed.black(' ERROR ')
24
+ };
25
+ class Logger {
26
+ _logHandler;
27
+ constructor(logOutput = console) {
28
+ this._logHandler = logOutput;
29
+ }
30
+ _log(type, msg, ...args) {
31
+ args = [Log.LOG_PREFIX[type], msg, ...args];
32
+ this._logHandler.log(...args);
33
+ }
34
+ log(msg, ...args) {
35
+ this._log(LogMessageType.log, msg, ...args);
36
+ }
37
+ error(msg, ...args) {
38
+ this._log(LogMessageType.error, msg, ...args);
39
+ }
40
+ info(msg, ...args) {
41
+ this._log(LogMessageType.info, msg, ...args);
42
+ }
43
+ warn(msg, ...args) {
44
+ this._log(LogMessageType.warning, msg, ...args);
45
+ }
46
+ done(msg, ...args) {
47
+ this._log(LogMessageType.done, msg, ...args);
48
+ }
49
+ }
50
+ Log.Logger = Logger;
51
+ })(Log || (exports.Log = Log = {}));
52
+ //# sourceMappingURL=log.js.map
package/out/main.js CHANGED
@@ -7,14 +7,14 @@ const commander_1 = require("commander");
7
7
  const package_json_1 = __importDefault(require("../package.json"));
8
8
  const cliFS_1 = require("./cliFS");
9
9
  const vscode_uri_1 = require("vscode-uri");
10
- const dependencies_1 = require("./dependencies");
11
- var installDependencies = dependencies_1.Dependencies.installDependencies;
12
- var installDependency = dependencies_1.Dependencies.installDependency;
13
- const package_1 = require("./package/package");
14
10
  const apm_1 = require("./package/apm");
15
11
  const globals_1 = require("./globals");
16
- const manifest_1 = require("./manifest");
12
+ const update_notifier_1 = __importDefault(require("update-notifier"));
13
+ const api_1 = require("./api");
14
+ const log_1 = require("./log");
17
15
  const program = new commander_1.Command();
16
+ const notifier = (0, update_notifier_1.default)({ pkg: package_json_1.default });
17
+ const logger = new log_1.Log.Logger();
18
18
  // dummy cwd
19
19
  const devPath = () => {
20
20
  if (process.env.NODE_ENV === 'local-dev-app') {
@@ -30,6 +30,19 @@ const devPath = () => {
30
30
  };
31
31
  const cwd = vscode_uri_1.Utils.joinPath(vscode_uri_1.URI.file(process.cwd()), devPath());
32
32
  program.version(package_json_1.default.version).usage('<command>');
33
+ /**
34
+ * Executes a task and ensures that the update available notification is sent after the task completes,
35
+ * regardless of whether it succeeds or fails.
36
+ *
37
+ * @param {Promise<void>} task - A promise representing the task to be executed.
38
+ * @return {void} This function does not return a value.
39
+ */
40
+ function main(task) {
41
+ // todo add task catch handler like: https://github.com/microsoft/vscode-vsce/blob/5518f2f242983d23f1983f6dd0350474f2011543/src/main.ts#L51
42
+ task.finally(() => {
43
+ notifier.notify();
44
+ });
45
+ }
33
46
  function handleStudioEnv(env) {
34
47
  process.env.STUDIO_ENV = env || globals_1.Globals.ENV.production;
35
48
  if (env && env !== globals_1.Globals.ENV.production) {
@@ -40,6 +53,12 @@ function handleStudioEnv(env) {
40
53
  function getStudioApiToken(opts) {
41
54
  return opts?.token || null;
42
55
  }
56
+ function getDefaultOptions(opts) {
57
+ return {
58
+ env: handleStudioEnv(opts.env),
59
+ token: getStudioApiToken(opts)
60
+ };
61
+ }
43
62
  /**
44
63
  * Generic option for the STUDIO_ENV
45
64
  */
@@ -58,29 +77,15 @@ program
58
77
  .allowExcessArguments(true)
59
78
  .addOption(optionStudioEnv)
60
79
  .addOption(optionStudioToken)
61
- .action(async (dependencies, opts) => {
62
- const env = handleStudioEnv(opts.env);
63
- const apiToken = getStudioApiToken(opts);
64
- try {
65
- if (dependencies.length > 0) {
66
- for (const dependency of dependencies) {
67
- const [libraryId, version] = dependency.split('@');
68
- await installDependency(cwd, cliFS_1.cliFS, env, apiToken, libraryId, version || null);
69
- }
70
- }
71
- else {
72
- return await installDependencies(cwd, cliFS_1.cliFS, env, apiToken);
73
- }
74
- }
75
- catch (e) {
76
- console.error(e);
77
- }
80
+ .action((dependencies, opts) => {
81
+ const { env, token } = getDefaultOptions(opts);
82
+ main((0, api_1.install)(cwd, cliFS_1.cliFS, env, token, dependencies));
78
83
  });
79
84
  program
80
85
  .command('build')
81
86
  .addOption(new commander_1.Option('-p --part <APM part>', 'APM part that should be build').choices(Object.values(apm_1.APM.Part)))
82
- .action(async (opts) => {
83
- await package_1.Package.buildAll(cwd, cliFS_1.cliFS, opts.part);
87
+ .action(opts => {
88
+ main((0, api_1.build)(cwd, cliFS_1.cliFS, logger, opts.part));
84
89
  });
85
90
  const releasePhaseArguments = Object.values(apm_1.APM.TagPhase);
86
91
  program
@@ -92,17 +97,8 @@ program
92
97
  .addOption(optionStudioEnv)
93
98
  .addOption(optionStudioToken)
94
99
  .action(async (opts) => {
95
- const env = handleStudioEnv(opts.env);
96
- const token = getStudioApiToken(opts);
97
- let allowedBackends = null;
98
- if (opts.allowedBackends) {
99
- allowedBackends = opts.allowedBackends === '*' ? opts.allowedBackends : opts.allowedBackends.split(';');
100
- const errorMessage = await manifest_1.Manifest.validateRegistryAllowedBackends(allowedBackends);
101
- if (errorMessage) {
102
- throw new Error(errorMessage);
103
- }
104
- }
105
- await package_1.Package.release(cwd, cliFS_1.cliFS, token, opts.phase, allowedBackends, env);
100
+ const { env, token } = getDefaultOptions(opts);
101
+ main((0, api_1.publish)(cwd, cliFS_1.cliFS, logger, env, token, opts.allowedBackends, opts.phase));
106
102
  });
107
103
  module.exports = function (argv) {
108
104
  program.parse(argv);
@@ -20,43 +20,76 @@ var Package;
20
20
  * Build the whole project or only a specific part
21
21
  * @param cwd
22
22
  * @param fs
23
- * @param apmPart - choose a specific part that should be build
23
+ * @param logger
24
+ * @param selectedParts - choose a specific part that should be build or if true all parts are build
24
25
  */
25
- async function buildAll(cwd, fs, apmPart) {
26
- if (!apmPart || apmPart === apm_1.APM.Part.dde) {
27
- await buildDDE(cwd, fs);
26
+ async function buildAll(cwd, fs, logger, selectedParts = true) {
27
+ if (selectedParts === true) {
28
+ logger.info('Building project...');
28
29
  }
29
- if (!apmPart || apmPart === apm_1.APM.Part.dlo) {
30
- await buildDLO(cwd, fs);
30
+ selectedParts = Object.values(apm_1.APM.Part);
31
+ const mergedDiagnostics = {
32
+ [apm_1.APM.Part.dde]: [],
33
+ [apm_1.APM.Part.dlo]: [],
34
+ [apm_1.APM.Part.dfiles]: []
35
+ };
36
+ // Helper for building parts
37
+ const buildMapping = {
38
+ [apm_1.APM.Part.dde]: buildDDE,
39
+ [apm_1.APM.Part.dlo]: buildDLO,
40
+ [apm_1.APM.Part.dfiles]: buildDfiles
41
+ };
42
+ // Build and validate specific parts
43
+ for (const part of [apm_1.APM.Part.dde, apm_1.APM.Part.dlo, apm_1.APM.Part.dfiles]) {
44
+ if (selectedParts.includes(part)) {
45
+ logger.info(`Building ${part.toUpperCase()}...`);
46
+ const hasError = await buildAndValidatePart(logger, part,
47
+ /*@ts-ignore*/
48
+ buildMapping[part],
49
+ /*@ts-ignore*/
50
+ mergedDiagnostics[part], cwd, fs);
51
+ if (hasError) {
52
+ return mergedDiagnostics; // Early exit on error
53
+ }
54
+ }
55
+ }
56
+ // Handle pov and blo parts that do not return diagnostics
57
+ if (selectedParts.includes(apm_1.APM.Part.pov)) {
58
+ await scriptRunner_1.Shell.tryBuildPov(cwd, fs, logger);
31
59
  }
32
- if (!apmPart || apmPart === apm_1.APM.Part.dfiles) {
33
- await buildDfiles(cwd, fs);
60
+ else {
61
+ logger.info('Skipping pov build');
34
62
  }
35
- if (!apmPart || apmPart === apm_1.APM.Part.pov) {
36
- await scriptRunner_1.Shell.tryBuildPov(cwd, fs);
63
+ if (selectedParts.includes(apm_1.APM.Part.blo)) {
64
+ await scriptRunner_1.Shell.tryBuildBlo(cwd, fs, logger);
37
65
  }
38
- if (!apmPart || apmPart === apm_1.APM.Part.blo) {
39
- await scriptRunner_1.Shell.tryBuildBlo(cwd, fs);
66
+ else {
67
+ logger.info('Skipping blo build');
40
68
  }
41
- console.log('DONE');
69
+ await processAdditionalFiles(cwd, fs, logger);
70
+ logger.done('Project build completed.');
71
+ return mergedDiagnostics;
42
72
  }
43
73
  Package.buildAll = buildAll;
44
74
  /**
45
75
  * Trigger the release based on the manifest settings
46
76
  * @param cwd
47
77
  * @param fs
78
+ * @param logger
48
79
  * @param token
49
80
  * @param releasePhase
50
81
  * @param allowedBackends
51
82
  * @param env
52
83
  */
53
- async function release(cwd, fs, token, releasePhase, allowedBackends, env) {
84
+ async function release(cwd, fs, logger, token, releasePhase, allowedBackends, env) {
54
85
  const manifest = await manifest_1.Manifest.read(cwd, fs);
55
86
  if (manifest_1.Manifest.isLibrary(manifest)) {
56
- await releaseLibrary(cwd, fs, token, env);
87
+ logger.info('Library project detected. Publishing library...');
88
+ return releaseLibrary(cwd, fs, logger, token, env);
57
89
  }
58
90
  else {
59
- await releaseAPM(cwd, fs, token, releasePhase, allowedBackends, env);
91
+ logger.info('App project detected. Publishing app...');
92
+ return releaseAPM(cwd, fs, logger, token, releasePhase, allowedBackends, env);
60
93
  }
61
94
  }
62
95
  Package.release = release;
@@ -64,12 +97,13 @@ var Package;
64
97
  * Publish an application model tag
65
98
  * @param cwd
66
99
  * @param fs
100
+ * @param logger
67
101
  * @param token
68
102
  * @param releasePhase
69
103
  * @param allowedBackends
70
104
  * @param env
71
105
  */
72
- async function releaseAPM(cwd, fs, token, releasePhase, allowedBackends = null, env) {
106
+ async function releaseAPM(cwd, fs, logger, token, releasePhase, allowedBackends = null, env) {
73
107
  if (!Object.values(apm_1.APM.TagPhase).includes(releasePhase)) {
74
108
  throw new Error(`ReleasePhase: ${releasePhase} is not a valid release phase`);
75
109
  }
@@ -79,7 +113,7 @@ var Package;
79
113
  return;
80
114
  }
81
115
  // build the complete project
82
- await buildAll(cwd, fs);
116
+ await buildAll(cwd, fs, logger);
83
117
  // update the store apm with the actual name/description/...
84
118
  await apm_1.APM.updateProfile(cwd, fs, token, env);
85
119
  const tagContent = await apm_1.APM.createTag(cwd, fs, releasePhase);
@@ -90,27 +124,28 @@ var Package;
90
124
  await registryAPI_1.Registry.updateExistingApplicationVersion(token, manifest.publisher, manifest.registry?.id, manifest.version, {
91
125
  allowedBackends
92
126
  }, env);
93
- console.log(`Tag "${newTag.version}" with phase "${newTag.phase}" shared with ${[...allowedBackends].join(';')}!`);
127
+ logger.info(`Tag "${newTag.version}" with phase "${newTag.phase}" shared with ${[...allowedBackends].join(';')}!`);
94
128
  }
95
- console.log(`Tag "${newTag.version}" with phase "${newTag.phase}" published!`);
129
+ logger.done(`Tag "${newTag.version}" with phase "${newTag.phase}" published!`);
96
130
  }
97
131
  Package.releaseAPM = releaseAPM;
98
132
  /**
99
133
  * Publish a library project
100
134
  * @param cwd
101
135
  * @param fs
136
+ * @param logger
102
137
  * @param token
103
138
  * @param env
104
139
  */
105
- async function releaseLibrary(cwd, fs, token, env) {
140
+ async function releaseLibrary(cwd, fs, logger, token, env) {
106
141
  const manifest = await manifest_1.Manifest.read(cwd, fs);
107
142
  await manifest_1.Manifest.validateBasicManifest(cwd, fs, manifest);
108
143
  await validatePublishSettings(cwd, fs, token, env);
109
144
  // build the complete project
110
- await buildAll(cwd, fs);
145
+ await buildAll(cwd, fs, logger);
111
146
  const archive = await library_1.Library.createArchive(cwd, fs);
112
147
  await library_1.Library.publishPackage(cwd, fs, token, archive, env);
113
- console.log(`Library "${manifest.publisher}/${manifest.name}" with version "${manifest.version}" published!`);
148
+ logger.done(`Library "${manifest.publisher}/${manifest.name}" with version "${manifest.version}" published!`);
114
149
  }
115
150
  Package.releaseLibrary = releaseLibrary;
116
151
  /**
@@ -196,55 +231,73 @@ var Package;
196
231
  * Generates all needed files out of the dde declaration
197
232
  * @param cwd
198
233
  * @param fs
234
+ * @param logger
199
235
  */
200
- async function buildDDE(cwd, fs) {
201
- console.log('Processing DDE...');
202
- const result = await dde_1.DDE.compileDDE(cwd, fs);
203
- result.diagnostics.forEach(diagnostic => {
204
- const message = `${diagnostic.file.path}: ${diagnostic.message}`;
205
- if (diagnostic.level === 'error') {
206
- console.error(message);
207
- }
208
- else if (diagnostic.level === 'warning') {
209
- console.warn(message);
210
- }
211
- else {
212
- console.log(message);
213
- }
214
- });
215
- throwIfDiagnosticsHaveError(apm_1.APM.Part.dde, result.diagnostics);
236
+ async function buildDDE(cwd, fs, logger) {
237
+ const result = await dde_1.DDE.compileDDE(cwd, fs, logger);
216
238
  if (result.ddeJSON) {
217
- await dde_1.DDE.exportMyDatanetXML(cwd, fs, result.ddeJSON);
239
+ await dde_1.DDE.exportMyDatanetXML(cwd, fs, logger, result.ddeJSON);
218
240
  const manifest = await manifest_1.Manifest.read(cwd, fs);
219
241
  // a library does not need a history.json
220
242
  if (!manifest_1.Manifest.isLibrary(manifest)) {
221
- await dde_1.DDE.exportHistoryJson(cwd, fs, result.ddeJSON);
243
+ await dde_1.DDE.exportHistoryJson(cwd, fs, logger, result.ddeJSON);
222
244
  }
223
- await dde_1.DDE.exportOpenApi(cwd, fs, result.ddeJSON);
245
+ await dde_1.DDE.exportOpenApi(cwd, fs, logger, result.ddeJSON);
224
246
  if (await manifest_1.Manifest.isApmPartEnabled(cwd, fs, apm_1.APM.Part.dlo, manifest)) {
225
- await dde_1.DDE.exportAutoDloFiles(cwd, fs, result.ddeJSON);
226
- await dlo_1.DLO.exportDloConfig(cwd, fs);
247
+ await dde_1.DDE.exportAutoDloFiles(cwd, fs, logger, result.ddeJSON);
248
+ await dlo_1.DLO.exportDloConfig(cwd, fs, logger);
227
249
  }
228
250
  }
229
- else {
230
- throw new Error('Project has errors!');
231
- }
251
+ return result.diagnostics;
232
252
  }
233
- async function buildDLO(cwd, fs) {
234
- console.log('Processing DLO...');
235
- const compiler = new compiler_1.DloCompiler();
253
+ async function buildDLO(cwd, fs, logger) {
254
+ const compiler = new compiler_1.DloCompiler(logger);
236
255
  const { diagnostics } = await compiler.compile(cwd, fs);
237
- throwIfDiagnosticsHaveError(apm_1.APM.Part.dlo, diagnostics);
256
+ return diagnostics;
238
257
  }
239
- async function buildDfiles(cwd, fs) {
240
- console.log('Processing DFILES...');
241
- const diagnostics = await dfiles_1.DFILES.process(cwd, fs);
242
- throwIfDiagnosticsHaveError(apm_1.APM.Part.dfiles, diagnostics);
258
+ async function buildDfiles(cwd, fs, logger) {
259
+ return await dfiles_1.DFILES.process(cwd, fs, logger);
243
260
  }
244
- function throwIfDiagnosticsHaveError(apmPart, diagnostics) {
261
+ /**
262
+ * Handle additional files like `mdn_report_template.json`
263
+ * @private
264
+ */
265
+ async function processAdditionalFiles(cwd, fs, logger) {
266
+ const reportTemplate = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.fileNames.reportTemplate);
267
+ if (await fs.stat(reportTemplate)) {
268
+ const distFolder = vscode_uri_1.Utils.joinPath(cwd, defaultFiles_1.DefaultFiles.filePaths.dist.reportTemplate);
269
+ await fs.copy(reportTemplate, distFolder);
270
+ logger.log(`Copied "${defaultFiles_1.DefaultFiles.fileNames.reportTemplate}" to dist folder.`);
271
+ }
272
+ }
273
+ function validateDiagnostics(logger, apmPart, diagnostics) {
274
+ if (apmPart !== apm_1.APM.Part.dlo) {
275
+ // dlo compiler does log diagnostics by itself
276
+ logDiagnostics(logger, diagnostics);
277
+ }
278
+ const hasErrors = diagnostics.some(diagnostic => diagnostic.level === 'error');
279
+ if (hasErrors) {
280
+ const message = `APM part "${apmPart}" has errors. Aborted.`;
281
+ throw new Error(message);
282
+ }
283
+ return hasErrors;
284
+ }
285
+ async function buildAndValidatePart(logger, part, buildFn, mergedDiagnostics, cwd, fs) {
286
+ const diagnostics = await buildFn(cwd, fs, logger);
287
+ mergedDiagnostics.push(...diagnostics);
288
+ return validateDiagnostics(logger, part, diagnostics);
289
+ }
290
+ function logDiagnostics(logger, diagnostics) {
245
291
  diagnostics.forEach(diagnostic => {
292
+ const message = `${diagnostic.file.path}: ${diagnostic.message}`;
246
293
  if (diagnostic.level === 'error') {
247
- throw new Error(`APM part '${apmPart}' has errors. Aborted.`);
294
+ logger.error(message);
295
+ }
296
+ else if (diagnostic.level === 'warning') {
297
+ logger.warn(message);
298
+ }
299
+ else {
300
+ logger.log(message);
248
301
  }
249
302
  });
250
303
  }
@@ -34,15 +34,16 @@ var Shell;
34
34
  * Calls the POV build command defined within the manifest
35
35
  * @param cwd
36
36
  * @param fs
37
+ * @param logger
37
38
  */
38
- async function tryBuildPov(cwd, fs) {
39
+ async function tryBuildPov(cwd, fs, logger) {
39
40
  const manifest = await manifest_1.Manifest.read(cwd, fs);
40
41
  if (await manifest_1.Manifest.isApmPartEnabled(cwd, fs, apm_1.APM.Part.pov)) {
41
- console.log('Executing POV build script', manifest.pov?.details.buildCommand);
42
+ logger.info('Executing POV build script', manifest.pov?.details.buildCommand);
42
43
  const { buildCommand, workingPath } = manifest.pov.details;
43
44
  const povDir = vscode_uri_1.Utils.joinPath(cwd, workingPath);
44
45
  try {
45
- await execShell(povDir, buildCommand);
46
+ await execShell(povDir, buildCommand, logger);
46
47
  }
47
48
  catch (e) {
48
49
  if (e.code) {
@@ -59,15 +60,16 @@ var Shell;
59
60
  * Calls the BLO build command defined within the manifest
60
61
  * @param cwd
61
62
  * @param fs
63
+ * @param logger
62
64
  */
63
- async function tryBuildBlo(cwd, fs) {
65
+ async function tryBuildBlo(cwd, fs, logger) {
64
66
  const manifest = await manifest_1.Manifest.read(cwd, fs);
65
67
  if (await manifest_1.Manifest.isApmPartEnabled(cwd, fs, apm_1.APM.Part.blo, manifest)) {
66
- console.log('Executing BLO build script', manifest.blo?.buildCommand);
68
+ logger.info('Executing BLO build script', manifest.blo?.buildCommand);
67
69
  const { buildCommand, workingPath } = manifest.blo;
68
70
  const bloDir = vscode_uri_1.Utils.joinPath(cwd, workingPath);
69
71
  try {
70
- await execShell(bloDir, buildCommand);
72
+ await execShell(bloDir, buildCommand, logger);
71
73
  }
72
74
  catch (e) {
73
75
  if (e.code) {
@@ -85,13 +87,14 @@ var Shell;
85
87
  * Generic shell executor
86
88
  * @param cwd - working dir where the command should be executed in
87
89
  * @param cmd - the shell command
90
+ * @param logger
88
91
  */
89
- async function execShell(cwd, cmd) {
92
+ async function execShell(cwd, cmd, logger) {
90
93
  return new Promise((resolve, reject) => {
91
94
  // todo use spawn instead of exec to allow streaming to the console
92
95
  child_process.exec(cmd, { cwd: cwd.fsPath, env: process.env }, (error, stdout, stderr) => {
93
- console.log(stdout);
94
- console.error(stderr);
96
+ logger.log(stdout);
97
+ logger.error(stderr);
95
98
  if (error) {
96
99
  reject(error);
97
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microtronics/studio-cli",
3
- "version": "0.24.1",
3
+ "version": "0.26.0",
4
4
  "description": "Microtronics Studio CLI Tool",
5
5
  "main": "./out/api.js",
6
6
  "typings": "./dist/studio-cli.d.ts",
@@ -28,6 +28,7 @@
28
28
  "ajv": "^8.17.1",
29
29
  "ajv-formats": "^3.0.1",
30
30
  "ajv-keywords": "^5.1.0",
31
+ "chalk": "^5.4.1",
31
32
  "commander": "^12.1.0",
32
33
  "cross-fetch": "^4.0.0",
33
34
  "dotenv": "^16.4.7",
@@ -42,6 +43,7 @@
42
43
  "semver": "^7.6.3",
43
44
  "tarballjs": "github:ankitrohatgi/tarballjs",
44
45
  "tinytar-fix": "^0.1.1",
46
+ "update-notifier": "^7.3.1",
45
47
  "vscode-uri": "^3.0.8",
46
48
  "yaml": "^2.6.1"
47
49
  },
@@ -56,6 +58,7 @@
56
58
  "@types/mocha": "^10.0.9",
57
59
  "@types/node": "^22.9.1",
58
60
  "@types/semver": "^7.5.6",
61
+ "@types/update-notifier": "^6.0.8",
59
62
  "@types/vscode": "^1.86.2",
60
63
  "chai": "^4.3.8",
61
64
  "chai-as-promised": "^7.1.2",