-
Notifications
You must be signed in to change notification settings - Fork 115
/
createApp.ts
57 lines (50 loc) · 1.95 KB
/
createApp.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
import { flags } from '@oclif/command'
import chalk from 'chalk'
import { IMemberRemarked, MemberRemarked } from '@joystream/metadata-protobuf'
import ExitCodes from '../../ExitCodes'
import { metadataToBytes } from '../../helpers/serialization'
import { getInputJson } from '../../helpers/InputOutput'
import AppCommandBase from '../../base/AppCommandBase'
import { AppInputDetails } from 'src/Types'
import MembershipsCommandBase from '../../base/MembershipsCommandBase'
export default class CreateApp extends AppCommandBase {
static description = 'Creates app for current member'
static flags = {
input: flags.string({
required: false,
char: 'i',
description: `Path to JSON file containing app details`,
}),
skip: flags.boolean({
char: 's',
description: "If true command won't prompt missing fields",
dependsOn: ['input'],
}),
...MembershipsCommandBase.flags,
}
async run(): Promise<void> {
const { input, skip } = this.parse(CreateApp).flags
await this.getRequiredMemberContext(true)
const defaults: Partial<AppInputDetails> = input ? await getInputJson<Partial<AppInputDetails>>(input) : {}
const name = defaults?.name || (await this.promptAppName())
const appMetadata = skip ? defaults : await this.promptAppMetadata(defaults)
const createAppRemarked: IMemberRemarked = {
createApp: {
name,
appMetadata,
},
}
this.jsonPrettyPrint(JSON.stringify({ name, ...appMetadata }))
await this.requireConfirmation('Do you confirm the provided input?', true)
const message = metadataToBytes(MemberRemarked, createAppRemarked)
await this.sendRemark(message)
this.log(chalk.green(`Member remark transaction successful!`))
}
async promptAppName(): Promise<string> {
const name = await this.simplePrompt<string>({ message: 'App name?' })
if (!name) {
this.error('Name is required', { exit: ExitCodes.InvalidInput })
}
return name
}
}