mirror of
https://onedev.site.tesses.net/crosslang/crosslangextras
synced 2026-02-08 17:15:45 +00:00
156 lines
5.0 KiB
Plaintext
156 lines
5.0 KiB
Plaintext
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 = new 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 = new 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 = new Tesses.CrossLang.PackageManager();
|
|
pm.Offline = offline;
|
|
var bt = new 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;
|
|
} |