create-young-proj 1.2.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +6 -1
  3. package/dist/index.mjs +12 -12
  4. package/package.json +1 -1
  5. package/src/index.ts +6 -1
  6. package/template-nuxt-admin/env.d.ts +19 -1
  7. package/template-nuxt-admin/nuxt.config.ts +4 -2
  8. package/template-nuxt-admin/server/plugins/env.ts +0 -1
  9. package/template-nuxt-website/README.md +4 -0
  10. package/template-nuxt-website/composables/utils.ts +0 -4
  11. package/template-nuxt-website/env.d.ts +18 -1
  12. package/template-nuxt-website/nuxt.config.ts +3 -2
  13. package/template-nuxt-website/package.json +4 -5
  14. package/template-nuxt-website/server/api/get_footer_info.get.ts +3 -3
  15. package/template-nuxt-website/server/api/get_gray_status.get.ts +1 -0
  16. package/template-nuxt-website/server/api/get_head_nav.get.ts +1 -1
  17. package/template-nuxt-website/server/api/get_home_banner.get.ts +2 -2
  18. package/template-nuxt-website/server/routes/get/env.ts +13 -0
  19. package/template-nuxt-website/yarn.lock +1173 -1599
  20. package/template-uni-app/.vscode/vue-html.code-snippets +2 -7
  21. package/template-uni-app/README.md +2 -0
  22. package/template-uni-app/_env +1 -1
  23. package/template-uni-app/auto-imports.d.ts +718 -1
  24. package/template-uni-app/custom-plugins/multiconf.ts +13 -2
  25. package/template-uni-app/eslint.config.js +3 -1
  26. package/template-uni-app/package.json +11 -9
  27. package/template-uni-app/pnpm-lock.yaml +531 -866
  28. package/template-uni-app/src/manifest.json +1 -1
  29. package/template-uni-app/src/pages/index.vue +12 -9
  30. package/template-uni-app/src/pages/my.vue +6 -9
  31. package/template-uni-app/src/pages.json +1 -1
  32. package/template-uni-app/uni-pages.d.ts +24 -0
  33. package/template-uni-app/vite.config.ts +6 -3
  34. package/template-vitepress/.vitepress/components/HomePage.vue +54 -0
  35. package/template-vitepress/.vitepress/components/TodoItem.vue +16 -0
  36. package/template-vitepress/.vitepress/components.d.ts +13 -0
  37. package/template-vitepress/.vitepress/config.mts +159 -0
  38. package/template-vitepress/.vitepress/theme/index.ts +26 -0
  39. package/template-vitepress/.vitepress/theme/style.css +139 -0
  40. package/template-vitepress/Dockerfile +41 -0
  41. package/template-vitepress/README.md +102 -0
  42. package/template-vitepress/_gitignore +6 -0
  43. package/template-vitepress/_npmrc +2 -0
  44. package/template-vitepress/_nvmrc +1 -0
  45. package/template-vitepress/boot.mjs +17 -0
  46. package/template-vitepress/index.md +53 -0
  47. package/template-vitepress/nitro.config.ts +19 -0
  48. package/template-vitepress/package.json +26 -0
  49. package/template-vitepress/plugins/init.ts +204 -0
  50. package/template-vitepress/tsconfig.json +3 -0
  51. package/template-vitepress/vite.config.ts +66 -0
  52. package/template-uni-app/.eslintignore +0 -1
  53. package/template-uni-app/.eslintrc +0 -16
