@qlover/create-app 0.0.1
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/CHANGELOG.md +10 -0
- package/bin/create-app.js +28 -0
- package/dist/cjs/index.d.ts +67 -0
- package/dist/cjs/index.js +1 -0
- package/dist/es/index.d.ts +67 -0
- package/dist/es/index.js +1 -0
- package/package.json +60 -0
- package/templates/fe-react/.env +3 -0
- package/templates/fe-react/README.md +50 -0
- package/templates/fe-react/config/app.common.ts +52 -0
- package/templates/fe-react/config/app.router.json +150 -0
- package/templates/fe-react/config/feapi.mock.json +14 -0
- package/templates/fe-react/config/i18n.ts +21 -0
- package/templates/fe-react/config/theme.json +90 -0
- package/templates/fe-react/eslint.config.js +31 -0
- package/templates/fe-react/index.html +13 -0
- package/templates/fe-react/lib/fe-react-controller/FeController.ts +15 -0
- package/templates/fe-react/lib/fe-react-controller/index.ts +2 -0
- package/templates/fe-react/lib/fe-react-controller/useController.ts +71 -0
- package/templates/fe-react/lib/fe-react-theme/ThemeController.ts +40 -0
- package/templates/fe-react/lib/fe-react-theme/ThemeStateGetter.ts +53 -0
- package/templates/fe-react/lib/fe-react-theme/index.ts +3 -0
- package/templates/fe-react/lib/fe-react-theme/tw-generator.js +239 -0
- package/templates/fe-react/lib/fe-react-theme/type.ts +21 -0
- package/templates/fe-react/lib/openAiApi/OpenAIAuthPlugin.ts +29 -0
- package/templates/fe-react/lib/openAiApi/OpenAIClient.ts +51 -0
- package/templates/fe-react/lib/openAiApi/StreamProcessor.ts +81 -0
- package/templates/fe-react/lib/openAiApi/index.ts +3 -0
- package/templates/fe-react/lib/request-common-plugin/index.ts +169 -0
- package/templates/fe-react/lib/tw-root10px/index.css +4 -0
- package/templates/fe-react/lib/tw-root10px/index.js +178 -0
- package/templates/fe-react/package.json +49 -0
- package/templates/fe-react/postcss.config.js +6 -0
- package/templates/fe-react/public/locales/en/about.json +3 -0
- package/templates/fe-react/public/locales/en/common.json +6 -0
- package/templates/fe-react/public/locales/en/executor.json +6 -0
- package/templates/fe-react/public/locales/en/home.json +10 -0
- package/templates/fe-react/public/locales/en/jsonStorage.json +11 -0
- package/templates/fe-react/public/locales/en/login.json +7 -0
- package/templates/fe-react/public/locales/en/request.json +15 -0
- package/templates/fe-react/public/locales/zh/about.json +3 -0
- package/templates/fe-react/public/locales/zh/common.json +7 -0
- package/templates/fe-react/public/locales/zh/executor.json +7 -0
- package/templates/fe-react/public/locales/zh/home.json +10 -0
- package/templates/fe-react/public/locales/zh/jsonStorage.json +11 -0
- package/templates/fe-react/public/locales/zh/login.json +8 -0
- package/templates/fe-react/public/locales/zh/request.json +15 -0
- package/templates/fe-react/public/logo.svg +1 -0
- package/templates/fe-react/src/App.tsx +20 -0
- package/templates/fe-react/src/assets/react.svg +1 -0
- package/templates/fe-react/src/components/Loading.tsx +41 -0
- package/templates/fe-react/src/components/LocaleLink.tsx +42 -0
- package/templates/fe-react/src/components/ProcessProvider.tsx +41 -0
- package/templates/fe-react/src/components/ThemeSwitcher.tsx +29 -0
- package/templates/fe-react/src/containers/context/BaseRouteContext.ts +27 -0
- package/templates/fe-react/src/containers/context/BaseRouteProvider.tsx +11 -0
- package/templates/fe-react/src/containers/globals.ts +31 -0
- package/templates/fe-react/src/containers/index.ts +71 -0
- package/templates/fe-react/src/hooks/useLanguageGuard.ts +25 -0
- package/templates/fe-react/src/hooks/useStrictEffect.ts +29 -0
- package/templates/fe-react/src/main.tsx +15 -0
- package/templates/fe-react/src/pages/404.tsx +14 -0
- package/templates/fe-react/src/pages/500.tsx +14 -0
- package/templates/fe-react/src/pages/auth/Layout.tsx +14 -0
- package/templates/fe-react/src/pages/auth/Login.tsx +62 -0
- package/templates/fe-react/src/pages/auth/Register.tsx +3 -0
- package/templates/fe-react/src/pages/base/About.tsx +12 -0
- package/templates/fe-react/src/pages/base/Executor.tsx +38 -0
- package/templates/fe-react/src/pages/base/Home.tsx +78 -0
- package/templates/fe-react/src/pages/base/JSONStorage.tsx +124 -0
- package/templates/fe-react/src/pages/base/Layout.tsx +17 -0
- package/templates/fe-react/src/pages/base/RedirectPathname.tsx +15 -0
- package/templates/fe-react/src/pages/base/Request.tsx +91 -0
- package/templates/fe-react/src/pages/base/components/BaseHeader.tsx +19 -0
- package/templates/fe-react/src/pages/index.tsx +108 -0
- package/templates/fe-react/src/services/controllers/ExecutorController.ts +56 -0
- package/templates/fe-react/src/services/controllers/JSONStorageController.ts +42 -0
- package/templates/fe-react/src/services/controllers/RequestController.ts +105 -0
- package/templates/fe-react/src/services/controllers/RouterController.ts +90 -0
- package/templates/fe-react/src/services/controllers/UserController.ts +146 -0
- package/templates/fe-react/src/services/feApi/FeApi.ts +51 -0
- package/templates/fe-react/src/services/feApi/FeApiMockPlugin.ts +42 -0
- package/templates/fe-react/src/services/feApi/FeApiType.ts +55 -0
- package/templates/fe-react/src/services/feApi/index.ts +2 -0
- package/templates/fe-react/src/services/i18n/index.ts +50 -0
- package/templates/fe-react/src/services/pageProcesser/PageProcesser.ts +29 -0
- package/templates/fe-react/src/services/pageProcesser/index.ts +1 -0
- package/templates/fe-react/src/styles/css/index.css +2 -0
- package/templates/fe-react/src/styles/css/page.css +3 -0
- package/templates/fe-react/src/styles/css/tailwind.css +3 -0
- package/templates/fe-react/src/types/Page.ts +49 -0
- package/templates/fe-react/src/types/UIDependenciesInterface.ts +31 -0
- package/templates/fe-react/src/types/global.d.ts +7 -0
- package/templates/fe-react/src/utils/RequestLogger.ts +34 -0
- package/templates/fe-react/src/utils/datetime.ts +25 -0
- package/templates/fe-react/src/utils/thread.ts +3 -0
- package/templates/fe-react/src/vite-env.d.ts +1 -0
- package/templates/fe-react/tailwind.config.js +18 -0
- package/templates/fe-react/tsconfig.app.json +29 -0
- package/templates/fe-react/tsconfig.json +7 -0
- package/templates/fe-react/tsconfig.node.json +22 -0
- package/templates/fe-react/vite.config.ts +32 -0
- package/templates/pack-app/.editorconfig +23 -0
- package/templates/pack-app/.env +5 -0
- package/templates/pack-app/.env.template +6 -0
- package/templates/pack-app/.gitattributes +2 -0
- package/templates/pack-app/.github/workflows/general-check.yml +50 -0
- package/templates/pack-app/.github/workflows/release.yml.template +110 -0
- package/templates/pack-app/.prettierignore +5 -0
- package/templates/pack-app/.prettierrc.js +3 -0
- package/templates/pack-app/CHANGELOG.md +0 -0
- package/templates/pack-app/README.md +1 -0
- package/templates/pack-app/eslint.config.js +77 -0
- package/templates/pack-app/fe-config.json +10 -0
- package/templates/pack-app/jest.config.js +31 -0
- package/templates/pack-app/package.json +66 -0
- package/templates/pack-app/packages/browser/__tests__/calc.test.ts +9 -0
- package/templates/pack-app/packages/browser/package.json +11 -0
- package/templates/pack-app/packages/browser/rollup.config.js +70 -0
- package/templates/pack-app/packages/browser/src/calc.ts +3 -0
- package/templates/pack-app/packages/browser/src/index.ts +1 -0
- package/templates/pack-app/packages/browser/tsconfig.json +15 -0
- package/templates/pack-app/packages/node/__tests__/readJson.test.ts +25 -0
- package/templates/pack-app/packages/node/package.json +11 -0
- package/templates/pack-app/packages/node/rollup.config.js +89 -0
- package/templates/pack-app/packages/node/src/index.ts +7 -0
- package/templates/pack-app/packages/node/src/readJson.ts +6 -0
- package/templates/pack-app/packages/node/tsconfig.json +17 -0
- package/templates/pack-app/packages/react-vite-lib/README.md +50 -0
- package/templates/pack-app/packages/react-vite-lib/__tests__/Sum.test.ts +9 -0
- package/templates/pack-app/packages/react-vite-lib/__tests__/Text.test.tsx +11 -0
- package/templates/pack-app/packages/react-vite-lib/eslint.config.js +28 -0
- package/templates/pack-app/packages/react-vite-lib/index.html +13 -0
- package/templates/pack-app/packages/react-vite-lib/package.json +30 -0
- package/templates/pack-app/packages/react-vite-lib/public/vite.svg +1 -0
- package/templates/pack-app/packages/react-vite-lib/src/calc.ts +3 -0
- package/templates/pack-app/packages/react-vite-lib/src/commponents/Text.tsx +7 -0
- package/templates/pack-app/packages/react-vite-lib/src/index.ts +2 -0
- package/templates/pack-app/packages/react-vite-lib/src/vite-env.d.ts +1 -0
- package/templates/pack-app/packages/react-vite-lib/tsconfig.json +25 -0
- package/templates/pack-app/packages/react-vite-lib/vite.config.ts +24 -0
- package/templates/pack-app/pnpm-workspace.yaml +2 -0
- package/templates/pack-app/tsconfig.json +9 -0
- package/templates/pack-app/tsconfig.test.json +10 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
name: Release [PATH_NAMES]
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
pull_request:
|
|
6
|
+
branches:
|
|
7
|
+
- master
|
|
8
|
+
types:
|
|
9
|
+
- closed
|
|
10
|
+
paths:
|
|
11
|
+
- [PATH_NAMES]/**
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
release-PR:
|
|
15
|
+
# only run when PR merged and has changes:[PATH_NAMES] and CI-Release labels
|
|
16
|
+
if: |
|
|
17
|
+
github.event.pull_request.merged == true &&
|
|
18
|
+
contains(github.event.pull_request.labels.*.name, 'changes:[PATH_NAMES]') &&
|
|
19
|
+
!contains(github.event.pull_request.labels.*.name, 'CI-Release')
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout repository
|
|
24
|
+
uses: actions/checkout@v3
|
|
25
|
+
with:
|
|
26
|
+
fetch-depth: 0
|
|
27
|
+
# ref: ${{ github.head_ref || github.ref_name }}
|
|
28
|
+
|
|
29
|
+
- name: Config Git
|
|
30
|
+
run: |
|
|
31
|
+
git config --global user.name "github-actions[bot]"
|
|
32
|
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
33
|
+
- name: Install Node.js
|
|
34
|
+
uses: actions/setup-node@v2
|
|
35
|
+
with:
|
|
36
|
+
node-version: '18.19.0'
|
|
37
|
+
|
|
38
|
+
- name: Install dependencies
|
|
39
|
+
run: |
|
|
40
|
+
npm install -g yarn
|
|
41
|
+
yarn
|
|
42
|
+
|
|
43
|
+
- name: Lint
|
|
44
|
+
run: yarn lint
|
|
45
|
+
|
|
46
|
+
- name: Test
|
|
47
|
+
run: yarn test
|
|
48
|
+
|
|
49
|
+
- name: Build dist
|
|
50
|
+
run: yarn build
|
|
51
|
+
|
|
52
|
+
- name: Create release PR
|
|
53
|
+
run: npm run release-pr:[PATH_NAMES]
|
|
54
|
+
env:
|
|
55
|
+
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN}}
|
|
56
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
|
|
57
|
+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
|
|
58
|
+
|
|
59
|
+
release:
|
|
60
|
+
# only run when PR merged and has changes:[PATH_NAMES] and CI-Release labels
|
|
61
|
+
if: |
|
|
62
|
+
github.event.pull_request.merged == true &&
|
|
63
|
+
contains(github.event.pull_request.labels.*.name, 'changes:[PATH_NAMES]') &&
|
|
64
|
+
contains(github.event.pull_request.labels.*.name, 'CI-Release')
|
|
65
|
+
|
|
66
|
+
runs-on: ubuntu-latest
|
|
67
|
+
|
|
68
|
+
steps:
|
|
69
|
+
- name: Checkout repository
|
|
70
|
+
uses: actions/checkout@v3
|
|
71
|
+
with:
|
|
72
|
+
fetch-depth: 0
|
|
73
|
+
# ref: ${{ github.head_ref || github.ref_name }}
|
|
74
|
+
|
|
75
|
+
- name: Config Git
|
|
76
|
+
run: |
|
|
77
|
+
git config --global user.name "github-actions[bot]"
|
|
78
|
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
79
|
+
|
|
80
|
+
- name: Install Node.js
|
|
81
|
+
uses: actions/setup-node@v2
|
|
82
|
+
with:
|
|
83
|
+
node-version: '18.19.0'
|
|
84
|
+
|
|
85
|
+
- name: Install dependencies
|
|
86
|
+
run: |
|
|
87
|
+
npm install -g yarn
|
|
88
|
+
yarn
|
|
89
|
+
|
|
90
|
+
- name: Lint
|
|
91
|
+
run: yarn lint
|
|
92
|
+
|
|
93
|
+
- name: Test
|
|
94
|
+
run: yarn test
|
|
95
|
+
|
|
96
|
+
- name: Build dist
|
|
97
|
+
run: yarn build
|
|
98
|
+
|
|
99
|
+
- name: Create tag and publish
|
|
100
|
+
run: npm run release:[PATH_NAMES]
|
|
101
|
+
env:
|
|
102
|
+
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN}}
|
|
103
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN}}
|
|
104
|
+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
|
|
105
|
+
|
|
106
|
+
- name: Debug Git status
|
|
107
|
+
run: |
|
|
108
|
+
git status
|
|
109
|
+
git branch
|
|
110
|
+
git rev-parse --abbrev-ref HEAD
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# fe pack-app
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
2
|
+
import jest from 'eslint-plugin-jest';
|
|
3
|
+
import * as eslintChain from '@qlover/fe-standard/eslint/index.js';
|
|
4
|
+
import reactEslint from './packages/react-vite-lib/eslint.config.js';
|
|
5
|
+
|
|
6
|
+
const { createCommon, createTslintRecommended, chainEnv } = eslintChain;
|
|
7
|
+
const allGlobals = {
|
|
8
|
+
...globals.browser,
|
|
9
|
+
...globals.node,
|
|
10
|
+
...globals.jest
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function createBrowserConfig() {
|
|
14
|
+
return chainEnv({
|
|
15
|
+
allGlobals,
|
|
16
|
+
files: ['packages/browser/**/*.ts'],
|
|
17
|
+
languageOptions: {
|
|
18
|
+
globals: globals.browser
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function createNodeConfig() {
|
|
24
|
+
return chainEnv({
|
|
25
|
+
allGlobals,
|
|
26
|
+
files: ['packages/node/**/*.ts'],
|
|
27
|
+
languageOptions: {
|
|
28
|
+
globals: globals.node
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function createReactConfig() {
|
|
34
|
+
return chainEnv({
|
|
35
|
+
allGlobals,
|
|
36
|
+
files: ['packages/react/**/*.tsx'],
|
|
37
|
+
...reactEslint
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createJESTConfig() {
|
|
42
|
+
const config = chainEnv({
|
|
43
|
+
allGlobals,
|
|
44
|
+
files: ['packages/**/*.test.ts', 'packages/**/*.test.js'],
|
|
45
|
+
plugins: {
|
|
46
|
+
jest
|
|
47
|
+
},
|
|
48
|
+
languageOptions: {
|
|
49
|
+
globals: {
|
|
50
|
+
// ...globals.browser,
|
|
51
|
+
...globals.node,
|
|
52
|
+
...globals.jest
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return config;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @type {import('eslint').Linter.Config[]}
|
|
61
|
+
*/
|
|
62
|
+
export default [
|
|
63
|
+
{
|
|
64
|
+
ignores: ['**/dist/**', '**/build/**', '**/node_modules/**', 'templates/**']
|
|
65
|
+
},
|
|
66
|
+
// common js and ts
|
|
67
|
+
createCommon(),
|
|
68
|
+
createTslintRecommended(['packages/**/*.ts']),
|
|
69
|
+
// browser
|
|
70
|
+
createBrowserConfig(),
|
|
71
|
+
// node
|
|
72
|
+
createNodeConfig(),
|
|
73
|
+
// react
|
|
74
|
+
createReactConfig(),
|
|
75
|
+
// jest
|
|
76
|
+
createJESTConfig()
|
|
77
|
+
];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import tsJestConfig from '@qlover/fe-standard/config/jest.esm.js';
|
|
2
|
+
|
|
3
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
4
|
+
export default {
|
|
5
|
+
// ...tsJestConfig,
|
|
6
|
+
testEnvironment: 'jest-environment-jsdom',
|
|
7
|
+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
|
|
8
|
+
projects: [
|
|
9
|
+
{
|
|
10
|
+
...tsJestConfig,
|
|
11
|
+
displayName: 'pack-app-node',
|
|
12
|
+
testMatch: tsJestConfig.testMatch.map(
|
|
13
|
+
(item) => '<rootDir>/packages/node/' + item
|
|
14
|
+
)
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
...tsJestConfig,
|
|
18
|
+
displayName: 'pack-app-browser',
|
|
19
|
+
testMatch: tsJestConfig.testMatch.map(
|
|
20
|
+
(item) => '<rootDir>/packages/browser/' + item
|
|
21
|
+
)
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
...tsJestConfig,
|
|
25
|
+
displayName: 'pack-app-react',
|
|
26
|
+
testEnvironment: 'jest-environment-jsdom',
|
|
27
|
+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
|
|
28
|
+
testMatch: ['<rootDir>/packages/react-vite-lib/__tests__/**/*.test.tsx']
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qlover/pack-app",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "A template for fe-pack-app",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": true,
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "github",
|
|
9
|
+
"url": "https://github.com/qlover/fe-base"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/qlover/fe-base#readme",
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "pnpm run build:node && pnpm run build:browser && pnpm run build:react",
|
|
14
|
+
"build:node": "pnpm run build --filter=@qlover/pack-app-node",
|
|
15
|
+
"build:browser": "pnpm run build --filter=@qlover/pack-app-browser",
|
|
16
|
+
"build:react": "pnpm run build --filter=@qlover/pack-app-react",
|
|
17
|
+
"prettier": "prettier --ignore-path .prettierignore **/*.{js,ts,json,cjs,mjs} --write",
|
|
18
|
+
"lint": "eslint . --fix",
|
|
19
|
+
"test": "jest",
|
|
20
|
+
"clean": "fe-clean",
|
|
21
|
+
"clean:build": "fe-clean -f packages/*/dist -r",
|
|
22
|
+
"check-packages": "fe-check-packages",
|
|
23
|
+
"commit": "fe-commit",
|
|
24
|
+
"clean-branch": "fe-clean-branch"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"template",
|
|
28
|
+
"fe-pack-app"
|
|
29
|
+
],
|
|
30
|
+
"author": "qlover",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"devEngines": {
|
|
33
|
+
"node": ">=18.19.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@qlover/fe-scripts": "^0.5.1",
|
|
37
|
+
"@qlover/fe-standard": "^0.0.2",
|
|
38
|
+
"@qlover/fe-utils": "^1.1.3",
|
|
39
|
+
"@rollup/plugin-commonjs": "^28.0.1",
|
|
40
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
41
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
42
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
43
|
+
"@rollup/plugin-typescript": "^12.1.1",
|
|
44
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
45
|
+
"@testing-library/react": "^16.1.0",
|
|
46
|
+
"@types/jest": "^29.5.11",
|
|
47
|
+
"eslint": "^9.17.0",
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
50
|
+
"rollup": "^4.24.2",
|
|
51
|
+
"rollup-plugin-delete": "^2.1.0",
|
|
52
|
+
"rollup-plugin-dts": "^6.1.1",
|
|
53
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
54
|
+
"ts-node": "^10.9.2",
|
|
55
|
+
"typescript": "~5.4.0"
|
|
56
|
+
},
|
|
57
|
+
"workspaces": [
|
|
58
|
+
"packages/*"
|
|
59
|
+
],
|
|
60
|
+
"lint-staged": {
|
|
61
|
+
"*.{js,jsx,ts,tsx}": [
|
|
62
|
+
"eslint --fix"
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
"packageManager": "pnpm@9.1.0"
|
|
66
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
+
import typescript from 'rollup-plugin-typescript2';
|
|
4
|
+
import dts from 'rollup-plugin-dts';
|
|
5
|
+
import terser from '@rollup/plugin-terser';
|
|
6
|
+
import { searchEnv } from '@qlover/fe-scripts';
|
|
7
|
+
import del from 'rollup-plugin-delete';
|
|
8
|
+
import { readFileSync } from 'fs';
|
|
9
|
+
|
|
10
|
+
const tsConfig = JSON.parse(readFileSync('./tsconfig.json', 'utf-8'));
|
|
11
|
+
const env = searchEnv({ logger: console });
|
|
12
|
+
const NODE_ENV = env.get('NODE_ENV');
|
|
13
|
+
const isProduction = NODE_ENV === 'production';
|
|
14
|
+
console.log('Enveronment is', NODE_ENV);
|
|
15
|
+
|
|
16
|
+
const buildDir = tsConfig.compilerOptions.outDir;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {{ entry: string, formats: string[], external: string[], target: string, clean: boolean }} options
|
|
20
|
+
* @returns {import('rollup').RollupOptions[]}
|
|
21
|
+
*/
|
|
22
|
+
function createBuilder({ target, entry, formats, external, clean, umdName }) {
|
|
23
|
+
target = target || `${buildDir}/${entry}`;
|
|
24
|
+
|
|
25
|
+
/** @type {import('rollup').OutputOptions[]} */
|
|
26
|
+
const outputs = formats.map((format) => ({
|
|
27
|
+
file: `${target}/index.${format}.js`,
|
|
28
|
+
format,
|
|
29
|
+
name: umdName,
|
|
30
|
+
sourcemap: !isProduction
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
input: `./${entry}/index.ts`,
|
|
36
|
+
output: outputs,
|
|
37
|
+
plugins: [
|
|
38
|
+
clean && del({ targets: `${buildDir}/*` }),
|
|
39
|
+
resolve({
|
|
40
|
+
preferBuiltins: false
|
|
41
|
+
}),
|
|
42
|
+
commonjs(),
|
|
43
|
+
typescript({ tsconfig: './tsconfig.json' }),
|
|
44
|
+
isProduction && terser()
|
|
45
|
+
],
|
|
46
|
+
external: external
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
input: `./${entry}/index.ts`,
|
|
50
|
+
output: {
|
|
51
|
+
file: `${target}/index.d.ts`,
|
|
52
|
+
format: 'es'
|
|
53
|
+
},
|
|
54
|
+
plugins: [dts()]
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @type {import('rollup').RollupOptions[]}
|
|
61
|
+
*/
|
|
62
|
+
export default [
|
|
63
|
+
...createBuilder({
|
|
64
|
+
entry: 'src',
|
|
65
|
+
formats: ['es', 'umd'],
|
|
66
|
+
target: buildDir,
|
|
67
|
+
umdName: 'PackAppBrowser',
|
|
68
|
+
clean: true
|
|
69
|
+
})
|
|
70
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './calc';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES5",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"declaration": false,
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"moduleResolution": "Node",
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"baseUrl": "./"
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readJson } from '../src/readJson';
|
|
2
|
+
import { writeFileSync, unlinkSync } from 'fs';
|
|
3
|
+
|
|
4
|
+
describe('readJson 函数测试', () => {
|
|
5
|
+
const testFilePath = './test.json';
|
|
6
|
+
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
// 创建一个测试文件
|
|
9
|
+
writeFileSync(testFilePath, JSON.stringify({ key: 'value' }));
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterAll(() => {
|
|
13
|
+
// 删除测试文件
|
|
14
|
+
unlinkSync(testFilePath);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('应该正确读取 JSON 文件', () => {
|
|
18
|
+
const result = readJson(testFilePath);
|
|
19
|
+
expect(result).toEqual({ key: 'value' });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('应该抛出错误当文件不存在时', () => {
|
|
23
|
+
expect(() => readJson('./nonexistent.json')).toThrow();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve';
|
|
2
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
3
|
+
import json from '@rollup/plugin-json';
|
|
4
|
+
import terser from '@rollup/plugin-terser';
|
|
5
|
+
import dts from 'rollup-plugin-dts';
|
|
6
|
+
import typescript from 'rollup-plugin-typescript2';
|
|
7
|
+
import { builtinModules } from 'module';
|
|
8
|
+
import { readFileSync, rmSync } from 'fs';
|
|
9
|
+
|
|
10
|
+
const pkg = JSON.parse(readFileSync('./package.json'), 'utf-8');
|
|
11
|
+
const tsConfig = JSON.parse(readFileSync('./tsconfig.json'), 'utf-8');
|
|
12
|
+
|
|
13
|
+
const isProduction = false;
|
|
14
|
+
const buildDir = tsConfig.compilerOptions.outDir;
|
|
15
|
+
|
|
16
|
+
const treeshake = {
|
|
17
|
+
moduleSideEffects: false,
|
|
18
|
+
propertyReadSideEffects: false,
|
|
19
|
+
tryCatchDeoptimization: false
|
|
20
|
+
};
|
|
21
|
+
const defaultExternal = [
|
|
22
|
+
...builtinModules,
|
|
23
|
+
...builtinModules.map((mod) => `node:${mod}`),
|
|
24
|
+
...Object.keys(pkg.dependencies || {}),
|
|
25
|
+
...Object.keys(pkg.devDependencies || {})
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
function createPlugin(minify) {
|
|
29
|
+
return [
|
|
30
|
+
resolve({
|
|
31
|
+
preferBuiltins: false
|
|
32
|
+
}),
|
|
33
|
+
commonjs(),
|
|
34
|
+
json(),
|
|
35
|
+
typescript({
|
|
36
|
+
tsconfig: './tsconfig.json',
|
|
37
|
+
tsconfigOverride: {
|
|
38
|
+
include: ['src']
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
minify && terser()
|
|
42
|
+
].filter(Boolean);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function cleanBuildDir() {
|
|
46
|
+
rmSync(buildDir, { recursive: true, force: true });
|
|
47
|
+
console.log(`${buildDir} cleaned`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
cleanBuildDir();
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @type {import('rollup').RollupOptions[]}
|
|
54
|
+
*/
|
|
55
|
+
const config = [
|
|
56
|
+
{
|
|
57
|
+
input: 'src/index.ts',
|
|
58
|
+
external: defaultExternal,
|
|
59
|
+
output: [
|
|
60
|
+
{
|
|
61
|
+
file: 'dist/cjs/index.js',
|
|
62
|
+
format: 'cjs'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
file: 'dist/es/index.js',
|
|
66
|
+
format: 'es'
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
plugins: createPlugin(isProduction),
|
|
70
|
+
treeshake
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
input: './src/index.ts',
|
|
74
|
+
output: [
|
|
75
|
+
{
|
|
76
|
+
file: 'dist/cjs/index.d.ts',
|
|
77
|
+
format: 'cjs'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
file: 'dist/es/index.d.ts',
|
|
81
|
+
format: 'es'
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
plugins: [dts()],
|
|
85
|
+
treeshake
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
export default config;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "ESNext",
|
|
4
|
+
"baseUrl": "./",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"moduleResolution": "Bundler",
|
|
8
|
+
"target": "ES2015",
|
|
9
|
+
"downlevelIteration": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"allowUnusedLabels": false,
|
|
12
|
+
"noUnusedLocals": true,
|
|
13
|
+
"noUnusedParameters": true
|
|
14
|
+
},
|
|
15
|
+
"include": ["src"],
|
|
16
|
+
"exclude": ["dist", "node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# React + TypeScript + Vite
|
|
2
|
+
|
|
3
|
+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
|
4
|
+
|
|
5
|
+
Currently, two official plugins are available:
|
|
6
|
+
|
|
7
|
+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
|
|
8
|
+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
|
9
|
+
|
|
10
|
+
## Expanding the ESLint configuration
|
|
11
|
+
|
|
12
|
+
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
|
|
13
|
+
|
|
14
|
+
- Configure the top-level `parserOptions` property like this:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
export default tseslint.config({
|
|
18
|
+
languageOptions: {
|
|
19
|
+
// other options...
|
|
20
|
+
parserOptions: {
|
|
21
|
+
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
|
22
|
+
tsconfigRootDir: import.meta.dirname,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
|
|
29
|
+
- Optionally add `...tseslint.configs.stylisticTypeChecked`
|
|
30
|
+
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
// eslint.config.js
|
|
34
|
+
import react from 'eslint-plugin-react'
|
|
35
|
+
|
|
36
|
+
export default tseslint.config({
|
|
37
|
+
// Set the react version
|
|
38
|
+
settings: { react: { version: '18.3' } },
|
|
39
|
+
plugins: {
|
|
40
|
+
// Add the react plugin
|
|
41
|
+
react,
|
|
42
|
+
},
|
|
43
|
+
rules: {
|
|
44
|
+
// other rules...
|
|
45
|
+
// Enable its recommended rules
|
|
46
|
+
...react.configs.recommended.rules,
|
|
47
|
+
...react.configs['jsx-runtime'].rules,
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { Text } from '../src/commponents/Text';
|
|
4
|
+
|
|
5
|
+
describe('Text Component', () => {
|
|
6
|
+
test('renders the text prop', () => {
|
|
7
|
+
render(<Text text="Hello, World!" />);
|
|
8
|
+
const textElement = screen.getByText(/Hello, World!/i);
|
|
9
|
+
expect(textElement).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
});
|