@ranger1/dx 0.1.56 → 0.1.57
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/lib/vercel-deploy.js +25 -16
- package/package.json +1 -1
package/lib/vercel-deploy.js
CHANGED
|
@@ -11,10 +11,12 @@ const TARGET_CONFIGS = {
|
|
|
11
11
|
front: {
|
|
12
12
|
configFile: 'vercel.front.json',
|
|
13
13
|
projectIdEnvVar: 'VERCEL_PROJECT_ID_FRONT',
|
|
14
|
+
deployCwd: 'apps/front',
|
|
14
15
|
},
|
|
15
16
|
admin: {
|
|
16
17
|
configFile: 'vercel.admin.json',
|
|
17
18
|
projectIdEnvVar: 'VERCEL_PROJECT_ID_ADMIN',
|
|
19
|
+
deployCwd: 'apps/admin-front',
|
|
18
20
|
},
|
|
19
21
|
'telegram-bot': {
|
|
20
22
|
configFile: 'vercel.telegram-bot.json',
|
|
@@ -85,13 +87,9 @@ function listMissingConfigs(targetConfigs, projectRoot) {
|
|
|
85
87
|
return missing
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
function appendTargetArgs(baseArgs, {
|
|
90
|
+
function appendTargetArgs(baseArgs, { orgId }) {
|
|
89
91
|
const args = [...baseArgs]
|
|
90
92
|
|
|
91
|
-
if (cwd) {
|
|
92
|
-
args.push('--cwd', cwd)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
93
|
if (orgId) {
|
|
96
94
|
args.push('--scope', orgId)
|
|
97
95
|
}
|
|
@@ -99,14 +97,19 @@ function appendTargetArgs(baseArgs, { cwd, orgId }) {
|
|
|
99
97
|
return args
|
|
100
98
|
}
|
|
101
99
|
|
|
100
|
+
export function resolveTargetRunCwd(projectRoot, targetConfig) {
|
|
101
|
+
if (!targetConfig?.deployCwd) return projectRoot
|
|
102
|
+
return join(projectRoot, targetConfig.deployCwd)
|
|
103
|
+
}
|
|
104
|
+
|
|
102
105
|
function maskIdentifier(value) {
|
|
103
106
|
const raw = String(value || '').trim()
|
|
104
107
|
if (raw.length <= 10) return raw || '-'
|
|
105
108
|
return `${raw.slice(0, 6)}...${raw.slice(-4)}`
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
function readLinkedProjectContext(
|
|
109
|
-
const path = join(
|
|
111
|
+
function readLinkedProjectContext(contextRoot) {
|
|
112
|
+
const path = join(contextRoot, VERCEL_PROJECT_LINK_PATH)
|
|
110
113
|
if (!existsSync(path)) {
|
|
111
114
|
return { exists: false, path, orgId: null, projectId: null, parseError: null }
|
|
112
115
|
}
|
|
@@ -132,8 +135,8 @@ function readLinkedProjectContext(projectRoot) {
|
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
|
|
135
|
-
function clearLinkedProjectContext(
|
|
136
|
-
const path = join(
|
|
138
|
+
function clearLinkedProjectContext(contextRoot) {
|
|
139
|
+
const path = join(contextRoot, VERCEL_PROJECT_LINK_PATH)
|
|
137
140
|
rmSync(path, { force: true })
|
|
138
141
|
}
|
|
139
142
|
|
|
@@ -191,7 +194,7 @@ export async function deployPrebuiltWithFallback(options) {
|
|
|
191
194
|
run = runVercel,
|
|
192
195
|
cleanupArchiveParts = () => {
|
|
193
196
|
try {
|
|
194
|
-
execSync('rm -f .vercel/source.tgz.part*', { stdio: 'ignore' })
|
|
197
|
+
execSync('rm -f .vercel/source.tgz.part*', { stdio: 'ignore', cwd: cwd || process.cwd() })
|
|
195
198
|
} catch {
|
|
196
199
|
// ignore
|
|
197
200
|
}
|
|
@@ -298,7 +301,15 @@ export async function deployToVercel(target, options = {}) {
|
|
|
298
301
|
const projectId = process.env[targetConfig.projectIdEnvVar]
|
|
299
302
|
const configFile = targetConfig.configFile
|
|
300
303
|
const configPath = join(projectRoot, configFile)
|
|
301
|
-
const
|
|
304
|
+
const runCwd = resolveTargetRunCwd(projectRoot, targetConfig)
|
|
305
|
+
|
|
306
|
+
if (!existsSync(runCwd)) {
|
|
307
|
+
logger.error(`部署目录不存在: target=${t} deployCwd=${targetConfig.deployCwd || '.'} resolved=${runCwd}`)
|
|
308
|
+
process.exitCode = 1
|
|
309
|
+
return
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const linkedContext = readLinkedProjectContext(runCwd)
|
|
302
313
|
|
|
303
314
|
const linkedMismatch =
|
|
304
315
|
linkedContext.exists &&
|
|
@@ -363,7 +374,7 @@ export async function deployToVercel(target, options = {}) {
|
|
|
363
374
|
|
|
364
375
|
try {
|
|
365
376
|
if (strictContext && process.env.DX_VERCEL_KEEP_LINK !== '1') {
|
|
366
|
-
clearLinkedProjectContext(
|
|
377
|
+
clearLinkedProjectContext(runCwd)
|
|
367
378
|
}
|
|
368
379
|
|
|
369
380
|
// 第一步:本地构建
|
|
@@ -371,7 +382,6 @@ export async function deployToVercel(target, options = {}) {
|
|
|
371
382
|
const buildArgs = appendTargetArgs(
|
|
372
383
|
['build', '--local-config', configPath, '--yes'],
|
|
373
384
|
{
|
|
374
|
-
cwd: projectRoot,
|
|
375
385
|
orgId,
|
|
376
386
|
},
|
|
377
387
|
)
|
|
@@ -381,7 +391,7 @@ export async function deployToVercel(target, options = {}) {
|
|
|
381
391
|
buildArgs.push('--prod')
|
|
382
392
|
}
|
|
383
393
|
|
|
384
|
-
await run(buildArgs, { env: envVars, cwd:
|
|
394
|
+
await run(buildArgs, { env: envVars, cwd: runCwd })
|
|
385
395
|
logger.success(`${t} 本地构建成功`)
|
|
386
396
|
|
|
387
397
|
// 第二步:上传预构建产物
|
|
@@ -389,7 +399,6 @@ export async function deployToVercel(target, options = {}) {
|
|
|
389
399
|
const baseDeployArgs = appendTargetArgs(
|
|
390
400
|
['deploy', '--prebuilt', '--local-config', configPath, '--yes'],
|
|
391
401
|
{
|
|
392
|
-
cwd: projectRoot,
|
|
393
402
|
orgId,
|
|
394
403
|
},
|
|
395
404
|
)
|
|
@@ -402,7 +411,7 @@ export async function deployToVercel(target, options = {}) {
|
|
|
402
411
|
const deployResult = await deployPrebuiltWithFallback({
|
|
403
412
|
baseArgs: baseDeployArgs,
|
|
404
413
|
env: envVars,
|
|
405
|
-
cwd:
|
|
414
|
+
cwd: runCwd,
|
|
406
415
|
run,
|
|
407
416
|
})
|
|
408
417
|
|