vite-shadcn-ui-cli 1.0.11 → 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 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
- 'warn',
24
- { allowConstantExport: true },
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/index.js CHANGED
@@ -36,22 +36,19 @@ program
36
36
  output: process.stdout,
37
37
  });
38
38
 
39
- // 提示用户是否覆盖
40
- rl.question('Do you want to overwrite it? (y/N): ', async (answer) => {
39
+ // 提示用户选择
40
+ rl.question('Do you want to overwrite it? (y/N): ', (answer) => {
41
41
  rl.close();
42
42
  if (answer.toLowerCase() === 'y') {
43
- try {
44
- await fs.promises.rm(targetPath, { recursive: true, force: true });
45
- console.log(chalk.yellow(`\n⚠️ The existing directory "${projectDir}" was removed.`));
46
-
47
- // 增加延时确保系统释放资源
48
- setTimeout(() => {
43
+ // fs.rmdirSync(targetPath, { recursive: true, force: true });
44
+ fs.rm(targetPath, { recursive: true, force: true }, (err) => {
45
+ if (err) {
46
+ console.error('Error deleting directory:', err);
47
+ } else {
48
+ console.log(chalk.yellow(`\n⚠️ The existing directory "${projectDir}" was removed.`));
49
49
  cloneRepo(projectDir);
50
- }, 500); // 500ms 延时
51
- } catch (err) {
52
- console.error(chalk.red(`Failed to remove directory: ${err.message}`));
53
- process.exit(1);
54
- }
50
+ }
51
+ });
55
52
  } else {
56
53
  console.log(chalk.blue('\nOperation cancelled.'));
57
54
  process.exit(1);
@@ -62,29 +59,29 @@ program
62
59
  }
63
60
  });
64
61
 
62
+ program.parse(process.argv);
63
+
65
64
  // 克隆 GitHub 仓库的函数
66
65
  async function cloneRepo(projectDir) {
67
66
  const spinner = ora('Cloning the repository...').start();
68
67
  const repoUrl = 'https://github.com/kyrie668/vite-shadcn-ui.git';
69
68
 
70
69
  try {
71
- execSync(`git clone ${repoUrl} ${projectDir}`, { stdio: 'ignore' });
70
+ await git.clone(repoUrl, projectDir);
72
71
  spinner.succeed('Project cloned successfully!');
73
72
 
74
73
  // 移除 .git 文件夹以断开 Git 关联
75
- await fs.promises.rm(path.join(projectDir, '.git'), { recursive: true, force: true });
74
+ fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
76
75
  console.log(
77
76
  chalk.green('\n✅ Git history removed. You can now initialize your own repository.')
78
77
  );
79
-
80
78
  console.log(chalk.cyan(`\n👉 Next steps:`));
81
79
  console.log(` cd ${projectDir}`);
82
80
  console.log(' npm install');
83
81
  console.log(' npm run dev');
84
82
  } catch (error) {
85
83
  spinner.fail('Failed to clone the repository.');
86
- console.error(chalk.red(`\nError: ${error.message}`));
84
+ console.error(error);
87
85
  process.exit(1);
88
86
  }
89
87
  }
90
- program.parse();
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "vite-shadcn-ui-cli",
3
- "version": "1.0.11",
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
- "chalk": "^4.1.2",
27
- "ora": "^6.0.0",
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
@@ -17,8 +17,8 @@
17
17
 
18
18
  /* Linting */
19
19
  "strict": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": false,
22
22
  "noFallthroughCasesInSwitch": true,
23
23
  "noUncheckedSideEffectImports": true,
24
24
  "baseUrl": ".",
@@ -15,8 +15,8 @@
15
15
 
16
16
  /* Linting */
17
17
  "strict": true,
18
- "noUnusedLocals": true,
19
- "noUnusedParameters": true,
18
+ "noUnusedLocals": false,
19
+ "noUnusedParameters": false,
20
20
  "noFallthroughCasesInSwitch": true,
21
21
  "noUncheckedSideEffectImports": true
22
22
  },
package/vite.config.ts CHANGED
@@ -1,12 +1,24 @@
1
- import path from "path"
2
- import react from "@vitejs/plugin-react"
3
- import { defineConfig } from "vite"
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
- "@": path.resolve(__dirname, "./src"),
21
+ '@': path.resolve(__dirname, './src'),
10
22
  },
11
23
  },
12
- })
24
+ });