@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.
Files changed (144) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/bin/create-app.js +28 -0
  3. package/dist/cjs/index.d.ts +67 -0
  4. package/dist/cjs/index.js +1 -0
  5. package/dist/es/index.d.ts +67 -0
  6. package/dist/es/index.js +1 -0
  7. package/package.json +60 -0
  8. package/templates/fe-react/.env +3 -0
  9. package/templates/fe-react/README.md +50 -0
  10. package/templates/fe-react/config/app.common.ts +52 -0
  11. package/templates/fe-react/config/app.router.json +150 -0
  12. package/templates/fe-react/config/feapi.mock.json +14 -0
  13. package/templates/fe-react/config/i18n.ts +21 -0
  14. package/templates/fe-react/config/theme.json +90 -0
  15. package/templates/fe-react/eslint.config.js +31 -0
  16. package/templates/fe-react/index.html +13 -0
  17. package/templates/fe-react/lib/fe-react-controller/FeController.ts +15 -0
  18. package/templates/fe-react/lib/fe-react-controller/index.ts +2 -0
  19. package/templates/fe-react/lib/fe-react-controller/useController.ts +71 -0
  20. package/templates/fe-react/lib/fe-react-theme/ThemeController.ts +40 -0
  21. package/templates/fe-react/lib/fe-react-theme/ThemeStateGetter.ts +53 -0
  22. package/templates/fe-react/lib/fe-react-theme/index.ts +3 -0
  23. package/templates/fe-react/lib/fe-react-theme/tw-generator.js +239 -0
  24. package/templates/fe-react/lib/fe-react-theme/type.ts +21 -0
  25. package/templates/fe-react/lib/openAiApi/OpenAIAuthPlugin.ts +29 -0
  26. package/templates/fe-react/lib/openAiApi/OpenAIClient.ts +51 -0
  27. package/templates/fe-react/lib/openAiApi/StreamProcessor.ts +81 -0
  28. package/templates/fe-react/lib/openAiApi/index.ts +3 -0
  29. package/templates/fe-react/lib/request-common-plugin/index.ts +169 -0
  30. package/templates/fe-react/lib/tw-root10px/index.css +4 -0
  31. package/templates/fe-react/lib/tw-root10px/index.js +178 -0
  32. package/templates/fe-react/package.json +49 -0
  33. package/templates/fe-react/postcss.config.js +6 -0
  34. package/templates/fe-react/public/locales/en/about.json +3 -0
  35. package/templates/fe-react/public/locales/en/common.json +6 -0
  36. package/templates/fe-react/public/locales/en/executor.json +6 -0
  37. package/templates/fe-react/public/locales/en/home.json +10 -0
  38. package/templates/fe-react/public/locales/en/jsonStorage.json +11 -0
  39. package/templates/fe-react/public/locales/en/login.json +7 -0
  40. package/templates/fe-react/public/locales/en/request.json +15 -0
  41. package/templates/fe-react/public/locales/zh/about.json +3 -0
  42. package/templates/fe-react/public/locales/zh/common.json +7 -0
  43. package/templates/fe-react/public/locales/zh/executor.json +7 -0
  44. package/templates/fe-react/public/locales/zh/home.json +10 -0
  45. package/templates/fe-react/public/locales/zh/jsonStorage.json +11 -0
  46. package/templates/fe-react/public/locales/zh/login.json +8 -0
  47. package/templates/fe-react/public/locales/zh/request.json +15 -0
  48. package/templates/fe-react/public/logo.svg +1 -0
  49. package/templates/fe-react/src/App.tsx +20 -0
  50. package/templates/fe-react/src/assets/react.svg +1 -0
  51. package/templates/fe-react/src/components/Loading.tsx +41 -0
  52. package/templates/fe-react/src/components/LocaleLink.tsx +42 -0
  53. package/templates/fe-react/src/components/ProcessProvider.tsx +41 -0
  54. package/templates/fe-react/src/components/ThemeSwitcher.tsx +29 -0
  55. package/templates/fe-react/src/containers/context/BaseRouteContext.ts +27 -0
  56. package/templates/fe-react/src/containers/context/BaseRouteProvider.tsx +11 -0
  57. package/templates/fe-react/src/containers/globals.ts +31 -0
  58. package/templates/fe-react/src/containers/index.ts +71 -0
  59. package/templates/fe-react/src/hooks/useLanguageGuard.ts +25 -0
  60. package/templates/fe-react/src/hooks/useStrictEffect.ts +29 -0
  61. package/templates/fe-react/src/main.tsx +15 -0
  62. package/templates/fe-react/src/pages/404.tsx +14 -0
  63. package/templates/fe-react/src/pages/500.tsx +14 -0
  64. package/templates/fe-react/src/pages/auth/Layout.tsx +14 -0
  65. package/templates/fe-react/src/pages/auth/Login.tsx +62 -0
  66. package/templates/fe-react/src/pages/auth/Register.tsx +3 -0
  67. package/templates/fe-react/src/pages/base/About.tsx +12 -0
  68. package/templates/fe-react/src/pages/base/Executor.tsx +38 -0
  69. package/templates/fe-react/src/pages/base/Home.tsx +78 -0
  70. package/templates/fe-react/src/pages/base/JSONStorage.tsx +124 -0
  71. package/templates/fe-react/src/pages/base/Layout.tsx +17 -0
  72. package/templates/fe-react/src/pages/base/RedirectPathname.tsx +15 -0
  73. package/templates/fe-react/src/pages/base/Request.tsx +91 -0
  74. package/templates/fe-react/src/pages/base/components/BaseHeader.tsx +19 -0
  75. package/templates/fe-react/src/pages/index.tsx +108 -0
  76. package/templates/fe-react/src/services/controllers/ExecutorController.ts +56 -0
  77. package/templates/fe-react/src/services/controllers/JSONStorageController.ts +42 -0
  78. package/templates/fe-react/src/services/controllers/RequestController.ts +105 -0
  79. package/templates/fe-react/src/services/controllers/RouterController.ts +90 -0
  80. package/templates/fe-react/src/services/controllers/UserController.ts +146 -0
  81. package/templates/fe-react/src/services/feApi/FeApi.ts +51 -0
  82. package/templates/fe-react/src/services/feApi/FeApiMockPlugin.ts +42 -0
  83. package/templates/fe-react/src/services/feApi/FeApiType.ts +55 -0
  84. package/templates/fe-react/src/services/feApi/index.ts +2 -0
  85. package/templates/fe-react/src/services/i18n/index.ts +50 -0
  86. package/templates/fe-react/src/services/pageProcesser/PageProcesser.ts +29 -0
  87. package/templates/fe-react/src/services/pageProcesser/index.ts +1 -0
  88. package/templates/fe-react/src/styles/css/index.css +2 -0
  89. package/templates/fe-react/src/styles/css/page.css +3 -0
  90. package/templates/fe-react/src/styles/css/tailwind.css +3 -0
  91. package/templates/fe-react/src/types/Page.ts +49 -0
  92. package/templates/fe-react/src/types/UIDependenciesInterface.ts +31 -0
  93. package/templates/fe-react/src/types/global.d.ts +7 -0
  94. package/templates/fe-react/src/utils/RequestLogger.ts +34 -0
  95. package/templates/fe-react/src/utils/datetime.ts +25 -0
  96. package/templates/fe-react/src/utils/thread.ts +3 -0
  97. package/templates/fe-react/src/vite-env.d.ts +1 -0
  98. package/templates/fe-react/tailwind.config.js +18 -0
  99. package/templates/fe-react/tsconfig.app.json +29 -0
  100. package/templates/fe-react/tsconfig.json +7 -0
  101. package/templates/fe-react/tsconfig.node.json +22 -0
  102. package/templates/fe-react/vite.config.ts +32 -0
  103. package/templates/pack-app/.editorconfig +23 -0
  104. package/templates/pack-app/.env +5 -0
  105. package/templates/pack-app/.env.template +6 -0
  106. package/templates/pack-app/.gitattributes +2 -0
  107. package/templates/pack-app/.github/workflows/general-check.yml +50 -0
  108. package/templates/pack-app/.github/workflows/release.yml.template +110 -0
  109. package/templates/pack-app/.prettierignore +5 -0
  110. package/templates/pack-app/.prettierrc.js +3 -0
  111. package/templates/pack-app/CHANGELOG.md +0 -0
  112. package/templates/pack-app/README.md +1 -0
  113. package/templates/pack-app/eslint.config.js +77 -0
  114. package/templates/pack-app/fe-config.json +10 -0
  115. package/templates/pack-app/jest.config.js +31 -0
  116. package/templates/pack-app/package.json +66 -0
  117. package/templates/pack-app/packages/browser/__tests__/calc.test.ts +9 -0
  118. package/templates/pack-app/packages/browser/package.json +11 -0
  119. package/templates/pack-app/packages/browser/rollup.config.js +70 -0
  120. package/templates/pack-app/packages/browser/src/calc.ts +3 -0
  121. package/templates/pack-app/packages/browser/src/index.ts +1 -0
  122. package/templates/pack-app/packages/browser/tsconfig.json +15 -0
  123. package/templates/pack-app/packages/node/__tests__/readJson.test.ts +25 -0
  124. package/templates/pack-app/packages/node/package.json +11 -0
  125. package/templates/pack-app/packages/node/rollup.config.js +89 -0
  126. package/templates/pack-app/packages/node/src/index.ts +7 -0
  127. package/templates/pack-app/packages/node/src/readJson.ts +6 -0
  128. package/templates/pack-app/packages/node/tsconfig.json +17 -0
  129. package/templates/pack-app/packages/react-vite-lib/README.md +50 -0
  130. package/templates/pack-app/packages/react-vite-lib/__tests__/Sum.test.ts +9 -0
  131. package/templates/pack-app/packages/react-vite-lib/__tests__/Text.test.tsx +11 -0
  132. package/templates/pack-app/packages/react-vite-lib/eslint.config.js +28 -0
  133. package/templates/pack-app/packages/react-vite-lib/index.html +13 -0
  134. package/templates/pack-app/packages/react-vite-lib/package.json +30 -0
  135. package/templates/pack-app/packages/react-vite-lib/public/vite.svg +1 -0
  136. package/templates/pack-app/packages/react-vite-lib/src/calc.ts +3 -0
  137. package/templates/pack-app/packages/react-vite-lib/src/commponents/Text.tsx +7 -0
  138. package/templates/pack-app/packages/react-vite-lib/src/index.ts +2 -0
  139. package/templates/pack-app/packages/react-vite-lib/src/vite-env.d.ts +1 -0
  140. package/templates/pack-app/packages/react-vite-lib/tsconfig.json +25 -0
  141. package/templates/pack-app/packages/react-vite-lib/vite.config.ts +24 -0
  142. package/templates/pack-app/pnpm-workspace.yaml +2 -0
  143. package/templates/pack-app/tsconfig.json +9 -0
  144. 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
