bio-dts 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/bin/cmd.js +9 -3
- package/lib/generate-types.js +16 -2
- package/lib/parsers/jsdoc.js +1 -1
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -20,10 +20,14 @@ npx bio-dts --outDir dist/types -r lib
|
|
|
20
20
|
|
|
21
21
|
## Features
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*
|
|
23
|
+
Generates clean type definitions from ES5 code bases:
|
|
24
|
+
|
|
25
|
+
* ES5 prototypical classes + inheritance
|
|
26
|
+
* Optional parameters before required ones
|
|
27
|
+
* Function overloading (via `@overlord` annotations, actually works!)
|
|
26
28
|
* Converts JSDoc to [TSDoc](https://github.com/microsoft/tsdoc)
|
|
29
|
+
* Only exposed documented parameters
|
|
30
|
+
* Validates, where needed declared parameters
|
|
27
31
|
|
|
28
32
|
Checkout the [test fixtures](./test/fixtures) for full coverage.
|
|
29
33
|
|
package/bin/cmd.js
CHANGED
|
@@ -21,7 +21,9 @@ async function run() {
|
|
|
21
21
|
} = ts.parseCommandLine(args);
|
|
22
22
|
|
|
23
23
|
const help = args.includes('--help') || args.includes('-h');
|
|
24
|
-
const
|
|
24
|
+
const verboseMatch = /--verbose(?:=([^\s$]+))?(\s|$)/.exec(args);
|
|
25
|
+
|
|
26
|
+
const verbose = verboseMatch ? verboseMatch[1] || true : false;
|
|
25
27
|
const recursive = args.includes('--recursive') || args.includes('-r');
|
|
26
28
|
|
|
27
29
|
if (help) {
|
|
@@ -58,13 +60,17 @@ async function run() {
|
|
|
58
60
|
|
|
59
61
|
console.log(`Generating types for ${files.length} files...`);
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
const generateOptions = {
|
|
62
64
|
allowJs: true,
|
|
63
65
|
declaration: true,
|
|
64
66
|
emitDeclarationOnly: true,
|
|
65
67
|
...options,
|
|
66
68
|
verbose
|
|
67
|
-
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
verbose && console.log('Using options ', generateOptions);
|
|
72
|
+
|
|
73
|
+
generateTypes(files, generateOptions);
|
|
68
74
|
|
|
69
75
|
console.log('Done.');
|
|
70
76
|
}
|
package/lib/generate-types.js
CHANGED
|
@@ -25,10 +25,11 @@ export default function generateTypes(fileNames, options) {
|
|
|
25
25
|
* @return {string}
|
|
26
26
|
*/
|
|
27
27
|
host.readFile = (fileName) => {
|
|
28
|
-
options.verbose && console.debug('[generate-types] [pre]', fileName);
|
|
29
28
|
|
|
30
29
|
let src = host._readFile(fileName);
|
|
31
30
|
|
|
31
|
+
isVerbose(options, fileName) && console.debug('[generate-types] [pre]', fileName, src);
|
|
32
|
+
|
|
32
33
|
if (names.has(path.resolve(fileName))) {
|
|
33
34
|
try {
|
|
34
35
|
src = preTransform(src);
|
|
@@ -38,13 +39,15 @@ export default function generateTypes(fileNames, options) {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
isVerbose(options, fileName) && console.debug('[generate-types] [pre] [generated]', fileName, src);
|
|
43
|
+
|
|
41
44
|
return src;
|
|
42
45
|
};
|
|
43
46
|
|
|
44
47
|
host._writeFile = host.writeFile;
|
|
45
48
|
|
|
46
49
|
host.writeFile = (fileName, text, ...args) => {
|
|
47
|
-
options
|
|
50
|
+
isVerbose(options, fileName) && console.debug('[generate-types] [post]', fileName, text);
|
|
48
51
|
|
|
49
52
|
try {
|
|
50
53
|
text = postTransform(text);
|
|
@@ -53,10 +56,21 @@ export default function generateTypes(fileNames, options) {
|
|
|
53
56
|
throw err;
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
isVerbose(options, fileName) && console.debug('[generate-types] [post] [generated]', fileName, text);
|
|
60
|
+
|
|
56
61
|
host._writeFile(fileName, text, ...args);
|
|
57
62
|
};
|
|
58
63
|
|
|
59
64
|
const program = ts.createProgram(fileNames, options, host);
|
|
60
65
|
|
|
61
66
|
program.emit();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function isVerbose(options, fileName) {
|
|
70
|
+
|
|
71
|
+
if (typeof options.verbose === 'boolean') {
|
|
72
|
+
return options.verbose;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return fileName.includes(options.verbose);
|
|
62
76
|
}
|
package/lib/parsers/jsdoc.js
CHANGED
|
@@ -108,7 +108,7 @@ export function parse(str) {
|
|
|
108
108
|
const contents = tag.param.contents = str.substring(match.start + 1, match.end - 1);
|
|
109
109
|
const idxEq = contents.indexOf('=');
|
|
110
110
|
|
|
111
|
-
tag.param.name = idxEq !== -1 ? contents.substring(0, idxEq) : contents;
|
|
111
|
+
tag.param.name = idxEq !== -1 ? contents.substring(0, idxEq).trim() : contents;
|
|
112
112
|
} else {
|
|
113
113
|
j = skipText(str, i);
|
|
114
114
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bio-dts",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Generate sane and clean types from JavaScript sources",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"test": "mocha test",
|
|
12
12
|
"test:dts": "node bin/cmd.js --outDir dist -r test/fixtures"
|
|
13
13
|
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/nikku/bio-dts"
|
|
17
|
+
},
|
|
14
18
|
"author": "Nico Rehwaldt",
|
|
15
19
|
"license": "MIT",
|
|
16
20
|
"dependencies": {
|