create-packer 1.20.2 → 1.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-packer",
3
- "version": "1.20.2",
3
+ "version": "1.21.0",
4
4
  "main": "index.js",
5
5
  "repository": "https://github.com/kevily/create-packer",
6
6
  "author": "1k <bug_zero@163.com>",
@@ -1 +1,2 @@
1
+ VITE_BASE_URL=/
1
2
  VITE_API_HOST=https://127.0.0.1
@@ -1 +1,2 @@
1
+ VITE_BASE_URL=/
1
2
  VITE_API_HOST=https://127.0.0.1
@@ -27,6 +27,7 @@
27
27
  "react": "18.2.0",
28
28
  "react-dom": "18.2.0",
29
29
  "react-router-dom": "6.14.0",
30
+ "react-use": "17.4.0",
30
31
  "zustand": "4.3.7"
31
32
  },
32
33
  "devDependencies": {
@@ -69,7 +70,8 @@
69
70
  "tailwindcss": "3.3.1",
70
71
  "typescript": "5.0.4",
71
72
  "vite": "4.3.1",
72
- "vite-plugin-eslint": "1.8.1"
73
+ "vite-plugin-eslint": "1.8.1",
74
+ "vite-plugin-svgr": "3.2.0"
73
75
  },
74
76
  "config": {
75
77
  "commitizen": {
@@ -1 +1,3 @@
1
1
  export { default as useComponentInstance } from './useComponentInstance'
2
+ export { default as useLoadingAction } from './useLoadingAction'
3
+ export { default as useInterval } from './useInterval'
@@ -0,0 +1,26 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { useInterval as useRUInterval } from 'react-use'
3
+
4
+ interface actionsType {
5
+ start: () => void
6
+ stop: () => void
7
+ }
8
+ export default function useInterval(
9
+ cb: (actions: actionsType) => Promise<void> | void,
10
+ delay: number
11
+ ): actionsType {
12
+ const [startInterval, setStartInterval] = useState(false)
13
+ const start: actionsType['start'] = () => {
14
+ setStartInterval(true)
15
+ }
16
+ const stop: actionsType['stop'] = () => {
17
+ setStartInterval(false)
18
+ }
19
+ useRUInterval(
20
+ async () => {
21
+ cb({ start, stop })
22
+ },
23
+ startInterval ? delay : null
24
+ )
25
+ return { start, stop }
26
+ }
@@ -0,0 +1,18 @@
1
+ import { useCallback, useState, DependencyList } from 'react'
2
+
3
+ export default function useLoadingAction<C extends (...arg: any) => Promise<any> | any>(
4
+ callback: C,
5
+ deps: DependencyList
6
+ ): [boolean, C] {
7
+ const [loading, setLoading] = useState(false)
8
+ const action = useCallback(async (...arg: any) => {
9
+ try {
10
+ setLoading(true)
11
+ return await callback(...arg)
12
+ } finally {
13
+ setLoading(false)
14
+ }
15
+ }, deps)
16
+
17
+ return [loading, action as C]
18
+ }
@@ -1,5 +1,6 @@
1
1
  import * as home from './home'
2
2
  export default {
3
3
  root: 'root',
4
+ notFound: 'notFound',
4
5
  ...home.ids
5
6
  }
@@ -15,7 +15,7 @@ const routes: routeType[] = [
15
15
  },
16
16
  {
17
17
  path: '*',
18
- id: '404',
18
+ id: ids.notFound,
19
19
  Component: lazy(() => import('@/pages/notFound'))
20
20
  }
21
21
  ]
@@ -1,6 +1,8 @@
1
1
  /// <reference types="vite/client" />
2
+ /// <reference types="vite-plugin-svgr/client" />
2
3
 
3
4
  interface ImportMetaEnv {
5
+ readonly VITE_BASE_URL: string
4
6
  readonly VITE_API_HOST: string
5
7
  // 更多环境变量...
6
8
  }
@@ -1,12 +1,17 @@
1
1
  import path from 'path'
2
- import { defineConfig } from 'vite'
2
+ import { defineConfig, loadEnv } from 'vite'
3
3
  import react from '@vitejs/plugin-react'
4
4
  import eslint from 'vite-plugin-eslint'
5
+ import svgr from 'vite-plugin-svgr'
5
6
 
6
7
  // https://vitejs.dev/config/
7
- export default defineConfig(({ command }) => {
8
+ export default defineConfig(({ command, mode }) => {
9
+ const env = loadEnv(mode, process.cwd(), '')
10
+ const plugins: any[] = [svgr(), eslint(), react()]
11
+
8
12
  return {
9
- plugins: [eslint(), react()],
13
+ base: env.VITE_BASE_URL,
14
+ plugins,
10
15
  resolve: {
11
16
  alias: {
12
17
  '@': path.join(__dirname, 'src')
@@ -14,6 +19,16 @@ export default defineConfig(({ command }) => {
14
19
  },
15
20
  esbuild: {
16
21
  drop: command === 'build' ? ['console', 'debugger'] : []
22
+ },
23
+ server: {
24
+ host: '0.0.0.0',
25
+ proxy: {
26
+ '/api': {
27
+ target: 'http://127.0.0.1',
28
+ changeOrigin: true,
29
+ rewrite: path => path.replace(/^\/api/, '')
30
+ }
31
+ }
17
32
  }
18
33
  }
19
34
  })
@@ -9,7 +9,7 @@
9
9
  "plugin:react/recommended",
10
10
  "plugin:react-hooks/recommended",
11
11
  "plugin:import/recommended",
12
- "plugin:import/typescript",
12
+ "plugin:import/typescript"
13
13
  ],
14
14
  "settings": {
15
15
  "import/resolver": {
@@ -0,0 +1,18 @@
1
+ import React from 'react'
2
+
3
+ declare global {
4
+ declare module '*.css'
5
+ declare module '*.less'
6
+ declare module '*.scss'
7
+ declare module '*.png'
8
+ declare module '*.svg' {
9
+ import * as React from 'react'
10
+
11
+ export const ReactComponent: React.FunctionComponent<
12
+ React.ComponentProps<'svg'> & { title?: string }
13
+ >
14
+ export function ReactComponent(props: React.SVGProps<SVGSVGElement>): React.ReactElement
15
+ const url: string
16
+ export default url
17
+ }
18
+ }
@@ -9,6 +9,9 @@
9
9
  "storybook": "storybook dev -p 6006",
10
10
  "build-storybook": "storybook build"
11
11
  },
12
+ "files": [
13
+ "dist"
14
+ ],
12
15
  "keywords": [],
13
16
  "author": "",
14
17
  "license": "ISC",
@@ -18,7 +18,8 @@
18
18
  "sourceMap": false,
19
19
  "declaration": true,
20
20
  "outDir": "dist",
21
- "baseUrl": "."
21
+ "baseUrl": ".",
22
+ "emitDeclarationOnly": true
22
23
  },
23
- "include": ["src"]
24
+ "include": ["src", "./global.d.ts"]
24
25
  }
@@ -0,0 +1,185 @@
1
+ /*
2
+ * For a detailed explanation regarding each configuration property, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ module.exports = {
7
+ // All imported modules in your tests should be mocked automatically
8
+ // automock: false,
9
+
10
+ // Stop running tests after `n` failures
11
+ // bail: 0,
12
+
13
+ // The directory where Jest should store its cached dependency information
14
+ // cacheDirectory: "/private/var/folders/hz/wwjd54d17xd_n09_zkrlx5v80000gn/T/jest_dx",
15
+
16
+ // Automatically clear mock calls and instances between every test
17
+ // clearMocks: false,
18
+
19
+ // Indicates whether the coverage information should be collected while executing the test
20
+ // collectCoverage: false,
21
+
22
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
23
+ // collectCoverageFrom: undefined,
24
+
25
+ // The directory where Jest should output its coverage files
26
+ // coverageDirectory: undefined,
27
+
28
+ // An array of regexp pattern strings used to skip coverage collection
29
+ // coveragePathIgnorePatterns: [
30
+ // "/node_modules/"
31
+ // ],
32
+
33
+ // Indicates which provider should be used to instrument code for coverage
34
+ coverageProvider: 'v8',
35
+
36
+ // A list of reporter names that Jest uses when writing coverage reports
37
+ // coverageReporters: [
38
+ // "json",
39
+ // "text",
40
+ // "lcov",
41
+ // "clover"
42
+ // ],
43
+
44
+ // An object that configures minimum threshold enforcement for coverage results
45
+ // coverageThreshold: undefined,
46
+
47
+ // A path to a custom dependency extractor
48
+ // dependencyExtractor: undefined,
49
+
50
+ // Make calling deprecated APIs throw helpful error messages
51
+ // errorOnDeprecated: false,
52
+
53
+ // Force coverage collection from ignored files using an array of glob patterns
54
+ // forceCoverageMatch: [],
55
+
56
+ // A path to a module which exports an async function that is triggered once before all test suites
57
+ // globalSetup: undefined,
58
+
59
+ // A path to a module which exports an async function that is triggered once after all test suites
60
+ // globalTeardown: undefined,
61
+
62
+ // A set of global variables that need to be available in all test environments
63
+ // globals: {},
64
+
65
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
66
+ // maxWorkers: "50%",
67
+
68
+ // An array of directory names to be searched recursively up from the requiring module's location
69
+ // moduleDirectories: [
70
+ // "node_modules"
71
+ // ],
72
+
73
+ // An array of file extensions your modules use
74
+ moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json', 'node'],
75
+
76
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
77
+ // moduleNameMapper: {},
78
+
79
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
80
+ // modulePathIgnorePatterns: [],
81
+
82
+ // Activates notifications for test results
83
+ // notify: false,
84
+
85
+ // An enum that specifies notification mode. Requires { notify: true }
86
+ // notifyMode: "failure-change",
87
+
88
+ // A preset that is used as a base for Jest's configuration
89
+ preset: 'ts-jest',
90
+
91
+ // Run tests from one or more projects
92
+ // projects: undefined,
93
+
94
+ // Use this configuration option to add custom reporters to Jest
95
+ // reporters: undefined,
96
+
97
+ // Automatically reset mock state between every test
98
+ // resetMocks: false,
99
+
100
+ // Reset the module registry before running each individual test
101
+ // resetModules: false,
102
+
103
+ // A path to a custom resolver
104
+ // resolver: undefined,
105
+
106
+ // Automatically restore mock state between every test
107
+ // restoreMocks: false,
108
+
109
+ // The root directory that Jest should scan for tests and modules within
110
+ // rootDir: undefined,
111
+
112
+ // A list of paths to directories that Jest should use to search for files in
113
+ roots: ['<rootDir>/src'],
114
+
115
+ // Allows you to use a custom runner instead of Jest's default test runner
116
+ // runner: "jest-runner",
117
+
118
+ // The paths to modules that run some code to configure or set up the testing environment before each test
119
+ // setupFiles: [],
120
+
121
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
122
+ // setupFilesAfterEnv: [],
123
+
124
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
125
+ // slowTestThreshold: 5,
126
+
127
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
128
+ // snapshotSerializers: [],
129
+
130
+ // The test environment that will be used for testing
131
+ testEnvironment: 'jsdom'
132
+
133
+ // Options that will be passed to the testEnvironment
134
+ // testEnvironmentOptions: {},
135
+
136
+ // Adds a location field to test results
137
+ // testLocationInResults: false,
138
+
139
+ // The glob patterns Jest uses to detect test files
140
+ // testMatch: [
141
+ // "**/__tests__/**/*.[jt]s?(x)",
142
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
143
+ // ],
144
+
145
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
146
+ // testPathIgnorePatterns: [
147
+ // "/node_modules/"
148
+ // ],
149
+
150
+ // The regexp pattern or array of patterns that Jest uses to detect test files
151
+ // testRegex: [],
152
+
153
+ // This option allows the use of a custom results processor
154
+ // testResultsProcessor: undefined,
155
+
156
+ // This option allows use of a custom test runner
157
+ // testRunner: "jest-circus/runner",
158
+
159
+ // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
160
+ // testURL: "http://localhost",
161
+
162
+ // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
163
+ // timers: "real",
164
+
165
+ // A map from regular expressions to paths to transformers
166
+ // transform: undefined,
167
+
168
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
169
+ // transformIgnorePatterns: [
170
+ // "/node_modules/",
171
+ // "\\.pnp\\.[^\\/]+$"
172
+ // ],
173
+
174
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
175
+ // unmockedModulePathPatterns: undefined,
176
+
177
+ // Indicates whether each individual test should be reported during the run
178
+ // verbose: undefined,
179
+
180
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
181
+ // watchPathIgnorePatterns: [],
182
+
183
+ // Whether to use watchman for file crawling
184
+ // watchman: true,
185
+ }
@@ -5,19 +5,26 @@
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
- "build": "tsc"
8
+ "build": "tsc",
9
+ "test": "jest --forceExit --coverage --verbose"
9
10
  },
11
+ "files": [
12
+ "dist"
13
+ ],
10
14
  "license": "ISC",
11
15
  "devDependencies": {
16
+ "@types/jest": "^29.5.2",
12
17
  "@typescript-eslint/eslint-plugin": "5.60.1",
13
18
  "@typescript-eslint/parser": "5.60.1",
14
19
  "eslint": "8.43.0",
15
20
  "eslint-import-resolver-typescript": "3.5.5",
16
21
  "eslint-plugin-import": "2.27.5",
17
22
  "eslint-plugin-prettier": "4.2.1",
23
+ "jest": "^29.5.0",
18
24
  "prettier": "2.8.8",
19
25
  "stylelint": "15.9.0",
20
26
  "stylelint-config-standard": "33.0.0",
27
+ "ts-jest": "29.0.5",
21
28
  "typescript": "5.1.3"
22
29
  }
23
30
  }
@@ -10,8 +10,9 @@
10
10
  "sourceMap": false,
11
11
  "declaration": true,
12
12
  "outDir": "dist",
13
- "baseUrl": "."
13
+ "baseUrl": ".",
14
+ "emitDeclarationOnly": true
14
15
  },
