var OS;!function(t){let e;!function(e){class i{constructor(e){this.worker=new Worker(e.asFileHandle().getlink()),this.jobs={},this.worker.onmessage=t=>{let e=t.data,i=this.jobs[e.id];i?"log"===e.type?i.logger&&(e.error?i.logger.error(e.result):!1===e.show_time&&i.logger.print?i.logger.print(e.result):i.logger.info(e.result)):(i.callback(e),delete this.jobs[e.id]):console.log("Unable to identify result of job",e.id,e)};const i={};for(const e in t.setting.system.packages){const r=t.setting.system.packages[e];i[e]={path:r.path,name:r.pkgname}}this.submit("sdk-setup",{REST:t.API.REST,pkgs:i})}newJobID(){return"job_"+Math.random().toString(36).replace(".","")}exectue_job(t,e,i,r,o){const s=this.newJobID(),a={id:s,cmd:t,data:e,root:i};this.jobs[s]={callback:r,logger:o},this.worker.postMessage(a)}submit(t,e,i,r){return new Promise((o,s)=>{this.exectue_job(t,e,i,t=>{if(t.error)return s(t.error);o(t.result)},r)})}terminate(){this.worker.terminate()}}class r{constructor(t,e){this.root=e,this.logger=t,r.worker||(r.worker=new i("pkg://libantosdk/core/worker.js"))}require(t){return this.run("sdk-import",t.map(t=>t+".worker.js"))}compile(t,e){return new Promise(async(i,r)=>{try{await this.require([t]),i(await this.run(t+"-compile",e))}catch(t){r(__e(t))}})}run(e,i){return"sdk-run-app"===e?new Promise(async(e,r)=>{try{let r=i;1==r.split("://").length&&(r=`${this.root}/${i}`);const o=await(r+"/package.json").asFileHandle().read("json");return o.text=o.name,o.path=r,o.filename=o.pkgname,o.type="app",o.mime="antos/app",o.icon&&(o.icon=`${o.path}/${o.icon}`),o.iconclass||o.icon||(o.iconclass="fa fa-adn"),this.logger.info(__("Installing...")),t.setting.system.packages[o.pkgname]=o,o.app?(this.logger.info(__("Running {0}...",o.app)),t.GUI.forceLaunch(o.app,[])):this.logger.error(__("{0} is not an application",o.pkgname)),e(void 0)}catch(t){r(t)}}):"batch"===e?new Promise(async(t,e)=>{try{if(!i||!i.target){const t=__("No target provided for job: batch");throw this.logger.error(t),new Error(t.__())}let e=i.pwd;e||(e=this.root);const o=await e.asFileHandle().read();if(o.error)throw this.logger.error(o.error),new Error(o.error);let s=o.result.filter(t=>"dir"===t.type);i.modules&&(s=s.filter(t=>i.modules.includes(t.filename)));for(let t of s){const e=(t.path+"/build.json").asFileHandle();try{await e.onready()}catch(e){this.logger.info(__("No build.json file found in {0}, ignore this file",t.path));continue}this.logger.info(__("########### BUILDING: {0} ###########",t.path));const o=new r(this.logger,t.path),s=await e.read("json");s.root||(s.root=t.path),await o.batch([i.target],s)}return this.logger.info(__("########### Batch building done ###########")),t(void 0)}catch(t){e(t)}}):r.worker.submit(e,i,this.root,this.logger)}batch(t,e){return e.root&&(this.root=e.root),new Promise(async(i,r)=>{try{e.targets||r("No target found");for(const i of t){const t=e.targets[i];if(!t)return r(__("No target: {0}",i));if(t.depend&&await this.batch(t.depend,e),t.require&&await this.require(t.require),this.logger&&this.logger.info(__("### RUNNING STAGE: {0}###",i).__()),t.jobs)for(const e of t.jobs)await this.run(e.name,e.data)}i(void 0)}catch(t){r(t)}})}}let o;e.AntOSDKBuilder=r,function(t){class e extends t.RemoteFileHandle{constructor(t){super(t);const e="pkg://libantosdk/"+this.genealogy.join("/");this.setPath(e.asFileHandle().path)}}t.SDKFileHandle=e,t.register("^sdk$",e)}(o=e.VFS||(e.VFS={}))}(e=t.API||(t.API={}))}(OS||(OS={})),function(t){let e;!function(e){class i{constructor(t){this.target=t}info(t){this.log("info",t,!0)}warn(t){this.log("warn",t,!0)}error(t){this.log("error",t,!0)}log(t,e,i){let r=$("
").attr("class","sdk-log-"+t);if(i){let t=new Date,i=t.getDate()+"/"+(t.getMonth()+1)+"/"+t.getFullYear()+" "+t.getHours()+":"+t.getMinutes()+":"+t.getSeconds();r.text(`[${i}]: ${e.__()}`)}else r.text(e.__());$(this.target).append(r),$(this.target).scrollTop($(this.target)[0].scrollHeight)}print(t){t.match(/warn/i)?this.log("warn",t,!1):t.match(/error/i)?this.log("error",t,!1):this.log("info",t,!1)}clear(){$(this.target).empty()}}class r extends e.BaseApplication{constructor(t){super("SDKBuilder",t)}main(){this.logger=new i(this.find("container")),this.sdk=new t.API.AntOSDKBuilder(this.logger,""),this.filehandle=void 0,this.options=void 0,this.targets=this.find("target-list"),this.args&&this.args.length>0&&(this.filehandle=this.args[0].path.asFileHandle()),this.find("btnbuild").onbtclick=t=>{const e=this.targets.selectedItem;e&&this.load(this.compile([e.data.text])).catch(t=>this.logger.error(__(t.stack)))},this.find("btnclear").onbtclick=t=>{this.logger.clear()},this.find("btnrefresh").onbtclick=t=>{this.open()},this.find("btnopen").onbtclick=async t=>{try{const t=await this.openDialog("FileDialog",{title:__("Select build file"),mimes:this.meta().mimes});this.filehandle=t.file.path.asFileHandle(),this.open()}catch(t){this.logger.error(t.toString())}},this.open()}open(){void 0!==this.filehandle&&this.filehandle.read("json").then(t=>{if(!t.targets)return this.logger.error(__("Invalid build file: {0}",this.filehandle.path));const e=Object.keys(t.targets).map(t=>({text:t}));this.scheme.apptitle=this.filehandle.path,this.options=t,this.options.root=this.filehandle.parent().path,this.targets.data=e,this.logger.info(__("Loaded: {0}",this.filehandle.path))}).catch(t=>this.logger.error(__("Unable to load build file: {0}: {1}",this.filehandle.path,t.toString())))}compile(t){return new Promise(async(e,i)=>{try{this.logger.clear(),await this.sdk.batch(t,this.options),e("OK")}catch(t){i(__e(t))}})}}e.SDKBuilder=r}(e=t.application||(t.application={}))}(OS||(OS={}));