Skip to content

Commit 8d4f7f4

Browse files
committed
Add TypeScript components generation support.
1 parent 2714c9f commit 8d4f7f4

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

Diff for: dash/meta-ts.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ if (process.env.MODULES_PATH) {
55
const ts = require('typescript');
66
const fs = require('fs');
77
const path = require('path');
8-
const R = require('ramda');
98

109
const args = process.argv.slice(2);
1110
const src = args[2];
@@ -40,9 +39,9 @@ const PRIMITIVES = [
4039
'node'
4140
];
4241

43-
const unionSupport = R.concat(PRIMITIVES, ['boolean', 'Element']);
42+
const unionSupport = PRIMITIVES.concat('boolean', 'Element');
4443

45-
const reArray = new RegExp(`(${R.join('|', unionSupport)})\\[\\]`);
44+
const reArray = new RegExp(`(${unionSupport.join('|')})\\[\\]`);
4645

4746
const isArray = rawType => reArray.test(rawType);
4847

@@ -62,6 +61,14 @@ if (fs.existsSync('tsconfig.json')) {
6261
tsconfig = JSON.parse(fs.readFileSync('tsconfig.json'));
6362
}
6463

64+
function zipArrays(...arrays) {
65+
const arr = [];
66+
for (let i = 0; i <= arrays[0].length - 1; i++) {
67+
arr.push(arrays.map(a => a[i]));
68+
}
69+
return arr;
70+
}
71+
6572
function gatherComponents(directory, components = {}) {
6673
const names = [];
6774
const filepaths = [];
@@ -158,7 +165,7 @@ function gatherComponents(directory, components = {}) {
158165
}
159166
}
160167
return (
161-
R.includes(typeName, unionSupport) ||
168+
unionSupport.includes(typeName) ||
162169
isArray(checker.typeToString(t))
163170
);
164171
})
@@ -175,7 +182,7 @@ function gatherComponents(directory, components = {}) {
175182
};
176183

177184
const getPropTypeName = propName => {
178-
if (R.includes('=>', propName) || propName === 'Function') {
185+
if (propName.includes('=>') || propName === 'Function') {
179186
return 'func';
180187
} else if (propName === 'boolean') {
181188
return 'bool';
@@ -200,25 +207,23 @@ function gatherComponents(directory, components = {}) {
200207
if (propType.isUnion()) {
201208
if (isUnionlitteral(propType)) {
202209
return {...getEnum(propType), raw};
203-
} else if (R.includes('|', raw)) {
210+
} else if (raw.includes('|')) {
204211
return {...getUnion(propType, propObj), raw};
205212
}
206213
}
207214

208215
name = getPropTypeName(name);
209216

210217
// Shapes & array support.
211-
if (
212-
!R.includes(name, R.concat(PRIMITIVES, ['enum', 'func', 'union']))
213-
) {
218+
if (!PRIMITIVES.concat('enum', 'func', 'union').includes(name)) {
214219
if (
215-
R.includes('[]', name) ||
216-
R.includes('Array', name) ||
220+
name.includes('[]') ||
221+
name.includes('Array') ||
217222
name === 'tuple'
218223
) {
219224
name = 'arrayOf';
220-
const replaced = R.replace('[]', '', raw);
221-
if (R.includes(replaced, unionSupport)) {
225+
const replaced = raw.replace('[]', '');
226+
if (unionSupport.includes('replaced')) {
222227
// Simple types are easier.
223228
value = {
224229
name: getPropTypeName(replaced),
@@ -307,17 +312,14 @@ function gatherComponents(directory, components = {}) {
307312
const comment = symbol.getDocumentationComment();
308313
const tags = symbol.getJsDocTags();
309314
if (comment && comment.length) {
310-
return R.join('\n')(
311-
R.concat(
312-
comment.map(c => c.text),
315+
return comment
316+
.map(c => c.text)
317+
.concat(
313318
tags.map(t =>
314-
R.concat(
315-
['@', t.name],
316-
(t.text || []).map(e => e.text)
317-
)
319+
['@', t.name].concat((t.text || []).map(e => e.text))
318320
)
319321
)
320-
);
322+
.join('\n');
321323
}
322324
return '';
323325
};
@@ -528,7 +530,7 @@ function gatherComponents(directory, components = {}) {
528530
return getProps(propertiesOfProps, propsObj, baseProps, defaultProps);
529531
};
530532

531-
R.zip(filepaths, names).forEach(([f, name]) => {
533+
zipArrays(filepaths, names).forEach(([f, name]) => {
532534
const source = program.getSourceFile(f);
533535
const moduleSymbol = checker.getSymbolAtLocation(source);
534536
const exports = checker.getExportsOfModule(moduleSymbol);

0 commit comments

Comments
 (0)