15
- "include": ["src/**/*"],
16
+ "include": ["src"],
16
17
  "exclude": ["node_modules/**/*"]
17
18
  }
package/template/vue/.env CHANGED
@@ -1 +1,2 @@
1
+ VITE_BASE_URL=/
1
2
  VITE_API_HOST=https://127.0.0.1
@@ -1 +1,2 @@
1
+ VITE_BASE_URL=/
1
2
  VITE_API_HOST=https://127.0.0.1
@@ -24,18 +24,19 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@commitlint/cli": "17.6.1",
27
- "@commitlint/config-conventional": "^17.6.1",
27
+ "@commitlint/config-conventional": "17.6.1",
28
28
  "@commitlint/cz-commitlint": "17.5.0",
29
29
  "@types/lodash-es": "4.17.7",
30
30
  "@typescript-eslint/eslint-plugin": "5.59.0",
31
31
  "@typescript-eslint/parser": "5.59.0",
32
32
  "@vitejs/plugin-vue": "4.2.3",
33
+ "@vitejs/plugin-vue-jsx": "3.0.1",
33
34
  "autoprefixer": "10.4.14",
34
35
  "commitizen": "4.3.0",
35
36
  "cssnano": "6.0.0",
36
37
  "eslint": "8.39.0",
37
- "eslint-import-resolver-typescript": "^3.5.5",
38
- "eslint-plugin-import": "^2.27.5",
38
+ "eslint-import-resolver-typescript": "3.5.5",
39
+ "eslint-plugin-import": "2.27.5",
39
40
  "eslint-plugin-prettier": "4.2.1",
