@glutinum/cli 1.0.0-beta.2 → 1.0.0-beta.3
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 +16 -0
- package/dist/Glutinum.Converter/Abbreviations.js +9 -32
- package/dist/Glutinum.Converter/DelegateExtensions.js +378 -0
- package/dist/Glutinum.Converter/FreeTypeParameters.js +211 -0
- package/dist/Glutinum.Converter/FsharpAST.js +116 -65
- package/dist/Glutinum.Converter/Generate.js +34 -21
- package/dist/Glutinum.Converter/GlueAST.js +79 -41
- package/dist/Glutinum.Converter/Hosting.js +132 -157
- package/dist/Glutinum.Converter/Merge.js +369 -337
- package/dist/Glutinum.Converter/Packages.js +391 -92
- package/dist/Glutinum.Converter/Printer.js +396 -423
- package/dist/Glutinum.Converter/Read.js +387 -88
- package/dist/Glutinum.Converter/Reader/ClassDeclaration.js +4 -4
- package/dist/Glutinum.Converter/Reader/Declaration.js +6 -12
- package/dist/Glutinum.Converter/Reader/Documentation.js +23 -35
- package/dist/Glutinum.Converter/Reader/ExportAssignment.js +103 -36
- package/dist/Glutinum.Converter/Reader/ExportDeclaration.js +21 -36
- package/dist/Glutinum.Converter/Reader/FunctionDeclaration.js +26 -13
- package/dist/Glutinum.Converter/Reader/IndexedAccessType.js +14 -20
- package/dist/Glutinum.Converter/Reader/InterfaceDeclaration.js +45 -2
- package/dist/Glutinum.Converter/Reader/Node.js +8 -11
- package/dist/Glutinum.Converter/Reader/Parameters.js +34 -26
- package/dist/Glutinum.Converter/Reader/TypeNode.js +1988 -1342
- package/dist/Glutinum.Converter/Reader/TypeOperatorNode.js +32 -44
- package/dist/Glutinum.Converter/Reader/TypeQueryNode.js +14 -37
- package/dist/Glutinum.Converter/Reader/TypeScriptReader.js +23 -5
- package/dist/Glutinum.Converter/Reader/Types.js +290 -15
- package/dist/Glutinum.Converter/Reader/UnionTypeNode.js +14 -28
- package/dist/Glutinum.Converter/Reader/Utils.js +325 -25
- package/dist/Glutinum.Converter/Reader/VariableStatement.js +2 -3
- package/dist/Glutinum.Converter/Transform.js +3568 -8456
- package/dist/Glutinum.Converter/Transformer/AnyFunctionOverloads.js +116 -0
- package/dist/Glutinum.Converter/Transformer/CallableProperties.js +454 -0
- package/dist/Glutinum.Converter/Transformer/Comment.js +136 -0
- package/dist/Glutinum.Converter/Transformer/Conditionals.js +1149 -0
- package/dist/Glutinum.Converter/Transformer/Context.js +666 -0
- package/dist/Glutinum.Converter/Transformer/Enum.js +80 -0
- package/dist/Glutinum.Converter/Transformer/Heritage.js +406 -0
- package/dist/Glutinum.Converter/Transformer/KeyOfMaps.js +488 -0
- package/dist/Glutinum.Converter/Transformer/ParamObjectCandidate.js +596 -0
- package/dist/Glutinum.Converter/Transformer/TypeParameters.js +448 -0
- package/dist/Glutinum.Converter/Transformer/UnionOverloads.js +353 -0
- package/dist/Glutinum.Converter/Transformer/Utils.js +341 -0
- package/dist/Glutinum.Converter/TypeScript.Extensions.js +0 -10
- package/dist/Glutinum.Converter/Utils/String.js +14 -3
- package/dist/Program.js +18 -10
- package/package.json +1 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
import { ofArray, iterate } from "../fable_modules/fable-library-js.5.17.2/List.js";
|
|
3
|
-
import { printf, toConsole } from "../fable_modules/fable-library-js.5.17.2/String.js";
|
|
4
2
|
|
|
5
3
|
export function TypeScript_Ts_SyntaxKind__SyntaxKind_get_Name(this$) {
|
|
6
4
|
switch (this$) {
|
|
@@ -727,11 +725,3 @@ export function TypeScript_Ts_SyntaxKind__SyntaxKind_get_Name(this$) {
|
|
|
727
725
|
}
|
|
728
726
|
}
|
|
729
727
|
|
|
730
|
-
export function TypeScript_Ts_TypeFlags__TypeFlags_Debug(this$) {
|
|
731
|
-
iterate((tupledArg) => {
|
|
732
|
-
if ((this$ & tupledArg[0]) !== 0) {
|
|
733
|
-
toConsole(printf("%s"))(tupledArg[1]);
|
|
734
|
-
}
|
|
735
|
-
}, ofArray([[1, "Any"], [2, "Unknown"], [32, "String"], [64, "Number"], [256, "Boolean"], [65536, "Enum"], [128, "BigInt"], [1024, "StringLiteral"], [2048, "NumberLiteral"], [8192, "BooleanLiteral"], [32768, "EnumLiteral"], [4096, "BigIntLiteral"], [512, "ESSymbol"], [16384, "UniqueESSymbol"], [16, "Void"], [4, "Undefined"], [8, "Null"], [262144, "Never"], [524288, "TypeParameter"], [1048576, "Object"], [134217728, "Union"], [268435456, "Intersection"], [2097152, "Index"], [33554432, "IndexedAccess"], [67108864, "Conditional"], [16777216, "Substitution"], [131072, "NonPrimitive"], [4194304, "TemplateLiteral"], [8388608, "StringMapping"], [15360, "Literal"], [97292, "Unit"], [80896, "Freshable"], [3072, "StringOrNumberLiteral"], [15868, "PossiblyFalsy"], [12583968, "StringLike"], [67648, "NumberLike"], [4224, "BigIntLike"], [8448, "BooleanLike"], [98304, "EnumLike"], [16896, "ESSymbolLike"], [20, "VoidLike"], [402653184, "UnionOrIntersection"], [403701760, "StructuredType"], [34078720, "TypeVariable"], [117964800, "InstantiableNonPrimitive"], [14680064, "InstantiablePrimitive"], [132644864, "Instantiable"], [536346624, "StructuredOrInstantiable"]]));
|
|
736
|
-
}
|
|
737
|
-
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
import { split, trim, replace as replace_1 } from "../../fable_modules/fable-library-js.5.17.2/String.js";
|
|
3
|
+
import { replace as replace_2 } from "../../fable_modules/fable-library-js.5.17.2/RegExp.js";
|
|
3
4
|
import { ofArray } from "../../fable_modules/fable-library-js.5.17.2/List.js";
|
|
4
5
|
|
|
5
6
|
export function replace(oldValue, newValue, input) {
|
|
@@ -22,11 +23,21 @@ export function capitalizeFirstLetter(text) {
|
|
|
22
23
|
return text[0].toLocaleUpperCase() + text.slice(1, text.length);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* `index.d.ts`, `index.d.mts` and `index.d.cts` without their extension
|
|
28
|
+
*/
|
|
29
|
+
export function withoutDeclarationExtension(fileName) {
|
|
30
|
+
return replace_2(fileName, "\\.d\\.[cm]?ts$", "");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A declaration file written on Windows ends its lines with `\r\n`
|
|
35
|
+
*/
|
|
36
|
+
export function normalizeLineEndings(text) {
|
|
37
|
+
return replace_1(replace_1(text, "\r\n", "\n"), "\r", "\n");
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
export function splitLines(text) {
|
|
30
|
-
return ofArray(split(
|
|
41
|
+
return ofArray(split(normalizeLineEndings(text), ["\n"], undefined, 0));
|
|
31
42
|
}
|
|
32
43
|
|
package/dist/Program.js
CHANGED
|
@@ -6,13 +6,17 @@ import { collect, map, toList } from "./fable_modules/fable-library-js.5.17.2/Se
|
|
|
6
6
|
import { join, concat, split } from "./fable_modules/fable-library-js.5.17.2/String.js";
|
|
7
7
|
import { item, equalsWith } from "./fable_modules/fable-library-js.5.17.2/Array.js";
|
|
8
8
|
import { defaultOf } from "./fable_modules/fable-library-js.5.17.2/Util.js";
|
|
9
|
+
import { defaultArg } from "./fable_modules/fable-library-js.5.17.2/Option.js";
|
|
10
|
+
import { parse } from "./fable_modules/fable-library-js.5.17.2/Int32.js";
|
|
11
|
+
import { defaultMaxOverloads } from "./Glutinum.Converter/Transformer/UnionOverloads.js";
|
|
9
12
|
import { GenerateOptions } from "./Glutinum.Converter/Packages.js";
|
|
10
|
-
import {
|
|
13
|
+
import { generateBindingFileWithOptions, generatePackagesFromDisk } from "./Glutinum.Converter/Generate.js";
|
|
11
14
|
import { exists, length, head, tail, isEmpty, empty } from "./fable_modules/fable-library-js.5.17.2/List.js";
|
|
12
|
-
import { defaultArg } from "./fable_modules/fable-library-js.5.17.2/Option.js";
|
|
13
15
|
import { success, error, info } from "./Glutinum.Converter/Log.js";
|
|
14
16
|
import { program as program_1 } from "commander";
|
|
15
17
|
|
|
18
|
+
const nodeProcess = process;
|
|
19
|
+
|
|
16
20
|
function getVersion() {
|
|
17
21
|
const moduleDir = path.dirname(fileURLToPath(import.meta.url));
|
|
18
22
|
let packageJson;
|
|
@@ -24,6 +28,7 @@ function getVersion() {
|
|
|
24
28
|
const helpText = "\n <input> can be:\n - an installed package name (e.g. chalk, @types/vscode)\n - a path to a package directory (e.g. ./node_modules/chalk)\n - a path to a .d.ts file (e.g. ./node_modules/chalk/source/index.d.ts)\n\n Several packages are generated in the same file, each one with every\n package it depends on. A .d.ts file is generated alone.\n\n The types of @types/node and @types/web (the DOM) are referenced from the\n Glutinum.Node and Glutinum.Web bindings, unless asked for or --no-externals.\n\nExamples:\n glutinum chalk --out-file ./Glutinum.Chalk.fs\n glutinum vscode vscode-languageclient --out-file ./Glutinum.Vscode.fs\n glutinum leaflet --external @types/geojson --out-file ./Glutinum.Leaflet.fs\n glutinum --all --out-file ./Glutinum.fs\n glutinum ./node_modules/my-lib/index.d.ts\n";
|
|
25
29
|
|
|
26
30
|
function toGenerateOptions(options) {
|
|
31
|
+
let option_2;
|
|
27
32
|
const externals = toList(map((value) => {
|
|
28
33
|
const matchValue = split(value, ["="], undefined, 0);
|
|
29
34
|
if (!equalsWith((x, y) => (x === y), matchValue, defaultOf()) && (matchValue.length === 2)) {
|
|
@@ -34,7 +39,10 @@ function toGenerateOptions(options) {
|
|
|
34
39
|
}
|
|
35
40
|
}, options.external));
|
|
36
41
|
const includes = toList(collect((value_1) => split(value_1, [","], undefined, 0), options.include));
|
|
37
|
-
|
|
42
|
+
const ExternalPackages = options.externals;
|
|
43
|
+
const ModuleName = options.moduleName;
|
|
44
|
+
const NoLib = !options.lib;
|
|
45
|
+
return new GenerateOptions(ExternalPackages, externals, ModuleName, defaultArg(options.global, false), defaultArg((option_2 = options.maxOverloads, (option_2 != null) ? parse(option_2, 511, false, 32) : undefined), defaultMaxOverloads), includes, NoLib);
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
function generate(options, isAll, inputs) {
|
|
@@ -66,7 +74,7 @@ function generate(options, isAll, inputs) {
|
|
|
66
74
|
case 0:
|
|
67
75
|
return generatePackagesFromDisk(options, empty());
|
|
68
76
|
case 1:
|
|
69
|
-
return
|
|
77
|
+
return generateBindingFileWithOptions(defaultArg(options.ModuleName, "Glutinum"), options.GlobalScript, options.MaxOverloads, input_1);
|
|
70
78
|
default:
|
|
71
79
|
return generatePackagesFromDisk(options, inputs_1);
|
|
72
80
|
}
|
|
@@ -74,14 +82,14 @@ function generate(options, isAll, inputs) {
|
|
|
74
82
|
|
|
75
83
|
function write(outFile, content) {
|
|
76
84
|
if (outFile == null) {
|
|
77
|
-
const stdout =
|
|
85
|
+
const stdout = nodeProcess.stdout;
|
|
78
86
|
stdout.write(content, "utf8");
|
|
79
87
|
}
|
|
80
88
|
else {
|
|
81
89
|
const outFile_1 = outFile;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
mkdirSync(path.dirname(outFile_1), {
|
|
91
|
+
recursive: true,
|
|
92
|
+
});
|
|
85
93
|
writeFileSync(outFile_1, content);
|
|
86
94
|
info(concat("Bindings written to: ", path.resolve(outFile_1)));
|
|
87
95
|
}
|
|
@@ -90,7 +98,7 @@ function write(outFile, content) {
|
|
|
90
98
|
function run(argv) {
|
|
91
99
|
const program = program_1;
|
|
92
100
|
program.name("glutinum").description("Generate Fable bindings from TypeScript definitions - https://github.com/glutinum-org/cli").version(getVersion());
|
|
93
|
-
program.argument("[inputs...]", "packages, a package directory, or a .d.ts file to generate").option("--out-file <path>", "destination file to write in, stdout otherwise").option("--all", "generate every package installed in the nearest node_modules").option("--module-name <name>", "full name of the generated module, instead of `Glutinum.<Module>`").option("--no-externals", "generate @types/node and @types/web instead of referencing them").option("--no-lib", "create the program without the TypeScript library");
|
|
101
|
+
program.argument("[inputs...]", "packages, a package directory, or a .d.ts file to generate").option("--out-file <path>", "destination file to write in, stdout otherwise").option("--all", "generate every package installed in the nearest node_modules").option("--module-name <name>", "full name of the generated module, instead of `Glutinum.<Module>`").option("--no-externals", "generate @types/node and @types/web instead of referencing them").option("--no-lib", "create the program without the TypeScript library").option("--global", "the .d.ts declares the globals of a script, nothing is imported").option("--max-overloads <count>", "overloads a signature gets at most from its union parameters, 16 by default");
|
|
94
102
|
program.option("--external <package>", "reference <package> from its own binding, as <package> or <package>=<Module>", (value_3, previous_1) => {
|
|
95
103
|
void (previous_1.push(value_3));
|
|
96
104
|
return previous_1;
|
|
@@ -139,7 +147,7 @@ function run(argv) {
|
|
|
139
147
|
|
|
140
148
|
(function (argv) {
|
|
141
149
|
const exitCode = run(argv) | 0;
|
|
142
|
-
|
|
150
|
+
nodeProcess.exitCode = exitCode;
|
|
143
151
|
return exitCode | 0;
|
|
144
152
|
})(typeof process === 'object' ? process.argv.slice(2) : []);
|
|
145
153
|
|