diff --git a/Templates/compiletool/cross.json b/Templates/compiletool/cross.json index 7ab38ad..a27cae5 100644 --- a/Templates/compiletool/cross.json +++ b/Templates/compiletool/cross.json @@ -7,11 +7,11 @@ "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", "homepage": "https://crosslang.tesseslanguage.com/", "license": "MIT", - "template_name": "compiletool", + "short_name": "compiletool", "template_info": { "type": "compile_tool" }, - "template_name_pretty": "Compile Tool", + "short_name_pretty": "Compile Tool", "template_ignored_files": ["bin","obj"], "description": "A tool that can be a dependency to a project (including libraries) that runs at compile time" } diff --git a/Templates/console/cross.json b/Templates/console/cross.json index 4705dd9..416cba6 100644 --- a/Templates/console/cross.json +++ b/Templates/console/cross.json @@ -7,11 +7,14 @@ "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", "homepage": "https://crosslang.tesseslanguage.com/", "license": "MIT", - "template_name": "console", + "short_name": "console", "template_info": { - "type": "console" + "type": "console", + "short_name": "changeme", + "short_name_pretty": "Change Me", + "description": "Change Me" }, - "template_name_pretty": "Console Application", + "short_name_pretty": "Console Application", "template_ignored_files": ["bin","obj"], "description": "A console application" } diff --git a/Templates/emptyweb/cross.json b/Templates/emptyweb/cross.json index 74480bb..500e6a3 100644 --- a/Templates/emptyweb/cross.json +++ b/Templates/emptyweb/cross.json @@ -7,12 +7,12 @@ "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", "homepage": "https://crosslang.tesseslanguage.com/", "license": "MIT", - "template_name": "emptyweb", + "short_name": "emptyweb", "description": "An empty website", "template_info": { "type": "console" }, - "template_name_pretty": "Empty Website", + "short_name_pretty": "Empty Website", "template_extra_text_ftles": [], "template_ignored_files": ["bin","obj"] } diff --git a/Templates/lib/cross.json b/Templates/lib/cross.json index 98f6a7b..6b9ddcc 100644 --- a/Templates/lib/cross.json +++ b/Templates/lib/cross.json @@ -7,12 +7,12 @@ "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", "homepage": "https://crosslang.tesseslanguage.com/", "license": "MIT", - "template_name": "lib", + "short_name": "lib", "template_info": { "type": "lib" }, "template_ignored_files": ["bin","obj"], "description": "A crosslang library", - "template_name_pretty": "Library" + "short_name_pretty": "Library" } } diff --git a/Templates/template/cross.json b/Templates/template/cross.json index 396f9bb..0fc9da7 100644 --- a/Templates/template/cross.json +++ b/Templates/template/cross.json @@ -7,11 +7,12 @@ "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", "homepage": "https://crosslang.tesseslanguage.com/", "license": "MIT", - "template_name": "template", + "short_name": "template", "description": "A template for a project", "template_info": { "type": "template", - "template_name": "mytemplate", + "short_name": "mytemplate", + "short_name_pretty": "My Template", "template_project_dependencies": [], "template_extra_text_ftles": [], "template_info": { @@ -22,6 +23,6 @@ "template_project_dependencies": [], "template_extra_text_ftles": [], "template_ignored_files": ["bin","obj"], - "template_name_pretty": "Template" + "short_name_pretty": "Template" } } diff --git a/Templates/tool/cross.json b/Templates/tool/cross.json index 078f777..89585f1 100644 --- a/Templates/tool/cross.json +++ b/Templates/tool/cross.json @@ -8,18 +8,19 @@ "template_info": { "type": "tool", "description": "This is my tool", - "toolname": "changeme" + "short_name": "changeme", + "short_name_pretty": "Change Me" }, "template_extra_text_ftles": [], "template_project_dependencies": [], - "template_name": "tool", + "short_name": "tool", "description": "A crosslang tool that you can run via crosslang tool", "type": "template", "maintainer": "Mike Nolan", "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", "homepage": "https://crosslang.tesseslanguage.com/", "license": "MIT", - "template_name_pretty": "Tool" + "short_name_pretty": "Tool" }, "version": "1.0.0.0-prod", "name": "Tesses.CrossLang.Template.Tool" diff --git a/Templates/web/cross.json b/Templates/web/cross.json index 79e86a0..cf282d3 100644 --- a/Templates/web/cross.json +++ b/Templates/web/cross.json @@ -7,12 +7,12 @@ "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", "homepage": "https://crosslang.tesseslanguage.com/", "license": "MIT", - "template_name": "web", + "short_name": "web", "description": "A Simple.CSS Website with my template engine", "template_info": { "type": "console" }, "template_ignored_files": ["bin","obj"], - "template_name_pretty": "WebSite" + "short_name_pretty": "WebSite" } } diff --git a/Templates/webapp/cross.json b/Templates/webapp/cross.json index 2f7c987..7693c2a 100644 --- a/Templates/webapp/cross.json +++ b/Templates/webapp/cross.json @@ -11,8 +11,8 @@ "type": "webapp", "license": "MIT" }, - "template_name": "webapp", - "template_name_pretty": "Web Application", + "short_name": "webapp", + "short_name_pretty": "Web Application", "template_project_dependencies": [ ], "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", diff --git a/Templates/webapp/src/main.tcross b/Templates/webapp/src/main.tcross index 7570b76..9b3a73b 100644 --- a/Templates/webapp/src/main.tcross +++ b/Templates/webapp/src/main.tcross @@ -10,3 +10,7 @@ func WebAppMain(args) return false; }; } +func main(args) +{ + Console.WriteLine("use crosslang webapp-test to test"); +} \ No newline at end of file diff --git a/Tesses.CrossLang.BuildEssentials/src/helpers.tcross b/Tesses.CrossLang.BuildEssentials/src/helpers.tcross index 86c05ba..82e4cfb 100644 --- a/Tesses.CrossLang.BuildEssentials/src/helpers.tcross +++ b/Tesses.CrossLang.BuildEssentials/src/helpers.tcross @@ -10,10 +10,8 @@ func Tesses.CrossLang.GetNameAndDescription(name) var j = Json.Decode(file.Info); var description = TypeOf(j.description) == "String" ? j.description : ""; - if(j.type == "template") - name = TypeOf(j.template_name) == "String" ? j.template_name : name; - else if(j.type == "tool") - name = TypeOf(j.toolname) == "String" ? j.toolname : name; + name = TypeOf(j.short_name) == "String" ? j.short_name : name; + return $"{name}: {description}"; } @@ -29,10 +27,8 @@ func Tesses.CrossLang.GetNameAndDescriptionJson(name) var j = Json.Decode(file.Info); var description = TypeOf(j.description) == "String" ? j.description : ""; - if(j.type == "template") - name = TypeOf(j.template_name) == "String" ? j.template_name : name; - else if(j.type == "tool") - name = TypeOf(j.toolname) == "String" ? j.toolname : name; + + name = TypeOf(j.short_name) == "String" ? j.short_name : name; return { name, diff --git a/Tesses.CrossLang.PackageServer/src/pages/package.tcross b/Tesses.CrossLang.PackageServer/src/pages/package.tcross index f61b4ae..880cdc7 100644 --- a/Tesses.CrossLang.PackageServer/src/pages/package.tcross +++ b/Tesses.CrossLang.PackageServer/src/pages/package.tcross @@ -29,8 +29,8 @@ func Pages.Package(ctx,name) case "console": installCmd = $"crosslang install-console {name} --version={package[0].version}"; break; - case "app": - installCmd = $"crosslang install-app {name} --version={package[0].version}"; + case "webapp": + installCmd = $"crosslang install-webapp {name} --version={package[0].version}"; break; case "tool": installCmd = $"crosslang install-tool {name} --version={package[0].version}"; diff --git a/Tesses.CrossLang.Shell/cross.json b/Tesses.CrossLang.Shell/cross.json index 70dd895..89843af 100644 --- a/Tesses.CrossLang.Shell/cross.json +++ b/Tesses.CrossLang.Shell/cross.json @@ -1,15 +1,16 @@ { - "name": "Tesses.CrossLang.Shell", - "version": "1.0.0.0-prod", - "info": { - "maintainer": "Mike Nolan", - "type": "console", - "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", - "homepage": "https://crosslang.tesseslanguage.com/", - "license": "LGPLv3" - }, - "project_dependencies": [ - "../Tesses.CrossLang.BuildEssentials", - "../Tesses.CrossLang.Args" - ] + "name": "Tesses.CrossLang.Shell", + "version": "1.0.0.0-prod", + "dependencies": [], + "info": { + "maintainer": "Mike Nolan", + "type": "console", + "repo": "https://onedev.site.tesses.net/CrossLang/CrossLangExtras", + "homepage": "https://crosslang.tesseslanguage.com/", + "license": "LGPLv3" + }, + "project_dependencies": [ + "../Tesses.CrossLang.BuildEssentials", + "../Tesses.CrossLang.Args" + ] } \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/console.tcross b/Tesses.CrossLang.Shell/src/console.tcross new file mode 100644 index 0000000..3333c9e --- /dev/null +++ b/Tesses.CrossLang.Shell/src/console.tcross @@ -0,0 +1,41 @@ +func Tesses.CrossLang.Shell.Console(dd) +{ + var dir = Env.CrossLangConfig / "ConsoleApps"; + if(dd.Arguments.Length == 1) + { + Console.WriteLine("List of console applications:"); + if(FS.Local.DirectoryExists(dir)) + each(var item : FS.Local.EnumeratePaths(dir)) + { + Console.WriteLine(Tesses.CrossLang.GetNameAndDescription(item / item.GetFileName() + ".crvm")); + } + return 0; + } + else if(dd.Arguments.Length >= 2) + { + var consolename = dd.Arguments[1]; + var consolepath = dir / consolename / consolename + ".crvm"; + + if(FS.Local.FileExists(consolepath)) + { + + var env = VM.CreateEnvironment({}); + env.RegisterEverything(); + env.LockRegister(); + + env.LoadFileWithDependencies(FS.Local,consolepath); + var myArgs = []; + myArgs.Add(consolepath.ToString()); + for(var i = 2; i < dd.Arguments.Count; i++) + { + myArgs.Add(dd.Arguments[i]); + } + return env.GetDictionary().main(myArgs); + } + else { + Console.WriteLine($"Could not find console application with name {consolename}."); + return 1; + } + } + +} \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/default.tcross b/Tesses.CrossLang.Shell/src/default.tcross index 18cdcc8..f49fdcc 100644 --- a/Tesses.CrossLang.Shell/src/default.tcross +++ b/Tesses.CrossLang.Shell/src/default.tcross @@ -16,6 +16,21 @@ func Tesses.CrossLang.Shell.Default(dd) Console.WriteLine("new: create new project"); Console.WriteLine("build: build a project"); Console.WriteLine("run: run a project"); + Console.WriteLine("debug: debug a project"); + Console.WriteLine("install-console: install a console application"); + Console.WriteLine("install-template: install a project template"); + Console.WriteLine("install-tool: install a tool"); + Console.WriteLine("install-webapp: install a web application"); + Console.WriteLine("console: run or list installed console applications"); + Console.WriteLine("webapp: run or list installed web applications"); + Console.WriteLine("webapp-test: test a web application in place"); + Console.WriteLine("tool: run or list installed tools"); + Console.WriteLine("tool-test: test a tool in place"); + Console.WriteLine("add-project: add project as a dependency"); + Console.WriteLine("add-dependency: add package as dependency"); + Console.WriteLine("upload-package: upload package to cpkg"); + Console.WriteLine("login: login to cpkg"); + Console.WriteLine("logout: logout from cpkg"); Console.WriteLine("configdir: print the config directory"); Console.WriteLine("update-shell: update the shell"); //this command is handled by runtime so we don't have to implement it here return 0; diff --git a/Tesses.CrossLang.Shell/src/install-console.tcross b/Tesses.CrossLang.Shell/src/install-console.tcross new file mode 100644 index 0000000..981c7b0 --- /dev/null +++ b/Tesses.CrossLang.Shell/src/install-console.tcross @@ -0,0 +1,204 @@ +func Tesses.CrossLang.Shell.InstallConsole(dd) +{ + //crosslang install-console Tesses.CrossLang.Console.SomeConsole --version=1.0.0.0-prod + var consoleDir = Env.CrossLangConfig / "ConsoleApps"; + + var offline=false; + var buildPath = "."; + var nobuild=false; + var output=.; + each(var flag : dd.Flags) + { + if(flag == "offline") + { + offline = true; + } + else if(flag == "help") + { + Console.WriteLine("USAGE: crosslang install-console [flags-and-options]"); + Console.WriteLine("USAGE: crosslang install-console [PackageName] [flags-and-options]"); + Console.WriteLine("FLAGS:"); + Console.WriteLine("offline: build with no internet (don't fetch files)"); + Console.WriteLine("help: this help"); + Console.WriteLine("nobuild: don't build, just install (irrelevant if you specify a PackageName)"); + Console.WriteLine(); + Console.WriteLine("OPTIONS:"); + Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config (irrelevant if you specify a PackageName)"); + Console.WriteLine("version=1.0.0.0-prod: specify the package version (irrelevant if you don't specify a PackageName)"); + Console.WriteLine(); + Console.WriteLine("ARGUMENTS:"); + Console.WriteLine("PackageName: the package name of a console application you want to download and install, if not specified we install the console application from the current directory"); + return 0; + } + else if(flag == "nobuild") + { + nobuild=true; + } + } + if(dd.Arguments.Length == 2) + { + var pm = Tesses.CrossLang.PackageManager(); + pm.Offline = offline; + var name = dd.Arguments[1]; + var version = null; + each(var opt : dd.Options) + { + if(opt.Key == "version") + version = opt.Value; + } + if(version == null) + { + var pm = Tesses.CrossLang.PackageManager(); + version = pm.GetLatest(name); + } + if(version == null) + { + Console.WriteLine("Could not get version"); + return 1; + } + var ms = new MemoryStream(true); + var ba = pm.GetPackage(name, version); + ms.WriteBlock(ba,0,ba.Length); + ms.Seek(0,0); + var exec = VM.LoadExecutable(ms); + var info = Json.Decode(exec.Info); + if(info.type != "console") + { + Console.WriteLine("The project is not a console application"); + ms.Close(); + return 1; + } + + if(TypeOf(info.short_name) == "String") + { + var dir = consoleDir / info.short_name; + if(FS.Local.DirectoryExists(dir)) + { + each(var item : FS.Local.EnumeratePaths(dir)) + { + if(FS.Local.FileExists(item) && item.GetExtension() == ".crvm") + { + FS.Local.DeleteFile(item); + } + } + } + + FS.Local.CreateDirectory(dir); + + FS.WriteAllBytes(FS.Local, dir / info.short_name + ".crvm", ba); + + func downloadDependency(_name, _version) + { + var ms = new MemoryStream(true); + var ba = pm.GetPackage(name, version); + ms.WriteBlock(ba,0,ba.Length); + ms.Seek(0,0); + var exec = VM.LoadExecutable(ms); + var execPath = dir / $"{_name}-{_version}.crvm"; + + if(!FS.Local.FileExists(execPath)) + FS.WriteAllBytes(FS.Local, execPath , ba); + + each(var item : exec.Dependencies) + downloadDependency(item.Name, item.Version); + ms.Close(); + } + + each(var item : exec.Dependencies) + downloadDependency(item.Name, item.Version); + Console.WriteLine($"Installed console application {info.short_name}"); + } + + ms.Close(); + + } + else if(dd.Arguments.Length == 1) + { + + var conf = ""; + each(var option : dd.Options) + { + if(option.Key == "conf") + { + conf = option.Value; + } + } + + if(FS.Local.FileExists("cross.json")) + { + var proj = Json.Decode(FS.ReadAllText(FS.Local,"cross.json")); + var name = proj.info.short_name; + + if(proj.info.type != "console") + { + Console.WriteLine("The project is not a console application"); + return 1; + } + if(TypeOf(name) != "String") + { + Console.WriteLine("The console application does not have a name"); + return 1; + } + var consoleDir2 = consoleDir / name; + FS.Local.CreateDirectory(consoleDir2); + var consoleFile = consoleDir2 / name + ".crvm"; + + if(nobuild) + { + var nameVer = $"{proj.name}-{proj.version}.crvm"; + var buildDir = TypeOf(proj.bin_directory) == "String" ? proj.bin_directory : "bin"; + + output = ./buildDir/nameVer; + if(!FS.Local.FileExists(output)) + { + Console.WriteLine($"ERROR: file {output} does not exist."); + return 1; + } + + } + else + { + var pm = Tesses.CrossLang.PackageManager(); + pm.Offline = offline; + var bt = Tesses.CrossLang.BuildTool(pm); + bt.Config = conf; + output = bt.BuildProject(buildPath).Output; + } + + 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(output,consoleFile); + return 0; + } + else + { + + Console.WriteLine("The current directory does not have a project"); + return 1; + } + } + return 0; +} \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/install-template.tcross b/Tesses.CrossLang.Shell/src/install-template.tcross new file mode 100644 index 0000000..23feac0 --- /dev/null +++ b/Tesses.CrossLang.Shell/src/install-template.tcross @@ -0,0 +1,156 @@ +func Tesses.CrossLang.Shell.InstallTemplate(dd) +{ + //crosslang install-template Tesses.CrossLang.Tool.Template --version=1.0.0.0-prod + var templatesDir = Env.CrossLangConfig / "Templates"; + + var offline=false; + var buildPath = "."; + var nobuild=false; + var output=.; + each(var flag : dd.Flags) + { + if(flag == "offline") + { + offline = true; + } + else if(flag == "help") + { + Console.WriteLine("USAGE: crosslang install-template [flags-and-options]"); + Console.WriteLine("USAGE: crosslang install-template [PackageName] [flags-and-options]"); + Console.WriteLine("FLAGS:"); + Console.WriteLine("offline: build with no internet (don't fetch files)"); + Console.WriteLine("help: this help"); + Console.WriteLine("nobuild: don't build, just install (irrelevant if you specify a PackageName)"); + Console.WriteLine(); + Console.WriteLine("OPTIONS:"); + Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config (irrelevant if you specify a PackageName)"); + Console.WriteLine("version=1.0.0.0-prod: specify the package version (irrelevant if you don't specify a PackageName)"); + Console.WriteLine(); + Console.WriteLine("ARGUMENTS:"); + Console.WriteLine("PackageName: the package name of a template you want to download and install, if not specified we install the template from the current directory"); + return 0; + } + else if(flag == "nobuild") + { + nobuild=true; + } + } + if(dd.Arguments.Length == 2) + { + var pm = Tesses.CrossLang.PackageManager(); + pm.Offline = offline; + var name = dd.Arguments[1]; + var version = null; + each(var opt : dd.Options) + { + if(opt.Key == "version") + version = opt.Value; + } + if(version == null) + { + var pm = Tesses.CrossLang.PackageManager(); + version = pm.GetLatest(name); + } + if(version == null) + { + Console.WriteLine("Could not get version"); + return 1; + } + var ms = new MemoryStream(true); + var ba = pm.GetPackage(name, version); + ms.WriteBlock(ba,0,ba.Length); + ms.Seek(0,0); + var exec = VM.LoadExecutable(ms); + var info = Json.Decode(exec.Info); + if(info.type != "template") + { + Console.WriteLine("The project is not a template"); + ms.Close(); + return 1; + } + + if(TypeOf(info.short_name) == "String") + { + + + + FS.WriteAllBytes(FS.Local, templatesDir / info.short_name + ".crvm", ba); + + Console.WriteLine($"Installed template {info.short_name}"); + } + + ms.Close(); + + } + else if(dd.Arguments.Length == 1) + { + + var conf = ""; + each(var option : dd.Options) + { + if(option.Key == "conf") + { + conf = option.Value; + } + } + + if(FS.Local.FileExists("cross.json")) + { + var proj = Json.Decode(FS.ReadAllText(FS.Local,"cross.json")); + var name = proj.info.short_name; + + if(proj.info.type != "template") + { + Console.WriteLine("The project is not a template"); + return 1; + } + if(TypeOf(name) != "String") + { + Console.WriteLine("The tool does not have a name"); + return 1; + } + FS.Local.CreateDirectory(templatesDir); + var templateFile = templatesDir / name + ".crvm"; + + if(nobuild) + { + var nameVer = $"{proj.name}-{proj.version}.crvm"; + var buildDir = TypeOf(proj.bin_directory) == "String" ? proj.bin_directory : "bin"; + output = ./buildDir/nameVer; + if(!FS.Local.FileExists(output)) + { + Console.WriteLine($"ERROR: file {output} does not exist."); + return 1; + } + + } + else + { + var pm = Tesses.CrossLang.PackageManager(); + pm.Offline = offline; + var bt = Tesses.CrossLang.BuildTool(pm); + bt.Config = conf; + output = bt.BuildProject(buildPath).Output; + } + + 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}"); + } + copyFile(output,toolFile); + return 0; + } + else + { + + Console.WriteLine("The current directory does not have a project"); + return 1; + } + } + return 0; +} \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/install-tool.tcross b/Tesses.CrossLang.Shell/src/install-tool.tcross index 26ba327..e62f6fd 100644 --- a/Tesses.CrossLang.Shell/src/install-tool.tcross +++ b/Tesses.CrossLang.Shell/src/install-tool.tcross @@ -35,8 +35,84 @@ func Tesses.CrossLang.Shell.InstallTool(dd) nobuild=true; } } - - if(dd.Arguments.Length == 1) + if(dd.Arguments.Length == 2) + { + var pm = Tesses.CrossLang.PackageManager(); + pm.Offline = offline; + var name = dd.Arguments[1]; + var version = null; + each(var opt : dd.Options) + { + if(opt.Key == "version") + version = opt.Value; + } + if(version == null) + { + var pm = Tesses.CrossLang.PackageManager(); + version = pm.GetLatest(name); + } + if(version == null) + { + Console.WriteLine("Could not get version"); + return 1; + } + var ms = new MemoryStream(true); + var ba = pm.GetPackage(name, version); + ms.WriteBlock(ba,0,ba.Length); + ms.Seek(0,0); + var exec = VM.LoadExecutable(ms); + var info = Json.Decode(exec.Info); + if(info.type != "tool") + { + Console.WriteLine("The project is not a tool"); + ms.Close(); + return 1; + } + + if(TypeOf(info.short_name) == "String") + { + var dir = toolsDir / info.short_name; + if(FS.Local.DirectoryExists(dir)) + { + each(var item : FS.Local.EnumeratePaths(dir)) + { + if(FS.Local.FileExists(item) && item.GetExtension() == ".crvm") + { + FS.Local.DeleteFile(item); + } + } + } + + FS.Local.CreateDirectory(dir); + + FS.WriteAllBytes(FS.Local, dir / info.short_name + ".crvm", ba); + + func downloadDependency(_name, _version) + { + var ms = new MemoryStream(true); + var ba = pm.GetPackage(name, version); + ms.WriteBlock(ba,0,ba.Length); + ms.Seek(0,0); + var exec = VM.LoadExecutable(ms); + var execPath = dir / $"{_name}-{_version}.crvm"; + + if(!FS.Local.FileExists(execPath)) + FS.WriteAllBytes(FS.Local, execPath , ba); + + each(var item : exec.Dependencies) + downloadDependency(item.Name, item.Version); + ms.Close(); + } + + each(var item : exec.Dependencies) + downloadDependency(item.Name, item.Version); + Console.WriteLine($"Installed tool {info.short_name}"); + } + + ms.Close(); + + } + else if(dd.Arguments.Length == 1) { var conf = ""; @@ -51,7 +127,7 @@ func Tesses.CrossLang.Shell.InstallTool(dd) if(FS.Local.FileExists("cross.json")) { var proj = Json.Decode(FS.ReadAllText(FS.Local,"cross.json")); - var name = TypeOf(proj.info.toolname) == "String" ? proj.info.toolname : proj.name; + var name = proj.info.short_name; if(proj.info.type != "tool") { @@ -78,7 +154,7 @@ func Tesses.CrossLang.Shell.InstallTool(dd) Console.WriteLine($"ERROR: file {output} does not exist."); return 1; } - + } else { diff --git a/Tesses.CrossLang.Shell/src/install-webapp.tcross b/Tesses.CrossLang.Shell/src/install-webapp.tcross new file mode 100644 index 0000000..5cba16c --- /dev/null +++ b/Tesses.CrossLang.Shell/src/install-webapp.tcross @@ -0,0 +1,204 @@ +func Tesses.CrossLang.Shell.InstallWebApp(dd) +{ + //crosslang install-webapp Tesses.CrossLang.WebApp.SomeWebApp --version=1.0.0.0-prod + var toolsDir = Env.CrossLangConfig / "WebApps"; + + var offline=false; + var buildPath = "."; + var nobuild=false; + var output=.; + each(var flag : dd.Flags) + { + if(flag == "offline") + { + offline = true; + } + else if(flag == "help") + { + Console.WriteLine("USAGE: crosslang install-webapp [flags-and-options]"); + Console.WriteLine("USAGE: crosslang install-webapp [PackageName] [flags-and-options]"); + Console.WriteLine("FLAGS:"); + Console.WriteLine("offline: build with no internet (don't fetch files)"); + Console.WriteLine("help: this help"); + Console.WriteLine("nobuild: don't build, just install (irrelevant if you specify a PackageName)"); + Console.WriteLine(); + Console.WriteLine("OPTIONS:"); + Console.WriteLine("conf=CONFIGSTRING: specify a conf string for compile_tool(s), is the property Config (irrelevant if you specify a PackageName)"); + Console.WriteLine("version=1.0.0.0-prod: specify the package version (irrelevant if you don't specify a PackageName)"); + Console.WriteLine(); + Console.WriteLine("ARGUMENTS:"); + Console.WriteLine("PackageName: the package name of a web application you want to download and install, if not specified we install the web application from the current directory"); + return 0; + } + else if(flag == "nobuild") + { + nobuild=true; + } + } + if(dd.Arguments.Length == 2) + { + var pm = Tesses.CrossLang.PackageManager(); + pm.Offline = offline; + var name = dd.Arguments[1]; + var version = null; + each(var opt : dd.Options) + { + if(opt.Key == "version") + version = opt.Value; + } + if(version == null) + { + var pm = Tesses.CrossLang.PackageManager(); + version = pm.GetLatest(name); + } + if(version == null) + { + Console.WriteLine("Could not get version"); + return 1; + } + var ms = new MemoryStream(true); + var ba = pm.GetPackage(name, version); + ms.WriteBlock(ba,0,ba.Length); + ms.Seek(0,0); + var exec = VM.LoadExecutable(ms); + var info = Json.Decode(exec.Info); + if(info.type != "webapp") + { + Console.WriteLine("The project is not a web application"); + ms.Close(); + return 1; + } + + if(TypeOf(info.short_name) == "String") + { + var dir = toolsDir / info.short_name; + if(FS.Local.DirectoryExists(dir)) + { + each(var item : FS.Local.EnumeratePaths(dir)) + { + if(FS.Local.FileExists(item) && item.GetExtension() == ".crvm") + { + FS.Local.DeleteFile(item); + } + } + } + + FS.Local.CreateDirectory(dir); + + FS.WriteAllBytes(FS.Local, dir / info.short_name + ".crvm", ba); + + func downloadDependency(_name, _version) + { + var ms = new MemoryStream(true); + var ba = pm.GetPackage(name, version); + ms.WriteBlock(ba,0,ba.Length); + ms.Seek(0,0); + var exec = VM.LoadExecutable(ms); + var execPath = dir / $"{_name}-{_version}.crvm"; + + if(!FS.Local.FileExists(execPath)) + FS.WriteAllBytes(FS.Local, execPath , ba); + + each(var item : exec.Dependencies) + downloadDependency(item.Name, item.Version); + ms.Close(); + } + + each(var item : exec.Dependencies) + downloadDependency(item.Name, item.Version); + Console.WriteLine($"Installed web application {info.short_name}"); + } + + ms.Close(); + + } + else if(dd.Arguments.Length == 1) + { + + var conf = ""; + each(var option : dd.Options) + { + if(option.Key == "conf") + { + conf = option.Value; + } + } + + if(FS.Local.FileExists("cross.json")) + { + var proj = Json.Decode(FS.ReadAllText(FS.Local,"cross.json")); + var name = proj.info.short_name; + + if(proj.info.type != "webapp") + { + Console.WriteLine("The project is not a web application"); + return 1; + } + if(TypeOf(name) != "String") + { + Console.WriteLine("The web application does not have a name"); + return 1; + } + var toolDir = toolsDir / name; + FS.Local.CreateDirectory(toolDir); + var toolFile = toolDir / name + ".crvm"; + + if(nobuild) + { + var nameVer = $"{proj.name}-{proj.version}.crvm"; + var buildDir = TypeOf(proj.bin_directory) == "String" ? proj.bin_directory : "bin"; + + output = ./buildDir/nameVer; + if(!FS.Local.FileExists(output)) + { + Console.WriteLine($"ERROR: file {output} does not exist."); + return 1; + } + + } + else + { + var pm = Tesses.CrossLang.PackageManager(); + pm.Offline = offline; + var bt = Tesses.CrossLang.BuildTool(pm); + bt.Config = conf; + output = bt.BuildProject(buildPath).Output; + } + + 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(output,toolFile); + return 0; + } + else + { + + Console.WriteLine("The current directory does not have a project"); + return 1; + } + } + return 0; +} \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/main.tcross b/Tesses.CrossLang.Shell/src/main.tcross index d7581f1..e2ce017 100644 --- a/Tesses.CrossLang.Shell/src/main.tcross +++ b/Tesses.CrossLang.Shell/src/main.tcross @@ -36,15 +36,23 @@ func main(args) case "install-tool": return Tesses.CrossLang.Shell.InstallTool(dd); break; + case "install-webapp": + return Tesses.CrossLang.Shell.InstallWebApp(dd); + break; case "console": return Tesses.CrossLang.Shell.Console(dd); break; case "tool": return Tesses.CrossLang.Shell.Tool(dd); break; + case "webapp": + return Tesses.CrossLang.Shell.WebApp(dd); case "tool-test": return Tesses.CrossLang.Shell.ToolTest(dd); break; + case "webapp-test": + return Tesses.CrossLang.Shell.WebAppTest(dd); + break; case "add-project": return Tesses.CrossLang.Shell.AddProject(dd); break; diff --git a/Tesses.CrossLang.Shell/src/s b/Tesses.CrossLang.Shell/src/s deleted file mode 100644 index ec57b98..0000000 --- a/Tesses.CrossLang.Shell/src/s +++ /dev/null @@ -1,27 +0,0 @@ - - - else if(commandName == "install-console") - { - //crosslang install-console ConsoleApp --version=1.0.0.0-prod [--outdir=DIR] - } - else if(commandName == "install-app") - { - //crosslang install-app - } - else if(commandName == "install-template") - { - //crosslang install-template Tesses.CrossLang.Template.Console --version=1.0.0.0-prod - } - - if(commandName == "install-tool") - { - - } - else if(commandName == "console") - { - //crosslang console myfavoriteapp - } - - - - \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/tool-test.tcross b/Tesses.CrossLang.Shell/src/tool-test.tcross index 792092e..0e00898 100644 --- a/Tesses.CrossLang.Shell/src/tool-test.tcross +++ b/Tesses.CrossLang.Shell/src/tool-test.tcross @@ -22,6 +22,6 @@ func Tesses.CrossLang.Shell.ToolTest(dd) Arguments=myArgs, Options = dd.Options, Flags = dd.Flags, - ToolName = proj.Info.toolname + ToolName = proj.Info.short_name }); } \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/tools.tcross b/Tesses.CrossLang.Shell/src/tools.tcross index 6db8ff6..66b30b3 100644 --- a/Tesses.CrossLang.Shell/src/tools.tcross +++ b/Tesses.CrossLang.Shell/src/tools.tcross @@ -4,10 +4,42 @@ func Tesses.CrossLang.Shell.Tool(dd) if(dd.Arguments.Length == 1) { Console.WriteLine("List of tools:"); + if(FS.Local.DirectoryExists(dir)) each(var item : FS.Local.EnumeratePaths(dir)) { Console.WriteLine(Tesses.CrossLang.GetNameAndDescription(item / item.GetFileName() + ".crvm")); } return 0; } + else if(dd.Arguments.Length >= 2) + { + var toolname = dd.Arguments[1]; + var toolpath = dir / toolname / toolname + ".crvm"; + + if(FS.Local.FileExists(toolpath)) + { + + var env = VM.CreateEnvironment({}); + env.RegisterEverything(); + env.LockRegister(); + + env.LoadFileWithDependencies(FS.Local,toolpath); + var myArgs = []; + for(var i = 2; i < dd.Arguments.Count; i++) + { + myArgs.Add(dd.Arguments[i]); + } + return env.GetDictionary().RunTool({ + Arguments=myArgs, + Options = dd.Options, + Flags = dd.Flags, + ToolName = toolname + }); + } + else { + Console.WriteLine($"Could not find tool with name {toolname}."); + return 1; + } + } + } \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/webapp-test.tcross b/Tesses.CrossLang.Shell/src/webapp-test.tcross new file mode 100644 index 0000000..e6796fc --- /dev/null +++ b/Tesses.CrossLang.Shell/src/webapp-test.tcross @@ -0,0 +1,38 @@ +func Tesses.CrossLang.Shell.WebAppTest(dd) +{ + var port = 4206; + + each(var item : dd.Options) + { + if(item.Key == "port") + { + var thePort = ParseLong(item.Value); + if(TypeOf(thePort) == "Long") port = thePort; + } + } + + + var pm = Tesses.CrossLang.PackageManager(); + pm.Offline = false; + var bt = Tesses.CrossLang.BuildTool(pm); + + + var proj=bt.BuildProject("."); + + var output = proj.Output; + + var env = VM.CreateEnvironment({}); + env.RegisterEverything(); + env.LockRegister(); + + env.LoadFileWithDependencies(FS.Local,output); + var myArgs = [output.ToString()]; + for(var i = 1; i < dd.Arguments.Count; i++) + { + myArgs.Add(dd.Arguments[i]); + } + var res = env.GetDictionary().WebAppMain(myArgs); + + + Net.Http.ListenSimpleWithLoop(res, port); +} \ No newline at end of file diff --git a/Tesses.CrossLang.Shell/src/webapp.tcross b/Tesses.CrossLang.Shell/src/webapp.tcross new file mode 100644 index 0000000..bdaf852 --- /dev/null +++ b/Tesses.CrossLang.Shell/src/webapp.tcross @@ -0,0 +1,54 @@ +func Tesses.CrossLang.Shell.WebApp(dd) +{ + var dir = Env.CrossLangConfig / "WebApps"; + if(dd.Arguments.Length == 1) + { + Console.WriteLine("List of web applications:"); + Console.WriteLine("Use --port=PORT to set port"); + + if(FS.Local.DirectoryExists(dir)) + each(var item : FS.Local.EnumeratePaths(dir)) + { + Console.WriteLine(Tesses.CrossLang.GetNameAndDescription(item / item.GetFileName() + ".crvm")); + } + return 0; + } + else if(dd.Arguments.Length >= 2) + { + var webappname = dd.Arguments[1]; + var webapppath = dir / webappname / webappname + ".crvm"; + var port = 4206; + each(var item : dd.Options) + { + if(item.Key == "port") + { + var thePort = ParseLong(item.Value); + if(TypeOf(thePort) == "Long") port = thePort; + } + } + + if(FS.Local.FileExists(webapppath)) + { + + var env = VM.CreateEnvironment({}); + env.RegisterEverything(); + env.LockRegister(); + + env.LoadFileWithDependencies(FS.Local,webapppath); + var myArgs = [webapppath.ToString()]; + for(var i = 2; i < dd.Arguments.Count; i++) + { + myArgs.Add(dd.Arguments[i]); + } + var res = env.GetDictionary().WebAppMain(myArgs); + + + Net.Http.ListenSimpleWithLoop(res, port); + } + else { + Console.WriteLine($"Could not find web application with name {toolname}."); + return 1; + } + } + +} \ No newline at end of file