diff --git a/.gitignore b/.gitignore index 42afbf6..0769628 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,6 @@ test/fixtures/*/project *.zip .vscode lib/app-plugin -*.d.ts \ No newline at end of file +*.d.ts +.lcui +build \ No newline at end of file diff --git a/test/basic.test.js b/test/basic.test.js index 9678771..2fe974d 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -1,7 +1,7 @@ -const fs from 'fs-extra'); -const path from 'path'); -const assert from 'assert'); -const { execSync } from 'child_process'); +const fs = require('fs-extra'); +const path = require('path'); +const assert = require('assert'); +const { execSync } = require('child_process'); describe('basic', () => { const cwd = path.resolve(__dirname, 'fixtures', 'basic'); diff --git a/test/fixtures/resource/.gitignore b/test/fixtures/resource/.gitignore deleted file mode 100644 index d66efff..0000000 --- a/test/fixtures/resource/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store diff --git a/test/fixtures/resource/src/main.c b/test/fixtures/resource/src/main.c deleted file mode 100644 index 9ae5805..0000000 --- a/test/fixtures/resource/src/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - printf("hello world!\n"); - return 0; -} diff --git a/test/fixtures/resource/src/ui/home.c b/test/fixtures/resource/src/ui/home.c deleted file mode 100644 index 65d2626..0000000 --- a/test/fixtures/resource/src/ui/home.c +++ /dev/null @@ -1 +0,0 @@ -#include "home.xml.h" diff --git a/test/fixtures/resource/src/ui/home.css b/test/fixtures/resource/src/ui/home.css deleted file mode 100644 index 9c4971f..0000000 --- a/test/fixtures/resource/src/ui/home.css +++ /dev/null @@ -1,9 +0,0 @@ -root { - background-color: #f6f8fa; -} - -.feedback { - color: #28a745; - font-size: 12px; - margin-top: 5px; -} diff --git a/test/fixtures/resource/src/ui/home.css.h b/test/fixtures/resource/src/ui/home.css.h deleted file mode 100644 index 38f74a6..0000000 --- a/test/fixtures/resource/src/ui/home.css.h +++ /dev/null @@ -1,12 +0,0 @@ -static const char *css_str_0 = "\ -root {\ - background-color: #f6f8fa;\ -}\ -\ -.feedback {\ - color: #28a745;\ - font-size: 12px;\ - margin-top: 5px;\ -}\ -\ -"; diff --git a/test/fixtures/resource/src/ui/home.js b/test/fixtures/resource/src/ui/home.js deleted file mode 100644 index 7661dc8..0000000 --- a/test/fixtures/resource/src/ui/home.js +++ /dev/null @@ -1,42 +0,0 @@ -module.exports = { - name: "lcui-app", - children: [ - { - name: "resource", - attributes: { type: "text/css", src: "home.css" }, - }, - { - name: "resource", - attributes: { - type: "application/font-ttf", - src: "iconfont.ttf", - }, - }, - { - name: "ui", - children: [ - { - name: "text", - children: [{ type: "text", text: "Enter a message and save it." }], - }, - { - name: "textedit", - attributes: { - ref: "input-message", - placeholder: "eg: hello, world!", - }, - }, - { - name: "button", - attributes: { ref: "btn-save-message" }, - children: [{ type: "text", text: "Save" }], - }, - { - name: "text", - attributes: { ref: "feedback", class: "feedback" }, - children: [{ type: "text", text: "Message has been saved!" }], - }, - ], - }, - ], -}; diff --git a/test/fixtures/resource/src/ui/home.js.h b/test/fixtures/resource/src/ui/home.js.h deleted file mode 100644 index 7ddeea1..0000000 --- a/test/fixtures/resource/src/ui/home.js.h +++ /dev/null @@ -1,61 +0,0 @@ -/** This file is generated from home.js */ - -#include - -typedef struct { - ui_widget_t *input_message; - ui_widget_t *btn_save_message; - ui_widget_t *feedback; -} home_refs_t; - -static ui_widget_prototype_t *home_proto; - -static const char *css_str_0 = "\ -root {\ - background-color: #f6f8fa;\ -}\ -\ -.feedback {\ - color: #28a745;\ - font-size: 12px;\ - margin-top: 5px;\ -}\ -\ -"; - - -static void home_init_prototype(void) -{ - home_proto = ui_create_widget_prototype("home", NULL); -} - -static void home_load_template(ui_widget_t *parent, home_refs_t *refs) -{ - ui_widget_t *w[4]; - - w[0] = ui_create_widget("text"); - w[1] = ui_create_widget(NULL); - ui_widget_set_text(w[1], "Enter a message and save it."); - ui_widget_append(w[0], w[1]); - refs->input_message = ui_create_widget("textedit"); - ui_widget_set_attr(refs->input_message, "placeholder", "eg: hello, world!"); - refs->btn_save_message = ui_create_widget("button"); - w[2] = ui_create_widget(NULL); - ui_widget_set_text(w[2], "Save"); - ui_widget_append(refs->btn_save_message, w[2]); - refs->feedback = ui_create_widget("text"); - ui_widget_add_class(refs->feedback, "feedback"); - w[3] = ui_create_widget(NULL); - ui_widget_set_text(w[3], "Message has been saved!"); - ui_widget_append(refs->feedback, w[3]); - ui_widget_append(parent, w[0]); - ui_widget_append(parent, refs->input_message); - ui_widget_append(parent, refs->btn_save_message); - ui_widget_append(parent, refs->feedback); -} - -static void home_load_resources(void) -{ - ui_load_css_string(css_str_0, "home.css"); - pd_font_library_load_file("iconfont.ttf"); -} diff --git a/test/fixtures/resource/src/ui/home.json b/test/fixtures/resource/src/ui/home.json deleted file mode 100644 index 887e8fa..0000000 --- a/test/fixtures/resource/src/ui/home.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "name": "lcui-app", - "children": [ - { - "name": "resource", - "attributes": { "type": "text/css", "src": "home.css" } - }, - { - "name": "resource", - "attributes": { - "type": "application/font-ttf", - "src": "iconfont.ttf" - } - }, - { - "name": "ui", - "children": [ - { - "name": "text", - "children": [ - { "type": "text", "text": "Enter a message and save it." } - ] - }, - { - "name": "textedit", - "attributes": { - "ref": "input-message", - "placeholder": "eg: hello, world!" - } - }, - { - "name": "button", - "attributes": { "ref": "btn-save-message" }, - "children": [{ "type": "text", "text": "Save" }] - }, - { - "name": "text", - "attributes": { "ref": "feedback", "class": "feedback" }, - "children": [{ "type": "text", "text": "Message has been saved!" }] - } - ] - } - ] -} diff --git a/test/fixtures/resource/src/ui/home.json.h b/test/fixtures/resource/src/ui/home.json.h deleted file mode 100644 index 0c6e191..0000000 --- a/test/fixtures/resource/src/ui/home.json.h +++ /dev/null @@ -1,61 +0,0 @@ -/** This file is generated from home.json */ - -#include - -typedef struct { - ui_widget_t *input_message; - ui_widget_t *btn_save_message; - ui_widget_t *feedback; -} home_refs_t; - -static ui_widget_prototype_t *home_proto; - -static const char *css_str_1 = "\ -root {\ - background-color: #f6f8fa;\ -}\ -\ -.feedback {\ - color: #28a745;\ - font-size: 12px;\ - margin-top: 5px;\ -}\ -\ -"; - - -static void home_init_prototype(void) -{ - home_proto = ui_create_widget_prototype("home", NULL); -} - -static void home_load_template(ui_widget_t *parent, home_refs_t *refs) -{ - ui_widget_t *w[4]; - - w[0] = ui_create_widget("text"); - w[1] = ui_create_widget(NULL); - ui_widget_set_text(w[1], "Enter a message and save it."); - ui_widget_append(w[0], w[1]); - refs->input_message = ui_create_widget("textedit"); - ui_widget_set_attr(refs->input_message, "placeholder", "eg: hello, world!"); - refs->btn_save_message = ui_create_widget("button"); - w[2] = ui_create_widget(NULL); - ui_widget_set_text(w[2], "Save"); - ui_widget_append(refs->btn_save_message, w[2]); - refs->feedback = ui_create_widget("text"); - ui_widget_add_class(refs->feedback, "feedback"); - w[3] = ui_create_widget(NULL); - ui_widget_set_text(w[3], "Message has been saved!"); - ui_widget_append(refs->feedback, w[3]); - ui_widget_append(parent, w[0]); - ui_widget_append(parent, refs->input_message); - ui_widget_append(parent, refs->btn_save_message); - ui_widget_append(parent, refs->feedback); -} - -static void home_load_resources(void) -{ - ui_load_css_string(css_str_1, "home.css"); - pd_font_library_load_file("iconfont.ttf"); -} diff --git a/test/fixtures/resource/src/ui/home.module.css b/test/fixtures/resource/src/ui/home.module.css deleted file mode 100644 index 788798a..0000000 --- a/test/fixtures/resource/src/ui/home.module.css +++ /dev/null @@ -1,15 +0,0 @@ -:global(.home) { - padding: 20px; -} - -.button { - padding: 5px 10px; - text-align: center; - border: 1px solid #eee; - border-radius: 4px; -} - -.text { - color: #f00; - font-size: 24px; -} diff --git a/test/fixtures/resource/src/ui/home.tsx b/test/fixtures/resource/src/ui/home.tsx deleted file mode 100644 index 7d74506..0000000 --- a/test/fixtures/resource/src/ui/home.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from "react"; -import styles from "./home.module.css"; - -export default function Home() { - return ( -
- Hello, World! - -
- ); -} diff --git a/test/fixtures/resource/src/ui/home.tsx.h b/test/fixtures/resource/src/ui/home.tsx.h deleted file mode 100644 index d442500..0000000 --- a/test/fixtures/resource/src/ui/home.tsx.h +++ /dev/null @@ -1,55 +0,0 @@ -/** This file is generated from home.tsx */ - -#include - -static ui_widget_prototype_t *home_proto; - -/** This css code string is compiled from file home.module.css */ -static const char *css_str_0 = "\ -.home {\ - padding: 20px;\ -}\ -\ -._button_1ayu2_9 {\ - padding: 5px 10px;\ - text-align: center;\ - border: 1px solid #eee;\ - border-radius: 4px;\ -}\ -\ -._text_1ayu2_23 {\ - color: #f00;\ - font-size: 24px;\ -}\ -\ -"; - - -static void home_init_prototype(void) -{ - home_proto = ui_create_widget_prototype("home", NULL); -} - -static void home_load_template(ui_widget_t *parent) -{ - ui_widget_t *w[4]; - - ui_widget_add_class(parent, "home"); - w[0] = ui_create_widget("text"); - ui_widget_add_class(w[0], "_text_1ayu2_23"); - w[1] = ui_create_widget("text"); - ui_widget_set_text(w[1], "Hello, World!"); - ui_widget_append(w[0], w[1]); - w[2] = ui_create_widget("button"); - ui_widget_add_class(w[2], "_button_1ayu2_9"); - w[3] = ui_create_widget("text"); - ui_widget_set_text(w[3], "Ok"); - ui_widget_append(w[2], w[3]); - ui_widget_append(parent, w[0]); - ui_widget_append(parent, w[2]); -} - -static void home_load_resources(void) -{ - ui_load_css_string(css_str_0, "home.tsx"); -} diff --git a/test/fixtures/resource/src/ui/home.xml b/test/fixtures/resource/src/ui/home.xml deleted file mode 100644 index 3f68156..0000000 --- a/test/fixtures/resource/src/ui/home.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - Enter a message and save it. - - - - - diff --git a/test/fixtures/resource/src/ui/home.xml.h b/test/fixtures/resource/src/ui/home.xml.h deleted file mode 100644 index 804948a..0000000 --- a/test/fixtures/resource/src/ui/home.xml.h +++ /dev/null @@ -1,57 +0,0 @@ -/** This file is generated from home.xml */ - -#include - -typedef struct { - ui_widget_t *input_message; - ui_widget_t *btn_save_message; - ui_widget_t *feedback; -} home_refs_t; - -static const char *css_str_0 = "\ -root {\ - background-color: #f6f8fa;\ -}\ -\ -.feedback {\ - color: #28a745;\ - font-size: 12px;\ - margin-top: 5px;\ -}\ -\ -"; - - -static void home_load_template(ui_widget_t *parent, home_refs_t *refs) -{ - ui_widget_t *w[5]; - - w[0] = ui_create_widget(NULL); - w[1] = ui_create_widget("text"); - w[2] = ui_create_widget(NULL); - ui_widget_set_text(w[2], "Enter a message and save it."); - ui_widget_append(w[1], w[2]); - refs->input_message = ui_create_widget("textedit"); - ui_widget_set_attr(refs->input_message, "placeholder", "eg: hello, world!"); - refs->btn_save_message = ui_create_widget("button"); - w[3] = ui_create_widget(NULL); - ui_widget_set_text(w[3], "Save"); - ui_widget_append(refs->btn_save_message, w[3]); - refs->feedback = ui_create_widget("text"); - ui_widget_add_class(refs->feedback, "feedback"); - w[4] = ui_create_widget(NULL); - ui_widget_set_text(w[4], "Message has been saved!"); - ui_widget_append(refs->feedback, w[4]); - ui_widget_append(parent, w[1]); - ui_widget_append(parent, refs->input_message); - ui_widget_append(parent, refs->btn_save_message); - ui_widget_append(parent, refs->feedback); - ui_widget_append(parent, parent); - ui_widget_append(w[0], parent); -} - -static void home_load_resources(void) -{ - ui_load_css_string(css_str_0, "home.css"); - pd_font_library_load_file("iconfont.ttf"); -} diff --git a/test/fixtures/resource/src/ui/home.yml b/test/fixtures/resource/src/ui/home.yml deleted file mode 100644 index 7c2b15c..0000000 --- a/test/fixtures/resource/src/ui/home.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: lcui-app -children: - - name: resource - attributes: - type: text/css - src: home.css - - name: resource - attributes: - type: application/font-ttf - src: iconfont.ttf - - name: ui - children: - - name: text - children: - - type: text - text: Enter a message and save it. - - name: textedit - attributes: - ref: input-message - placeholder: "eg: hello, world!" - - name: button - attributes: - ref: btn-save-message - children: - - type: text - text: Save - - name: text - attributes: - ref: feedback - class: feedback - children: - - type: text - text: Message has been saved! diff --git a/test/fixtures/resource/src/ui/home.yml.h b/test/fixtures/resource/src/ui/home.yml.h deleted file mode 100644 index ddd2a14..0000000 --- a/test/fixtures/resource/src/ui/home.yml.h +++ /dev/null @@ -1,61 +0,0 @@ -/** This file is generated from home.yml */ - -#include - -typedef struct { - ui_widget_t *input_message; - ui_widget_t *btn_save_message; - ui_widget_t *feedback; -} home_refs_t; - -static ui_widget_prototype_t *home_proto; - -static const char *css_str_3 = "\ -root {\ - background-color: #f6f8fa;\ -}\ -\ -.feedback {\ - color: #28a745;\ - font-size: 12px;\ - margin-top: 5px;\ -}\ -\ -"; - - -static void home_init_prototype(void) -{ - home_proto = ui_create_widget_prototype("home", NULL); -} - -static void home_load_template(ui_widget_t *parent, home_refs_t *refs) -{ - ui_widget_t *w[4]; - - w[0] = ui_create_widget("text"); - w[1] = ui_create_widget(NULL); - ui_widget_set_text(w[1], "Enter a message and save it."); - ui_widget_append(w[0], w[1]); - refs->input_message = ui_create_widget("textedit"); - ui_widget_set_attr(refs->input_message, "placeholder", "eg: hello, world!"); - refs->btn_save_message = ui_create_widget("button"); - w[2] = ui_create_widget(NULL); - ui_widget_set_text(w[2], "Save"); - ui_widget_append(refs->btn_save_message, w[2]); - refs->feedback = ui_create_widget("text"); - ui_widget_add_class(refs->feedback, "feedback"); - w[3] = ui_create_widget(NULL); - ui_widget_set_text(w[3], "Message has been saved!"); - ui_widget_append(refs->feedback, w[3]); - ui_widget_append(parent, w[0]); - ui_widget_append(parent, refs->input_message); - ui_widget_append(parent, refs->btn_save_message); - ui_widget_append(parent, refs->feedback); -} - -static void home_load_resources(void) -{ - ui_load_css_string(css_str_3, "home.css"); - pd_font_library_load_file("iconfont.ttf"); -} diff --git a/test/fixtures/resource/xmake.lua b/test/fixtures/resource/xmake.lua deleted file mode 100644 index 1a1c6f4..0000000 --- a/test/fixtures/resource/xmake.lua +++ /dev/null @@ -1,5 +0,0 @@ -add_rules("mode.debug", "mode.release") - -target("app") - set_kind("binary") - add_files("src/**.c") diff --git a/test/fixtures/ts-loader/app.c b/test/fixtures/ts-loader/app.c new file mode 100644 index 0000000..7bd6ca5 --- /dev/null +++ b/test/fixtures/ts-loader/app.c @@ -0,0 +1,87 @@ +#include "app.tsx.h" +#include "app.h" + +typedef struct { + MyButton_react_t base; + // Add additional states to your component here + // ... +} MyButton_t; + +static void MyButton_init(ui_widget_t *w) +{ + ui_widget_add_data(w, MyButton_proto, sizeof(MyButton_t)); + MyButton_react_init(w); + // Write the initialization code for your component here + // such as state initialization, event binding, etc + // ... +} + +static void MyButton_destroy(ui_widget_t *w) +{ + // Write code here to destroy the relevant resources of the component + // ... + + MyButton_react_destroy(w); +} + +void MyButton_update(ui_widget_t *w) +{ + MyButton_react_update(w); + // Write code here to update other content of your component + // ... +} + +ui_widget_t *ui_create_MyButton(void) +{ + return ui_create_widget_with_prototype(MyButton_proto); +} + +void ui_register_MyButton(void) +{ + MyButton_init_prototype(); + MyButton_proto->init = MyButton_init; + MyButton_proto->destroy = MyButton_destroy; +} + + +typedef struct { + App_react_t base; + // Add additional states to your component here + // ... +} App_t; + +static void App_init(ui_widget_t *w) +{ + ui_widget_add_data(w, App_proto, sizeof(App_t)); + App_react_init(w); + // Write the initialization code for your component here + // such as state initialization, event binding, etc + // ... +} + +static void App_destroy(ui_widget_t *w) +{ + // Write code here to destroy the relevant resources of the component + // ... + + App_react_destroy(w); +} + +void App_update(ui_widget_t *w) +{ + App_react_update(w); + // Write code here to update other content of your component + // ... +} + +ui_widget_t *ui_create_App(void) +{ + return ui_create_widget_with_prototype(App_proto); +} + +void ui_register_App(void) +{ + App_init_prototype(); + App_proto->init = App_init; + App_proto->destroy = App_destroy; +} diff --git a/test/fixtures/ts-loader/app.h b/test/fixtures/ts-loader/app.h new file mode 100644 index 0000000..941586c --- /dev/null +++ b/test/fixtures/ts-loader/app.h @@ -0,0 +1,16 @@ +#include + +void ui_register_MyButton(void); + +ui_widget_t *ui_create_MyButton(void); + +void MyButton_update(ui_widget_t *w); + + +void ui_register_App(void); + +ui_widget_t *ui_create_App(void); + +void App_update(ui_widget_t *w); + +void ui_load_App_resources(void); diff --git a/test/fixtures/ts-loader/app.tsx b/test/fixtures/ts-loader/app.tsx new file mode 100644 index 0000000..f782751 --- /dev/null +++ b/test/fixtures/ts-loader/app.tsx @@ -0,0 +1,12 @@ +function MyButton() { + return
Button
; +} + +export default function App() { + return ( +
+ Hello + +
+ ); +} diff --git a/test/fixtures/ts-loader/app.tsx.h b/test/fixtures/ts-loader/app.tsx.h new file mode 100644 index 0000000..a968204 --- /dev/null +++ b/test/fixtures/ts-loader/app.tsx.h @@ -0,0 +1,89 @@ +/** This file is generated from app.tsx */ +#include + +// UTF-8 encoded string from: Button +static const unsigned char widget_text_0[] = {0x42, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0}; +// UTF-8 encoded string from: Hello +static const unsigned char widget_text_1[] = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0}; + +typedef struct App_react_state { + char empty; +} App_react_state_t; + +typedef struct App_react { + App_react_state_t state; +} App_react_t; + +static ui_widget_prototype_t *MyButton_proto; + +static void MyButton_init_prototype(void) +{ + MyButton_proto = ui_create_widget_prototype("MyButton", NULL); +} + +static void MyButton_load_template(ui_widget_t *parent) +{ + ui_widget_t *w[2]; + + ui_widget_set_text(parent, (const char*)widget_text_0); +} + +static void App_react_update(ui_widget_t *w) +{ + App_react_t *_that = ui_widget_get_data(w, App_proto); +} + +static void App_react_init(ui_widget_t *w) +{ + App_react_t *_that = ui_widget_get_data(w, App_proto); + App_load_template(w); +} + +static void App_react_destroy(ui_widget_t *w) +{ +} + +typedef struct App_react_state { + char empty; +} App_react_state_t; + +typedef struct App_react { + App_react_state_t state; +} App_react_t; + +static ui_widget_prototype_t *App_proto; + +static void App_init_prototype(void) +{ + App_proto = ui_create_widget_prototype("App", NULL); +} + +static void App_load_template(ui_widget_t *parent) +{ + ui_widget_t *w[2]; + + w[0] = ui_create_widget("text"); + ui_widget_set_text(w[0], (const char*)widget_text_1); + w[1] = ui_create_widget("MyButton"); + ui_widget_append(parent, w[0]); + ui_widget_append(parent, w[1]); +} + +static void App_react_update(ui_widget_t *w) +{ + App_react_t *_that = ui_widget_get_data(w, App_proto); +} + +static void App_react_init(ui_widget_t *w) +{ + App_react_t *_that = ui_widget_get_data(w, App_proto); + App_load_template(w); +} + +static void App_react_destroy(ui_widget_t *w) +{ +} + +void ui_load_app_resources(void) +{ +} diff --git a/test/fixtures/ts-loader/app/main.c b/test/fixtures/ts-loader/app/main.c new file mode 100644 index 0000000..ef32a7d --- /dev/null +++ b/test/fixtures/ts-loader/app/main.c @@ -0,0 +1,12 @@ +#include "main.h" + +int main(int argc, char *argv[]) +{ + lcui_app_init(); + + // Write code here to initialize your application, + // such as loading configuration files, initializing functional modules + // ... + + return lcui_app_run(); +} diff --git a/test/fixtures/ts-loader/app/main.h b/test/fixtures/ts-loader/app/main.h new file mode 100644 index 0000000..4348744 --- /dev/null +++ b/test/fixtures/ts-loader/app/main.h @@ -0,0 +1,19 @@ +#include +#include +#include + +#include "..\app.h" + +static void lcui_app_init(void) +{ + setlocale(LC_CTYPE, ""); + lcui_init(); + ui_load_App_resources(); + ui_register_App(); +} + +static int lcui_app_run(void) +{ + return lcui_run(); +} + diff --git a/test/fixtures/ts-loader/package.json b/test/fixtures/ts-loader/package.json new file mode 100644 index 0000000..6b3b147 --- /dev/null +++ b/test/fixtures/ts-loader/package.json @@ -0,0 +1,6 @@ +{ + "name": "ts-loader", + "version": "1.0.0", + "main": "index.js", + "license": "MIT" +}