This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
/
create-contract-position-fetcher.ts
41 lines (33 loc) · 1.81 KB
/
create-contract-position-fetcher.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
/* eslint no-console: 0 */
import { Command } from '@oclif/core';
import { AppGroup, GroupType } from '../../src/app/app.interface';
import { addGroupToAppDefinition } from '../generators/generate-app-definition';
import { addContractPositionFetcherToAppModule } from '../generators/generate-app-module';
import { generateContractPositionFetcher } from '../generators/generate-contract-position-fetcher';
import { loadAppDefinition } from '../generators/utils';
import { promptAppGroupId, promptAppNetwork, promptNewGroupId, promptNewGroupLabel } from '../prompts';
export default class CreateContractPositionFetcher extends Command {
static description = 'Creates a contract position fetcher in a given app';
static examples = [`$ ./studio create-contract-position-fetcher appId`];
static args = [{ name: 'appId', description: 'The application id ', required: true }];
static flags = {};
async run(): Promise<void> {
const { args } = await this.parse(CreateContractPositionFetcher);
const appId = args.appId;
const definition = await loadAppDefinition(appId);
const groupIds = Object.values(definition.groups ?? {}).map(v => v.id);
const networks = Object.keys(definition.supportedNetworks ?? {});
let groupId = await promptAppGroupId(groupIds);
let group: AppGroup | null = null;
if (!groupId) {
const newGroupId = await promptNewGroupId(groupIds);
const newGroupLabel = await promptNewGroupLabel();
group = { id: newGroupId, label: newGroupLabel, type: GroupType.POSITION };
groupId = newGroupId;
}
const network = await promptAppNetwork(networks);
await generateContractPositionFetcher(appId, groupId, network);
await addContractPositionFetcherToAppModule({ appId, groupId, network });
if (group) await addGroupToAppDefinition({ appId, group });
}
}