@hitachivantara/app-shell-vite-plugin 1.3.3 → 1.4.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.
@@ -1,4 +1,8 @@
1
1
  import type { HvAppShellConfig, HvAppShellViewsConfig } from "@hitachivantara/app-shell-shared";
2
+ interface AutomaticView {
3
+ viewConfig: HvAppShellViewsConfig;
4
+ module: string;
5
+ }
2
6
  /**
3
7
  * Maps, through all the index files under viewsFolderPath, to a set of main views config (@see HvAppShellViewsConfig)
4
8
  * and the respective module (to be transformed to the final bundle)
@@ -6,19 +10,20 @@ import type { HvAppShellConfig, HvAppShellViewsConfig } from "@hitachivantara/ap
6
10
  * @param viewsFolder the relative base folder where the files are included
7
11
  * @return an array of viewConfig and their correspondent module definition
8
12
  */
9
- export declare function mapFolderIndexFilesToRoutes(root: string, viewsFolder: string): {
10
- viewConfig: HvAppShellViewsConfig;
11
- module: string;
12
- }[];
13
+ export declare function mapFolderIndexFilesToRoutes(root: string, viewsFolder: string): AutomaticView[];
13
14
  /**
14
- * Adds the automatically identified view (from the "viewsFolder" folder) to the AppShell configuration and calculate
15
- * the correspondent module to be generated
16
- * It guarantees that any new route will not overlap any manual defined route
15
+ * Adds the automatically identified views (from the "viewsFolder" folder) to the AppShell configuration and calculate
16
+ * the correspondent modules to be generated.
17
+ *
18
+ * It guarantees that an automatic route will not overlap any manual defined route.
19
+ *
17
20
  * @param config The app Shell config file
21
+ * @param selfAppName The package name of this app
18
22
  * @param root Project root folder
19
23
  * @param viewsFolder Views folder
20
24
  * @return the array of modules to be created by the rollup mechanism
21
25
  */
22
- export declare function applyAutomaticViewsAndRoutes(config: HvAppShellConfig, root: string, viewsFolder: string): string[];
26
+ export declare function applyAutomaticViewsAndRoutes(config: HvAppShellConfig, selfAppName: string, root: string, viewsFolder: string): string[];
23
27
  export declare function applyAutomaticMenu(config: HvAppShellConfig): void;
28
+ export {};
24
29
  //# sourceMappingURL=automatic-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"automatic-utils.d.ts","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAEhB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AA+B1C;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB;IACD,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB,EAAE,CAoCF;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,MAAM,EAAE,CAyCV;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,QAoD1D"}
1
+ {"version":3,"file":"automatic-utils.d.ts","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAEhB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AA2C1C,UAAU,aAAa;IACrB,UAAU,EAAE,qBAAqB,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE,CAoCjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,gBAAgB,EACxB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAClB,MAAM,EAAE,CAwDV;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,QAoD1D"}
@@ -24,6 +24,17 @@ function findIndexFiles(dir) {
24
24
  });
25
25
  return files;
26
26
  }
27
+ function flattenViews(views, base = "") {
28
+ return views.reduce((acc, view) => {
29
+ // concatenate base with view route
30
+ const route = `${base}${view.route}`;
31
+ acc.push({ ...view, route });
32
+ if (view.views != null) {
33
+ acc.push(...flattenViews(view.views, route));
34
+ }
35
+ return acc;
36
+ }, []);
37
+ }
27
38
  /**
28
39
  * Maps, through all the index files under viewsFolderPath, to a set of main views config (@see HvAppShellViewsConfig)
29
40
  * and the respective module (to be transformed to the final bundle)
@@ -59,15 +70,18 @@ export function mapFolderIndexFilesToRoutes(root, viewsFolder) {
59
70
  return routes;
60
71
  }
61
72
  /**
62
- * Adds the automatically identified view (from the "viewsFolder" folder) to the AppShell configuration and calculate
63
- * the correspondent module to be generated
64
- * It guarantees that any new route will not overlap any manual defined route
73
+ * Adds the automatically identified views (from the "viewsFolder" folder) to the AppShell configuration and calculate
74
+ * the correspondent modules to be generated.
75
+ *
76
+ * It guarantees that an automatic route will not overlap any manual defined route.
77
+ *
65
78
  * @param config The app Shell config file
79
+ * @param selfAppName The package name of this app
66
80
  * @param root Project root folder
67
81
  * @param viewsFolder Views folder
68
82
  * @return the array of modules to be created by the rollup mechanism
69
83
  */
