diff --git a/Tesses.CrossLang.BuildEssentials/res/cml.txt b/Tesses.CrossLang.BuildEssentials/res/cml.txt new file mode 100644 index 0000000..713ab37 --- /dev/null +++ b/Tesses.CrossLang.BuildEssentials/res/cml.txt @@ -0,0 +1,46 @@ +cmake_minimum_required(VERSION 3.16) + +project(@<>@) + +option(@<>@_FETCHCONTENT "Whether to use fetchcontent" ON) +option(@<>@_SHARED_CROSSLANG "Whether to use shared crosslang" ON) + +add_executable(@<>@ src/main.cpp) + +if(@<>@_FETCHCONTENT) + + set(TESSESFRAMEWORK_ENABLE_EXAMPLES OFF CACHE INTERNAL "For TessesFramework" FORCE) + set(TESSESFRAMEWORK_ENABLE_APPS OFF CACHE INTERNAL "For TessesFramework" FORCE) + + set(TESSESFRAMEWORK_FETCHCONTENT ON CACHE INTERNAL "For TessesFramework" FORCE) + set(CROSSLANG_ENABLE_BINARIES OFF CACHE INTERNAL "For CrossLang" FORCE) + + if(@<>@_SHARED_CROSSLANG) + set(TESSESFRAMEWORK_ENABLE_STATIC OFF CACHE INTERNAL "For TessesFramework" FORCE) + set(TESSESFRAMEWORK_ENABLE_SHARED ON CACHE INTERNAL "For TessesFramework" FORCE) + else() + set(TESSESFRAMEWORK_ENABLE_STATIC ON CACHE INTERNAL "For TessesFramework" FORCE) + set(TESSESFRAMEWORK_ENABLE_SHARED OFF CACHE INTERNAL "For TessesFramework" FORCE) + endif() + include(FetchContent) + FetchContent_Declare( + TessesCrossLang + GIT_REPOSITORY https://onedev.site.tesses.net/crosslang.git + ) + + FetchContent_MakeAvailable(TessesCrossLang) + if(@<>@_SHARED_CROSSLANG) + target_link_libraries(@<>@ PUBLIC crosslang_shared) + else() + target_link_libraries(@<>@ PUBLIC crosslang_static) + endif() +else() + find_package(TessesCrossLang REQUIRED) + if(@<>@_SHARED_CROSSLANG) + target_link_libraries(@<>@ PUBLIC TessesCrossLang::crosslang_shared) + else() + target_link_libraries(@<>@ PUBLIC TessesCrossLang::crosslang_static) + endif() +endif() +install(TARGETS @<>@ DESTINATION "${CMAKE_INSTALL_BINDIR}") + \ No newline at end of file diff --git a/Tesses.CrossLang.BuildEssentials/res/cppfiletemplate.cpp b/Tesses.CrossLang.BuildEssentials/res/cppfiletemplate.cpp new file mode 100644 index 0000000..46fa5cd --- /dev/null +++ b/Tesses.CrossLang.BuildEssentials/res/cppfiletemplate.cpp @@ -0,0 +1,76 @@ +#include +#include "@<
>@.h" +using namespace Tesses::Framework; +using namespace Tesses::CrossLang; +int main(int argc, char** argv) +{ + std::string name = argv[0]; + Tesses::Framework::Filesystem::LocalFilesystem fs; + Tesses::Framework::Filesystem::VFSPath exePath=fs.SystemToVFSPath(name); + exePath.MakeAbsolute(); + + + TF_InitWithConsole(); + + GC gc; + gc.Start(); + GCList ls(gc); + TRootEnvironment* env = TRootEnvironment::Create(ls, TDictionary::Create(ls)); + + TStd::RegisterStd(&gc,env); + { + auto ms = std::shared_ptr(false); + auto& buff = ms->GetBuffer(); + buff.resize(@<>@_length); + memcpy(buff.data(),@<>@_data,@<>@_length); + auto file = TFile::Create(ls); + file->Load(&gc, &ms); + env->LoadFile(&gc,file); + } + + + + if(env->HasVariable("WebAppMain")) + { + Args args(argc, argv); + int port = 4206; + for(auto& item : args.options) + { + if(item.first == "port") + { + port = std::stoi(item.second); + } + } + TList* args2 = TList::Create(ls); + args2->Add(exePath.ToString()); + for(auto& item : args.positional) + { + args2->Add(item); + } + + auto res = env->CallFunction(ls, "WebAppMain", {args2}); + TObjectHttpServer http(&gc, res); + Tesses::Framework::Http::HttpServer svr(port,http,false); + + svr.StartAccepting(); + TF_RunEventLoop(); + TDictionary* _dict; + if(GetObjectHeap(res,_dict)) + { + _dict->CallMethod(ls,"Close",{}); + } + TF_Quit(); + } + else { + TList* args = TList::Create(ls); + args->Add(exePath.ToString()); + for(int arg=1;argAdd(argv[arg]); + auto res = env->CallFunction(ls,"main",{args}); + int64_t iresult; + if(GetObject(res,iresult)) + return (int)iresult; + } + return 0; +} + \ No newline at end of file diff --git a/Tesses.CrossLang.BuildEssentials/src/PackageManager.tcross b/Tesses.CrossLang.BuildEssentials/src/PackageManager.tcross index ca40d46..c138a3e 100644 --- a/Tesses.CrossLang.BuildEssentials/src/PackageManager.tcross +++ b/Tesses.CrossLang.BuildEssentials/src/PackageManager.tcross @@ -10,9 +10,9 @@ class Tesses.CrossLang.PackageManager public PackageManager() { this.configRoot = Env.CrossLangConfig; - this.packageCache = configRoot / "PackageCache"; + this.packageCache = this.configRoot / "PackageCache"; - FS.Local.CreateDirectory(packageCache); + FS.Local.CreateDirectory(this.packageCache); } /^ Parse package filename ^/ public ParseFileName(name) @@ -60,6 +60,7 @@ class Tesses.CrossLang.PackageManager var v = Version.Parse(version); var useCache = v.Stage != "dev"; var pkgFile = packageCache / name / v.ToString(); + if(useCache && FS.Local.RegularFileExists(pkgFile)) { return FS.ReadAllBytes(FS.Local,pkgFile); diff --git a/Tesses.CrossLang.BuildEssentials/src/Publisher.tcross b/Tesses.CrossLang.BuildEssentials/src/Publisher.tcross new file mode 100644 index 0000000..56dbc59 --- /dev/null +++ b/Tesses.CrossLang.BuildEssentials/src/Publisher.tcross @@ -0,0 +1,248 @@ +class Tesses.CrossLang.Publisher +{ + public Publisher(builder,project_dir) + { + + this.ProjectBuilder = builder; + this.ProjectDirectory = project_dir; + this.ProjectInfo = Json.Decode(FS.ReadAllText(FS.Local, project_dir / "cross.json")); + } + /^ + The project directory to publish + ^/ + public ProjectDirectory; + + /^ + The project builder + ^/ + public ProjectBuilder; + /^ + The project cross.json contents + ^/ + public ProjectInfo; + + + /^ + Where we output the published files + If null (which is default) we output at ProjectDirectory / "publish" / RuntimeIdentifier + ^/ + public OutputDirectory = null; + /^ + The runtime identifier + + builtins: + "crvm" (merge to one crvm) + "header" (merge to one crvm and generate C header) + "cmake" (merge to one crvm and generate C header and create a cmake project) + + actual runtimes can be found here: https://cpkg.tesseslanguage.com/packages?q=Tesses.CrossLang.Runtime. (you need to strip the Tesses.CrossLang.Runtime. from the names) + + ^/ + public RuntimeIdentifier="crvm"; + /^ + The prefix of the package (to prepend onto runtime identifier, we put the trailing period for you) + ^/ + public PackagePrefix = "Tesses.CrossLang.Runtime"; + /^ + Merge for runtimes (one crvm file) + ^/ + public MergeForRuntimes = false; + + private Build() + { + var out = this.ProjectBuilder.BuildProject(this.ProjectDirectory).Output; + return FS.MakeFull(out); + } + + private Merge() + { + var path = this.Build(); + var objDir = "obj"; + if(TypeOf(ProjectInfo.obj_directory) == "String") + objDir = ProjectInfo.obj_directory; + + var packPath = this.ProjectDirectory / objDir / "merge"; + if(packPath.Count > 0 && FS.Local.DirectoryExists(packPath)) + { + FS.Local.DeleteDirectoryRecurse(packPath); + } + FS.Local.CreateDirectory(packPath); + + var pack_dir = new SubdirFilesystem(FS.Local, packPath); + + return packPath / VM.Merge(FS.Local,path,pack_dir); + } + private CopyBuild(destPath) + { + func CopyCRVM(src,dest) + { + func copyFile(src,dest) + { + var _src = FS.Local.OpenFile(src,"rb"); + var _dest = FS.Local.OpenFile(dest, "wb"); + _src.CopyTo(_dest); + _src.Close(); + _dest.Close(); + Console.WriteLine($"{src} -> {dest}"); + } + if(FS.Local.FileExists(dest)) return; + copyFile(src,dest); + + + var srcStrm = FS.Local.OpenFile(src,"rb"); + var crvm = VM.LoadExecutable(srcStrm); + + srcStrm.Close(); + each(var dep : crvm.Dependencies) + { + var name = $"{dep.Name}-{dep.Version.ToString()}.crvm"; + CopyCRVM(src.GetParent()/name, dest.GetParent()/name); + } + } + CopyCRVM(this.Build(), destPath); + } + + private CreateCMake(dir, short_name) + { + FS.Local.CreateDirectory(dir / "src"); + var path = this.Merge(); + var bytes = FS.ReadAllBytes(FS.Local, path); + var caps_version = this.FixCHeaderName(short_name); + + FS.WriteAllText(FS.Local, dir / "src" / $"{short_name}.h", bytes.ToCHeaderFile(caps_version)); + + if(!FS.Local.RegularFileExists(dir / "CMakeLists.txt")) + { + var cmake_file = embed("cml.txt").ToString().Replace("@<>@",caps_version).Replace("@<>@",short_name); + FS.WriteAllText(FS.Local,dir / "CMakeLists.txt", cmake_file); + } + + if(!FS.Local.RegularFileExists(dir / "src"/"main.cpp")) + { + + var cppFile = embed("cppfiletemplate.cpp").ToString().Replace("@<>@", caps_version).Replace("@<
>@",short_name); + + FS.WriteAllText(FS.Local,dir / "src"/"main.cpp", cppFile); + } + } + + private CopyFile(src,dest) + { + var srcStrm = FS.Local.OpenFile(src,"rb"); + var destStrm = FS.Local.OpenFile(dest, "wb"); + + srcStrm.CopyTo(destStrm); + srcStrm.Close(); + destStrm.Close(); + } + + private FixCHeaderName(name) + { + var myStr = name.ToUpper(); + name = ""; + each(var item : myStr) + { + if((item >= 'A' && item <= 'Z') || (item >= '0' && item <= '9') || item == '_') + name += item; + } + if(name.Length == 0) return "NONAME"; + else if(name[0] >= '0' && name[0] <= '9') + return $"_{name}"; + return name; + } + + + /^ Start the publishing process ^/ + public Publish() + { + + + var outDir = TypeOf(this.OutputDirectory) == "Null" ? (this.ProjectDirectory / "publish" / this.RuntimeIdentifier) : this.OutputDirectory; + var short_name = TypeOf(this.ProjectInfo.info.short_name) == "String" ? this.ProjectInfo.info.short_name : this.ProjectInfo.name; + + FS.Local.CreateDirectory(outDir); + + switch(this.RuntimeIdentifier) + { + case "crvm": + { + var path = this.Merge(); + FS.Local.MoveFile(path, outDir / $"{short_name}.crvm"); + } + break; + case "header": + { + var path = this.Merge(); + var bytes = FS.ReadAllBytes(FS.Local, path); + FS.WriteAllText(FS.Local, outDir / $"{short_name}.h", bytes.ToCHeaderFile(this.FixCHeaderName(short_name))); + } + break; + case "cmake": + { + this.CreateCMake(outDir, short_name); + } + break; + default: + { + var runtimePackageName = this.PackagePrefix; + + if(runtimePackageName.Count > 0 && !runtimePackageName.EndsWith('.')) + runtimePackageName += "."; + + runtimePackageName += this.RuntimeIdentifier; + + var version = this.ProjectBuilder.PackageManager.GetLatest(runtimePackageName); + if(TypeOf(version) != "String") + { + throw { + Type="PackageNotFoundException", + Message=$"Could not find package {runtimePackageName}.", + ToString=(this)=>$"{this.Type} on line: {this.Line} {this.Message}" + }; + } + + var pkgObj = this.ProjectBuilder.PackageManager.GetPackage(runtimePackageName, version); + var strm = new MemoryStream(true); + strm.WriteBlock(pkgObj,0,pkgObj.Length); + strm.Seek(0,0); + var sdfs = new SubdirFilesystem(FS.Local, outDir); + var archiveResponse = FS.ExtractArchive(strm,sdfs); + sdfs.Close(); + + var archiveInfo = Json.Decode(archiveResponse.Info); + + if(archiveInfo.executable_can_be_renamed) + { + var executable_name_path = /archiveInfo.executable_name; + var executable_extension = executable_name_path.GetExtension(); + var newName = outDir/short_name; + if(executable_extension.Length > 0) newName += executable_extension; + + FS.Local.MoveFile(outDir/archiveInfo.executable_name,newName); + FS.Local.Chmod(newName, 0755); + if(this.MergeForRuntimes) + { + FS.Local.MoveFile(this.Merge(), outDir / short_name + ".crvm"); + } + else { + this.CopyBuild(outDir / short_name + ".crvm"); + } + } + else { + var executable_name_path = /archiveInfo.executable_name; + FS.Local.Chmod(outDir/archiveInfo.executable_name, 0755); + var executable_name_no_ext = executable_name_path.ChangeExtension(null).GetFileName(); + if(this.MergeForRuntimes) + { + FS.Local.MoveFile(this.Merge(), outDir / executable_name_no_ext + ".crvm"); + } + else { + this.CopyBuild(outDir / executable_name_no_ext + ".crvm"); + } + } + } + break; + + } + } +} \ No newline at end of file diff --git a/Tesses.CrossLang.BuildEssentials/src/buildtool.tcross b/Tesses.CrossLang.BuildEssentials/src/buildtool.tcross index 139f941..073a131 100644 --- a/Tesses.CrossLang.BuildEssentials/src/buildtool.tcross +++ b/Tesses.CrossLang.BuildEssentials/src/buildtool.tcross @@ -4,16 +4,16 @@ class Tesses.CrossLang.BuildTool /^ Construct the build tool with Package Manager ^/ public BuildTool(pm) { - this.PacakgeManager = pm; + this.PackageManager = pm; } private copyFile(src,dest) { - var src = FS.Local.OpenFile(src,"rb"); - var dest = FS.Local.OpenFile(dest, "wb"); - src.CopyTo(dest); - src.Close(); - dest.Close(); + var srcStrm = FS.Local.OpenFile(src,"rb"); + var destStrm = FS.Local.OpenFile(dest, "wb"); + srcStrm.CopyTo(destStrm); + srcStrm.Close(); + destStrm.Close(); } /^ Package Manager Object ^/ public PackageManager; @@ -22,8 +22,9 @@ class Tesses.CrossLang.BuildTool /^ Get the dependencies (don't use this directly unless you know what you are doing) ^/ public GetPackageDependencies(name, version, dir) { - var dep = PackageManager.GetPackage(name,version); + var dep = this.PackageManager.GetPackage(name,version); if(TypeOf(dep) == "Null") throw $"Package {name} with version {version} does not exist"; + var pkgPath = dir / $"{name}-{version}.crvm"; @@ -102,7 +103,7 @@ class Tesses.CrossLang.BuildTool outputDir = configData.bin_directory; if(TypeOf(configData.obj_directory) != "Undefined") - outputDir = configData.obj_directory; + objDir = configData.obj_directory; if(TypeOf(configData.source_directory) != "Undefined") srcDir = configData.source_directory; if(TypeOf(configData.resource_directory) != "Undefined") @@ -185,7 +186,7 @@ class Tesses.CrossLang.BuildTool FS.Local.CreateDirectory(newDir); var newFile = newDir / $"{item.Name}-{item.Version}.crvm"; - copyFile(item.Output, newFile); + this.copyFile(item.Output, newFile); each(var item2 : item.Dependencies) { walk_for_compiling(item2, newDir); @@ -205,7 +206,7 @@ class Tesses.CrossLang.BuildTool } else { - copyFile(item.Output, dir2 / $"{item.Name}-{item.Version}.crvm"); + this.copyFile(item.Output, dir2 / $"{item.Name}-{item.Version}.crvm"); each(var item2 : item.Dependencies) { walk_for_compiling(item2, dir2); diff --git a/Tesses.CrossLang.PackageServer/src/backend/db.tcross b/Tesses.CrossLang.PackageServer/src/backend/db.tcross index 8cd96e4..e2a3051 100644 --- a/Tesses.CrossLang.PackageServer/src/backend/db.tcross +++ b/Tesses.CrossLang.PackageServer/src/backend/db.tcross @@ -104,7 +104,7 @@ func DB.Init(working) var dbCon = DB.Open(); Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS packages (id INTEGER PRIMARY KEY AUTOINCREMENT, packageName TEXT UNIQUE, accountId INTEGER);"); - Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT, uploadTime INTEGER);"); + Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT, uploadTime INTEGER, pluginHost TEXT);"); Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS accounts (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT UNIQUE, accountName TEXT UNIQUE, password_hash TEXT, password_salt TEXT, motto TEXT, verifyKey TEXT UNIQUE, verifyExpire INTEGER, flags INTEGER);"); Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY AUTOINCREMENT, accountId INTEGER, key STRING UNIQUE);"); Sqlite.Exec(dbCon,"CREATE TABLE IF NOT EXISTS reserved_prefixes (id INTEGER PRIMARY KEY AUTOINCREMENT, accountId INTEGER, prefix STRING UNIQUE);"); diff --git a/Tesses.CrossLang.PackageServer/src/backend/packageversion.tcross b/Tesses.CrossLang.PackageServer/src/backend/packageversion.tcross index 0d8fa21..4c3c0a2 100644 --- a/Tesses.CrossLang.PackageServer/src/backend/packageversion.tcross +++ b/Tesses.CrossLang.PackageServer/src/backend/packageversion.tcross @@ -24,6 +24,8 @@ func DB.GetPackageVersions(name) var list = []; each(var item : res) { + var pluginHost = item.pluginHost; + if(TypeOf(pluginHost) != "String") pluginHost = ""; var version = Version.FromLong(ParseLong(item.version)).ToString(); var uploadTime = ParseLong(item.uploadTime); list.Add({ @@ -39,6 +41,7 @@ func DB.GetPackageVersions(name) license = item.license, uploadTime, uploadDate=new DateTime(uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC") + pluginHost }); } return list; @@ -63,7 +66,9 @@ func DB.UpdateVersion(pkgInfo) var homepage = info.homepage; var repo = info.repo; var license = info.license; + var pluginHost = info.plugin_host; if(TypeOf(description) != "String") description=""; + if(TypeOf(pluginHost) != "String") pluginHost = ""; if(TypeOf(type) != "String") type=""; @@ -77,7 +82,7 @@ func DB.UpdateVersion(pkgInfo) //CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT); //VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)}); - Sqlite.Exec(dbCon,$"UPDATE versions SET description = {Sqlite.Escape(description)}, type = {Sqlite.Escape(type)}, maintainer = {Sqlite.Escape(maintainer)}, homepage = {Sqlite.Escape(homepage)}, repo = {Sqlite.Escape(repo)}, license = {Sqlite.Escape(license)}, uploadTime = {DateTime.NowEpoch} WHERE packageId = {pkgId} AND version = {version};"); + Sqlite.Exec(dbCon,$"UPDATE versions SET pluginHost = {Sqlite.Escape(pluginHost)}, description = {Sqlite.Escape(description)}, type = {Sqlite.Escape(type)}, maintainer = {Sqlite.Escape(maintainer)}, homepage = {Sqlite.Escape(homepage)}, repo = {Sqlite.Escape(repo)}, license = {Sqlite.Escape(license)}, uploadTime = {DateTime.NowEpoch} WHERE packageId = {pkgId} AND version = {version};"); Sqlite.Close(dbCon); DB.Unlock(); @@ -101,6 +106,8 @@ func DB.AddVersion(pkgInfo) var homepage = info.homepage; var repo = info.repo; var license = info.license; + var pluginHost = info.plugin_host; + if(TypeOf(pluginHost) != "String") pluginHost = ""; if(TypeOf(description) != "String") description=""; if(TypeOf(type) != "String") type=""; @@ -115,7 +122,7 @@ func DB.AddVersion(pkgInfo) //CREATE TABLE IF NOT EXISTS versions (id INTEGER PRIMARY KEY AUTOINCREMENT, packageId INTEGER, version INTEGER, description TEXT, type TEXT, maintainer TEXT, homepage TEXT, repo TEXT, license TEXT); - Sqlite.Exec(dbCon,$"INSERT INTO versions (packageId,version,description,type,maintainer,homepage,repo,license,uploadTime) VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)},{DateTime.NowEpoch});"); + Sqlite.Exec(dbCon,$"INSERT INTO versions (packageId,version,description,type,maintainer,homepage,repo,license,uploadTime,pluginHost) VALUES ({pkgId},{version},{Sqlite.Escape(description)},{Sqlite.Escape(type)},{Sqlite.Escape(maintainer)},{Sqlite.Escape(homepage)},{Sqlite.Escape(repo)},{Sqlite.Escape(license)},{DateTime.NowEpoch},Sqlite.Escape(pluginHost));"); Sqlite.Close(dbCon); DB.Unlock(); diff --git a/Tesses.CrossLang.PackageServer/src/pages/package.tcross b/Tesses.CrossLang.PackageServer/src/pages/package.tcross index 880cdc7..3d35ee4 100644 --- a/Tesses.CrossLang.PackageServer/src/pages/package.tcross +++ b/Tesses.CrossLang.PackageServer/src/pages/package.tcross @@ -112,6 +112,11 @@ func Pages.Package(ctx,name)
  • Last updated: {new DateTime(package[0].uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")}
  • Latest version: {package[0].version}
  • Type: {package[0].type}
  • + 0)> + +
  • PluginHost: {package[0].pluginHost}
  • +
    +
  • Download
  • View Docs
  • @@ -153,6 +158,11 @@ func Pages.Package(ctx,name)
  • Uploaded: {new DateTime(package[i].uploadTime).ToString("%Y/%m/%d %H:%M:%S UTC")}
  • Type: {package[i].type}
  • + 0)> + +
  • PluginHost: {package[i].pluginHost}
  • +
    +
  • Download
  • View Docs
  • diff --git a/Tesses.CrossLang.PackageServer/src/program.tcross b/Tesses.CrossLang.PackageServer/src/program.tcross index 55d94f5..4464206 100644 --- a/Tesses.CrossLang.PackageServer/src/program.tcross +++ b/Tesses.CrossLang.PackageServer/src/program.tcross @@ -71,13 +71,19 @@ func main(args) } if(ctx.Path == "/api/v1/search") { - var filter = ctx.QueryParams.TryGetFirst("filter"); - if(TypeOf(filter) != "String") filter = ""; - var filters = filter.Length > 0 ? filter.Split(",") : []; - - if(filters.Length > 0) + var filter = ""; + var type = ctx.QueryParams.TryGetFirst("type"); + if(TypeOf(type) != "String") type = ""; + var types = type.Length > 0 ? type.Split(",") : []; + + var pluginHost = ctx.QueryParams.TryGetFirst("pluginHost"); + if(TypeOf(pluginHost) == "String") { - filter = " AND ("; + filter += $" AND v.pluginHost = {Sqlite.Escape(pluginHost)}"; + } + if(types.Length > 0) + { + filter += " AND ("; var first = true; each(var item : filters) { diff --git a/Tesses.CrossLang.Shell/src/main.tcross b/Tesses.CrossLang.Shell/src/main.tcross index d967701..64fc916 100644 --- a/Tesses.CrossLang.Shell/src/main.tcross +++ b/Tesses.CrossLang.Shell/src/main.tcross @@ -77,6 +77,9 @@ func main(args) case "docs": return Tesses.CrossLang.Shell.Docs(dd); break; + case "publish": + return Tesses.CrossLang.Shell.Publish(dd); + break; default: return Tesses.CrossLang.Shell.Default(dd); } diff --git a/Tesses.CrossLang.Shell/src/publish.tcross b/Tesses.CrossLang.Shell/src/publish.tcross new file mode 100644 index 0000000..058d505 --- /dev/null +++ b/Tesses.CrossLang.Shell/src/publish.tcross @@ -0,0 +1,80 @@ +func Tesses.CrossLang.Shell.Publish(dd) +{ + var offline=false; + var allowFullCompTime=false; + var buildPath = "."; + var merge=false; + var packagePrefix = "Tesses.CrossLang.Runtime"; + var out = null; + var identifier = "crvm"; + if(dd.Arguments.Count > 1) + { + identifier = dd.Arguments[1]; + if(dd.Arguments.Length > 2) + { + buildPath = dd.Arguments[2]; + } + } + each(var flag : dd.Flags) + { + if(flag == "offline") + { + offline = true; + } + if(flag == "allow-insecure-comptime") + { + allowFullCompTime=true; + } + if(flag == "merge") + { + merge = true; + } + if(flag == "help") + { + Console.WriteLine("USAGE: crosslang publish [publish-flags-and-options] identifier projectDir"); + Console.WriteLine("FLAGS:"); + Console.WriteLine("offline: build with no internet (don't fetch files)"); + Console.WriteLine("help: this help"); + Console.WriteLine("allow-insecure-comptime: Allow full comptime"); + Console.WriteLine("merge: Merge the crvms into one (when bundling a runtime)"); + Console.WriteLine(); + Console.WriteLine("OPTIONS:"); + Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config"); + Console.WriteLine("runtime-package-prefix=PREFIX: prefix the identifier (defaults to Tesses.CrossLang.Runtime, we add the dot automaticly unless you provide empty string)"); + Console.WriteLine("out=DIR: where to output the published artifact, defaults to projectDir/publish/identifier"); + return 0; + } + } + var conf = ""; + each(var option : dd.Options) + { + if(option.Key == "conf") + { + conf = option.Value; + } + if(option.Key == "runtime-package-prefix") + { + packagePrefix = option.Value; + } + if(option.Key == "out") + { + out = option.Value; + } + } + + + + var pm = new Tesses.CrossLang.PackageManager(); + pm.Offline = offline; + var bt = new Tesses.CrossLang.BuildTool(pm); + bt.Config = conf; + bt.AllowFullCompTime = allowFullCompTime; + var publisher = new Tesses.CrossLang.Publisher(bt, FS.MakeFull(buildPath)); + publisher.OutputDirectory = out; + publisher.RuntimeIdentifier = identifier; + publisher.PackagePrefix = packagePrefix; + publisher.MergeForRuntimes = merge; + + publisher.Publish(); + return 0; +} \ No newline at end of file diff --git a/build.tcross b/build.tcross index 424828c..73dfe6b 100644 --- a/build.tcross +++ b/build.tcross @@ -14,7 +14,7 @@ func cmd(name, args) func main(args) { - var args2=["-o","./Tesses.CrossLang.BuildEssentials/bin-tmp","-n","Tesses.CrossLang.BuildEssentials","-v","1.0.0.0-prod","Tesses.CrossLang.BuildEssentials/main.tcross"]; + var args2=["-o","./Tesses.CrossLang.BuildEssentials/bin-tmp","-r","./Tesses.CrossLang.BuildEssentials/res","-n","Tesses.CrossLang.BuildEssentials","-v","1.0.0.0-prod","Tesses.CrossLang.BuildEssentials/main.tcross"]; each(var f : FS.Local.EnumeratePaths("./Tesses.CrossLang.BuildEssentials/src")) { if(f.GetExtension() == ".tcross")