@@ -0,0 +1,5 @@
1
+ .github
2
+ .husky
3
+ **/dist/*
4
+ **/node_modules/*
5
+ **/.output/*
@@ -0,0 +1,3 @@
1
+ import prettierConfig from '@qlover/fe-standard/config/prettierrc.js';
2
+
3
+ export default prettierConfig;
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,10 @@
1
+ {
2
+ "protectedBranches": ["master", "develop"],
3
+ "release": {
4
+ "packagesDirectories": [
5
+ "packages/browser",
6
+ "packages/node",
7
+ "packages/react-vite-lib"
8
+ ]
9
+ }
10
+ }
@@ -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,9 @@
1
+ import { calc } from '../src/calc';
2
+
3
+ describe('calc 函数测试', () => {
4
+ it('应该返回两个数字的和', () => {
5
+ expect(calc(1, 2)).toBe(3);
6
+ expect(calc(-1, 1)).toBe(0);
7
+ expect(calc(0, 0)).toBe(0);
8
+ });
9
+ });
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@qlover/pack-app-browser",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "main": "index.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "rollup -c",
9
+ "test": "jest"
10
+ }
11
+ }
@@ -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,3 @@
1
+ export function calc(a: number, b: number): number {
2
+ return a + b;
3
+ }
@@ -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,11 @@
1
+ {
2
+ "name": "@qlover/pack-app-node",
3
+ "version": "0.0.1",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "private": true,
7
+ "scripts": {
8
+ "build": "rollup -c",
9
+ "test": "jest"
10
+ }
11
+ }
@@ -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,7 @@
1
+ import { readJson } from './readJson';
2
+
3
+ export * from './readJson';
4
+
5
+ console.log('readJson', readJson('./package.json'));
6
+
7
+ console.log('process.cwd', process.cwd());
@@ -0,0 +1,6 @@
1
+ import { readFileSync } from 'fs';
2
+
3
+ export function readJson(path: string): Record<string, unknown> {
4
+ const packageJson = readFileSync(path, 'utf8');
5
+ return JSON.parse(packageJson);
6
+ }
@@ -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,9 @@
1
+ import { sum } from '../src/sum';
2
+
3
+ describe('sum 函数测试', () => {
4
+ it('应该返回两个数字的和', () => {
5
+ expect(sum(1, 2)).toBe(3);
6
+ expect(sum(-1, 1)).toBe(0);
7
+ expect(sum(0, 0)).toBe(0);
8
+ });
9
+ });
@@ -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
+ });