@trackunit/iris-app-webpack-plugin 0.0.198 → 0.0.200

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,13 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.0.200](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.199...iris-app-webpack-plugin/0.0.200) (2024-06-11)
6
+
7
+ ### Dependency Updates
8
+
9
+ * `iris-app-api` updated to version `0.0.199`
10
+ ## [0.0.199](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.198...iris-app-webpack-plugin/0.0.199) (2024-06-11)
11
+
5
12
  ## [0.0.198](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.197...iris-app-webpack-plugin/0.0.198) (2024-06-10)
6
13
 
7
14
  ## [0.0.197](https://github.com/Trackunit/manager/compare/iris-app-webpack-plugin/0.0.196...iris-app-webpack-plugin/0.0.197) (2024-05-21)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/iris-app-webpack-plugin",
3
- "version": "0.0.198",
3
+ "version": "0.0.200",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "repository": "https://github.com/Trackunit/manager",
6
6
  "engines": {
@@ -3,7 +3,7 @@ import * as wp from "webpack";
3
3
  interface TrackunitIrisAppWebpackPluginOptions {
4
4
  nxRootDir: string;
5
5
  appDir: string;
6
- manifest: IrisAppManifest;
6
+ manifest?: IrisAppManifest;
7
7
  }
8
8
  /**
9
9
  * Webpack plugin that generates a manifest.json file
@@ -93,17 +93,17 @@ class TrackunitIrisAppWebpackPlugin {
93
93
  // "assets" is an object that contains all assets
94
94
  // in the compilation, the keys of the object are pathnames of the assets
95
95
  // and the values are file sources.
96
- var _a, _b, _c;
96
+ var _a;
97
97
  // Iterating over all the assets and
98
98
  // generating content for our Markdown file.
99
- if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.manifest)) {
99
+ if (!this.options.manifest) {
100
100
  throw Error("you must provide a app manifest");
101
101
  }
102
102
  const manifest = this.options.manifest;
103
103
  const indexContents = fs.readFileSync(path.join(__dirname, "index.html"), "utf8");
104
104
  const manifestJson = this.options.manifest;
105
105
  const appSrc = path.join(this.options.appDir, "src");
106
- (_b = this.options.manifest.customFieldDefinitions) === null || _b === void 0 ? void 0 : _b.forEach(customFieldDefinition => {
106
+ (_a = this.options.manifest.customFieldDefinitions) === null || _a === void 0 ? void 0 : _a.forEach(customFieldDefinition => {
107
107
  if ((0, iris_app_api_1.isCustomFieldTranslationArray)(customFieldDefinition.translations)) {
108
108
  const foundEn = customFieldDefinition.translations.find(translation => translation.language === "en");
109
109
  if (!foundEn) {
@@ -146,21 +146,21 @@ class TrackunitIrisAppWebpackPlugin {
146
146
  }
147
147
  });
148
148
  manifestJson.extensions = this.options.manifest.extensions;
149
- (_c = this.options.manifest.extensions) === null || _c === void 0 ? void 0 : _c.forEach(extension => {
150
- var _a, _b, _c, _d;
149
+ this.options.manifest.extensions.forEach(extension => {
150
+ var _a, _b;
151
151
  const translationKey = (extension.type !== "IRIS_APP_SETTINGS_EXTENSION" &&
152
152
  extension.type !== "WIDGET_EXTENSION" &&
153
- ((_a = extension.menuItem) === null || _a === void 0 ? void 0 : _a.name)) ||
153
+ extension.menuItem.name) ||
154
154
  null;
155
155
  convertTranslationKeyIfNeeded(translationKey, extension.sourceRoot);
156
- const headerTranslationKey = (extension.type === "WIDGET_EXTENSION" && extension.header && extension.header.name) || null;
156
+ const headerTranslationKey = (extension.type === "WIDGET_EXTENSION" && extension.header.name) || null;
157
157
  convertTranslationKeyIfNeeded(headerTranslationKey, extension.sourceRoot);
158
- if (extension.type === "REPORT_EXTENSION" && isTranslationKey((_b = extension.menuItem) === null || _b === void 0 ? void 0 : _b.description)) {
158
+ if (extension.type === "REPORT_EXTENSION" && isTranslationKey(extension.menuItem.description)) {
159
159
  const description = extension.menuItem.description;
160
160
  convertTranslationKeyIfNeeded(description, extension.sourceRoot);
161
161
  }
162
162
  if (extension.type === "ASSET_HOME_EXTENSION" || extension.type === "FLEET_EXTENSION") {
163
- if ((_c = extension.conditions) === null || _c === void 0 ? void 0 : _c.brand) {
163
+ if ((_a = extension.conditions) === null || _a === void 0 ? void 0 : _a.brand) {
164
164
  if (Array.isArray(extension.conditions.brand)) {
165
165
  extension.conditions.brand.forEach(brand => {
166
166
  if (typeof brand !== "string") {
@@ -172,7 +172,7 @@ class TrackunitIrisAppWebpackPlugin {
172
172
  extension.conditions.brand.pattern = extension.conditions.brand.pattern.toString();
173
173
  }
174
174
  }
175
- if ((_d = extension.conditions) === null || _d === void 0 ? void 0 : _d.model) {
175
+ if ((_b = extension.conditions) === null || _b === void 0 ? void 0 : _b.model) {
176
176
  if (Array.isArray(extension.conditions.model)) {
177
177
  extension.conditions.model.forEach(model => {
178
178
  if (typeof model !== "string") {
@@ -1 +1 @@
1
- {"version":3,"file":"TrackunitIrisAppWebpackPlugin.js","sourceRoot":"","sources":["../../../../../../libs/iris-app-sdk/iris-app-webpack-plugin/src/lib/TrackunitIrisAppWebpackPlugin.ts"],"names":[],"mappings":";;;;AAAA,0DAUiC;AACjC,mCAAqC;AACrC,2CAAoC;AACpC,+CAAyB;AACzB,mDAA6B;AAC7B,qCAA+B;AAS/B,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,KAAK,GAAG,UAAU,CAAC;AACzB,MAAM,GAAG,GAAG,UAAU,CAAC;AACvB,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,MAAM,6BAA6B,GAAG,CACpC,cAAyE,EACzE,MAAc,EACd,EAAE;IACF,IAAI,gBAAgB,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC;QAE1C,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,E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AC;gBACD,oEAAoE;gBACpE,oDAAoD;gBACpD,WAAW,CAAC,SAAS,CAAC,YAAY,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;YAC3D,CAAC,CAAA,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AArMD,sEAqMC","sourcesContent":["import {\n CustomFieldTranslationArray,\n irisAppCspInput,\n irisAppDefaultCsp,\n IrisAppManifest,\n isCustomFieldTranslationArray,\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 })?.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/iris-sdk-portal#runLocal\\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.menuItem?.name) ||\n null;\n convertTranslationKeyIfNeeded(translationKey, extension.sourceRoot);\n\n const headerTranslationKey =\n (extension.type === \"WIDGET_EXTENSION\" && extension.header && 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 });\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":";;;;AAAA,0DAUiC;AACjC,mCAAqC;AACrC,2CAAoC;AACpC,+CAAyB;AACzB,mDAA6B;AAC7B,qCAA+B;AAS/B,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,MAAM,KAAK,GAAG,UAAU,CAAC;AACzB,MAAM,GAAG,GAAG,UAAU,CAAC;AACvB,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,MAAM,6BAA6B,GAAG,CACpC,cAAyE,EACzE,MAAc,EACd,EAAE;IACF,IAAI,gBAAgB,CAAC,cAAc,CAAC,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC;QAE1C,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,sCAAsC;YACtC,OAAO,CAAC,KAAK,CACX,GAAG,EACH,uCAAuC,cAAc,CAAC,GAAG,kBAAkB,qBAAqB,EAAE,EAClG,KAAK,CACN,CAAC;YACF,IAAA,cAAI,EAAC,CAAC,CAAC,CAAC;QACV,CAAC;QACD,MAAM,cAA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M,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,CAAA,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AApMD,sEAoMC","sourcesContent":["import {\n CustomFieldTranslationArray,\n irisAppCspInput,\n irisAppDefaultCsp,\n IrisAppManifest,\n isCustomFieldTranslationArray,\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/iris-sdk-portal#runLocal\\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.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 });\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"]}