@@ -0,0 +1,102 @@
1
+ # template-vitepress
2
+
3
+ [![](https://img.shields.io/badge/Author-BluesYoung--web-blue)](https://gitee.com/BluesYoung-web)
4
+
5
+ ## 本地运行
6
+
7
+ ::: code-group
8
+ ```bash [yarn]
9
+ # 装依赖
10
+ yarn
11
+ # 运行
12
+ yarn dev
13
+ ```
14
+ ```bash [pnpm]
15
+ # 装依赖
16
+ pnpm i
17
+ # 运行
18
+ pnpm dev
19
+ ```
20
+ ```bash [bun]
21
+ # 装依赖
22
+ bun i
23
+ # 运行
24
+ bun dev
25
+ ```
26
+ ```bash [npm]
27
+ # 装依赖
28
+ npm i
29
+ # 运行
30
+ npm run dev
31
+ ```
32
+ :::
33
+
34
+ ## 到手之后需要自行调整的内容
35
+
36
+ ### `.vitepress/config.mts`
37
+
38
+ <TodoItem>seo 相关<code ml-1>title, description</code></TodoItem>
39
+
40
+ :::danger
41
+ <TodoItem>部署相关<code ml-1>base</code></TodoItem>
42
+
43
+ - 根路径部署就删掉,否则为部署的路径,**必须以 `/` 结尾**
44
+
45
+ - [官方文档](https://vitepress.dev/reference/site-config#base)
46
+ :::
47
+
48
+ <TodoItem><a href="https://vitepress.dev/reference/default-theme-nav" target="_blank">顶部导航</a> <code ml-1>themeConfig -> nav</code></TodoItem>
49
+
50
+ <TodoItem><a href="https://vitepress.dev/reference/default-theme-sidebar" target="_blank">侧边栏导航</a> <code ml-1>themeConfig -> sidebar</code></TodoItem>
51
+
52
+ <TodoItem>替换仓库地址 <code ml-1>themeConfig -> socialLinks -> link</code></TodoItem>
53
+
54
+ <TodoItem>替换仓库地址 <code ml-1>themeConfig -> editLink -> pattern</code></TodoItem>
55
+
56
+ ### `index.md`
57
+
58
+ <TodoItem>标题及描述 <code ml-1>hero -> [name, text, tagline]</code></TodoItem>
59
+
60
+ <TodoItem>快捷导航 <code ml-1>hero -> actions</code></TodoItem>
61
+
62
+ <TodoItem>特性介绍 <code ml-1>features</code></TodoItem>
63
+
64
+ ### 首页贡献者
65
+
66
+ `.vitepress/components/HomePage.vue -> teamMembers` 按需修改
67
+
68
+ :::info
69
+ 如果不需要展示,将 `.vitepress/theme/index.ts -> 'home-features-after'` 这一行注释即可
70
+ :::
71
+
72
+ ## 文档书写
73
+
74
+ ### 简介
75
+
76
+ 标题:`使用 # 符号表示标题,数量代表标题级别。例如:# 一级标题、## 二级标题`
77
+
78
+ 段落和换行:`段落之间使用空行分隔,要插入换行符,可以在行末添加两个空格`
79
+
80
+ 强调:`使用 * 或 _ 包围文本来斜体显示,使用两个 * 或 _ 包围文本来加粗显示。例如:*斜体文本*、**加粗文本**`
81
+
82
+ 列表:`使用 *、+ 或 - 开头创建无序列表,使用数字后跟句点创建有序列表。嵌套列表时缩进四个空格或一个制表符`
83
+
84
+ 链接:`使用 [显示文本](链接地址) 的格式创建链接。例如:[OpenAI](https://openai.com)`
85
+
86
+ 图片:`使用 ![替代文本](图片链接地址) 的格式插入图片。例如:![Logo](https://example.com/logo.png)`
87
+
88
+ 引用块:`使用 > 表示引用块。可以嵌套使用多个 > 表示多层引用`
89
+
90
+ 代码块:`使用三个反引号 ```` 或四个空格缩进来创建代码块。可以指定语言以进行语法高亮`
91
+
92
+ 水平线:`使用三个或更多连续的 -、* 或 _ 创建水平线分隔线`
93
+
94
+ 转义字符:`在特殊字符前添加反斜杠 \ 可以转义字符的原始含义`
95
+
96
+ ### 外部教程
97
+
98
+ [vitepress 扩展语法](https://vitepress.dev/guide/markdown)
99
+
100
+ [基础语法](https://www.markdownguide.org/basic-syntax/)
101
+
102
+ [中文技术文档的写作规范——阮一峰](https://github.com/ruanyf/document-style-guide)
@@ -0,0 +1,6 @@
1
+ node_modules
2
+ *.log
3
+ cache
4
+ dist
5
+ .output
6
+ .nitro
@@ -0,0 +1,2 @@
1
+ shamefully-hoist=true
2
+ strict-peer-dependencies=false
@@ -0,0 +1 @@
1
+ 20.9.0
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2022-09-16 11:48:05
4
+ * @LastEditTime: 2023-11-09 11:59:07
5
+ * @Description:
6
+ */
7
+ (async () => {
8
+ const env = process.env.DEPLOY_ENV || 'dev';
9
+ const listenPort = process.env.LISTEN_PORT || 3333;
10
+ console.log('当前环境:', env);
11
+ console.log('服务监听端口:', listenPort);
12
+
13
+ process.env.NITRO_PORT = listenPort;
14
+
15
+ await import('./.output/server/index.mjs');
16
+ })();
17
+
@@ -0,0 +1,53 @@
1
+ ---
2
+ # https://vitepress.dev/reference/default-theme-home-page
3
+ layout: home
4
+
5
+ hero:
6
+ name: 前端知识库
7
+ text: 知识共建,共创未来
8
+ tagline: 多种实用工具,满足不同需求
9
+ image:
10
+ src: https://api.iconify.design/noto:rocket.svg?color=%2312b2e7&width=320
11
+ actions:
12
+ - theme: brand
13
+ text: 快速开始
14
+ link: /newer
15
+ - theme: alt
16
+ text: 前端规范
17
+ link: /standards
18
+ - theme: alt
19
+ text: 常见问题及解决方案
20
+ link: /problems
21
+
22
+ features:
23
+ - title: '@bluesyoung/ui-vue3-element-plus'
24
+ icon: <span class="i-ep-element-plus text-[#409eff]"></span>
25
+ details: 基于 element-plus 二次封装的常用组件库
26
+ link: /libs/public/ui-vue3-element-plus
27
+
28
+ - title: '@bluesyoung/http'
29
+ icon: <span class="i-logos-lighttpd"></span>
30
+ details: 基于 axios 封装的 http 请求库, 拥有完善的 TS 类型提示, 支持 web/微信小程序
31
+ link: /libs/public/http
32
+
33
+ - title: '@bluesyoung/utils'
34
+ icon: <span class="i-tabler-tools text-[#409eff]"></span>
35
+ details: 常用工具函数
36
+ link: https://gitee.com/-/ide/project/BluesYoung-web/young/edit/master/-/packages/utils/dist/index.d.ts
37
+
38
+ - title: '@bluesyoung/logger'
39
+ icon: <span class="i-vscode-icons-file-type-log"></span>
40
+ details: 基于 consola 封装的日志工具, 默认格式化为容器部署要求的格式, 并保留了扩充能力
41
+ link: /libs/public/logger
42
+
43
+ - title: '@bluesyoung/rpc'
44
+ icon: <span class="i-simple-icons-trpc text-[#409eff]"></span>
45
+ details: 页面与其嵌套的 iframe 或由其打开的子页面之间进行通信
46
+ link: /libs/public/rpc
47
+
48
+ - title: '@bluesyoung/ui-vue3'
49
+ icon: <span class="i-logos-vue"></span>
50
+ details: 基于 vue3 + @vueuse/core 封装的组件,无额外的依赖
51
+ link: /libs/public/ui-vue3
52
+ ---
53
+
@@ -0,0 +1,19 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2022-12-28 11:59:56
4
+ * @LastEditTime: 2023-11-14 09:18:38
5
+ * @Description:
6
+ */
7
+ export default defineNitroConfig({
8
+ /**
9
+ * 托管前端静态资源
10
+ */
11
+ serveStatic: 'node',
12
+ publicAssets: [
13
+ {
14
+ dir: '.vitepress/dist',
15
+ },
16
+ ],
17
+ preset: 'bun'
18
+ });
19
+
@@ -0,0 +1,26 @@
1
+ {
2
+ "scripts": {
3
+ "dev": "vitepress dev",
4
+ "docs:dev": "vitepress dev",
5
+ "docs:build": "vitepress build",
6
+ "docs:preview": "vitepress preview",
7
+ "build": "vitepress build && nitropack build",
8
+ "postinstall": "nitropack prepare"
9
+ },
10
+ "devDependencies": {
11
+ "@iconify/json": "^2.2.139",
12
+ "@types/md5": "^2.3.5",
13
+ "@types/node": "20",
14
+ "nitropack": "^2.7.2",
15
+ "pathe": "^1.1.1",
16
+ "unocss": "^0.57.2",
17
+ "unplugin-vue-components": "^0.25.2",
18
+ "vitepress": "^1.0.0-rc.25",
19
+ "vue": "^3.3.8"
20
+ },
21
+ "dependencies": {
22
+ "c12": "^1.5.1",
23
+ "md5": "^2.3.0"
24
+ },
25
+ "version": "1.0.0"
26
+ }
@@ -0,0 +1,204 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2023-11-10 18:02:07
4
+ * @LastEditTime: 2023-11-27 15:01:31
5
+ * @Description:
6
+ */
7
+ import { resolve } from 'node:path'
8
+ import { loadConfig } from 'c12'
9
+ import md5 from 'md5'
10
+
11
+ /**
12
+ * 签名
13
+ * @param params 参与签名的参数
14
+ * @param token 秘钥
15
+ */
16
+ export function signFn(params: Record<string, any>, token: string) {
17
+ const asciiSortedIndexArr = Object.keys(params).sort()
18
+ let str = ''
19
+ const obj: Record<string, any> = {}
20
+ if (asciiSortedIndexArr.length > 0) {
21
+ for (const key of asciiSortedIndexArr) {
22
+ const v = params[key]
23
+ if (v !== null && v !== '') {
24
+ str += `${key}=${encodeURIComponent(v)}&`
25
+ obj[key] = v
26
+ }
27
+ }
28
+ }
29
+ str += `token=${token}`
30
+ return {
31
+ sign: md5(str).toUpperCase(),
32
+ rawValue: obj,
33
+ }
34
+ }
35
+
36
+ /**
37
+ * 服务上报
38
+ */
39
+ export async function useServerReport(port: number) {
40
+ enum ReportURL {
41
+ 上线 = '/register/login',
42
+ 心跳 = '/register/heart',
43
+ }
44
+
45
+ const commonReq = async <T>(url: string, data: Record<string, any>, token: string) => {
46
+ const api_server_url
47
+ = process.env.NUXT_PUBLIC_API_SERVER || `http://${process.env.APIGATEHOST}`
48
+ const { sign, rawValue } = signFn(data, token)
49
+
50
+ console.log('🚀 ~ file: env.ts:41 ~ commonReq ~ api_server_url:', api_server_url, rawValue)
51
+
52
+ const headers = {
53
+ 'Authorization': `Bearer ${token}`,
54
+ 'content-type': 'application/json; charset=utf-8;',
55
+ 'time': `${Math.floor(Date.now() / 1000)}`,
56
+ sign,
57
+ }
58
+
59
+ return $fetch<T>(`${api_server_url}${url}`, {
60
+ method: 'post',
61
+ headers,
62
+ body: JSON.stringify(rawValue),
63
+ })
64
+ }
65
+
66
+ /**
67
+ * auth token
68
+ */
69
+ let token: string
70
+
71
+ /**
72
+ * 登录/获取 token
73
+ */
74
+ const login = async () => {
75
+ const data = {
76
+ serverId: process.env.APP_SERVER_ID,
77
+ serverName: process.env.APP_SERVER_NAME,
78
+ }
79
+
80
+ const { data: _data } = await commonReq<{
81
+ code: number
82
+ message: string
83
+ data: { token: string }
84
+ }>('/account/v1/internal/service/get_token', data, process.env.APP_SERVER_SECERET as string)
85
+
86
+ console.log('🚀 ~ file: env.ts:73 ~ login ~ _data:', _data)
87
+
88
+ const { token } = _data
89
+ console.log('login success, token: ', token, '\ntime: ', new Date().toLocaleString())
90
+ return token
91
+ }
92
+
93
+ /**
94
+ * 获取 auth token
95
+ */
96
+ const getToken = async () => {
97
+ if (!token) {
98
+ token = await login()
99
+ setInterval(() => {
100
+ // 每 23 小时刷一次 token
101
+ token = ''
102
+ }, 1000 * 3600 * 23)
103
+ }
104
+ return token
105
+ }
106
+
107
+ /**
108
+ * 服务上线
109
+ */
110
+ const report = async (url: ReportURL) => {
111
+ const token = await getToken()
112
+ try {
113
+ const res = await commonReq<{
114
+ host: string
115
+ port: string | number
116
+ weight: number
117
+ expire: number
118
+ }>(url, { port }, token)
119
+
120
+ console.log('请求成功:', url, new Date().toLocaleString())
121
+ return res
122
+ }
123
+ catch (error) {
124
+ console.error('请求失败:', url, error)
125
+ }
126
+ }
127
+
128
+ console.log('------------------------服务登录------------------------')
129
+ await login()
130
+ console.log('--------------------------------------------------------')
131
+
132
+ console.log('------------------------服务上线------------------------')
133
+ const info1 = await report(ReportURL.上线)
134
+ console.log('🚀 ~ file: init.ts:156 ~ defineNitroPlugin ~ info', info1)
135
+ console.log('--------------------------------------------------------')
136
+
137
+ console.log('------------------------服务心跳上报----------------------')
138
+ const info2 = await report(ReportURL.心跳)
139
+ console.log('🚀 ~ file: init.ts:163 ~ setInterval ~ info', info2)
140
+ console.log('----------------------------------------------------------')
141
+ setInterval(async () => {
142
+ console.log('------------------------服务心跳上报----------------------')
143
+ const info = await report(ReportURL.心跳)
144
+ console.log('🚀 ~ file: init.ts:163 ~ setInterval ~ info', info)
145
+ console.log('----------------------------------------------------------')
146
+ }, 1e4)
147
+ }
148
+
149
+ export default defineNitroPlugin(async (nitroApp) => {
150
+ const env = (process.env.DEPLOY_ENV as 'dev' | 'test' | 'online') || 'dev'
151
+ const { config } = await loadConfig<Record<string, any>>({
152
+ name: env,
153
+ cwd: resolve(process.cwd(), 'config'),
154
+ defaultConfig: {
155
+ // 此处可以放置通用的环境变量
156
+ // 由于频繁修改 package.json 会浪费 docker 性能,故将版本信息放于此处
157
+ // 优先读取环境变量中的版本信息(自己打的 Tag)
158
+ NUXT_PUBLIC_CURRENT_VERSION: process.env.PROJECT_VERSION || 'v0.0.1',
159
+
160
+ // 服务秘钥,不对前端开放
161
+ APP_SERVER_SECERET: '我是秘钥',
162
+ APP_SERVER_NAME: '我是服务名称',
163
+ APP_SERVER_ID: '我是服务id',
164
+ },
165
+ })
166
+
167
+ for (const key in config) {
168
+ if (process.env[key]) {
169
+ console.log(
170
+ '系统环境变量优先: ',
171
+ key,
172
+ ' = ',
173
+ process.env[key],
174
+ ' -> ',
175
+ config[key],
176
+ ' -> ',
177
+ '覆盖',
178
+ )
179
+ config[key] = process.env[key]
180
+ }
181
+ else {
182
+ process.env[key] = config[key]
183
+ }
184
+ if (!(key.indexOf('NUXT_PUBLIC_') === 0))
185
+ delete config[key]
186
+ }
187
+
188
+ console.log('------------------------读取配置文件------------------------')
189
+ console.log(config)
190
+ console.log('-------------------------------------------------------------')
191
+
192
+ nitroApp.hooks.hook('request', (event) => {
193
+ const headers = event.node.req.headers
194
+ const path = event.node.req.url
195
+ console.log('path', path, 'ua', headers['user-agent'], 'x-forwarded-for', headers['x-forwarded-for'], 'x-real-ip', headers['x-real-ip'])
196
+ })
197
+
198
+ // 本地开发,不上报
199
+ if (process.env.NODE_ENV === 'development')
200
+ return
201
+
202
+ const port = process.env.LISTEN_PORT || 3333
203
+ useServerReport(+port)
204
+ })
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./.nitro/types/tsconfig.json"
3
+ }
@@ -0,0 +1,66 @@
1
+ /*
2
+ * @Author: zhangyang
3
+ * @Date: 2023-11-08 16:35:24
4
+ * @LastEditTime: 2023-11-08 16:37:49
5
+ * @Description:
6
+ */
7
+ import fs from 'node:fs'
8
+ import type { Plugin } from 'vite'
9
+ import { defineConfig } from 'vite'
10
+ import Components from 'unplugin-vue-components/vite'
11
+ import Unocss from 'unocss/vite'
12
+ import { presetAttributify, presetIcons, presetUno } from 'unocss'
13
+ import { resolve } from 'pathe'
14
+
15
+ export default defineConfig({
16
+ optimizeDeps: {
17
+ // vitepress is aliased with replacement `join(DIST_CLIENT_PATH, '/index')`
18
+ // This needs to be excluded from optimization
19
+ exclude: ['@vueuse/core', 'vitepress'],
20
+ },
21
+ server: {
22
+ host: true,
23
+ hmr: {
24
+ overlay: false,
25
+ },
26
+ },
27
+ plugins: [
28
+ Components({
29
+ include: [/\.vue/, /\.md/],
30
+ dirs: '.vitepress/components',
31
+ dts: '.vitepress/components.d.ts',
32
+ }) as Plugin,
33
+ Unocss({
34
+ shortcuts: [
35
+ ['btn', 'px-4 py-1 rounded inline-flex justify-center gap-2 text-white leading-30px children:mya !no-underline cursor-pointer disabled:cursor-default disabled:bg-gray-600 disabled:opacity-50'],
36
+ ],
37
+ presets: [
38
+ presetUno({
39
+ dark: 'media',
40
+ }),
41
+ presetAttributify(),
42
+ presetIcons({
43
+ scale: 1.2,
44
+ }),
45
+ ],
46
+ }),
47
+ IncludesPlugin(),
48
+ ],
49
+ })
50
+
51
+ function IncludesPlugin(): Plugin {
52
+ return {
53
+ name: 'include-plugin',
54
+ enforce: 'pre',
55
+ transform(code, id) {
56
+ let changed = false
57
+ code = code.replace(/\[@@include\]\((.*?)\)/, (_, url) => {
58
+ changed = true
59
+ const full = resolve(id, url)
60
+ return fs.readFileSync(full, 'utf-8')
61
+ })
62
+ if (changed)
63
+ return code
64
+ },
65
+ }
66
+ }
@@ -1 +0,0 @@
1
- src/uni_modules
@@ -1,16 +0,0 @@
1
- {
2
- "root": true,
3
- "extends": "@antfu",
4
- "rules": {
5
- "@typescript-eslint/no-use-before-define": "off",
6
- "no-console": "off",
7
- "n/prefer-global/process": "off",
8
- "unused-imports/no-unused-vars": "off",
9
- "@typescript-eslint/ban-types": "off",
10
- "vue/valid-v-model": "off",
11
- "@typescript-eslint/ban-ts-comment": "off",
12
- "no-throw-literal": "off",
13
- "prefer-promise-reject-errors": "off",
14
- "no-async-promise-executor": "off"
15
- }
16
- }