70
- export function applyAutomaticViewsAndRoutes(config, root, viewsFolder) {
84
+ export function applyAutomaticViewsAndRoutes(config, selfAppName, root, viewsFolder) {
71
85
  const appShellConfiguration = config;
72
86
  const routes = mapFolderIndexFilesToRoutes(root, viewsFolder);
73
87
  if (routes.length === 0) {
@@ -78,23 +92,40 @@ export function applyAutomaticViewsAndRoutes(config, root, viewsFolder) {
78
92
  if (!appShellConfiguration.mainPanel?.views ||
79
93
  appShellConfiguration.mainPanel.views.length === 0) {
80
94
  if (!appShellConfiguration.mainPanel) {
81
- appShellConfiguration.mainPanel = { views: [] };
95
+ appShellConfiguration.mainPanel = { views };
82
96
  }
83
- appShellConfiguration.mainPanel.views = views;
84
- return modules;
85
- }
86
- const nonOverlappingRoutes = routes.filter(route => {
87
- const exists = appShellConfiguration.mainPanel?.views?.some(existingView => existingView.bundle === route.viewConfig.bundle ||
88
- existingView.route === route.viewConfig.route);
89
- if (exists) {
90
- console.info(`SKIPPED: View with bundle:[${route.viewConfig.bundle}] or route:[${route.viewConfig.route}] will not be created as their values are already used by another one.`);
97
+ else {
98
+ appShellConfiguration.mainPanel.views = views;
91
99
  }
92
- return !exists;
93
- });
94
- const nonOverlappingViews = nonOverlappingRoutes.map(r => r.viewConfig);
95
- const nonOverlappingModules = nonOverlappingRoutes.map(r => r.module);
96
- appShellConfiguration.mainPanel.views.push(...nonOverlappingViews);
97
- return nonOverlappingModules;
100
+ }
101
+ else {
102
+ const flattenedViews = flattenViews(appShellConfiguration.mainPanel.views);
103
+ const existingRoutes = flattenedViews.map(view => view.route);
104
+ const existingBundles = flattenedViews.reduce((bundles, view) => {
105
+ if (view.bundle.startsWith("@self/")) {
106
+ bundles.push(view.bundle);
107
+ }
108
+ else if (view.bundle.startsWith(selfAppName)) {
109
+ bundles.push(view.bundle.replace(selfAppName, "@self"));
110
+ }
111
+ return bundles;
112
+ }, []);
113
+ const nonOverlappingRoutes = routes.filter(route => {
114
+ if (existingBundles.includes(route.viewConfig.bundle)) {
115
+ // automatic View is already defined in the config
116
+ return false;
117
+ }
118
+ if (existingRoutes.includes(route.viewConfig.route)) {
119
+ // automatic route is already defined in the config and associated with a different bundle
120
+ console.info(`SKIPPED: Automatic route for bundle ${route.viewConfig.bundle} not created as it conflicts with existing route in the config file (${route.viewConfig.route}).`);
121
+ return false;
122
+ }
123
+ return true;
124
+ });
125
+ const nonOverlappingViews = nonOverlappingRoutes.map(r => r.viewConfig);
126
+ appShellConfiguration.mainPanel.views.push(...nonOverlappingViews);
127
+ }
128
+ return modules;
98
129
  }
99
130
  export function applyAutomaticMenu(config) {
100
131
  const appShellConfiguration = config;
@@ -1 +1 @@
1
- {"version":3,"file":"automatic-utils.js","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB,OAAO,EAAE,kB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AAW,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,IAAI,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;YAC7D,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;gBACpB,OAAO,GAAG;oBACR,KAAK;oBACL,QAAQ,EAAE,EAAE;iBACb,CAAC;gBACF,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC5B,CAAC;YACD,WAAW,GAAG,OAAO,CAAC,QAAS,CAAC;QAClC,CAAC;QAED,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/D,IAAI,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;QAC9D,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACrB,QAAQ,GAAG;gBACT,KAAK;aACN,CAAC;YACF,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC;QACD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,qBAAqB,CAAC,IAAI,GAAG,IAAI,CAAC;AACpC,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellMenuConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport { getFinalModuleName } from \"./config-utils.js\";\n\nfunction createLabel(str: string) {\n const noExtension = str.replace(/\\.[^/.]+$/, \"\");\n const splitByCapital = noExtension.split(/(?=[A-Z])/).join(\" \");\n return splitByCapital.charAt(0).toUpperCase() + splitByCapital.slice(1);\n}\n\n/**\n * Find all the index.tsx or index.jsx files existent at the provided path (including all the subdirectories)\n * @param dir the path to search for the index.tsx or index.jsx files\n */\nfunction findIndexFiles(dir: string): string[] {\n const files: string[] = [];\n\n fs.readdirSync(dir).forEach(file => {\n const filePath = path.join(dir, file);\n const stat = fs.statSync(filePath);\n\n if (stat.isDirectory()) {\n files.push(...findIndexFiles(filePath));\n } else if (/^index\\.[tj]sx?$/.exec(file)) {\n files.push(filePath);\n }\n });\n\n return files;\n}\n\n/**\n * Maps, through all the index files under viewsFolderPath, to a set of main views config (@see HvAppShellViewsConfig)\n * and the respective module (to be transformed to the final bundle)\n * @param root the absolute path to the views folder\n * @param viewsFolder the relative base folder where the files are included\n * @return an array of viewConfig and their correspondent module definition\n */\nexport function mapFolderIndexFilesToRoutes(\n root: string,\n viewsFolder: string\n): {\n viewConfig: HvAppShellViewsConfig;\n module: string;\n}[] {\n // the regex removes any existing '/' either at the start, at the end or in both cases of the viewsFolder parameter.\n const normalizedViewsFolder = viewsFolder.replace(/(^\\/|\\/$|)/g, \"\");\n\n const viewsFolderPath = path.resolve(root, normalizedViewsFolder);\n if (!fs.existsSync(viewsFolderPath)) {\n return [];\n }\n\n const routes: { viewConfig: HvAppShellViewsConfig; module: string }[] = [];\n const indexFiles = findIndexFiles(viewsFolderPath);\n\n indexFiles.forEach(filePath => {\n // required to work on Windows and also on Linux/macOS\n const normalizedFilePath = filePath.replaceAll(path.sep, \"/\");\n\n // fetches what is between the normalizedViewsFolder (inclusive) and the last '/' (exclusive)\n // example: 'dummy/path/src/pages/Page1/index.tsx' and 'src/pages' returns src/pages/Page1\n const bundle = normalizedFilePath.substring(\n normalizedFilePath.lastIndexOf(`/${normalizedViewsFolder}/`) + 1,\n normalizedFilePath.lastIndexOf(\"/\")\n );\n\n const route = bundle\n .replace(new RegExp(`^${normalizedViewsFolder}`), \"\")\n .replaceAll(/\\$/g, \":\")\n .toLowerCase();\n\n const viewConfig = {\n bundle: `@self/${getFinalModuleName(bundle)}.js`,\n route\n };\n routes.push({ viewConfig, module: bundle });\n });\n\n return routes;\n}\n\n/**\n * Adds the automatically identified view (from the \"viewsFolder\" folder) to the AppShell configuration and calculate\n * the correspondent module to be generated\n * It guarantees that any new route will not overlap any manual defined route\n * @param config The app Shell config file\n * @param root Project root folder\n * @param viewsFolder Views folder\n * @return the array of modules to be created by the rollup mechanism\n */\nexport function applyAutomaticViewsAndRoutes(\n config: HvAppShellConfig,\n root: string,\n viewsFolder: string\n): string[] {\n const appShellConfiguration = config;\n\n const routes = mapFolderIndexFilesToRoutes(root, viewsFolder);\n if (routes.length === 0) {\n return [];\n }\n\n const views = routes.map(r => r.viewConfig);\n const modules = routes.map(r => r.module);\n\n if (\n !appShellConfiguration.mainPanel?.views ||\n appShellConfiguration.mainPanel.views.length === 0\n ) {\n if (!appShellConfiguration.mainPanel) {\n appShellConfiguration.mainPanel = { views: [] };\n }\n appShellConfiguration.mainPanel.views = views;\n return modules;\n }\n\n const nonOverlappingRoutes = routes.filter(route => {\n const exists = appShellConfiguration.mainPanel?.views?.some(\n existingView =>\n existingView.bundle === route.viewConfig.bundle ||\n existingView.route === route.viewConfig.route\n );\n if (exists) {\n console.info(\n `SKIPPED: View with bundle:[${route.viewConfig.bundle}] or route:[${route.viewConfig.route}] will not be created as their values are already used by another one.`\n );\n }\n return !exists;\n });\n\n const nonOverlappingViews = nonOverlappingRoutes.map(r => r.viewConfig);\n const nonOverlappingModules = nonOverlappingRoutes.map(r => r.module);\n\n appShellConfiguration.mainPanel.views.push(...nonOverlappingViews);\n return nonOverlappingModules;\n}\n\nexport function applyAutomaticMenu(config: HvAppShellConfig) {\n const appShellConfiguration = config;\n\n if (\n !appShellConfiguration.mainPanel?.views ||\n appShellConfiguration.mainPanel?.views.length === 0\n ) {\n return;\n }\n\n const menu: HvAppShellMenuConfig[] = [];\n\n appShellConfiguration.mainPanel?.views.forEach(view => {\n // skip dynamic routes (e.g. /list/:id))\n if (view.route.indexOf(\":\") !== -1) {\n return;\n }\n\n let currentMenu = menu;\n const bundleParts = view.bundle.split(\"/\");\n const numberOfParts = view.route\n .split(\"/\")\n .filter(part => part !== \"\").length;\n const srcFolderParts = bundleParts.length - numberOfParts;\n if (bundleParts.length <= srcFolderParts) {\n return;\n }\n for (let j = srcFolderParts; j < bundleParts.length - 1; j += 1) {\n const label = createLabel(bundleParts[j]);\n let submenu = currentMenu.find(item => item.label === label);\n if (submenu == null) {\n submenu = {\n label,\n submenus: []\n };\n currentMenu.push(submenu);\n }\n currentMenu = submenu.submenus!;\n }\n\n const label = createLabel(bundleParts[bundleParts.length - 1]);\n let menuitem = currentMenu.find(item => item.label === label);\n if (menuitem == null) {\n menuitem = {\n label\n };\n currentMenu.push(menuitem);\n }\n menuitem.target = view.route;\n });\n\n appShellConfiguration.menu = menu;\n}\n"]}
1
+ {"version":3,"file":"automatic-utils.js","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAQxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACjD,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChE,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,GAAW;IACjC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACtC,MAAM,IAAI,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QACD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,qBAAqB,CAAC,IAAI,GAAG,IAAI,CAAC;AACpC,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellMenuConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport { getFinalModuleName } from \"./config-utils.js\";\n\nfunction createLabel(str: string) {\n const noExtension = str.replace(/\\.[^/.]+$/, \"\");\n const splitByCapital = noExtension.split(/(?=[A-Z])/).join(\" \");\n return splitByCapital.charAt(0).toUpperCase() + splitByCapital.slice(1);\n}\n\n/**\n * Find all the index.tsx or index.jsx files existent at the provided path (including all the subdirectories)\n * @param dir the path to search for the index.tsx or index.jsx files\n */\nfunction findIndexFiles(dir: string): string[] {\n const files: string[] = [];\n\n fs.readdirSync(dir).forEach(file => {\n const filePath = path.join(dir, file);\n const stat = fs.statSync(filePath);\n\n if (stat.isDirectory()) {\n files.push(...findIndexFiles(filePath));\n } else if (/^index\\.[tj]sx?$/.exec(file)) {\n files.push(filePath);\n }\n });\n\n return files;\n}\n\nfunction flattenViews(views: HvAppShellViewsConfig[], base = \"\") {\n return views.reduce<HvAppShellViewsConfig[]>((acc, view) => {\n // concatenate base with view route\n const route = `${base}${view.route}` as HvAppShellViewsConfig[\"route\"];\n acc.push({ ...view, route });\n if (view.views != null) {\n acc.push(...flattenViews(view.views, route));\n }\n return acc;\n }, []);\n}\n\ninterface AutomaticView {\n viewConfig: HvAppShellViewsConfig;\n module: string;\n}\n\n/**\n * Maps, through all the index files under viewsFolderPath, to a set of main views config (@see HvAppShellViewsConfig)\n * and the respective module (to be transformed to the final bundle)\n * @param root the absolute path to the views folder\n * @param viewsFolder the relative base folder where the files are included\n * @return an array of viewConfig and their correspondent module definition\n */\nexport function mapFolderIndexFilesToRoutes(\n root: string,\n viewsFolder: string\n): AutomaticView[] {\n // the regex removes any existing '/' either at the start, at the end or in both cases of the viewsFolder parameter.\n const normalizedViewsFolder = viewsFolder.replace(/(^\\/|\\/$|)/g, \"\");\n\n const viewsFolderPath = path.resolve(root, normalizedViewsFolder);\n if (!fs.existsSync(viewsFolderPath)) {\n return [];\n }\n\n const routes: { viewConfig: HvAppShellViewsConfig; module: string }[] = [];\n const indexFiles = findIndexFiles(viewsFolderPath);\n\n indexFiles.forEach(filePath => {\n // required to work on Windows and also on Linux/macOS\n const normalizedFilePath = filePath.replaceAll(path.sep, \"/\");\n\n // fetches what is between the normalizedViewsFolder (inclusive) and the last '/' (exclusive)\n // example: 'dummy/path/src/pages/Page1/index.tsx' and 'src/pages' returns src/pages/Page1\n const bundle = normalizedFilePath.substring(\n normalizedFilePath.lastIndexOf(`/${normalizedViewsFolder}/`) + 1,\n normalizedFilePath.lastIndexOf(\"/\")\n );\n\n const route = bundle\n .replace(new RegExp(`^${normalizedViewsFolder}`), \"\")\n .replaceAll(/\\$/g, \":\")\n .toLowerCase() as HvAppShellViewsConfig[\"route\"];\n\n const viewConfig = {\n bundle: `@self/${getFinalModuleName(bundle)}.js`,\n route\n };\n routes.push({ viewConfig, module: bundle });\n });\n\n return routes;\n}\n\n/**\n * Adds the automatically identified views (from the \"viewsFolder\" folder) to the AppShell configuration and calculate\n * the correspondent modules to be generated.\n *\n * It guarantees that an automatic route will not overlap any manual defined route.\n *\n * @param config The app Shell config file\n * @param selfAppName The package name of this app\n * @param root Project root folder\n * @param viewsFolder Views folder\n * @return the array of modules to be created by the rollup mechanism\n */\nexport function applyAutomaticViewsAndRoutes(\n config: HvAppShellConfig,\n selfAppName: string,\n root: string,\n viewsFolder: string\n): string[] {\n const appShellConfiguration = config;\n\n const routes = mapFolderIndexFilesToRoutes(root, viewsFolder);\n if (routes.length === 0) {\n return [];\n }\n\n const views = routes.map(r => r.viewConfig);\n const modules = routes.map(r => r.module);\n\n if (\n !appShellConfiguration.mainPanel?.views ||\n appShellConfiguration.mainPanel.views.length === 0\n ) {\n if (!appShellConfiguration.mainPanel) {\n appShellConfiguration.mainPanel = { views };\n } else {\n appShellConfiguration.mainPanel.views = views;\n }\n } else {\n const flattenedViews = flattenViews(appShellConfiguration.mainPanel.views);\n\n const existingRoutes = flattenedViews.map(view => view.route);\n const existingBundles = flattenedViews.reduce((bundles, view) => {\n if (view.bundle.startsWith(\"@self/\")) {\n bundles.push(view.bundle);\n } else if (view.bundle.startsWith(selfAppName)) {\n bundles.push(view.bundle.replace(selfAppName, \"@self\"));\n }\n return bundles;\n }, [] as string[]);\n\n const nonOverlappingRoutes = routes.filter(route => {\n if (existingBundles.includes(route.viewConfig.bundle)) {\n // automatic View is already defined in the config\n return false;\n }\n\n if (existingRoutes.includes(route.viewConfig.route)) {\n // automatic route is already defined in the config and associated with a different bundle\n console.info(\n `SKIPPED: Automatic route for bundle ${route.viewConfig.bundle} not created as it conflicts with existing route in the config file (${route.viewConfig.route}).`\n );\n return false;\n }\n\n return true;\n });\n\n const nonOverlappingViews = nonOverlappingRoutes.map(r => r.viewConfig);\n\n appShellConfiguration.mainPanel.views.push(...nonOverlappingViews);\n }\n\n return modules;\n}\n\nexport function applyAutomaticMenu(config: HvAppShellConfig) {\n const appShellConfiguration = config;\n\n if (\n !appShellConfiguration.mainPanel?.views ||\n appShellConfiguration.mainPanel?.views.length === 0\n ) {\n return;\n }\n\n const menu: HvAppShellMenuConfig[] = [];\n\n appShellConfiguration.mainPanel?.views.forEach(view => {\n // skip dynamic routes (e.g. /list/:id))\n if (view.route.indexOf(\":\") !== -1) {\n return;\n }\n\n let currentMenu = menu;\n const bundleParts = view.bundle.split(\"/\");\n const numberOfParts = view.route\n .split(\"/\")\n .filter(part => part !== \"\").length;\n const srcFolderParts = bundleParts.length - numberOfParts;\n if (bundleParts.length <= srcFolderParts) {\n return;\n }\n for (let j = srcFolderParts; j < bundleParts.length - 1; j += 1) {\n const label = createLabel(bundleParts[j]);\n let submenu = currentMenu.find(item => item.label === label);\n if (submenu == null) {\n submenu = {\n label,\n submenus: []\n };\n currentMenu.push(submenu);\n }\n currentMenu = submenu.submenus!;\n }\n\n const label = createLabel(bundleParts[bundleParts.length - 1]);\n let menuitem = currentMenu.find(item => item.label === label);\n if (menuitem == null) {\n menuitem = {\n label\n };\n currentMenu.push(menuitem);\n }\n menuitem.target = view.route;\n });\n\n appShellConfiguration.menu = menu;\n}\n"]}
@@ -1,7 +1,43 @@
1
1
  import { expect } from "vitest";
2
2
  import mock from "mock-fs";
3
- import { applyAutomaticMenu, mapFolderIndexFilesToRoutes } from "../automatic-utils";
3
+ import { applyAutomaticMenu, applyAutomaticViewsAndRoutes, mapFolderIndexFilesToRoutes } from "../automatic-utils";
4
4
  describe("test automatic utils", () => {
5
+ const pagesFolderContent = {
6
+ "/dummy/path/app/src/pages": {},
7
+ "/dummy/path/app/src/pages/Page1": {
8
+ "index.tsx": "dummy content"
9
+ },
10
+ "/dummy/path/app/src/pages/Page2": {
11
+ "something.else": "dummy content"
12
+ },
13
+ "/dummy/path/app/src/pages/Page3": {
14
+ "index.tsx": "dummy content"
15
+ },
16
+ "/dummy/path/app/src/pages/Page4": {
17
+ /** empty directory */
18
+ },
19
+ "/dummy/path/app/src/pages/Page5/$id": {
20
+ "index.tsx": "dummy content"
21
+ },
22
+ "/dummy/path/app/src/pages/Page5/$id/Page5_1": {
23
+ "index.tsx": "dummy content"
24
+ },
25
+ "/dummy/path/app/src/pages/Page5/$id/Page5_1/$name": {
26
+ /** empty directory */
27
+ },
28
+ "/dummy/path/app/src/pages/Page5/$id/Page5_1/$name/Page5_2": {
29
+ "index.tsx": "dummy content"
30
+ }
31
+ };
32
+ const noIndexFilesInPagesFolderContent = {
33
+ "/dummy/path/app/src/pages": {},
34
+ "/dummy/path/app/src/pages/Page3": {
35
+ "something.else": "dummy content"
36
+ },
37
+ "/dummy/path/app/src/pages/Page4": {
38
+ /** empty directory */
39
+ }
40
+ };
5
41
  describe("test `mapFolderIndexFilesToRoutes` method", () => {
6
42
  afterEach(() => {
7
43
  mock.restore();
@@ -9,28 +45,13 @@ describe("test automatic utils", () => {
9
45
  it("should return an empty array when resolved views folder does not exist", () => {
10
46
  const root = "/some/other/root";
11
47
  const viewsFolder = "src/pages";
12
- mock({
13
- "/dummy/path/app/src/pages/Page3": {
14
- "something.else": "dummy content"
15
- },
16
- "/dummy/path/app/src/pages/Page4": {
17
- /** empty directory */
18
- }
19
- });
48
+ mock(noIndexFilesInPagesFolderContent);
20
49
  expect(mapFolderIndexFilesToRoutes(root, viewsFolder)).toEqual([]);
21
50
  });
22
51
  it("should return an empty array when there are no index files in the resolved views folder", () => {
23
52
  const root = "/dummy/path/app";
24
53
  const viewsFolder = "src/pages";
25
- mock({
26
- "/dummy/path/app/src/pages": {},
27
- "/dummy/path/app/src/pages/Page3": {
28
- "something.else": "dummy content"
29
- },
30
- "/dummy/path/app/src/pages/Page4": {
31
- /** empty directory */
32
- }
33
- });
54
+ mock(noIndexFilesInPagesFolderContent);
34
55
  expect(mapFolderIndexFilesToRoutes(root, viewsFolder)).toEqual([]);
35
56
  });
36
57
  test.each([
@@ -39,33 +60,7 @@ describe("test automatic utils", () => {
39
60
  ["/dummy/path/app", "/src/pages/"],
40
61
  ["/dummy/path/app", "/src/pages"]
41
62
  ])("should return all mapped main view configs and corresponding modules", (viewsFolderPath, viewsFolder) => {
42
- mock({
43
- "/dummy/path/app/src/pages": {},
44
- "/dummy/path/app/src/pages/Page1": {
45
- "index.tsx": "dummy content"
46
- },
47
- "/dummy/path/app/src/pages/Page2": {
48
- "something.else": "dummy content"
49
- },
50
- "/dummy/path/app/src/pages/Page3": {
51
- "index.tsx": "dummy content"
52
- },
53
- "/dummy/path/app/src/pages/Page4": {
54
- /** empty directory */
55
- },
56
- "/dummy/path/app/src/pages/Page5/$id": {
57
- "index.tsx": "dummy content"
58
- },
59
- "/dummy/path/app/src/pages/Page5/$id/Page5_1": {
60
- "index.tsx": "dummy content"
61
- },
62
- "/dummy/path/app/src/pages/Page5/$id/Page5_1/$name": {
63
- /** empty directory */
64
- },
65
- "/dummy/path/app/src/pages/Page5/$id/Page5_1/$name/Page5_2": {
66
- "index.tsx": "dummy content"
67
- }
68
- });
63
+ mock(pagesFolderContent);
69
64
  expect(mapFolderIndexFilesToRoutes(viewsFolderPath, viewsFolder)).toEqual([
70
65
  {
71
66
  viewConfig: {
@@ -230,5 +225,219 @@ describe("test automatic utils", () => {
230
225
  expect(config.menu).toBe(undefined);
231
226
  });
232
227
  });
228
+ describe("test applyAutomaticViewsAndRoutes", () => {
229
+ const selfAppName = "@hv-tests/some-app";
230
+ const root = "/dummy/path/app";
231
+ const viewsFolder = "src/pages";
232
+ afterEach(() => {
233
+ mock.restore();
234
+ });
235
+ it("should return an empty array when there are neither automatic or manual views", () => {
236
+ mock(noIndexFilesInPagesFolderContent);
237
+ const config = {};
238
+ const result = applyAutomaticViewsAndRoutes(config, selfAppName, root, viewsFolder);
239
+ expect(result.length).toEqual(0);
240
+ expect(config.mainPanel?.views?.length ?? 0).toBe(0);
241
+ });
242
+ it("should return an empty array when there are no automatic views and keep the manual ones", () => {
243
+ mock(noIndexFilesInPagesFolderContent);
244
+ const config = {
245
+ mainPanel: {
246
+ views: [
247
+ { bundle: "@self/pages/Home.js", route: "/" },
248
+ { bundle: "@hv-tests/some-app/pages/Page0.js", route: "/page0" },
249
+ { bundle: "@self/pages/Other.js", route: "/some-path" },
250
+ {
251
+ bundle: "@hv-tests/other-app/pages/HelloFromOther.js",
252
+ route: "/other"
253
+ }
254
+ ]
255
+ }
256
+ };
257
+ const result = applyAutomaticViewsAndRoutes(config, selfAppName, root, viewsFolder);
258
+ expect(result.length).toEqual(0);
259
+ expect(config.mainPanel?.views?.length).toEqual(4);
260
+ expect(config.mainPanel?.views).toEqual(expect.arrayContaining([
261
+ { bundle: "@self/pages/Home.js", route: "/" },
262
+ { bundle: "@hv-tests/some-app/pages/Page0.js", route: "/page0" },
263
+ { bundle: "@self/pages/Other.js", route: "/some-path" },
264
+ {
265
+ bundle: "@hv-tests/other-app/pages/HelloFromOther.js",
266
+ route: "/other"
267
+ }
268
+ ]));
269
+ });
270
+ it("should return modules of found automatic views and add them to the configuration when there are no manual views", () => {
271
+ mock(pagesFolderContent);
272
+ const config = {};
273
+ const result = applyAutomaticViewsAndRoutes(config, selfAppName, root, viewsFolder);
274
+ expect(result.length).toEqual(5);
275
+ expect(result).toEqual(expect.arrayContaining([
276
+ "src/pages/Page1",
277
+ "src/pages/Page3",
278
+ "src/pages/Page5/$id/Page5_1/$name/Page5_2",
279
+ "src/pages/Page5/$id/Page5_1",
280
+ "src/pages/Page5/$id"
281
+ ]));
282
+ expect(config.mainPanel?.views?.length).toEqual(5);
283
+ expect(config.mainPanel?.views).toEqual(expect.arrayContaining([
284
+ { bundle: "@self/pages/Page1.js", route: "/page1" },
285
+ { bundle: "@self/pages/Page3.js", route: "/page3" },
286
+ {
287
+ bundle: "@self/pages/Page5/_id.js",
288
+ route: "/page5/:id"
289
+ },
290
+ {
291
+ bundle: "@self/pages/Page5/_id/Page5_1.js",
292
+ route: "/page5/:id/page5_1"
293
+ },
294
+ {
295
+ bundle: "@self/pages/Page5/_id/Page5_1/_name/Page5_2.js",
296
+ route: "/page5/:id/page5_1/:name/page5_2"
297
+ }
298
+ ]));
299
+ });
300
+ it("should return modules of found automatic views and append them to the configuration when there are manual views", () => {
301
+ mock(pagesFolderContent);
302
+ const config = {
303
+ mainPanel: {
304
+ views: [
305
+ { bundle: "@self/pages/Home.js", route: "/" },
306
+ { bundle: "@hv-tests/some-app/pages/Page0.js", route: "/page0" },
307
+ { bundle: "@self/pages/Other.js", route: "/some-path" },
308
+ {
309
+ bundle: "@hv-tests/other-app/pages/HelloFromOther.js",
310
+ route: "/other"
311
+ }
312
+ ]
313
+ }
314
+ };
315
+ const result = applyAutomaticViewsAndRoutes(config, selfAppName, root, viewsFolder);
316
+ expect(result.length).toEqual(5);
317
+ expect(result).toEqual(expect.arrayContaining([
318
+ "src/pages/Page1",
319
+ "src/pages/Page3",
320
+ "src/pages/Page5/$id/Page5_1/$name/Page5_2",
321
+ "src/pages/Page5/$id/Page5_1",
322
+ "src/pages/Page5/$id"
323
+ ]));
324
+ expect(config.mainPanel?.views?.length).toEqual(9);
325
+ expect(config.mainPanel?.views).toEqual(expect.arrayContaining([
326
+ { bundle: "@self/pages/Home.js", route: "/" },
327
+ { bundle: "@hv-tests/some-app/pages/Page0.js", route: "/page0" },
328
+ { bundle: "@self/pages/Other.js", route: "/some-path" },
329
+ {
330
+ bundle: "@hv-tests/other-app/pages/HelloFromOther.js",
331
+ route: "/other"
332
+ },
333
+ { bundle: "@self/pages/Page1.js", route: "/page1" },
334
+ { bundle: "@self/pages/Page3.js", route: "/page3" },
335
+ {
336
+ bundle: "@self/pages/Page5/_id.js",
337
+ route: "/page5/:id"
338
+ },
339
+ {
340
+ bundle: "@self/pages/Page5/_id/Page5_1.js",
341
+ route: "/page5/:id/page5_1"
342
+ },
343
+ {
344
+ bundle: "@self/pages/Page5/_id/Page5_1/_name/Page5_2.js",
345
+ route: "/page5/:id/page5_1/:name/page5_2"
346
+ }
347
+ ]));
348
+ });
349
+ it("should skip overlapping routes and bundles", () => {
350
+ mock(pagesFolderContent);
351
+ const config = {
352
+ mainPanel: {
353
+ views: [
354
+ { bundle: "@self/pages/Page1.js", route: "/other-path" },
355
+ { bundle: "@hv-tests/some-app/pages/Page3.js", route: "/page3" },
356
+ { bundle: "@self/pages/Other.js", route: "/page5/:id" },
357
+ {
358
+ bundle: "@hv-tests/other-app/pages/HelloFromOther.js",
359
+ route: "/other"
360
+ }
361
+ ]
362
+ }
363
+ };
364
+ const result = applyAutomaticViewsAndRoutes(config, selfAppName, root, viewsFolder);
365
+ expect(result.length).toEqual(5);
366
+ expect(result).toEqual(expect.arrayContaining([
367
+ "src/pages/Page1",
368
+ "src/pages/Page3",
369
+ "src/pages/Page5/$id/Page5_1/$name/Page5_2",
370
+ "src/pages/Page5/$id/Page5_1",
371
+ "src/pages/Page5/$id"
372
+ ]));
373
+ expect(config.mainPanel?.views?.length).toEqual(6);
374
+ expect(config.mainPanel?.views).toEqual(expect.arrayContaining([
375
+ {
376
+ bundle: "@hv-tests/other-app/pages/HelloFromOther.js",
377
+ route: "/other"
378
+ },
379
+ { bundle: "@self/pages/Page1.js", route: "/other-path" },
380
+ { bundle: "@hv-tests/some-app/pages/Page3.js", route: "/page3" },
381
+ { bundle: "@self/pages/Other.js", route: "/page5/:id" },
382
+ {
383
+ bundle: "@self/pages/Page5/_id/Page5_1.js",
384
+ route: "/page5/:id/page5_1"
385
+ },
386
+ {
387
+ bundle: "@self/pages/Page5/_id/Page5_1/_name/Page5_2.js",
388
+ route: "/page5/:id/page5_1/:name/page5_2"
389
+ }
390
+ ]));
391
+ });
392
+ it("should skip overlapping routes and bundles, including nested views", () => {
393
+ mock(pagesFolderContent);
394
+ const config = {
395
+ mainPanel: {
396
+ views: [
397
+ {
398
+ bundle: "@self/pages/Page1.js",
399
+ route: "/other-path",
400
+ views: [{ bundle: "@self/pages/Page3.js", route: "/subpage3" }]
401
+ },
402
+ { bundle: "@self/pages/Other.js", route: "/page5/:id" },
403
+ {
404
+ bundle: "@hv-tests/other-app/pages/HelloFromOther.js",
405
+ route: "/other"
406
+ }
407
+ ]
408
+ }
409
+ };
410
+ const result = applyAutomaticViewsAndRoutes(config, selfAppName, root, viewsFolder);
411
+ expect(result.length).toEqual(5);
412
+ expect(result).toEqual(expect.arrayContaining([
413
+ "src/pages/Page1",
414
+ "src/pages/Page3",
415
+ "src/pages/Page5/$id/Page5_1/$name/Page5_2",
416
+ "src/pages/Page5/$id/Page5_1",
417
+ "src/pages/Page5/$id"
418
+ ]));
419
+ expect(config.mainPanel?.views?.length).toEqual(5);
420
+ expect(config.mainPanel?.views).toEqual(expect.arrayContaining([
421
+ {
422
+ bundle: "@hv-tests/other-app/pages/HelloFromOther.js",
423
+ route: "/other"
424
+ },
425
+ {
426
+ bundle: "@self/pages/Page1.js",
427
+ route: "/other-path",
428
+ views: [{ bundle: "@self/pages/Page3.js", route: "/subpage3" }]
429
+ },
430
+ { bundle: "@self/pages/Other.js", route: "/page5/:id" },
431
+ {
432
+ bundle: "@self/pages/Page5/_id/Page5_1.js",
433
+ route: "/page5/:id/page5_1"
434
+ },
435
+ {
436
+ bundle: "@self/pages/Page5/_id/Page5_1/_name/Page5_2.js",
437
+ route: "/page5/:id/page5_1/:name/page5_2"
438
+ }
439
+ ]));
440
+ });
441
+ });
233
442
  });
234
443
  //# sourceMappingURL=automatic-utils.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"automatic-utils.test.js","sourceRoot":"","sources":["../../src/tests/automatic-utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,IAAI,MAAM,SAAS,CAAC;AAI3B,OAAO,EACL,kBAAkB,EAClB,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAE5B,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,QAAQ,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACzD,SAAS,CAAC,GAAG,EAAE;YACb,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wEAAwE,EAAE,GAAG,EAAE;YAChF,MAAM,IAAI,GAAG,kBAAkB,CAAC;YAChC,MAAM,WAAW,GAAG,WAAW,CAAC;YAEhC,IAAI,CAAC;gBACH,iCAAiC,EAAE;oBACjC,gBAAgB,EAAE,eAAe;iBAClC;gBACD,iCAAiC,EAAE;gBACjC,sBAAsB;iBACvB;aACF,CAAC,CAAC;YAEH,MAAM,CAAC,2BAA2B,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yFAAyF,EAAE,GAAG,EAAE;YACjG,MAAM,IAAI,GAAG,iBAAiB,CAAC;YAC/B,MAAM,WAAW,GAAG,WAAW,CAAC;YA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CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;YACjD,MAAM,MAAM,GAAqB;gBAC/B,SAAS,EAAE;oBACT,KAAK,EAAE,EAAE;iBACV;aACF,CAAC;YAEF,kBAAkB,CAAC,MAAM,CAAC,CAAC;YAE3B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from \"vitest\";\nimport mock from \"mock-fs\";\n\nimport { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport {\n applyAutomaticMenu,\n mapFolderIndexFilesToRoutes\n} from \"../automatic-utils\";\n\ndescribe(\"test automatic utils\", () => {\n describe(\"test `mapFolderIndexFilesToRoutes` method\", () => {\n afterEach(() => {\n mock.restore();\n });\n\n it(\"should return an empty array when resolved views folder does not exist\", () => {\n const root = \"/some/other/root\";\n const viewsFolder = \"src/pages\";\n\n mock({\n \"/dummy/path/app/src/pages/Page3\": {\n \"something.else\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page4\": {\n /** empty directory */\n }\n });\n\n expect(mapFolderIndexFilesToRoutes(root, viewsFolder)).toEqual([]);\n });\n\n it(\"should return an empty array when there are no index files in the resolved views folder\", () => {\n const root = \"/dummy/path/app\";\n const viewsFolder = \"src/pages\";\n\n mock({\n \"/dummy/path/app/src/pages\": {},\n \"/dummy/path/app/src/pages/Page3\": {\n \"something.else\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page4\": {\n /** empty directory */\n }\n });\n\n expect(mapFolderIndexFilesToRoutes(root, viewsFolder)).toEqual([]);\n });\n\n test.each([\n [\"/dummy/path/app\", \"src/pages\"],\n [\"/dummy/path/app\", \"src/pages/\"],\n [\"/dummy/path/app\", \"/src/pages/\"],\n [\"/dummy/path/app\", \"/src/pages\"]\n ])(\n \"should return all mapped main view configs and corresponding modules\",\n (viewsFolderPath: string, viewsFolder: string) => {\n mock({\n \"/dummy/path/app/src/pages\": {},\n \"/dummy/path/app/src/pages/Page1\": {\n \"index.tsx\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page2\": {\n \"something.else\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page3\": {\n \"index.tsx\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page4\": {\n /** empty directory */\n },\n \"/dummy/path/app/src/pages/Page5/$id\": {\n \"index.tsx\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page5/$id/Page5_1\": {\n \"index.tsx\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page5/$id/Page5_1/$name\": {\n /** empty directory */\n },\n \"/dummy/path/app/src/pages/Page5/$id/Page5_1/$name/Page5_2\": {\n \"index.tsx\": \"dummy content\"\n }\n });\n\n expect(\n mapFolderIndexFilesToRoutes(viewsFolderPath, viewsFolder)\n ).toEqual([\n {\n viewConfig: {\n bundle: \"@self/pages/Page1.js\",\n route: \"/page1\"\n },\n module: \"src/pages/Page1\"\n },\n {\n viewConfig: {\n bundle: \"@self/pages/Page3.js\",\n route: \"/page3\"\n },\n module: \"src/pages/Page3\"\n },\n {\n viewConfig: {\n bundle: \"@self/pages/Page5/_id/Page5_1/_name/Page5_2.js\",\n route: \"/page5/:id/page5_1/:name/page5_2\"\n },\n module: \"src/pages/Page5/$id/Page5_1/$name/Page5_2\"\n },\n {\n viewConfig: {\n bundle: \"@self/pages/Page5/_id/Page5_1.js\",\n route: \"/page5/:id/page5_1\"\n },\n module: \"src/pages/Page5/$id/Page5_1\"\n },\n {\n viewConfig: {\n bundle: \"@self/pages/Page5/_id.js\",\n route: \"/page5/:id\"\n },\n module: \"src/pages/Page5/$id\"\n }\n ]);\n }\n );\n });\n\n describe(\"test `applyAutomaticMenu` method\", () => {\n it(\"should create correct menu labels for simple routes\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Page1.js\", route: \"/page1\" },\n { bundle: \"@self/pages/Page2.js\", route: \"/page2\" },\n { bundle: \"@self/pages/helloToWorld.js\", route: \"/hello\" }\n ]\n }\n };\n\n applyAutomaticMenu(config);\n\n const expectedMenu = [\n { label: \"Page1\", target: \"/page1\" },\n { label: \"Page2\", target: \"/page2\" },\n { label: \"Hello To World\", target: \"/hello\" }\n ];\n\n expect(config.menu).toEqual(expectedMenu);\n });\n\n it(\"should handle nested routes correctly\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Section/Page1.js\", route: \"/section/page1\" },\n { bundle: \"@self/pages/Section/Page2.js\", route: \"/section/page2\" },\n {\n bundle: \"@self/pages/Planets/helloToEarth.js\",\n route: \"/planets/earth\"\n },\n {\n bundle: \"@self/pages/Planets/HelloToMars.js\",\n route: \"/planets/mars\"\n },\n {\n bundle: \"@self/pages/someOtherFolder/ToImportantStuff.js\",\n route: \"/other/important\"\n },\n {\n bundle: \"@self/pages/SomeOtherFolder/thisIsOnTheSameMenu.js\",\n route: \"/other/same\"\n }\n ]\n }\n };\n\n applyAutomaticMenu(config);\n\n const expectedMenu = [\n {\n label: \"Section\",\n submenus: [\n { label: \"Page1\", target: \"/section/page1\" },\n { label: \"Page2\", target: \"/section/page2\" }\n ]\n },\n {\n label: \"Planets\",\n submenus: [\n { label: \"Hello To Earth\", target: \"/planets/earth\" },\n { label: \"Hello To Mars\", target: \"/planets/mars\" }\n ]\n },\n {\n label: \"Some Other Folder\",\n submenus: [\n { label: \"To Important Stuff\", target: \"/other/important\" },\n { label: \"This Is On The Same Menu\", target: \"/other/same\" }\n ]\n }\n ];\n\n expect(config.menu).toEqual(expectedMenu);\n });\n\n it(\"should skip dynamic routes\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Page1.js\", route: \"/page1\" },\n { bundle: \"@self/pages/Page2/:id.js\", route: \"/page2/:id\" },\n { bundle: \"@self/pages/Page3.js\", route: \"/page3\" }\n ]\n }\n };\n\n applyAutomaticMenu(config);\n\n const expectedMenu = [\n { label: \"Page1\", target: \"/page1\" },\n // Note: Page2 is skipped because it's a dynamic route\n { label: \"Page3\", target: \"/page3\" }\n ];\n\n expect(config.menu).toEqual(expectedMenu);\n });\n\n it(\"should handle special characters and capitalization in routes\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n {\n bundle:\n \"@self/pages/lowerUpper/Look🙄ingAbóve/SomeSpÉcialPage.js\",\n route: \"/l1/l2/someSpecialPage\"\n }\n ]\n }\n };\n\n applyAutomaticMenu(config);\n\n const expectedMenu = [\n {\n label: \"Lower Upper\",\n submenus: [\n {\n label: \"Look🙄ing Abóve\",\n submenus: [\n { label: \"Some SpÉcial Page\", target: \"/l1/l2/someSpecialPage\" }\n ]\n }\n ]\n }\n ];\n\n expect(config.menu).toEqual(expectedMenu);\n });\n\n it(\"should return undefined for empty views\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: []\n }\n };\n\n applyAutomaticMenu(config);\n\n expect(config.menu).toBe(undefined);\n });\n });\n});\n"]}
1
+ {"version":3,"file":"automatic-utils.test.js","sourceRoot":"","sources":["../../src/tests/automatic-utils.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,IAAI,MAAM,SAAS,CAAC;AAI3B,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAE5B,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,MAAM,kBAAkB,GAAG;QACzB,2BAA2B,EAAE,EAAE;QAC/B,iCAAiC,EAAE;YACjC,WAAW,EAAE,eAAe;SAC7B;QACD,iCAAiC,EAAE;YACjC,gBAAgB,EAAE,eAAe;SAClC;QACD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jB,iBAAiB;gBACjB,2CAA2C;gBAC3C,6BAA6B;gBAC7B,qBAAqB;aACtB,CAAC,CACH,CAAC;YAEF,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACnD,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,OAAO,CACrC,MAAM,CAAC,eAAe,CAAC;gBACrB;oBACE,MAAM,EAAE,6CAA6C;oBACrD,KAAK,EAAE,QAAQ;iBAChB;gBAED;oBACE,MAAM,EAAE,sBAAsB;oBAC9B,KAAK,EAAE,aAAa;oBACpB,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;iBAChE;gBAED,EAAE,MAAM,EAAE,sBAAsB,EAAE,KAAK,EAAE,YAAY,EAAE;gBACvD;oBACE,MAAM,EAAE,kCAAkC;oBAC1C,KAAK,EAAE,oBAAoB;iBAC5B;gBACD;oBACE,MAAM,EAAE,gDAAgD;oBACxD,KAAK,EAAE,kCAAkC;iBAC1C;aACF,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from \"vitest\";\nimport mock from \"mock-fs\";\n\nimport { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport {\n applyAutomaticMenu,\n applyAutomaticViewsAndRoutes,\n mapFolderIndexFilesToRoutes\n} from \"../automatic-utils\";\n\ndescribe(\"test automatic utils\", () => {\n const pagesFolderContent = {\n \"/dummy/path/app/src/pages\": {},\n \"/dummy/path/app/src/pages/Page1\": {\n \"index.tsx\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page2\": {\n \"something.else\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page3\": {\n \"index.tsx\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page4\": {\n /** empty directory */\n },\n \"/dummy/path/app/src/pages/Page5/$id\": {\n \"index.tsx\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page5/$id/Page5_1\": {\n \"index.tsx\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page5/$id/Page5_1/$name\": {\n /** empty directory */\n },\n \"/dummy/path/app/src/pages/Page5/$id/Page5_1/$name/Page5_2\": {\n \"index.tsx\": \"dummy content\"\n }\n };\n\n const noIndexFilesInPagesFolderContent = {\n \"/dummy/path/app/src/pages\": {},\n \"/dummy/path/app/src/pages/Page3\": {\n \"something.else\": \"dummy content\"\n },\n \"/dummy/path/app/src/pages/Page4\": {\n /** empty directory */\n }\n };\n\n describe(\"test `mapFolderIndexFilesToRoutes` method\", () => {\n afterEach(() => {\n mock.restore();\n });\n\n it(\"should return an empty array when resolved views folder does not exist\", () => {\n const root = \"/some/other/root\";\n const viewsFolder = \"src/pages\";\n\n mock(noIndexFilesInPagesFolderContent);\n\n expect(mapFolderIndexFilesToRoutes(root, viewsFolder)).toEqual([]);\n });\n\n it(\"should return an empty array when there are no index files in the resolved views folder\", () => {\n const root = \"/dummy/path/app\";\n const viewsFolder = \"src/pages\";\n\n mock(noIndexFilesInPagesFolderContent);\n\n expect(mapFolderIndexFilesToRoutes(root, viewsFolder)).toEqual([]);\n });\n\n test.each([\n [\"/dummy/path/app\", \"src/pages\"],\n [\"/dummy/path/app\", \"src/pages/\"],\n [\"/dummy/path/app\", \"/src/pages/\"],\n [\"/dummy/path/app\", \"/src/pages\"]\n ])(\n \"should return all mapped main view configs and corresponding modules\",\n (viewsFolderPath: string, viewsFolder: string) => {\n mock(pagesFolderContent);\n\n expect(\n mapFolderIndexFilesToRoutes(viewsFolderPath, viewsFolder)\n ).toEqual([\n {\n viewConfig: {\n bundle: \"@self/pages/Page1.js\",\n route: \"/page1\"\n },\n module: \"src/pages/Page1\"\n },\n {\n viewConfig: {\n bundle: \"@self/pages/Page3.js\",\n route: \"/page3\"\n },\n module: \"src/pages/Page3\"\n },\n {\n viewConfig: {\n bundle: \"@self/pages/Page5/_id/Page5_1/_name/Page5_2.js\",\n route: \"/page5/:id/page5_1/:name/page5_2\"\n },\n module: \"src/pages/Page5/$id/Page5_1/$name/Page5_2\"\n },\n {\n viewConfig: {\n bundle: \"@self/pages/Page5/_id/Page5_1.js\",\n route: \"/page5/:id/page5_1\"\n },\n module: \"src/pages/Page5/$id/Page5_1\"\n },\n {\n viewConfig: {\n bundle: \"@self/pages/Page5/_id.js\",\n route: \"/page5/:id\"\n },\n module: \"src/pages/Page5/$id\"\n }\n ]);\n }\n );\n });\n\n describe(\"test `applyAutomaticMenu` method\", () => {\n it(\"should create correct menu labels for simple routes\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Page1.js\", route: \"/page1\" },\n { bundle: \"@self/pages/Page2.js\", route: \"/page2\" },\n { bundle: \"@self/pages/helloToWorld.js\", route: \"/hello\" }\n ]\n }\n };\n\n applyAutomaticMenu(config);\n\n const expectedMenu = [\n { label: \"Page1\", target: \"/page1\" },\n { label: \"Page2\", target: \"/page2\" },\n { label: \"Hello To World\", target: \"/hello\" }\n ];\n\n expect(config.menu).toEqual(expectedMenu);\n });\n\n it(\"should handle nested routes correctly\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Section/Page1.js\", route: \"/section/page1\" },\n { bundle: \"@self/pages/Section/Page2.js\", route: \"/section/page2\" },\n {\n bundle: \"@self/pages/Planets/helloToEarth.js\",\n route: \"/planets/earth\"\n },\n {\n bundle: \"@self/pages/Planets/HelloToMars.js\",\n route: \"/planets/mars\"\n },\n {\n bundle: \"@self/pages/someOtherFolder/ToImportantStuff.js\",\n route: \"/other/important\"\n },\n {\n bundle: \"@self/pages/SomeOtherFolder/thisIsOnTheSameMenu.js\",\n route: \"/other/same\"\n }\n ]\n }\n };\n\n applyAutomaticMenu(config);\n\n const expectedMenu = [\n {\n label: \"Section\",\n submenus: [\n { label: \"Page1\", target: \"/section/page1\" },\n { label: \"Page2\", target: \"/section/page2\" }\n ]\n },\n {\n label: \"Planets\",\n submenus: [\n { label: \"Hello To Earth\", target: \"/planets/earth\" },\n { label: \"Hello To Mars\", target: \"/planets/mars\" }\n ]\n },\n {\n label: \"Some Other Folder\",\n submenus: [\n { label: \"To Important Stuff\", target: \"/other/important\" },\n { label: \"This Is On The Same Menu\", target: \"/other/same\" }\n ]\n }\n ];\n\n expect(config.menu).toEqual(expectedMenu);\n });\n\n it(\"should skip dynamic routes\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Page1.js\", route: \"/page1\" },\n { bundle: \"@self/pages/Page2/:id.js\", route: \"/page2/:id\" },\n { bundle: \"@self/pages/Page3.js\", route: \"/page3\" }\n ]\n }\n };\n\n applyAutomaticMenu(config);\n\n const expectedMenu = [\n { label: \"Page1\", target: \"/page1\" },\n // Note: Page2 is skipped because it's a dynamic route\n { label: \"Page3\", target: \"/page3\" }\n ];\n\n expect(config.menu).toEqual(expectedMenu);\n });\n\n it(\"should handle special characters and capitalization in routes\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n {\n bundle:\n \"@self/pages/lowerUpper/Look🙄ingAbóve/SomeSpÉcialPage.js\",\n route: \"/l1/l2/someSpecialPage\"\n }\n ]\n }\n };\n\n applyAutomaticMenu(config);\n\n const expectedMenu = [\n {\n label: \"Lower Upper\",\n submenus: [\n {\n label: \"Look🙄ing Abóve\",\n submenus: [\n { label: \"Some SpÉcial Page\", target: \"/l1/l2/someSpecialPage\" }\n ]\n }\n ]\n }\n ];\n\n expect(config.menu).toEqual(expectedMenu);\n });\n\n it(\"should return undefined for empty views\", () => {\n const config: HvAppShellConfig = {\n mainPanel: {\n views: []\n }\n };\n\n applyAutomaticMenu(config);\n\n expect(config.menu).toBe(undefined);\n });\n });\n\n describe(\"test applyAutomaticViewsAndRoutes\", () => {\n const selfAppName = \"@hv-tests/some-app\";\n const root = \"/dummy/path/app\";\n const viewsFolder = \"src/pages\";\n\n afterEach(() => {\n mock.restore();\n });\n\n it(\"should return an empty array when there are neither automatic or manual views\", () => {\n mock(noIndexFilesInPagesFolderContent);\n\n const config: HvAppShellConfig = {};\n\n const result = applyAutomaticViewsAndRoutes(\n config,\n selfAppName,\n root,\n viewsFolder\n );\n\n expect(result.length).toEqual(0);\n\n expect(config.mainPanel?.views?.length ?? 0).toBe(0);\n });\n\n it(\"should return an empty array when there are no automatic views and keep the manual ones\", () => {\n mock(noIndexFilesInPagesFolderContent);\n\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Home.js\", route: \"/\" },\n { bundle: \"@hv-tests/some-app/pages/Page0.js\", route: \"/page0\" },\n { bundle: \"@self/pages/Other.js\", route: \"/some-path\" },\n {\n bundle: \"@hv-tests/other-app/pages/HelloFromOther.js\",\n route: \"/other\"\n }\n ]\n }\n };\n\n const result = applyAutomaticViewsAndRoutes(\n config,\n selfAppName,\n root,\n viewsFolder\n );\n\n expect(result.length).toEqual(0);\n\n expect(config.mainPanel?.views?.length).toEqual(4);\n expect(config.mainPanel?.views).toEqual(\n expect.arrayContaining([\n { bundle: \"@self/pages/Home.js\", route: \"/\" },\n { bundle: \"@hv-tests/some-app/pages/Page0.js\", route: \"/page0\" },\n { bundle: \"@self/pages/Other.js\", route: \"/some-path\" },\n {\n bundle: \"@hv-tests/other-app/pages/HelloFromOther.js\",\n route: \"/other\"\n }\n ])\n );\n });\n\n it(\"should return modules of found automatic views and add them to the configuration when there are no manual views\", () => {\n mock(pagesFolderContent);\n\n const config: HvAppShellConfig = {};\n\n const result = applyAutomaticViewsAndRoutes(\n config,\n selfAppName,\n root,\n viewsFolder\n );\n\n expect(result.length).toEqual(5);\n expect(result).toEqual(\n expect.arrayContaining([\n \"src/pages/Page1\",\n \"src/pages/Page3\",\n \"src/pages/Page5/$id/Page5_1/$name/Page5_2\",\n \"src/pages/Page5/$id/Page5_1\",\n \"src/pages/Page5/$id\"\n ])\n );\n\n expect(config.mainPanel?.views?.length).toEqual(5);\n expect(config.mainPanel?.views).toEqual(\n expect.arrayContaining([\n { bundle: \"@self/pages/Page1.js\", route: \"/page1\" },\n { bundle: \"@self/pages/Page3.js\", route: \"/page3\" },\n {\n bundle: \"@self/pages/Page5/_id.js\",\n route: \"/page5/:id\"\n },\n {\n bundle: \"@self/pages/Page5/_id/Page5_1.js\",\n route: \"/page5/:id/page5_1\"\n },\n {\n bundle: \"@self/pages/Page5/_id/Page5_1/_name/Page5_2.js\",\n route: \"/page5/:id/page5_1/:name/page5_2\"\n }\n ])\n );\n });\n\n it(\"should return modules of found automatic views and append them to the configuration when there are manual views\", () => {\n mock(pagesFolderContent);\n\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Home.js\", route: \"/\" },\n { bundle: \"@hv-tests/some-app/pages/Page0.js\", route: \"/page0\" },\n { bundle: \"@self/pages/Other.js\", route: \"/some-path\" },\n {\n bundle: \"@hv-tests/other-app/pages/HelloFromOther.js\",\n route: \"/other\"\n }\n ]\n }\n };\n\n const result = applyAutomaticViewsAndRoutes(\n config,\n selfAppName,\n root,\n viewsFolder\n );\n\n expect(result.length).toEqual(5);\n expect(result).toEqual(\n expect.arrayContaining([\n \"src/pages/Page1\",\n \"src/pages/Page3\",\n \"src/pages/Page5/$id/Page5_1/$name/Page5_2\",\n \"src/pages/Page5/$id/Page5_1\",\n \"src/pages/Page5/$id\"\n ])\n );\n\n expect(config.mainPanel?.views?.length).toEqual(9);\n expect(config.mainPanel?.views).toEqual(\n expect.arrayContaining([\n { bundle: \"@self/pages/Home.js\", route: \"/\" },\n { bundle: \"@hv-tests/some-app/pages/Page0.js\", route: \"/page0\" },\n { bundle: \"@self/pages/Other.js\", route: \"/some-path\" },\n {\n bundle: \"@hv-tests/other-app/pages/HelloFromOther.js\",\n route: \"/other\"\n },\n\n { bundle: \"@self/pages/Page1.js\", route: \"/page1\" },\n { bundle: \"@self/pages/Page3.js\", route: \"/page3\" },\n {\n bundle: \"@self/pages/Page5/_id.js\",\n route: \"/page5/:id\"\n },\n {\n bundle: \"@self/pages/Page5/_id/Page5_1.js\",\n route: \"/page5/:id/page5_1\"\n },\n {\n bundle: \"@self/pages/Page5/_id/Page5_1/_name/Page5_2.js\",\n route: \"/page5/:id/page5_1/:name/page5_2\"\n }\n ])\n );\n });\n\n it(\"should skip overlapping routes and bundles\", () => {\n mock(pagesFolderContent);\n\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n { bundle: \"@self/pages/Page1.js\", route: \"/other-path\" },\n { bundle: \"@hv-tests/some-app/pages/Page3.js\", route: \"/page3\" },\n { bundle: \"@self/pages/Other.js\", route: \"/page5/:id\" },\n {\n bundle: \"@hv-tests/other-app/pages/HelloFromOther.js\",\n route: \"/other\"\n }\n ]\n }\n };\n\n const result = applyAutomaticViewsAndRoutes(\n config,\n selfAppName,\n root,\n viewsFolder\n );\n\n expect(result.length).toEqual(5);\n expect(result).toEqual(\n expect.arrayContaining([\n \"src/pages/Page1\",\n \"src/pages/Page3\",\n \"src/pages/Page5/$id/Page5_1/$name/Page5_2\",\n \"src/pages/Page5/$id/Page5_1\",\n \"src/pages/Page5/$id\"\n ])\n );\n\n expect(config.mainPanel?.views?.length).toEqual(6);\n expect(config.mainPanel?.views).toEqual(\n expect.arrayContaining([\n {\n bundle: \"@hv-tests/other-app/pages/HelloFromOther.js\",\n route: \"/other\"\n },\n\n { bundle: \"@self/pages/Page1.js\", route: \"/other-path\" },\n { bundle: \"@hv-tests/some-app/pages/Page3.js\", route: \"/page3\" },\n { bundle: \"@self/pages/Other.js\", route: \"/page5/:id\" },\n {\n bundle: \"@self/pages/Page5/_id/Page5_1.js\",\n route: \"/page5/:id/page5_1\"\n },\n {\n bundle: \"@self/pages/Page5/_id/Page5_1/_name/Page5_2.js\",\n route: \"/page5/:id/page5_1/:name/page5_2\"\n }\n ])\n );\n });\n\n it(\"should skip overlapping routes and bundles, including nested views\", () => {\n mock(pagesFolderContent);\n\n const config: HvAppShellConfig = {\n mainPanel: {\n views: [\n {\n bundle: \"@self/pages/Page1.js\",\n route: \"/other-path\",\n views: [{ bundle: \"@self/pages/Page3.js\", route: \"/subpage3\" }]\n },\n { bundle: \"@self/pages/Other.js\", route: \"/page5/:id\" },\n {\n bundle: \"@hv-tests/other-app/pages/HelloFromOther.js\",\n route: \"/other\"\n }\n ]\n }\n };\n\n const result = applyAutomaticViewsAndRoutes(\n config,\n selfAppName,\n root,\n viewsFolder\n );\n\n expect(result.length).toEqual(5);\n expect(result).toEqual(\n expect.arrayContaining([\n \"src/pages/Page1\",\n \"src/pages/Page3\",\n \"src/pages/Page5/$id/Page5_1/$name/Page5_2\",\n \"src/pages/Page5/$id/Page5_1\",\n \"src/pages/Page5/$id\"\n ])\n );\n\n expect(config.mainPanel?.views?.length).toEqual(5);\n expect(config.mainPanel?.views).toEqual(\n expect.arrayContaining([\n {\n bundle: \"@hv-tests/other-app/pages/HelloFromOther.js\",\n route: \"/other\"\n },\n\n {\n bundle: \"@self/pages/Page1.js\",\n route: \"/other-path\",\n views: [{ bundle: \"@self/pages/Page3.js\", route: \"/subpage3\" }]\n },\n\n { bundle: \"@self/pages/Other.js\", route: \"/page5/:id\" },\n {\n bundle: \"@self/pages/Page5/_id/Page5_1.js\",\n route: \"/page5/:id/page5_1\"\n },\n {\n bundle: \"@self/pages/Page5/_id/Page5_1/_name/Page5_2.js\",\n route: \"/page5/:id/page5_1/:name/page5_2\"\n }\n ])\n );\n });\n });\n});\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vite-configuration-processor-plugin.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-configuration-processor-plugin.test.d.ts","sourceRoot":"","sources":["../../src/tests/vite-configuration-processor-plugin.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,72 @@
1
+ import { replaceReferencesToSelf } from "../vite-configuration-processor-plugin";
2
+ describe("replaceReferencesToSelf", () => {
3
+ it("should replace references to self in bundle definitions", () => {
4
+ const bundles = [
5
+ {
6
+ bundle: "@self/pages/Page1.js",
7
+ views: [
8
+ {
9
+ bundle: "@self/pages/Page2.js"
10
+ },
11
+ {
12
+ bundle: "@other-app/pages/Page3.js"
13
+ }
14
+ ]
15
+ },
16
+ {
17
+ bundle: "@other-app/pages/Page4.js"
18
+ }
19
+ ];
20
+ const selfAppName = "@hv-tests/some-app";
21
+ const expectedBundles = [
22
+ {
23
+ bundle: "@hv-tests/some-app/pages/Page1.js",
24
+ views: [
25
+ {
26
+ bundle: "@hv-tests/some-app/pages/Page2.js"
27
+ },
28
+ {
29
+ bundle: "@other-app/pages/Page3.js"
30
+ }
31
+ ]
32
+ },
33
+ {
34
+ bundle: "@other-app/pages/Page4.js"
35
+ }
36
+ ];
37
+ const result = replaceReferencesToSelf(bundles, selfAppName);
38
+ expect(result).toEqual(expectedBundles);
39
+ });
40
+ it("should not modify bundle definitions without references to self", () => {
41
+ const bundles = [
42
+ {
43
+ bundle: "@other-app/pages/Page1.js"
44
+ },
45
+ {
46
+ bundle: "@other-app/pages/Page2.js",
47
+ views: [
48
+ {
49
+ bundle: "@other-app/pages/Page3.js"
50
+ }
51
+ ]
52
+ }
53
+ ];
54
+ const selfAppName = "@hv-tests/some-app";
55
+ const expectedBundles = [
56
+ {
57
+ bundle: "@other-app/pages/Page1.js"
58
+ },
59
+ {
60
+ bundle: "@other-app/pages/Page2.js",
61
+ views: [
62
+ {
63
+ bundle: "@other-app/pages/Page3.js"
64
+ }
65
+ ]
66
+ }
67
+ ];
68
+ const result = replaceReferencesToSelf(bundles, selfAppName);
69
+ expect(result).toEqual(expectedBundles);
70
+ });
71
+ });
72
+ //# sourceMappingURL=vite-configuration-processor-plugin.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-configuration-processor-plugin.test.js","sourceRoot":"","sources":["../../src/tests/vite-configuration-processor-plugin.test.ts"],"names":[],"mappings":"AAAA,OAAO,E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C,OAAO,EAAE,WAAW,CAAC,CAAC;QAE7D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { replaceReferencesToSelf } from \"../vite-configuration-processor-plugin\";\n\ndescribe(\"replaceReferencesToSelf\", () => {\n it(\"should replace references to self in bundle definitions\", () => {\n const bundles = [\n {\n bundle: \"@self/pages/Page1.js\",\n views: [\n {\n bundle: \"@self/pages/Page2.js\"\n },\n {\n bundle: \"@other-app/pages/Page3.js\"\n }\n ]\n },\n {\n bundle: \"@other-app/pages/Page4.js\"\n }\n ];\n\n const selfAppName = \"@hv-tests/some-app\";\n\n const expectedBundles = [\n {\n bundle: \"@hv-tests/some-app/pages/Page1.js\",\n views: [\n {\n bundle: \"@hv-tests/some-app/pages/Page2.js\"\n },\n {\n bundle: \"@other-app/pages/Page3.js\"\n }\n ]\n },\n {\n bundle: \"@other-app/pages/Page4.js\"\n }\n ];\n\n const result = replaceReferencesToSelf(bundles, selfAppName);\n\n expect(result).toEqual(expectedBundles);\n });\n\n it(\"should not modify bundle definitions without references to self\", () => {\n const bundles = [\n {\n bundle: \"@other-app/pages/Page1.js\"\n },\n {\n bundle: \"@other-app/pages/Page2.js\",\n views: [\n {\n bundle: \"@other-app/pages/Page3.js\"\n }\n ]\n }\n ];\n\n const selfAppName = \"@hv-tests/some-app\";\n\n const expectedBundles = [\n {\n bundle: \"@other-app/pages/Page1.js\"\n },\n {\n bundle: \"@other-app/pages/Page2.js\",\n views: [\n {\n bundle: \"@other-app/pages/Page3.js\"\n }\n ]\n }\n ];\n\n const result = replaceReferencesToSelf(bundles, selfAppName);\n\n expect(result).toEqual(expectedBundles);\n });\n});\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { PluginOption } from "vite";
2
- import type { HvAppShellConfig } from "@hitachivantara/app-shell-shared";
2
+ import type { HvAppShellConfig, HvAppShellHeaderAction, HvAppShellProvidersConfig, HvAppShellViewsConfig } from "@hitachivantara/app-shell-shared";
3
+ type BundleDefinition = HvAppShellProvidersConfig | HvAppShellViewsConfig | HvAppShellHeaderAction;
4
+ export declare function replaceReferencesToSelf<T extends BundleDefinition>(bundles: T[], selfAppName: string): T[];
3
5
  /**
4
6
  * Process configuration, executing several tasks:
5
7
  * - Create rollup configuration to support module creation
@@ -14,4 +16,5 @@ import type { HvAppShellConfig } from "@hitachivantara/app-shell-shared";
14
16
  * @param modules the set of modules to be created by the rollup
15
17
  */
16
18
  export default function processConfiguration(root: string, appShellConfig: HvAppShellConfig, selfAppName: string, buildEntryPoint: boolean, inlineConfig: boolean, generateEmptyShell: boolean, modules?: string[]): PluginOption;
19
+ export {};
17
20
  //# sourceMappingURL=vite-configuration-processor-plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite-configuration-processor-plugin.d.ts","sourceRoot":"","sources":["../src/vite-configuration-processor-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,MAAM,CAAC;AAGrD,OAAO,KAAK,EACV,gBAAgB,EAIjB,MAAM,kCAAkC,CAAC;AAgC1C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,gBAAgB,EAChC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,OAAO,EACxB,YAAY,EAAE,OAAO,EACrB,kBAAkB,EAAE,OAAO,EAC3B,OAAO,GAAE,MAAM,EAAO,GACrB,YAAY,CAiJd"}
1
+ {"version":3,"file":"vite-configuration-processor-plugin.d.ts","sourceRoot":"","sources":["../src/vite-configuration-processor-plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,MAAM,CAAC;AAGrD,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAc1C,KAAK,gBAAgB,GACjB,yBAAyB,GACzB,qBAAqB,GACrB,sBAAsB,CAAC;AAE3B,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,gBAAgB,EAChE,OAAO,EAAE,CAAC,EAAE,EACZ,WAAW,EAAE,MAAM,GAClB,CAAC,EAAE,CAkBL;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,gBAAgB,EAChC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,OAAO,EACxB,YAAY,EAAE,OAAO,EACrB,kBAAkB,EAAE,OAAO,EAC3B,OAAO,GAAE,MAAM,EAAO,GACrB,YAAY,CAiJd"}
@@ -6,11 +6,20 @@ var ViteCommand;
6
6
  ViteCommand["BUILD"] = "build";
7
7
  ViteCommand["SERVE"] = "serve";
8
8
  })(ViteCommand || (ViteCommand = {}));
9
- function replaceReferencesToSelf(bundles, selfAppName) {
9
+ export function replaceReferencesToSelf(bundles, selfAppName) {
10
10
  return bundles.map(bundleDefinition => {
11
+ if ("views" in bundleDefinition && bundleDefinition.views != null) {
12
+ return {
13
+ ...bundleDefinition,
14
+ bundle: replaceSelf(bundleDefinition.bundle, `${selfAppName}/`),
15
+ views: replaceReferencesToSelf(bundleDefinition.views, selfAppName)
16
+ };
17
+ }
11
18
  if (startsWithSelf(bundleDefinition.bundle)) {
12
- const bundleName = replaceSelf(bundleDefinition.bundle);
13
- return { ...bundleDefinition, bundle: `${selfAppName}/${bundleName}` };
19
+ return {
20
+ ...bundleDefinition,
21
+ bundle: replaceSelf(bundleDefinition.bundle, `${selfAppName}/`)
22
+ };
14
23
  }
15
24
  return bundleDefinition;
16
25
  });
@@ -1 +1 @@
1
- {"version":3,"file":"vite-configuration-processor-plugin.js","sourceRoot":"","sources":["../src/vite-configuration-processor-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAA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,uBAAuB,CAC1D,mBAAmB,CAAC,MAAM,EAAE,OAAO,EACnC,WAAW,CACZ,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAChD,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;YACJ,CAAC;QACH,CAAC;QAED,kBAAkB,EAAE;YAClB,OAAO,EAAE,IAAI,CAAC,EAAE;gBACd,IAAI,CAAC,YAAY,EAAE,CAAC;oBAClB,OAAO,SAAS,CAAC;gBACnB,CAAC;gBAED,OAAO;oBACL,IAAI;oBAEJ,IAAI,EAAE;wBACJ;4BACE,GAAG,EAAE,QAAQ;4BACb,QAAQ,EAAE,cAAc;4BACxB,QAAQ,EAAE,oCACR,kBAAkB;gCAChB,CAAC,CAAC,qBAAqB;gCACvB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,IAAI,cAAc,CAC1D,GAAG;yBACJ;qBACF;iBACF,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type { PluginOption, UserConfig } from \"vite\";\nimport type { NormalizedOutputOptions } from \"rollup\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellHeaderAction,\n HvAppShellProvidersConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport {\n getAppModules,\n getPublicPath,\n replaceSelf,\n startsWithSelf\n} from \"./config-utils.js\";\n\nenum ViteCommand {\n BUILD = \"build\",\n SERVE = \"serve\"\n}\n\ntype BundleDefinition =\n | HvAppShellProvidersConfig\n | HvAppShellViewsConfig\n | HvAppShellHeaderAction;\n\nfunction replaceReferencesToSelf(\n bundles: BundleDefinition[],\n selfAppName: string\n) {\n return bundles.map(bundleDefinition => {\n if (startsWithSelf(bundleDefinition.bundle)) {\n const bundleName = replaceSelf(bundleDefinition.bundle);\n return { ...bundleDefinition, bundle: `${selfAppName}/${bundleName}` };\n }\n return bundleDefinition;\n });\n}\n\n/**\n * Process configuration, executing several tasks:\n * - Create rollup configuration to support module creation\n * - Generates final transformed configuration json\n * - \"base\" value is always \"./\" for build, and main app baseUrl for preview or dev\n * @param root Project root directory.\n * @param appShellConfig The original App Shell configuration json.\n * @param selfAppName The name of the application bundle being built.\n * @param buildEntryPoint If true, the index.html entry point will be added to the bundle.\n * @param inlineConfig flag to control if config is included at index.html\n * @param generateEmptyShell flag to control if we are creating an empty AppShell instance\n * @param modules the set of modules to be created by the rollup\n */\nexport default function processConfiguration(\n root: string,\n appShellConfig: HvAppShellConfig,\n selfAppName: string,\n buildEntryPoint: boolean,\n inlineConfig: boolean,\n generateEmptyShell: boolean,\n modules: string[] = []\n): PluginOption {\n let finalAppShellConfig: HvAppShellConfig;\n\n return {\n name: \"vite-plugin-appShell-configuration-processor\",\n\n config(config: UserConfig, { command }) {\n const projectRoot = root ?? config.root;\n\n const publicPath = getPublicPath(appShellConfig);\n let appModules: Record<string, string> = {};\n if (!generateEmptyShell) {\n appModules = getAppModules(projectRoot, modules);\n console.info(\n \"Modules exported by the application bundle:\",\n Object.entries(appModules).reduce(\n (acc, [key, value]) => {\n acc[`${selfAppName}/${key}.js`] = value;\n return acc;\n },\n {} as Record<string, string>\n )\n );\n }\n\n return {\n build: {\n rollupOptions: {\n preserveEntrySignatures: \"strict\",\n input: {\n ...(buildEntryPoint &&\n fs.existsSync(path.resolve(projectRoot, \"index.html\"))\n ? { main: path.resolve(projectRoot, \"index.html\") }\n : {}),\n ...appModules\n },\n output: {\n entryFileNames: \"[name].js\"\n }\n }\n },\n // if serve (preview/dev) it uses the baseUrl. Otherwise(build), use ./\n base: command === ViteCommand.SERVE ? publicPath : \"./\"\n };\n },\n\n /**\n * Rollup hook with the info for bundle generation\n * It will be used to create a new configuration with:\n * - bundles replace with the final location (e.g. -> \"bundle\": \"src/pages/Main\" transformed to \"bundle\": \"pages/Main.js\",\n * @param options build options\n */\n async generateBundle(options: NormalizedOutputOptions) {\n if (generateEmptyShell || !buildEntryPoint) {\n return;\n }\n\n // obtain the directory (dist) where the new config file will be placed\n let targetDir: string | undefined;\n if (options.dir) {\n targetDir = options.dir;\n } else if (options.file) {\n targetDir = path.dirname(options.file);\n }\n\n if (!targetDir) {\n throw new Error(\n \"Please set outputPath, so we can know where to place the json file\"\n );\n }\n\n // create the targetDir if it does not exist\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n // theming structure does not rely on having the 'bundle' prop\n const { theming } = appShellConfig;\n if (theming != null) {\n theming.themes = theming.themes?.map(theme => {\n if (startsWithSelf(theme)) {\n const bundleName = replaceSelf(theme);\n return `${selfAppName}/${bundleName}`;\n }\n\n return theme;\n });\n }\n\n finalAppShellConfig = { ...appShellConfig };\n finalAppShellConfig.apps = undefined;\n // also replace implicit references to selfApp in other parts of the configuration\n if (finalAppShellConfig.providers != null) {\n finalAppShellConfig.providers = replaceReferencesToSelf(\n finalAppShellConfig.providers,\n selfAppName\n );\n }\n\n if (finalAppShellConfig.mainPanel?.views != null) {\n finalAppShellConfig.mainPanel.views = replaceReferencesToSelf(\n finalAppShellConfig.mainPanel.views,\n selfAppName\n ) as HvAppShellViewsConfig[];\n }\n\n if (finalAppShellConfig.header?.actions != null) {\n finalAppShellConfig.header.actions = replaceReferencesToSelf(\n finalAppShellConfig.header?.actions,\n selfAppName\n );\n }\n\n if (!inlineConfig) {\n fs.writeFileSync(\n path.resolve(targetDir, \"app-shell.config.json\"),\n JSON.stringify(finalAppShellConfig)\n );\n }\n },\n\n transformIndexHtml: {\n handler: html => {\n if (!inlineConfig) {\n return undefined;\n }\n\n return {\n html,\n\n tags: [\n {\n tag: \"script\",\n injectTo: \"head-prepend\",\n children: `globalThis.__appshell_config__ = ${\n generateEmptyShell\n ? \"%%APPSHELL_CONFIG%%\"\n : JSON.stringify(finalAppShellConfig ?? appShellConfig)\n };`\n }\n ]\n };\n }\n }\n };\n}\n"]}
1
+ {"version":3,"file":"vite-configuration-processor-plugin.js","sourceRoot":"","sources":["../src/vite-configuration-processor-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAYxB,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,cAAc,EACf,MAAM,mBAAmB,CAAC;AAE3B,IAAK,WAGJ;AAHD,WAAK,WAAW;IACd,8BAAe,CAAA;IACf,8BAAe,CAAA;AACjB,CAAC,EAHI,WAAW,KAAX,WAAW,QAGf;AAOD,MAAM,UAAU,uBAAuB,CACrC,OAAY,EACZ,WAAmB;IAEnB,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE;QACpC,IAAI,OAAO,IAAI,gBAAgB,IAAI,gBAAgB,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YAClE,OAAO;gBACL,GAAG,gBAAgB;gBACnB,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,WAAW,GAAG,CAAC;gBAC/D,KAAK,EAAE,uBAAuB,CAAC,gBAAgB,CAAC,KAAK,EAAE,WAAW,CAAC;aACpE,CAAC;QACJ,CAAC;QAED,IAAI,cAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5C,OAAO;gBACL,GAAG,gBAAgB;gBACnB,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,WAAW,GAAG,CAAC;aAChE,CAAC;QACJ,CAAC;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,IAAY,EACZ,cAAgC,EAChC,WAAmB,EACnB,eAAwB,EACxB,YAAqB,EACrB,kBAA2B,EAC3B,UAAoB,EAA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,IAAI,IAAI,EAAE,CAAC;gBAC1C,mBAAmB,CAAC,SAAS,GAAG,uBAAuB,CACrD,mBAAmB,CAAC,SAAS,EAC7B,WAAW,CACZ,CAAC;YACJ,CAAC;YAED,IAAI,mBAAmB,CAAC,SAAS,EAAE,KAAK,IAAI,IAAI,EAAE,CAAC;gBACjD,mBAAmB,CAAC,SAAS,CAAC,KAAK,GAAG,uBAAuB,CAC3D,mBAAmB,CAAC,SAAS,CAAC,KAAK,EACnC,WAAW,CACe,CAAC;YAC/B,CAAC;YAED,IAAI,mBAAmB,CAAC,MAAM,EAAE,OAAO,IAAI,IAAI,EAAE,CAAC;gBAChD,mBAAmB,CAAC,MAAM,CAAC,OAAO,GAAG,uBAAuB,CAC1D,mBAAmB,CAAC,MAAM,EAAE,OAAO,EACnC,WAAW,CACZ,CAAC;YACJ,CAAC;YAED,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,EAAE,CAAC,aAAa,CACd,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAChD,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;YACJ,CAAC;QACH,CAAC;QAED,kBAAkB,EAAE;YAClB,OAAO,EAAE,IAAI,CAAC,EAAE;gBACd,IAAI,CAAC,YAAY,EAAE,CAAC;oBAClB,OAAO,SAAS,CAAC;gBACnB,CAAC;gBAED,OAAO;oBACL,IAAI;oBAEJ,IAAI,EAAE;wBACJ;4BACE,GAAG,EAAE,QAAQ;4BACb,QAAQ,EAAE,cAAc;4BACxB,QAAQ,EAAE,oCACR,kBAAkB;gCAChB,CAAC,CAAC,qBAAqB;gCACvB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,mBAAmB,IAAI,cAAc,CAC1D,GAAG;yBACJ;qBACF;iBACF,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type { PluginOption, UserConfig } from \"vite\";\nimport type { NormalizedOutputOptions } from \"rollup\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellHeaderAction,\n HvAppShellProvidersConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport {\n getAppModules,\n getPublicPath,\n replaceSelf,\n startsWithSelf\n} from \"./config-utils.js\";\n\nenum ViteCommand {\n BUILD = \"build\",\n SERVE = \"serve\"\n}\n\ntype BundleDefinition =\n | HvAppShellProvidersConfig\n | HvAppShellViewsConfig\n | HvAppShellHeaderAction;\n\nexport function replaceReferencesToSelf<T extends BundleDefinition>(\n bundles: T[],\n selfAppName: string\n): T[] {\n return bundles.map(bundleDefinition => {\n if (\"views\" in bundleDefinition && bundleDefinition.views != null) {\n return {\n ...bundleDefinition,\n bundle: replaceSelf(bundleDefinition.bundle, `${selfAppName}/`),\n views: replaceReferencesToSelf(bundleDefinition.views, selfAppName)\n };\n }\n\n if (startsWithSelf(bundleDefinition.bundle)) {\n return {\n ...bundleDefinition,\n bundle: replaceSelf(bundleDefinition.bundle, `${selfAppName}/`)\n };\n }\n return bundleDefinition;\n });\n}\n\n/**\n * Process configuration, executing several tasks:\n * - Create rollup configuration to support module creation\n * - Generates final transformed configuration json\n * - \"base\" value is always \"./\" for build, and main app baseUrl for preview or dev\n * @param root Project root directory.\n * @param appShellConfig The original App Shell configuration json.\n * @param selfAppName The name of the application bundle being built.\n * @param buildEntryPoint If true, the index.html entry point will be added to the bundle.\n * @param inlineConfig flag to control if config is included at index.html\n * @param generateEmptyShell flag to control if we are creating an empty AppShell instance\n * @param modules the set of modules to be created by the rollup\n */\nexport default function processConfiguration(\n root: string,\n appShellConfig: HvAppShellConfig,\n selfAppName: string,\n buildEntryPoint: boolean,\n inlineConfig: boolean,\n generateEmptyShell: boolean,\n modules: string[] = []\n): PluginOption {\n let finalAppShellConfig: HvAppShellConfig;\n\n return {\n name: \"vite-plugin-appShell-configuration-processor\",\n\n config(config: UserConfig, { command }) {\n const projectRoot = root ?? config.root;\n\n const publicPath = getPublicPath(appShellConfig);\n let appModules: Record<string, string> = {};\n if (!generateEmptyShell) {\n appModules = getAppModules(projectRoot, modules);\n console.info(\n \"Modules exported by the application bundle:\",\n Object.entries(appModules).reduce(\n (acc, [key, value]) => {\n acc[`${selfAppName}/${key}.js`] = value;\n return acc;\n },\n {} as Record<string, string>\n )\n );\n }\n\n return {\n build: {\n rollupOptions: {\n preserveEntrySignatures: \"strict\",\n input: {\n ...(buildEntryPoint &&\n fs.existsSync(path.resolve(projectRoot, \"index.html\"))\n ? { main: path.resolve(projectRoot, \"index.html\") }\n : {}),\n ...appModules\n },\n output: {\n entryFileNames: \"[name].js\"\n }\n }\n },\n // if serve (preview/dev) it uses the baseUrl. Otherwise(build), use ./\n base: command === ViteCommand.SERVE ? publicPath : \"./\"\n };\n },\n\n /**\n * Rollup hook with the info for bundle generation\n * It will be used to create a new configuration with:\n * - bundles replace with the final location (e.g. -> \"bundle\": \"src/pages/Main\" transformed to \"bundle\": \"pages/Main.js\",\n * @param options build options\n */\n async generateBundle(options: NormalizedOutputOptions) {\n if (generateEmptyShell || !buildEntryPoint) {\n return;\n }\n\n // obtain the directory (dist) where the new config file will be placed\n let targetDir: string | undefined;\n if (options.dir) {\n targetDir = options.dir;\n } else if (options.file) {\n targetDir = path.dirname(options.file);\n }\n\n if (!targetDir) {\n throw new Error(\n \"Please set outputPath, so we can know where to place the json file\"\n );\n }\n\n // create the targetDir if it does not exist\n if (!fs.existsSync(targetDir)) {\n fs.mkdirSync(targetDir, { recursive: true });\n }\n\n // theming structure does not rely on having the 'bundle' prop\n const { theming } = appShellConfig;\n if (theming != null) {\n theming.themes = theming.themes?.map(theme => {\n if (startsWithSelf(theme)) {\n const bundleName = replaceSelf(theme);\n return `${selfAppName}/${bundleName}`;\n }\n\n return theme;\n });\n }\n\n finalAppShellConfig = { ...appShellConfig };\n finalAppShellConfig.apps = undefined;\n // also replace implicit references to selfApp in other parts of the configuration\n if (finalAppShellConfig.providers != null) {\n finalAppShellConfig.providers = replaceReferencesToSelf(\n finalAppShellConfig.providers,\n selfAppName\n );\n }\n\n if (finalAppShellConfig.mainPanel?.views != null) {\n finalAppShellConfig.mainPanel.views = replaceReferencesToSelf(\n finalAppShellConfig.mainPanel.views,\n selfAppName\n ) as HvAppShellViewsConfig[];\n }\n\n if (finalAppShellConfig.header?.actions != null) {\n finalAppShellConfig.header.actions = replaceReferencesToSelf(\n finalAppShellConfig.header?.actions,\n selfAppName\n );\n }\n\n if (!inlineConfig) {\n fs.writeFileSync(\n path.resolve(targetDir, \"app-shell.config.json\"),\n JSON.stringify(finalAppShellConfig)\n );\n }\n },\n\n transformIndexHtml: {\n handler: html => {\n if (!inlineConfig) {\n return undefined;\n }\n\n return {\n html,\n\n tags: [\n {\n tag: \"script\",\n injectTo: \"head-prepend\",\n children: `globalThis.__appshell_config__ = ${\n generateEmptyShell\n ? \"%%APPSHELL_CONFIG%%\"\n : JSON.stringify(finalAppShellConfig ?? appShellConfig)\n };`\n }\n ]\n };\n }\n }\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,YAAY,EAAE,MAAM,MAAM,CAAC;AAa7C,OAAO,EACL,iBAAiB,EAIlB,MAAM,mBAAmB,CAAC;AAc3B,MAAM,MAAM,qBAAqB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAErD,MAAM,WAAW,yBAAyB;IACxC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,qBAAqB,CAAC;IAE7B;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEzC;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,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vB;;;;;;;;;;;OAWG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,iBAAS,kBAAkB,CACzB,IAAI,GAAE,yBAA8B,EACpC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,YAAY,CA4Kd;AAED,eAAe,kBAAkB,CAAC"}
@@ -41,7 +41,7 @@ function appShellVitePlugin(opts = {}, env = {}) {
41
41
  let autoViewsBundles = [];
42
42
  if (!generateEmptyShell) {
43
43
  if (autoViewsAndRoutes) {
44
- autoViewsBundles = applyAutomaticViewsAndRoutes(appShellConfiguration, root, viewsFolder);
44
+ autoViewsBundles = applyAutomaticViewsAndRoutes(appShellConfiguration, packageJson.name, root, viewsFolder);
45
45
  }
46
46
  if (autoMenu) {
47
47
  applyAutomaticMenu(appShellConfiguration);
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAI7C,OAAO,iBAAiB,EAAE,EACxB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OAAO,oBAAoB,MAAM,0CAA0C,CAAC;AAC5E,OAAO,eAAe,MAAM,gCAAgC,CAAC;AAC7D,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,mBAAmB,MAAM,+BAA+B,CAAC;AAChE,OAAO,kBAAkB,MAAM,uCAAuC,CAAC;AAEvE,OAAO,EAEL,sBAAsB,EACtB,kBAAkB,EAClB,cAAc,EACf,MAAM,mBAAmB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AI,IAAI,WAAW,KAAK,CAAC;wBAC1C,CAAC,qBAAqB,CAAC,OAAO,IAAI,GAAG,CAAC,GAAG,MAAM,CAAC;oBAClD,OAAO,GAAG,CAAC;gBACb,CAAC,EACD,EAA4B,CAC7B;gBACH,CAAC,CAAC,EAAE,CAAC;SACR,EACD,WAAW,CAAC,IAAI,EAChB,CAAC,GAAG,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC,EACnE,iBAAiB,IAAI,eAAe,EACpC,kBAAkB,CACnB;QAED,4CAA4C;QAC5C,eAAe,IAAI,cAAc,EAAE;QAEnC,2DAA2D;QAC3D,eAAe;YACb,eAAe,CAAC,qBAAqB,EAAE,kBAAkB,CAAC;QAE5D,uDAAuD;QACvD,oBAAoB,CAClB,IAAI,EACJ,qBAAqB,EACrB,WAAW,CAAC,IAAI,EAChB,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CACjC;QAED,gEAAgE;QAChE,mBAAmB,CACjB,qBAAqB,EACrB,IAAI,EACJ,WAAW,CAAC,IAAI,EAChB,kBAAkB,EAClB,kBAAkB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAC7C;QAED,0EAA0E;QAC1E,kBAAkB,IAAI,kBAAkB,CAAC,iBAAiB,EAAE,YAAY,CAAC;KAC1E,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport virtual from \"@rollup/plugin-virtual\";\nimport { viteStaticCopy } from \"vite-plugin-static-copy\";\n\nimport { loadEnv, PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport generateImportmap, {\n extraDependencies\n} from \"./vite-importmap-plugin.js\";\nimport processConfiguration from \"./vite-configuration-processor-plugin.js\";\nimport generateBaseTag from \"./vite-generate-base-plugin.js\";\nimport injectMetadata from \"./vite-metadata-plugin.js\";\nimport serveAppShellConfig from \"./vite-watch-config-plugin.js\";\nimport generateBashScript from \"./vite-generate-bash-script-plugin.js\";\n\nimport {\n ConfigReplacement,\n findAppShellConfigFile,\n getFinalModuleName,\n loadConfigFile\n} from \"./config-utils.js\";\nimport { getModulePath, resolveModule } from \"./nodeModule.js\";\nimport {\n applyAutomaticMenu,\n applyAutomaticViewsAndRoutes\n} from \"./automatic-utils.js\";\nimport getVirtualEntrypoints from \"./virtual-entrypoints.js\";\nimport SHARED_DEPENDENCIES from \"./shared-dependencies.js\";\n\nenum ViteBuildMode {\n PRODUCTION = \"production\",\n DEVELOPMENT = \"development\"\n}\n\nexport type ApplicationBundleType = \"app\" | \"bundle\";\n\nexport interface AppShellVitePluginOptions {\n /**\n * Project root directory. Most likely the location of the vite config file.\n *\n * @default process.cwd()\n */\n root?: string;\n /**\n * Execution mode.\n */\n mode?: string;\n\n /**\n * Type of application bundle being built. Can be \"app\" or \"bundle\".\n *\n * - \"app\": The application bundle includes both the index.html entry point and the exported modules.\n * - \"bundle\": The application bundle will not include the index.html entry point.\n *\n * @default \"app\"\n */\n type?: ApplicationBundleType;\n\n /** Array of tokens that are replaced at app-shell.config.json during the build of the solution.\n * e.g.\n * {\n * token: \"USER_NOTIFICATIONS_URL\",\n * value: \"http://localhost:8080\"\n * }\n * Tokens used at config file must be wrapped (at the beginning and at the end) by @@ sequence\n * e.g.\n * {\n * \"@hv/user-notifications-client\": \"@@USER_NOTIFICATIONS_URL@@\"\n * }\n */\n configReplacements?: ConfigReplacement[];\n\n /**\n * The folder containing Views to be shared as Shared Modules. Defaults to \"src/pages\".\n *\n * The folder path must be relative to the project root (e.g. \"src/pages\").\n */\n viewsFolder?: string;\n /**\n * If set, the plugin will search for Views at the folder specified by `viewsFolder` and will add them to the App Shell configuration as views.\n * The views' modules will be exported accordingly, and a route will be created from the folder structure.\n * Dynamic route parameters are supported by prefixing the folder name with a $ (e.g. \"src/pages/List/$id/index.tsx\" will be configured as \"/list/:id\").\n */\n autoViewsAndRoutes?: boolean;\n /**\n * If true, the plugin will try to automatically add the views to the menu.\n * Any menu defined in the App Shell config file will be overwritten.\n */\n autoMenu?: boolean;\n\n /**\n * If true, the plugin will generate the importmap with an external js file instead of inline in the html.\n * The map will be saved at the root of the application destination dir and named as \"importmap.js\".\n *\n * This option is not for general use. It is only intended to be used for easing the automated testing of the App Shell.\n *\n * @default false\n * @private\n */\n externalImportMap?: boolean;\n /**\n * If true, the plugin will inline the app-shell.config.json file in a script tag of the index html.\n *\n * This option is not for general use. Its value will be automatically managed by the App Shell build process.\n *\n * @default false, true if generateEmptyShell is true\n * @private\n */\n inlineConfig?: boolean;\n /**\n * If true, the config file is ignored, only the App Shell is built and the generated index.html will contain a placeholders\n * for importmap (if externalImportMap is false), app shell config (if inlineConfig is true) and title.\n *\n * A bash script will also be added to the dist folder to replace the placeholders with the actual content,\n * when provided with a concrete configuration.\n *\n * This option is not for general use. It is used for generating the App Shell container image.\n *\n * @default false\n * @private\n */\n generateEmptyShell?: boolean;\n /**\n * The modules to be exported by the application.\n *\n * All the modules that the application need to export should be declared here in order to have them built properly.\n *\n */\n modules?: string[];\n}\n\n/**\n * Vite plugin to support App Shell apps setup\n * @param opts Plugin options\n * @param env Environment variable\n */\nfunction appShellVitePlugin(\n opts: AppShellVitePluginOptions = {},\n env: Record<string, string> = {}\n): PluginOption {\n const {\n root = process.cwd(),\n mode = ViteBuildMode.PRODUCTION,\n externalImportMap = false,\n viewsFolder = \"src/pages\",\n autoViewsAndRoutes = false,\n autoMenu = false,\n inlineConfig = opts.generateEmptyShell ?? false,\n generateEmptyShell = false,\n modules = []\n } = opts;\n\n const globalEnv = loadEnv(mode, process.cwd(), \"\");\n\n const { type = globalEnv.CI ? \"bundle\" : \"app\" } = opts;\n\n console.info(`Vite running in mode: ${mode}`);\n console.info(`AppShell Vite plugin running with type: ${type}`);\n\n const devMode = mode === ViteBuildMode.DEVELOPMENT;\n const buildEntryPoint = type !== \"bundle\";\n\n const packageJsonRaw = fs.readFileSync(\n path.resolve(root, \"package.json\"),\n \"utf-8\"\n );\n const packageJson = JSON.parse(packageJsonRaw);\n\n const appShellConfigFile = !generateEmptyShell\n ? findAppShellConfigFile(root)\n : undefined;\n const appShellConfiguration: HvAppShellConfig = loadConfigFile(\n appShellConfigFile,\n opts,\n env\n );\n\n let autoViewsBundles: string[] = [];\n\n if (!generateEmptyShell) {\n if (autoViewsAndRoutes) {\n autoViewsBundles = applyAutomaticViewsAndRoutes(\n appShellConfiguration,\n root,\n viewsFolder\n );\n }\n\n if (autoMenu) {\n applyAutomaticMenu(appShellConfiguration);\n }\n }\n\n return [\n // copy the shared dependencies js bundles to the \"bundles\" folder\n (buildEntryPoint || devMode) &&\n viteStaticCopy({\n targets: [\n {\n src: getModulePath(\"es-module-shims\", \"dist/*\"),\n dest: \"bundles\"\n },\n // copy the ui kit icons' sprites to the \"icons\" folder\n {\n src: [\n getModulePath(\n \"@hitachivantara/uikit-react-icons\",\n \"dist/sprites/*.svg\"\n )\n ],\n dest: \"icons\"\n },\n ...(!devMode && buildEntryPoint\n ? [\n {\n src: SHARED_DEPENDENCIES.flatMap(dep => [\n resolveModule(dep.bundleSrc),\n resolveModule(`${dep.bundleSrc}.map`)\n ]),\n dest: \"bundles\"\n }\n ]\n : [])\n ]\n }),\n\n // create virtual endpoints for shell code and for shared dependencies\n virtual({\n ...getVirtualEntrypoints(inlineConfig),\n\n ...SHARED_DEPENDENCIES.reduce(\n (acc, dep) => {\n acc[`/bundles/${dep.bundle}`] = dep.virtualSrc;\n return acc;\n },\n {} as Record<string, string>\n )\n }),\n\n // generate the importmap for shared dependencies and for apps referenced in the config file\n generateImportmap(\n {\n ...SHARED_DEPENDENCIES.reduce(\n (acc, dep) => {\n acc[dep.moduleId] = `./bundles/${dep.bundle}`;\n return acc;\n },\n {} as Record<string, string>\n ),\n\n ...extraDependencies,\n\n ...Object.entries(appShellConfiguration?.apps ?? {}).reduce(\n (acc, [key, value]) => {\n acc[`${key}/`] = value;\n return acc;\n },\n {} as Record<string, string>\n ),\n\n [`${packageJson.name}/`]: appShellConfiguration.baseUrl ?? \"/\",\n\n ...(devMode\n ? modules.concat(autoViewsBundles).reduce(\n (acc, module) => {\n const finalModule = getFinalModuleName(module);\n acc[`${packageJson.name}/${finalModule}.js`] =\n (appShellConfiguration.baseUrl ?? \"/\") + module;\n return acc;\n },\n {} as Record<string, string>\n )\n : {})\n },\n packageJson.name,\n [...SHARED_DEPENDENCIES.map(dep => dep.moduleId), packageJson.name],\n externalImportMap && buildEntryPoint,\n generateEmptyShell\n ),\n\n // inject version metadata in the index.html\n buildEntryPoint && injectMetadata(),\n\n // set the base tag and replace the title in the index.html\n buildEntryPoint &&\n generateBaseTag(appShellConfiguration, generateEmptyShell),\n\n // configure the build process based on the config file\n processConfiguration(\n root,\n appShellConfiguration,\n packageJson.name,\n buildEntryPoint,\n inlineConfig,\n generateEmptyShell,\n modules.concat(autoViewsBundles)\n ),\n\n // serve the app shell config file as json and watch for changes\n serveAppShellConfig(\n appShellConfiguration,\n root,\n packageJson.name,\n appShellConfigFile,\n autoViewsAndRoutes ? viewsFolder : undefined\n ),\n\n // generate the shell script to replace the placeholders in the index.html\n generateEmptyShell && generateBashScript(externalImportMap, inlineConfig)\n ];\n}\n\nexport default appShellVitePlugin;\n"]}
1
+ {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,OAAO,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAgB,MAAM,MAAM,CAAC;AAI7C,OAAO,iBAAiB,EAAE,EACxB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AACpC,OA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Ae,kBAAkB,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport virtual from \"@rollup/plugin-virtual\";\nimport { viteStaticCopy } from \"vite-plugin-static-copy\";\n\nimport { loadEnv, PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport generateImportmap, {\n extraDependencies\n} from \"./vite-importmap-plugin.js\";\nimport processConfiguration from \"./vite-configuration-processor-plugin.js\";\nimport generateBaseTag from \"./vite-generate-base-plugin.js\";\nimport injectMetadata from \"./vite-metadata-plugin.js\";\nimport serveAppShellConfig from \"./vite-watch-config-plugin.js\";\nimport generateBashScript from \"./vite-generate-bash-script-plugin.js\";\n\nimport {\n ConfigReplacement,\n findAppShellConfigFile,\n getFinalModuleName,\n loadConfigFile\n} from \"./config-utils.js\";\nimport { getModulePath, resolveModule } from \"./nodeModule.js\";\nimport {\n applyAutomaticMenu,\n applyAutomaticViewsAndRoutes\n} from \"./automatic-utils.js\";\nimport getVirtualEntrypoints from \"./virtual-entrypoints.js\";\nimport SHARED_DEPENDENCIES from \"./shared-dependencies.js\";\n\nenum ViteBuildMode {\n PRODUCTION = \"production\",\n DEVELOPMENT = \"development\"\n}\n\nexport type ApplicationBundleType = \"app\" | \"bundle\";\n\nexport interface AppShellVitePluginOptions {\n /**\n * Project root directory. Most likely the location of the vite config file.\n *\n * @default process.cwd()\n */\n root?: string;\n /**\n * Execution mode.\n */\n mode?: string;\n\n /**\n * Type of application bundle being built. Can be \"app\" or \"bundle\".\n *\n * - \"app\": The application bundle includes both the index.html entry point and the exported modules.\n * - \"bundle\": The application bundle will not include the index.html entry point.\n *\n * @default \"app\"\n */\n type?: ApplicationBundleType;\n\n /** Array of tokens that are replaced at app-shell.config.json during the build of the solution.\n * e.g.\n * {\n * token: \"USER_NOTIFICATIONS_URL\",\n * value: \"http://localhost:8080\"\n * }\n * Tokens used at config file must be wrapped (at the beginning and at the end) by @@ sequence\n * e.g.\n * {\n * \"@hv/user-notifications-client\": \"@@USER_NOTIFICATIONS_URL@@\"\n * }\n */\n configReplacements?: ConfigReplacement[];\n\n /**\n * The folder containing Views to be shared as Shared Modules. Defaults to \"src/pages\".\n *\n * The folder path must be relative to the project root (e.g. \"src/pages\").\n */\n viewsFolder?: string;\n /**\n * If set, the plugin will search for Views at the folder specified by `viewsFolder` and will add them to the App Shell configuration as views.\n * The views' modules will be exported accordingly, and a route will be created from the folder structure.\n * Dynamic route parameters are supported by prefixing the folder name with a $ (e.g. \"src/pages/List/$id/index.tsx\" will be configured as \"/list/:id\").\n */\n autoViewsAndRoutes?: boolean;\n /**\n * If true, the plugin will try to automatically add the views to the menu.\n * Any menu defined in the App Shell config file will be overwritten.\n */\n autoMenu?: boolean;\n\n /**\n * If true, the plugin will generate the importmap with an external js file instead of inline in the html.\n * The map will be saved at the root of the application destination dir and named as \"importmap.js\".\n *\n * This option is not for general use. It is only intended to be used for easing the automated testing of the App Shell.\n *\n * @default false\n * @private\n */\n externalImportMap?: boolean;\n /**\n * If true, the plugin will inline the app-shell.config.json file in a script tag of the index html.\n *\n * This option is not for general use. Its value will be automatically managed by the App Shell build process.\n *\n * @default false, true if generateEmptyShell is true\n * @private\n */\n inlineConfig?: boolean;\n /**\n * If true, the config file is ignored, only the App Shell is built and the generated index.html will contain a placeholders\n * for importmap (if externalImportMap is false), app shell config (if inlineConfig is true) and title.\n *\n * A bash script will also be added to the dist folder to replace the placeholders with the actual content,\n * when provided with a concrete configuration.\n *\n * This option is not for general use. It is used for generating the App Shell container image.\n *\n * @default false\n * @private\n */\n generateEmptyShell?: boolean;\n /**\n * The modules to be exported by the application.\n *\n * All the modules that the application need to export should be declared here in order to have them built properly.\n *\n */\n modules?: string[];\n}\n\n/**\n * Vite plugin to support App Shell apps setup\n * @param opts Plugin options\n * @param env Environment variable\n */\nfunction appShellVitePlugin(\n opts: AppShellVitePluginOptions = {},\n env: Record<string, string> = {}\n): PluginOption {\n const {\n root = process.cwd(),\n mode = ViteBuildMode.PRODUCTION,\n externalImportMap = false,\n viewsFolder = \"src/pages\",\n autoViewsAndRoutes = false,\n autoMenu = false,\n inlineConfig = opts.generateEmptyShell ?? false,\n generateEmptyShell = false,\n modules = []\n } = opts;\n\n const globalEnv = loadEnv(mode, process.cwd(), \"\");\n\n const { type = globalEnv.CI ? \"bundle\" : \"app\" } = opts;\n\n console.info(`Vite running in mode: ${mode}`);\n console.info(`AppShell Vite plugin running with type: ${type}`);\n\n const devMode = mode === ViteBuildMode.DEVELOPMENT;\n const buildEntryPoint = type !== \"bundle\";\n\n const packageJsonRaw = fs.readFileSync(\n path.resolve(root, \"package.json\"),\n \"utf-8\"\n );\n const packageJson = JSON.parse(packageJsonRaw);\n\n const appShellConfigFile = !generateEmptyShell\n ? findAppShellConfigFile(root)\n : undefined;\n const appShellConfiguration: HvAppShellConfig = loadConfigFile(\n appShellConfigFile,\n opts,\n env\n );\n\n let autoViewsBundles: string[] = [];\n\n if (!generateEmptyShell) {\n if (autoViewsAndRoutes) {\n autoViewsBundles = applyAutomaticViewsAndRoutes(\n appShellConfiguration,\n packageJson.name,\n root,\n viewsFolder\n );\n }\n\n if (autoMenu) {\n applyAutomaticMenu(appShellConfiguration);\n }\n }\n\n return [\n // copy the shared dependencies js bundles to the \"bundles\" folder\n (buildEntryPoint || devMode) &&\n viteStaticCopy({\n targets: [\n {\n src: getModulePath(\"es-module-shims\", \"dist/*\"),\n dest: \"bundles\"\n },\n // copy the ui kit icons' sprites to the \"icons\" folder\n {\n src: [\n getModulePath(\n \"@hitachivantara/uikit-react-icons\",\n \"dist/sprites/*.svg\"\n )\n ],\n dest: \"icons\"\n },\n ...(!devMode && buildEntryPoint\n ? [\n {\n src: SHARED_DEPENDENCIES.flatMap(dep => [\n resolveModule(dep.bundleSrc),\n resolveModule(`${dep.bundleSrc}.map`)\n ]),\n dest: \"bundles\"\n }\n ]\n : [])\n ]\n }),\n\n // create virtual endpoints for shell code and for shared dependencies\n virtual({\n ...getVirtualEntrypoints(inlineConfig),\n\n ...SHARED_DEPENDENCIES.reduce(\n (acc, dep) => {\n acc[`/bundles/${dep.bundle}`] = dep.virtualSrc;\n return acc;\n },\n {} as Record<string, string>\n )\n }),\n\n // generate the importmap for shared dependencies and for apps referenced in the config file\n generateImportmap(\n {\n ...SHARED_DEPENDENCIES.reduce(\n (acc, dep) => {\n acc[dep.moduleId] = `./bundles/${dep.bundle}`;\n return acc;\n },\n {} as Record<string, string>\n ),\n\n ...extraDependencies,\n\n ...Object.entries(appShellConfiguration?.apps ?? {}).reduce(\n (acc, [key, value]) => {\n acc[`${key}/`] = value;\n return acc;\n },\n {} as Record<string, string>\n ),\n\n [`${packageJson.name}/`]: appShellConfiguration.baseUrl ?? \"/\",\n\n ...(devMode\n ? modules.concat(autoViewsBundles).reduce(\n (acc, module) => {\n const finalModule = getFinalModuleName(module);\n acc[`${packageJson.name}/${finalModule}.js`] =\n (appShellConfiguration.baseUrl ?? \"/\") + module;\n return acc;\n },\n {} as Record<string, string>\n )\n : {})\n },\n packageJson.name,\n [...SHARED_DEPENDENCIES.map(dep => dep.moduleId), packageJson.name],\n externalImportMap && buildEntryPoint,\n generateEmptyShell\n ),\n\n // inject version metadata in the index.html\n buildEntryPoint && injectMetadata(),\n\n // set the base tag and replace the title in the index.html\n buildEntryPoint &&\n generateBaseTag(appShellConfiguration, generateEmptyShell),\n\n // configure the build process based on the config file\n processConfiguration(\n root,\n appShellConfiguration,\n packageJson.name,\n buildEntryPoint,\n inlineConfig,\n generateEmptyShell,\n modules.concat(autoViewsBundles)\n ),\n\n // serve the app shell config file as json and watch for changes\n serveAppShellConfig(\n appShellConfiguration,\n root,\n packageJson.name,\n appShellConfigFile,\n autoViewsAndRoutes ? viewsFolder : undefined\n ),\n\n // generate the shell script to replace the placeholders in the index.html\n generateEmptyShell && generateBashScript(externalImportMap, inlineConfig)\n ];\n}\n\nexport default appShellVitePlugin;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"vite-watch-config-plugin.d.ts","sourceRoot":"","sources":["../src/vite-watch-config-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAgDzE,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,cAAc,EAAE,gBAAgB,EAChC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,oBAAoB,CAAC,EAAE,MAAM,GAC5B,YAAY,CA+Cd"}
1
+ {"version":3,"file":"vite-watch-config-plugin.d.ts","sourceRoot":"","sources":["../src/vite-watch-config-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AA2CzE,MAAM,CAAC,OAAO,UAAU,mBAAmB,CACzC,cAAc,EAAE,gBAAgB,EAChC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,oBAAoB,CAAC,EAAE,MAAM,GAC5B,YAAY,CA+Cd"}
@@ -1,6 +1,7 @@
1
1
  import path from "path";
2
2
  import { require } from "./nodeModule.js";
3
3
  import { getPublicPath, replaceSelf } from "./config-utils.js";
4
+ import { replaceReferencesToSelf } from "./vite-configuration-processor-plugin.js";
4
5
  const prepareConfigForDevMode = (config, selfAppName) => {
5
6
  const { mainPanel, header, theming, providers } = config;
6
7
  const replacedConfig = {
@@ -9,18 +10,11 @@ const prepareConfigForDevMode = (config, selfAppName) => {
9
10
  const self = `${selfAppName}/`;
10
11
  // Main panel - Views
11
12
  if (mainPanel?.views && replacedConfig.mainPanel) {
12
- replacedConfig.mainPanel.views = mainPanel.views?.map(view => {
13
- return { ...view, bundle: replaceSelf(view.bundle, self) };
14
- });
13
+ replacedConfig.mainPanel.views = replaceReferencesToSelf(mainPanel.views, selfAppName);
15
14
  }
16
15
  // Header - Actions
17
16
  if (header?.actions && replacedConfig.header) {
18
- replacedConfig.header.actions = header.actions?.map(action => {
19
- return {
20
- ...action,
21
- bundle: replaceSelf(action.bundle, self)
22
- };
23
- });
17
+ replacedConfig.header.actions = replaceReferencesToSelf(header.actions, selfAppName);
24
18
  }
25
19
  // Theming
26
20
  if (theming?.themes && replacedConfig.theming) {
@@ -30,12 +24,7 @@ const prepareConfigForDevMode = (config, selfAppName) => {
30
24
  }
31
25
  // Providers
32
26
  if (providers) {
33
- replacedConfig.providers = providers.map(provider => {
34
- return {
35
- ...provider,
36
- bundle: replaceSelf(provider.bundle, self)
37
- };
38
- });
27
+ replacedConfig.providers = replaceReferencesToSelf(providers, selfAppName);
39
28
  }
40
29
  return replacedConfig;
41
30
  };
@@ -1 +1 @@
1
- {"version":3,"file":"vite-watch-config-plugin.js","sourceRoot":"","sources":["../src/vite-watch-config-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE/D,MAAM,uBAAuB,GAAG,CAC9B,MAAwB,EACxB,WAAmB,EACnB,EAAE;IACF,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IACzD,MAAM,cAAc,GAAqB;QACvC,GAAG,MAAM;KACV,CAAC;IACF,MAAM,IAAI,GAAG,GAAG,WAAW,GAAG,CAAC;IAC/B,qBAAqB;IACrB,IAAI,SAAS,EAAE,KAAK,IAAI,cAAc,CAAC,SAAS,EAAE,CAAC;QACjD,cAAc,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;YAC3D,OAAO,EAAE,GAAG,IAAI,EA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,KAAK,EAAE,cAAc,CAAC,CAAC;YAC3C,CAAC;YAED,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;YACjD,MAAM,CAAC,WAAW,CAAC,GAAG,CACpB,GAAG,UAAU,uBAAuB,EACpC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;gBACjB,GAAG,CAAC,GAAG,CACL,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,CACrE,CAAC;YACJ,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import path from \"path\";\n\nimport type { PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport { require } from \"./nodeModule.js\";\nimport { getPublicPath, replaceSelf } from \"./config-utils.js\";\n\nconst prepareConfigForDevMode = (\n config: HvAppShellConfig,\n selfAppName: string\n) => {\n const { mainPanel, header, theming, providers } = config;\n const replacedConfig: HvAppShellConfig = {\n ...config\n };\n const self = `${selfAppName}/`;\n // Main panel - Views\n if (mainPanel?.views && replacedConfig.mainPanel) {\n replacedConfig.mainPanel.views = mainPanel.views?.map(view => {\n return { ...view, bundle: replaceSelf(view.bundle, self) };\n });\n }\n // Header - Actions\n if (header?.actions && replacedConfig.header) {\n replacedConfig.header.actions = header.actions?.map(action => {\n return {\n ...action,\n bundle: replaceSelf(action.bundle, self)\n };\n });\n }\n // Theming\n if (theming?.themes && replacedConfig.theming) {\n replacedConfig.theming.themes = theming.themes?.map(theme => {\n return replaceSelf(theme, self);\n });\n }\n // Providers\n if (providers) {\n replacedConfig.providers = providers.map(provider => {\n return {\n ...provider,\n bundle: replaceSelf(provider.bundle, self)\n };\n });\n }\n\n return replacedConfig;\n};\n\nexport default function serveAppShellConfig(\n appShellConfig: HvAppShellConfig,\n root: string,\n selfAppName: string,\n appShellConfigFile?: string,\n automaticViewsFolder?: string\n): PluginOption {\n return {\n name: \"vite-plugin-watch-app-shell-config\",\n apply: \"serve\",\n\n configureServer(server) {\n const restartServer = (file: string) => {\n if (appShellConfigFile != null && file.endsWith(appShellConfigFile)) {\n console.info(\"App Shell configuration file changed. Reloading...\");\n delete require.cache[require.resolve(appShellConfigFile)];\n server\n .restart()\n .catch(e => console.error(`Restart failed with: ${e}`));\n }\n };\n\n const restartServer2 = (file: string) => {\n if (automaticViewsFolder != null && /\\/index\\.[tj]sx?$/.exec(file)) {\n console.info(\"Automatic views folder changed. Reloading...\");\n server\n .restart()\n .catch(e => console.error(`Restart failed with: ${e}`));\n }\n };\n\n if (appShellConfigFile != null) {\n server.watcher.add(appShellConfigFile);\n server.watcher.on(\"change\", restartServer);\n }\n\n if (automaticViewsFolder != null) {\n server.watcher.add(path.resolve(root, automaticViewsFolder));\n server.watcher.on(\"unlink\", restartServer2);\n server.watcher.on(\"add\", restartServer2);\n }\n\n const publicPath = getPublicPath(appShellConfig);\n server.middlewares.use(\n `${publicPath}app-shell.config.json`,\n async (req, res) => {\n res.end(\n JSON.stringify(prepareConfigForDevMode(appShellConfig, selfAppName))\n );\n }\n );\n }\n };\n}\n"]}
1
+ {"version":3,"file":"vite-watch-config-plugin.js","sourceRoot":"","sources":["../src/vite-watch-config-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AAEnF,MAAM,uBAAuB,GAAG,CAC9B,MAAwB,EACxB,WAAmB,EACnB,EAAE;IACF,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IACzD,MAAM,cAAc,GAAqB;QACvC,GAAG,MAAM;KACV,CAAC;IACF,MAAM,IAAI,GAAG,GAAG,WAA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K,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;gBACjB,GAAG,CAAC,GAAG,CACL,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,CACrE,CAAC;YACJ,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import path from \"path\";\n\nimport type { PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport { require } from \"./nodeModule.js\";\nimport { getPublicPath, replaceSelf } from \"./config-utils.js\";\nimport { replaceReferencesToSelf } from \"./vite-configuration-processor-plugin.js\";\n\nconst prepareConfigForDevMode = (\n config: HvAppShellConfig,\n selfAppName: string\n) => {\n const { mainPanel, header, theming, providers } = config;\n const replacedConfig: HvAppShellConfig = {\n ...config\n };\n const self = `${selfAppName}/`;\n // Main panel - Views\n if (mainPanel?.views && replacedConfig.mainPanel) {\n replacedConfig.mainPanel.views = replaceReferencesToSelf(\n mainPanel.views,\n selfAppName\n );\n }\n // Header - Actions\n if (header?.actions && replacedConfig.header) {\n replacedConfig.header.actions = replaceReferencesToSelf(\n header.actions,\n selfAppName\n );\n }\n // Theming\n if (theming?.themes && replacedConfig.theming) {\n replacedConfig.theming.themes = theming.themes?.map(theme => {\n return replaceSelf(theme, self);\n });\n }\n // Providers\n if (providers) {\n replacedConfig.providers = replaceReferencesToSelf(providers, selfAppName);\n }\n\n return replacedConfig;\n};\n\nexport default function serveAppShellConfig(\n appShellConfig: HvAppShellConfig,\n root: string,\n selfAppName: string,\n appShellConfigFile?: string,\n automaticViewsFolder?: string\n): PluginOption {\n return {\n name: \"vite-plugin-watch-app-shell-config\",\n apply: \"serve\",\n\n configureServer(server) {\n const restartServer = (file: string) => {\n if (appShellConfigFile != null && file.endsWith(appShellConfigFile)) {\n console.info(\"App Shell configuration file changed. Reloading...\");\n delete require.cache[require.resolve(appShellConfigFile)];\n server\n .restart()\n .catch(e => console.error(`Restart failed with: ${e}`));\n }\n };\n\n const restartServer2 = (file: string) => {\n if (automaticViewsFolder != null && /\\/index\\.[tj]sx?$/.exec(file)) {\n console.info(\"Automatic views folder changed. Reloading...\");\n server\n .restart()\n .catch(e => console.error(`Restart failed with: ${e}`));\n }\n };\n\n if (appShellConfigFile != null) {\n server.watcher.add(appShellConfigFile);\n server.watcher.on(\"change\", restartServer);\n }\n\n if (automaticViewsFolder != null) {\n server.watcher.add(path.resolve(root, automaticViewsFolder));\n server.watcher.on(\"unlink\", restartServer2);\n server.watcher.on(\"add\", restartServer2);\n }\n\n const publicPath = getPublicPath(appShellConfig);\n server.middlewares.use(\n `${publicPath}app-shell.config.json`,\n async (req, res) => {\n res.end(\n JSON.stringify(prepareConfigForDevMode(appShellConfig, selfAppName))\n );\n }\n );\n }\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hitachivantara/app-shell-vite-plugin",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "description": "AppShell Vite Plugin",
5
5
  "author": "Hitachi Vantara - Boba Fett Team",
6
6
  "license": "Apache-2.0",
@@ -38,8 +38,8 @@
38
38
  "dependencies": {
39
39
  "@emotion/cache": "^11.11.0",
40
40
  "@emotion/react": "^11.11.1",
41
- "@hitachivantara/app-shell-shared": "1.0.0",
42
- "@hitachivantara/app-shell-ui": "1.0.2",
41
+ "@hitachivantara/app-shell-shared": "1.1.0",
42
+ "@hitachivantara/app-shell-ui": "1.1.0",
43
43
  "@hitachivantara/uikit-react-icons": "^5.6.0",
44
44
  "@hitachivantara/uikit-react-shared": "^5.1.0",
45
45
  "@rollup/plugin-commonjs": "^25.0.7",
@@ -64,5 +64,5 @@
64
64
  "peerDependencies": {
65
65
  "vite": "^4.1.4 || ^5.0.4"
66
66
  },
67
- "gitHead": "a8d9e67b3b95129336d749475c666dc215bbbe42"
67
+ "gitHead": "6140d2027f6c2d215f1d3c015a9adafd0cf00de6"
68
68
  }