@hitachivantara/app-shell-vite-plugin 1.0.0 → 1.0.2
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 +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;
|
|
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;AA6B1C;;;;;;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,CA0CF;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"}
|
package/dist/automatic-utils.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
+
function createLabel(str) {
|
|
4
|
+
const noExtension = str.replace(/\.[^/.]+$/, "");
|
|
5
|
+
const splitByCapital = noExtension.split(/(?=[A-Z])/).join(" ");
|
|
6
|
+
return splitByCapital.charAt(0).toUpperCase() + splitByCapital.slice(1);
|
|
7
|
+
}
|
|
3
8
|
/**
|
|
4
9
|
* Find all the index.tsx or index.jsx files existent at the provided path (including all the subdirectories)
|
|
5
10
|
* @param dir the path to search for the index.tsx or index.jsx files
|
|
@@ -116,18 +121,18 @@ export function applyAutomaticMenu(config) {
|
|
|
116
121
|
return;
|
|
117
122
|
}
|
|
118
123
|
for (let j = srcFolderParts; j < bundleParts.length - 1; j += 1) {
|
|
119
|
-
const
|
|
120
|
-
let submenu = currentMenu.find(item => item.label ===
|
|
124
|
+
const label = createLabel(bundleParts[j]);
|
|
125
|
+
let submenu = currentMenu.find(item => item.label === label);
|
|
121
126
|
if (submenu == null) {
|
|
122
127
|
submenu = {
|
|
123
|
-
label
|
|
128
|
+
label,
|
|
124
129
|
submenus: []
|
|
125
130
|
};
|
|
126
131
|
currentMenu.push(submenu);
|
|
127
132
|
}
|
|
128
133
|
currentMenu = submenu.submenus;
|
|
129
134
|
}
|
|
130
|
-
const label = bundleParts[bundleParts.length - 1];
|
|
135
|
+
const label = createLabel(bundleParts[bundleParts.length - 1]);
|
|
131
136
|
let menuitem = currentMenu.find(item => item.label === label);
|
|
132
137
|
if (menuitem == null) {
|
|
133
138
|
menuitem = {
|
|
@@ -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;;;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,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEnC,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YACvB,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1C,CAAC;aA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,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\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 let 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 // module to be added when building the application\n const module = bundle;\n\n // src needs to be replaced either with '@self' (that when built is replaced by the app id) or \"immediately\" with\n // the app id.\n bundle = bundle.replace(/^(\\/?)src\\//, \"@self/\");\n bundle = bundle.replaceAll(\"$\", \"_\");\n bundle += \".js\";\n\n const viewConfig = { bundle, route };\n routes.push({ viewConfig, module });\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 part = bundleParts[j];\n let submenu = currentMenu.find(item => item.label === part);\n if (submenu == null) {\n submenu = {\n label: part,\n submenus: []\n };\n currentMenu.push(submenu);\n }\n currentMenu = submenu.submenus!;\n }\n\n const label = 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,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,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IAAI,CAAC,EAAE,CAAC;YAChE,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,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\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 let 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 // module to be added when building the application\n const module = bundle;\n\n // src needs to be replaced either with '@self' (that when built is replaced by the app id) or \"immediately\" with\n // the app id.\n bundle = bundle.replace(/^(\\/?)src\\//, \"@self/\");\n bundle = bundle.replaceAll(\"$\", \"_\");\n bundle += \".js\";\n\n const viewConfig = { bundle, route };\n routes.push({ viewConfig, module });\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,6 +1,6 @@
|
|
|
1
1
|
import { expect } from "vitest";
|
|
2
2
|
import mock from "mock-fs";
|
|
3
|
-
import { mapFolderIndexFilesToRoutes } from "../automatic-utils";
|
|
3
|
+
import { applyAutomaticMenu, mapFolderIndexFilesToRoutes } from "../automatic-utils";
|
|
4
4
|
describe("test automatic utils", () => {
|
|
5
5
|
describe("test `mapFolderIndexFilesToRoutes` method", () => {
|
|
6
6
|
afterEach(() => {
|
|
@@ -105,5 +105,130 @@ describe("test automatic utils", () => {
|
|
|
105
105
|
]);
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
|
+
describe("test `applyAutomaticMenu` method", () => {
|
|
109
|
+
it("should create correct menu labels for simple routes", () => {
|
|
110
|
+
const config = {
|
|
111
|
+
mainPanel: {
|
|
112
|
+
views: [
|
|
113
|
+
{ bundle: "@self/pages/Page1.js", route: "/page1" },
|
|
114
|
+
{ bundle: "@self/pages/Page2.js", route: "/page2" },
|
|
115
|
+
{ bundle: "@self/pages/helloToWorld.js", route: "/hello" }
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
applyAutomaticMenu(config);
|
|
120
|
+
const expectedMenu = [
|
|
121
|
+
{ label: "Page1", target: "/page1" },
|
|
122
|
+
{ label: "Page2", target: "/page2" },
|
|
123
|
+
{ label: "Hello To World", target: "/hello" }
|
|
124
|
+
];
|
|
125
|
+
expect(config.menu).toEqual(expectedMenu);
|
|
126
|
+
});
|
|
127
|
+
it("should handle nested routes correctly", () => {
|
|
128
|
+
const config = {
|
|
129
|
+
mainPanel: {
|
|
130
|
+
views: [
|
|
131
|
+
{ bundle: "@self/pages/Section/Page1.js", route: "/section/page1" },
|
|
132
|
+
{ bundle: "@self/pages/Section/Page2.js", route: "/section/page2" },
|
|
133
|
+
{
|
|
134
|
+
bundle: "@self/pages/Planets/helloToEarth.js",
|
|
135
|
+
route: "/planets/earth"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
bundle: "@self/pages/Planets/HelloToMars.js",
|
|
139
|
+
route: "/planets/mars"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
bundle: "@self/pages/someOtherFolder/ToImportantStuff.js",
|
|
143
|
+
route: "/other/important"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
bundle: "@self/pages/SomeOtherFolder/thisIsOnTheSameMenu.js",
|
|
147
|
+
route: "/other/same"
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
applyAutomaticMenu(config);
|
|
153
|
+
const expectedMenu = [
|
|
154
|
+
{
|
|
155
|
+
label: "Section",
|
|
156
|
+
submenus: [
|
|
157
|
+
{ label: "Page1", target: "/section/page1" },
|
|
158
|
+
{ label: "Page2", target: "/section/page2" }
|
|
159
|
+
]
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
label: "Planets",
|
|
163
|
+
submenus: [
|
|
164
|
+
{ label: "Hello To Earth", target: "/planets/earth" },
|
|
165
|
+
{ label: "Hello To Mars", target: "/planets/mars" }
|
|
166
|
+
]
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
label: "Some Other Folder",
|
|
170
|
+
submenus: [
|
|
171
|
+
{ label: "To Important Stuff", target: "/other/important" },
|
|
172
|
+
{ label: "This Is On The Same Menu", target: "/other/same" }
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
];
|
|
176
|
+
expect(config.menu).toEqual(expectedMenu);
|
|
177
|
+
});
|
|
178
|
+
it("should skip dynamic routes", () => {
|
|
179
|
+
const config = {
|
|
180
|
+
mainPanel: {
|
|
181
|
+
views: [
|
|
182
|
+
{ bundle: "@self/pages/Page1.js", route: "/page1" },
|
|
183
|
+
{ bundle: "@self/pages/Page2/:id.js", route: "/page2/:id" },
|
|
184
|
+
{ bundle: "@self/pages/Page3.js", route: "/page3" }
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
applyAutomaticMenu(config);
|
|
189
|
+
const expectedMenu = [
|
|
190
|
+
{ label: "Page1", target: "/page1" },
|
|
191
|
+
// Note: Page2 is skipped because it's a dynamic route
|
|
192
|
+
{ label: "Page3", target: "/page3" }
|
|
193
|
+
];
|
|
194
|
+
expect(config.menu).toEqual(expectedMenu);
|
|
195
|
+
});
|
|
196
|
+
it("should handle special characters and capitalization in routes", () => {
|
|
197
|
+
const config = {
|
|
198
|
+
mainPanel: {
|
|
199
|
+
views: [
|
|
200
|
+
{
|
|
201
|
+
bundle: "@self/pages/lowerUpper/Look🙄ingAbóve/SomeSpÉcialPage.js",
|
|
202
|
+
route: "/l1/l2/someSpecialPage"
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
applyAutomaticMenu(config);
|
|
208
|
+
const expectedMenu = [
|
|
209
|
+
{
|
|
210
|
+
label: "Lower Upper",
|
|
211
|
+
submenus: [
|
|
212
|
+
{
|
|
213
|
+
label: "Look🙄ing Abóve",
|
|
214
|
+
submenus: [
|
|
215
|
+
{ label: "Some SpÉcial Page", target: "/l1/l2/someSpecialPage" }
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
];
|
|
221
|
+
expect(config.menu).toEqual(expectedMenu);
|
|
222
|
+
});
|
|
223
|
+
it("should return undefined for empty views", () => {
|
|
224
|
+
const config = {
|
|
225
|
+
mainPanel: {
|
|
226
|
+
views: []
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
applyAutomaticMenu(config);
|
|
230
|
+
expect(config.menu).toBe(undefined);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
108
233
|
});
|
|
109
234
|
//# 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;AAC3B,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,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,CAA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1D,CAAC,OAAO,CAAC;gBACR;oBACE,UAAU,EAAE;wBACV,MAAM,EAAE,sBAAsB;wBAC9B,KAAK,EAAE,QAAQ;qBAChB;oBACD,MAAM,EAAE,iBAAiB;iBAC1B;gBACD;oBACE,UAAU,EAAE;wBACV,MAAM,EAAE,sBAAsB;wBAC9B,KAAK,EAAE,QAAQ;qBAChB;oBACD,MAAM,EAAE,iBAAiB;iBAC1B;gBACD;oBACE,UAAU,EAAE;wBACV,MAAM,EAAE,gDAAgD;wBACxD,KAAK,EAAE,kCAAkC;qBAC1C;oBACD,MAAM,EAAE,2CAA2C;iBACpD;gBACD;oBACE,UAAU,EAAE;wBACV,MAAM,EAAE,kCAAkC;wBAC1C,KAAK,EAAE,oBAAoB;qBAC5B;oBACD,MAAM,EAAE,6BAA6B;iBACtC;gBACD;oBACE,UAAU,EAAE;wBACV,MAAM,EAAE,0BAA0B;wBAClC,KAAK,EAAE,YAAY;qBACpB;oBACD,MAAM,EAAE,qBAAqB;iBAC9B;aACF,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expect } from \"vitest\";\nimport mock from \"mock-fs\";\nimport { mapFolderIndexFilesToRoutes } 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"]}
|
|
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;YAEhC,IAAI,CAAC;gBACH,2BAA2B,EAAE,EAAE;gBAC/B,iCAAiC,EAAE;oBACjC,gBAAgB,EAAE,eAAe;iB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,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hitachivantara/app-shell-vite-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "AppShell Vite Plugin",
|
|
5
5
|
"author": "Hitachi Vantara - Boba Fett Team",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@emotion/cache": "^11.11.0",
|
|
40
40
|
"@emotion/react": "^11.11.1",
|
|
41
41
|
"@hitachivantara/app-shell-shared": "1.0.0",
|
|
42
|
-
"@hitachivantara/app-shell-ui": "1.0.
|
|
42
|
+
"@hitachivantara/app-shell-ui": "1.0.1",
|
|
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": "
|
|
67
|
+
"gitHead": "dd45ab80c936795769735b2c4577164a262ec183"
|
|
68
68
|
}
|