@trackunit/iris-app-webpack-plugin 0.0.219 → 0.0.221

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
@@ -2,6 +2,16 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.221](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.220...iris-app-webpack-plugin/0.0.221) (2024-09-16)
6
+
7
+ ### Dependency Updates
8
+
9
+ * `iris-app-api` updated to version `0.0.220`
10
+ ## [0.0.220](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.219...iris-app-webpack-plugin/0.0.220) (2024-09-11)
11
+
12
+ ### Dependency Updates
13
+
14
+ * `iris-app-api` updated to version `0.0.219`
5
15
  ## [0.0.219](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.218...iris-app-webpack-plugin/0.0.219) (2024-09-09)
6
16
 
7
17
  ### Dependency Updates
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/iris-app-webpack-plugin",
3
- "version": "0.0.219",
3
+ "version": "0.0.221",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "engines": {
@@ -2,49 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TrackunitIrisAppWebpackPlugin = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const iris_app_api_1 = require("@trackunit/iris-app-api");
6
- const crypto_1 = require("crypto");
7
- const csp_header_1 = require("csp-header");
8
5
  const fs = tslib_1.__importStar(require("fs"));
9
6
  const path = tslib_1.__importStar(require("path"));
10
- const process_1 = require("process");
11
- const RESET = "\x1b[0m";
12
- const GREEN = "\x1b[32m";
13
- const RED = "\x1b[31m";
14
- const YELLOW = "\x1b[33m";
15
- const convertTranslationKeyIfNeeded = (translationObj, srcDir) => {
16
- if (isTranslationKey(translationObj)) {
17
- const translationKey = translationObj.key;
18
- const enTranslationFilePath = path.join(srcDir, "locales", "en", "translation.json");
19
- if (!fs.existsSync(enTranslationFilePath)) {
20
- // eslint-disable-next-line no-console
21
- console.error(RED, ` ✨ Translation file not found for: "${translationObj.key}" looked here: ${enTranslationFilePath}`, RESET);
22
- (0, process_1.exit)(1);
23
- }
24
- const enTranslations = JSON.parse(fs.readFileSync(enTranslationFilePath, "utf8"));
25
- if (!enTranslations[translationKey]) {
26
- // eslint-disable-next-line no-console
27
- console.error(RED, ` ✨ Translation not found for: "${translationObj.key}" looked here: ${enTranslationFilePath}`, RESET);
28
- (0, process_1.exit)(1);
29
- }
30
- iris_app_api_1.languageKeys.forEach(languageCode => {
31
- const translationFilePath = path.join(srcDir, "locales", languageCode, "translation.json");
32
- if (fs.existsSync(translationFilePath)) {
33
- const translations = JSON.parse(fs.readFileSync(translationFilePath, "utf8"));
34
- // Here we substitute the translation key with the actual translation
35
- translationObj[languageCode] = translations[translationKey];
36
- }
37
- else {
38
- // eslint-disable-next-line no-console
39
- console.log(YELLOW, ` ✨ Warning translation file not found for: "${translationObj.key}" looked here: ${translationFilePath}`, RESET);
40
- }
41
- });
42
- delete translationObj.key;
43
- }
44
- };
45
- const isTranslationKey = (object) => {
46
- return !!(object === null || object === void 0 ? void 0 : object.key);
47
- };
7
+ const consoleUtils_1 = require("./consoleUtils");
8
+ const customFieldUtil_1 = require("./customFieldUtil");
9
+ const extensionUtil_1 = require("./extensionUtil");
10
+ const indexHtmlUtil_1 = require("./indexHtmlUtil");
48
11
  /**
49
12
  * Webpack plugin that generates a manifest.json file
50
13
  */
@@ -74,8 +37,7 @@ class TrackunitIrisAppWebpackPlugin {
74
37
  compiler.hooks.done.tap("AfterBuildPlugin", stats => {
75
38
  if (!stats.hasErrors()) {
76
39
  setTimeout(() => {
77
- // eslint-disable-next-line no-console
78
- console.log(GREEN, "\n✨ Iris App is now started, check it out ✨\nhttps://new.manager.trackunit.com/goto/iris-app-dev\n", RESET);
40
+ (0, consoleUtils_1.logInfo)("\n✨ Iris App is now started, check it out ✨\nhttps://new.manager.trackunit.com/goto/iris-app-dev\n");
79
41
  }, 0);
80
42
  }
81
43
  });
@@ -93,126 +55,19 @@ class TrackunitIrisAppWebpackPlugin {
93
55
  // "assets" is an object that contains all assets
94
56
  // in the compilation, the keys of the object are pathnames of the assets
95
57
  // and the values are file sources.
96
- var _a;
97
58
  // Iterating over all the assets and
98
59
  // generating content for our Markdown file.
99
60
  if (!this.options.manifest) {
100
61
  throw Error("you must provide a app manifest");
101
62
  }
102
- const manifest = this.options.manifest;
103
- const indexContents = fs.readFileSync(path.join(__dirname, "index.html"), "utf8");
104
63
  const manifestJson = this.options.manifest;
105
64
  const appSrc = path.join(this.options.appDir, "src");
106
- (_a = this.options.manifest.customFieldDefinitions) === null || _a === void 0 ? void 0 : _a.forEach(customFieldDefinition => {
107
- if ((0, iris_app_api_1.isCustomFieldTranslationArray)(customFieldDefinition.translations)) {
108
- const foundEn = customFieldDefinition.translations.find(translation => translation.language === "en");
109
- if (!foundEn) {
110
- // eslint-disable-next-line no-console
111
- console.error(RED, ` ✨ Translation not found for language "en" you must supply the english translation for custom field: ${customFieldDefinition.key}`, RESET);
112
- (0, process_1.exit)(1);
113
- }
114
- }
115
- else {
116
- convertTranslationKeyIfNeeded(customFieldDefinition.translations.title, appSrc);
117
- convertTranslationKeyIfNeeded(customFieldDefinition.translations.description, appSrc);
118
- // now transform to array
119
- const titles = customFieldDefinition.translations.title;
120
- const descriptions = customFieldDefinition.translations
121
- .description;
122
- const keys = Object.keys(titles);
123
- const foundEn = keys.indexOf("en") !== -1;
124
- if (!foundEn) {
125
- // eslint-disable-next-line no-console
126
- console.error(RED, ` ✨ Translation not found for language "en" you must supply the english translation for custom field: ${customFieldDefinition.key}`, RESET);
127
- (0, process_1.exit)(1);
128
- }
129
- const translations = [
130
- {
131
- language: "en",
132
- title: titles.en,
133
- description: descriptions.en,
134
- },
135
- ];
136
- keys.forEach(language => {
137
- if (language !== "en") {
138
- translations.push({
139
- language,
140
- title: titles[language],
141
- description: descriptions[language],
142
- });
143
- }
144
- });
145
- customFieldDefinition.translations = translations;
146
- }
147
- });
148
- manifestJson.extensions = this.options.manifest.extensions;
149
- this.options.manifest.extensions.forEach(extension => {
150
- var _a, _b;
151
- const translationKey = (extension.type !== "IRIS_APP_SETTINGS_EXTENSION" &&
152
- extension.type !== "WIDGET_EXTENSION" &&
153
- extension.type !== "LIFECYCLE_EXTENSION" &&
154
- extension.menuItem.name) ||
155
- null;
156
- convertTranslationKeyIfNeeded(translationKey, extension.sourceRoot);
157
- const headerTranslationKey = (extension.type === "WIDGET_EXTENSION" && extension.header.name) || null;
158
- convertTranslationKeyIfNeeded(headerTranslationKey, extension.sourceRoot);
159
- if (extension.type === "REPORT_EXTENSION" && isTranslationKey(extension.menuItem.description)) {
160
- const description = extension.menuItem.description;
161
- convertTranslationKeyIfNeeded(description, extension.sourceRoot);
162
- }
163
- if (extension.type === "ASSET_HOME_EXTENSION" || extension.type === "FLEET_EXTENSION") {
164
- if ((_a = extension.conditions) === null || _a === void 0 ? void 0 : _a.brand) {
165
- if (Array.isArray(extension.conditions.brand)) {
166
- extension.conditions.brand.forEach(brand => {
167
- if (typeof brand !== "string") {
168
- brand.pattern = brand.pattern.toString();
169
- }
170
- });
171
- }
172
- else if (typeof extension.conditions.brand !== "string") {
173
- extension.conditions.brand.pattern = extension.conditions.brand.pattern.toString();
174
- }
175
- }
176
- if ((_b = extension.conditions) === null || _b === void 0 ? void 0 : _b.model) {
177
- if (Array.isArray(extension.conditions.model)) {
178
- extension.conditions.model.forEach(model => {
179
- if (typeof model !== "string") {
180
- model.pattern = model.pattern.toString();
181
- }
182
- });
183
- }
184
- else if (typeof extension.conditions.model !== "string") {
185
- extension.conditions.model.pattern = extension.conditions.model.pattern.toString();
186
- }
187
- }
188
- if (extension.type === "FLEET_EXTENSION" &&
189
- (0, iris_app_api_1.isIconImage)(extension.menuItem.image) &&
190
- !extension.menuItem.image.path.startsWith(extension.id)) {
191
- extension.menuItem.image.path = extension.id + "/" + extension.menuItem.image.path.toString();
192
- }
193
- }
194
- });
195
- manifestJson.extensions = this.options.manifest.extensions;
65
+ manifestJson.customFieldDefinitions = (0, customFieldUtil_1.updateCustomFields)(this.options.manifest.customFieldDefinitions, appSrc);
66
+ manifestJson.extensions = (0, extensionUtil_1.updateExtensions)(this.options.manifest.extensions);
196
67
  compilation.emitAsset("manifest.json", new RawSource(JSON.stringify(manifestJson, null, 2)));
197
68
  const packageJson = fs.readFileSync(`${this.options.appDir}/package.json`, "utf8");
198
69
  compilation.emitAsset("package.json", new RawSource(packageJson));
199
- const scopeAndModuleNonce = (0, crypto_1.randomBytes)(16).toString("base64");
200
- const csp = (0, csp_header_1.getCSP)({
201
- directives: (0, iris_app_api_1.irisAppCspInput)(manifest.validDomains, manifest.cspHeader),
202
- presets: {
203
- irisAppDefaultCsp: iris_app_api_1.irisAppDefaultCsp,
204
- localDev: { "connect-src": ["ws://localhost:8097/"], "script-src": [`'nonce-${scopeAndModuleNonce}'`] },
205
- },
206
- });
207
- let html = indexContents.replace("{{cspContent}}", csp);
208
- html = html.replace("{{nonce}}", scopeAndModuleNonce);
209
- html = html.replace("{{scope}}", JSON.parse(packageJson).name);
210
- if (manifestJson.scopes) {
211
- html = html.replace("{{manifestScopes}}", JSON.stringify(manifestJson.scopes));
212
- }
213
- else {
214
- html = html.replace("{{manifestScopes}}", "[]");
215
- }
70
+ const html = (0, indexHtmlUtil_1.updateIndexHtml)(fs.readFileSync(path.join(__dirname, "index.html"), "utf8"), manifestJson, packageJson);
216
71
  // Adding new asset to the compilation, so it would be automatically
217
72
  // generated by the webpack in the output directory.
218
73
  compilation.emitAsset("index.html", new RawSource(html));
@@ -1 +1 @@
1
- {"version":3,"file":"TrackunitIrisAppWebpackPlugin.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/TrackunitIris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MAAM,GAAG,GAAG,IAAA,mBAAM,EAAC;oBACjB,UAAU,EAAE,IAAA,8BAAe,EAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,SAAS,CAAC;oBACtE,OAAO,EAAE;wBACP,iBAAiB,EAAjB,gCAAiB;wBACjB,QAAQ,EAAE,EAAE,aAAa,EAAE,CAAC,sBAAsB,CAAC,EAAE,YAAY,EAAE,CAAC,UAAU,mBAAmB,GAAG,CAAC,EAAE;qBACxG;iBACF,CAAC,CAAC;gBACH,IAAI,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;gBAExD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;gBAEtD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;gBAC/D,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC;oBACxB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;gBACjF,CAAC;qBAAM,CAAC;oBACN,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;gBAClD,CAAC;gBACD,oEAAoE;gBACpE,oDAAoD;gBACpD,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3D,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7MD,sEA6MC","sourcesContent":["import {\n CustomFieldTranslationArray,\n irisAppCspInput,\n irisAppDefaultCsp,\n IrisAppManifest,\n isCustomFieldTranslationArray,\n isIconImage,\n languageKeys,\n TranslationKey,\n TranslationLanguageKeys,\n Translations,\n} from \"@trackunit/iris-app-api\";\nimport { randomBytes } from \"crypto\";\nimport { getCSP } from \"csp-header\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { exit } from \"process\";\nimport * as wp from \"webpack\";\n\ninterface TrackunitIrisAppWebpackPluginOptions {\n nxRootDir: string;\n appDir: string;\n manifest?: IrisAppManifest;\n}\n\nconst RESET = \"\\x1b[0m\";\nconst GREEN = \"\\x1b[32m\";\nconst RED = \"\\x1b[31m\";\nconst YELLOW = \"\\x1b[33m\";\n\nconst convertTranslationKeyIfNeeded = (\n translationObj: string | Translations | TranslationKey | null | undefined,\n srcDir: string\n) => {\n if (isTranslationKey(translationObj)) {\n const translationKey = translationObj.key;\n\n const enTranslationFilePath = path.join(srcDir, \"locales\", \"en\", \"translation.json\");\n if (!fs.existsSync(enTranslationFilePath)) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation file not found for: \"${translationObj.key}\" looked here: ${enTranslationFilePath}`,\n RESET\n );\n exit(1);\n }\n const enTranslations = JSON.parse(fs.readFileSync(enTranslationFilePath, \"utf8\"));\n if (!enTranslations[translationKey]) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for: \"${translationObj.key}\" looked here: ${enTranslationFilePath}`,\n RESET\n );\n exit(1);\n }\n\n languageKeys.forEach(languageCode => {\n const translationFilePath = path.join(srcDir, \"locales\", languageCode, \"translation.json\");\n if (fs.existsSync(translationFilePath)) {\n const translations = JSON.parse(fs.readFileSync(translationFilePath, \"utf8\"));\n // Here we substitute the translation key with the actual translation\n (translationObj as unknown as Translations)[languageCode] = translations[translationKey];\n } else {\n // eslint-disable-next-line no-console\n console.log(\n YELLOW,\n ` ✨ Warning translation file not found for: \"${translationObj.key}\" looked here: ${translationFilePath}`,\n RESET\n );\n }\n });\n delete (translationObj as { key?: string }).key;\n }\n};\n\nconst isTranslationKey = (\n object: string | Translations | TranslationKey | undefined | null\n): object is TranslationKey => {\n return !!(object as { key?: string } | null)?.key;\n};\n\n/**\n * Webpack plugin that generates a manifest.json file\n */\nexport class TrackunitIrisAppWebpackPlugin {\n /**\n * @param options - Plugin options\n * @param {string} options.appDir - Directory path where the app resides\n * @param {object} options.manifest - Object containing the app's manifest\n */\n public constructor(private options: TrackunitIrisAppWebpackPluginOptions) {}\n\n /**\n Webpack plugin for generating a Markdown file from app manifest and index HTML file.\n */\n public apply(compiler: wp.Compiler) {\n const pluginName = TrackunitIrisAppWebpackPlugin.name;\n\n // webpack module instance can be accessed from the compiler object,\n // this ensures that correct version of the module is used\n // (do not require/import the webpack or any symbols from it directly).\n const { webpack } = compiler;\n\n // Compilation object gives us reference to some useful constants.\n const { Compilation } = webpack;\n\n // RawSource is one of the \"sources\" classes that should be used\n // to represent asset sources in compilation.\n const { RawSource } = webpack.sources;\n\n compiler.hooks.done.tap(\"AfterBuildPlugin\", stats => {\n if (!stats.hasErrors()) {\n setTimeout(() => {\n // eslint-disable-next-line no-console\n console.log(\n GREEN,\n \"\\n✨ Iris App is now started, check it out ✨\\nhttps://new.manager.trackunit.com/goto/iris-app-dev\\n\",\n RESET\n );\n }, 0);\n }\n });\n\n // Tapping to the \"thisCompilation\" hook in order to further tap\n // to the compilation process on an earlier stage.\n compiler.hooks.thisCompilation.tap(pluginName, (compilation: wp.Compilation) => {\n // Tapping to the assets processing pipeline on a specific stage.\n compilation.contextDependencies.add(this.options.appDir);\n compilation.hooks.processAssets.tap(\n {\n name: pluginName,\n\n // Using one of the later asset processing stages to ensure\n // that all assets were already added to the compilation by other plugins.\n stage: Compilation.PROCESS_ASSETS_STAGE_DERIVED,\n },\n async assets => {\n // \"assets\" is an object that contains all assets\n // in the compilation, the keys of the object are pathnames of the assets\n // and the values are file sources.\n\n // Iterating over all the assets and\n // generating content for our Markdown file.\n if (!this.options.manifest) {\n throw Error(\"you must provide a app manifest\");\n }\n const manifest = this.options.manifest;\n const indexContents = fs.readFileSync(path.join(__dirname, \"index.html\"), \"utf8\");\n\n const manifestJson = this.options.manifest;\n\n const appSrc = path.join(this.options.appDir, \"src\");\n this.options.manifest.customFieldDefinitions?.forEach(customFieldDefinition => {\n if (isCustomFieldTranslationArray(customFieldDefinition.translations)) {\n const foundEn = customFieldDefinition.translations.find(translation => translation.language === \"en\");\n if (!foundEn) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`,\n RESET\n );\n exit(1);\n }\n } else {\n convertTranslationKeyIfNeeded(customFieldDefinition.translations.title, appSrc);\n convertTranslationKeyIfNeeded(customFieldDefinition.translations.description, appSrc);\n\n // now transform to array\n\n const titles: Translations = customFieldDefinition.translations.title as unknown as Translations;\n const descriptions: Translations = customFieldDefinition.translations\n .description as unknown as Translations;\n const keys = Object.keys(titles) as TranslationLanguageKeys[];\n\n const foundEn = keys.indexOf(\"en\") !== -1;\n if (!foundEn) {\n // eslint-disable-next-line no-console\n console.error(\n RED,\n ` ✨ Translation not found for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`,\n RESET\n );\n exit(1);\n }\n const translations: CustomFieldTranslationArray = [\n {\n language: \"en\",\n title: titles.en,\n description: descriptions.en,\n },\n ];\n\n keys.forEach(language => {\n if (language !== \"en\") {\n translations.push({\n language,\n title: titles[language]!,\n description: descriptions[language],\n });\n }\n });\n customFieldDefinition.translations = translations;\n }\n });\n\n manifestJson.extensions = this.options.manifest.extensions;\n this.options.manifest.extensions.forEach(extension => {\n const translationKey =\n (extension.type !== \"IRIS_APP_SETTINGS_EXTENSION\" &&\n extension.type !== \"WIDGET_EXTENSION\" &&\n extension.type !== \"LIFECYCLE_EXTENSION\" &&\n extension.menuItem.name) ||\n null;\n convertTranslationKeyIfNeeded(translationKey, extension.sourceRoot);\n\n const headerTranslationKey = (extension.type === \"WIDGET_EXTENSION\" && extension.header.name) || null;\n convertTranslationKeyIfNeeded(headerTranslationKey, extension.sourceRoot);\n\n if (extension.type === \"REPORT_EXTENSION\" && isTranslationKey(extension.menuItem.description)) {\n const description = extension.menuItem.description;\n convertTranslationKeyIfNeeded(description, extension.sourceRoot);\n }\n if (extension.type === \"ASSET_HOME_EXTENSION\" || extension.type === \"FLEET_EXTENSION\") {\n if (extension.conditions?.brand) {\n if (Array.isArray(extension.conditions.brand)) {\n extension.conditions.brand.forEach(brand => {\n if (typeof brand !== \"string\") {\n brand.pattern = brand.pattern.toString();\n }\n });\n } else if (typeof extension.conditions.brand !== \"string\") {\n extension.conditions.brand.pattern = extension.conditions.brand.pattern.toString();\n }\n }\n if (extension.conditions?.model) {\n if (Array.isArray(extension.conditions.model)) {\n extension.conditions.model.forEach(model => {\n if (typeof model !== \"string\") {\n model.pattern = model.pattern.toString();\n }\n });\n } else if (typeof extension.conditions.model !== \"string\") {\n extension.conditions.model.pattern = extension.conditions.model.pattern.toString();\n }\n }\n\n if (\n extension.type === \"FLEET_EXTENSION\" &&\n isIconImage(extension.menuItem.image) &&\n !extension.menuItem.image.path.startsWith(extension.id)\n ) {\n extension.menuItem.image.path = extension.id + \"/\" + extension.menuItem.image.path.toString();\n }\n }\n });\n\n manifestJson.extensions = this.options.manifest.extensions;\n compilation.emitAsset(\"manifest.json\", new RawSource(JSON.stringify(manifestJson, null, 2)));\n\n const packageJson = fs.readFileSync(`${this.options.appDir}/package.json`, \"utf8\");\n compilation.emitAsset(\"package.json\", new RawSource(packageJson));\n\n const scopeAndModuleNonce = randomBytes(16).toString(\"base64\");\n\n const csp = getCSP({\n directives: irisAppCspInput(manifest.validDomains, manifest.cspHeader),\n presets: {\n irisAppDefaultCsp,\n localDev: { \"connect-src\": [\"ws://localhost:8097/\"], \"script-src\": [`'nonce-${scopeAndModuleNonce}'`] },\n },\n });\n let html = indexContents.replace(\"{{cspContent}}\", csp);\n\n html = html.replace(\"{{nonce}}\", scopeAndModuleNonce);\n\n html = html.replace(\"{{scope}}\", JSON.parse(packageJson).name);\n if (manifestJson.scopes) {\n html = html.replace(\"{{manifestScopes}}\", JSON.stringify(manifestJson.scopes));\n } else {\n html = html.replace(\"{{manifestScopes}}\", \"[]\");\n }\n // Adding new asset to the compilation, so it would be automatically\n // generated by the webpack in the output directory.\n compilation.emitAsset(\"index.html\", new RawSource(html));\n }\n );\n });\n }\n}\n"]}
1
+ {"version":3,"file":"TrackunitIrisAppWebpackPlugin.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/TrackunitIrisAppWebpackPlugin.ts"],"names":[],"mappings":";;;;AACA,+CAAyB;AACzB,mDAA6B;AAE7B,iDAAyC;AACzC,uDAAuD;AACvD,mDAAmD;AACnD,mDAAkD;AAOlD;;GAEG;AACH,MAAa,6BAA6B;IACxC;;;;OAIG;IACH,YAA2B,OAA6C;QAA7C,YAAO,GAAP,OAAO,CAAsC;IAAG,CAAC;IAE5E;;OAEG;IACI,KAAK,CAAC,QAAqB;QAChC,MAAM,UAAU,GAAG,6BAA6B,CAAC,IAAI,CAAC;QAEtD,oEAAoE;QACpE,0DAA0D;QAC1D,uEAAuE;QACvE,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;QAE7B,kEAAkE;QAClE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAEhC,gEAAgE;QAChE,6CAA6C;QAC7C,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAEtC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,kBAAkB,EAAE,KAAK,CAAC,EAAE;YAClD,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,CAAC;gBACvB,UAAU,CAAC,GAAG,EAAE;oBACd,IAAA,sBAAO,EACL,oGAAoG,CACrG,CAAC;gBACJ,CAAC,EAAE,CAAC,CAAC,CAAC;YACR,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,gEAAgE;QAChE,kDAAkD;QAClD,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,EAAE,CAAC,WAA2B,EAAE,EAAE;YAC7E,iE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ElE,MAAM,IAAI,GAAG,IAAA,+BAAe,EAC1B,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,EAAE,MAAM,CAAC,EAC3D,YAAY,EACZ,WAAW,CACZ,CAAC;gBAEF,oEAAoE;gBACpE,oDAAoD;gBACpD,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3D,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAtFD,sEAsFC","sourcesContent":["import { IrisAppManifest } from \"@trackunit/iris-app-api\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport * as wp from \"webpack\";\nimport { logInfo } from \"./consoleUtils\";\nimport { updateCustomFields } from \"./customFieldUtil\";\nimport { updateExtensions } from \"./extensionUtil\";\nimport { updateIndexHtml } from \"./indexHtmlUtil\";\n\ninterface TrackunitIrisAppWebpackPluginOptions {\n nxRootDir: string;\n appDir: string;\n manifest?: IrisAppManifest;\n}\n/**\n * Webpack plugin that generates a manifest.json file\n */\nexport class TrackunitIrisAppWebpackPlugin {\n /**\n * @param options - Plugin options\n * @param {string} options.appDir - Directory path where the app resides\n * @param {object} options.manifest - Object containing the app's manifest\n */\n public constructor(private options: TrackunitIrisAppWebpackPluginOptions) {}\n\n /**\n Webpack plugin for generating a Markdown file from app manifest and index HTML file.\n */\n public apply(compiler: wp.Compiler) {\n const pluginName = TrackunitIrisAppWebpackPlugin.name;\n\n // webpack module instance can be accessed from the compiler object,\n // this ensures that correct version of the module is used\n // (do not require/import the webpack or any symbols from it directly).\n const { webpack } = compiler;\n\n // Compilation object gives us reference to some useful constants.\n const { Compilation } = webpack;\n\n // RawSource is one of the \"sources\" classes that should be used\n // to represent asset sources in compilation.\n const { RawSource } = webpack.sources;\n\n compiler.hooks.done.tap(\"AfterBuildPlugin\", stats => {\n if (!stats.hasErrors()) {\n setTimeout(() => {\n logInfo(\n \"\\n✨ Iris App is now started, check it out ✨\\nhttps://new.manager.trackunit.com/goto/iris-app-dev\\n\"\n );\n }, 0);\n }\n });\n\n // Tapping to the \"thisCompilation\" hook in order to further tap\n // to the compilation process on an earlier stage.\n compiler.hooks.thisCompilation.tap(pluginName, (compilation: wp.Compilation) => {\n // Tapping to the assets processing pipeline on a specific stage.\n compilation.contextDependencies.add(this.options.appDir);\n compilation.hooks.processAssets.tap(\n {\n name: pluginName,\n\n // Using one of the later asset processing stages to ensure\n // that all assets were already added to the compilation by other plugins.\n stage: Compilation.PROCESS_ASSETS_STAGE_DERIVED,\n },\n async assets => {\n // \"assets\" is an object that contains all assets\n // in the compilation, the keys of the object are pathnames of the assets\n // and the values are file sources.\n\n // Iterating over all the assets and\n // generating content for our Markdown file.\n if (!this.options.manifest) {\n throw Error(\"you must provide a app manifest\");\n }\n const manifestJson = this.options.manifest;\n\n const appSrc = path.join(this.options.appDir, \"src\");\n manifestJson.customFieldDefinitions = updateCustomFields(\n this.options.manifest.customFieldDefinitions,\n appSrc\n );\n\n manifestJson.extensions = updateExtensions(this.options.manifest.extensions);\n compilation.emitAsset(\"manifest.json\", new RawSource(JSON.stringify(manifestJson, null, 2)));\n\n const packageJson = fs.readFileSync(`${this.options.appDir}/package.json`, \"utf8\");\n compilation.emitAsset(\"package.json\", new RawSource(packageJson));\n\n const html = updateIndexHtml(\n fs.readFileSync(path.join(__dirname, \"index.html\"), \"utf8\"),\n manifestJson,\n packageJson\n );\n\n // Adding new asset to the compilation, so it would be automatically\n // generated by the webpack in the output directory.\n compilation.emitAsset(\"index.html\", new RawSource(html));\n }\n );\n });\n }\n}\n"]}
@@ -0,0 +1,16 @@
1
+ export declare const RESET = "\u001B[0m";
2
+ export declare const GREEN = "\u001B[32m";
3
+ export declare const RED = "\u001B[31m";
4
+ export declare const YELLOW = "\u001B[33m";
5
+ /**
6
+ * Logs an error message and exits the program with a non-zero exit code.
7
+ */
8
+ export declare const logError: (message: string) => void;
9
+ /**
10
+ * Logs a warning message.
11
+ */
12
+ export declare const logWarning: (message: string) => void;
13
+ /**
14
+ * Logs an info message.
15
+ */
16
+ export declare const logInfo: (message: string) => void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logInfo = exports.logWarning = exports.logError = exports.YELLOW = exports.RED = exports.GREEN = exports.RESET = void 0;
4
+ exports.RESET = "\x1b[0m";
5
+ exports.GREEN = "\x1b[32m";
6
+ exports.RED = "\x1b[31m";
7
+ exports.YELLOW = "\x1b[33m";
8
+ /**
9
+ * Logs an error message and exits the program with a non-zero exit code.
10
+ */
11
+ const logError = (message) => {
12
+ // eslint-disable-next-line no-console
13
+ console.error(exports.RED, message, exports.RESET);
14
+ };
15
+ exports.logError = logError;
16
+ /**
17
+ * Logs a warning message.
18
+ */
19
+ const logWarning = (message) => {
20
+ // eslint-disable-next-line no-console
21
+ console.warn(exports.YELLOW, message, exports.RESET);
22
+ };
23
+ exports.logWarning = logWarning;
24
+ /**
25
+ * Logs an info message.
26
+ */
27
+ const logInfo = (message) => {
28
+ // eslint-disable-next-line no-console
29
+ console.info(exports.GREEN, message, exports.RESET);
30
+ };
31
+ exports.logInfo = logInfo;
32
+ //# sourceMappingURL=consoleUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consoleUtils.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/consoleUtils.ts"],"names":[],"mappings":";;;AAAa,QAAA,KAAK,GAAG,SAAS,CAAC;AAClB,QAAA,KAAK,GAAG,UAAU,CAAC;AACnB,QAAA,GAAG,GAAG,UAAU,CAAC;AACjB,QAAA,MAAM,GAAG,UAAU,CAAC;AAEjC;;GAEG;AACI,MAAM,QAAQ,GAAG,CAAC,OAAe,EAAE,EAAE;IAC1C,sCAAsC;IACtC,OAAO,CAAC,KAAK,CAAC,WAAG,EAAE,OAAO,EAAE,aAAK,CAAC,CAAC;AACrC,CAAC,CAAC;AAHW,QAAA,QAAQ,YAGnB;AAEF;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,OAAe,EAAE,EAAE;IAC5C,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,cAAM,EAAE,OAAO,EAAE,aAAK,CAAC,CAAC;AACvC,CAAC,CAAC;AAHW,QAAA,UAAU,cAGrB;AAEF;;GAEG;AACI,MAAM,OAAO,GAAG,CAAC,OAAe,EAAE,EAAE;IACzC,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,aAAK,EAAE,OAAO,EAAE,aAAK,CAAC,CAAC;AACtC,CAAC,CAAC;AAHW,QAAA,OAAO,WAGlB","sourcesContent":["export const RESET = \"\\x1b[0m\";\nexport const GREEN = \"\\x1b[32m\";\nexport const RED = \"\\x1b[31m\";\nexport const YELLOW = \"\\x1b[33m\";\n\n/**\n * Logs an error message and exits the program with a non-zero exit code.\n */\nexport const logError = (message: string) => {\n // eslint-disable-next-line no-console\n console.error(RED, message, RESET);\n};\n\n/**\n * Logs a warning message.\n */\nexport const logWarning = (message: string) => {\n // eslint-disable-next-line no-console\n console.warn(YELLOW, message, RESET);\n};\n\n/**\n * Logs an info message.\n */\nexport const logInfo = (message: string) => {\n // eslint-disable-next-line no-console\n console.info(GREEN, message, RESET);\n};\n"]}
@@ -0,0 +1,9 @@
1
+ import { CustomFieldDefinition } from "@trackunit/iris-app-api";
2
+ /**
3
+ * Updates the custom field definitions with the given app source directory.
4
+ * If the custom field definitions are not provided, it returns an empty array.
5
+ * If the app source directory is not provided, it returns the custom field definitions.
6
+ *
7
+ * @returns {CustomFieldDefinition[]} the updated custom field definitions array
8
+ */
9
+ export declare const updateCustomFields: (customFieldDefinitions?: CustomFieldDefinition[], appSrc?: string) => CustomFieldDefinition[];
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateCustomFields = void 0;
4
+ const iris_app_api_1 = require("@trackunit/iris-app-api");
5
+ const process_1 = require("process");
6
+ const consoleUtils_1 = require("./consoleUtils");
7
+ const irisAppTranslationUtils_1 = require("./irisAppTranslationUtils");
8
+ /**
9
+ * Updates the custom field definitions with the given app source directory.
10
+ * If the custom field definitions are not provided, it returns an empty array.
11
+ * If the app source directory is not provided, it returns the custom field definitions.
12
+ *
13
+ * @returns {CustomFieldDefinition[]} the updated custom field definitions array
14
+ */
15
+ const updateCustomFields = (customFieldDefinitions, appSrc
16
+ // eslint-disable-next-line sonarjs/cognitive-complexity
17
+ ) => {
18
+ if (!customFieldDefinitions || !appSrc) {
19
+ return [];
20
+ }
21
+ customFieldDefinitions.forEach(customFieldDefinition => {
22
+ if ((0, iris_app_api_1.isCustomFieldTranslationArray)(customFieldDefinition.translations)) {
23
+ const foundEn = customFieldDefinition.translations.find(translation => translation.language === "en");
24
+ if (!foundEn) {
25
+ (0, consoleUtils_1.logError)(` ✨ Translation not found for language "en" you must supply the english translation for custom field: ${customFieldDefinition.key}`);
26
+ (0, process_1.exit)(1);
27
+ }
28
+ }
29
+ else {
30
+ const titles = (0, irisAppTranslationUtils_1.convertTranslationKeyIfNeeded)(customFieldDefinition.translations.title, appSrc);
31
+ const descriptions = (0, irisAppTranslationUtils_1.convertTranslationKeyIfNeeded)(customFieldDefinition.translations.description, appSrc);
32
+ if (!titles || !descriptions) {
33
+ (0, consoleUtils_1.logError)(` ✨ Translation not found for language "en" you must supply the english translation for custom field: ${customFieldDefinition.key}`);
34
+ (0, process_1.exit)(1);
35
+ }
36
+ const titleKeys = (0, irisAppTranslationUtils_1.isTranslationsObject)(titles)
37
+ ? // eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys
38
+ Object.keys(titles).filter((key) => key in titles)
39
+ : null;
40
+ if (titleKeys !== null && titleKeys.indexOf("en") === -1) {
41
+ (0, consoleUtils_1.logError)(` ✨ Translation not found 'title' for language "en" you must supply the english translation for custom field: ${customFieldDefinition.key}`);
42
+ (0, process_1.exit)(1);
43
+ }
44
+ const descriptionKeys = (0, irisAppTranslationUtils_1.isTranslationsObject)(descriptions)
45
+ ? // eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys
46
+ Object.keys(descriptions).filter((key) => key in descriptions)
47
+ : null;
48
+ if (descriptionKeys !== null && descriptionKeys.indexOf("en") === -1) {
49
+ (0, consoleUtils_1.logError)(` ✨ Translation not found 'description' for language "en" you must supply the english translation for custom field: ${customFieldDefinition.key}`);
50
+ (0, process_1.exit)(1);
51
+ }
52
+ const keys = new Set([...(titleKeys || []), ...(descriptionKeys || [])]);
53
+ const translations = [
54
+ {
55
+ language: "en",
56
+ title: (0, irisAppTranslationUtils_1.isTranslationsObject)(titles) ? titles.en : titles,
57
+ description: (0, irisAppTranslationUtils_1.isTranslationsObject)(descriptions) ? descriptions.en : descriptions,
58
+ },
59
+ ];
60
+ keys.forEach(language => {
61
+ if (language !== "en") {
62
+ translations.push({
63
+ language,
64
+ // eslint-disable-next-line local-rules/no-typescript-assertion
65
+ title: (0, irisAppTranslationUtils_1.isTranslationsObject)(titles) ? titles[language] : titles,
66
+ description: (0, irisAppTranslationUtils_1.isTranslationsObject)(descriptions) ? descriptions[language] : descriptions,
67
+ });
68
+ }
69
+ });
70
+ customFieldDefinition.translations = translations;
71
+ }
72
+ });
73
+ return customFieldDefinitions;
74
+ };
75
+ exports.updateCustomFields = updateCustomFields;
76
+ //# sourceMappingURL=customFieldUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customFieldUtil.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/customFieldUtil.ts"],"names":[],"mappings":";;;AAAA,0DAKiC;AACjC,qCAA+B;AAC/B,iDAA0C;AAC1C,uEAAgG;AAEhG;;;;;;GAMG;AACI,MAAM,kBAAkB,GAAG,CAChC,sBAAgD,EAChD,MAAe;AACf,wDAAwD;EAC/B,EAAE;IAC3B,IAAI,CAAC,sBAAsB,IAAI,CAAC,MAAM,EAAE,CAAC;QACvC,OAAO,EAAE,CAA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AAC,MAAM;wBAChE,WAAW,EAAE,IAAA,8CAAoB,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY;qBACxF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;YACH,qBAAqB,CAAC,YAAY,GAAG,YAAY,CAAC;QACpD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,sBAAsB,CAAC;AAChC,CAAC,CAAC;AA1EW,QAAA,kBAAkB,sBA0E7B","sourcesContent":["import {\n CustomFieldDefinition,\n CustomFieldTranslationArray,\n isCustomFieldTranslationArray,\n TranslationLanguageKeys,\n} from \"@trackunit/iris-app-api\";\nimport { exit } from \"process\";\nimport { logError } from \"./consoleUtils\";\nimport { convertTranslationKeyIfNeeded, isTranslationsObject } from \"./irisAppTranslationUtils\";\n\n/**\n * Updates the custom field definitions with the given app source directory.\n * If the custom field definitions are not provided, it returns an empty array.\n * If the app source directory is not provided, it returns the custom field definitions.\n *\n * @returns {CustomFieldDefinition[]} the updated custom field definitions array\n */\nexport const updateCustomFields = (\n customFieldDefinitions?: CustomFieldDefinition[],\n appSrc?: string\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): CustomFieldDefinition[] => {\n if (!customFieldDefinitions || !appSrc) {\n return [];\n }\n customFieldDefinitions.forEach(customFieldDefinition => {\n if (isCustomFieldTranslationArray(customFieldDefinition.translations)) {\n const foundEn = customFieldDefinition.translations.find(translation => translation.language === \"en\");\n if (!foundEn) {\n logError(\n ` ✨ Translation not found for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`\n );\n exit(1);\n }\n } else {\n const titles = convertTranslationKeyIfNeeded(customFieldDefinition.translations.title, appSrc);\n const descriptions = convertTranslationKeyIfNeeded(customFieldDefinition.translations.description, appSrc);\n\n if (!titles || !descriptions) {\n logError(\n ` ✨ Translation not found for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`\n );\n exit(1);\n }\n const titleKeys = isTranslationsObject(titles)\n ? // eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys\n Object.keys(titles).filter((key): key is TranslationLanguageKeys => key in titles)\n : null;\n\n if (titleKeys !== null && titleKeys.indexOf(\"en\") === -1) {\n logError(\n ` ✨ Translation not found 'title' for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`\n );\n exit(1);\n }\n\n const descriptionKeys = isTranslationsObject(descriptions)\n ? // eslint-disable-next-line no-autofix/local-rules/prefer-custom-object-keys\n Object.keys(descriptions).filter((key): key is TranslationLanguageKeys => key in descriptions)\n : null;\n\n if (descriptionKeys !== null && descriptionKeys.indexOf(\"en\") === -1) {\n logError(\n ` ✨ Translation not found 'description' for language \"en\" you must supply the english translation for custom field: ${customFieldDefinition.key}`\n );\n exit(1);\n }\n\n const keys = new Set([...(titleKeys || []), ...(descriptionKeys || [])]);\n const translations: CustomFieldTranslationArray = [\n {\n language: \"en\",\n title: isTranslationsObject(titles) ? titles.en : titles,\n description: isTranslationsObject(descriptions) ? descriptions.en : descriptions,\n },\n ];\n\n keys.forEach(language => {\n if (language !== \"en\") {\n translations.push({\n language,\n // eslint-disable-next-line local-rules/no-typescript-assertion\n title: isTranslationsObject(titles) ? titles[language]! : titles,\n description: isTranslationsObject(descriptions) ? descriptions[language] : descriptions,\n });\n }\n });\n customFieldDefinition.translations = translations;\n }\n });\n return customFieldDefinitions;\n};\n"]}
@@ -0,0 +1,14 @@
1
+ import { AssetHomeExtensionManifest, FleetExtensionManifest, IrisAppExtension } from "@trackunit/iris-app-api";
2
+ /**
3
+ * Updates the extensions with the correct translation keys and paths
4
+ *
5
+ * @param extensions - The extensions to update
6
+ * @returns { IrisAppExtension[]} The updated extensions
7
+ */
8
+ export declare const updateExtensions: (extensions: IrisAppExtension[]) => IrisAppExtension[];
9
+ /**
10
+ * Updates the conditions of the extension
11
+ *
12
+ * @param extension - The extension to update
13
+ */
14
+ export declare const updateConditions: (extension: AssetHomeExtensionManifest | FleetExtensionManifest) => void;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateConditions = exports.updateExtensions = void 0;
4
+ const iris_app_api_1 = require("@trackunit/iris-app-api");
5
+ const irisAppTranslationUtils_1 = require("./irisAppTranslationUtils");
6
+ /**
7
+ * Updates the extensions with the correct translation keys and paths
8
+ *
9
+ * @param extensions - The extensions to update
10
+ * @returns { IrisAppExtension[]} The updated extensions
11
+ */
12
+ const updateExtensions = (extensions) => {
13
+ extensions.forEach(extension => {
14
+ if (extension.type !== "IRIS_APP_SETTINGS_EXTENSION" &&
15
+ extension.type !== "WIDGET_EXTENSION" &&
16
+ extension.type !== "LIFECYCLE_EXTENSION" &&
17
+ extension.menuItem.name) {
18
+ extension.menuItem.name =
19
+ (0, irisAppTranslationUtils_1.convertTranslationKeyIfNeeded)(extension.menuItem.name, extension.sourceRoot) || "Unknown";
20
+ }
21
+ if (extension.type === "WIDGET_EXTENSION" && extension.header.name) {
22
+ extension.header.name = (0, irisAppTranslationUtils_1.convertTranslationKeyIfNeeded)(extension.header.name, extension.sourceRoot) || "Unknown";
23
+ }
24
+ if (extension.type === "REPORT_EXTENSION" && (0, irisAppTranslationUtils_1.isTranslationKey)(extension.menuItem.description)) {
25
+ extension.menuItem.description =
26
+ (0, irisAppTranslationUtils_1.convertTranslationKeyIfNeeded)(extension.menuItem.description, extension.sourceRoot) || "Unknown";
27
+ }
28
+ if (extension.type === "ASSET_HOME_EXTENSION" || extension.type === "FLEET_EXTENSION") {
29
+ (0, exports.updateConditions)(extension);
30
+ }
31
+ if (extension.type === "FLEET_EXTENSION") {
32
+ if ((0, iris_app_api_1.isIconByPath)(extension.menuItem.image) && !extension.menuItem.image.path.startsWith(extension.id)) {
33
+ // eslint-disable-next-line local-rules/no-typescript-assertion
34
+ extension.menuItem.image.path = (extension.id + "/" + extension.menuItem.image.path.toString());
35
+ }
36
+ if (extension.menuItem.description) {
37
+ extension.menuItem.description = (0, irisAppTranslationUtils_1.convertTranslationKeyIfNeeded)(extension.menuItem.description, extension.sourceRoot);
38
+ }
39
+ }
40
+ });
41
+ return extensions;
42
+ };
43
+ exports.updateExtensions = updateExtensions;
44
+ /**
45
+ * Updates the conditions of the extension
46
+ *
47
+ * @param extension - The extension to update
48
+ */
49
+ const updateConditions = (extension) => {
50
+ var _a, _b;
51
+ if ((_a = extension.conditions) === null || _a === void 0 ? void 0 : _a.brand) {
52
+ if (Array.isArray(extension.conditions.brand)) {
53
+ extension.conditions.brand.forEach(brand => {
54
+ if (typeof brand !== "string") {
55
+ brand.pattern = brand.pattern.toString();
56
+ }
57
+ });
58
+ }
59
+ else if (typeof extension.conditions.brand !== "string") {
60
+ extension.conditions.brand.pattern = extension.conditions.brand.pattern.toString();
61
+ }
62
+ }
63
+ if ((_b = extension.conditions) === null || _b === void 0 ? void 0 : _b.model) {
64
+ if (Array.isArray(extension.conditions.model)) {
65
+ extension.conditions.model.forEach(model => {
66
+ if (typeof model !== "string") {
67
+ model.pattern = model.pattern.toString();
68
+ }
69
+ });
70
+ }
71
+ else if (typeof extension.conditions.model !== "string") {
72
+ extension.conditions.model.pattern = extension.conditions.model.pattern.toString();
73
+ }
74
+ }
75
+ };
76
+ exports.updateConditions = updateConditions;
77
+ //# sourceMappingURL=extensionUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensionUtil.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/extensionUtil.ts"],"names":[],"mappings":";;;AAAA,0DAMiC;AACjC,uEAA4F;AAC5F;;;;;GAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,UAA8B,EAAsB,EAAE;IACrF,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC7B,IACE,SAAS,CAAC,IAAI,KAAK,6BAA6B;YAChD,SAAS,CAAC,IAAI,KAAK,kBAAkB;YACrC,SAAS,CAAC,IAAI,KAAK,qBAAqB;YACxC,SAAS,CAAC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K,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC9B,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;gBAC3C,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,IAAI,OAAO,SAAS,CAAC,UAAU,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC1D,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrF,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAvBW,QAAA,gBAAgB,oBAuB3B","sourcesContent":["import {\n AssetHomeExtensionManifest,\n FleetExtensionManifest,\n IrisAppExtension,\n isIconByPath,\n SvgImagePath,\n} from \"@trackunit/iris-app-api\";\nimport { convertTranslationKeyIfNeeded, isTranslationKey } from \"./irisAppTranslationUtils\";\n/**\n * Updates the extensions with the correct translation keys and paths\n *\n * @param extensions - The extensions to update\n * @returns { IrisAppExtension[]} The updated extensions\n */\nexport const updateExtensions = (extensions: IrisAppExtension[]): IrisAppExtension[] => {\n extensions.forEach(extension => {\n if (\n extension.type !== \"IRIS_APP_SETTINGS_EXTENSION\" &&\n extension.type !== \"WIDGET_EXTENSION\" &&\n extension.type !== \"LIFECYCLE_EXTENSION\" &&\n extension.menuItem.name\n ) {\n extension.menuItem.name =\n convertTranslationKeyIfNeeded(extension.menuItem.name, extension.sourceRoot) || \"Unknown\";\n }\n\n if (extension.type === \"WIDGET_EXTENSION\" && extension.header.name) {\n extension.header.name = convertTranslationKeyIfNeeded(extension.header.name, extension.sourceRoot) || \"Unknown\";\n }\n\n if (extension.type === \"REPORT_EXTENSION\" && isTranslationKey(extension.menuItem.description)) {\n extension.menuItem.description =\n convertTranslationKeyIfNeeded(extension.menuItem.description, extension.sourceRoot) || \"Unknown\";\n }\n if (extension.type === \"ASSET_HOME_EXTENSION\" || extension.type === \"FLEET_EXTENSION\") {\n updateConditions(extension);\n }\n if (extension.type === \"FLEET_EXTENSION\") {\n if (isIconByPath(extension.menuItem.image) && !extension.menuItem.image.path.startsWith(extension.id)) {\n // eslint-disable-next-line local-rules/no-typescript-assertion\n extension.menuItem.image.path = (extension.id + \"/\" + extension.menuItem.image.path.toString()) as SvgImagePath;\n }\n if (extension.menuItem.description) {\n extension.menuItem.description = convertTranslationKeyIfNeeded(\n extension.menuItem.description,\n extension.sourceRoot\n );\n }\n }\n });\n return extensions;\n};\n\n/**\n * Updates the conditions of the extension\n *\n * @param extension - The extension to update\n */\nexport const updateConditions = (extension: AssetHomeExtensionManifest | FleetExtensionManifest) => {\n if (extension.conditions?.brand) {\n if (Array.isArray(extension.conditions.brand)) {\n extension.conditions.brand.forEach(brand => {\n if (typeof brand !== \"string\") {\n brand.pattern = brand.pattern.toString();\n }\n });\n } else if (typeof extension.conditions.brand !== \"string\") {\n extension.conditions.brand.pattern = extension.conditions.brand.pattern.toString();\n }\n }\n if (extension.conditions?.model) {\n if (Array.isArray(extension.conditions.model)) {\n extension.conditions.model.forEach(model => {\n if (typeof model !== \"string\") {\n model.pattern = model.pattern.toString();\n }\n });\n } else if (typeof extension.conditions.model !== \"string\") {\n extension.conditions.model.pattern = extension.conditions.model.pattern.toString();\n }\n }\n};\n"]}
@@ -0,0 +1,5 @@
1
+ import { IrisAppManifest } from "@trackunit/iris-app-api";
2
+ /**
3
+ * Updates the index.html file with the given manifest and package.json file.
4
+ */
5
+ export declare const updateIndexHtml: (indexContents: string, manifest: IrisAppManifest, packageJson: string) => string;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateIndexHtml = void 0;
4
+ const iris_app_api_1 = require("@trackunit/iris-app-api");
5
+ const crypto_1 = require("crypto");
6
+ const csp_header_1 = require("csp-header");
7
+ /**
8
+ * Updates the index.html file with the given manifest and package.json file.
9
+ */
10
+ const updateIndexHtml = (indexContents, manifest, packageJson) => {
11
+ const scopeAndModuleNonce = (0, crypto_1.randomBytes)(16).toString("base64");
12
+ const csp = (0, csp_header_1.getCSP)({
13
+ directives: (0, iris_app_api_1.irisAppCspInput)(manifest.validDomains, manifest.cspHeader),
14
+ presets: {
15
+ irisAppDefaultCsp: iris_app_api_1.irisAppDefaultCsp,
16
+ localDev: { "connect-src": ["ws://localhost:8097/"], "script-src": [`'nonce-${scopeAndModuleNonce}'`] },
17
+ },
18
+ });
19
+ let html = indexContents.replace("{{cspContent}}", csp);
20
+ html = html.replace("{{nonce}}", scopeAndModuleNonce);
21
+ html = html.replace("{{scope}}", JSON.parse(packageJson).name);
22
+ if (manifest.scopes) {
23
+ html = html.replace("{{manifestScopes}}", JSON.stringify(manifest.scopes));
24
+ }
25
+ else {
26
+ html = html.replace("{{manifestScopes}}", "[]");
27
+ }
28
+ return html;
29
+ };
30
+ exports.updateIndexHtml = updateIndexHtml;
31
+ //# sourceMappingURL=indexHtmlUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexHtmlUtil.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/indexHtmlUtil.ts"],"names":[],"mappings":";;;AAAA,0DAA8F;AAC9F,mCAAqC;AACrC,2CAAoC;AAEpC;;GAEG;AACI,MAAM,eAAe,GAAG,CAAC,aAAqB,EAAE,QAAyB,EAAE,WAAmB,EAAE,EAAE;IACvG,MAAM,mBAAmB,GAAG,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE/D,MAAM,GAAG,GAAG,IAAA,mBAAM,EAAC;QACjB,UAAU,EAAE,IAAA,8BAAe,EAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,SAAS,CAAC;QACtE,OAAO,EAAE;YACP,iBAAiB,EAAjB,gCAAiB;YACjB,QAAQ,EAAE,EAAE,aAAa,EAAE,CAAC,sBAAsB,CAAC,EAAE,YAAY,EAAE,CAAC,UAAU,mBAAmB,GAAG,CAAC,EAAE;SACxG;KACF,CAAC,CAAC;IACH,IAAI,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;IAExD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;IAEtD,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;IAC/D,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7E,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AArBW,QAAA,eAAe,mBAqB1B","sourcesContent":["import { irisAppCspInput, irisAppDefaultCsp, IrisAppManifest } from \"@trackunit/iris-app-api\";\nimport { randomBytes } from \"crypto\";\nimport { getCSP } from \"csp-header\";\n\n/**\n * Updates the index.html file with the given manifest and package.json file.\n */\nexport const updateIndexHtml = (indexContents: string, manifest: IrisAppManifest, packageJson: string) => {\n const scopeAndModuleNonce = randomBytes(16).toString(\"base64\");\n\n const csp = getCSP({\n directives: irisAppCspInput(manifest.validDomains, manifest.cspHeader),\n presets: {\n irisAppDefaultCsp,\n localDev: { \"connect-src\": [\"ws://localhost:8097/\"], \"script-src\": [`'nonce-${scopeAndModuleNonce}'`] },\n },\n });\n let html = indexContents.replace(\"{{cspContent}}\", csp);\n\n html = html.replace(\"{{nonce}}\", scopeAndModuleNonce);\n\n html = html.replace(\"{{scope}}\", JSON.parse(packageJson).name);\n if (manifest.scopes) {\n html = html.replace(\"{{manifestScopes}}\", JSON.stringify(manifest.scopes));\n } else {\n html = html.replace(\"{{manifestScopes}}\", \"[]\");\n }\n return html;\n};\n"]}
@@ -0,0 +1,34 @@
1
+ import { TranslationKey, Translations } from "@trackunit/iris-app-api";
2
+ /**
3
+ * Convert translation key if needed
4
+ *
5
+ * @param translationObj - The translation object to convert
6
+ * @param srcDir - The source directory
7
+ */
8
+ export declare const convertTranslationKeyIfNeeded: (translationObj: string | Translations | TranslationKey | null | undefined, srcDir: string) => Translations | string | undefined;
9
+ /**
10
+ * Check if the object is a translation key
11
+ *
12
+ * @param object - The object to check
13
+ * @returns {boolean} if the object is a translation key, false otherwise
14
+ * @example
15
+ * const translationKey: TranslationKey = {
16
+ * key: "hello",
17
+ * };
18
+ * console.log(isTranslationKey(translationKey)); // true
19
+ */
20
+ export declare const isTranslationKey: (object: string | Translations | TranslationKey | undefined | null) => object is TranslationKey;
21
+ /**
22
+ * Check if the object is a translations object
23
+ *
24
+ * @param object - The object to check
25
+ * @returns {boolean} if the object is a translations object, false otherwise
26
+ * @example
27
+ * const translations: Translations = {
28
+ * en: "Hello",
29
+ * da: "Hej",
30
+ * };
31
+ * console.log(isTranslationsObject(translations)); // true
32
+ * console.log(isTranslationsObject({ edn: "Hello" })); // false
33
+ */
34
+ export declare const isTranslationsObject: (object: string | Translations | TranslationKey | undefined | null) => object is Translations;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTranslationsObject = exports.isTranslationKey = exports.convertTranslationKeyIfNeeded = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const iris_app_api_1 = require("@trackunit/iris-app-api");
6
+ const fs = tslib_1.__importStar(require("fs"));
7
+ const path = tslib_1.__importStar(require("path"));
8
+ const process_1 = require("process");
9
+ const consoleUtils_1 = require("./consoleUtils");
10
+ /**
11
+ * Convert translation key if needed
12
+ *
13
+ * @param translationObj - The translation object to convert
14
+ * @param srcDir - The source directory
15
+ */
16
+ const convertTranslationKeyIfNeeded = (translationObj, srcDir) => {
17
+ const result = translationObj;
18
+ if ((0, exports.isTranslationKey)(result)) {
19
+ const translationKey = result.key;
20
+ const enTranslationFilePath = path.join(srcDir, "locales", "en", "translation.json");
21
+ if (!fs.existsSync(enTranslationFilePath)) {
22
+ (0, consoleUtils_1.logError)(` ✨ Translation file not found for: "${result.key}" looked here: ${enTranslationFilePath}`);
23
+ (0, process_1.exit)(1);
24
+ }
25
+ const enTranslations = JSON.parse(fs.readFileSync(enTranslationFilePath, "utf8"));
26
+ if (!enTranslations[translationKey]) {
27
+ (0, consoleUtils_1.logError)(` ✨ Translation not found for: "${result.key}" looked here: ${enTranslationFilePath}`);
28
+ (0, process_1.exit)(1);
29
+ }
30
+ const translations = {
31
+ en: enTranslations[translationKey],
32
+ };
33
+ iris_app_api_1.languageKeys.forEach(languageCode => {
34
+ const translationFilePath = path.join(srcDir, "locales", languageCode, "translation.json");
35
+ if (fs.existsSync(translationFilePath)) {
36
+ const lngTranslations = JSON.parse(fs.readFileSync(translationFilePath, "utf8"));
37
+ translations[languageCode] = lngTranslations[translationKey];
38
+ }
39
+ else {
40
+ (0, consoleUtils_1.logWarning)(` ✨ Warning translation file not found for: "${result.key}" looked here: ${translationFilePath}`);
41
+ }
42
+ });
43
+ return translations;
44
+ }
45
+ return result || undefined;
46
+ };
47
+ exports.convertTranslationKeyIfNeeded = convertTranslationKeyIfNeeded;
48
+ /**
49
+ * Check if the object is a translation key
50
+ *
51
+ * @param object - The object to check
52
+ * @returns {boolean} if the object is a translation key, false otherwise
53
+ * @example
54
+ * const translationKey: TranslationKey = {
55
+ * key: "hello",
56
+ * };
57
+ * console.log(isTranslationKey(translationKey)); // true
58
+ */
59
+ const isTranslationKey = (object) => {
60
+ return typeof object === "object" && object !== null && "key" in object;
61
+ };
62
+ exports.isTranslationKey = isTranslationKey;
63
+ /**
64
+ * Check if the object is a translations object
65
+ *
66
+ * @param object - The object to check
67
+ * @returns {boolean} if the object is a translations object, false otherwise
68
+ * @example
69
+ * const translations: Translations = {
70
+ * en: "Hello",
71
+ * da: "Hej",
72
+ * };
73
+ * console.log(isTranslationsObject(translations)); // true
74
+ * console.log(isTranslationsObject({ edn: "Hello" })); // false
75
+ */
76
+ const isTranslationsObject = (object) => {
77
+ return typeof object === "object" && object !== null && "en" in object;
78
+ };
79
+ exports.isTranslationsObject = isTranslationsObject;
80
+ //# sourceMappingURL=irisAppTranslationUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"irisAppTranslationUtils.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/irisAppTranslationUtils.ts"],"names":[],"mappings":";;;;AAAA,0DAAqF;AACrF,+CAAyB;AACzB,mDAA6B;AAC7B,qCAA+B;AAC/B,iDAAsD;AAEtD;;;;;GAKG;AACI,MAAM,6BAA6B,GAAG,CAC3C,cAAyE,EACzE,MAAc,EACqB,EAAE;IACrC,MAAM,MAAM,GAAG,cAAc,CAAC;IAE9B,IAAI,IAAA,wBAAgB,EAAC,MAAM,CAAC,EAAE,CAAC;QAC7B,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC;QAElC,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC;QACrF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,qBAAqB,CAAC,EAAE,CAAC;YAC1C,IAAA,uBAAQ,EAAC,uCAAuC,MAAM,CAAC,GAAG,kBAAkB,qBAAqB,EAAE,CAAC,CAAC;YACrG,IAAA,cAAI,EAAC,CAAC,CAAC,CAAC;QACV,CAAC;QACD,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,CAAC;QAClF,IAAI,CAAC,cAAc,CAAC,cAAc,CAA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AAI,MAAM,KAAK,IAAI,IAAI,IAAI,IAAI,MAAM,CAAC;AACzE,CAAC,CAAC;AAJW,QAAA,oBAAoB,wBAI/B","sourcesContent":["import { languageKeys, TranslationKey, Translations } from \"@trackunit/iris-app-api\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport { exit } from \"process\";\nimport { logError, logWarning } from \"./consoleUtils\";\n\n/**\n * Convert translation key if needed\n *\n * @param translationObj - The translation object to convert\n * @param srcDir - The source directory\n */\nexport const convertTranslationKeyIfNeeded = (\n translationObj: string | Translations | TranslationKey | null | undefined,\n srcDir: string\n): Translations | string | undefined => {\n const result = translationObj;\n\n if (isTranslationKey(result)) {\n const translationKey = result.key;\n\n const enTranslationFilePath = path.join(srcDir, \"locales\", \"en\", \"translation.json\");\n if (!fs.existsSync(enTranslationFilePath)) {\n logError(` ✨ Translation file not found for: \"${result.key}\" looked here: ${enTranslationFilePath}`);\n exit(1);\n }\n const enTranslations = JSON.parse(fs.readFileSync(enTranslationFilePath, \"utf8\"));\n if (!enTranslations[translationKey]) {\n logError(` ✨ Translation not found for: \"${result.key}\" looked here: ${enTranslationFilePath}`);\n exit(1);\n }\n\n const translations: Translations = {\n en: enTranslations[translationKey],\n };\n\n languageKeys.forEach(languageCode => {\n const translationFilePath = path.join(srcDir, \"locales\", languageCode, \"translation.json\");\n if (fs.existsSync(translationFilePath)) {\n const lngTranslations = JSON.parse(fs.readFileSync(translationFilePath, \"utf8\"));\n translations[languageCode] = lngTranslations[translationKey];\n } else {\n logWarning(` ✨ Warning translation file not found for: \"${result.key}\" looked here: ${translationFilePath}`);\n }\n });\n return translations;\n }\n return result || undefined;\n};\n\n/**\n * Check if the object is a translation key\n *\n * @param object - The object to check\n * @returns {boolean} if the object is a translation key, false otherwise\n * @example\n * const translationKey: TranslationKey = {\n * key: \"hello\",\n * };\n * console.log(isTranslationKey(translationKey)); // true\n */\nexport const isTranslationKey = (\n object: string | Translations | TranslationKey | undefined | null\n): object is TranslationKey => {\n return typeof object === \"object\" && object !== null && \"key\" in object;\n};\n\n/**\n * Check if the object is a translations object\n *\n * @param object - The object to check\n * @returns {boolean} if the object is a translations object, false otherwise\n * @example\n * const translations: Translations = {\n * en: \"Hello\",\n * da: \"Hej\",\n * };\n * console.log(isTranslationsObject(translations)); // true\n * console.log(isTranslationsObject({ edn: \"Hello\" })); // false\n */\nexport const isTranslationsObject = (\n object: string | Translations | TranslationKey | undefined | null\n): object is Translations => {\n return typeof object === \"object\" && object !== null && \"en\" in object;\n};\n"]}