@component-hook/create-app 1.5.0 → 1.6.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 +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +86 -80
- package/package.json +12 -12
- package/template-react/.vscode/extensions.json +9 -0
- package/template-react/.vscode/settings.json +18 -0
- package/template-react/README.md.art +85 -0
- package/template-react/e2e/home.spec.ts +40 -0
- package/template-react/eslint.config.js +18 -0
- package/template-react/index.html.art +13 -0
- package/template-react/lint-staged.config.js +6 -0
- package/template-react/package.json +70 -0
- package/template-react/public/vite.svg +1 -0
- package/template-react/src/App.tsx +6 -0
- package/template-react/src/assets/svg-icons/react.svg +1 -0
- package/template-react/src/components/common/index.ts +1 -0
- package/template-react/src/components/common/svg-icon/index.ts +1 -0
- package/template-react/src/components/common/svg-icon/src/index.tsx +23 -0
- package/template-react/src/main.tsx +26 -0
- package/template-react/src/mocks/browser.ts +4 -0
- package/template-react/src/mocks/handlers/index.ts +1 -0
- package/template-react/src/mocks/server.ts +4 -0
- package/template-react/src/pages/home/components/hello-world/index.test.tsx +45 -0
- package/template-react/src/pages/home/components/hello-world/index.tsx +49 -0
- package/template-react/src/pages/home/index.module.css +8 -0
- package/template-react/src/pages/home/index.test.tsx +19 -0
- package/template-react/src/pages/home/index.tsx +37 -0
- package/template-react/src/plugins/i18n/index.ts +19 -0
- package/template-react/src/plugins/i18n/locales/en-US.json +3 -0
- package/template-react/src/plugins/i18n/locales/zh-TW.json +3 -0
- package/template-react/src/router/index.tsx +22 -0
- package/template-react/src/stores/constants.ts +1 -0
- package/template-react/src/stores/index.ts +1 -0
- package/template-react/src/stores/middleware.ts +17 -0
- package/template-react/src/stores/modules/config.ts +27 -0
- package/template-react/src/styles/base.css +68 -0
- package/template-react/src/styles/common/all.css +1 -0
- package/template-react/src/styles/common/button.css +26 -0
- package/template-react/src/styles/index.css +3 -0
- package/template-react/src/styles/tailwind.css +14 -0
- package/template-react/src/test-utils/index.tsx +15 -0
- package/template-react/src/vite-env.d.ts +9 -0
- package/template-react/tsconfig.app.json +32 -0
- package/template-react/tsconfig.vitest.json +10 -0
- package/template-react/vite.config.ts +40 -0
- package/template-react/vitest.config.ts +18 -0
- package/template-react/vitest.setup.ts +13 -0
- package/template-shared/.browserslistrc +10 -0
- package/template-shared/.github/actions/setup-environment/action.yml +21 -0
- package/template-shared/.github/renovate.json +14 -0
- package/template-shared/.github/workflows/ci.yml +22 -0
- package/template-shared/.github/workflows/deploy.yml +27 -0
- package/template-shared/.github/workflows/preview.yml +17 -0
- package/template-shared/.gitlab/setup.yml +18 -0
- package/template-shared/.husky/commit-msg +1 -0
- package/template-shared/.husky/pre-commit +1 -0
- package/{LICENSE → template-shared/LICENSE} +1 -1
- package/template-shared/_gitignore +32 -0
- package/template-shared/_gitlab-ci.yml +22 -0
- package/template-shared/commitlint.config.js +3 -0
- package/template-shared/playwright.config.ts +49 -0
- package/template-shared/postcss.config.js +15 -0
- package/template-shared/prettier.config.js +13 -0
- package/template-shared/scripts/build-info/index.ts +21 -0
- package/template-shared/tsconfig.json +14 -0
- package/template-shared/tsconfig.node.json +12 -0
- package/template-vue/.vscode/extensions.json +10 -0
- package/template-vue/.vscode/settings.json +18 -0
- package/template-vue/README.md.art +81 -0
- package/template-vue/e2e/home.spec.ts +59 -0
- package/template-vue/eslint.config.js +18 -0
- package/template-vue/index.html.art +28 -0
- package/template-vue/lint-staged.config.js +6 -0
- package/template-vue/package.json +69 -0
- package/template-vue/public/vite.svg +1 -0
- package/template-vue/src/App.vue +7 -0
- package/template-vue/src/assets/svg-icons/vue.svg +1 -0
- package/template-vue/src/components/common/index.ts +1 -0
- package/template-vue/src/components/common/svg-icon/index.ts +1 -0
- package/template-vue/src/components/common/svg-icon/src/index.vue +29 -0
- package/template-vue/src/locales/en-US.json +3 -0
- package/template-vue/src/locales/zh-TW.json +3 -0
- package/template-vue/src/main.ts +21 -0
- package/template-vue/src/mocks/browser.ts +4 -0
- package/template-vue/src/mocks/handlers/index.ts +1 -0
- package/template-vue/src/mocks/server.ts +4 -0
- package/template-vue/src/pages/home/components/HelloWorld.test.ts +57 -0
- package/template-vue/src/pages/home/components/HelloWorld.vue +54 -0
- package/template-vue/src/pages/home/index.test.ts +17 -0
- package/template-vue/src/pages/home/index.vue +46 -0
- package/template-vue/src/plugins/i18n.ts +11 -0
- package/template-vue/src/router/index.ts +23 -0
- package/template-vue/src/stores/constants.ts.art +1 -0
- package/template-vue/src/stores/index.ts +15 -0
- package/template-vue/src/stores/modules/config.ts +20 -0
- package/template-vue/src/styles/base.css +59 -0
- package/template-vue/src/styles/common/all.css +1 -0
- package/template-vue/src/styles/common/button.css +15 -0
- package/template-vue/src/styles/index.css +3 -0
- package/template-vue/src/styles/tailwind.css +1 -0
- package/template-vue/src/test-utils/index.ts +33 -0
- package/template-vue/src/vite-env.d.ts +9 -0
- package/template-vue/tsconfig.app.json +12 -0
- package/template-vue/tsconfig.vitest.json +10 -0
- package/template-vue/vite.config.ts +46 -0
- package/template-vue/vitest.config.ts +18 -0
- package/template-vue/vitest.setup.ts +12 -0
package/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Scaffolding a basic `typescript` project.
|
|
4
4
|
|
|
5
5
|
> **Compatibility Note:**
|
|
6
|
+
>
|
|
6
7
|
> Requires [Node.js](https://nodejs.org/en/) version 20.19.6+. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
|
|
7
8
|
|
|
8
9
|
<p>
|
package/dist/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {}
|
package/dist/index.mjs
CHANGED
|
@@ -43,8 +43,8 @@ function toUpperCasePackageName(projectName) {
|
|
|
43
43
|
function getPkgManagerInfo() {
|
|
44
44
|
const userAgent = process.env.npm_config_user_agent;
|
|
45
45
|
if (!userAgent) return;
|
|
46
|
-
const [pkgManager] = userAgent.split(" ");
|
|
47
|
-
const [name, version] = pkgManager.split("/");
|
|
46
|
+
const [pkgManager] = userAgent.split(" ", 1);
|
|
47
|
+
const [name, version] = pkgManager.split("/", 2);
|
|
48
48
|
return {
|
|
49
49
|
name,
|
|
50
50
|
version
|
|
@@ -82,92 +82,98 @@ function styleTitle(title) {
|
|
|
82
82
|
return colors.bold(colors.magenta(title));
|
|
83
83
|
}
|
|
84
84
|
function operationPrompts({ targetDir, template, ci }) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return existsSync(dir) && !isEmptyFolder(dir) ? "select" : null;
|
|
96
|
-
},
|
|
97
|
-
name: "overwrite",
|
|
98
|
-
message: (nameAnswer) => {
|
|
99
|
-
const dirName = nameAnswer ?? targetDir;
|
|
100
|
-
return styleTitle(`${dirName === "." ? "current directory" : `Target directory "${dirName}"`} is not empty. Please choose how to proceed:`);
|
|
101
|
-
},
|
|
102
|
-
initial: 0,
|
|
103
|
-
choices: [
|
|
104
|
-
{
|
|
105
|
-
title: "Cancel operation",
|
|
106
|
-
value: "cancel"
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
title: "Remove existing files and continue",
|
|
110
|
-
value: "overwrite"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
title: "Ignore files and continue",
|
|
114
|
-
value: "ignore"
|
|
115
|
-
}
|
|
116
|
-
]
|
|
85
|
+
const projectName = {
|
|
86
|
+
type: targetDir ? null : "text",
|
|
87
|
+
name: "projectName",
|
|
88
|
+
message: styleTitle("Project name:"),
|
|
89
|
+
initial: DEFAULT_PROJECT_NAME
|
|
90
|
+
};
|
|
91
|
+
const overwrite = {
|
|
92
|
+
type: (nameAnswer) => {
|
|
93
|
+
const dir = nameAnswer ?? targetDir;
|
|
94
|
+
return existsSync(dir) && !isEmptyFolder(dir) ? "select" : null;
|
|
117
95
|
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
},
|
|
123
|
-
name: "overwriteChecker"
|
|
96
|
+
name: "overwrite",
|
|
97
|
+
message: (nameAnswer) => {
|
|
98
|
+
const dirName = nameAnswer ?? targetDir;
|
|
99
|
+
return styleTitle(`${dirName === "." ? "current directory" : `Target directory "${dirName}"`} is not empty. Please choose how to proceed:`);
|
|
124
100
|
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
101
|
+
initial: 0,
|
|
102
|
+
choices: [
|
|
103
|
+
{
|
|
104
|
+
title: "Cancel operation",
|
|
105
|
+
value: "cancel"
|
|
128
106
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return toValidPackageName(getProjectName(nameAnswer ?? targetDir));
|
|
107
|
+
{
|
|
108
|
+
title: "Remove existing files and continue",
|
|
109
|
+
value: "overwrite"
|
|
133
110
|
},
|
|
134
|
-
|
|
135
|
-
|
|
111
|
+
{
|
|
112
|
+
title: "Ignore files and continue",
|
|
113
|
+
value: "ignore"
|
|
136
114
|
}
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
const overwriteChecker = {
|
|
118
|
+
type: (overwriteAnswer) => {
|
|
119
|
+
if (overwriteAnswer === "cancel") onCancel();
|
|
120
|
+
return null;
|
|
121
|
+
},
|
|
122
|
+
name: "overwriteChecker"
|
|
123
|
+
};
|
|
124
|
+
const packageName = {
|
|
125
|
+
type: (_, { projectName: nameAnswer }) => {
|
|
126
|
+
return isValidPackageName(getProjectName(nameAnswer ?? targetDir)) ? null : "text";
|
|
137
127
|
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
initial: 0,
|
|
143
|
-
choices: [{
|
|
144
|
-
title: colors.green("Vue"),
|
|
145
|
-
value: "vue"
|
|
146
|
-
}, {
|
|
147
|
-
title: colors.blue("React"),
|
|
148
|
-
value: "react"
|
|
149
|
-
}]
|
|
128
|
+
name: "packageName",
|
|
129
|
+
message: styleTitle("Package name:"),
|
|
130
|
+
initial: (_, { projectName: nameAnswer }) => {
|
|
131
|
+
return toValidPackageName(getProjectName(nameAnswer ?? targetDir));
|
|
150
132
|
},
|
|
151
|
-
{
|
|
152
|
-
|
|
153
|
-
name: "ci",
|
|
154
|
-
message: styleTitle(ci ? `${colors.red(ci)} isn't a valid CI/CD. Please choose from below:` : "Choose CI/CD:"),
|
|
155
|
-
choices: [
|
|
156
|
-
{
|
|
157
|
-
title: "GitHub Actions",
|
|
158
|
-
value: "github-actions"
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
title: "GitLab CI",
|
|
162
|
-
value: "gitlab-ci"
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
title: "None",
|
|
166
|
-
value: "none"
|
|
167
|
-
}
|
|
168
|
-
],
|
|
169
|
-
initial: 0
|
|
133
|
+
validate: (name) => {
|
|
134
|
+
return isValidPackageName(name) || "Invalid package.json name";
|
|
170
135
|
}
|
|
136
|
+
};
|
|
137
|
+
const framework = {
|
|
138
|
+
type: builtinTemplate(template) ? null : "select",
|
|
139
|
+
name: "framework",
|
|
140
|
+
message: styleTitle(template ? `${colors.red(template)} isn't a valid template. Please choose from below:` : "Select a framework:"),
|
|
141
|
+
initial: 0,
|
|
142
|
+
choices: [{
|
|
143
|
+
title: colors.green("Vue"),
|
|
144
|
+
value: "vue"
|
|
145
|
+
}, {
|
|
146
|
+
title: colors.blue("React"),
|
|
147
|
+
value: "react"
|
|
148
|
+
}]
|
|
149
|
+
};
|
|
150
|
+
const ciPrompt = {
|
|
151
|
+
type: checkCi(ci) ? null : "select",
|
|
152
|
+
name: "ci",
|
|
153
|
+
message: styleTitle(ci ? `${colors.red(ci)} isn't a valid CI/CD. Please choose from below:` : "Choose CI/CD:"),
|
|
154
|
+
choices: [
|
|
155
|
+
{
|
|
156
|
+
title: "GitHub Actions",
|
|
157
|
+
value: "github-actions"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
title: "GitLab CI",
|
|
161
|
+
value: "gitlab-ci"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
title: "None",
|
|
165
|
+
value: "none"
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
initial: 0
|
|
169
|
+
};
|
|
170
|
+
return prompts([
|
|
171
|
+
projectName,
|
|
172
|
+
overwrite,
|
|
173
|
+
overwriteChecker,
|
|
174
|
+
packageName,
|
|
175
|
+
framework,
|
|
176
|
+
ciPrompt
|
|
171
177
|
], { onCancel });
|
|
172
178
|
}
|
|
173
179
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@component-hook/create-app",
|
|
3
|
-
"
|
|
4
|
-
"version": "1.5.0",
|
|
3
|
+
"version": "1.6.0",
|
|
5
4
|
"description": "Scaffolding a basic typescript project",
|
|
6
|
-
"author": "Tzuyi",
|
|
7
|
-
"license": "MIT",
|
|
8
5
|
"homepage": "https://github.com/tzuyi0817/component-hook/tree/master/packages/create-app#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/tzuyi0817/component-hook/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Tzuyi",
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
13
|
"url": "git+https://github.com/tzuyi0817/component-hook.git",
|
|
12
14
|
"directory": "packages/create-app"
|
|
13
15
|
},
|
|
14
|
-
"bugs": {
|
|
15
|
-
"url": "https://github.com/tzuyi0817/component-hook/issues"
|
|
16
|
-
},
|
|
17
16
|
"bin": {
|
|
18
17
|
"create-component-hook": "bin/index.js"
|
|
19
18
|
},
|
|
@@ -22,12 +21,10 @@
|
|
|
22
21
|
"dist",
|
|
23
22
|
"template-*"
|
|
24
23
|
],
|
|
25
|
-
"
|
|
26
|
-
"node": ">=20.19.6"
|
|
27
|
-
},
|
|
24
|
+
"type": "module",
|
|
28
25
|
"dependencies": {
|
|
29
|
-
"art-template": "^4.13.
|
|
30
|
-
"fs-extra": "^11.
|
|
26
|
+
"art-template": "^4.13.4",
|
|
27
|
+
"fs-extra": "^11.4.0",
|
|
31
28
|
"minimist": "^1.2.8",
|
|
32
29
|
"ora": "^9.4.1",
|
|
33
30
|
"picocolors": "^1.1.1",
|
|
@@ -38,6 +35,9 @@
|
|
|
38
35
|
"@types/minimist": "^1.2.5",
|
|
39
36
|
"@types/prompts": "^2.4.9"
|
|
40
37
|
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20.19.6"
|
|
40
|
+
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"dev": "tsdown --watch",
|
|
43
43
|
"build": "tsdown",
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.tabSize": 2,
|
|
3
|
+
"editor.formatOnSave": true,
|
|
4
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
5
|
+
|
|
6
|
+
"[json]": {
|
|
7
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
"debug.javascript.autoAttachFilter": "smart",
|
|
11
|
+
|
|
12
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
13
|
+
|
|
14
|
+
"workbench.editor.splitInGroupLayout": "vertical",
|
|
15
|
+
"terminal.integrated.shellIntegration.enabled": true,
|
|
16
|
+
|
|
17
|
+
"cSpell.words": ["dotenv", "unplugin", "Sonarjs", "typecheck", "pxtorem", "norem", "partialize"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
This project is built with [react](https://react.dev/) + [vite](https://vite.dev/), using [pnpm](https://pnpm.io/) for package management and [zustand](https://zustand-demo.pmnd.rs/) for state management.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Development Experience**: Written in [typeScript](https://www.typescriptlang.org/), styled with [tailwindcss](https://tailwindcss.com/), and structured with [react-router-dom](https://reactrouter.com/), and [react-i18next](https://react.i18next.com/). Supports SVGs ([vite-plugin-svg-icons](https://github.com/vbenjs/vite-plugin-svg-icons)).
|
|
8
|
+
- **API & Mocking**: Handles requests with [axios](https://axios-http.com/docs/intro) and mocks APIs using [msw](https://mswjs.io/).
|
|
9
|
+
- **Code Quality**: Enforces standards with [eslint](https://eslint.org/) and [prettier](https://prettier.io/), with [husky](https://www.npmjs.com/package/husky), [commitlint](https://commitlint.js.org/#/), and [lint-staged](https://github.com/okonet/lint-staged) for commit validation.
|
|
10
|
+
- **Testing**: Uses [vitest](https://vitest.dev/) + [testing-library](https://testing-library.com/) for unit testing and [playwright](https://playwright.dev/) for E2E testing.
|
|
11
|
+
- **Optimization**: Compresses CSS with [cssnano](https://cssnano.github.io/cssnano/), converts units with [postcss-pxtorem](https://www.npmjs.com/package/postcss-pxtorem), convert modern CSS into something most browsers can understand with [postcss-preset-env](https://www.npmjs.com/package/postcss-preset-env), and analyzes assets with [rollup-plugin-visualizer](https://github.com/btd/rollup-plugin-visualizer).
|
|
12
|
+
{{ciContent}}
|
|
13
|
+
|
|
14
|
+
## Code Features / Opinions
|
|
15
|
+
|
|
16
|
+
- Project root aliased as `@` to `<project_root>/src`
|
|
17
|
+
- ESlint plugin use [@component-hook/eslint-plugin](https://www.npmjs.com/package/@component-hook/eslint-plugin?activeTab=readme)
|
|
18
|
+
- if encounter npx: command not found, can execute `ln -s $(which npx) /usr/local/bin/npx` in zsh
|
|
19
|
+
- Predefined and fully typed global variables:
|
|
20
|
+
- `VITE_APP_VERSION` is read from `package.json` version at build time
|
|
21
|
+
- `VITE_APP_LAST_COMMIT_HASH` is last commit hash at build time
|
|
22
|
+
- `VITE_APP_BUILD_EPOCH` is populated as `Date.now()` at build time
|
|
23
|
+
- `VITE_APP_MOCK` is use mock environment
|
|
24
|
+
|
|
25
|
+
## Project Files
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
e2e/*
|
|
29
|
+
src/
|
|
30
|
+
├── assets/*
|
|
31
|
+
│ └── svg-icons
|
|
32
|
+
│ └── react.svg
|
|
33
|
+
├── components/
|
|
34
|
+
│ └── common
|
|
35
|
+
│ ├── svg-icon/
|
|
36
|
+
│ │ ├── src
|
|
37
|
+
│ │ │ └── index.tsx
|
|
38
|
+
│ │ └── index.ts
|
|
39
|
+
│ └── index.ts
|
|
40
|
+
├── constants/*
|
|
41
|
+
├── hooks/*
|
|
42
|
+
├── mocks/
|
|
43
|
+
│ ├── handlers/*
|
|
44
|
+
│ │ ├── modules/*
|
|
45
|
+
│ │ └── index.ts
|
|
46
|
+
│ │── browser.ts
|
|
47
|
+
│ └── server.ts
|
|
48
|
+
├── pages/
|
|
49
|
+
│ └── home/
|
|
50
|
+
│ ├── components
|
|
51
|
+
│ │ └── hello-world
|
|
52
|
+
│ │ ├── index.test.tsx
|
|
53
|
+
│ │ └── index.tsx
|
|
54
|
+
│ ├── index.module.css
|
|
55
|
+
│ ├── index.test.tsx
|
|
56
|
+
│ └── index.tsx
|
|
57
|
+
├── plugins/
|
|
58
|
+
│ └── i18n
|
|
59
|
+
│ ├── locales
|
|
60
|
+
│ │ ├── es-US.json
|
|
61
|
+
│ │ └── zh-TW.json
|
|
62
|
+
│ └── index.ts
|
|
63
|
+
├── router/
|
|
64
|
+
│ └── index.tsx
|
|
65
|
+
├── stores/
|
|
66
|
+
│ ├── modules
|
|
67
|
+
│ │ └── config.ts
|
|
68
|
+
│ ├── constants.ts
|
|
69
|
+
│ ├── index.ts
|
|
70
|
+
│ └── middleware.ts
|
|
71
|
+
├── styles/
|
|
72
|
+
│ ├── common/
|
|
73
|
+
| │ ├── all.css
|
|
74
|
+
| │ └── button.css
|
|
75
|
+
│ ├── base.css
|
|
76
|
+
│ ├── index.css
|
|
77
|
+
│ └── tailwind.css
|
|
78
|
+
├── test-utils/
|
|
79
|
+
│ └── index.tsx
|
|
80
|
+
├── types/*
|
|
81
|
+
├── utils/*
|
|
82
|
+
├── App.tsx
|
|
83
|
+
├── vite-env.d.ts
|
|
84
|
+
└── main.tsx
|
|
85
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { expect, test } from '@playwright/test';
|
|
2
|
+
|
|
3
|
+
test.beforeEach(async ({ page }) => {
|
|
4
|
+
await page.goto('/');
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
test('click Vite logo open Vite official website blank tab', async ({ page }) => {
|
|
8
|
+
const link = page.getByRole('link', { name: /vite logo/i });
|
|
9
|
+
|
|
10
|
+
await expect(link).toBeVisible();
|
|
11
|
+
const [popup] = await Promise.all([page.waitForEvent('popup'), link.evaluate((node: HTMLElement) => node.click())]);
|
|
12
|
+
|
|
13
|
+
await popup.waitForLoadState();
|
|
14
|
+
await expect(popup).toHaveTitle('Vite | Next Generation Frontend Tooling');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('click React logo open React official website blank tab', async ({ page }) => {
|
|
18
|
+
await page.addStyleTag({ content: `* { animation: none !important; }` });
|
|
19
|
+
const link = page.getByLabel(/react link/i);
|
|
20
|
+
|
|
21
|
+
await expect(link).toBeVisible();
|
|
22
|
+
const [popup] = await Promise.all([page.waitForEvent('popup'), link.evaluate((node: HTMLElement) => node.click())]);
|
|
23
|
+
|
|
24
|
+
await popup.waitForLoadState();
|
|
25
|
+
await expect(popup).toHaveTitle('React');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('homepage count button interact', async ({ page }) => {
|
|
29
|
+
await page.getByRole('button', { name: 'count is 0' }).click();
|
|
30
|
+
await expect(page.getByRole('button', { name: 'count is 1' })).toBeVisible();
|
|
31
|
+
await page.getByRole('button', { name: 'count is 1' }).click();
|
|
32
|
+
await expect(page.getByRole('button', { name: 'count is 2' })).toBeVisible();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('locale change interact', async ({ page }) => {
|
|
36
|
+
await page.getByRole('button', { name: 'English' }).click();
|
|
37
|
+
await expect(page.getByRole('button', { name: '中文' })).toBeVisible();
|
|
38
|
+
await page.getByRole('button', { name: '中文' }).click();
|
|
39
|
+
await expect(page.getByRole('button', { name: 'English' })).toBeVisible();
|
|
40
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import componentHookPlugin from '@component-hook/eslint-plugin';
|
|
2
|
+
|
|
3
|
+
export default [
|
|
4
|
+
...componentHookPlugin.configs.basic,
|
|
5
|
+
...componentHookPlugin.configs.react,
|
|
6
|
+
componentHookPlugin.configs.prettier,
|
|
7
|
+
...componentHookPlugin.configs.sonarjs,
|
|
8
|
+
componentHookPlugin.configs.security,
|
|
9
|
+
...componentHookPlugin.configs.markdown,
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.test.[jt]s?(x)'],
|
|
12
|
+
...componentHookPlugin.configs['testing-library/react'],
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
files: ['**/e2e/**/*.spec.[jt]s?(x)'],
|
|
16
|
+
...componentHookPlugin.configs.playwright,
|
|
17
|
+
},
|
|
18
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<title>{{projectName}}</title>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"></div>
|
|
11
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
12
|
+
</body>
|
|
13
|
+
</html>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-starter",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"dev:mock": "cross-env MOCK=true vite",
|
|
9
|
+
"build": "pnpm typecheck && vite build",
|
|
10
|
+
"lint": "eslint --fix .",
|
|
11
|
+
"test:unit": "vitest --coverage",
|
|
12
|
+
"test:e2e": "playwright test --headed",
|
|
13
|
+
"test:ui-e2e": "playwright test --ui",
|
|
14
|
+
"test:ci-e2e": "playwright test",
|
|
15
|
+
"typecheck": "tsc --noEmit",
|
|
16
|
+
"prepare": "husky",
|
|
17
|
+
"preview": "vite preview"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"axios": "^1.20.0",
|
|
21
|
+
"i18next": "^26.4.2",
|
|
22
|
+
"react": "^19.3.0",
|
|
23
|
+
"react-dom": "^19.3.0",
|
|
24
|
+
"react-i18next": "^17.0.14",
|
|
25
|
+
"react-router-dom": "^7.18.4",
|
|
26
|
+
"zustand": "^5.0.15"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@component-hook/eslint-plugin": "^1.5.1",
|
|
30
|
+
"@playwright/test": "^1.63.0",
|
|
31
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
32
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
33
|
+
"@testing-library/react": "^16.3.3",
|
|
34
|
+
"@testing-library/user-event": "^14.6.7",
|
|
35
|
+
"@tsconfig/node24": "^24.0.5",
|
|
36
|
+
"@types/node": "^24.13.5",
|
|
37
|
+
"@types/react": "^19.3.0",
|
|
38
|
+
"@types/react-dom": "^19.3.0",
|
|
39
|
+
"@vitejs/plugin-react-swc": "^4.3.3",
|
|
40
|
+
"@vitest/coverage-v8": "^5.0.1",
|
|
41
|
+
"cross-env": "^10.1.0",
|
|
42
|
+
"cssnano": "^9.0.5",
|
|
43
|
+
"eslint": "^9.39.5",
|
|
44
|
+
"fast-glob": "^3.3.3",
|
|
45
|
+
"jsdom": "^30.1.0",
|
|
46
|
+
"msw": "^2.15.0",
|
|
47
|
+
"postcss": "^8.5.28",
|
|
48
|
+
"postcss-preset-env": "^11.5.3",
|
|
49
|
+
"postcss-pxtorem": "^6.1.0",
|
|
50
|
+
"prettier": "^3.9.8",
|
|
51
|
+
"prettier-plugin-tailwindcss": "^0.8.1",
|
|
52
|
+
"tailwindcss": "^4.3.3",
|
|
53
|
+
"typescript": "^6.0.3",
|
|
54
|
+
"vite": "^8.3.0",
|
|
55
|
+
"vite-plugin-svg-icons": "^2.0.1",
|
|
56
|
+
"vitest": "^5.0.1"
|
|
57
|
+
},
|
|
58
|
+
"optionalDependencies": {
|
|
59
|
+
"@commitlint/cli": "^21.2.2",
|
|
60
|
+
"@commitlint/config-conventional": "^21.2.2",
|
|
61
|
+
"husky": "^9.1.7",
|
|
62
|
+
"lint-staged": "^17.5.1"
|
|
63
|
+
},
|
|
64
|
+
"packageManager": "pnpm@12.4.2",
|
|
65
|
+
"msw": {
|
|
66
|
+
"workerDirectory": [
|
|
67
|
+
"public"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './svg-icon';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SvgIcon } from './src/index';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { HTMLAttributes } from 'react';
|
|
2
|
+
|
|
3
|
+
type Props = HTMLAttributes<SVGElement> & {
|
|
4
|
+
name: string;
|
|
5
|
+
prefix?: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function SvgIcon({ name, prefix = 'icon', color = '#333', ...props }: Props) {
|
|
10
|
+
const symbolId = `#${prefix}-${name}`;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<svg
|
|
14
|
+
{...props}
|
|
15
|
+
aria-hidden="true"
|
|
16
|
+
>
|
|
17
|
+
<use
|
|
18
|
+
href={symbolId}
|
|
19
|
+
fill={color}
|
|
20
|
+
/>
|
|
21
|
+
</svg>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StrictMode } from 'react';
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
|
+
import { App } from './App.tsx';
|
|
4
|
+
|
|
5
|
+
import 'virtual:svg-icons-register';
|
|
6
|
+
import '@/plugins/i18n';
|
|
7
|
+
import '@/styles/index.css';
|
|
8
|
+
|
|
9
|
+
const root = createRoot(document.querySelector('#root') as HTMLElement);
|
|
10
|
+
const isDev = import.meta.env.DEV;
|
|
11
|
+
|
|
12
|
+
if (import.meta.env.VITE_APP_MOCK === 'service-worker') {
|
|
13
|
+
const { worker } = await import('@/mocks/browser');
|
|
14
|
+
|
|
15
|
+
worker.start();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (isDev) {
|
|
19
|
+
root.render(<App />);
|
|
20
|
+
} else {
|
|
21
|
+
root.render(
|
|
22
|
+
<StrictMode>
|
|
23
|
+
<App />
|
|
24
|
+
</StrictMode>,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const handlers = [];
|