Skip to content

Commit 9a4aa86

Browse files
authored
fix(cli): bump config version & fix scripts (#4963)
- fix check script - bump minimum config version - remove unused hbs templates - fix hbs formatting - rename viteOptionsAppShell to appShellAutoMenu - default App Shell autoViewsAndRoutes Co-authored-by: Bruno Henriques <[email protected]>
1 parent 1be7f5a commit 9a4aa86

File tree

9 files changed

+30
-79
lines changed

9 files changed

+30
-79
lines changed

packages/cli/src/app-shell.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const plop = await nodePlop(`${__dirname}/plopfile.js`);
88

99
const createAppShellIndexHtml = plop.getGenerator("createAppShellIndexHtml");
1010
const createAppShellConfig = plop.getGenerator("createAppShellConfig");
11-
const createAppShellViteConfig = plop.getGenerator("createAppShellViteConfig");
11+
const createAppShellAutoMenu = plop.getGenerator("createAppShellAutoMenu");
1212

1313
const createAppShellIndexHtmlFile = async (path, name) => {
1414
await createAppShellIndexHtml.runActions({
@@ -21,7 +21,7 @@ const createAppShellConfigFile = async (
2121
path,
2222
name,
2323
appShellFeatures = [],
24-
viteOptionsAppShell = {},
24+
appShellAutoMenu = true,
2525
) => {
2626
const pagesPath = `${path}/src/pages`;
2727
const pages = fs.readdirSync(pagesPath);
@@ -58,24 +58,7 @@ const createAppShellConfigFile = async (
5858
appName: name.replace(/([a-z])([A-Z])/g, "$1 $2"),
5959
pages: templatePages,
6060
feats: appShellFeats,
61-
viteOptionsAppShell,
62-
});
63-
};
64-
65-
const createAppShellViteConfigFile = async (path, viteOptionsAppShell) => {
66-
const pagesPath = `${path}/src/pages`;
67-
const pages = fs.readdirSync(pagesPath);
68-
69-
const templatePages = pages.map((page) => ({
70-
path,
71-
pagesPath: "src/pages",
72-
name: page,
73-
}));
74-
75-
await createAppShellViteConfig.runActions({
76-
path,
77-
pages: templatePages,
78-
viteOptionsAppShell,
61+
appShellAutoMenu,
7962
});
8063
};
8164

@@ -94,8 +77,8 @@ export const createAppShellBaseline = async (appPath) => {
9477
export const setupAppShell = async (
9578
appPath,
9679
name,
97-
appShellFeatures,
98-
viteOptionsAppShell,
80+
appShellFeatures = [],
81+
appShellAutoMenu = true,
9982
packageName,
10083
) => {
10184
console.log(`\nConfiguring App Shell environment\n`);
@@ -108,11 +91,12 @@ export const setupAppShell = async (
10891
appPath,
10992
name,
11093
appShellFeatures,
111-
viteOptionsAppShell,
94+
appShellAutoMenu,
11295
);
11396

114-
// generate app shell vite config file
115-
await createAppShellViteConfigFile(appPath, viteOptionsAppShell);
97+
if (appShellAutoMenu) {
98+
await createAppShellAutoMenu.runActions({ path: appPath });
99+
}
116100

117101
// replace package name in i18n.ts file
118102
const i18nFile = `${appPath}/src/lib/i18n.ts`;

packages/cli/src/baselines/app-shell/vite/_package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "vite",
77
"build": "vite build",
88
"preview": "vite preview",
9-
"check": "npm run check:format && check:types && npm run check:lint",
9+
"check": "npm run check:format && npm run check:types && npm run check:lint",
1010
"check:types": "tsc --noEmit",
1111
"check:lint": "oxlint",
1212
"check:format": "prettier --check .",
@@ -33,8 +33,8 @@
3333
},
3434
"devDependencies": {
3535
"@hitachivantara/app-shell-vite-plugin": "^1.0.0",
36-
"@hitachivantara/uikit-config": "^0.4.0",
37-
"@hitachivantara/uikit-uno-preset": "^0.2.5",
36+
"@hitachivantara/uikit-config": "^0.5.1",
37+
"@hitachivantara/uikit-uno-preset": "^0.2.71",
3838
"@testing-library/jest-dom": "^6.1.5",
3939
"@testing-library/react": "^14.0.0",
4040
"@testing-library/user-event": "^14.4.3",

packages/cli/src/plop-templates/app-shell/vite.config.ts.hbs renamed to packages/cli/src/baselines/app-shell/vite/vite.config.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/// <reference types="vite/client" />
22
/// <reference types="vitest" />
33

4-
import { defineConfig } from "vite";
5-
64
import react from "@vitejs/plugin-react";
7-
import tsconfigPaths from "vite-tsconfig-paths";
85
import unoCSS from "unocss/vite";
6+
import { defineConfig } from "vite";
97
import cssInjectedByJsPlugin from "vite-plugin-css-injected-by-js";
10-
8+
import tsconfigPaths from "vite-tsconfig-paths";
119
import { HvAppShellVitePlugin } from "@hitachivantara/app-shell-vite-plugin";
1210

1311
export default defineConfig(({ mode }) => ({
@@ -20,17 +18,7 @@ export default defineConfig(({ mode }) => ({
2018
}),
2119
HvAppShellVitePlugin({
2220
mode,
23-
{{#if viteOptionsAppShell}}
2421
autoViewsAndRoutes: true,
25-
autoMenu: true
26-
{{/if}}
27-
{{#unless viteOptionsAppShell}}
28-
modules: [
29-
{{#each pages}}
30-
"{{pagesPath}}/{{name}}"{{#unless @last}},{{/unless}}
31-
{{/each}}
32-
]
33-
{{/unless}}
3422
}),
3523
],
3624

packages/cli/src/baselines/vite/_package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "vite",
77
"build": "vite build",
88
"preview": "vite preview",
9-
"check": "npm run check:format && check:types && npm run check:lint",
9+
"check": "npm run check:format && npm run check:types && npm run check:lint",
1010
"check:types": "tsc --noEmit",
1111
"check:lint": "oxlint",
1212
"check:format": "prettier --check .",
@@ -33,8 +33,8 @@
3333
"tiny-cookie": "^2.4.1"
3434
},
3535
"devDependencies": {
36-
"@hitachivantara/uikit-config": "^0.4.0",
37-
"@hitachivantara/uikit-uno-preset": "^0.2.5",
36+
"@hitachivantara/uikit-config": "^0.5.1",
37+
"@hitachivantara/uikit-uno-preset": "^0.2.71",
3838
"@testing-library/jest-dom": "^6.1.5",
3939
"@testing-library/react": "^14.0.0",
4040
"@testing-library/user-event": "^14.4.3",

packages/cli/src/create.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ const questions = [
4444
},
4545
{
4646
type: "confirm",
47-
name: "viteOptionsAppShell",
48-
message:
49-
"Use file based routing and automatic menu generation in App Shell?",
47+
name: "appShellAutoMenu",
48+
message: "Use automatic menu generation in App Shell?",
5049
default: true,
5150
when(answers) {
5251
return answers.useAppShell;
@@ -82,7 +81,7 @@ const create = async ({
8281
name = "uikit-app",
8382
useAppShell = true,
8483
appShellFeatures = [],
85-
viteOptionsAppShell = true,
84+
appShellAutoMenu = true,
8685
templates = [],
8786
}) => {
8887
console.log(chalk.cyan("\nUI kit app generator\n"));
@@ -113,7 +112,7 @@ const create = async ({
113112
appPath,
114113
name,
115114
appShellFeatures,
116-
viteOptionsAppShell,
115+
appShellAutoMenu,
117116
packageName,
118117
);
119118
console.log(
@@ -166,7 +165,7 @@ export const createCommand = new Command()
166165
name,
167166
useAppShell: !withoutAppShell,
168167
appShellFeatures: appShellFeatures?.split(",").map(toPascalCase),
169-
viteOptionsAppShell: !disableFileBasedRouting,
168+
appShellAutoMenu: !disableFileBasedRouting,
170169
templates: templates?.split(",").map(toPascalCase),
171170
});
172171
}

packages/cli/src/plop-templates/app-shell/app-shell.config.ts.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default (): HvAppShellConfig => ({
1919
{{/if}}
2020

2121
mainPanel: {
22-
maxWidth: "xl"{{#unless viteOptionsAppShell}},
22+
maxWidth: "xl"{{#unless appShellAutoMenu}},
2323
views: [
2424
{{#each pages}}
2525
{ bundle: "@self/{{pagesPath}}/{{name}}.js", route: "/{{kebabCase name}}" }{{#unless @last}},{{/unless}}
@@ -28,7 +28,7 @@ export default (): HvAppShellConfig => ({
2828
{{/unless}}
2929
},
3030

31-
{{#unless viteOptionsAppShell}}
31+
{{#unless appShellAutoMenu}}
3232
menu: [
3333
{{#each pages}}
3434
{ label: "key_{{name}}", target: "/{{kebabCase name}}" }{{#unless @last}},{{/unless}}

packages/cli/src/plop-templates/navigation.ts.hbs

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/cli/src/plop-templates/routes.tsx.hbs

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/cli/src/plopfile.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const createRoute = {
44
type: "append",
55
path: "{{path}}/src/routes.tsx",
66
pattern: "// APP ROUTES",
7-
template: `{ path: "{{kebabCase name}}", lazy: () => import("./pages/{{name}}") },`,
7+
template: ` { path: "{{kebabCase name}}", lazy: () => import("./pages/{{name}}") },`,
88
},
99
],
1010
};
@@ -40,12 +40,13 @@ const createAppShellConfig = {
4040
],
4141
};
4242

43-
const createAppShellViteConfig = {
43+
const createAppShellAutoMenu = {
4444
actions: [
4545
{
46-
type: "add",
46+
type: "append",
4747
path: "{{path}}/vite.config.ts",
48-
templateFile: "plop-templates/app-shell/vite.config.ts.hbs",
48+
pattern: "autoViewsAndRoutes: true,",
49+
template: ` autoMenu: true,`,
4950
},
5051
],
5152
};
@@ -56,5 +57,5 @@ export default (plop) => {
5657
plop.setGenerator("createReadMe", createReadMe);
5758
plop.setGenerator("createAppShellIndexHtml", createAppShellIndexHtml);
5859
plop.setGenerator("createAppShellConfig", createAppShellConfig);
59-
plop.setGenerator("createAppShellViteConfig", createAppShellViteConfig);
60+
plop.setGenerator("createAppShellAutoMenu", createAppShellAutoMenu);
6061
};

0 commit comments

Comments
 (0)