create-packer 1.17.32 → 1.18.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 +1 -1
- package/template/chrome-extension/{src/manifest.json → manifest.json} +3 -3
- package/template/chrome-extension/package.json +5 -4
- package/template/chrome-extension/src/providers/index.ts +2 -2
- package/template/chrome-extension/src/providers/modelUtils.ts +52 -0
- package/template/chrome-extension/src/providers/request.ts +57 -4
- package/template/chrome-extension/src/types/index.ts +1 -0
- package/template/chrome-extension/src/types/utils.ts +19 -0
- package/template/chrome-extension/vite.config.ts +3 -9
- package/template/react/src/layout/layout.container.tsx +11 -2
- package/template/react/src/pages/home/home.spec.tsx +1 -1
- package/template/react/src/pages/home/index.ts +1 -1
- package/template/react/src/pages/notFound/index.ts +1 -1
- package/template/react/src/router/home/routes.tsx +1 -1
- package/template/react/src/router/index.ts +1 -1
- package/template/react/src/router/router.provider.ts +3 -3
- package/template/react/src/router/router.tsx +9 -6
- package/template/react/src/router/router.types.ts +4 -1
- package/template/chrome-extension/src/providers/defineStore.ts +0 -42
- /package/template/chrome-extension/{src/assets → public}/vite.svg +0 -0
- /package/template/react/src/pages/home/{home.container.tsx → home.tsx} +0 -0
- /package/template/react/src/pages/notFound/{notFound.container.tsx → notFound.tsx} +0 -0
package/package.json
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
"description": "Base Level Extension",
|
|
5
5
|
"version": "1.0",
|
|
6
6
|
"action": {
|
|
7
|
-
"default_popup": "popup/popup.html",
|
|
8
|
-
"default_icon": "
|
|
7
|
+
"default_popup": "src/popup/popup.html",
|
|
8
|
+
"default_icon": "vite.svg"
|
|
9
9
|
},
|
|
10
10
|
"content_scripts": [
|
|
11
11
|
{
|
|
12
|
-
"js": ["content_script/index.tsx"],
|
|
12
|
+
"js": ["src/content_script/index.tsx"],
|
|
13
13
|
"matches": [
|
|
14
14
|
"https://developer.chrome.com/docs/extensions/*",
|
|
15
15
|
"https://developer.chrome.com/docs/webstore/*"
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepare": "husky install",
|
|
8
|
-
"dev": "vite
|
|
9
|
-
"build": "tsc && vite build",
|
|
8
|
+
"dev": "vite",
|
|
9
|
+
"build": "tsc --noEmit && vite build",
|
|
10
10
|
"preview": "vite preview",
|
|
11
11
|
"up:vite": "pnpm up vite @vitejs/* -L",
|
|
12
12
|
"format": "prettier --write \"src/**/*.{ts,js,tsx,jsx,css,scss,less}\" \"./package.json\"",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"commit": "git add . && npm run cz"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"axios": "1.3.6",
|
|
24
23
|
"immer": "10.0.1",
|
|
25
24
|
"lodash-es": "4.17.21",
|
|
25
|
+
"qs": "6.11.2",
|
|
26
26
|
"react": "18.2.0",
|
|
27
27
|
"react-dom": "18.2.0",
|
|
28
28
|
"zustand": "4.3.7"
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@commitlint/cli": "17.6.1",
|
|
32
32
|
"@commitlint/config-conventional": "17.6.1",
|
|
33
33
|
"@commitlint/cz-commitlint": "17.5.0",
|
|
34
|
+
"@crxjs/vite-plugin": "2.0.0-beta.18",
|
|
34
35
|
"@testing-library/dom": "9.2.0",
|
|
35
36
|
"@testing-library/jest-dom": "5.16.5",
|
|
36
37
|
"@testing-library/react": "14.0.0",
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
"@types/jest": "29.5.1",
|
|
39
40
|
"@types/lodash-es": "4.17.7",
|
|
40
41
|
"@types/node": "18.16.0",
|
|
42
|
+
"@types/qs": "6.9.7",
|
|
41
43
|
"@types/react": "18.0.38",
|
|
42
44
|
"@types/react-dom": "18.0.11",
|
|
43
45
|
"@types/testing-library__jest-dom": "5.14.5",
|
|
@@ -66,7 +68,6 @@
|
|
|
66
68
|
"tailwindcss": "3.3.1",
|
|
67
69
|
"typescript": "5.0.4",
|
|
68
70
|
"vite": "4.3.1",
|
|
69
|
-
"vite-plugin-chrome-extension": "0.0.7",
|
|
70
71
|
"vite-plugin-eslint": "1.8.1"
|
|
71
72
|
},
|
|
72
73
|
"config": {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export
|
|
1
|
+
export * from './modelUtils'
|
|
2
|
+
export * from './request'
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { create, StoreApi, UseBoundStore } from 'zustand'
|
|
2
|
+
import { combine } from 'zustand/middleware'
|
|
3
|
+
import { produce } from 'immer'
|
|
4
|
+
import { ExtractModelType } from '@/types'
|
|
5
|
+
|
|
6
|
+
export interface insideActionsType<S> {
|
|
7
|
+
reset: () => void
|
|
8
|
+
setState: (updater: (state: S) => void) => void
|
|
9
|
+
}
|
|
10
|
+
export type actionsType<S, OptionAction, InsideActions = unknown> = (
|
|
11
|
+
getState: () => S,
|
|
12
|
+
actions: insideActionsType<S> & InsideActions,
|
|
13
|
+
store: StoreApi<S>
|
|
14
|
+
) => OptionAction
|
|
15
|
+
export interface optionsType<S, OptionAction> {
|
|
16
|
+
state: () => S
|
|
17
|
+
actions: actionsType<S, OptionAction>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function define<S extends Record<string, any>, OptionActions extends Record<string, any>>(
|
|
21
|
+
options: optionsType<S, OptionActions>
|
|
22
|
+
) {
|
|
23
|
+
return create(
|
|
24
|
+
combine(options.state(), (set, get, store) => {
|
|
25
|
+
const setState: insideActionsType<S>['setState'] = updater => {
|
|
26
|
+
set(
|
|
27
|
+
produce((store: S) => {
|
|
28
|
+
updater(store)
|
|
29
|
+
}) as any
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
const reset: insideActionsType<S>['reset'] = () => {
|
|
33
|
+
set(() => options.state() as never)
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
...options.state(),
|
|
37
|
+
reset,
|
|
38
|
+
setState,
|
|
39
|
+
subscribe: store.subscribe,
|
|
40
|
+
...options.actions(get, { reset, setState }, store)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function defineComputed<
|
|
47
|
+
Model extends UseBoundStore<StoreApi<any>>,
|
|
48
|
+
K extends string,
|
|
49
|
+
R = any
|
|
50
|
+
>(useStore: Model, computed: Record<K, (state: ExtractModelType<Model>) => R>) {
|
|
51
|
+
return (field: K) => useStore(computed[field])
|
|
52
|
+
}
|
|
@@ -1,7 +1,60 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isFunction, size } from 'lodash-es'
|
|
2
|
+
import { stringify } from 'qs'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
type fetchConfigType = Required<Parameters<typeof fetch>>[1]
|
|
5
|
+
|
|
6
|
+
interface configType {
|
|
7
|
+
baseURL: string
|
|
8
|
+
headers?: {
|
|
9
|
+
'Content-Type'?: string
|
|
10
|
+
[key: string]: string | undefined
|
|
11
|
+
}
|
|
12
|
+
onError?: (e: Error) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const DEFAULT_CONFIG: Partial<configType> = {
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
class Request {
|
|
22
|
+
baseURL: configType['baseURL']
|
|
23
|
+
constructor(config: configType) {
|
|
24
|
+
this.baseURL = config.baseURL
|
|
25
|
+
}
|
|
26
|
+
async request(url: string, config?: fetchConfigType) {
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(this.baseURL + url, {
|
|
29
|
+
headers: DEFAULT_CONFIG.headers as never,
|
|
30
|
+
...config
|
|
31
|
+
})
|
|
32
|
+
if (response.status !== 200) {
|
|
33
|
+
const errMsg = `服务器错误状态:${response.status}`
|
|
34
|
+
throw new Error(errMsg)
|
|
35
|
+
}
|
|
36
|
+
return await response.json()
|
|
37
|
+
} catch (error: any) {
|
|
38
|
+
if (isFunction(DEFAULT_CONFIG.onError)) {
|
|
39
|
+
DEFAULT_CONFIG.onError(error)
|
|
40
|
+
}
|
|
41
|
+
throw new Error(error.message)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
get(url: string, data?: Record<string, any> | any[]) {
|
|
45
|
+
const query = size(data) > 0 ? `?${stringify(data)}` : ''
|
|
46
|
+
return this.request(url + query, {
|
|
47
|
+
method: 'GET'
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
post(url: string, body?: any) {
|
|
51
|
+
return this.request(url, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body: JSON.stringify(body)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const request = new Request({
|
|
4
59
|
baseURL: import.meta.env.VITE_API_HOST
|
|
5
60
|
})
|
|
6
|
-
|
|
7
|
-
export default request
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils'
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UseBoundStore, StoreApi } from 'zustand'
|
|
2
|
+
export type ExtractArrayElType<T> = T extends Array<infer E> ? E : unknown
|
|
3
|
+
export type ExtractReadonlyArrayElType<T> = T extends ReadonlyArray<infer E> ? E : unknown
|
|
4
|
+
export type ExtractReadonlyArrayFieldType<T, K extends keyof any> = T extends ReadonlyArray<infer V>
|
|
5
|
+
? V extends { [key in K]: infer V2 }
|
|
6
|
+
? V2
|
|
7
|
+
: any
|
|
8
|
+
: any
|
|
9
|
+
export type ExtractArrayFieldType<T, K extends keyof any> = T extends Array<infer V>
|
|
10
|
+
? V extends { [key in K]: infer V2 }
|
|
11
|
+
? V2
|
|
12
|
+
: any
|
|
13
|
+
: any
|
|
14
|
+
|
|
15
|
+
export type UnReadonly<R extends Record<string, any>> = {
|
|
16
|
+
-readonly [K in keyof R]: R[K]
|
|
17
|
+
}
|
|
18
|
+
export type ValueType<R extends Record<string, any>> = R extends Record<string, infer V> ? V : R
|
|
19
|
+
export type ExtractModelType<T> = T extends UseBoundStore<StoreApi<infer S>> ? S : unknown
|
|
@@ -2,25 +2,19 @@ import path from 'path'
|
|
|
2
2
|
import { defineConfig } from 'vite'
|
|
3
3
|
import react from '@vitejs/plugin-react'
|
|
4
4
|
import eslint from 'vite-plugin-eslint'
|
|
5
|
-
import {
|
|
5
|
+
import { crx } from '@crxjs/vite-plugin'
|
|
6
6
|
|
|
7
7
|
// https://vitejs.dev/config/
|
|
8
8
|
export default defineConfig(({ mode }) => {
|
|
9
9
|
return {
|
|
10
|
-
plugins: [eslint(), react(),
|
|
10
|
+
plugins: [eslint(), react(), crx({ manifest: require('./manifest.json') })],
|
|
11
11
|
resolve: {
|
|
12
12
|
alias: {
|
|
13
13
|
'@': path.join(__dirname, 'src')
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
esbuild: {
|
|
17
|
-
drop: mode === '
|
|
18
|
-
},
|
|
19
|
-
build: {
|
|
20
|
-
rollupOptions: {
|
|
21
|
-
input: 'src/manifest.json'
|
|
22
|
-
},
|
|
23
|
-
minify: mode === 'developmemnt' ? false : 'esbuild'
|
|
17
|
+
drop: mode === 'development' ? [] : ['console', 'debugger']
|
|
24
18
|
}
|
|
25
19
|
}
|
|
26
20
|
})
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { Suspense } from 'react'
|
|
2
|
-
import { Outlet } from 'react-router-dom'
|
|
1
|
+
import { Suspense, useLayoutEffect } from 'react'
|
|
2
|
+
import { Outlet, useLocation } from 'react-router-dom'
|
|
3
|
+
import { navigate, routerIds } from '@/router'
|
|
3
4
|
import { Loading } from './components'
|
|
4
5
|
|
|
5
6
|
export default function Layout() {
|
|
7
|
+
const location = useLocation()
|
|
8
|
+
|
|
9
|
+
useLayoutEffect(() => {
|
|
10
|
+
if (location.pathname === '/') {
|
|
11
|
+
navigate({ id: routerIds.home })
|
|
12
|
+
}
|
|
13
|
+
}, [location])
|
|
14
|
+
|
|
6
15
|
return (
|
|
7
16
|
<Suspense fallback={<Loading />}>
|
|
8
17
|
<Outlet />
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './home
|
|
1
|
+
export { default } from './home'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default } from './notFound
|
|
1
|
+
export { default } from './notFound'
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { get } from 'lodash-es'
|
|
2
2
|
import { stringify } from 'qs'
|
|
3
3
|
import { NavigateOptions } from 'react-router-dom'
|
|
4
4
|
import { routeType } from '@/router/router.types'
|
|
5
|
-
import { router,
|
|
5
|
+
import { router, routesById } from './router'
|
|
6
6
|
|
|
7
7
|
export function getRoute(id: routeType['id'], path?: string | string[]) {
|
|
8
|
-
const route =
|
|
8
|
+
const route = routesById[id]
|
|
9
9
|
if (path) {
|
|
10
10
|
return get(route, path)
|
|
11
11
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { lazy } from 'react'
|
|
2
2
|
import { createBrowserRouter } from 'react-router-dom'
|
|
3
|
-
import {
|
|
3
|
+
import { assign, isArray, reduce } from 'lodash-es'
|
|
4
|
+
import { ValueType } from '@/types'
|
|
4
5
|
import ids from './ids'
|
|
6
|
+
import * as home from './home'
|
|
5
7
|
import type { routeType } from './router.types'
|
|
6
8
|
|
|
7
9
|
const routes: routeType[] = [
|
|
@@ -9,7 +11,7 @@ const routes: routeType[] = [
|
|
|
9
11
|
path: '/',
|
|
10
12
|
id: ids.root,
|
|
11
13
|
Component: lazy(() => import('@/layout')),
|
|
12
|
-
children: []
|
|
14
|
+
children: [...home.routes]
|
|
13
15
|
},
|
|
14
16
|
{
|
|
15
17
|
path: '*',
|
|
@@ -18,22 +20,23 @@ const routes: routeType[] = [
|
|
|
18
20
|
}
|
|
19
21
|
]
|
|
20
22
|
|
|
21
|
-
export const
|
|
23
|
+
export const routesById = (function flat(routes: routeType[], parentRoute?: routeType) {
|
|
22
24
|
return reduce(
|
|
23
25
|
routes,
|
|
24
26
|
(result, route) => {
|
|
25
27
|
if (parentRoute) {
|
|
26
28
|
route.path = `${parentRoute.path === '/' ? '' : parentRoute.path}/${route.path}`
|
|
27
29
|
}
|
|
28
|
-
result.
|
|
30
|
+
result[route.id] = route
|
|
29
31
|
if (isArray(route.children)) {
|
|
30
|
-
|
|
32
|
+
assign(result, flat(route.children, route))
|
|
31
33
|
}
|
|
32
34
|
return result
|
|
33
35
|
},
|
|
34
|
-
|
|
36
|
+
{} as Record<ValueType<typeof ids>, routeType>
|
|
35
37
|
)
|
|
36
38
|
})(routes)
|
|
39
|
+
|
|
37
40
|
export const router = createBrowserRouter(routes as never, {
|
|
38
41
|
basename: import.meta.env.VITE_BASE_URL
|
|
39
42
|
})
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { create } from 'zustand'
|
|
2
|
-
import { combine } from 'zustand/middleware'
|
|
3
|
-
import { produce } from 'immer'
|
|
4
|
-
|
|
5
|
-
type setStateType<S> = (updater: (state: S) => void) => void
|
|
6
|
-
export interface defineStoreOptionsType<S extends object, A extends object> {
|
|
7
|
-
state: () => S
|
|
8
|
-
actions: (
|
|
9
|
-
setState: setStateType<S>,
|
|
10
|
-
getState: () => S,
|
|
11
|
-
getActions: () => Record<string, any>
|
|
12
|
-
) => A
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function defineStore<S extends object, A extends object>(
|
|
16
|
-
options: defineStoreOptionsType<S, A>
|
|
17
|
-
) {
|
|
18
|
-
return create(
|
|
19
|
-
combine({ state: options.state() }, (setState, getState, store) => {
|
|
20
|
-
const _setState: setStateType<S> = updater => {
|
|
21
|
-
setState(
|
|
22
|
-
produce((store: { state: S }) => {
|
|
23
|
-
updater(store.state)
|
|
24
|
-
}) as any
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
const _getState = () => getState().state
|
|
28
|
-
const _getActions = () => (getState() as any).actions
|
|
29
|
-
return {
|
|
30
|
-
actions: {
|
|
31
|
-
reset: () => {
|
|
32
|
-
setState({ state: options.state() })
|
|
33
|
-
},
|
|
34
|
-
setState: _setState,
|
|
35
|
-
destroy: store.destroy,
|
|
36
|
-
subscribe: store.subscribe,
|
|
37
|
-
...options.actions(_setState, _getState, _getActions)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
)
|
|
42
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|