@liujitcn/kratos-uni-app-cli 0.0.32 → 0.0.34

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.mjs +25 -5
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "type": "git",
8
8
  "url": "git@github.com:liujitcn/kratos-admin.git"
9
9
  },
10
- "version": "0.0.32",
10
+ "version": "0.0.34",
11
11
  "type": "module",
12
12
  "files": [
13
13
  "bin",
package/src/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
1
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
2
2
  import { basename, resolve } from 'node:path'
3
3
 
4
4
  const cliPackage = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
@@ -60,6 +60,10 @@ export function scaffoldKratosApp(targetPath, options = {}) {
60
60
  }),
61
61
  )
62
62
  writeEnvironmentFiles(target)
63
+ copyFileSync(
64
+ new URL('../assets/favicon.ico', import.meta.url),
65
+ resolve(target, 'apps/uni-app/favicon.ico'),
66
+ )
63
67
  write(
64
68
  target,
65
69
  'README.md',
@@ -90,6 +94,8 @@ pnpm build:h5
90
94
  pnpm build:mp-weixin
91
95
  \`\`\`
92
96
 
97
+ H5 通过局域网 IP 访问时,先在仓库根目录运行 bash scripts/generate-dev-cert.sh 192.168.1.100 生成证书,再在 .env.development-h5.local 中设置 VITE_APP_HTTPS=true;后端使用 HTTPS 时同时设置 VITE_APP_API_URL=https://localhost:7001。
98
+
93
99
  模块装配入口是 \`apps/uni-app/src/module-manifest.ts\`。新增、删除或调整模块时同步维护该清单,并在模块自己的 README 中记录页面和接口职责。
94
100
 
95
101
  生产构建前请在 \`.env.production\` 中填写实际 API 和静态资源地址;该文件默认留空,不应使用本机地址。
@@ -271,7 +277,7 @@ export function createApp() {
271
277
  target,
272
278
  'apps/uni-app/index.html',
273
279
  `<!doctype html>
274
- <html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><title>${projectName}</title></head>
280
+ <html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><link rel="icon" href="./favicon.ico"><title>${projectName}</title></head>
275
281
  <body><div id="app"><!--app-html--></div><script type="module" src="/src/main.ts"></script></body></html>
276
282
  `,
277
283
  )
@@ -279,6 +285,7 @@ export function createApp() {
279
285
  target,
280
286
  'apps/uni-app/vite.config.ts',
281
287
  `import { dirname, resolve } from 'node:path'
288
+ import { existsSync, readFileSync } from 'node:fs'
282
289
  import { fileURLToPath } from 'node:url'
283
290
  import {
284
291
  createKratosUniPlugin,
@@ -293,6 +300,16 @@ const workspaceRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..')
293
300
  const coreRoot = resolve(workspaceRoot, 'node_modules/@liujitcn/kratos-uni-app-core')
294
301
  const systemRoot = resolve(workspaceRoot, 'node_modules/@liujitcn/kratos-uni-app-system')
295
302
 
303
+ function resolveHttpsOptions(env, root) {
304
+ if (env.VITE_APP_HTTPS !== 'true') return undefined
305
+ const keyPath = resolve(root, env.VITE_APP_HTTPS_KEY || '../../certs/dev-key.pem')
306
+ const certPath = resolve(root, env.VITE_APP_HTTPS_CERT || '../../certs/dev-cert.pem')
307
+ if (!existsSync(keyPath) || !existsSync(certPath)) {
308
+ throw new Error('VITE_APP_HTTPS 已开启,但未找到证书文件,请先在仓库根目录运行 scripts/generate-dev-cert.sh;期望路径:' + keyPath + ' 和 ' + certPath)
309
+ }
310
+ return { key: readFileSync(keyPath), cert: readFileSync(certPath) }
311
+ }
312
+
296
313
  function resolveEnv(mode) {
297
314
  const modeEnv = loadEnv(mode, workspaceRoot, '')
298
315
  if (mode === 'development-h5') return { ...loadEnv('development', workspaceRoot, ''), ...modeEnv }
@@ -304,6 +321,8 @@ export default defineConfig(({ mode }) => {
304
321
  const env = resolveEnv(mode)
305
322
  const devEnv = mode === 'development-h5' ? loadEnv('development', workspaceRoot, '') : env
306
323
  const base = env.VITE_APP_BASE_PATH || (mode === 'production-h5' ? '/app/' : '/')
324
+ const httpsOptions = resolveHttpsOptions(env, workspaceRoot)
325
+ const apiProxyOptions = devEnv.VITE_APP_API_URL?.startsWith('https://') ? { secure: false } : {}
307
326
  return {
308
327
  base,
309
328
  envDir: workspaceRoot,
@@ -327,9 +346,10 @@ export default defineConfig(({ mode }) => {
327
346
  server: {
328
347
  host: '0.0.0.0',
329
348
  port: Number(env.VITE_APP_PORT || 5004),
349
+ https: httpsOptions,
330
350
  proxy: {
331
- [env.VITE_APP_BASE_API || '/api']: { changeOrigin: true, target: devEnv.VITE_APP_API_URL },
332
- '/events': { changeOrigin: true, target: devEnv.VITE_APP_API_URL },
351
+ [env.VITE_APP_BASE_API || '/api']: { changeOrigin: true, target: devEnv.VITE_APP_API_URL, ...apiProxyOptions },
352
+ '/events': { changeOrigin: true, target: devEnv.VITE_APP_API_URL, ...apiProxyOptions },
333
353
  },
334
354
  },
335
355
  build: {
@@ -430,7 +450,7 @@ function writeEnvironmentFiles(target) {
430
450
  write(
431
451
  target,
432
452
  '.env.development-h5',
433
- 'VITE_APP_PORT=5004\nVITE_APP_BASE_PATH=/\nVITE_APP_BASE_API=/api\nVITE_APP_API_URL=http://localhost:7001\nVITE_APP_STATIC_API=\nVITE_APP_STATIC_URL=http://localhost:7001\n',
453
+ 'VITE_APP_PORT=5004\nVITE_APP_HTTPS=false\n# VITE_APP_HTTPS_KEY=../../certs/dev-key.pem\n# VITE_APP_HTTPS_CERT=../../certs/dev-cert.pem\n# 后端使用 HTTPS 时,在 .env.development-h5.local 覆盖 VITE_APP_API_URL=https://localhost:7001\nVITE_APP_BASE_PATH=/\nVITE_APP_BASE_API=/api\nVITE_APP_API_URL=http://localhost:7001\nVITE_APP_STATIC_API=\nVITE_APP_STATIC_URL=http://localhost:7001\n',
434
454
  )
435
455
  write(
436
456
  target,