@hitachivantara/app-shell-vite-plugin 0.12.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -15
- package/dist/automatic-utils.d.ts +6 -0
- package/dist/automatic-utils.d.ts.map +1 -0
- package/dist/automatic-utils.js +105 -0
- package/dist/automatic-utils.js.map +1 -0
- package/dist/config-utils.d.ts +34 -0
- package/dist/config-utils.d.ts.map +1 -0
- package/dist/config-utils.js +126 -0
- package/dist/config-utils.js.map +1 -0
- package/dist/esm-externals/react-dom.production.min.js +1 -1
- package/dist/esm-externals/react-dom.production.min.js.map +1 -1
- package/dist/esm-externals/react.production.min.js +1 -1
- package/dist/esm-externals/react.production.min.js.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/shared-dependencies.d.ts +8 -0
- package/dist/shared-dependencies.d.ts.map +1 -0
- package/dist/shared-dependencies.js +87 -0
- package/dist/shared-dependencies.js.map +1 -0
- package/dist/virtual-entrypoints.d.ts +5 -0
- package/dist/virtual-entrypoints.d.ts.map +1 -0
- package/dist/virtual-entrypoints.js +37 -0
- package/dist/virtual-entrypoints.js.map +1 -0
- package/dist/vite-configuration-processor-plugin.d.ts +14 -0
- package/dist/vite-configuration-processor-plugin.d.ts.map +1 -0
- package/dist/vite-configuration-processor-plugin.js +161 -0
- package/dist/vite-configuration-processor-plugin.js.map +1 -0
- package/dist/vite-generate-base-plugin.d.ts +8 -0
- package/dist/vite-generate-base-plugin.d.ts.map +1 -0
- package/dist/vite-generate-base-plugin.js +32 -0
- package/dist/vite-generate-base-plugin.js.map +1 -0
- package/dist/vite-generate-bash-script-plugin.d.ts +3 -0
- package/dist/vite-generate-bash-script-plugin.d.ts.map +1 -0
- package/dist/vite-generate-bash-script-plugin.js +122 -0
- package/dist/vite-generate-bash-script-plugin.js.map +1 -0
- package/dist/vite-importmap-plugin.d.ts +2 -2
- package/dist/vite-importmap-plugin.d.ts.map +1 -1
- package/dist/vite-importmap-plugin.js +15 -4
- package/dist/vite-importmap-plugin.js.map +1 -1
- package/dist/vite-metadata-plugin.d.ts.map +1 -1
- package/dist/vite-metadata-plugin.js.map +1 -1
- package/dist/vite-plugin.d.ts +36 -13
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +49 -525
- package/dist/vite-plugin.js.map +1 -1
- package/dist/vite-watch-config-plugin.d.ts +4 -0
- package/dist/vite-watch-config-plugin.d.ts.map +1 -0
- package/dist/vite-watch-config-plugin.js +41 -0
- package/dist/vite-watch-config-plugin.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,7 +16,6 @@ It performs the following actions:
|
|
|
16
16
|
exported and consumed by others
|
|
17
17
|
- create `importmap` and inject it into `index.html`
|
|
18
18
|
- create <base href="..."> tag and inject it into `index.html`
|
|
19
|
-
- creates APP_BASE_PATH variable that can be used in app code.
|
|
20
19
|
|
|
21
20
|
## How to use
|
|
22
21
|
|
|
@@ -64,17 +63,3 @@ Empty Configuration Validity: With these automatic features in place, the config
|
|
|
64
63
|
|
|
65
64
|
The <base href="..."> tag is automatically injected at index.html file during the build process. The value of tag is the same as for the app base path. More information related to the way app base path is obtained can be checked [here](../../../docs/app-shell-utilities.md#usehvappshellbasepath).
|
|
66
65
|
|
|
67
|
-
## APP_BASE_PATH variable
|
|
68
|
-
|
|
69
|
-
Vite supports the creation at configuration/build time of env variables that, if needed, can be used at apps.
|
|
70
|
-
|
|
71
|
-
More information about vite env variables can be checked [here](https://vitejs.dev/guide/env-and-mode.html).
|
|
72
|
-
|
|
73
|
-
Vite plugin creates the following env properties:
|
|
74
|
-
|
|
75
|
-
| Property | Description | Notes |
|
|
76
|
-
| :------------ | :------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
77
|
-
| APP_BASE_PATH | App base path value | More information about the base path value can be checked [here](https://vitejs.dev/guide/env-and-mode.html). Usage example: [here](../../samples/internal-route-ice-cream-app/src/App.tsx) |
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
_Typescript projects shall use [env.d.ts](../../samples/internal-route-ice-cream-app/src/env.d.ts) for type's definition._
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HvAppShellConfig, HvAppShellViewsConfig } from "@hitachivantara/app-shell-shared";
|
|
2
|
+
export declare function findIndexFiles(dir: string): string[];
|
|
3
|
+
export declare function mapIndexFilesToRoutes(files: string[], folder: string): HvAppShellViewsConfig[];
|
|
4
|
+
export declare function applyAutomaticViewsAndRoutes(config: HvAppShellConfig, root: string, viewsFolder: string): void;
|
|
5
|
+
export declare function applyAutomaticMenu(config: HvAppShellConfig): void;
|
|
6
|
+
//# sourceMappingURL=automatic-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"automatic-utils.d.ts","sourceRoot":"","sources":["../src/automatic-utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAI1C,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAepD;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,GACb,qBAAqB,EAAE,CAiBzB;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,gBAAgB,EACxB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,QAqCpB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,gBAAgB,QA+C1D"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { getMainApp } from "./config-utils.js";
|
|
4
|
+
export function findIndexFiles(dir) {
|
|
5
|
+
const files = [];
|
|
6
|
+
fs.readdirSync(dir).forEach(file => {
|
|
7
|
+
const filePath = path.join(dir, file);
|
|
8
|
+
const stat = fs.statSync(filePath);
|
|
9
|
+
if (stat.isDirectory()) {
|
|
10
|
+
files.push(...findIndexFiles(filePath));
|
|
11
|
+
}
|
|
12
|
+
else if (file.match(/^index\.[tj]sx?$/)) {
|
|
13
|
+
files.push(filePath);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return files;
|
|
17
|
+
}
|
|
18
|
+
export function mapIndexFilesToRoutes(files, folder) {
|
|
19
|
+
const routes = [];
|
|
20
|
+
files.forEach(filePath => {
|
|
21
|
+
const bundle = filePath.substring(filePath.lastIndexOf(`/${folder.replace(/^\/|\/$/g, "")}/`) + 1, filePath.lastIndexOf("/"));
|
|
22
|
+
const route = bundle
|
|
23
|
+
.replace(new RegExp(`^${folder}`), "")
|
|
24
|
+
.replace(/index\.[t|j]sx?$/, "")
|
|
25
|
+
.replaceAll(/\$/g, ":")
|
|
26
|
+
.toLowerCase();
|
|
27
|
+
routes.push({ bundle, route });
|
|
28
|
+
});
|
|
29
|
+
return routes;
|
|
30
|
+
}
|
|
31
|
+
export function applyAutomaticViewsAndRoutes(config, root, viewsFolder) {
|
|
32
|
+
const appShellConfiguration = config;
|
|
33
|
+
let selfApp = getMainApp(appShellConfiguration);
|
|
34
|
+
const folder = path.resolve(root, viewsFolder);
|
|
35
|
+
if (fs.existsSync(folder)) {
|
|
36
|
+
const views = mapIndexFilesToRoutes(findIndexFiles(folder), viewsFolder);
|
|
37
|
+
if (views.length > 0) {
|
|
38
|
+
if (selfApp == null) {
|
|
39
|
+
selfApp = {
|
|
40
|
+
id: "@self",
|
|
41
|
+
baseUrl: "/"
|
|
42
|
+
};
|
|
43
|
+
if (appShellConfiguration.apps == null) {
|
|
44
|
+
appShellConfiguration.apps = [];
|
|
45
|
+
}
|
|
46
|
+
appShellConfiguration.apps.push(selfApp);
|
|
47
|
+
}
|
|
48
|
+
if (selfApp.views != null && selfApp.views.length > 0) {
|
|
49
|
+
const nowOverlappingViews = views.filter(view => {
|
|
50
|
+
const exists = selfApp.views.some(existingView => existingView.bundle === view.bundle ||
|
|
51
|
+
existingView.route === view.route);
|
|
52
|
+
return !exists;
|
|
53
|
+
});
|
|
54
|
+
selfApp.views.push(...nowOverlappingViews);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
selfApp.views = views;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function applyAutomaticMenu(config) {
|
|
63
|
+
const appShellConfiguration = config;
|
|
64
|
+
const selfApp = getMainApp(appShellConfiguration);
|
|
65
|
+
if (selfApp?.views != null && selfApp.views.length > 0) {
|
|
66
|
+
const menu = [];
|
|
67
|
+
for (let i = 0; i !== selfApp.views.length; i += 1) {
|
|
68
|
+
const view = selfApp.views[i];
|
|
69
|
+
// skip dynamic routes (e.g. /list/:id))
|
|
70
|
+
if (view.route.indexOf(":") === -1) {
|
|
71
|
+
let currentMenu = menu;
|
|
72
|
+
const bundleParts = view.bundle.split("/");
|
|
73
|
+
const numberOfParts = view.route
|
|
74
|
+
.split("/")
|
|
75
|
+
.filter(part => part !== "").length;
|
|
76
|
+
const srcFolderParts = bundleParts.length - numberOfParts;
|
|
77
|
+
if (bundleParts.length > srcFolderParts) {
|
|
78
|
+
for (let j = srcFolderParts; j !== bundleParts.length - 1; j += 1) {
|
|
79
|
+
const part = bundleParts[j];
|
|
80
|
+
let submenu = currentMenu.find(item => item.label === part);
|
|
81
|
+
if (submenu == null) {
|
|
82
|
+
submenu = {
|
|
83
|
+
label: part,
|
|
84
|
+
submenus: []
|
|
85
|
+
};
|
|
86
|
+
currentMenu.push(submenu);
|
|
87
|
+
}
|
|
88
|
+
currentMenu = submenu.submenus;
|
|
89
|
+
}
|
|
90
|
+
const label = bundleParts[bundleParts.length - 1];
|
|
91
|
+
let menuitem = currentMenu.find(item => item.label === label);
|
|
92
|
+
if (menuitem == null) {
|
|
93
|
+
menuitem = {
|
|
94
|
+
label
|
|
95
|
+
};
|
|
96
|
+
currentMenu.push(menuitem);
|
|
97
|
+
}
|
|
98
|
+
menuitem.target = view.route;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
appShellConfiguration.menu = menu;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=automatic-utils.js.map
|
|
@@ -0,0 +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;AAOxB,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,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;YACtB,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;SACzC;aAAM,IAAI,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE;YACzC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SACtB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,KAAe,EACf,MAAc;IAEd,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QACvB,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAC/B,QAAQ,CAAC,WAAW,CAAC,I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Content":["import fs from \"fs\";\nimport path from \"path\";\n\nimport type {\n HvAppShellConfig,\n HvAppShellViewsConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport { getMainApp } from \"./config-utils.js\";\n\nexport function 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 (file.match(/^index\\.[tj]sx?$/)) {\n files.push(filePath);\n }\n });\n\n return files;\n}\n\nexport function mapIndexFilesToRoutes(\n files: string[],\n folder: string\n): HvAppShellViewsConfig[] {\n const routes: HvAppShellViewsConfig[] = [];\n\n files.forEach(filePath => {\n const bundle = filePath.substring(\n filePath.lastIndexOf(`/${folder.replace(/^\\/|\\/$/g, \"\")}/`) + 1,\n filePath.lastIndexOf(\"/\")\n );\n const route = bundle\n .replace(new RegExp(`^${folder}`), \"\")\n .replace(/index\\.[t|j]sx?$/, \"\")\n .replaceAll(/\\$/g, \":\")\n .toLowerCase();\n routes.push({ bundle, route });\n });\n\n return routes;\n}\n\nexport function applyAutomaticViewsAndRoutes(\n config: HvAppShellConfig,\n root: string,\n viewsFolder: string\n) {\n const appShellConfiguration = config;\n let selfApp = getMainApp(appShellConfiguration);\n\n const folder = path.resolve(root, viewsFolder);\n if (fs.existsSync(folder)) {\n const views = mapIndexFilesToRoutes(findIndexFiles(folder), viewsFolder);\n\n if (views.length > 0) {\n if (selfApp == null) {\n selfApp = {\n id: \"@self\",\n baseUrl: \"/\"\n };\n if (appShellConfiguration.apps == null) {\n appShellConfiguration.apps = [];\n }\n appShellConfiguration.apps.push(selfApp);\n }\n\n if (selfApp.views != null && selfApp.views.length > 0) {\n const nowOverlappingViews = views.filter(view => {\n const exists = selfApp!.views!.some(\n existingView =>\n existingView.bundle === view.bundle ||\n existingView.route === view.route\n );\n return !exists;\n });\n\n selfApp.views.push(...nowOverlappingViews);\n } else {\n selfApp.views = views;\n }\n }\n }\n}\n\nexport function applyAutomaticMenu(config: HvAppShellConfig) {\n const appShellConfiguration = config;\n const selfApp = getMainApp(appShellConfiguration);\n\n if (selfApp?.views != null && selfApp.views.length > 0) {\n const menu: HvAppShellConfig[\"menu\"] = [];\n\n for (let i = 0; i !== selfApp.views.length; i += 1) {\n const view = selfApp.views[i];\n\n // skip dynamic routes (e.g. /list/:id))\n if (view.route.indexOf(\":\") === -1) {\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 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 }\n\n appShellConfiguration.menu = menu;\n }\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { HvAppShellAppsConfig, HvAppShellConfig } from "@hitachivantara/app-shell-shared";
|
|
2
|
+
import type { AppShellVitePluginOptions } from "./vite-plugin.js";
|
|
3
|
+
export interface ConfigReplacement {
|
|
4
|
+
token: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
export type AppShellConfigFunction = (pluginOptions: AppShellVitePluginOptions, env: Record<string, string>) => HvAppShellConfig;
|
|
8
|
+
export declare const DEFAULT_CONFIG_FILES: string[];
|
|
9
|
+
export declare function findAppShellConfigFile(root: string): string | undefined;
|
|
10
|
+
export declare function loadConfigFile(appShellConfigFile: string | undefined, opts: AppShellVitePluginOptions, env?: Record<string, string>): HvAppShellConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Return the main app (identified by @self)
|
|
13
|
+
* @param appShellConfig The App shell configuration
|
|
14
|
+
*/
|
|
15
|
+
export declare const getMainApp: (appShellConfig: HvAppShellConfig) => HvAppShellAppsConfig | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Return the public path to be use by vite to launch the application.
|
|
18
|
+
* Value is obtained by returning the baseUrl value of the main app {@link #getMainApp}
|
|
19
|
+
* @param appShellConfig The App shell configuration
|
|
20
|
+
*/
|
|
21
|
+
export declare const getPublicPath: (appShellConfig: HvAppShellConfig) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the modules to be created by the build of the app.
|
|
24
|
+
* The list of modules is defined by the app-shell-config.json file routes ( limited to the @self app)
|
|
25
|
+
* The bundles will be created following the original directories structure ( having the src folder path removed)
|
|
26
|
+
*
|
|
27
|
+
* @param root Project root directory.
|
|
28
|
+
* @param appShellConfig The App Shell configuration.
|
|
29
|
+
* @param selfAppName The name of the application bundle being built.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getAppModules(root: string, appShellConfig: HvAppShellConfig, selfAppName: string): {
|
|
32
|
+
[key: string]: string;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=config-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-utils.d.ts","sourceRoot":"","sources":["../src/config-utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAalE,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,sBAAsB,GAAG,CACnC,aAAa,EAAE,yBAAyB,EACxC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACxB,gBAAgB,CAAC;AAEtB,eAAO,MAAM,oBAAoB,UAIhC,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAUvE;AAED,wBAAgB,cAAc,CAC5B,kBAAkB,EAAE,MAAM,GAAG,SAAS,EACtC,IAAI,EAAE,yBAAyB,EAC/B,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAC/B,gBAAgB,CAgClB;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,mBACL,gBAAgB,KAC/B,oBAAoB,GAAG,SAEzB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,mBAAoB,gBAAgB,KAAG,MAWhE,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,gBAAgB,EAChC,WAAW,EAAE,MAAM;;EA4DpB"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { register, createEsmHooks } from "ts-node";
|
|
4
|
+
import { require } from "./nodeModule.js";
|
|
5
|
+
createEsmHooks(register({
|
|
6
|
+
transpileOnly: true,
|
|
7
|
+
moduleTypes: {
|
|
8
|
+
"app-shell.config.ts": "cjs"
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
11
|
+
export const DEFAULT_CONFIG_FILES = [
|
|
12
|
+
"app-shell.config.ts",
|
|
13
|
+
"app-shell.config.js",
|
|
14
|
+
"app-shell.config.json"
|
|
15
|
+
];
|
|
16
|
+
export function findAppShellConfigFile(root) {
|
|
17
|
+
const filename = DEFAULT_CONFIG_FILES.find(file => fs.existsSync(path.resolve(root, file)));
|
|
18
|
+
if (filename) {
|
|
19
|
+
return path.resolve(root, filename);
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
export function loadConfigFile(appShellConfigFile, opts, env = {}) {
|
|
24
|
+
if (!appShellConfigFile) {
|
|
25
|
+
// an empty configuration is actually valid
|
|
26
|
+
// and with the automatic views option, it can even make sense
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
if (appShellConfigFile.endsWith(".json")) {
|
|
30
|
+
let appShellConfigRaw = fs.readFileSync(appShellConfigFile, "utf-8");
|
|
31
|
+
// token replacement is only supported for json files
|
|
32
|
+
opts.configReplacements?.forEach(item => {
|
|
33
|
+
appShellConfigRaw = appShellConfigRaw.replaceAll(`@@${item.token}@@`, item.value);
|
|
34
|
+
});
|
|
35
|
+
return JSON.parse(appShellConfigRaw);
|
|
36
|
+
}
|
|
37
|
+
// using require instead of import to avoid using --experimental-loader ts-node/esm
|
|
38
|
+
// eslint-disable-next-line import/no-dynamic-require
|
|
39
|
+
const loadedAppShellConfig = require(appShellConfigFile).default;
|
|
40
|
+
if (typeof loadedAppShellConfig === "function") {
|
|
41
|
+
return loadedAppShellConfig(opts, env);
|
|
42
|
+
}
|
|
43
|
+
return loadedAppShellConfig;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Return the main app (identified by @self)
|
|
47
|
+
* @param appShellConfig The App shell configuration
|
|
48
|
+
*/
|
|
49
|
+
export const getMainApp = (appShellConfig) => {
|
|
50
|
+
return appShellConfig.apps?.filter(app => app.id === "@self")[0];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Return the public path to be use by vite to launch the application.
|
|
54
|
+
* Value is obtained by returning the baseUrl value of the main app {@link #getMainApp}
|
|
55
|
+
* @param appShellConfig The App shell configuration
|
|
56
|
+
*/
|
|
57
|
+
export const getPublicPath = (appShellConfig) => {
|
|
58
|
+
const mainApp = getMainApp(appShellConfig);
|
|
59
|
+
if (!mainApp) {
|
|
60
|
+
return "/";
|
|
61
|
+
}
|
|
62
|
+
const url = mainApp.baseUrl;
|
|
63
|
+
try {
|
|
64
|
+
return new URL(url).pathname;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return url;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Returns the modules to be created by the build of the app.
|
|
72
|
+
* The list of modules is defined by the app-shell-config.json file routes ( limited to the @self app)
|
|
73
|
+
* The bundles will be created following the original directories structure ( having the src folder path removed)
|
|
74
|
+
*
|
|
75
|
+
* @param root Project root directory.
|
|
76
|
+
* @param appShellConfig The App Shell configuration.
|
|
77
|
+
* @param selfAppName The name of the application bundle being built.
|
|
78
|
+
*/
|
|
79
|
+
export function getAppModules(root, appShellConfig, selfAppName) {
|
|
80
|
+
const appModules = {};
|
|
81
|
+
const selfApp = getMainApp(appShellConfig);
|
|
82
|
+
if (selfApp != null) {
|
|
83
|
+
const selfViews = selfApp.views?.map(view => {
|
|
84
|
+
const bundleName = view.bundle.replace(/^src\//, "");
|
|
85
|
+
return {
|
|
86
|
+
...view,
|
|
87
|
+
bundleName
|
|
88
|
+
};
|
|
89
|
+
}) ?? [];
|
|
90
|
+
selfViews.forEach(view => {
|
|
91
|
+
appModules[view.bundleName] = path.resolve(root, view.bundle);
|
|
92
|
+
});
|
|
93
|
+
const selfModules = selfApp.modules?.map(module => {
|
|
94
|
+
const bundleName = module.bundle.replace(/^src\//, "");
|
|
95
|
+
return {
|
|
96
|
+
...module,
|
|
97
|
+
bundleName
|
|
98
|
+
};
|
|
99
|
+
}) ?? [];
|
|
100
|
+
selfModules.forEach(module => {
|
|
101
|
+
appModules[module.bundleName] = path.resolve(root, module.bundle);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const implicitThemeModules = appShellConfig?.theming?.themes?.map(theme => {
|
|
105
|
+
if (theme.startsWith("/src/") ||
|
|
106
|
+
theme.startsWith("@self/") ||
|
|
107
|
+
theme.startsWith(selfAppName)) {
|
|
108
|
+
const bundle = theme
|
|
109
|
+
.replace(/^@self\//, "")
|
|
110
|
+
.replace(new RegExp(`^${selfAppName}/`), "");
|
|
111
|
+
const bundleName = bundle.replace(/^(\/?)src\//, "");
|
|
112
|
+
return {
|
|
113
|
+
bundle,
|
|
114
|
+
bundleName
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}) ?? [];
|
|
119
|
+
implicitThemeModules.forEach(module => {
|
|
120
|
+
if (module != null && appModules[module.bundleName] == null) {
|
|
121
|
+
appModules[module.bundleName] = path.resolve(root, module.bundle);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return appModules;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=config-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-utils.js","sourceRoot":"","sources":["../src/config-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AASnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,cAAc,CACZ,QAAQ,CAAC;IACP,aAAa,EAAE,IAAI;IACnB,WAAW,EAAE;QACX,qBAAqB,EAAE,KAAK;KAC7B;CACF,CAAC,CACH,CAAC;AAYF,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,qBAAqB;IACrB,qBAAqB;IACrB,uBAAuB;CACxB,CAAC;AAEF,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAChD,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CACxC,CAAC;IAEF,IAAI,QAAQ,EAAE;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;KACrC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,kBAAsC,EACtC,IAA+B,EAC/B,MAA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,CAAC;KACJ;IAED,MAAM,oBAAoB,GACxB,cAAc,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE;QAC3C,IACE,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;YACzB,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC;YAC1B,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAC7B;YACA,MAAM,MAAM,GAAG,KAAK;iBACjB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;iBACvB,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,WAAW,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;YACrD,OAAO;gBACL,MAAM;gBACN,UAAU;aACX,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,IAAI,EAAE,CAAC;IAEX,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACpC,IAAI,MAAM,IAAI,IAAI,IAAI,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE;YAC3D,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;SACnE;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\n\nimport { register, createEsmHooks } from \"ts-node\";\n\nimport type {\n HvAppShellAppsConfig,\n HvAppShellConfig\n} from \"@hitachivantara/app-shell-shared\";\n\nimport type { AppShellVitePluginOptions } from \"./vite-plugin.js\";\n\nimport { require } from \"./nodeModule.js\";\n\ncreateEsmHooks(\n register({\n transpileOnly: true,\n moduleTypes: {\n \"app-shell.config.ts\": \"cjs\"\n }\n })\n);\n\nexport interface ConfigReplacement {\n token: string;\n value: string;\n}\n\nexport type AppShellConfigFunction = (\n pluginOptions: AppShellVitePluginOptions,\n env: Record<string, string>\n) => HvAppShellConfig;\n\nexport const DEFAULT_CONFIG_FILES = [\n \"app-shell.config.ts\",\n \"app-shell.config.js\",\n \"app-shell.config.json\"\n];\n\nexport function findAppShellConfigFile(root: string): string | undefined {\n const filename = DEFAULT_CONFIG_FILES.find(file =>\n fs.existsSync(path.resolve(root, file))\n );\n\n if (filename) {\n return path.resolve(root, filename);\n }\n\n return undefined;\n}\n\nexport function loadConfigFile(\n appShellConfigFile: string | undefined,\n opts: AppShellVitePluginOptions,\n env: Record<string, string> = {}\n): HvAppShellConfig {\n if (!appShellConfigFile) {\n // an empty configuration is actually valid\n // and with the automatic views option, it can even make sense\n return {};\n }\n\n if (appShellConfigFile.endsWith(\".json\")) {\n let appShellConfigRaw = fs.readFileSync(appShellConfigFile, \"utf-8\");\n\n // token replacement is only supported for json files\n opts.configReplacements?.forEach(item => {\n appShellConfigRaw = appShellConfigRaw.replaceAll(\n `@@${item.token}@@`,\n item.value\n );\n });\n\n return JSON.parse(appShellConfigRaw) as HvAppShellConfig;\n }\n\n // using require instead of import to avoid using --experimental-loader ts-node/esm\n // eslint-disable-next-line import/no-dynamic-require\n const loadedAppShellConfig = require(appShellConfigFile).default as\n | AppShellConfigFunction\n | HvAppShellConfig;\n\n if (typeof loadedAppShellConfig === \"function\") {\n return loadedAppShellConfig(opts, env);\n }\n\n return loadedAppShellConfig;\n}\n\n/**\n * Return the main app (identified by @self)\n * @param appShellConfig The App shell configuration\n */\nexport const getMainApp = (\n appShellConfig: HvAppShellConfig\n): HvAppShellAppsConfig | undefined => {\n return appShellConfig.apps?.filter(app => app.id === \"@self\")[0];\n};\n\n/**\n * Return the public path to be use by vite to launch the application.\n * Value is obtained by returning the baseUrl value of the main app {@link #getMainApp}\n * @param appShellConfig The App shell configuration\n */\nexport const getPublicPath = (appShellConfig: HvAppShellConfig): string => {\n const mainApp = getMainApp(appShellConfig);\n if (!mainApp) {\n return \"/\";\n }\n const url = mainApp.baseUrl;\n try {\n return new URL(url).pathname;\n } catch {\n return url;\n }\n};\n\n/**\n * Returns the modules to be created by the build of the app.\n * The list of modules is defined by the app-shell-config.json file routes ( limited to the @self app)\n * The bundles will be created following the original directories structure ( having the src folder path removed)\n *\n * @param root Project root directory.\n * @param appShellConfig The App Shell configuration.\n * @param selfAppName The name of the application bundle being built.\n */\nexport function getAppModules(\n root: string,\n appShellConfig: HvAppShellConfig,\n selfAppName: string\n) {\n const appModules: { [key: string]: string } = {};\n\n const selfApp = getMainApp(appShellConfig);\n if (selfApp != null) {\n const selfViews =\n selfApp.views?.map(view => {\n const bundleName = view.bundle.replace(/^src\\//, \"\");\n return {\n ...view,\n bundleName\n };\n }) ?? [];\n\n selfViews.forEach(view => {\n appModules[view.bundleName] = path.resolve(root, view.bundle);\n });\n\n const selfModules =\n selfApp.modules?.map(module => {\n const bundleName = module.bundle.replace(/^src\\//, \"\");\n return {\n ...module,\n bundleName\n };\n }) ?? [];\n\n selfModules.forEach(module => {\n appModules[module.bundleName] = path.resolve(root, module.bundle);\n });\n }\n\n const implicitThemeModules =\n appShellConfig?.theming?.themes?.map(theme => {\n if (\n theme.startsWith(\"/src/\") ||\n theme.startsWith(\"@self/\") ||\n theme.startsWith(selfAppName)\n ) {\n const bundle = theme\n .replace(/^@self\\//, \"\")\n .replace(new RegExp(`^${selfAppName}/`), \"\");\n const bundleName = bundle.replace(/^(\\/?)src\\//, \"\");\n return {\n bundle,\n bundleName\n };\n }\n\n return undefined;\n }) ?? [];\n\n implicitThemeModules.forEach(module => {\n if (module != null && appModules[module.bundleName] == null) {\n appModules[module.bundleName] = path.resolve(root, module.bundle);\n }\n });\n\n return appModules;\n}\n"]}
|