Skip to content

Commit 3a8547f

Browse files
update types
1 parent 2fde6fb commit 3a8547f

File tree

10 files changed

+39
-23
lines changed

10 files changed

+39
-23
lines changed

src/registry/routes/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const dateStringified = require('../../utils/date-stringify').default;
88
const getComponentsHistory = require('./helpers/get-components-history')
99
.default;
1010
const getAvailableDependencies = require('./helpers/get-available-dependencies');
11-
const indexView = require('../views');
11+
const indexView = require('../views').default;
1212
// @ts-ignore
1313
const packageInfo = require('../../../package.json');
1414
const urlBuilder = require('../domain/url-builder');

src/registry/views/index.js renamed to src/registry/views/index.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
module.exports = vm => {
1+
import dependencies from './partials/components-dependencies';
2+
import history from './partials/components-history';
3+
import list from './partials/components-list';
4+
import templates from './partials/components-templates';
5+
import plugins from './partials/components-plugins';
6+
import indexJS from './static/index';
7+
8+
import getLayout from './partials/layout';
9+
import getProperty from './partials/property';
10+
import { VM } from '../../types';
11+
12+
export default function indexView(vm: VM): string {
213
const tabs = {
3-
dependencies: require('./partials/components-dependencies').default(vm),
4-
history: require('./partials/components-history').default(vm),
5-
list: require('./partials/components-list').default(vm),
6-
templates: require('./partials/components-templates').default(vm),
7-
plugins: require('./partials/components-plugins').default(vm)
14+
dependencies: dependencies(vm),
15+
history: history(vm),
16+
list: list(vm),
17+
templates: templates(vm),
18+
plugins: plugins(vm)
819
};
920

10-
const indexJS = require('./static/index').default;
11-
const layout = require('./partials/layout').default(vm);
12-
const property = require('./partials/property').default();
21+
const layout = getLayout(vm);
22+
const property = getProperty();
1323

14-
const getCount = state => vm.stateCounts[state] || 0;
24+
const getCount = (state: 'deprecated' | 'experimental') =>
25+
vm.stateCounts[state] || 0;
1526
const isLocal = vm.type !== 'oc-registry';
1627

1728
const componentsValue = `${vm.components.length} (${getCount(
@@ -52,4 +63,4 @@ module.exports = vm => {
5263
${indexJS}</script>`;
5364

5465
return layout({ content, scripts });
55-
};
66+
}

src/registry/views/info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function info(vm: Vm): string {
2727
const layout = getLayout(vm);
2828
const property = getProperty();
2929

30-
const showArray = (title, arr) =>
30+
const showArray = (title: string, arr?: string[]) =>
3131
property(title, !!arr && arr.length > 0 ? arr.join(', ') : 'none');
3232

3333
const { component, dependencies, href, repositoryUrl, sandBoxDefaultQs } = vm;

src/registry/views/partials/component-parameters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '../../../types';
1+
import { Component, OcParameter } from '../../../types';
22

33
const componentParameters = ({
44
component
@@ -11,7 +11,7 @@ const componentParameters = ({
1111
return `${parameters}<p class="w-100">none</p>`;
1212
}
1313

14-
const parameterRow = (param, paramName) => {
14+
const parameterRow = (param: OcParameter, paramName: string) => {
1515
const mandatory = param.mandatory ? 'mandatory' : 'optional';
1616
const description = param.description
1717
? `<span>${param.description}</span><br /><br />`

src/registry/views/partials/component-versions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const componentVersions = ({
55
}: {
66
component: Component;
77
}) => (): string => {
8-
const componentOption = version =>
8+
const componentOption = (version: string) =>
99
`<option value="${version}"${
1010
version === component.version ? ' selected="selected"' : ''
1111
}>${version}</option>`;

src/registry/views/partials/components-history.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { VM } from '../../../types';
22

3-
export default function componentsHistory(vm: VM) {
3+
export default function componentsHistory(vm: VM): string {
44
const componentRow = ({
55
name,
66
publishDate,

src/registry/views/partials/components-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { VM } from '../../../types';
1+
import { Component, VM } from '../../../types';
22
import getSelectedCheckbox from './selected-checkbox';
33

44
export default function componentsList(vm: VM): string {
@@ -9,7 +9,7 @@ export default function componentsList(vm: VM): string {
99
? '<div class="date">Updated</div><div class="activity">Activity</div>'
1010
: '';
1111

12-
const componentRow = component => {
12+
const componentRow = (component: Component) => {
1313
const componentState = component.oc.state
1414
? `<div class="state component-state-${component.oc.state.toLowerCase()}">${
1515
component.oc.state

src/registry/views/partials/components-plugins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { VM } from '../../../types';
22

3-
export default function componentsPlugins(vm: VM) {
3+
export default function componentsPlugins(vm: VM): string {
44
const pluginRow = ([
55
name,
66
description

src/registry/views/partials/components-templates.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { VM } from '../../../types';
22

33
export default function componentsTemplates(vm: VM): string {
4-
const externalLink = ({ global, url }) =>
5-
`<a href="${url}" target="_blank">${global}</a>`;
4+
const externalLink = ({
5+
global,
6+
url
7+
}: {
8+
global: string | string[];
9+
url: string;
10+
}) => `<a href="${url}" target="_blank">${global}</a>`;
611

712
const templateRow = ({
813
externals,

src/registry/views/partials/layout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const layout = (vm: { title: string; href: string }) => ({
66
}: {
77
content: string;
88
scripts: string;
9-
}) => {
9+
}): string => {
1010
const href = vm.href.replace('http://', '//').replace('https://', '//');
1111

1212
return `<!DOCTYPE html><html>

0 commit comments

Comments
 (0)