Skip to content

Commit 03f8b84

Browse files
move registrycli type to its file
1 parent 3fc4906 commit 03f8b84

File tree

8 files changed

+17
-29
lines changed

8 files changed

+17
-29
lines changed

src/cli/domain/registry.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import put from '../../utils/put';
77
import settings from '../../resources/settings';
88
import * as urlBuilder from '../../registry/domain/url-builder';
99
import * as urlParser from '../domain/url-parser';
10-
import { RegistryCli } from '../../types';
10+
import { Component } from '../../types';
1111

1212
const getOcVersion = (): string => {
1313
const ocPackagePath = path.join(__dirname, '../../../package.json');
@@ -20,15 +20,15 @@ interface RegistryOptions {
2020
registry?: string;
2121
}
2222

23-
export default function registry(opts: RegistryOptions = {}): RegistryCli {
23+
export default function registry(opts: RegistryOptions = {}) {
2424
let requestsHeaders = {
2525
'user-agent': `oc-cli-${getOcVersion()}/${process.version}-${
2626
process.platform
2727
}-${process.arch}`
2828
};
2929

3030
return {
31-
async add(registry: string) {
31+
async add(registry: string): Promise<void> {
3232
if (registry.slice(registry.length - 1) !== '/') {
3333
registry += '/';
3434
}
@@ -57,7 +57,7 @@ export default function registry(opts: RegistryOptions = {}): RegistryCli {
5757
throw 'oc registry not available';
5858
}
5959
},
60-
async get() {
60+
async get(): Promise<string[]> {
6161
if (opts.registry) {
6262
return [opts.registry];
6363
}
@@ -73,12 +73,12 @@ export default function registry(opts: RegistryOptions = {}): RegistryCli {
7373
throw 'No oc registries';
7474
}
7575
},
76-
getApiComponentByHref(href: string) {
76+
getApiComponentByHref(href: string): Promise<Component> {
7777
return got(href + settings.registry.componentInfoPath, {
7878
headers: requestsHeaders
7979
}).json();
8080
},
81-
async getComponentPreviewUrlByUrl(componentHref: string) {
81+
async getComponentPreviewUrlByUrl(componentHref: string): Promise<string> {
8282
const res: { requestVersion: string; href: string } = await got(
8383
componentHref,
8484
{ headers: requestsHeaders }
@@ -93,7 +93,7 @@ export default function registry(opts: RegistryOptions = {}): RegistryCli {
9393
password?: string;
9494
route: string;
9595
path: string;
96-
}) {
96+
}): Promise<void> {
9797
if (!!options.username && !!options.password) {
9898
requestsHeaders = Object.assign(requestsHeaders, {
9999
Authorization:
@@ -129,7 +129,7 @@ export default function registry(opts: RegistryOptions = {}): RegistryCli {
129129
throw errMsg;
130130
}
131131
},
132-
async remove(registry: string) {
132+
async remove(registry: string): Promise<void> {
133133
if (registry.slice(registry.length - 1) !== '/') {
134134
registry += '/';
135135
}
@@ -143,3 +143,5 @@ export default function registry(opts: RegistryOptions = {}): RegistryCli {
143143
}
144144
};
145145
}
146+
147+
export type RegistryCli = ReturnType<typeof registry>;

src/cli/facade/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import open from 'open';
22
import { fromPromise } from 'universalify';
33

44
import strings from '../../resources/index';
5-
import { RegistryCli } from '../../types';
5+
import { RegistryCli } from '../domain/registry';
66
import { Logger } from '../logger';
77

88
const preview = ({

src/cli/facade/publish.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import readCb from 'read';
55
import { promisify } from 'util';
66
import { Logger } from '../logger';
77
import type { Local } from '../domain/local';
8-
import { Component, RegistryCli } from '../../types';
8+
import { Component } from '../../types';
99
import { fromPromise } from 'universalify';
1010

1111
import handleDependencies from '../domain/handle-dependencies';
1212
import strings from '../../resources/index';
13+
import { RegistryCli } from '../domain/registry';
1314

1415
const read = promisify(readCb);
1516

src/cli/facade/registry-add.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fromPromise } from 'universalify';
22
import strings from '../../resources/index';
3-
import { RegistryCli } from '../../types';
3+
import { RegistryCli } from '../domain/registry';
44
import { Logger } from '../logger';
55

66
const registryAdd = ({

src/cli/facade/registry-ls.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fromPromise } from 'universalify';
22

33
import strings from '../../resources/index';
4-
import { RegistryCli } from '../../types';
4+
import { RegistryCli } from '../domain/registry';
55
import { Logger } from '../logger';
66

77
const registryLs = ({

src/cli/facade/registry-remove.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fromPromise } from 'universalify';
22
import strings from '../../resources/index';
3-
import { RegistryCli } from '../../types';
3+
import { RegistryCli } from '../domain/registry';
44
import { Logger } from '../logger';
55

66
const registryRemove = ({

src/cli/programmatic-api.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import local, { Local } from './domain/local';
22
import { Logger } from './logger';
3-
import Registry from './domain/registry';
3+
import Registry, { RegistryCli } from './domain/registry';
44

55
import dev from './facade/dev';
66
import init from './facade/init';
@@ -11,7 +11,6 @@ import preview from './facade/preview';
1111
import registryAdd from './facade/registry-add';
1212
import registryLs from './facade/registry-ls';
1313
import registryRemove from './facade/registry-remove';
14-
import { RegistryCli } from '../types';
1514

1615
type Options<T extends (...args: any) => any> = Parameters<ReturnType<T>>[0];
1716
type Cb<T extends (...args: any) => any> = Parameters<ReturnType<T>>[1];

src/types.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,6 @@ export interface Plugin {
235235
};
236236
}
237237

238-
export interface RegistryCli {
239-
add(registry: string): Promise<void>;
240-
get(): Promise<string[]>;
241-
getApiComponentByHref(href: string): Promise<Component>;
242-
getComponentPreviewUrlByUrl(componentHref: string): Promise<string>;
243-
putComponent(options: {
244-
username?: string;
245-
password?: string;
246-
route: string;
247-
path: string;
248-
}): Promise<void>;
249-
remove(registry: string): Promise<void>;
250-
}
251-
252238
declare global {
253239
// eslint-disable-next-line @typescript-eslint/no-namespace
254240
namespace Express {

0 commit comments

Comments
 (0)