From 0b50d75f30a509737d8d9d9b1478f671e1ff90c8 Mon Sep 17 00:00:00 2001 From: lxsang Date: Mon, 4 Jul 2022 22:36:20 +0200 Subject: [PATCH] add GitGraph build file --- GitGraph/build/debug/README.md | 17 +++ GitGraph/build/debug/api/api.lua | 86 ++++++++++++ GitGraph/build/debug/libgitgraph.js | 1 + GitGraph/build/debug/main.css | 208 ++++++++++++++++++++++++++++ GitGraph/build/debug/main.js | 1 + GitGraph/build/debug/package.json | 16 +++ GitGraph/build/debug/scheme.html | 12 ++ GitGraph/build/release/GitGraph.zip | Bin 0 -> 6780 bytes 8 files changed, 341 insertions(+) create mode 100644 GitGraph/build/debug/README.md create mode 100644 GitGraph/build/debug/api/api.lua create mode 100644 GitGraph/build/debug/libgitgraph.js create mode 100644 GitGraph/build/debug/main.css create mode 100644 GitGraph/build/debug/main.js create mode 100644 GitGraph/build/debug/package.json create mode 100644 GitGraph/build/debug/scheme.html create mode 100644 GitGraph/build/release/GitGraph.zip diff --git a/GitGraph/build/debug/README.md b/GitGraph/build/debug/README.md new file mode 100644 index 0000000..1e38d6c --- /dev/null +++ b/GitGraph/build/debug/README.md @@ -0,0 +1,17 @@ +# LibGitGraph +Git grapth visualization API for AntOS application. + +The visualization can be easily integrated to an AntOS application, example: + +```typescript +const graph = new API.LibGitGraph({ + target: this.find("git-graph") +}); +graph.on_open_diff = (files) => { + console.log(files); +} +graph.base_dir = "home://workspace/repo-git"; +``` + +## Change logs: +- v0.1.0-b: Initial version \ No newline at end of file diff --git a/GitGraph/build/debug/api/api.lua b/GitGraph/build/debug/api/api.lua new file mode 100644 index 0000000..708d43b --- /dev/null +++ b/GitGraph/build/debug/api/api.lua @@ -0,0 +1,86 @@ +-- nothing todo for now +local args=... +local vfs = require("vfs") + +local result = function(data) + return { error = false, result = data } +end + +local error = function(msg) + return {error = msg, result = false} +end + +local handle = {} + +handle.log = function(data) + -- convert VFS to OS path + local os_path = vfs.ospath(data.base_dir) + if(not os_path) then + return error("Base dir "..data.base_dir.." is not found") + end + local cmd = "cd "..os_path.." && " + cmd = cmd.."git --no-pager log -n "..data.n_commits.." --all --format='{ \"hashes\":{ \"commit\":\"%H\", \"tree\":\"%T\", \"parents\":\"%P\" }, \"author\":{ \"date\": \"%ai\", \"name\": \"%an\", \"email\":\"%ae\" }, \"committer\":{ \"date\": \"%ci\", \"name\": \"%cn\", \"email\":\"%ce\" }, \"extra\":\"%D\"} ====:RAW:====%B====:RAW:========:COMMITEND:===='" + if(data.before) then + cmd = cmd.." --before='"..data.before.."'" + end + local f = assert(io.popen(cmd, 'r')) + local s = assert(f:read('*a')) + f:close() + local ret = {} + for line in s:gmatch("(.-)====:COMMITEND:====\n") do + local arr = {} + for el in line:gmatch("(.-)====:RAW:====") do + table.insert(arr, el) + end + local commit = JSON.decodeString(arr[1]) + commit.message = arr[2] + table.insert(ret, commit) + end + return result(ret) +end + +handle.list_file = function(data) + local os_path = vfs.ospath(data.base_dir) + if(not os_path) then + return error("Base dir "..data.base_dir.." is not found") + end + local cmd = "cd "..os_path..' && git --no-pager log -m -1 --name-status --pretty="format:" '..data.commit + local f = assert(io.popen(cmd, 'r')) + local s = assert(f:read('*a')) + f:close() + local ret = {} + for line in s:gmatch("(.-)\n") do + table.insert(ret, line) + end + return result(ret) +end + +handle.get_changes = function(data) + local os_path = vfs.ospath(data.base_dir) + if(not os_path) then + return error("Base dir "..data.base_dir.." is not found") + end + local cmd = "cd "..os_path.." && git --no-pager diff --no-prefix -U1000 "..data.commit.."^:"..data.file.." "..data.commit..":"..data.file + local f = assert(io.popen(cmd, 'r')) + local s = assert(f:read('*a')) + f:close() + return result(s) +end + +handle.get_file = function(data) + local os_path = vfs.ospath(data.base_dir) + if(not os_path) then + return error("Base dir "..data.base_dir.." is not found") + end + local cmd = "cd "..os_path.." && git --no-pager show "..data.commit..":"..data.file + local f = assert(io.popen(cmd, 'r')) + local s = assert(f:read('*a')) + f:close() + return result(s) +end + +if args.action and handle[args.action] then + return handle[args.action](args.args) +else + return error("Invalid action parameter") +end \ No newline at end of file diff --git a/GitGraph/build/debug/libgitgraph.js b/GitGraph/build/debug/libgitgraph.js new file mode 100644 index 0000000..c7b83f4 --- /dev/null +++ b/GitGraph/build/debug/libgitgraph.js @@ -0,0 +1 @@ +var OS;!function(t){let s;!function(s){s.LibGitGraph=class{constructor(t){this._base_dir=void 0,this.lines_data=[],this.commits={},this.oldest_commit_date=void 0,this.svg_element=void 0,this.commits_list_element=void 0,this.load_more_el=void 0,this.commit_detail_el=void 0,this.current_head=void 0,this._on_open_diff=void 0,this.options={commits_per_page:100,x_offset:24,y_offset:24,target:void 0,popup_height:250};for(const s in t)this.options[s]=t[s];this.current_y_offset=this.options.y_offset,this.init_graph()}set base_dir(t){this._base_dir=t,t&&this.render_next()}gen_color(t){let s=t+11;const e=[0,0,0];for(let t=0;t<24;t++)e[t%3]<<=1,e[t%3]|=1&s,s>>=1;return"#"+e.reduce((t,s)=>(s>15?s.toString(16):"0"+s.toString(16))+t,"")}meta(){return t.setting.system.packages.GitGraph}call(t){return new Promise(async(e,i)=>{t.args.base_dir=this._base_dir.path;let o={path:this.meta().path+"/api/api.lua",parameters:t},a=await s.apigateway(o,!1);a.error?i(s.throwe(__("LibGitGrapth server call error: {0}",a.error))):e(a.result)})}load(t){let s={action:"log",args:{n_commits:this.options.commits_per_page.toString(),before:t||null}};return this.call(s)}error(s){t.announcer.oserror(__("GitGraph error: {0}",s.toString()),s)}set on_open_diff(t){this._on_open_diff=t}init_graph(){if(!this.options.target)return this.error(s.throwe("Target element is undefined"));$(this.options.target).css("overflow-y","auto").css("overflow-x","hidden").css("display","block").css("position","relative"),this.svg_element=this.make_svg_el("svg",{width:this.options.x_offset,height:this.options.y_offset}),$(this.svg_element).css("display","block").css("position","absolute").css("left","0").css("top","0"),$(this.options.target).empty(),this.options.target.appendChild(this.svg_element);const t=$("
").css("position","absolute").css("left","0").css("top","0").css("width","100%").css("padding-top",this.options.y_offset/2+"px");this.commits_list_element=t[0],this.options.target.appendChild(this.commits_list_element);const e=$("

