🌳
pt0/deployF/eptClusterSyncF.mts
1import { enterKlusterCtxs, type KlusterCfg } from './k8sF/ctxF/klusterCtxF.mts'
7import { tsAbsPath, type importMetaUrlType } from '../ptDirF.mts'
8import { ptnodeBin } from './constantsF.mts'
22const parseStepsArg = () => {
23 const stepsArg = getProcArgv().find(a => a.startsWith('--steps='))
24 return stepsArg ? stepsArg.slice(8).split(',') : null
27export const eptClusterSync = async ({importMetaUrl, steps, extraActionsH, ...klusterCfg}: {importMetaUrl: importMetaUrlType, steps: Record<string, () => Promise<unknown>>, extraActionsH?: Record<string, (...a: any[]) => any>, cluster_name: string, [k: string]: unknown}) => {
28 importMetaUrlCtx.enterWith({importMetaUrl}) // ctx:clear
29 enterKlusterCtxs(klusterCfg as KlusterCfg, {importMetaUrl})
31 if (extraActionsH) {
32 availActionsCtx.enterWith({...availActionsCtx.getStore(), ...extraActionsH})
33 }
35 if (klusterCfg.cfApiKeySecretName) {
36 availActionsCtx.enterWith({...availActionsCtx.getStore(), overwriteextdnsowner, listcfdnsrecords, cfensuressl, ensurewcdnsrecords})
37 }
39 const action = getAction()
40 const stepNames = Object.keys(steps)
41 const requestedSteps = parseStepsArg() ?? (action === 'delete' || action === 'help' ? null : stepNames)
42 const epPath = absPathToPtPath(tsAbsPath(getImportMetaUrlPath(importMetaUrl)))
44 if (action === 'runtests') {
45 await mkRuntests({
46 allSuites: ['clitests'],
47 localAppCfg: {importMetaUrl},
48 suiteConfigs: [{name: 'clitests', runner: runClusterCliTestsSuite, deps: []}],
49 })()
50 return
51 }
53 if (await tryDispatchAction()) return
55 // help --steps=X shows step-specific help, help alone lists steps
56 if (action === 'help') {
57 if (!requestedSteps) {
58 console.log(`$ ${ptnodeBin} ${epPath} help\n`)
59 console.log(`[action] --steps=step1,step2\n\nAvailable steps: ${stepNames.join(', ')}`)
60 return
61 }
62 const invalidSteps = requestedSteps.filter(s => !steps[s])
63 if (invalidSteps.length) {
64 throPtErr('unknown steps', {invalidSteps, available: stepNames})
65 }
66 for (const name of requestedSteps) {
67 console.log(`\n--- ${name} ---`)
68 await steps[name]()
69 }
70 return
71 }
73 const coreActions = ['apply', 'delete', 'info', 'help', 'runtests']
74 const isCustomAction = !coreActions.includes(action)
76 if (isCustomAction) {
77 const customActionsH = availActionsCtx.getStore() || {}
78 const customAction = customActionsH[action]
79 if (customAction) {
80 if (customAction.cliSchema) exitOnUnknownArgs(customAction)
81 cliValidatedCtx.enterWith({validated: true}) // ctx:clear
82 if (typeof customAction === 'function') await customAction()
83 return
84 }
85 }
87 exitOnUnknownArgs({cliSchema: {steps: {}, ...applyCli}, cliAcceptsPositional: isCustomAction})
89 cliValidatedCtx.enterWith({validated: true}) // ctx:clear
91 if (!requestedSteps) {
92 console.log(`Usage: ${ptnodeBin} ${epPath} ${action} --steps=step1,step2`)
93 console.log(`Available: ${stepNames.join(', ')}`)
94 return
95 }
97 const invalidSteps = requestedSteps.filter(s => !steps[s])
98 if (invalidSteps.length) {
99 throPtErr('unknown steps', {invalidSteps, available: stepNames})
100 }
102 for (const [name, fn] of Object.entries(steps)) {
103 if (requestedSteps.includes(name)) {
104 console.log(`\n--- ${name} ---`)
105 await fn()
106 }
107 }