dts-gen 0.7.4 → 0.8.2
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/CHANGELOG.md +19 -0
- package/LICENSE +17 -17
- package/README.md +148 -172
- package/dist/definitely-typed.d.ts +1 -0
- package/dist/definitely-typed.js +129 -0
- package/dist/definitely-typed.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/{bin/lib → dist}/index.js +76 -50
- package/dist/index.js.map +1 -0
- package/dist/names.d.ts +1 -0
- package/{bin/lib → dist}/names.js +3 -2
- package/dist/names.js.map +1 -0
- package/dist/run.d.ts +2 -0
- package/dist/run.js +199 -0
- package/dist/run.js.map +1 -0
- package/package.json +31 -39
- package/templates/global-modifying-module.d.ts +8 -8
- package/templates/global-plugin.d.ts +7 -7
- package/templates/global.d.ts +35 -35
- package/templates/module-class.d.ts +7 -7
- package/templates/module-function.d.ts +15 -15
- package/templates/module-plugin.d.ts +17 -17
- package/templates/module.d.ts +11 -11
- package/SECURITY.md +0 -41
- package/bin/lib/definitely-typed.js +0 -145
- package/bin/lib/run.js +0 -166
- package/tsconfig.json +0 -21
- package/tslint.json +0 -24
- package/webpack.config.js +0 -19
package/bin/lib/run.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const yargs = require("yargs");
|
|
7
|
-
const guess = require("./");
|
|
8
|
-
const definitely_typed_1 = require("./definitely-typed");
|
|
9
|
-
const templatesDirectory = path.join(__dirname, "..", "..", "templates");
|
|
10
|
-
const args = yargs
|
|
11
|
-
.alias('m', 'module')
|
|
12
|
-
.alias('i', 'identifier')
|
|
13
|
-
.alias('e', 'expression')
|
|
14
|
-
.alias('n', 'name')
|
|
15
|
-
.alias('f', 'file')
|
|
16
|
-
.alias('d', 'dt')
|
|
17
|
-
.alias('s', 'stdout')
|
|
18
|
-
.alias('o', 'overwrite')
|
|
19
|
-
.alias('t', 'template')
|
|
20
|
-
.alias('v', 'version')
|
|
21
|
-
.argv;
|
|
22
|
-
class ArgsError extends Error {
|
|
23
|
-
constructor(argsError) {
|
|
24
|
-
super();
|
|
25
|
-
this.argsError = argsError;
|
|
26
|
-
this.name = 'ArgsError';
|
|
27
|
-
this.message = argsError;
|
|
28
|
-
Object.setPrototypeOf(this, ArgsError.prototype);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
let result;
|
|
32
|
-
try {
|
|
33
|
-
if (args.version) {
|
|
34
|
-
console.log(require("../../package.json").version);
|
|
35
|
-
process.exit(0);
|
|
36
|
-
}
|
|
37
|
-
if (+!!args.dt + +!!args.file + +!!args.stdout > 1) {
|
|
38
|
-
throw new ArgsError('Cannot specify more than one output mode');
|
|
39
|
-
}
|
|
40
|
-
if (+!!args.identifier + +!!args.expression + +!!args.module + +!!args['expression-file'] + +!!args.template
|
|
41
|
-
!== 1) {
|
|
42
|
-
throw new ArgsError('Must specify exactly one input');
|
|
43
|
-
}
|
|
44
|
-
if (typeof args.name === 'boolean')
|
|
45
|
-
throw new ArgsError('Must specify a value for "--name"');
|
|
46
|
-
if (typeof args.identifier === 'boolean')
|
|
47
|
-
throw new ArgsError('Must specify a value for "--identifier"');
|
|
48
|
-
if (typeof args.module === 'boolean')
|
|
49
|
-
throw new ArgsError('Must specify a value for "--module"');
|
|
50
|
-
if (args.overwrite !== undefined && args.overwrite !== true)
|
|
51
|
-
throw new ArgsError('--overwrite does not accept an argument');
|
|
52
|
-
let name;
|
|
53
|
-
if (args.module) {
|
|
54
|
-
if (args.name)
|
|
55
|
-
throw new ArgsError('Cannot use --name with --module');
|
|
56
|
-
name = args.module;
|
|
57
|
-
module.paths.unshift(process.cwd() + '/node_modules');
|
|
58
|
-
result = guess.generateModuleDeclarationFile(args.module, require(args.module));
|
|
59
|
-
}
|
|
60
|
-
else if (args.expression) {
|
|
61
|
-
name = args.name || 'dts_gen_expr';
|
|
62
|
-
result = guess.generateIdentifierDeclarationFile(name, eval(args.expression));
|
|
63
|
-
}
|
|
64
|
-
else if (args['expression-file']) {
|
|
65
|
-
if (args.name)
|
|
66
|
-
throw new ArgsError('Cannot use --name with --expression-file');
|
|
67
|
-
const filename = args['expression-file'];
|
|
68
|
-
name = path.basename(filename, path.extname(filename)).replace(/[^A-Za-z0-9]/g, '_');
|
|
69
|
-
module.paths.unshift(process.cwd() + '/node_modules');
|
|
70
|
-
const fileContent = fs.readFileSync(filename, "utf-8");
|
|
71
|
-
result = guess.generateIdentifierDeclarationFile(name, eval(fileContent));
|
|
72
|
-
}
|
|
73
|
-
else if (args.identifier) {
|
|
74
|
-
if (args.name)
|
|
75
|
-
throw new ArgsError('Cannot use --name with --identifier');
|
|
76
|
-
if (args.module || args.expression)
|
|
77
|
-
throw new ArgsError('Cannot specify more than one input');
|
|
78
|
-
name = args.identifier;
|
|
79
|
-
result = guess.generateIdentifierDeclarationFile(args.identifier, eval(args.identifier));
|
|
80
|
-
}
|
|
81
|
-
else if (args.template) {
|
|
82
|
-
if (!args.name)
|
|
83
|
-
throw new ArgsError('Needs a name');
|
|
84
|
-
name = args.name;
|
|
85
|
-
if (args.module || args.expression)
|
|
86
|
-
throw new ArgsError('Cannot mix --template with --module or --expression');
|
|
87
|
-
result = getTemplate(args.template);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
throw new Error('Internal error, please log a bug with the commandline you specified');
|
|
91
|
-
}
|
|
92
|
-
if (args.dt) {
|
|
93
|
-
(0, definitely_typed_1.default)(result, name, !!args.overwrite);
|
|
94
|
-
}
|
|
95
|
-
else if (args.stdout) {
|
|
96
|
-
console.log(result);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
let filename = typeof args.file === 'boolean' || args.file === undefined ? name + '.d.ts' : args.file;
|
|
100
|
-
if (!filename.endsWith('.d.ts')) {
|
|
101
|
-
filename = filename + '.d.ts';
|
|
102
|
-
}
|
|
103
|
-
if (!args.overwrite && fs.existsSync(filename)) {
|
|
104
|
-
console.error(`File ${filename} already exists and --overwrite was not specified; exiting.`);
|
|
105
|
-
process.exit(2);
|
|
106
|
-
}
|
|
107
|
-
fs.writeFileSync(filename, prependOurHeader(result), 'utf-8');
|
|
108
|
-
console.log(`Wrote ${result.split(/\r\n|\r|\n/).length} lines to ${filename}.`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
if (e instanceof ArgsError) {
|
|
113
|
-
console.error('Invalid arguments: ' + e.argsError);
|
|
114
|
-
console.log('');
|
|
115
|
-
printHelp();
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
else if (e.code === 'MODULE_NOT_FOUND') {
|
|
119
|
-
console.error(`Error loading module "${args.module}".\n` +
|
|
120
|
-
getErrorMessageFirstLine(e).replace(/'/g, '"') + '.\n' +
|
|
121
|
-
`Please install missing module and try again.`);
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
console.log('Unexpected crash! Please log a bug with the commandline you specified.');
|
|
126
|
-
throw e;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function printHelp() {
|
|
130
|
-
console.log('Usage: dts-gen input [settings] [output]');
|
|
131
|
-
console.log('');
|
|
132
|
-
console.log('Input Options:');
|
|
133
|
-
console.log(' -m[odule] fs The "fs" node module (must be installed)');
|
|
134
|
-
console.log(' -i[dentifier] Math The global variable "Math"');
|
|
135
|
-
console.log(' -e[xpression] "new C()" The expression "new C()"');
|
|
136
|
-
console.log(' -t[emplate] module Name of a template. Templates are:');
|
|
137
|
-
console.log(` ${allTemplateNames()}`);
|
|
138
|
-
console.log('');
|
|
139
|
-
console.log('Settings:');
|
|
140
|
-
console.log(' -n[ame] n The name to emit when generating for an expression');
|
|
141
|
-
console.log('');
|
|
142
|
-
console.log('Output Options:');
|
|
143
|
-
console.log(' -f[ile] [filename.d.ts] Write to a file (default)');
|
|
144
|
-
console.log(' -d[t] [dirName] Create a folder suitable for DefinitelyTyped');
|
|
145
|
-
console.log(' -s[tdout] Write to stdout');
|
|
146
|
-
console.log(' -o[verwrite] Allow overwriting files');
|
|
147
|
-
console.log('');
|
|
148
|
-
console.log('Example: dts-gen -m fs --stdout');
|
|
149
|
-
}
|
|
150
|
-
function prependOurHeader(result) {
|
|
151
|
-
return `/** Declaration file generated by dts-gen */\r\n\r\n` + result;
|
|
152
|
-
}
|
|
153
|
-
function getTemplate(templateName) {
|
|
154
|
-
try {
|
|
155
|
-
return fs.readFileSync(path.join(templatesDirectory, templateName + ".d.ts"), "utf-8");
|
|
156
|
-
}
|
|
157
|
-
catch (e) {
|
|
158
|
-
throw new ArgsError(`Could not read template '${templateName}'. Expected one of:\n${allTemplateNames()}`);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function allTemplateNames() {
|
|
162
|
-
return fs.readdirSync(templatesDirectory).map(t => t.slice(0, t.length - ".d.ts".length)).join(", ");
|
|
163
|
-
}
|
|
164
|
-
function getErrorMessageFirstLine(error) {
|
|
165
|
-
return error.message.split('\n', 1)[0];
|
|
166
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": [
|
|
3
|
-
"lib",
|
|
4
|
-
"tests"
|
|
5
|
-
],
|
|
6
|
-
"compilerOptions": {
|
|
7
|
-
"lib": [
|
|
8
|
-
"es6",
|
|
9
|
-
"dom"
|
|
10
|
-
],
|
|
11
|
-
"module": "commonjs",
|
|
12
|
-
"target": "es6",
|
|
13
|
-
"noImplicitAny": true,
|
|
14
|
-
"strictNullChecks": true,
|
|
15
|
-
"noUnusedLocals": true,
|
|
16
|
-
"noUnusedParameters": true,
|
|
17
|
-
"sourceMap": false,
|
|
18
|
-
"outDir": "./bin",
|
|
19
|
-
"newLine": "LF"
|
|
20
|
-
}
|
|
21
|
-
}
|
package/tslint.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "tslint:latest",
|
|
3
|
-
"rules": {
|
|
4
|
-
"arrow-parens": [true, "ban-single-arg-parens"],
|
|
5
|
-
"indent": [true, "spaces"],
|
|
6
|
-
"interface-name": [true, "never-prefix"],
|
|
7
|
-
"member-access": [true, "no-public"],
|
|
8
|
-
|
|
9
|
-
"ban-types": false,
|
|
10
|
-
"curly": false,
|
|
11
|
-
"member-ordering": false,
|
|
12
|
-
"no-duplicate-imports": false,
|
|
13
|
-
"no-angle-bracket-type-assertion": false,
|
|
14
|
-
"no-bitwise": false,
|
|
15
|
-
"no-console": false,
|
|
16
|
-
"no-empty": false,
|
|
17
|
-
"no-eval": false,
|
|
18
|
-
"no-shadowed-variable": false,
|
|
19
|
-
"no-var-requires": false,
|
|
20
|
-
"object-literal-sort-keys": false,
|
|
21
|
-
"quotemark": false,
|
|
22
|
-
"variable-name": false
|
|
23
|
-
}
|
|
24
|
-
}
|
package/webpack.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const webpack = require('webpack');
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
entry: './bin/browser/browser.js',
|
|
5
|
-
output: {
|
|
6
|
-
path: './docs',
|
|
7
|
-
filename: 'browser-bundle.js'
|
|
8
|
-
},
|
|
9
|
-
plugins: [
|
|
10
|
-
new webpack.optimize.UglifyJsPlugin({
|
|
11
|
-
compress: {
|
|
12
|
-
warnings: false,
|
|
13
|
-
},
|
|
14
|
-
output: {
|
|
15
|
-
comments: false,
|
|
16
|
-
},
|
|
17
|
-
}),
|
|
18
|
-
]
|
|
19
|
-
};
|