public override void Run() { string name = string.Format("./slipe-{0}", DateTime.Now.ToShortDateString()); string path = name + ".zip"; new WebClient().DownloadFile("http://mta-slipe.com/slipe-core.zip", path); ZipFile.ExtractToDirectory(path, name); // copy Slipe/Core from zip to project string sourcePath = name + "/Slipe/Core"; string destinationPath = "./Slipe/Core"; if (Directory.Exists(destinationPath)) { Directory.Delete(destinationPath, true); } foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(sourcePath, destinationPath)); } foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(sourcePath, destinationPath), true); } SlipeConfig newConfig = ConfigHelper.Read(name + "/.slipe"); SlipeModule newModuleConfig = new SlipeModule(); // locate core module config for (int i = 0; i < newConfig.modules.Count; i++) { var module = newConfig.modules[i]; if (module.name == "SlipeCore") { newModuleConfig = module; break; } } for (int i = 0; i < config.modules.Count; i++) { var module = config.modules[i]; if (module.name == "SlipeCore") { config.modules[i] = newModuleConfig; break; } } // clean up Directory.Delete(name, true); File.Delete(path); }
public override void Run() { if (parameters.Count < 1) { throw new SlipeException("Please specify the module name, syntax: \n" + Template + " {filepath or url}"); } string pathOrUrl = parameters[0]; string path; Uri uriResult; bool isUrl = Uri.TryCreate(pathOrUrl, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (isUrl) { path = "./DownloadedModule.zip"; new WebClient().DownloadFile(pathOrUrl, path); } else { path = pathOrUrl; } if (!File.Exists(path)) { throw new SlipeException("Unable to find file at " + path); } string tempDir = path.Replace(".zip", ""); ZipFile.ExtractToDirectory(path, tempDir); SlipeModule module = ConfigHelper.ReadModule(tempDir + "/.slipe"); foreach (SlipeModule existingModule in config.modules) { if (existingModule.name == module.name) { Directory.Delete(existingModule.path, true); module.path = existingModule.path; config.modules.Remove(existingModule); break; } } string targetDirectory = module.path; Directory.Move(tempDir, targetDirectory); config.modules.Add(module); if (isUrl) { File.Delete(path); } }
public override void Run() { if (parameters.Count < 1) { throw new SlipeException("Please specify the module name, syntax: \n" + Template + " {name} [-directory {directory}]"); } string name = parameters[0]; string directory = "ExportedModules/" + name; if (options.ContainsKey("directory")) { directory = options["directory"]; } SlipeModule module = new SlipeModule(); bool found = false; foreach (SlipeModule slipeModule in config.modules) { if (slipeModule.name == name) { module = slipeModule; found = true; break; } } if (!found) { throw new SlipeException("No module by the name of '" + name + "' can be found in the configs."); } CopyFiles(module.path + "/DLL", directory + "/DLL"); CopyFiles(module.path + "/Lua", directory + "/Lua"); SlipeModule exportModule = new SlipeModule() { assetDirectories = module.assetDirectories, systemComponents = module.systemComponents, backingLua = module.backingLua, name = module.name, dlls = module.dlls }; ConfigHelper.WriteModule(exportModule, directory + "/.slipe"); if (options.ContainsKey("zip")) { ZipFile.CreateFromDirectory(directory, directory + ".zip"); Directory.Delete(directory, true); } }
private void CompileModule(string moduleName) { SlipeModule moduleConfig = config.modules.Find(module => module.name == moduleName); if (moduleConfig.type != "internal") { throw new SlipeException("Only internal modules can be compiled"); } string basePath = moduleConfig.path; string buildPath = basePath + "/Build"; string clientBuildPath = buildPath + "/Client"; string serverBuildPath = buildPath + "/Server"; string distPath = basePath + "/Lua/Compiled"; string clientDistPath = basePath + "/Lua/Compiled/Client"; string serverDistPath = basePath + "/Lua/Compiled/Server"; string dllPath = basePath + "/DLL"; List <string> dlls = GetDlls(moduleName); PrepareBuildDirectory(buildPath); if (!options.ContainsKey("server-only")) { PrepareDistDirectory(clientDistPath); foreach (string project in moduleConfig.compileTargets.client) { CopySourceFiles(basePath + "/" + project, clientBuildPath + "/" + project); } CompileSourceFiles(clientBuildPath, clientDistPath, dlls.ToArray(), true); foreach (string project in moduleConfig.compileTargets.client) { CopyDlls(basePath + "/" + project, dllPath); } } if (!options.ContainsKey("client-only")) { PrepareDistDirectory(serverDistPath); foreach (string project in moduleConfig.compileTargets.server) { CopySourceFiles(basePath + "/" + project, serverBuildPath + "/" + project); } CompileSourceFiles(serverBuildPath, serverDistPath, dlls.ToArray(), true); foreach (string project in moduleConfig.compileTargets.server) { CopyDlls(basePath + "/" + project, dllPath); } } }
private void UpdateCoreModule() { string name = string.Format("./slipe-{0}", DateTime.Now.ToShortDateString().Replace("/", "-").Replace("\\", "-")); string path = name + ".zip"; string coreUrl = options.ContainsKey("dev") ? Urls.devResourceTemplateUrl : Urls.resourceTemplateUrl; new WebClient().DownloadFile(coreUrl, path); ZipFile.ExtractToDirectory(path, name); // copy Slipe/Core from zip to project string sourcePath = name + "/Slipe/Core"; string destinationPath = "./Slipe/Core"; CopyFiles(sourcePath, destinationPath); CopyFiles(name + "/Slipe/Compiler", "./Slipe/Compiler"); CopyFiles(name + "/Slipe/Lua", "./Slipe/Lua"); SlipeConfig newConfig = ConfigHelper.Read(name + "/.slipe"); SlipeModule newModuleConfig = new SlipeModule(); // locate core module config for (int i = 0; i < newConfig.modules.Count; i++) { var module = newConfig.modules[i]; if (module.name == "SlipeCore") { newModuleConfig = module; break; } } for (int i = 0; i < config.modules.Count; i++) { var module = config.modules[i]; if (module.name == "SlipeCore") { config.modules[i] = newModuleConfig; break; } } // clean up Directory.Delete(name, true); File.Delete(path); }
public override void ParseArguments(string[] args) { config = ConfigHelper.Read(); base.ParseArguments(args); if (options.ContainsKey("module")) { SlipeConfig config = ConfigHelper.Read(); foreach (SlipeModule module in config.modules) { if (module.name == options["module"]) { targetModule = module; targetsModule = true; break; } } } }
public override void Run() { if (parameters.Count < 1) { throw new SlipeException("Please specify the project name, syntax: \n" + Template + " {name} [-directory {directory}]"); } string name = parameters[0]; string directory = "Modules/" + name; if (options.ContainsKey("directory")) { directory = options["directory"]; } if (Directory.Exists(directory)) { throw new SlipeException("The directory \"" + directory + "\" already exists."); } Directory.CreateDirectory(directory); SlipeModule module = new SlipeModule() { type = "internal", compileTargets = new SlipeConfigCompileTarget() { client = new List <string>(), server = new List <string>() }, name = name, path = directory, assetDirectories = new List <SlipeAssetDirectory>(), systemComponents = new List <string>(), backingLua = new List <string>(), dlls = new List <string>() }; Console.WriteLine(JsonConvert.SerializeObject(module)); config.modules.Add(module); }
private List <string> GetModuleDlls(string moduleName) { SlipeModule moduleConfig = config.modules.Find(module => module.name == moduleName); string basePath = moduleConfig.path; string dllPath = basePath + "/DLL"; List <string> dlls = new List <string>(); if (!Directory.Exists(dllPath)) { return(dlls); } string[] files = Directory.GetFiles(dllPath, "", SearchOption.AllDirectories); foreach (string file in files) { dlls.Add(file.Replace(".dll", "!")); } return(dlls); }
public override void Run() { if (parameters.Count < 1) { throw new SlipeException("Please specify the project name, syntax: \n" + Template + " {name}"); } if (!options.ContainsKey("y")) { Console.WriteLine("Are you sure you wish to proceed? This action can not be undone. y/n"); if (Console.ReadKey().Key != ConsoleKey.Y) { return; } } string name = parameters[0]; SlipeModule module = config.modules.Find((module) => module.name == name); DirectoryInfo directoryInfo = new DirectoryInfo(module.path); foreach (FileInfo file in directoryInfo.GetFiles()) { file.Delete(); } foreach (DirectoryInfo directory in directoryInfo.GetDirectories()) { directory.Delete(true); } Directory.Delete(module.path); config.modules.Remove(module); }
public override void Run() { if (parameters.Count < 1) { throw new SlipeException("Please specify the module name, syntax: \n" + Template + " {filepath or url} [-directory {directory}]"); } string pathOrUrl = parameters[0]; string path; Uri uriResult; bool isUrl = Uri.TryCreate(pathOrUrl, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (isUrl) { path = "/DownloadedModule.zip"; new WebClient().DownloadFile("http://mta-slipe.com/slipe-core.zip", path); } else { path = pathOrUrl; } if (!File.Exists(path)) { throw new SlipeException("Unable to find file at " + path); } string tempDir = path.Replace(".zip", ""); ZipFile.ExtractToDirectory(path, tempDir); SlipeModule module = ConfigHelper.ReadModule(tempDir + "/.slipe"); foreach (SlipeModule existingModule in config.modules) { if (existingModule.name == module.name) { if (isUrl) { Directory.Delete(path, true); } Directory.Delete(tempDir, true); throw new SlipeException("A module with the name '" + module.name + "' already exists, use `slipe update-module` if you wish to update this module"); } } string targetDirectory = "./Modules/" + module.name; if (options.ContainsKey("directory")) { targetDirectory = options["directory"]; } Directory.Move(tempDir, targetDirectory); config.modules.Add(module); if (isUrl) { Directory.Delete(path, true); } }