(options: {
repoRoot: string;
check?: boolean;
yes?: boolean;
targets?: string[];
})
| 37 | } |
| 38 | |
| 39 | async function syncEnvVars(options: { |
| 40 | repoRoot: string; |
| 41 | check?: boolean; |
| 42 | missingSecretsOnly?: boolean; |
| 43 | yes?: boolean; |
| 44 | targets?: string[]; |
| 45 | }): Promise<SyncResult> { |
| 46 | const { repoRoot, check = false, missingSecretsOnly = false, yes = false, targets } = options; |
| 47 | const serviceFilter = resolveServiceFilter(targets); |
| 48 | const refreshSourceBackedSecrets = !check && !missingSecretsOnly; |
| 49 | const plan = await computePlanAsync(repoRoot, serviceFilter, refreshSourceBackedSecrets); |
| 50 | |
| 51 | if (plan.missingEnvLocal) { |
| 52 | displayPlan(plan); |
| 53 | return { ok: false, changed: 0, missing: 0 }; |
| 54 | } |
| 55 | |
| 56 | const hasChanges = planHasChanges(plan); |
| 57 | const totalMissing = |
| 58 | plan.devVarsChanges.reduce((sum, c) => sum + c.missingValues.length, 0) + |
| 59 | plan.secretStoreWarnings.reduce((sum, c) => sum + c.bindings.length, 0); |
| 60 | |
| 61 | displayPlan(plan); |
| 62 | |
| 63 | if (check) { |
| 64 | return { |
| 65 | ok: !hasChanges && plan.secretStoreWarnings.length === 0, |
| 66 | changed: |
| 67 | plan.devVarsChanges.length + |
| 68 | plan.envLocalAutoCreates.length + |
| 69 | plan.secretStoreAutoCreates.length, |
| 70 | missing: totalMissing, |
| 71 | }; |
| 72 | } |
| 73 | |
| 74 | if (hasChanges) { |
| 75 | const shouldApply = yes || (await confirm(`\nApply changes? [y/N] `)); |
| 76 | if (shouldApply) { |
| 77 | applyEnvLocalAutoCreates(plan.envLocalAutoCreates, repoRoot); |
| 78 | const applyReadyPlan = |
| 79 | plan.envLocalAutoCreates.length > 0 |
| 80 | ? await computePlanAsync(repoRoot, serviceFilter, refreshSourceBackedSecrets) |
| 81 | : plan; |
| 82 | await applyPlan(applyReadyPlan, repoRoot); |
| 83 | console.log(`\n${GREEN}✓ Applied${RESET}`); |
| 84 | } else { |
| 85 | console.log('Skipped.'); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return { |
| 90 | ok: true, |
| 91 | changed: |
| 92 | plan.devVarsChanges.length + |
| 93 | plan.envLocalAutoCreates.length + |
| 94 | plan.secretStoreAutoCreates.length, |
| 95 | missing: totalMissing, |
| 96 | }; |
no test coverage detected