@lark-apaas/miaoda-cli 0.1.37 → 0.1.39
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/dist/config/sync-configs/index.js +3 -1
- package/dist/config/sync-configs/vite-react.js +20 -0
- package/package.json +1 -1
- package/upgrade/templates/nestjs-react-fullstack/templates/nest-cli.json +1 -10
- package/upgrade/templates/nestjs-react-fullstack/templates/scripts/build.sh +5 -0
- package/upgrade/templates/vite-react/templates/scripts/build.sh +61 -0
|
@@ -23,13 +23,15 @@ const node_fs_1 = __importDefault(require("node:fs"));
|
|
|
23
23
|
const node_path_1 = __importDefault(require("node:path"));
|
|
24
24
|
const nestjs_react_fullstack_1 = __importDefault(require("./nestjs-react-fullstack"));
|
|
25
25
|
const design_stack_1 = __importDefault(require("./design-stack"));
|
|
26
|
+
const vite_react_1 = __importDefault(require("./vite-react"));
|
|
26
27
|
/**
|
|
27
|
-
* 已纳入新 sync 机制的 stack 注册表。未在表里的 stack
|
|
28
|
+
* 已纳入新 sync 机制的 stack 注册表。未在表里的 stack(如 html / design-html)走旧的
|
|
28
29
|
* `upgrade/templates/<stack>/{files,patches}` 机制,由 sync handler 兜底。
|
|
29
30
|
*/
|
|
30
31
|
const STACK_REGISTRY = {
|
|
31
32
|
'nestjs-react-fullstack': nestjs_react_fullstack_1.default,
|
|
32
33
|
'design-stack': design_stack_1.default,
|
|
34
|
+
'vite-react': vite_react_1.default,
|
|
33
35
|
};
|
|
34
36
|
/** 返回该 stack 的 SyncConfig;表里没有时返回 null。 */
|
|
35
37
|
function getSyncConfig(stack) {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* vite-react sync 规则(镜像 fullstack-cli 的 viteReactProfile):只同步 build.sh 一支,
|
|
4
|
+
* 回溯 public/* → dist/output/ 修复。
|
|
5
|
+
* ⚠️ build.sh 源须与 miaoda-coding 模板、fullstack-cli `templates/vite-react/build.sh` 逐字一致。
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.SYNC_CONFIG = void 0;
|
|
9
|
+
exports.SYNC_CONFIG = {
|
|
10
|
+
sync: [
|
|
11
|
+
// 覆盖 scripts/build.sh:回溯 public/* → dist/output/(同源根 /app/<appId>/*)修复
|
|
12
|
+
{
|
|
13
|
+
type: 'file',
|
|
14
|
+
from: 'scripts/build.sh',
|
|
15
|
+
to: 'scripts/build.sh',
|
|
16
|
+
overwrite: true,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
exports.default = exports.SYNC_CONFIG;
|
package/package.json
CHANGED
|
@@ -146,6 +146,11 @@ STEP_START=$(node -e "console.log(Date.now())")
|
|
|
146
146
|
# 使用 mv 而非 cp:HTML 不能上传到公网 CDN,移走后 dist/client 中不再包含 HTML
|
|
147
147
|
if [ -d "$DIST_DIR/client" ]; then
|
|
148
148
|
mkdir -p "$DIST_DIR/dist/client"
|
|
149
|
+
# public 先进(顶层 client 打包被排除;server setBaseViewsDir + 中间件同源 serve)
|
|
150
|
+
if [ -d "$ROOT_DIR/client/public" ]; then
|
|
151
|
+
cp -R "$ROOT_DIR/client/public/." "$DIST_DIR/dist/client/"
|
|
152
|
+
fi
|
|
153
|
+
# 构建产物 HTML 随后 move,覆盖 public 里的同名文件(保证入口页是构建版,不被 public 静默覆盖)
|
|
149
154
|
find "$DIST_DIR/client" -maxdepth 1 -name "*.html" -exec mv {} "$DIST_DIR/dist/client/" \;
|
|
150
155
|
fi
|
|
151
156
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
5
|
+
OUTPUT="$ROOT/dist/output"
|
|
6
|
+
OUTPUT_RESOURCE="$ROOT/dist/output_resource"
|
|
7
|
+
OUTPUT_STATIC="$ROOT/dist/output_static"
|
|
8
|
+
|
|
9
|
+
# 映射平台环境变量到 preset 期望的变量名
|
|
10
|
+
# MIAODA_APP_ID → /app/<appId> 作为客户端 base path
|
|
11
|
+
# MIAODA_RESOURCE_CDN_PREFIX → assets (JS/CSS) 的 CDN 前缀
|
|
12
|
+
# CLI 注入约定见 miaoda-cli src/services/deploy/modern/atoms/build.ts
|
|
13
|
+
export CLIENT_BASE_PATH="${MIAODA_APP_ID:+/app/$MIAODA_APP_ID}"
|
|
14
|
+
export ASSETS_CDN_PATH="${MIAODA_RESOURCE_CDN_PREFIX:-/}"
|
|
15
|
+
export STATIC_ASSETS_BASE_URL="${MIAODA_STATIC_CDN_PREFIX}"
|
|
16
|
+
export NODE_ENV="${NODE_ENV:-production}"
|
|
17
|
+
|
|
18
|
+
# 清理
|
|
19
|
+
rm -rf "$ROOT/dist"
|
|
20
|
+
|
|
21
|
+
# 1. Vite 构建 → dist/client/(相对于项目根目录输出)
|
|
22
|
+
npx vite build --outDir "$ROOT/dist/client" --emptyOutDir
|
|
23
|
+
|
|
24
|
+
# 2. public/ 静态资源 + HTML → dist/output/(模型 B:public = 应用根目录,同源 /app/<appId>/*)
|
|
25
|
+
mkdir -p "$OUTPUT"
|
|
26
|
+
# 2a. public/*:vite copyPublicDir 已把 public/* 平铺进 dist/client,但下面白名单只取
|
|
27
|
+
# *.html/routes.json,其余(favicon / 图片 / 运行时 fetch 的数据文件)会随 dist/client 被删。
|
|
28
|
+
# 从源 public/ 补拷到 output/(同源根),让 fetch('/x') / resolveAppUrl('/x') 线上可用。
|
|
29
|
+
# 先拷 public、再拷 HTML,保证构建产出的 index.html/routes.json 覆盖 public 里的同名文件(若有)。
|
|
30
|
+
if [ -d "$ROOT/public" ]; then
|
|
31
|
+
cp -R "$ROOT/public/." "$OUTPUT/"
|
|
32
|
+
fi
|
|
33
|
+
# 2b. HTML + routes.json(构建产物)
|
|
34
|
+
find "$ROOT/dist/client" -maxdepth 1 \( -name '*.html' -o -name 'routes.json' \) -exec cp {} "$OUTPUT/" \;
|
|
35
|
+
|
|
36
|
+
# 3. assets/ → dist/output_resource/(JS/CSS/字体,上传到 CDN)
|
|
37
|
+
if [ -d "$ROOT/dist/client/assets" ]; then
|
|
38
|
+
mkdir -p "$OUTPUT_RESOURCE"
|
|
39
|
+
cp -r "$ROOT/dist/client/assets" "$OUTPUT_RESOURCE/"
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
# 4. 私有静态资源 → dist/output_static/(排除代码文件)
|
|
43
|
+
if [ -d "$ROOT/shared/static" ]; then
|
|
44
|
+
mkdir -p "$OUTPUT_STATIC"
|
|
45
|
+
rsync -a --exclude='*.ts' --exclude='*.tsx' --exclude='*.js' --exclude='*.jsx' "$ROOT/shared/static/" "$OUTPUT_STATIC/"
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# 5. capability 配置 → dist/output_capabilities/
|
|
49
|
+
if [ -d "$ROOT/shared/capabilities" ]; then
|
|
50
|
+
mkdir -p "$ROOT/dist/output_capabilities"
|
|
51
|
+
cp -r "$ROOT/shared/capabilities/." "$ROOT/dist/output_capabilities/"
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
# 清理中间产物
|
|
55
|
+
rm -rf "$ROOT/dist/client"
|
|
56
|
+
|
|
57
|
+
echo "Build complete"
|
|
58
|
+
echo " HTML → dist/output/"
|
|
59
|
+
[ -d "$OUTPUT_RESOURCE" ] && echo " Resource → dist/output_resource/" || true
|
|
60
|
+
[ -d "$OUTPUT_STATIC" ] && echo " Static → dist/output_static/" || true
|
|
61
|
+
[ -d "$ROOT/dist/output_capabilities" ] && echo " Capabilities → dist/output_capabilities/" || true
|