@hitachivantara/app-shell-vite-plugin 0.18.5 → 0.18.6
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/dist/tests/config-utils.test.d.ts +2 -0
- package/dist/tests/config-utils.test.d.ts.map +1 -0
- package/dist/tests/config-utils.test.js +90 -0
- package/dist/tests/config-utils.test.js.map +1 -0
- package/dist/tests/mocks/path.mock.d.ts +5 -0
- package/dist/tests/mocks/path.mock.d.ts.map +1 -0
- package/dist/tests/mocks/path.mock.js +6 -0
- package/dist/tests/mocks/path.mock.js.map +1 -0
- package/dist/tests/setup.d.ts +2 -0
- package/dist/tests/setup.d.ts.map +1 -0
- package/dist/tests/setup.js +2 -0
- package/dist/tests/setup.js.map +1 -0
- package/dist/tests/vite-generate-base-plugin.test.d.ts +2 -0
- package/dist/tests/vite-generate-base-plugin.test.d.ts.map +1 -0
- package/dist/tests/vite-generate-base-plugin.test.js +12 -0
- package/dist/tests/vite-generate-base-plugin.test.js.map +1 -0
- package/dist/tests/vite-metadata-plugin.test.d.ts +2 -0
- package/dist/tests/vite-metadata-plugin.test.d.ts.map +1 -0
- package/dist/tests/vite-metadata-plugin.test.js +47 -0
- package/dist/tests/vite-metadata-plugin.test.js.map +1 -0
- package/dist/vite-generate-base-plugin.d.ts +9 -0
- package/dist/vite-generate-base-plugin.d.ts.map +1 -1
- package/dist/vite-generate-base-plugin.js +12 -3
- package/dist/vite-generate-base-plugin.js.map +1 -1
- package/package.json +7 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-utils.test.d.ts","sourceRoot":"","sources":["../../src/tests/config-utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { findAppShellConfigFile, getAppModules, getPublicPath, loadConfigFile } from "../config-utils";
|
|
3
|
+
vi.mock("path", async () => vi.importActual("./mocks/path.mock.ts"));
|
|
4
|
+
const existsSyncMock = vi.fn();
|
|
5
|
+
const readFileSyncMock = vi.fn();
|
|
6
|
+
fs.existsSync = existsSyncMock;
|
|
7
|
+
fs.readFileSync = readFileSyncMock;
|
|
8
|
+
describe("test app-shell-vite-generate-base plugin", () => {
|
|
9
|
+
describe("test `findAppShellConfigFile`", () => {
|
|
10
|
+
it("it returns the config file location (and its content) if exists", () => {
|
|
11
|
+
existsSyncMock.mockImplementation((file) => {
|
|
12
|
+
return file.match("/dummyPath/dummyRootProject/app-shell.config.json");
|
|
13
|
+
});
|
|
14
|
+
const filePath = findAppShellConfigFile("/dummyPath/dummyRootProject");
|
|
15
|
+
expect(filePath).toBe("/dummyPath/dummyRootProject/app-shell.config.json");
|
|
16
|
+
});
|
|
17
|
+
it("it returns undefined if config file don't exists", () => {
|
|
18
|
+
existsSyncMock.mockImplementation(() => {
|
|
19
|
+
return false;
|
|
20
|
+
});
|
|
21
|
+
const filePath = findAppShellConfigFile("/dummyPath/dummyRootProject");
|
|
22
|
+
expect(filePath).toBeUndefined();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe("test `loadConfigFile`", () => {
|
|
26
|
+
it("returns an empty config if the config file is not defined", () => {
|
|
27
|
+
const appShellConfig = loadConfigFile(undefined, {}, {});
|
|
28
|
+
expect(appShellConfig).toMatchObject({});
|
|
29
|
+
});
|
|
30
|
+
it("returns the config if config file exists", () => {
|
|
31
|
+
const config = {
|
|
32
|
+
baseUrl: "dummyBaseUrl"
|
|
33
|
+
};
|
|
34
|
+
existsSyncMock.mockImplementation((file) => {
|
|
35
|
+
return file.match("/dummyPath/dummyRootProject/app-shell.config.json");
|
|
36
|
+
});
|
|
37
|
+
readFileSyncMock.mockImplementation(() => {
|
|
38
|
+
return JSON.stringify(config);
|
|
39
|
+
});
|
|
40
|
+
const appShellConfig = loadConfigFile("/dummyPath/dummyRootProject/app-shell.config.json", {}, {});
|
|
41
|
+
expect(appShellConfig).toMatchObject(config);
|
|
42
|
+
});
|
|
43
|
+
it("replaces tokens at configurations defined at json files", () => {
|
|
44
|
+
const config = {
|
|
45
|
+
baseUrl: "@@BASE_URL@@"
|
|
46
|
+
};
|
|
47
|
+
existsSyncMock.mockImplementation((file) => {
|
|
48
|
+
return file.match("/dummyPath/dummyRootProject/app-shell.config.json");
|
|
49
|
+
});
|
|
50
|
+
readFileSyncMock.mockImplementation(() => {
|
|
51
|
+
return JSON.stringify(config);
|
|
52
|
+
});
|
|
53
|
+
const appShellConfig = loadConfigFile("/dummyPath/dummyRootProject/app-shell.config.json", {
|
|
54
|
+
configReplacements: [
|
|
55
|
+
{ token: "BASE_URL", value: "dummyBaseUrlWithTokens" }
|
|
56
|
+
]
|
|
57
|
+
}, {});
|
|
58
|
+
expect(appShellConfig).toMatchObject({
|
|
59
|
+
baseUrl: "dummyBaseUrlWithTokens"
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe("getPublicPath", () => {
|
|
64
|
+
it("getPublicPath", () => {
|
|
65
|
+
expect(getPublicPath({ baseUrl: "/teste" })).toBe("/teste");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe("getAppModules", () => {
|
|
69
|
+
it("modules are correctly mapped", () => {
|
|
70
|
+
expect(getAppModules("dummyPath", [
|
|
71
|
+
"src/pages/DummyPath",
|
|
72
|
+
"src/pages/DummyPath-2"
|
|
73
|
+
])).toMatchObject({
|
|
74
|
+
"pages/DummyPath": "dummyPath/src/pages/DummyPath",
|
|
75
|
+
"pages/DummyPath-2": "dummyPath/src/pages/DummyPath-2"
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
it("removes modules that are not defined at src folder", () => {
|
|
79
|
+
expect(getAppModules("dummyPath", [
|
|
80
|
+
"src/pages/DummyPath",
|
|
81
|
+
"dummySrc/pages/DummyPath-2",
|
|
82
|
+
"src/pages/DummyPath-3"
|
|
83
|
+
])).toMatchObject({
|
|
84
|
+
"pages/DummyPath": "dummyPath/src/pages/DummyPath",
|
|
85
|
+
"pages/DummyPath-3": "dummyPath/src/pages/DummyPath-3"
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=config-utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-utils.test.js","sourceRoot":"","sources":["../../src/tests/config-utils.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,aAAa,EACb,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC,CAAC;AAErE,MAAM,cAAc,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AAC/B,MAAM,gBAAgB,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AACjC,EAAE,CAAC,UAAU,GAAG,cAAc,CAAC;AAC/B,EAAE,CAAC,YAAY,GAAG,gBAAgB,CAAC;AACnC,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;IACxD,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;QAC7C,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,cAAc,CAAC,kBAAkB,CAAC,CAAC,IAAY,EAAE,EAAE;gBACjD,OAAO,IAAI,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;YACzE,CAAC,CAAC,CAAC;YACH,MAAM,QAAQ,GAAG,sBAAsB,CAAC,6BAA6B,CAAC,CAAC;YACvE,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CACnB,mDAAmD,CACpD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;YAC1D,cAAc,CAAC,kBAAkB,CAAC,GAAG,EAAE;gBACrC,OAAO,KAAK,CAAC;YACf,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AC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\nimport fs from \"fs\";\nimport {\n findAppShellConfigFile,\n getAppModules,\n getPublicPath,\n loadConfigFile\n} from \"../config-utils\";\n\nvi.mock(\"path\", async () => vi.importActual(\"./mocks/path.mock.ts\"));\n\nconst existsSyncMock = vi.fn();\nconst readFileSyncMock = vi.fn();\nfs.existsSync = existsSyncMock;\nfs.readFileSync = readFileSyncMock;\ndescribe(\"test app-shell-vite-generate-base plugin\", () => {\n describe(\"test `findAppShellConfigFile`\", () => {\n it(\"it returns the config file location (and its content) if exists\", () => {\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n const filePath = findAppShellConfigFile(\"/dummyPath/dummyRootProject\");\n expect(filePath).toBe(\n \"/dummyPath/dummyRootProject/app-shell.config.json\"\n );\n });\n\n it(\"it returns undefined if config file don't exists\", () => {\n existsSyncMock.mockImplementation(() => {\n return false;\n });\n const filePath = findAppShellConfigFile(\"/dummyPath/dummyRootProject\");\n expect(filePath).toBeUndefined();\n });\n });\n\n describe(\"test `loadConfigFile`\", () => {\n it(\"returns an empty config if the config file is not defined\", () => {\n const appShellConfig = loadConfigFile(undefined, {}, {});\n expect(appShellConfig).toMatchObject({});\n });\n\n it(\"returns the config if config file exists\", () => {\n const config: HvAppShellConfig = {\n baseUrl: \"dummyBaseUrl\"\n };\n\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n\n readFileSyncMock.mockImplementation(() => {\n return JSON.stringify(config);\n });\n\n const appShellConfig = loadConfigFile(\n \"/dummyPath/dummyRootProject/app-shell.config.json\",\n {},\n {}\n );\n expect(appShellConfig).toMatchObject(config);\n });\n\n it(\"replaces tokens at configurations defined at json files\", () => {\n const config: HvAppShellConfig = {\n baseUrl: \"@@BASE_URL@@\"\n };\n\n existsSyncMock.mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n\n readFileSyncMock.mockImplementation(() => {\n return JSON.stringify(config);\n });\n\n const appShellConfig = loadConfigFile(\n \"/dummyPath/dummyRootProject/app-shell.config.json\",\n {\n configReplacements: [\n { token: \"BASE_URL\", value: \"dummyBaseUrlWithTokens\" }\n ]\n },\n {}\n );\n expect(appShellConfig).toMatchObject({\n baseUrl: \"dummyBaseUrlWithTokens\"\n });\n });\n });\n\n describe(\"getPublicPath\", () => {\n it(\"getPublicPath\", () => {\n expect(getPublicPath({ baseUrl: \"/teste\" })).toBe(\"/teste\");\n });\n });\n\n describe(\"getAppModules\", () => {\n it(\"modules are correctly mapped\", () => {\n expect(\n getAppModules(\"dummyPath\", [\n \"src/pages/DummyPath\",\n \"src/pages/DummyPath-2\"\n ])\n ).toMatchObject({\n \"pages/DummyPath\": \"dummyPath/src/pages/DummyPath\",\n \"pages/DummyPath-2\": \"dummyPath/src/pages/DummyPath-2\"\n });\n });\n\n it(\"removes modules that are not defined at src folder\", () => {\n expect(\n getAppModules(\"dummyPath\", [\n \"src/pages/DummyPath\",\n \"dummySrc/pages/DummyPath-2\",\n \"src/pages/DummyPath-3\"\n ])\n ).toMatchObject({\n \"pages/DummyPath\": \"dummyPath/src/pages/DummyPath\",\n \"pages/DummyPath-3\": \"dummyPath/src/pages/DummyPath-3\"\n });\n });\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.mock.d.ts","sourceRoot":"","sources":["../../../src/tests/mocks/path.mock.ts"],"names":[],"mappings":";wBACsB,MAAM,EAAE;;AAD9B,wBAIE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.mock.js","sourceRoot":"","sources":["../../../src/tests/mocks/path.mock.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,OAAO,EAAE,CAAC,GAAG,KAAe,EAAE,EAAE;QAC9B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;CACF,CAAC","sourcesContent":["export default {\n resolve: (...paths: string[]) => {\n return paths.join(\"/\");\n }\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/tests/setup.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/tests/setup.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC","sourcesContent":["import \"@testing-library/jest-dom/vitest\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-generate-base-plugin.test.d.ts","sourceRoot":"","sources":["../../src/tests/vite-generate-base-plugin.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getAppTitle } from "../vite-generate-base-plugin";
|
|
2
|
+
describe("test vite-generate-base plugin", () => {
|
|
3
|
+
describe("test `getAppTitle` method", () => {
|
|
4
|
+
test.each([
|
|
5
|
+
[false, { name: "dummyName" }, "dummyName"],
|
|
6
|
+
[true, {}, "%%APPSHELL_TITLE%%"]
|
|
7
|
+
])("At mode %b, %j, app title matches %s", (value, config, expected) => {
|
|
8
|
+
expect(getAppTitle(value, config)).toMatchObject(expected);
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=vite-generate-base-plugin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-generate-base-plugin.test.js","sourceRoot":"","sources":["../../src/tests/vite-generate-base-plugin.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACzC,IAAI,CAAC,IAAI,CAAC;YACR,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,WAAW,CAAC;YAC3C,CAAC,IAAI,EAAE,EAAE,EAAE,oBAAoB,CAAC;SACjC,CAAC,CACA,uCAAuC,EACvC,CAAC,KAAc,EAAE,MAAc,EAAE,QAAgB,EAAE,EAAE;YACnD,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAA0B,CAAC,CAAC,CAAC,aAAa,CAClE,QAAQ,CACT,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\nimport { getAppTitle } from \"../vite-generate-base-plugin\";\n\ndescribe(\"test vite-generate-base plugin\", () => {\n describe(\"test `getAppTitle` method\", () => {\n test.each([\n [false, { name: \"dummyName\" }, \"dummyName\"],\n [true, {}, \"%%APPSHELL_TITLE%%\"]\n ])(\n \"At mode %b, %j, app title matches %s\",\n (value: boolean, config: object, expected: string) => {\n expect(getAppTitle(value, config as HvAppShellConfig)).toMatchObject(\n expected\n );\n }\n );\n });\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-metadata-plugin.test.d.ts","sourceRoot":"","sources":["../../src/tests/vite-metadata-plugin.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import injectMetadata from "../vite-metadata-plugin";
|
|
3
|
+
describe("test vite-metadata plugin", () => {
|
|
4
|
+
it("it returns the injectMetadata information", () => {
|
|
5
|
+
const fsTmp = fs.existsSync;
|
|
6
|
+
fs.existsSync = vi.fn().mockImplementation((file) => {
|
|
7
|
+
return file.match("/dummyPath/dummyRootProject/app-shell.config.json");
|
|
8
|
+
});
|
|
9
|
+
const readFileSyncTmp = fs.readFileSync;
|
|
10
|
+
fs.readFileSync = vi.fn().mockImplementation((file) => {
|
|
11
|
+
const version = (packageFile) => {
|
|
12
|
+
if (packageFile.indexOf("/client/packages/app-shell-ui/package.json") >= 0) {
|
|
13
|
+
return "appShellUIDummyVersion";
|
|
14
|
+
}
|
|
15
|
+
if (packageFile.indexOf("/client/packages/app-shell-vite-plugin/package.json") >= 0) {
|
|
16
|
+
return "appShellVitePluginDummyVersion";
|
|
17
|
+
}
|
|
18
|
+
return "dummyVersion";
|
|
19
|
+
};
|
|
20
|
+
return JSON.stringify({ version: version(file) });
|
|
21
|
+
});
|
|
22
|
+
const metadata = injectMetadata();
|
|
23
|
+
const { transformIndexHtml } = metadata;
|
|
24
|
+
// @ts-expect-error This is a function an dis callable
|
|
25
|
+
expect(transformIndexHtml()).toMatchObject([
|
|
26
|
+
{
|
|
27
|
+
attrs: {
|
|
28
|
+
content: "appShellUIDummyVersion",
|
|
29
|
+
name: "app-shell-ui-version"
|
|
30
|
+
},
|
|
31
|
+
tag: "meta"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
attrs: {
|
|
35
|
+
content: "appShellVitePluginDummyVersion",
|
|
36
|
+
name: "app-shell-vite-plugin-version"
|
|
37
|
+
},
|
|
38
|
+
tag: "meta"
|
|
39
|
+
}
|
|
40
|
+
]);
|
|
41
|
+
// Restore the original fs.existsSync
|
|
42
|
+
fs.existsSync = fsTmp;
|
|
43
|
+
// Restore the original fs.existsSync
|
|
44
|
+
fs.readFileSync = readFileSyncTmp;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
//# sourceMappingURL=vite-metadata-plugin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite-metadata-plugin.test.js","sourceRoot":"","sources":["../../src/tests/vite-metadata-plugin.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,cAAc,MAAM,yBAAyB,CAAC;AAErD,QAAQ,CAAC,2BAA2B,EA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A+B;iBACtC;gBACD,GAAG,EAAE,MAAM;aACZ;SACF,CAAC,CAAC;QAEH,qCAAqC;QACrC,EAAE,CAAC,UAAU,GAAG,KAAK,CAAC;QACtB,qCAAqC;QACrC,EAAE,CAAC,YAAY,GAAG,eAAe,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import fs from \"fs\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport injectMetadata from \"../vite-metadata-plugin\";\n\ndescribe(\"test vite-metadata plugin\", () => {\n it(\"it returns the injectMetadata information\", () => {\n const fsTmp = fs.existsSync;\n fs.existsSync = vi.fn().mockImplementation((file: string) => {\n return file.match(\"/dummyPath/dummyRootProject/app-shell.config.json\");\n });\n\n const readFileSyncTmp = fs.readFileSync;\n fs.readFileSync = vi.fn().mockImplementation((file: string) => {\n const version = (packageFile: string) => {\n if (\n packageFile.indexOf(\"/client/packages/app-shell-ui/package.json\") >= 0\n ) {\n return \"appShellUIDummyVersion\";\n }\n if (\n packageFile.indexOf(\n \"/client/packages/app-shell-vite-plugin/package.json\"\n ) >= 0\n ) {\n return \"appShellVitePluginDummyVersion\";\n }\n return \"dummyVersion\";\n };\n return JSON.stringify({ version: version(file) });\n });\n\n const metadata: PluginOption = injectMetadata();\n const { transformIndexHtml } = metadata as Plugin;\n // @ts-expect-error This is a function an dis callable\n expect(transformIndexHtml()).toMatchObject([\n {\n attrs: {\n content: \"appShellUIDummyVersion\",\n name: \"app-shell-ui-version\"\n },\n tag: \"meta\"\n },\n {\n attrs: {\n content: \"appShellVitePluginDummyVersion\",\n name: \"app-shell-vite-plugin-version\"\n },\n tag: \"meta\"\n }\n ]);\n\n // Restore the original fs.existsSync\n fs.existsSync = fsTmp;\n // Restore the original fs.existsSync\n fs.readFileSync = readFileSyncTmp;\n });\n});\n"]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { PluginOption } from "vite";
|
|
2
2
|
import type { HvAppShellConfig } from "@hitachivantara/app-shell-shared";
|
|
3
|
+
/**
|
|
4
|
+
* Calculate the App title, It applies the following rules to calculate the final value
|
|
5
|
+
* - If we are generating an empty App Shell, it returns the value “%%APPSHELL_TITLE%%.”
|
|
6
|
+
* - Otherwise, it returns the value of the configuration name property.
|
|
7
|
+
* @param generateEmptyShell flag to control if we are generating an empty App Shell instance
|
|
8
|
+
* @param appShellConfig App shell config values
|
|
9
|
+
* @returns The app title
|
|
10
|
+
*/
|
|
11
|
+
export declare const getAppTitle: (generateEmptyShell: boolean, appShellConfig: HvAppShellConfig) => string | undefined;
|
|
3
12
|
/**
|
|
4
13
|
* Add the <BASE> tag at index.html file. Tag value is obtained by the baseUrl config value ({@link #getPublicPath})‘
|
|
5
14
|
* @param appShellConfig The app shell configuration.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-generate-base-plugin.d.ts","sourceRoot":"","sources":["../src/vite-generate-base-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAIzE;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,cAAc,EAAE,gBAAgB,EAChC,kBAAkB,EAAE,OAAO,GAC1B,YAAY,
|
|
1
|
+
{"version":3,"file":"vite-generate-base-plugin.d.ts","sourceRoot":"","sources":["../src/vite-generate-base-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAEzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAIzE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,uBACF,OAAO,kBACX,gBAAgB,uBAGjC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,cAAc,EAAE,gBAAgB,EAChC,kBAAkB,EAAE,OAAO,GAC1B,YAAY,CAwCd"}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { getPublicPath } from "./config-utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Calculate the App title, It applies the following rules to calculate the final value
|
|
4
|
+
* - If we are generating an empty App Shell, it returns the value “%%APPSHELL_TITLE%%.”
|
|
5
|
+
* - Otherwise, it returns the value of the configuration name property.
|
|
6
|
+
* @param generateEmptyShell flag to control if we are generating an empty App Shell instance
|
|
7
|
+
* @param appShellConfig App shell config values
|
|
8
|
+
* @returns The app title
|
|
9
|
+
*/
|
|
10
|
+
export const getAppTitle = (generateEmptyShell, appShellConfig) => {
|
|
11
|
+
return generateEmptyShell ? "%%APPSHELL_TITLE%%" : appShellConfig.name;
|
|
12
|
+
};
|
|
2
13
|
/**
|
|
3
14
|
* Add the <BASE> tag at index.html file. Tag value is obtained by the baseUrl config value ({@link #getPublicPath})‘
|
|
4
15
|
* @param appShellConfig The app shell configuration.
|
|
@@ -13,9 +24,7 @@ export default function generateBaseTag(appShellConfig, generateEmptyShell) {
|
|
|
13
24
|
order: "post",
|
|
14
25
|
handler: (html) => ({
|
|
15
26
|
html: generateEmptyShell || appShellConfig.name != null
|
|
16
|
-
? html.replace(/<title>(.*?)<\/title>/, `<title>${generateEmptyShell
|
|
17
|
-
? "%%APPSHELL_TITLE%%"
|
|
18
|
-
: appShellConfig.name}</title>`)
|
|
27
|
+
? html.replace(/<title>(.*?)<\/title>/, `<title>${getAppTitle(generateEmptyShell, appShellConfig)}</title>`)
|
|
19
28
|
: html,
|
|
20
29
|
tags: [
|
|
21
30
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-generate-base-plugin.js","sourceRoot":"","sources":["../src/vite-generate-base-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,cAAgC,EAChC,kBAA2B;IAE3B,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;IAEjD,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,OAAO,EAAE,KAAK;QACd,kBAAkB,EAAE;YAClB,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;gBAC1B,IAAI,EACF,kBAAkB,IAAI,cAAc,CAAC,IAAI,IAAI,IAAI;oBAC/C,CAAC,CAAC,IAAI,CAAC,OAAO,CACV,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"vite-generate-base-plugin.js","sourceRoot":"","sources":["../src/vite-generate-base-plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,kBAA2B,EAC3B,cAAgC,EAChC,EAAE;IACF,OAAO,kBAAkB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC;AACzE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,cAAgC,EAChC,kBAA2B;IAE3B,MAAM,UAAU,GAAG,aAAa,CAAC,cAAc,CAAC,CAAC;IAEjD,OAAO;QACL,IAAI,EAAE,2BAA2B;QACjC,OAAO,EAAE,KAAK;QACd,kBAAkB,EAAE;YAClB,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;gBAC1B,IAAI,EACF,kBAAkB,IAAI,cAAc,CAAC,IAAI,IAAI,IAAI;oBAC/C,CAAC,CAAC,IAAI,CAAC,OAAO,CACV,uBAAuB,EACvB,UAAU,WAAW,CACnB,kBAAkB,EAClB,cAAc,CACf,UAAU,CACZ;oBACH,CAAC,CAAC,IAAI;gBACV,IAAI,EAAE;oBACJ;wBACE,GAAG,EAAE,MAAM;wBACX,KAAK,EAAE;4BACL,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,UAAU;yBAC5D;wBACD,QAAQ,EAAE,cAAc;qBACzB;oBACD;wBACE,GAAG,EAAE,MAAM;wBACX,QAAQ,EAAE,cAAc;wBACxB,KAAK,EAAE;4BACL,GAAG,EAAE,SAAS;4BACd,EAAE,EAAE,OAAO;4BACX,IAAI,EAAE,mBAAmB;yBAC1B;qBACF;iBACF;aACF,CAAC;SACH;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { PluginOption } from \"vite\";\n\nimport type { HvAppShellConfig } from \"@hitachivantara/app-shell-shared\";\n\nimport { getPublicPath } from \"./config-utils.js\";\n\n/**\n * Calculate the App title, It applies the following rules to calculate the final value\n * - If we are generating an empty App Shell, it returns the value “%%APPSHELL_TITLE%%.”\n * - Otherwise, it returns the value of the configuration name property.\n * @param generateEmptyShell flag to control if we are generating an empty App Shell instance\n * @param appShellConfig App shell config values\n * @returns The app title\n */\nexport const getAppTitle = (\n generateEmptyShell: boolean,\n appShellConfig: HvAppShellConfig\n) => {\n return generateEmptyShell ? \"%%APPSHELL_TITLE%%\" : appShellConfig.name;\n};\n\n/**\n * Add the <BASE> tag at index.html file. Tag value is obtained by the baseUrl config value ({@link #getPublicPath})‘\n * @param appShellConfig The app shell configuration.\n * @param generateEmptyShell Flag that controls if an empty app shell application is created with tags instead of final values\n */\nexport default function generateBaseTag(\n appShellConfig: HvAppShellConfig,\n generateEmptyShell: boolean\n): PluginOption {\n const publicPath = getPublicPath(appShellConfig);\n\n return {\n name: \"vite-plugin-generate-base\",\n enforce: \"pre\",\n transformIndexHtml: {\n order: \"post\",\n handler: (html: string) => ({\n html:\n generateEmptyShell || appShellConfig.name != null\n ? html.replace(\n /<title>(.*?)<\\/title>/,\n `<title>${getAppTitle(\n generateEmptyShell,\n appShellConfig\n )}</title>`\n )\n : html,\n tags: [\n {\n tag: \"base\",\n attrs: {\n href: generateEmptyShell ? \"%%APPSHELL_BASE%%\" : publicPath\n },\n injectTo: \"head-prepend\"\n },\n {\n tag: \"link\",\n injectTo: \"head-prepend\",\n attrs: {\n rel: \"preload\",\n as: \"image\",\n href: \"./icons/icons.svg\"\n }\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": "0.18.
|
|
3
|
+
"version": "0.18.6",
|
|
4
4
|
"description": "AppShell Vite Plugin",
|
|
5
5
|
"author": "Hitachi Vantara - Boba Fett Team",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,13 +31,15 @@
|
|
|
31
31
|
"lint-check": "npx eslint --ext .js,.jsx,.ts,.tsx src --color",
|
|
32
32
|
"lint": "npm-run-all --parallel lint:*",
|
|
33
33
|
"lint:eslint": "npm run lint-check -- --cache --fix",
|
|
34
|
-
"lint:prettier": "npx prettier --write \"src/**/*.{html,css,js,jsx,ts,tsx}\""
|
|
34
|
+
"lint:prettier": "npx prettier --write \"src/**/*.{html,css,js,jsx,ts,tsx}\"",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"coverage": "vitest run --coverage"
|
|
35
37
|
},
|
|
36
38
|
"dependencies": {
|
|
37
39
|
"@emotion/cache": "^11.11.0",
|
|
38
40
|
"@emotion/react": "^11.11.1",
|
|
39
|
-
"@hitachivantara/app-shell-shared": "0.13.
|
|
40
|
-
"@hitachivantara/app-shell-ui": "0.38.
|
|
41
|
+
"@hitachivantara/app-shell-shared": "0.13.1",
|
|
42
|
+
"@hitachivantara/app-shell-ui": "0.38.4",
|
|
41
43
|
"@hitachivantara/uikit-react-icons": "^5.6.0",
|
|
42
44
|
"@hitachivantara/uikit-react-shared": "^5.1.0",
|
|
43
45
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
@@ -62,5 +64,5 @@
|
|
|
62
64
|
"peerDependencies": {
|
|
63
65
|
"vite": "^4.1.4 || ^5.0.4"
|
|
64
66
|
},
|
|
65
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "2c0c98f104c9a33a627cfd8f1abdbefe93f7951f"
|
|
66
68
|
}
|