mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-12-25 11:48:21 +01:00
enable downlevelIteration build option in typescript
This commit is contained in:
parent
2fc1a8cee4
commit
1d55e82259
File diff suppressed because one or more lines are too long
@ -1,24 +1,89 @@
|
|||||||
{
|
{
|
||||||
"pkgname": "Antedit",
|
"pkgname": "Antedit",
|
||||||
"app":"Antedit",
|
"app": "Antedit",
|
||||||
"name":"Antos Editor",
|
"name": "Antos Editor",
|
||||||
"description":"Antos text/code editor",
|
"description": "Antos text/code editor",
|
||||||
"info":{
|
"info": {
|
||||||
"author": "Xuan Sang LE",
|
"author": "Xuan Sang LE",
|
||||||
"email": "mrsang@iohub.dev"
|
"email": "mrsang@iohub.dev"
|
||||||
},
|
},
|
||||||
"version":"0.1.8-a",
|
"version": "0.1.8-a",
|
||||||
"category":"Development",
|
"category": "Development",
|
||||||
"iconclass":"bi bi-journal-code",
|
"iconclass": "bi bi-journal-code",
|
||||||
"mimes":[
|
"mimes": [
|
||||||
"text/.*",
|
"text/.*",
|
||||||
"[^/]*/json.*",
|
"[^/]*/json.*",
|
||||||
"[^/]*/.*ml",
|
"[^/]*/.*ml",
|
||||||
"[^/]*/javascript",
|
"[^/]*/javascript",
|
||||||
"dir"
|
"dir"
|
||||||
],
|
],
|
||||||
"dependencies":[
|
"dependencies": [
|
||||||
"MonacoCore@0.23.0-r"
|
"MonacoCore@0.23.0-r"
|
||||||
],
|
],
|
||||||
"locale": {}
|
"locale": {
|
||||||
|
"en_GB": {
|
||||||
|
"Output": "Output",
|
||||||
|
"Close tab": "Close tab",
|
||||||
|
"Close without saving ?": "Close without saving ?",
|
||||||
|
"Unable to open: {0}": "Unable to open: {0}",
|
||||||
|
"Unable to save file: {0}": "Unable to save file: {0}",
|
||||||
|
"Save as": "Save as",
|
||||||
|
"New extension at": "New extension at",
|
||||||
|
"Select extension archive": "Select extension archive",
|
||||||
|
"Current folder is not found": "Current folder is not found",
|
||||||
|
"Select build directory": "Select build directory",
|
||||||
|
"Unable to read meta-data": "Unable to read meta-data",
|
||||||
|
"ExtensionName": "ExtensionName",
|
||||||
|
"Files generated in {0}": "Files generated in {0}",
|
||||||
|
"Unable to build extension:{0}": "Unable to build extension:{0}",
|
||||||
|
"Unable to read meta-data:{0}": "Unable to read meta-data:{0}",
|
||||||
|
"Invalid extension meta-data": "Invalid extension meta-data",
|
||||||
|
"Unable to run extension:{0}": "Unable to run extension:{0}",
|
||||||
|
"Archive created at {0}": "Archive created at {0}",
|
||||||
|
"Unable to read meta-data: {0}": "Unable to read meta-data: {0}",
|
||||||
|
"Extension installed": "Extension installed",
|
||||||
|
"Unable to install extension: {0}": "Unable to install extension: {0}",
|
||||||
|
"Enter URI": "Enter URI",
|
||||||
|
"Please enter extension URI:": "Please enter extension URI:",
|
||||||
|
"Unable to create extension directories: {0}": "Unable to create extension directories: {0}",
|
||||||
|
"New file": "New file",
|
||||||
|
"New folder": "New folder",
|
||||||
|
"Rename": "Rename",
|
||||||
|
"Delete": "Delete",
|
||||||
|
"File name": "File name",
|
||||||
|
"Folder name": "Folder name",
|
||||||
|
"Quit": "Quit",
|
||||||
|
"View": "View",
|
||||||
|
"Toggle bottom bar": "Toggle bottom bar",
|
||||||
|
"Toggle split view": "Toggle split view",
|
||||||
|
"Unable to move file/folder": "Unable to move file/folder",
|
||||||
|
"Editor": "Editor",
|
||||||
|
"Change language mode": "Change language mode",
|
||||||
|
"Select language": "Select language",
|
||||||
|
"Unable to disable split view: Please save changes of modified files on the right panel": "Unable to disable split view: Please save changes of modified files on the right panel",
|
||||||
|
"File": "File",
|
||||||
|
"New": "New",
|
||||||
|
"Open Recent": "Open Recent",
|
||||||
|
"Open": "Open",
|
||||||
|
"Open Folder": "Open Folder",
|
||||||
|
"Save": "Save",
|
||||||
|
"Fail to create: {0}": "Fail to create: {0}",
|
||||||
|
"Fail to rename: {0}": "Fail to rename: {0}",
|
||||||
|
"Fail to delete: {0}": "Fail to delete: {0}",
|
||||||
|
"Open file": "Open file",
|
||||||
|
"Open folder": "Open folder",
|
||||||
|
"Cannot load extension meta data": "Cannot load extension meta data",
|
||||||
|
"unable to load extension: {0}": "unable to load extension: {0}",
|
||||||
|
"Unable to find extension: {0}": "Unable to find extension: {0}",
|
||||||
|
"Unable to find action: {0}": "Unable to find action: {0}",
|
||||||
|
"Unable to preload extension": "Unable to preload extension",
|
||||||
|
"Example action": "Example action",
|
||||||
|
"New Extension": "New Extension",
|
||||||
|
"Build": "Build",
|
||||||
|
"Run": "Run",
|
||||||
|
"Build release": "Build release",
|
||||||
|
"Install extension from file": "Install extension from file",
|
||||||
|
"Install extension from URL": "Install extension from URL"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Binary file not shown.
@ -2,6 +2,7 @@
|
|||||||
AntOSDK: development API for AntOS based applications/projects
|
AntOSDK: development API for AntOS based applications/projects
|
||||||
|
|
||||||
## Change logs
|
## Change logs
|
||||||
|
- 0.0.7: enable typescript downlevelIteration compile option
|
||||||
- 0.0.6: add GUI application for building a JSON build file
|
- 0.0.6: add GUI application for building a JSON build file
|
||||||
- 0.0.5: add API that supports running Linux commands on server
|
- 0.0.5: add API that supports running Linux commands on server
|
||||||
- 0.0.4: support automatic locale generation
|
- 0.0.4: support automatic locale generation
|
@ -91,8 +91,8 @@
|
|||||||
{
|
{
|
||||||
"name": "linux-exec",
|
"name": "linux-exec",
|
||||||
"data": {
|
"data": {
|
||||||
"cmd": "ls -al .",
|
"cmd": "tree .",
|
||||||
"pwd": "home://"
|
"pwd": "home://workspace/antosdk-apps/libantosdk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
AntOSDK: development API for AntOS based applications/projects
|
AntOSDK: development API for AntOS based applications/projects
|
||||||
|
|
||||||
## Change logs
|
## Change logs
|
||||||
|
- 0.0.7: enable typescript downlevelIteration compile option
|
||||||
- 0.0.6: add GUI application for building a JSON build file
|
- 0.0.6: add GUI application for building a JSON build file
|
||||||
- 0.0.5: add API that supports running Linux commands on server
|
- 0.0.5: add API that supports running Linux commands on server
|
||||||
- 0.0.4: support automatic locale generation
|
- 0.0.4: support automatic locale generation
|
70
libantosdk/build/debug/core/linux.worker.js
Normal file
70
libantosdk/build/debug/core/linux.worker.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
class LinuxJob extends AntOSDKBaseJob {
|
||||||
|
constructor(data)
|
||||||
|
{
|
||||||
|
super(data);
|
||||||
|
}
|
||||||
|
execute()
|
||||||
|
{
|
||||||
|
switch (this.job.cmd) {
|
||||||
|
case 'linux-exec':
|
||||||
|
/**
|
||||||
|
* Execute a linux command with the
|
||||||
|
* help of a server side lua API
|
||||||
|
* script
|
||||||
|
*/
|
||||||
|
this.exec();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
const err_msg = `Unkown job ${this.job.cmd}`;
|
||||||
|
this.log_error(err_msg);
|
||||||
|
return this.error(err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exec()
|
||||||
|
{
|
||||||
|
const path = "pkg://libantosdk/core/lua/api.lua".abspath(this.job.root);
|
||||||
|
const url = API.REST.replace("http","ws") + "/system/apigateway?ws=1";
|
||||||
|
try{
|
||||||
|
const socket = new WebSocket(url);
|
||||||
|
socket.onerror = (e)=> {
|
||||||
|
this.log_error(e.toString());
|
||||||
|
this.error(e);
|
||||||
|
socket.close();
|
||||||
|
};
|
||||||
|
socket.onclose = (e) => {
|
||||||
|
this.log_info("Connection closed");
|
||||||
|
this.result("Done");
|
||||||
|
};
|
||||||
|
socket.onopen = (e) => {
|
||||||
|
// send the command
|
||||||
|
const cmd = {
|
||||||
|
path: path,
|
||||||
|
parameters: {
|
||||||
|
action: "exec",
|
||||||
|
args: this.job.data
|
||||||
|
}
|
||||||
|
};
|
||||||
|
socket.send(JSON.stringify(cmd));
|
||||||
|
};
|
||||||
|
socket.onmessage = (e) => {
|
||||||
|
const json = JSON.parse(e.data);
|
||||||
|
if(json.error)
|
||||||
|
{
|
||||||
|
this.log_error(json.error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.log_print(json.result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(error)
|
||||||
|
{
|
||||||
|
this.log_error(error.toString());
|
||||||
|
return this.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
API.jobhandle["linux-exec"] = LinuxJob;
|
31
libantosdk/build/debug/core/lua/api.lua
Normal file
31
libantosdk/build/debug/core/lua/api.lua
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
local args=...
|
||||||
|
|
||||||
|
local result = function(data)
|
||||||
|
return { error = false, result = data }
|
||||||
|
end
|
||||||
|
|
||||||
|
local error = function(msg)
|
||||||
|
return {error = msg, result = false}
|
||||||
|
end
|
||||||
|
|
||||||
|
local handle = {}
|
||||||
|
|
||||||
|
handle.exec = function(data)
|
||||||
|
local cmd = data.cmd
|
||||||
|
if data.pwd then
|
||||||
|
cmd = "cd "..require("vfs").ospath(data.pwd).. " && "..cmd
|
||||||
|
end
|
||||||
|
cmd = cmd.." 2>&1"
|
||||||
|
local pipe = io.popen(cmd)
|
||||||
|
for line in pipe:lines() do
|
||||||
|
echo(JSON.encode(result(line)))
|
||||||
|
end
|
||||||
|
pipe:close()
|
||||||
|
return result("Done: ["..cmd.."]")
|
||||||
|
end
|
||||||
|
|
||||||
|
if args.action and handle[args.action] then
|
||||||
|
return handle[args.action](args.args)
|
||||||
|
else
|
||||||
|
return error("Invalid action parameter")
|
||||||
|
end
|
@ -92,6 +92,7 @@ class TSJob extends AntOSDKBaseJob {
|
|||||||
const program = ts.createProgram(files, {
|
const program = ts.createProgram(files, {
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
"downlevelIteration": true
|
||||||
}, host);
|
}, host);
|
||||||
const result = program.emit();
|
const result = program.emit();
|
||||||
const diagnostics = result.diagnostics.concat((ts.getPreEmitDiagnostics(program)));
|
const diagnostics = result.diagnostics.concat((ts.getPreEmitDiagnostics(program)));
|
||||||
|
32
libantosdk/build/debug/main.css
Normal file
32
libantosdk/build/debug/main.css
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
afx-app-window[data-id = "SDKBuilder"] afx-resizer {
|
||||||
|
border-left: 1px solid #656565;
|
||||||
|
background-color:transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] {
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
user-select: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] pre {
|
||||||
|
margin: 3px;
|
||||||
|
white-space: pre-wrap; /* css-3 */
|
||||||
|
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
|
||||||
|
white-space: -pre-wrap; /* Opera 4-6 */
|
||||||
|
white-space: -o-pre-wrap; /* Opera 7 */
|
||||||
|
word-wrap: break-word; /* Internet Explorer 5.5+ */
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] pre.sdk-log-error {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] pre.sdk-log-warn {
|
||||||
|
color: orange;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] pre.sdk-log-info {
|
||||||
|
color: green;
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
"author": "Xuan Sang LE",
|
"author": "Xuan Sang LE",
|
||||||
"email": "mrsang@iohub.dev"
|
"email": "mrsang@iohub.dev"
|
||||||
},
|
},
|
||||||
"version": "0.0.6-a",
|
"version": "0.0.7-a",
|
||||||
"category": "Development",
|
"category": "Development",
|
||||||
"iconclass": "fa fa-cog",
|
"iconclass": "fa fa-cog",
|
||||||
"mimes": [
|
"mimes": [
|
||||||
|
30
libantosdk/build/debug/scheme.html
Normal file
30
libantosdk/build/debug/scheme.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<afx-app-window apptitle="__(AntOSDK Builder)" width="600" height="500" data-id="SDKBuilder">
|
||||||
|
<afx-hbox>
|
||||||
|
<afx-vbox data-width="150">
|
||||||
|
<div data-height="10"></div>
|
||||||
|
<afx-list-view data-id="target-list"></afx-list-view>
|
||||||
|
<div data-height="5"></div>
|
||||||
|
<afx-hbox data-height="23" style="text-align: left;">
|
||||||
|
<afx-button data-id="btnopen" data-width="25" iconclass ="bi bi-file-arrow-up-fill"></afx-button>
|
||||||
|
<afx-button data-id="btnrefresh" data-width="25" iconclass ="fa fa-refresh"></afx-button>
|
||||||
|
<afx-button data-id="btnbuild" text="__(Run)"></afx-button>
|
||||||
|
<div data-width="5"></div>
|
||||||
|
</afx-hbox>
|
||||||
|
<div data-height="10"></div>
|
||||||
|
</afx-vbox>
|
||||||
|
<afx-resizer data-width="3"></afx-resizer>
|
||||||
|
<afx-vbox data-id="right-pannel">
|
||||||
|
<div data-height="10"></div>
|
||||||
|
<afx-hbox data-id="wrapper">
|
||||||
|
<div data-width="10"></div>
|
||||||
|
<div data-id="container"></div>
|
||||||
|
</afx-hbox>
|
||||||
|
<div data-height="5"></div>
|
||||||
|
<afx-hbox data-height="23" style="text-align: right;">
|
||||||
|
<afx-button data-id="btnclear" iconclass="fa fa-trash" text="__(Clear log)"></afx-button>
|
||||||
|
<div data-width="5"></div>
|
||||||
|
</afx-hbox>
|
||||||
|
<div data-height="10"></div>
|
||||||
|
</afx-vbox>
|
||||||
|
</afx-hbox>
|
||||||
|
</afx-app-window>
|
Binary file not shown.
70
libantosdk/core/linux.worker.js
Normal file
70
libantosdk/core/linux.worker.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
class LinuxJob extends AntOSDKBaseJob {
|
||||||
|
constructor(data)
|
||||||
|
{
|
||||||
|
super(data);
|
||||||
|
}
|
||||||
|
execute()
|
||||||
|
{
|
||||||
|
switch (this.job.cmd) {
|
||||||
|
case 'linux-exec':
|
||||||
|
/**
|
||||||
|
* Execute a linux command with the
|
||||||
|
* help of a server side lua API
|
||||||
|
* script
|
||||||
|
*/
|
||||||
|
this.exec();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
const err_msg = `Unkown job ${this.job.cmd}`;
|
||||||
|
this.log_error(err_msg);
|
||||||
|
return this.error(err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exec()
|
||||||
|
{
|
||||||
|
const path = "pkg://libantosdk/core/lua/api.lua".abspath(this.job.root);
|
||||||
|
const url = API.REST.replace("http","ws") + "/system/apigateway?ws=1";
|
||||||
|
try{
|
||||||
|
const socket = new WebSocket(url);
|
||||||
|
socket.onerror = (e)=> {
|
||||||
|
this.log_error(e.toString());
|
||||||
|
this.error(e);
|
||||||
|
socket.close();
|
||||||
|
};
|
||||||
|
socket.onclose = (e) => {
|
||||||
|
this.log_info("Connection closed");
|
||||||
|
this.result("Done");
|
||||||
|
};
|
||||||
|
socket.onopen = (e) => {
|
||||||
|
// send the command
|
||||||
|
const cmd = {
|
||||||
|
path: path,
|
||||||
|
parameters: {
|
||||||
|
action: "exec",
|
||||||
|
args: this.job.data
|
||||||
|
}
|
||||||
|
};
|
||||||
|
socket.send(JSON.stringify(cmd));
|
||||||
|
};
|
||||||
|
socket.onmessage = (e) => {
|
||||||
|
const json = JSON.parse(e.data);
|
||||||
|
if(json.error)
|
||||||
|
{
|
||||||
|
this.log_error(json.error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.log_print(json.result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(error)
|
||||||
|
{
|
||||||
|
this.log_error(error.toString());
|
||||||
|
return this.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
API.jobhandle["linux-exec"] = LinuxJob;
|
31
libantosdk/core/lua/api.lua
Normal file
31
libantosdk/core/lua/api.lua
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
local args=...
|
||||||
|
|
||||||
|
local result = function(data)
|
||||||
|
return { error = false, result = data }
|
||||||
|
end
|
||||||
|
|
||||||
|
local error = function(msg)
|
||||||
|
return {error = msg, result = false}
|
||||||
|
end
|
||||||
|
|
||||||
|
local handle = {}
|
||||||
|
|
||||||
|
handle.exec = function(data)
|
||||||
|
local cmd = data.cmd
|
||||||
|
if data.pwd then
|
||||||
|
cmd = "cd "..require("vfs").ospath(data.pwd).. " && "..cmd
|
||||||
|
end
|
||||||
|
cmd = cmd.." 2>&1"
|
||||||
|
local pipe = io.popen(cmd)
|
||||||
|
for line in pipe:lines() do
|
||||||
|
echo(JSON.encode(result(line)))
|
||||||
|
end
|
||||||
|
pipe:close()
|
||||||
|
return result("Done: ["..cmd.."]")
|
||||||
|
end
|
||||||
|
|
||||||
|
if args.action and handle[args.action] then
|
||||||
|
return handle[args.action](args.args)
|
||||||
|
else
|
||||||
|
return error("Invalid action parameter")
|
||||||
|
end
|
@ -92,6 +92,7 @@ class TSJob extends AntOSDKBaseJob {
|
|||||||
const program = ts.createProgram(files, {
|
const program = ts.createProgram(files, {
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
|
"downlevelIteration": true
|
||||||
}, host);
|
}, host);
|
||||||
const result = program.emit();
|
const result = program.emit();
|
||||||
const diagnostics = result.diagnostics.concat((ts.getPreEmitDiagnostics(program)));
|
const diagnostics = result.diagnostics.concat((ts.getPreEmitDiagnostics(program)));
|
||||||
|
32
libantosdk/main.css
Normal file
32
libantosdk/main.css
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
afx-app-window[data-id = "SDKBuilder"] afx-resizer {
|
||||||
|
border-left: 1px solid #656565;
|
||||||
|
background-color:transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] {
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
user-select: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] pre {
|
||||||
|
margin: 3px;
|
||||||
|
white-space: pre-wrap; /* css-3 */
|
||||||
|
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
|
||||||
|
white-space: -pre-wrap; /* Opera 4-6 */
|
||||||
|
white-space: -o-pre-wrap; /* Opera 7 */
|
||||||
|
word-wrap: break-word; /* Internet Explorer 5.5+ */
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] pre.sdk-log-error {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] pre.sdk-log-warn {
|
||||||
|
color: orange;
|
||||||
|
}
|
||||||
|
|
||||||
|
afx-app-window[data-id = "SDKBuilder"] div[data-id="container"] pre.sdk-log-info {
|
||||||
|
color: green;
|
||||||
|
}
|
@ -7,7 +7,7 @@
|
|||||||
"author": "Xuan Sang LE",
|
"author": "Xuan Sang LE",
|
||||||
"email": "mrsang@iohub.dev"
|
"email": "mrsang@iohub.dev"
|
||||||
},
|
},
|
||||||
"version": "0.0.6-a",
|
"version": "0.0.7-a",
|
||||||
"category": "Development",
|
"category": "Development",
|
||||||
"iconclass": "fa fa-cog",
|
"iconclass": "fa fa-cog",
|
||||||
"mimes": [
|
"mimes": [
|
||||||
|
213
libantosdk/ts/app.ts
Normal file
213
libantosdk/ts/app.ts
Normal file
@ -0,0 +1,213 @@
|
|||||||
|
namespace OS {
|
||||||
|
declare var $: any;
|
||||||
|
export namespace application {
|
||||||
|
class Logger {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Referent to the log container
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @type {HTMLElement}
|
||||||
|
* @memberof Logger
|
||||||
|
*/
|
||||||
|
private target: HTMLElement;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of Logger.
|
||||||
|
* @param {HTMLElement} el target container
|
||||||
|
* @memberof Logger
|
||||||
|
*/
|
||||||
|
constructor(el: HTMLElement) {
|
||||||
|
this.target = el;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log level info
|
||||||
|
*
|
||||||
|
* @param {string|FormattedString} s
|
||||||
|
* @memberof Logger
|
||||||
|
*/
|
||||||
|
info(s: string | FormattedString): void {
|
||||||
|
this.log("info", s, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log level warning
|
||||||
|
*
|
||||||
|
* @param {string|FormattedString} s
|
||||||
|
* @memberof Logger
|
||||||
|
*/
|
||||||
|
warn(s: string | FormattedString): void {
|
||||||
|
this.log("warn", s, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log level error
|
||||||
|
*
|
||||||
|
* @param {string|FormattedString} s
|
||||||
|
* @memberof Logger
|
||||||
|
*/
|
||||||
|
error(s: string | FormattedString): void {
|
||||||
|
this.log("error", s, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a string to target container
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} c class name of the appended log element
|
||||||
|
* @param {string|FormattedString} s log string
|
||||||
|
* @param {boolean} showtime define whether the logger should insert datetime prefix
|
||||||
|
* in the log string
|
||||||
|
* @memberof Logger
|
||||||
|
*/
|
||||||
|
private log(c: string, s: string | FormattedString, showtime: boolean): void {
|
||||||
|
let el = $("<pre></pre>")
|
||||||
|
.attr("class", `sdk-log-${c}`);
|
||||||
|
if (showtime) {
|
||||||
|
let date = new Date();
|
||||||
|
let prefix = date.getDate() + "/"
|
||||||
|
+ (date.getMonth() + 1) + "/"
|
||||||
|
+ date.getFullYear() + " "
|
||||||
|
+ date.getHours() + ":"
|
||||||
|
+ date.getMinutes() + ":"
|
||||||
|
+ date.getSeconds();
|
||||||
|
el.text(`[${prefix}]: ${s.__()}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
el.text(s.__());
|
||||||
|
}
|
||||||
|
$(this.target).append(el);
|
||||||
|
$(this.target).scrollTop($(this.target)[0].scrollHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a log message without prefix
|
||||||
|
*
|
||||||
|
* @param {string|FormattedString} s text to print
|
||||||
|
* @memberof Logger
|
||||||
|
*/
|
||||||
|
print(s: string | FormattedString): void {
|
||||||
|
if(s.match(/warn/i))
|
||||||
|
{
|
||||||
|
this.log("warn", s, false);
|
||||||
|
}
|
||||||
|
else if(s.match(/error/i))
|
||||||
|
{
|
||||||
|
this.log("error", s, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.log("info", s, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty the log container
|
||||||
|
*
|
||||||
|
* @memberof Logger
|
||||||
|
*/
|
||||||
|
clear(): void {
|
||||||
|
$(this.target).empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @class libantosdk
|
||||||
|
* @extends {BaseApplication}
|
||||||
|
*/
|
||||||
|
export class libantosdk extends BaseApplication {
|
||||||
|
private sdk: API.AntOSDKBuilder;
|
||||||
|
private logger: Logger;
|
||||||
|
private filehandle: OS.API.VFS.BaseFileHandle;
|
||||||
|
private options: GenericObject<any>;
|
||||||
|
private targets: OS.GUI.tag.ListViewTag;
|
||||||
|
constructor(args: AppArgumentsType[]) {
|
||||||
|
super("libantosdk", args);
|
||||||
|
}
|
||||||
|
main(): void {
|
||||||
|
this.logger = new Logger(this.find("container"));
|
||||||
|
this.sdk = new API.AntOSDKBuilder(this.logger,"");
|
||||||
|
this.filehandle = undefined;
|
||||||
|
this.options = undefined;
|
||||||
|
this.targets = this.find("target-list") as OS.GUI.tag.ListViewTag;
|
||||||
|
if(this.args && this.args.length > 0)
|
||||||
|
this.filehandle = this.args[0].path.asFileHandle();
|
||||||
|
|
||||||
|
(this.find("btnbuild") as GUI.tag.ButtonTag).onbtclick = (e) => {
|
||||||
|
const selected = this.targets.selectedItem;
|
||||||
|
if(!selected)
|
||||||
|
return;
|
||||||
|
this.load(this.compile([selected.data.text]));
|
||||||
|
}
|
||||||
|
|
||||||
|
(this.find("btnclear") as GUI.tag.ButtonTag).onbtclick = (e) => {
|
||||||
|
this.logger.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
(this.find("btnrefresh") as GUI.tag.ButtonTag).onbtclick = (e) => {
|
||||||
|
this.open();
|
||||||
|
}
|
||||||
|
(this.find("btnopen") as GUI.tag.ButtonTag).onbtclick = async (e) => {
|
||||||
|
try{
|
||||||
|
const d = await this.openDialog("FileDialog", {
|
||||||
|
title: __("Select build file"),
|
||||||
|
mimes: this.meta().mimes
|
||||||
|
});
|
||||||
|
this.filehandle = d.file.path.asFileHandle();
|
||||||
|
this.open();
|
||||||
|
}
|
||||||
|
catch(error)
|
||||||
|
{
|
||||||
|
this.logger.error(error.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private open(): void {
|
||||||
|
if(this.filehandle === undefined)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.filehandle
|
||||||
|
.read("json")
|
||||||
|
.then((data) => {
|
||||||
|
if(! data.targets)
|
||||||
|
{
|
||||||
|
return this.logger.error(
|
||||||
|
__("Invalid build file: {0}", this.filehandle.path)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const targets = Object.keys(data.targets).map(e =>{
|
||||||
|
return {text: e};
|
||||||
|
} );
|
||||||
|
(this.scheme as GUI.tag.WindowTag).apptitle = this.filehandle.path;
|
||||||
|
this.options = data;
|
||||||
|
this.options.root = this.filehandle.parent().path;
|
||||||
|
this.targets.data = targets;
|
||||||
|
this.logger.info(__("Loaded: {0}", this.filehandle.path));
|
||||||
|
})
|
||||||
|
.catch((e) => this.logger.error(
|
||||||
|
__("Unable to load build file: {0}: {1}", this.filehandle.path, e.toString())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private compile(stages: string[]): Promise<string> {
|
||||||
|
return new Promise( async (resolve, reject) => {
|
||||||
|
try {
|
||||||
|
this.logger.clear();
|
||||||
|
await this.sdk.batch(stages,this.options);
|
||||||
|
resolve("OK");
|
||||||
|
}
|
||||||
|
catch(e)
|
||||||
|
{
|
||||||
|
reject(__e(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -195,7 +195,7 @@
|
|||||||
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/libantosdk/README.md",
|
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/libantosdk/README.md",
|
||||||
"category": "Development",
|
"category": "Development",
|
||||||
"author": "Xuan Sang LE",
|
"author": "Xuan Sang LE",
|
||||||
"version": "0.0.6-a",
|
"version": "0.0.7-a",
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/libantosdk/build/release/libantosdk.zip"
|
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/libantosdk/build/release/libantosdk.zip"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user