AntOSDK now can generate release zip of the application

This commit is contained in:
Xuan Sang LE 2018-03-19 23:58:35 +01:00
parent 1e4c134454
commit 0882a6a1f1
2 changed files with 52 additions and 11 deletions

View File

@ -276,6 +276,7 @@ self.OS.API =
f() if f f() if f
else else
console.log l, "Library exist, no need to load" console.log l, "Library exist, no need to load"
f() if f
_courrier.trigger "sharedlibraryloaded", l _courrier.trigger "sharedlibraryloaded", l
requires:(libs, f) -> requires:(libs, f) ->

View File

@ -145,13 +145,11 @@ class AntOSDK extends this.OS.GUI.BaseApplication
@bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save" @bindKey "CTRL-S", () -> me.actionFile "#{me.name}-Save"
@bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas" @bindKey "ALT-W", () -> me.actionFile "#{me.name}-Saveas"
@bindKey "CTRL-R", () -> me.bnR() @bindKey "CTRL-R", () -> me.bnR()
@bindKey "CTRL-B", () -> me.actionBuild "#{me.name}-Build" @bindKey "ALT-B", () -> me.actionBuild "#{me.name}-Build"
@bindKey "ALT-P", () -> me.buildAndRelease()
@openProject @prjfile if @prjfile @openProject @prjfile if @prjfile
@trigger "calibrate" @trigger "calibrate"
@log "ERROR", "This is an error"
@log "WARNING", "This is a warning"
newProject: (f) -> newProject: (f) ->
me = @ me = @
@openDialog "FileDiaLog", (d, n, p) -> @openDialog "FileDiaLog", (d, n, p) ->
@ -164,6 +162,7 @@ class AntOSDK extends this.OS.GUI.BaseApplication
dirs = [ dirs = [
rpath, rpath,
"#{rpath}/build", "#{rpath}/build",
"#{rpath}/release",
"#{rpath}/javascripts", "#{rpath}/javascripts",
"#{rpath}/css", "#{rpath}/css",
"#{rpath}/coffees", "#{rpath}/coffees",
@ -217,7 +216,7 @@ class AntOSDK extends this.OS.GUI.BaseApplication
"css": [], "css": [],
"javascripts": [], "javascripts": [],
"coffees": ["coffees/main.coffee"], "coffees": ["coffees/main.coffee"],
"copies": ["assets/scheme.html", "package.json"] "copies": ["assets/scheme.html", "package.json", "README.md"]
} }
""" """
}, },
@ -427,9 +426,9 @@ class AntOSDK extends this.OS.GUI.BaseApplication
text: "__(Build)", text: "__(Build)",
child: [ child: [
{ text: "__(Build and Run)", dataid: "#{@name}-Run", shortcut: "C-R" }, { text: "__(Build and Run)", dataid: "#{@name}-Run", shortcut: "C-R" },
{ text: "__(Build release)", dataid: "#{@name}-Release", shortcut: "C-P" }, { text: "__(Build release)", dataid: "#{@name}-Release", shortcut: "A-P" },
{ text: "__(Build)", dataid: "#{@name}-Build", shortcut: "C-B" }, { text: "__(Build)", dataid: "#{@name}-Build", shortcut: "A-B" },
{ text: "__(Build Options)", dataid: "#{@name}-Options", shortcut: "A-P" } { text: "__(Build Options)", dataid: "#{@name}-Options", shortcut: "A-C" }
], ],
onmenuselect: (e) -> me.actionBuild e.item.data.dataid onmenuselect: (e) -> me.actionBuild e.item.data.dataid
} }
@ -496,6 +495,8 @@ class AntOSDK extends this.OS.GUI.BaseApplication
when "#{@name}-Build" when "#{@name}-Build"
me.build().then(() ->).catch (ex) -> me.build().then(() ->).catch (ex) ->
me.log "ERROR", ex.toString() me.log "ERROR", ex.toString()
when "#{@name}-Release"
me.buildAndRelease()
isDirty: () -> isDirty: () ->
@ -563,7 +564,7 @@ class AntOSDK extends this.OS.GUI.BaseApplication
f.read (d) -> f.read (d) ->
tof.cache = new Blob [d], { type: f.info.mime } tof.cache = new Blob [d], { type: f.info.mime }
tof.write f.info.mime, (res) -> tof.write f.info.mime, (res) ->
me.log "SUCCESS", __("Copied {0} -> {1}", f.path, to) me.log "INFO", __("Copied {0} -> {1}", f.path, to)
return e res.error if res.error return e res.error if res.error
fn(l) fn(l)
, "binary" , "binary"
@ -621,7 +622,7 @@ class AntOSDK extends this.OS.GUI.BaseApplication
copylist = ("#{me.prjfile.cache.root}/#{v}" for v in me.prjfile.cache.copies) copylist = ("#{me.prjfile.cache.root}/#{v}" for v in me.prjfile.cache.copies)
me.copy copylist, "#{me.prjfile.cache.root}/build" me.copy copylist, "#{me.prjfile.cache.root}/build"
.then () -> .then () ->
me.log "INFO", __("Build done") me.log "SUCCESS", __("Build done")
me.dirty = false me.dirty = false
return new Promise (r, e) -> r() return new Promise (r, e) -> r()
@ -647,6 +648,7 @@ class AntOSDK extends this.OS.GUI.BaseApplication
, "json" , "json"
bnR: () -> bnR: () ->
@log "clean"
return @run() unless @dirty return @run() unless @dirty
me = @ me = @
@build().then () -> @build().then () ->
@ -654,6 +656,44 @@ class AntOSDK extends this.OS.GUI.BaseApplication
.catch (ex) -> .catch (ex) ->
me.log "ERROR", ex.toString() me.log "ERROR", ex.toString()
release: () ->
me = @
@log "INFO", __("Preparing for release")
new Promise (r, e) ->
me._api.require "jszip.min", () ->
fp = "#{me.prjfile.cache.root}/build".asFileHandler()
fp.read (d) ->
return e d.error if d.error
r d.result
.then (files) ->
return new Promise (r, e) ->
zip = new JSZip()
fn = (list) ->
return r zip if list.length is 0
f = (list.splice 0, 1)[0].path.asFileHandler()
return fn list if f.type is "dir"
f.read (d) ->
zip.file f.basename, d, { binary: true }
me.log "INFO", __("add {0} to zip", f.basename)
fn list
, "binary"
fn files
.then (zip) ->
zip.generateAsync({type:"base64"}).then (data) ->
f = "#{me.prjfile.cache.root}/release/#{me.prjfile.cache.name}.zip".asFileHandler()
f.cache = 'data:application/zip;base64,' + data
f.write "base64", (r) ->
return me.log "ERROR", __("Cannot save the zip file {0} : {1}", f.path, r.error) if r.error
me.log "SUCCESS", __("zip file generated in release folder")
buildAndRelease: () ->
@log "clean"
return @release() unless @dirty
me = @
@build().then () ->
me.release()
.catch (ex) ->
me.log "ERROR", ex.toString()
AntOSDK.singleton = false AntOSDK.singleton = false
AntOSDK.dependencies = [ AntOSDK.dependencies = [
"ace/ace", "ace/ace",