vite-shadcn-ui-cli 1.0.13 → 1.0.14
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/eslint.config.js +16 -11
- package/package.json +8 -7
- package/src/App.tsx +8 -0
- package/src/request.ts +55 -0
- package/src/utils/index.ts +44 -0
- package/tsconfig.app.json +2 -2
- package/tsconfig.node.json +2 -2
- package/vite.config.ts +18 -6
package/eslint.config.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import js from '@eslint/js'
|
2
|
-
import globals from 'globals'
|
3
|
-
import reactHooks from 'eslint-plugin-react-hooks'
|
4
|
-
import reactRefresh from 'eslint-plugin-react-refresh'
|
5
|
-
import tseslint from 'typescript-eslint'
|
1
|
+
import js from '@eslint/js';
|
2
|
+
import globals from 'globals';
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh';
|
5
|
+
import tseslint from 'typescript-eslint';
|
6
6
|
|
7
7
|
export default tseslint.config(
|
8
8
|
{ ignores: ['dist'] },
|
@@ -19,10 +19,15 @@ export default tseslint.config(
|
|
19
19
|
},
|
20
20
|
rules: {
|
21
21
|
...reactHooks.configs.recommended.rules,
|
22
|
-
'react-refresh/only-export-components': [
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
|
23
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
24
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
25
|
+
'no-unused-vars': 'off',
|
26
|
+
'@typescript-eslint/no-floating-promises': 'off',
|
27
|
+
'react-hooks/exhaustive-deps': 'off',
|
28
|
+
'react/no-unescaped-entities': 'off',
|
29
|
+
'react-refresh/only-export-components': 'off',
|
30
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
26
31
|
},
|
27
|
-
}
|
28
|
-
)
|
32
|
+
}
|
33
|
+
);
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "vite-shadcn-ui-cli",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.14",
|
4
4
|
"description": "A CLI tool to bootstrap Vite projects with shadcn UI components",
|
5
5
|
"main": "index.js",
|
6
6
|
"bin": {
|
7
7
|
"create-vite-shadcn-ui": "./index.js"
|
8
8
|
},
|
9
|
-
"type":"module",
|
9
|
+
"type": "module",
|
10
10
|
"scripts": {
|
11
11
|
"dev": "vite",
|
12
12
|
"build": "tsc -b && vite build",
|
@@ -15,17 +15,18 @@
|
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
17
|
"@radix-ui/react-slot": "^1.1.1",
|
18
|
+
"axios": "^1.7.9",
|
19
|
+
"chalk": "^4.1.2",
|
18
20
|
"class-variance-authority": "^0.7.1",
|
19
21
|
"clsx": "^2.1.1",
|
22
|
+
"commander": "^11.0.0",
|
20
23
|
"lucide-react": "^0.473.0",
|
24
|
+
"ora": "^6.0.0",
|
21
25
|
"react": "^18.3.1",
|
22
26
|
"react-dom": "^18.3.1",
|
23
|
-
"tailwind-merge": "^2.6.0",
|
24
|
-
"tailwindcss-animate": "^1.0.7",
|
25
27
|
"simple-git": "^3.8.0",
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"commander": "^11.0.0"
|
28
|
+
"tailwind-merge": "^2.6.0",
|
29
|
+
"tailwindcss-animate": "^1.0.7"
|
29
30
|
},
|
30
31
|
"devDependencies": {
|
31
32
|
"@eslint/js": "^9.17.0",
|
package/src/App.tsx
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
+
import { useEffect } from 'react';
|
1
2
|
import './App.css';
|
2
3
|
import { Button } from '@/components/ui/button';
|
4
|
+
import { get } from './request';
|
3
5
|
|
4
6
|
function App() {
|
7
|
+
useEffect(() => {
|
8
|
+
// 发送 GET 请求
|
9
|
+
get('/user', { id: 1 }).then((res) => {
|
10
|
+
console.log('User Info:', res);
|
11
|
+
});
|
12
|
+
}, []);
|
5
13
|
return (
|
6
14
|
<>
|
7
15
|
<div>
|
package/src/request.ts
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
import axios, { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @description 请求基础配置
|
5
|
+
*/
|
6
|
+
const axiosInstance: AxiosInstance = axios.create({
|
7
|
+
baseURL: '/api', // API 基础 URL
|
8
|
+
timeout: 5000, // 超时时间 5s
|
9
|
+
withCredentials: true, // 允许跨域携带凭证
|
10
|
+
headers: {
|
11
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
12
|
+
},
|
13
|
+
});
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @description 请求拦截器
|
17
|
+
*/
|
18
|
+
axiosInstance.interceptors.request.use(
|
19
|
+
(config: InternalAxiosRequestConfig) => {
|
20
|
+
// 可以在此处添加 token
|
21
|
+
return config;
|
22
|
+
},
|
23
|
+
(error) => {
|
24
|
+
return Promise.reject(error);
|
25
|
+
}
|
26
|
+
);
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @description 响应拦截器
|
30
|
+
*/
|
31
|
+
axiosInstance.interceptors.response.use(
|
32
|
+
(response: AxiosResponse) => {
|
33
|
+
return response.data;
|
34
|
+
},
|
35
|
+
(error) => {
|
36
|
+
console.error('请求出错:', error);
|
37
|
+
return Promise.reject(error);
|
38
|
+
}
|
39
|
+
);
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @description 封装 GET 请求
|
43
|
+
*/
|
44
|
+
export function get<T>(url: string, params?: object): Promise<T> {
|
45
|
+
return axiosInstance.get<T>(url, { params }).then((response) => response.data); // ✅ 提取出 AxiosResponse 中的数据部分
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* @description 封装 POST 请求
|
50
|
+
*/
|
51
|
+
export function post<T>(url: string, data?: object): Promise<T> {
|
52
|
+
return axiosInstance.post<T>(url, data).then((response) => response.data); // ✅ 提取出 AxiosResponse 中的数据部分
|
53
|
+
}
|
54
|
+
|
55
|
+
export default axiosInstance;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/**
|
2
|
+
* @description 函数防抖
|
3
|
+
* @param func 需要进行防抖的函数
|
4
|
+
* @param delay 时间间隔(毫秒)
|
5
|
+
* @returns 返回一个防抖后的函数
|
6
|
+
*/
|
7
|
+
export function debounce<T extends (...args: any[]) => void>(func: T, delay: number): T {
|
8
|
+
let timer: NodeJS.Timeout | null = null;
|
9
|
+
|
10
|
+
return function (this: ThisParameterType<T>, ...args: Parameters<T>) {
|
11
|
+
if (timer) clearTimeout(timer);
|
12
|
+
|
13
|
+
timer = setTimeout(() => {
|
14
|
+
func.apply(this, args);
|
15
|
+
}, delay);
|
16
|
+
} as T;
|
17
|
+
}
|
18
|
+
|
19
|
+
/**
|
20
|
+
* @description 函数节流
|
21
|
+
* @param func 需要进行节流的函数
|
22
|
+
* @param delay 时间间隔(毫秒)
|
23
|
+
* @returns 返回一个节流后的函数
|
24
|
+
*/
|
25
|
+
export function throttle<T extends (...args: any[]) => void>(func: T, delay: number): T {
|
26
|
+
let lastExecTime = 0;
|
27
|
+
let timer: NodeJS.Timeout | null = null;
|
28
|
+
|
29
|
+
return function (this: ThisParameterType<T>, ...args: Parameters<T>) {
|
30
|
+
const currentTime = Date.now();
|
31
|
+
const elapsedTime = currentTime - lastExecTime;
|
32
|
+
|
33
|
+
if (!timer || elapsedTime >= delay) {
|
34
|
+
func.apply(this, args);
|
35
|
+
lastExecTime = currentTime;
|
36
|
+
} else {
|
37
|
+
if (timer) clearTimeout(timer);
|
38
|
+
timer = setTimeout(() => {
|
39
|
+
func.apply(this, args);
|
40
|
+
lastExecTime = Date.now();
|
41
|
+
}, delay - elapsedTime);
|
42
|
+
}
|
43
|
+
} as T;
|
44
|
+
}
|
package/tsconfig.app.json
CHANGED
package/tsconfig.node.json
CHANGED
package/vite.config.ts
CHANGED
@@ -1,12 +1,24 @@
|
|
1
|
-
import path from
|
2
|
-
import react from
|
3
|
-
import { defineConfig } from
|
4
|
-
|
1
|
+
import path from 'path';
|
2
|
+
import react from '@vitejs/plugin-react';
|
3
|
+
import { defineConfig } from 'vite';
|
4
|
+
|
5
5
|
export default defineConfig({
|
6
6
|
plugins: [react()],
|
7
|
+
server: {
|
8
|
+
port: 8888,
|
9
|
+
cors: true, // 允许跨域
|
10
|
+
hmr: true, // 开启热更新
|
11
|
+
proxy: {
|
12
|
+
"/api": {
|
13
|
+
target: "http://baidu.com", // 设置要代理到的主机名
|
14
|
+
changeOrigin: true,
|
15
|
+
},
|
16
|
+
},
|
17
|
+
},
|
18
|
+
base: './',
|
7
19
|
resolve: {
|
8
20
|
alias: {
|
9
|
-
|
21
|
+
'@': path.resolve(__dirname, './src'),
|
10
22
|
},
|
11
23
|
},
|
12
|
-
})
|
24
|
+
});
|