Skip to content

Commit

Permalink
some change
Browse files Browse the repository at this point in the history
  • Loading branch information
yoozo committed Aug 8, 2024
1 parent 82d75e7 commit 33127e3
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions packages/cli/src/commands/project/create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,11 @@
// SPDX-License-Identifier: GPL-3.0

import assert from 'assert';
import {search} from '@inquirer/prompts';
import {Command, Flags} from '@oclif/core';
import fuzzy from 'fuzzy';
import {BASE_PROJECT_URL, ROOT_API_URL_PROD} from '../../constants';
import {createProject} from '../../controller/project-controller';
import {checkToken, valueOrPrompt} from '../../utils';

export type CreateProjectType = 'subquery' | 'subgraph';
// Helper function for fuzzy search on prompt input
function filterInput<T>(arr: T[]) {
return (input: string | undefined, opt: {signal: any}): Promise<ReadonlyArray<{value: T}>> => {
input ??= '';
return Promise.resolve(fuzzy.filter(input, arr).map((r) => ({value: r.original})));
};
}

export default class Create_project extends Command {
static description = 'Create Project on Hosted Service';

Expand All @@ -31,32 +20,32 @@ export default class Create_project extends Command {
description: Flags.string({description: 'Enter description', default: '', required: false}),
apiVersion: Flags.string({description: 'Enter api version', default: '2', required: false}),
dedicatedDB: Flags.string({description: 'Enter dedicated DataBase', required: false}),
projectType: Flags.string({description: 'Enter project type [subquery|subgraph]', required: false}),
projectType: Flags.string({
description: 'Enter project type [subquery|subgraph]',
default: 'subquery',
required: false,
}),
};

async run(): Promise<void> {
const {flags} = await this.parse(Create_project);

let {gitRepo, org, projectName, projectType} = flags;
let {gitRepo, org, projectName} = flags;
assert(
['subquery', 'subgraph'].includes(flags.projectType),
'Invalid project type, Only support subQuery and subgraph'
);
const authToken = await checkToken();

org = await valueOrPrompt(org, 'Enter organisation', 'Organisation is required');
projectName = await valueOrPrompt(projectName, 'Enter project name', 'Project name is required');
gitRepo = await valueOrPrompt(gitRepo, 'Enter git repository', 'Git repository is required');

if (!projectType) {
projectType = await search<CreateProjectType>({
message: 'Select a project type',
source: filterInput(['subquery', 'subgraph']),
});
}
assert(projectType === 'subquery' || projectType === 'subgraph', 'Invalid project type');

const result = await createProject(
org,
flags.subtitle,
flags.logoURL,
projectType === 'subquery' ? 1 : 3,
flags.projectType === 'subquery' ? 1 : 3,
projectName,
authToken,
gitRepo,
Expand Down

0 comments on commit 33127e3

Please sign in to comment.