Updated some declaration

canary
WolverinDEV 2020-03-28 13:58:36 +01:00
parent 6ebe771178
commit 5f0c1b303a
24 changed files with 37293 additions and 78 deletions

37115
client/generated/client.js Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,9 @@
#!/usr/bin/env bash
BASEDIR=$(dirname "$0")
# shellcheck disable=SC1090
source "${BASEDIR}/resolve_commands.sh"
cd "$BASEDIR/../"
cd "$BASEDIR/../" || { echo "Failed to enter parent directory!"; exit 1; }
function generate_link() {
if [[ ! -L $2 ]] || [[ "${BASH_ARGV[0]}" == "force" ]]; then
@ -20,12 +21,19 @@ function replace_tribble() {
#Building the generator
./tools/build_dtsgen.sh
if [[ $? -ne 0 ]]; then
echo "Failed to build typescript declaration generator"
./tools/build_dtsgen.sh; _exit_code=$?
if [[ $_exit_code -ne 0 ]]; then
echo "Failed to build typescript declaration generator ($_exit_code)"
exit 1
fi
#Shared
./shared/generate_declarations.sh; _exit_code=$?
[[ $_exit_code -ne 0 ]] && {
echo "Failed to generate shared ($_exit_code)"
}
exit 0
#Easy going: Each "module" has it's exports and imports
#So lets first build the exports and ignore any errors
#Note: For the client we have to use the given file
@ -40,12 +48,6 @@ npm run dtsgen -- --config client/tsconfig/dtsconfig.json -v
replace_tribble client/declarations/exports.d.ts
echo "Generated client declarations"
#Shared
./shared/generate_declarations.sh
[[ $? -ne 0 ]] && {
echo "Failed to generate shared"
}
#replace_tribble shared/declarations/exports.d.ts
echo "Generated shared declarations"

View File

@ -1,21 +1,21 @@
#!/usr/bin/env bash
BASEDIR=$(dirname "$0")
cd "$BASEDIR"
cd "$BASEDIR" || { echo "Failed to enter script base dir"; exit 1; }
source ../scripts/resolve_commands.sh
function generate_declaration() {
echo "Generating declarations for project $1 ($2)"
if [[ -e ${2} ]]; then
rm ${2}
if [[ $? -ne 0 ]]; then
echo "Failed to remove old declaration file ($2)!"
if [[ -e "${2}" ]]; then
rm "${2}"; _exit_code=$?
if [[ $_exit_code -ne 0 ]]; then
echo "Failed to remove old declaration file ($2): $_exit_code!"
echo "This could be critical later!"
fi
fi
npm run dtsgen -- --config $(pwd)/tsconfig/$1 -v
npm run dtsgen -- --config "$(pwd)/tsconfig/$1" -v
if [[ ! -e $2 ]]; then
echo "Failed to generate definitions"
exit 1

View File

@ -1,9 +1,11 @@
{
"source_files": [
"../js/**/*.ts"
"**/*.ts"
],
"exclude": [
"../js/workers/**/*.ts"
"workers/**/*.ts"
],
"target_file": "../declarations/exports_app.d.ts"
}
"base_directory": "shared/js/",
"target_directory": "../declarations/shared-app",
"modular": true
}

View File

@ -39,7 +39,7 @@ function append_modifier<T extends ts.Modifier["kind"]>(modifiers: ts.ModifiersA
const comparator = (a: ts.Modifier, b: ts.Modifier) => sort_oder[a.kind] - sort_oder[b.kind];
return ts.createNodeArray(
[ts.createModifier(target as number), ...(modifiers || [])].map((e, index, array) => {
[ts.createModifier(target as number), ...(modifiers || [])].sort(comparator).map((e, index, array) => {
const range = ts.getCommentRange(e);
if(range.end === -1 && range.pos === -1)
return e;
@ -51,7 +51,7 @@ function append_modifier<T extends ts.Modifier["kind"]>(modifiers: ts.ModifiersA
else
console.warn("Dropping comment on node because first node already has a comment");
return e;
}).sort(comparator),
}),
(modifiers || {hasTrailingComma: false}).hasTrailingComma
);
}
@ -167,6 +167,8 @@ export interface Settings {
log?: {
unhandled_types: boolean;
} | boolean;
module_mode?: boolean;
}
class _Settings implements Settings {
@ -182,7 +184,9 @@ class _Settings implements Settings {
unhandled_types: boolean;
} = {
unhandled_types: false
}
};
module_mode?: boolean;
}
function specify_settings(settings?: Settings) : _Settings {
@ -201,7 +205,8 @@ function specify_settings(settings?: Settings) : _Settings {
result.log = {
unhandled_types: settings.log,
};
if(typeof(settings.module_mode) !== "boolean")
result.module_mode = false;
return result;
}
@ -210,7 +215,13 @@ export function generate(file: ts.SourceFile, settings?: Settings) : ts.Node[]{
const stack = new StackParameters();
const _settings = specify_settings(settings);
stack.push({
flag_class: false,
flag_declare: false,
flag_namespace: _settings.module_mode
});
_generate(_settings, stack, layer, file);
stack.pop();
return layer;
}
@ -235,12 +246,9 @@ generators[SyntaxKind.ModuleBlock] = (settings, stack, node: ts.ModuleBlock) =>
};
generators[SyntaxKind.ModuleDeclaration] = (settings, stack, node: ts.ModuleDeclaration) => {
switch (node.flags) {
case ts.NodeFlags.Namespace:
break;
default:
//throw "flag " + node.flags + " isn't supported yet!"; /* TODO wrap with more info */
}
//if (node.flags & ~(ts.NodeFlags.Namespace | ts.NodeFlags.NestedNamespace | ts.NodeFlags.ExportContext)) {
// throw "Some module declaration flags are not jet supported (flags: " + Object.keys(ts.NodeFlags).filter(e => node.flags & ts.NodeFlags[e]).join(", ") + ")";
//}
stack.push({
@ -425,24 +433,25 @@ generators[SyntaxKind.EnumDeclaration] = (settings, stack, node: ts.EnumDeclarat
return ts.createEnumDeclaration(undefined, append_export(append_declare(node.modifiers, !stack.flag_declare), stack.flag_namespace), node.name, members);
};
generators[SyntaxKind.HeritageClause] = (settings, stack, node: ts.HeritageClause) => {
return undefined;
};
generators[SyntaxKind.HeritageClause] = () => undefined;
/* every variable in a block has no global scope! */
generators[SyntaxKind.Block] = (settings, stack, node: ts.Block) => {
return undefined;
};
generators[SyntaxKind.Block] = () => undefined;
generators[SyntaxKind.IfStatement] = () => undefined;
generators[SyntaxKind.IfStatement] = (settings, stack, node: ts.IfStatement) => {
return undefined;
};
/* Example for an ExpressionStatement would be: Module["text"] = "XXX"; */
generators[SyntaxKind.ExpressionStatement] = () => undefined;
generators[SyntaxKind.SemicolonClassElement] = () => undefined;
/* Example for an ExpressionStatement would be: Modul["text"] = "XXX"; */
generators[SyntaxKind.ExpressionStatement] = (settings, stack, node: ts.ExpressionStatement) => {
return undefined;
};
generators[SyntaxKind.ImportDeclaration] = (settings, stack, node: ts.ImportDeclaration) => {
const specifier = node.moduleSpecifier as ts.StringLiteral;
if(specifier.kind !== SyntaxKind.StringLiteral)
throw "cant handle import declaration with specifier of type " + specifier.kind;
generators[SyntaxKind.SemicolonClassElement] = (settings, stack, node: ts.ExpressionStatement) => {
return undefined;
return ts.createImportDeclaration(
node.decorators,
node.modifiers,
node.importClause,
ts.createStringLiteral(specifier.text + ".d")
);
};

View File

@ -1,40 +1,44 @@
import {readFileSync, writeFileSync, mkdir} from "fs";
import {isArray, isString} from "util";
import {readFileSync, writeFileSync, mkdir, existsSync} from "fs";
import * as ts from "typescript";
import * as decl from "./declarator";
import * as glob from "glob";
import * as path from "path";
import * as mkdirp from "mkdirp";
import {removeSync} from "fs-extra";
let source_files: string[] = [];
let exclude_files: string[] = [];
let target_file: string = "out.d.ts";
let target_directory: string = "out.d/";
let verbose: boolean = false;
let config_file: string = undefined;
let base_path = process.cwd();
let module_mode: boolean = false;
let args = process.argv.slice(2);
while(args.length > 0) {
if(args[0] == "--file") {
if(args[0] === "--file") {
source_files.push(args[1]);
args = args.slice(2);
} else if(args[0] == "--exclude") {
} else if(args[0] === "--exclude") {
exclude_files.push(args[1]);
args = args.slice(2);
} else if(args[0] == "--destination") {
target_file = args[1];
} else if(args[0] === "--destination") {
target_directory = args[1];
args = args.slice(2);
} else if(args[0] == "-v" || args[0] == "--verbose") {
} else if(args[0] === "-v" || args[0] === "--verbose") {
verbose = true;
args = args.slice(1);
} else if(args[0] == "-c" || args[0] == "--config") {
} else if(args[0] === "-c" || args[0] === "--config") {
config_file = args[1];
base_path = path.normalize(path.dirname(config_file));
args = args.slice(2);
} else if(args[0] == "-b" || args[0] == "--base") {
} else if(args[0] === "-b" || args[0] === "--base-directory") {
base_path = args[1];
base_path = path.normalize(base_path);
args = args.slice(2);
} else if(args[0] === "-m" || args[0] === "--module") {
module_mode = true;
args = args.slice(1);
} else {
console.error("Invalid command line option %s", args[0]);
process.exit(1);
@ -49,12 +53,16 @@ if(config_file) {
process.exit(1);
}
if(isArray(json["source_files"]))
if(Array.isArray(json["source_files"]))
source_files.push(...json["source_files"]);
if(isArray(json["exclude"]))
if(Array.isArray(json["exclude"]))
exclude_files.push(...json["exclude"]);
if(isString(json["target_file"]))
target_file = json["target_file"];
if(typeof json["target_directory"] === "string")
target_directory = json["target_directory"];
if(typeof json["base_directory"] === "string")
base_path = json["base_directory"];
if(typeof json["modular"] === "boolean")
module_mode = json["modular"];
}
if(verbose) {
@ -62,15 +70,30 @@ if(verbose) {
console.log("Input files:");
for(const file of source_files)
console.log(" - " + file);
console.log("Target file: " + target_file);
console.log("Target directory: " + target_directory);
}
if(existsSync(target_directory)) {
removeSync(target_directory);
if(existsSync(target_directory)) {
console.error("Failed to remove target directory (%s)", target_directory);
process.exit(1);
}
}
const negate_files: string[] = [].concat.apply([], exclude_files.map(file => glob.sync(base_path + "/" + file))).map(file => path.normalize(file));
let result = "";
source_files.forEach(file => {
glob.sync(base_path + "/" + file).forEach(_file => {
const glob_base = path.normalize(path.join(process.cwd(), base_path));
if(verbose)
console.log("Globbing %s", glob_base);
glob.sync(glob_base + "/" + file).forEach(_file => {
_file = path.normalize(_file);
if(!_file.startsWith(glob_base)) {
/* this should never happen */
console.log("Skipping %s because of unmatching base directory.", _file);
return;
}
for(const n_file of negate_files) {
if(n_file == _file) {
console.log("Skipping %s", _file);
@ -78,6 +101,7 @@ source_files.forEach(file => {
}
}
const relpath = _file.substr(glob_base.length);
let source = ts.createSourceFile(
_file,
readFileSync(_file).toString(),
@ -85,15 +109,17 @@ source_files.forEach(file => {
true
);
console.log("Compile " + _file);
result += "\n/* File: " + _file + " */\n" + decl.print(source, decl.generate(source, {
remove_private: false
console.log("Compile %s (%s)", _file, relpath);
const result = decl.print(source, decl.generate(source, {
remove_private: false,
module_mode: module_mode
}));
let fpath = path.join(base_path, target_directory, relpath);
fpath = fpath.substr(0, fpath.lastIndexOf(".")) + ".d.ts";
mkdirp(path.normalize(path.dirname(fpath)), error => {
if(error) throw error;
writeFileSync(fpath, result);
});
});
});
mkdirp(path.normalize(path.dirname(base_path + "/" + target_file)), error => {
if(error)
throw error;
writeFileSync(base_path + "/" + target_file, result);
});

View File

@ -1,6 +0,0 @@
/* File: /home/wolverindev/TeaSpeak/Web-Client/tools/dtsgen/test/test_07.ts */
declare namespace C { }
declare namespace C {
export function test(arg: string);
}

8
tools/dtsgen/out.d/module_a.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
export declare class TestClass {
public say_hi();
}
export declare function say_hello_a();
export declare namespace X {
export class Y {
}
}

5
tools/dtsgen/out.d/test_01.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
import * as module_a from "./module_a.d";
export declare class C extends module_a.TestClass {
}
export declare const say_a;
export declare function say_b();

8
tools/dtsgen/out.d/test_02.d.ts vendored Normal file
View File

@ -0,0 +1,8 @@
import * as module_a from "./module_a.d";
/* CLASS COMMENT!*/
export declare class C extends module_a.TestClass {
}
/* Say a comment */
export declare const say_a;
/* Say b comment */
export declare function say_b();

View File

@ -0,0 +1,11 @@
export class TestClass {
public say_hi() {}
}
export function say_hello_a() {
}
export namespace X {
export class Y {}
}

View File

@ -0,0 +1,9 @@
import * as module_a from "./module_a";
export class C extends module_a.TestClass {}
export const say_a = module_a.say_hello_a;
export function say_b() {
console.log("B!");
module_a.say_hello_a();
}

View File

@ -0,0 +1,14 @@
/* IMPOTZ COMMENT */
import * as module_a from "./module_a";
/* CLASS COMMENT!*/
export class C extends module_a.TestClass {}
/* Say a comment */
export const say_a = module_a.say_hello_a;
/* Say b comment */
export function say_b() {
console.log("B!");
module_a.say_hello_a();
}

View File

@ -0,0 +1,5 @@
/* File: tools\dtsgen\test_modular\test_01.ts */
import * as module_a from "./module_a";
export declare const say_a;
export declare function say_b();

View File

@ -6,7 +6,11 @@
"sourceMap": true,
"lib": ["es6", "dom", "dom.iterable"],
"removeComments": true, /* we dont really need them within the target files */
"jsx": "react"
"jsx": "react",
"baseUrl": ".",
"paths": {
"*": ["shared/declarations/*"]
}
},
"exclude": [
"node_modules",

View File

@ -1,3 +1,5 @@
import {log, LogCategory} from "shared-app/log";
namespace audio.player {
let _globalContext: AudioContext;
let _global_destination: GainNode;