Skip to content

Commit e312f74

Browse files
Merge pull request #1299 from opencomponents/refactor-types
Refactor types
2 parents 644b31a + 03f8b84 commit e312f74

27 files changed

+100
-142
lines changed

src/cli/domain/local.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import mock from './mock';
1010
import packageComponents from './package-components';
1111
import strings from '../../resources';
1212
import * as validator from '../../registry/domain/validators';
13-
import { Local } from '../../types';
13+
import { Logger } from '../logger';
1414

15-
export default function local(): Local {
15+
export default function local() {
1616
return {
1717
clean,
18-
cleanup(compressedPackagePath: string) {
18+
cleanup(compressedPackagePath: string): Promise<void> {
1919
return fs.unlink(compressedPackagePath);
2020
},
21-
compress(input, output) {
21+
compress(input: string, output: string): Promise<void> {
2222
return promisify(targz.compress)({
2323
src: input,
2424
dest: output,
@@ -32,7 +32,12 @@ export default function local(): Local {
3232
});
3333
},
3434
getComponentsByDir: getComponentsByDir(),
35-
async init(options) {
35+
async init(options: {
36+
componentName: string;
37+
logger: Logger;
38+
componentPath: string;
39+
templateType: string;
40+
}): Promise<void> {
3641
const { componentName, logger } = options;
3742
let { templateType } = options;
3843
if (!validator.validateComponentName(componentName)) {
@@ -68,3 +73,5 @@ export default function local(): Local {
6873
package: packageComponents()
6974
};
7075
}
76+
77+
export type Local = ReturnType<typeof local>;

src/cli/domain/package-components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import requireTemplate from './handle-dependencies/require-template';
66
import * as validator from '../../registry/domain/validators';
77
import { Component } from '../../types';
88

9-
interface PackageOptions {
9+
export interface PackageOptions {
1010
componentPath: string;
1111
minify?: boolean;
1212
verbose?: boolean;

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/clean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import readCb from 'read';
22
import { fromPromise } from 'universalify';
33
import { promisify } from 'util';
44
import strings from '../../resources/index';
5-
import { Local } from '../../types';
5+
import type { Local } from '../domain/local';
66
import { Logger } from '../logger';
77

88
const read = promisify(readCb);

src/cli/facade/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as oc from '../../index';
1111
import strings from '../../resources/index';
1212
import watch from '../domain/watch';
1313
import { Logger } from '../logger';
14-
import { Local } from '../../types';
14+
import type { Local } from '../domain/local';
1515

1616
type Registry = ReturnType<typeof oc.Registry>;
1717

src/cli/facade/init.ts

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

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

88
const init = ({ local, logger }: { local: Local; logger: Logger }) =>

src/cli/facade/mock.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 { Local } from '../../types';
3+
import type { Local } from '../domain/local';
44
import { Logger } from '../logger';
55

66
const mock = ({ local, logger }: { local: Local; logger: Logger }) =>

src/cli/facade/package.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import path from 'path';
33
import { fromPromise } from 'universalify';
44
import handleDependencies from '../domain/handle-dependencies';
55
import { Logger } from '../logger';
6-
import { Component, Local } from '../../types';
6+
import type { Local } from '../domain/local';
7+
import { Component } from '../../types';
78

89
const cliPackage = ({ local, logger }: { local: Local; logger: Logger }) =>
910
fromPromise(

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import fs from 'fs-extra';
44
import readCb from 'read';
55
import { promisify } from 'util';
66
import { Logger } from '../logger';
7-
import { Component, RegistryCli, Local } from '../../types';
7+
import type { Local } from '../domain/local';
8+
import { Component } from '../../types';
89
import { fromPromise } from 'universalify';
910

1011
import handleDependencies from '../domain/handle-dependencies';
1112
import strings from '../../resources/index';
13+
import { RegistryCli } from '../domain/registry';
1214

1315
const read = promisify(readCb);
1416

0 commit comments

Comments
 (0)