代码拉取完成,页面将自动刷新
//扩展库发布工具
import console
import fsys;
import string.template;
import fsys.tar;
import web.json;
import fsys.file;
import sevenZip.lzma;
import System.IO.Compression.ZipFile;
var ZipFile = System.IO.Compression.ZipFile;
// https://github.com/kanadeblisst00/aardio-extlibs
thread.set("GithubRepo", "http://git.pygrower.cn/kanadeblisst/aardio-extlibs");
::DEBUG = true;
io.open()
setupCode = /*
import fsys;
fsys.createDir("~\lib\${LIBDIR}");
fsys.copy( "\${FILENAME}","~\lib\${LIBDIR}" );
${LOADPRIVATEFONT}
import ide;
ide.refreshStdLib();
import win;
win.msgboxTimeout("${LIBNAME} 扩展库已安装成功!","aardio- ${LIBNAME}扩展库安装程序")
*/
var tmpPath = "\.temp";
var getLibInfo = function(libpath){
var code = string.load(libpath);
var s = string.match(code, "libInfo = (\{[\s\S]+?\})");
var libInfo = {
"version": "1.0.0.1",
"author": "kanadeblisst",
"description": "...",
"weight": 1
}
if(s){
libInfo = eval(s);
if(!libInfo["weight"]) libInfo["weight"] = 1;
}
return libInfo;
}
var packLib = function(libname){
console.log("正在打包库: ", libname);
var libpath,libdir = io.libpath(libname);
var libInfo = getLibInfo(libpath);
var setupFile;
var libfilename = fsys.getFileName(libpath);
if( libfilename == "_.aardio" ){
libfilename = fsys.getFileName(libdir)
libpath = libdir;
libdir = fsys.getParentDir(libdir);..io.print(libpath)
setupFile = ..io.exist( ..fsys.joinpath(libpath,"setup.dl.aardio") );
}
// 获取/lib/下的相对路径
libdir = fsys.path.relative(libdir,"~/lib/",false) : fsys.path.relative(libdir,"/lib/",false);
var libTmpPath = tmpPath + "\" + libname;
fsys.createDir(libTmpPath);
fsys.copy(libpath,libTmpPath);
var tarFilePath = "\dist\package\"+ libname + ".tar";
if( ! setupFile ){
var tmp = string.template(setupCode)
var setupCode = tmp.format(
LIBNAME = libname;
LIBDIR = libdir;
FILENAME = libfilename;
LOADPRIVATEFONT = "";
)
string.save(io.joinpath(libTmpPath,"setup.dl.aardio"),setupCode )
}
..fsys.delete(tarFilePath);
var tarFile = fsys.tar(tarFilePath);
tarFile.pack(libTmpPath,,false)
tarFile.close();
sevenZip.lzma.encodeFile(tarFilePath,tarFilePath+".lzma");
fsys.delete(libTmpPath);
fsys.delete(tarFilePath);
console.log("已打包完成,路径: ", tarFilePath+".lzma");
libInfo["url"] = libInfo["url"] : thread.get("GithubRepo") + "/raw/branch/master/dist/package/" + libname + ".tar.lzma";
if(io.exist("\res\"+libname)){
libInfo["sampleZipUrl"] = libInfo["sampleZipUrl"] : thread.get("GithubRepo") + "/raw/branch/master/dist/samples/" + libname + ".zip"
}
return libInfo;
}
var getPathModifyTime = function(path){
var writeTime = fsys.file(path).getTime().write.addhour(8)
return tostring(writeTime,"%Y-%m-%d %H:%M:%S");
}
var packSamples = function(libInfos){
import win;
var lastModifyTimePath = "\dist\sample_lasttime.json";
var lastModifyTimeTable = {};
if(io.exist(lastModifyTimePath)){
var fileStr = string.load(lastModifyTimePath);
if(#fileStr){
lastModifyTimeTable = ..web.json.tryParse(fileStr) : {};
}
}
fsys.enum( "\res", "*.*",function(dir,filename,fullpath,findData){
if(filename) return;
var mTime = getPathModifyTime(fullpath);
var zipPath = io.fullpath("/dist/samples/"+dir+".zip");
if(lastModifyTimeTable[dir] && mTime == lastModifyTimeTable[dir] && io.exist(zipPath)) return;
lastModifyTimeTable[dir] = mTime;
console.log("正在打包库案例,库: ", dir)
fsys.delete(zipPath);
win.delay(100)
ZipFile.CreateFromDirectory (
fullpath,
zipPath,
0,false )
},false);
string.save(lastModifyTimePath, ..web.json.stringify(lastModifyTimeTable,true))
console.log("打包案例完成 ")
}
var main = function(){
fsys.delete(tmpPath);
fsys.createDir(tmpPath);
fsys.createDir("\dist\package");
fsys.createDir("\dist\samples");
var lastModifyTimePath = "\dist\package_lasttime.json";
var extlibsJsonPath = "\dist\exlibs.json";
var lastModifyTimeTable = {};
if(io.exist(lastModifyTimePath)){
var fileStr = string.load(lastModifyTimePath);
if(#fileStr){
lastModifyTimeTable = ..web.json.tryParse(fileStr) : {};
}
}
var exlibsInfos = {};
if(io.exist(extlibsJsonPath)){
var fileStr = string.load(extlibsJsonPath);
if(#fileStr){
exlibsInfos = ..web.json.tryParse(fileStr) : {};
}
}
var libInfos = {};
fsys.enum( "\lib", "*.*",function(dir,filename,fullpath,findData){
if(filename == "config.aardio") return;
if(dir == "fonts") return ;
var libname = filename ? string.slice(filename,1,-8,true) : dir;
if(string.startWith(libname,"_")) return;
var mTime = getPathModifyTime(fullpath);
if(lastModifyTimeTable[libname] && mTime == lastModifyTimeTable[libname] && io.exist("/dist/package/" + libname + ".tar.lzma")) {
libInfos[libname] = exlibsInfos[libname];
return;
}
lastModifyTimeTable[libname] = mTime;
var libInfo = packLib(libname);
libInfo["lastModifyTime"] = string.split(mTime," ")[1];
libInfos[libname] = libInfo;
},false);
fsys.delete(tmpPath);
string.save(extlibsJsonPath, ..web.json.stringify(libInfos,true));
string.save(lastModifyTimePath, ..web.json.stringify(lastModifyTimeTable,true))
packSamples(libInfos);
}
main()
console.pause(true)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。