").css("height",this.options.y_offset+"px").css("display","block").css("padding","0").css("margin","0").css("line-height",this.options.y_offset+"px").css("vertical-align","middle");e.addClass("git_grapth_load_more"),e.on("click",t=>this.render_next()),e.text(__("More").__()),this.load_more_el=e[0],this.commits_list_element.appendChild(this.load_more_el);const i=$("

").css("position","absolute").css("top","0").css("height",this.options.popup_height+"px").css("display","none").css("user-select","text").addClass("git_grapth_commit_detail");this.commit_detail_el=i[0],this.options.target.appendChild(this.commit_detail_el)}render_next(){null!=this._base_dir&&this.load(this.oldest_commit_date).then(t=>{this.oldest_commit_date&&t.shift(),this.draw_graph(t)}).catch(t=>this.error(t))}make_svg_el(t,s){const e=document.createElementNS("http://www.w3.org/2000/svg",t);for(var i in s)e.setAttribute(i,s[i]);return e}max_line_off_x(){return 0==this.lines_data.length?0:Math.max.apply(Math,this.lines_data.map(t=>t.x_offset))}update_line_data(t,s){const e=t.hashes.parents.split(" "),i=this.lines_data.filter(s=>s.next_commit==t.hashes.commit);let o={src:[],dest:void 0};if(0===i.length){let i={next_commit:e[0],x_offset:this.max_line_off_x()+this.options.x_offset,current_commit:t.hashes.commit,beginning:!0,y_offset:s,color:this.gen_color(this.lines_data.length)};this.lines_data.push(i),o.dest=i}else{let a=Math.min.apply(Math,i.map(t=>t.x_offset)),n=void 0;for(let _ of i)_.x_offset==a?(n=_,n.next_commit=e[0],n.current_commit=t.hashes.commit,n.y_offset=s):(this.lines_data.splice(this.lines_data.indexOf(_),1),o.src.push(_));o.dest=n}if(2===e.length){let i=void 0;i=this.lines_data.filter(t=>t.next_commit==e[1])[0],i?i.y_offset=s+this.options.y_offset:(i={next_commit:e[1],x_offset:this.max_line_off_x()+this.options.x_offset,current_commit:t.hashes.commit,beginning:!0,y_offset:s+this.options.y_offset,color:this.gen_color(this.lines_data.length)},this.lines_data.push(i)),o.src.push(i)}return o}draw_line(t,s,e,i,o,a){let n={stroke:o,fill:"none","stroke-width":1.5};if(a&&(n["stroke-width"]=a),t==e)n.d=`M ${t},${s} L ${e},${i}`;else{let o=t,a=s,_=e,h=i,l=(Math.abs(_-o),Math.abs(h-a));s").css("display","block");return e[0].innerHTML=`${t.__()}: ${s}`,e[0]}open_popup(s){const e=s.domel;if(!e)return;$(this.commit_detail_el).empty();const i=$(e).position(),o=this.svg_element.getBBox(),a=o.x+o.width+this.options.x_offset/2,n=this.make_svg_el("svg",{width:a-s.cx+5,height:this.options.y_offset});$(n).css("display","block").css("position","absolute").css("left","0").css("top","-2px"),n.appendChild(this.draw_line(0,this.options.y_offset/2,a-s.cx,this.options.y_offset/2,s.color)),$(this.commit_detail_el).css("border","2px solid "+s.color).css("color",s.color).append($("
").css("position","absolute").css("height",this.options.y_offset).css("left",s.cx-a).css("padding-left",a-s.cx).append(n).append($("").text("[X]").css("cursor","pointer")).addClass("git_grapth_commit_detail_ctrl").on("click",t=>{$(this.commit_detail_el).css("display","none").empty()}));const _=$("
").css("display","block").css("overflow-y","auto").css("overflow-x","hidden").css("flex","1").css("border-right","1px solid "+s.color).addClass("git_grapth_commit_detail_left"),h=$("
").css("display","block").css("overflow-y","auto").css("overflow-x","hidden").css("flex","1").addClass("git_grapth_commit_detail_right");_.append(this.gen_commit_data_header(__("Commit"),s.hashes.commit)),_.append(this.gen_commit_data_header(__("Parents"),s.hashes.parents)),_.append(this.gen_commit_data_header(__("Author"),`${s.committer.name} <${s.committer.email}>`)),_.append(this.gen_commit_data_header(__("Date"),new Date(s.committer.date).toDateString())),_.append($("
").css("white-space","pre-wrap").text(s.message)),this.commit_detail_el.appendChild(_[0]),this.commit_detail_el.appendChild(h[0]),this.list_file(s.hashes.commit).then(e=>{const i=$("