Skip to content

Commit

Permalink
Add package.json for typescript project
Browse files Browse the repository at this point in the history
Add npm command to compile typescript
  • Loading branch information
Geequlim committed Aug 1, 2020
1 parent 23e3d75 commit 68d2f2c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
3 changes: 3 additions & 0 deletions SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ if env['tools']:
with open_file("tools/decorators.ts.gen.cpp", "w") as f:
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::TS_DECORATORS_CONTENT = \n${source};'
f.write(text.replace('${source}', dump_text_file_to_cpp("misc/decorators.ts")))
with open_file("tools/package.json.gen.cpp", "w") as f:
text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString ECMAScriptPlugin::PACKAGE_JSON_CONTENT = \n${source};'
f.write(text.replace('${source}', dump_text_file_to_cpp("misc/package.json")))
env_module.add_source_files(env.modules_sources, 'tools/*.cpp')

env_module.Append(CPPPATH=["#modules/ECMAScript"])
Expand Down
9 changes: 9 additions & 0 deletions misc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"watch": "tsc -w -p .",
"compile": "tsc -p ."
},
"devDependencies": {
"typescript": "^3.9.7"
}
}
29 changes: 14 additions & 15 deletions tools/editor_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ struct ECMAScriptAlphCompare {
}
};

static Error dump_to_file(const String &p_path, const String &p_content) {
FileAccessRef tsconfig = FileAccess::open(p_path, FileAccess::WRITE);
if (tsconfig.f && tsconfig->is_open()) {
tsconfig->store_string(p_content);
tsconfig->close();
return OK;
}
return FAILED;
}

void ECMAScriptPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_menu_item_pressed"), &ECMAScriptPlugin::_on_menu_item_pressed);
ClassDB::bind_method(D_METHOD("_export_typescript_declare_file"), &ECMAScriptPlugin::_export_typescript_declare_file);
Expand Down Expand Up @@ -685,23 +695,12 @@ void ECMAScriptPlugin::_export_enumeration_binding_file(const String &p_path) {
dict["enumerations"] = enumerations;
file_content = applay_partern(file_content, dict);

FileAccessRef f = FileAccess::open(p_path, FileAccess::WRITE);
if (f.f && f->is_open()) {
f->store_string(file_content);
f->close();
}
dump_to_file(p_path, file_content);
}

void ECMAScriptPlugin::_generate_typescript_project() {
_export_typescript_declare_file("res:https://godot.d.ts");
FileAccessRef tsconfig = FileAccess::open("res:https://tsconfig.json", FileAccess::WRITE);
if (tsconfig.f && tsconfig->is_open()) {
tsconfig->store_string(TSCONFIG_CONTENT);
tsconfig->close();
}
FileAccessRef decorators = FileAccess::open("res:https://decorators.ts", FileAccess::WRITE);
if (decorators.f && decorators->is_open()) {
decorators->store_string(TS_DECORATORS_CONTENT);
decorators->close();
}
dump_to_file("res:https://tsconfig.json", TSCONFIG_CONTENT);
dump_to_file("res:https://decorators.ts", TS_DECORATORS_CONTENT);
dump_to_file("res:https://package.json", PACKAGE_JSON_CONTENT);
}
1 change: 1 addition & 0 deletions tools/editor_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ECMAScriptPlugin : public EditorPlugin {
static String BUILTIN_DECLEARATION_TEXT;
static String TSCONFIG_CONTENT;
static String TS_DECORATORS_CONTENT;
static String PACKAGE_JSON_CONTENT;

static void _bind_methods();

Expand Down

0 comments on commit 68d2f2c

Please sign in to comment.