-
Notifications
You must be signed in to change notification settings - Fork 113
/
jsapiimpls.ts
96 lines (89 loc) · 2.84 KB
/
jsapiimpls.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { PackagePath, AppVersionDescriptor, log } from 'ern-core'
import { getActiveCauldron } from 'ern-cauldron-api'
import { syncCauldronContainer } from 'ern-orchestrator'
import {
epilog,
logErrorAndExitIfNotSatisfied,
askUserToChooseANapDescriptorFromCauldron,
tryCatchWrap,
emptyContainerIfSingleMiniAppOrJsApiImpl,
} from '../../../lib'
import { Argv } from 'yargs'
export const command = 'jsapiimpls <jsapiimpls..>'
export const desc =
'Remove one or more JS API implementation(s) from a given native application version in the Cauldron'
export const builder = (argv: Argv) => {
return argv
.option('containerVersion', {
alias: 'v',
describe:
'Version to use for generated container. If none provided, version will be patched bumped by default.',
type: 'string',
})
.option('descriptor', {
alias: 'd',
describe: 'A complete native application descriptor',
type: 'string',
})
.coerce('descriptor', d => AppVersionDescriptor.fromString(d))
.coerce('jsapiimpls', d => d.map(PackagePath.fromString))
.epilog(epilog(exports))
}
export const commandHandler = async ({
containerVersion,
descriptor,
jsapiimpls,
}: {
containerVersion?: string
descriptor?: AppVersionDescriptor
jsapiimpls: PackagePath[]
}) => {
descriptor =
descriptor ||
(await askUserToChooseANapDescriptorFromCauldron({
onlyNonReleasedVersions: true,
}))
await logErrorAndExitIfNotSatisfied({
isNewerContainerVersion: containerVersion
? {
containerVersion,
descriptor,
extraErrorMessage:
'To avoid conflicts with previous versions, you can only use container version newer than the current one',
}
: undefined,
isValidContainerVersion: containerVersion
? { containerVersion }
: undefined,
napDescriptorExistInCauldron: {
descriptor,
extraErrorMessage:
'This command cannot work on a non existing native application version',
},
})
const cauldronCommitMessage = [
`${
jsapiimpls.length === 1
? `Remove ${jsapiimpls[0]} JS API implementation from ${descriptor}`
: `Remove multiple JS API implementations from ${descriptor}`
}`,
]
if (!(await emptyContainerIfSingleMiniAppOrJsApiImpl(descriptor))) {
const cauldron = await getActiveCauldron()
await syncCauldronContainer(
async () => {
for (const jsApiImpl of jsapiimpls) {
await cauldron.removeJsApiImplFromContainer(descriptor!, jsApiImpl)
cauldronCommitMessage.push(
`- Remove ${jsApiImpl} JS API implementation`
)
}
},
descriptor,
cauldronCommitMessage,
{ containerVersion }
)
}
log.info(`JS API implementation(s) successfully removed from ${descriptor}`)
}
export const handler = tryCatchWrap(commandHandler)