@dazhicheng/common 1.0.39 → 1.0.41

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/.gitlab-ci.yml +62 -18
  2. package/package.json +1 -1
package/.gitlab-ci.yml CHANGED
@@ -5,6 +5,10 @@ stages:
5
5
 
6
6
  variables:
7
7
  DOCKER_BUILDKIT: 1
8
+ # 加速 cache / artifact 压缩
9
+ FF_USE_FASTZIP: "true"
10
+ # 装 pnpm 走国内镜像,避免 npm 官方源拖慢(上次约 49s)
11
+ npm_config_registry: https://registry.npmmirror.com
8
12
 
9
13
  # 构建锚点 ----------------------------------------------------------------
10
14
  .build_template: &build_template
@@ -12,12 +16,22 @@ variables:
12
16
  image: node:24
13
17
  tags:
14
18
  - build
15
- script:
16
- - npm install -g pnpm@latest
19
+ cache:
20
+ key:
21
+ files:
22
+ - pnpm-lock.yaml
23
+ paths:
24
+ - .pnpm-store
25
+ policy: pull-push
26
+ before_script:
27
+ # corepack 启用最新 pnpm,比 npm install -g 快很多
28
+ - corepack enable
29
+ - corepack prepare pnpm@latest --activate
30
+ - pnpm config set store-dir .pnpm-store
17
31
  - pnpm config set registry https://registry.npmmirror.com
18
32
  - pnpm config set @dazhicheng:registry https://registry.npmjs.org
33
+ script:
19
34
  - pnpm install --no-frozen-lockfile
20
- - pnpm up:dzc
21
35
  - pnpm "build:${NODE_ENV}"
22
36
  artifacts:
23
37
  paths:
@@ -27,23 +41,45 @@ variables:
27
41
  - Dockerfile
28
42
  expire_in: 1 day
29
43
 
44
+ # develop:一次 install + 一次类型检查,再分别 vite 出两套产物
45
+ .build_develop_template: &build_develop_template
46
+ <<: *build_template
47
+ script:
48
+ - pnpm install --no-frozen-lockfile
49
+ - pnpm exec vue-tsc --noEmit
50
+ - pnpm exec vite build --mode dev
51
+ - mv dist dist-dev
52
+ - pnpm exec vite build --mode test
53
+ - mv dist dist-test
54
+ artifacts:
55
+ paths:
56
+ - dist-dev/
57
+ - dist-test/
58
+ - nginx_*.conf
59
+ - docker-entrypoint.sh
60
+ - Dockerfile
61
+ expire_in: 1 day
62
+
30
63
  # 部署锚点(通用脚本直接写在这里,不需要项目覆盖) -------------------------
31
64
  # 使用 named volume 持久化静态资源:发版时合并新构建并保留旧 hashed 文件,
32
65
  # 使已打开的旧页面仍能懒加载到旧入口资源。
66
+ # 若存在 dist-${NODE_ENV}(develop 双构建产物),先还原为 dist/ 再 docker build。
33
67
  .deploy_template: &deploy_template
34
68
  stage: deploy
35
69
  image: docker:26.1.4
36
70
  script:
71
+ - |
72
+ if [ -d "dist-${NODE_ENV}" ]; then
73
+ rm -rf dist
74
+ mv "dist-${NODE_ENV}" dist
75
+ fi
37
76
  - docker volume create ${IMAGE_NAME}-assets || true
38
77
  - docker build --build-arg NODE_ENV=$NODE_ENV -t $IMAGE_NAME:latest .
39
78
  - docker stop $IMAGE_NAME || true
40
79
  - docker rm $IMAGE_NAME || true
41
80
  - >
42
- docker run -d --name $IMAGE_NAME --restart always
43
- -p $HOST_PORT:$CONTAINER_PORT
44
- -v ${IMAGE_NAME}-assets:/usr/share/nginx/html
45
- -e ASSET_RETENTION_DAYS=14
46
- $IMAGE_NAME:latest
81
+ docker run -d --name $IMAGE_NAME --restart always -p $HOST_PORT:$CONTAINER_PORT -v ${IMAGE_NAME}-assets:/usr/share/nginx/html -e ASSET_RETENTION_DAYS=14 $IMAGE_NAME:latest
82
+
47
83
  - docker image prune -f || true
48
84
 
49
85
  # MR 验证 -----------------------------------------------------------------
@@ -66,23 +102,23 @@ MR 构建验证:
66
102
  - if: $CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "test" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "release" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "sit")
67
103
 
68
104
  # 项目级 deploy jobs 注入点 ------------------------------------------------
69
- 构建_dev:
70
- <<: *build_template
71
- resource_group: build-dev
72
- variables:
73
- NODE_ENV: dev
105
+ # develop:新 job 一次装依赖,编出两套产物
106
+ 构建_develop:
107
+ <<: *build_develop_template
108
+ resource_group: build-develop
74
109
  only: [develop]
75
110
 
111
+ # test 分支:单环境构建(产物为 dist/)
76
112
  构建_test:
77
113
  <<: *build_template
78
114
  resource_group: build-test
79
115
  variables:
80
116
  NODE_ENV: test
81
- only: [test, develop]
117
+ only: [test]
82
118
 
83
119
  开发环境发版:
84
120
  <<: *deploy_template
85
- needs: [构建_dev]
121
+ needs: [构建_develop]
86
122
  tags: [develop]
87
123
  resource_group: deploy-develop
88
124
  variables:
@@ -92,7 +128,7 @@ MR 构建验证:
92
128
 
93
129
  # 开发环境发版_107:
94
130
  # <<: *deploy_template
95
- # needs: [构建_dev]
131
+ # needs: [构建_develop]
96
132
  # tags: [develop_107]
97
133
  # resource_group: deploy-develop_107
98
134
  # variables:
@@ -102,7 +138,11 @@ MR 构建验证:
102
138
 
103
139
  测试环境发版:
104
140
  <<: *deploy_template
105
- needs: [构建_test]
141
+ needs:
142
+ - job: 构建_develop
143
+ optional: true
144
+ - job: 构建_test
145
+ optional: true
106
146
  tags: [test]
107
147
  resource_group: deploy-test
108
148
  variables:
@@ -112,7 +152,11 @@ MR 构建验证:
112
152
 
113
153
  # 测试环境发版_107:
114
154
  # <<: *deploy_template
115
- # needs: [构建_test]
155
+ # needs:
156
+ # - job: 构建_develop
157
+ # optional: true
158
+ # - job: 构建_test
159
+ # optional: true
116
160
  # tags: [test_107]
117
161
  # resource_group: deploy-test_107
118
162
  # variables:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dazhicheng/common",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "共享配置文件",
5
5
  "type": "module",
6
6
  "types": "./src/types/index.d.ts",