Skip to content

Commit 4c59276

Browse files
Merge branch 'master' into yet-another-ts-pr
2 parents 50ed15b + 09f0550 commit 4c59276

15 files changed

+105
-45
lines changed

src/cli/domain/clean.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import path from 'path';
55

66
const getComponentsByDir = makeGetComponentsByDir();
77

8-
export function fetchList(dirPath: string, callback: Callback<string[]>) {
8+
export function fetchList(dirPath: string, callback: Callback<string[]>): void {
99
return getComponentsByDir(dirPath, (err, list) => {
1010
if (err) return (callback as any)(err);
1111
if (list.length === 0) return callback(null, []);
1212

1313
const toRemove = list.map(folder => path.join(folder, 'node_modules'));
14-
const folderExists = (folder, cb) =>
14+
const folderExists = (folder: string, cb: Callback<boolean>) =>
1515
fs.exists(folder, exists => cb(null, exists));
1616

1717
async.filterSeries(toRemove, folderExists, callback as any);
1818
});
1919
}
2020

21-
export function remove(list: string[], callback: Callback<string>) {
21+
export function remove(list: string[], callback: Callback<string>): void {
2222
return async.eachSeries(list, fs.remove, callback as any);
2323
}

src/registry/routes/component-info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const parseAuthor = require('parse-author');
44
const _ = require('lodash');
55

66
const getComponentFallback = require('./helpers/get-component-fallback');
7-
const infoView = require('../views/info');
7+
const infoView = require('../views/info').default;
88
const isUrlDiscoverable = require('./helpers/is-url-discoverable').default;
99
const urlBuilder = require('../domain/url-builder');
1010

src/registry/routes/component-preview.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const _ = require('lodash');
44

55
const getComponentFallback = require('./helpers/get-component-fallback');
6-
const previewView = require('../views/preview');
6+
const previewView = require('../views/preview').default;
77
const urlBuilder = require('../domain/url-builder');
88

99
function componentPreview(err, req, res, component, templates) {
@@ -25,6 +25,7 @@ function componentPreview(err, req, res, component, templates) {
2525
return res.send(
2626
previewView({
2727
component,
28+
// @ts-ignore
2829
dependencies: Object.keys(component.dependencies || {}),
2930
href: res.conf.baseUrl,
3031
liveReload,

src/registry/views/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export default function indexView(vm: VM): string {
2121
const layout = getLayout(vm);
2222
const property = getProperty();
2323

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

2728
const componentsValue = `${vm.components.length} (${getCount(

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

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1-
module.exports = vm => {
2-
const componentAuthor = require('./partials/component-author')(vm);
3-
const componentParameters = require('./partials/component-parameters')(vm);
4-
const componentState = require('./partials/component-state')(vm);
5-
const componentVersions = require('./partials/component-versions')(vm);
6-
const infoJS = require('./static/info').default;
7-
const layout = require('./partials/layout').default(vm);
8-
const property = require('./partials/property').default();
9-
const isTemplateLegacy = require('../../utils/is-template-legacy').default;
1+
import { Component } from '../../types';
102

11-
const showArray = (title, arr) =>
3+
import getComponentAuthor from './partials/component-author';
4+
import getComponentParameters from './partials/component-parameters';
5+
import getComponentState from './partials/component-state';
6+
import getComponentVersions from './partials/component-versions';
7+
import infoJS from './static/info';
8+
import getLayout from './partials/layout';
9+
import getProperty from './partials/property';
10+
import isTemplateLegacy from '../../utils/is-template-legacy';
11+
12+
interface Vm {
13+
parsedAuthor: { name?: string; email?: string; url?: string };
14+
component: Component;
15+
dependencies: string[];
16+
href: string;
17+
sandBoxDefaultQs: string;
18+
title: string;
19+
repositoryUrl: string;
20+
}
21+
22+
export default function info(vm: Vm): string {
23+
const componentAuthor = getComponentAuthor(vm);
24+
const componentParameters = getComponentParameters(vm);
25+
const componentState = getComponentState(vm);
26+
const componentVersions = getComponentVersions(vm);
27+
const layout = getLayout(vm);
28+
const property = getProperty();
29+
30+
const showArray = (title: string, arr?: string[]) =>
1231
property(title, !!arr && arr.length > 0 ? arr.join(', ') : 'none');
1332

1433
const { component, dependencies, href, repositoryUrl, sandBoxDefaultQs } = vm;
@@ -64,4 +83,4 @@ module.exports = vm => {
6483
</script>`;
6584

6685
return layout({ content, scripts });
67-
};
86+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
module.exports = vm => () => {
1+
const componentAuthor = (vm: {
2+
parsedAuthor: {
3+
name?: string;
4+
email?: string;
5+
url?: string;
6+
};
7+
}) => (): string => {
28
const author = vm.parsedAuthor;
39
let placeholder = '';
410

@@ -11,16 +17,14 @@ module.exports = vm => () => {
1117
}
1218

1319
if (author.email) {
14-
placeholder += `<span><a href="mailto:${author.email}">${
15-
author.email
16-
}</a>&nbsp;</span>`;
20+
placeholder += `<span><a href="mailto:${author.email}">${author.email}</a>&nbsp;</span>`;
1721
}
1822

1923
if (author.url) {
20-
placeholder += `<span><a href="${author.url}" target="_blank">${
21-
author.url
22-
}</a></span>`;
24+
placeholder += `<span><a href="${author.url}" target="_blank">${author.url}</a></span>`;
2325
}
2426

2527
return `<div class="field"><p>Author:</p>${placeholder}</div>`;
2628
};
29+
30+
export default componentAuthor;

src/registry/views/partials/component-parameters.js renamed to src/registry/views/partials/component-parameters.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
module.exports = ({ component }) => () => {
1+
import { Component, OcParameter } from '../../../types';
2+
3+
const componentParameters = ({
4+
component
5+
}: {
6+
component: Component;
7+
}) => (): string => {
28
let parameters = `<h3>Parameters</h3>`;
39

410
if (!component.oc.parameters) {
511
return `${parameters}<p class="w-100">none</p>`;
612
}
713

8-
const parameterRow = (param, paramName) => {
14+
const parameterRow = (param: OcParameter, paramName: string) => {
915
const mandatory = param.mandatory ? 'mandatory' : 'optional';
1016
const description = param.description
1117
? `<span>${param.description}</span><br /><br />`
1218
: '';
1319
const defaultParam =
1420
!param.mandatory && param.default
15-
? `<br /><br /><span class="bold">Default:</span><span>${
16-
param.default
17-
}</span>`
21+
? `<br /><br /><span class="bold">Default:</span><span>${param.default}</span>`
1822
: '';
1923

2024
return `<div class="row">
@@ -41,9 +45,11 @@ module.exports = ({ component }) => () => {
4145
<div class="row header">
4246
<div class="parameter">Parameters</div>
4347
<div class="parameter-description"></div>
44-
</div>
48+
</div>
4549
${rows}
4650
</div>`;
4751

4852
return parameters;
4953
};
54+
55+
export default componentParameters;
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
module.exports = ({ component }) => () =>
1+
import { Component } from '../../../types';
2+
3+
const componentState = ({
4+
component
5+
}: {
6+
component: Component;
7+
}) => (): string =>
28
!component.oc.state
39
? ''
410
: `<span class="details-state">
511
<span class="component-state-${component.oc.state.toLowerCase()}">
612
${component.oc.state}
713
</span>
814
</span>`;
15+
16+
export default componentState;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
module.exports = ({ component }) => () => {
2-
const componentOption = version =>
1+
import { Component } from '../../../types';
2+
3+
const componentVersions = ({
4+
component
5+
}: {
6+
component: Component;
7+
}) => (): string => {
8+
const componentOption = (version: string) =>
39
`<option value="${version}"${
410
version === component.version ? ' selected="selected"' : ''
511
}>${version}</option>`;
@@ -8,3 +14,5 @@ module.exports = ({ component }) => () => {
814
.map(componentOption)
915
.join('')}</select>`;
1016
};
17+
18+
export default componentVersions;

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,

0 commit comments

Comments
 (0)