40
41
  "eslint-plugin-vue": "9.13.0",
41
42
  "husky": "8.0.3",
@@ -50,6 +51,7 @@
50
51
  "typescript": "5.0.4",
51
52
  "vite": "4.3.8",
52
53
  "vite-plugin-eslint": "1.8.1",
54
+ "vite-svg-loader": "4.0.0",
53
55
  "vue-tsc": "1.6.5"
54
56
  },
55
57
  "config": {
@@ -1,4 +1,5 @@
1
1
  /// <reference types="vite/client" />
2
+ /// <reference types="vite-svg-loader" />
2
3
 
3
4
  declare module '*.vue' {
4
5
  import type { DefineComponent } from 'vue'
@@ -7,6 +8,7 @@ declare module '*.vue' {
7
8
  }
8
9
 
9
10
  interface ImportMetaEnv {
11
+ readonly VITE_BASE_URL: string
10
12
  readonly VITE_API_HOST: string
11
13
  // 更多环境变量...
12
14
  }
@@ -1,19 +1,28 @@
1
- import { defineConfig } from 'vite'
1
+ import path from 'path'
2
+ import { defineConfig, loadEnv } from 'vite'
2
3
  import vue from '@vitejs/plugin-vue'
3
4
  import eslint from 'vite-plugin-eslint'
4
- import path from 'path'
5
+ import vueJsx from '@vitejs/plugin-vue-jsx'
6
+ import svgLoader from 'vite-svg-loader'
5
7
 
6
8
  // https://vitejs.dev/config/
7
- export default defineConfig(({ command }) => {
9
+ export default defineConfig(({ command, mode }) => {
10
+ const env = loadEnv(mode, process.cwd(), '')
11
+ const plugins: any[] = [
12
+ eslint(),
13
+ vueJsx({
14
+ enableObjectSlots: false
15
+ }),
16
+ vue({
17
+ script: {
18
+ defineModel: true
19
+ }
20
+ }),
21
+ svgLoader()
22
+ ]
8
23
  return {
9
- plugins: [
10
- eslint(),
11
- vue({
12
- script: {
13
- defineModel: true
14
- }
15
- })
16
- ],
24
+ base: env.VITE_BASE_URL,
25
+ plugins,
17
26
  resolve: {
18
27
  alias: {
19
28
  '@': path.join(__dirname, 'src')
@@ -22,6 +31,16 @@ export default defineConfig(({ command }) => {
22
31
  esbuild: {
23
32
  drop: command === 'build' ? ['console', 'debugger'] : []
24
33
  },
25
- build: {}
34
+ build: {},
35
+ server: {
36
+ host: '0.0.0.0',
37
+ proxy: {
38
+ '/api': {
39
+ target: 'http://127.0.0.1',
40
+ changeOrigin: true,
41
+ rewrite: path => path.replace(/^\/api/, '')
42
+ }
43
+ }
44
+ }
26
45
  }
27
46
  })
@@ -5,7 +5,7 @@
5
5
  "fixed": [],
6
6
  "linked": [],
7
7
  "access": "restricted",
8
- "baseBranch": "master",
8
+ "baseBranch": "main",
9
9
  "updateInternalDependencies": "patch",
10
10
  "ignore": []
11
11
  }
@@ -23,13 +23,14 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "1k-tasks": "3.0.2",
26
+ "1k-tasks": "3.5.0",
27
27
  "@commitlint/config-conventional": "17.6.6",
28
28
  "@commitlint/cz-commitlint": "17.5.0",
29
29
  "commitizen": "4.3.0",
30
30
  "rimraf": "5.0.1"
31
31
  },
32
32
  "devDependencies": {
33
+ "@changesets/cli": "^2.26.2",
33
34
  "@types/node": "20.3.2",
34
35
  "inquirer": "8",
35
36
  "ts-node": "10.9.1",