protected override void OnRun() { var cmdPaths = CmdLine.GetPaths(); var workingDir = cmdPaths.Length > 0 ? cmdPaths[0] : Environment.CurrentDirectory; var outputPath = CmdLine.Property("out", Path.Combine(workingDir, "dictionary.md")); var tables = Directory.GetFiles(workingDir, "*.table", SearchOption.AllDirectories) .Select(dir => RantDictionaryTable.FromStream(dir, File.Open(dir, FileMode.Open))) .OrderBy(table => table.Name) .ToList(); if (tables.Count == 0) { Console.WriteLine("No tables found."); return; } using (var writer = new StreamWriter(outputPath)) { foreach (var table in tables) { writer.WriteLine($"## {table.Name}"); writer.WriteLine($"**Entries:** {table.EntryCount}\n"); if (table.HiddenClasses.Any()) { writer.WriteLine($"**Hidden classes:** {table.HiddenClasses.Select(cl => $"`{cl}`").Aggregate((c, n) => $"{c}, {n}")}\n"); } // Write subtype list writer.WriteLine($"### Subtypes\n"); for (int i = 0; i < table.TermsPerEntry; i++) { writer.WriteLine($"{i + 1}. {table.GetSubtypesForIndex(i).Select(st => $"`{st}`").Aggregate((c, n) => $"{c}, {n}")}"); } writer.WriteLine(); // Write classes writer.WriteLine($"### Classes\n"); foreach (var cl in table.GetClasses().OrderBy(cl => cl)) { writer.WriteLine($"- `{cl}` ({table.GetEntries().Count(e => e.ContainsClass(cl))})"); } writer.WriteLine(); } } }
protected override void OnRun() { foreach (var path in CmdLine.GetPaths()) { try { Console.Write($"Building {path}..."); var pgm = RantProgram.CompileFile(path); var pgmpath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + ".rantpgm"); pgm.SaveToFile(pgmpath); Console.WriteLine(" Done."); } catch (RantCompilerException ex) { throw new Exception($"Build failed for {path}.\n{ex.Message}\n"); } catch (Exception ex) { throw new Exception($"Error while building: {ex.Message}"); } } }
protected override void OnRun() { var pkg = new RantPackage(); var paths = CmdLine.GetPaths(); bool compress = !CmdLine.Flag("no-compress"); Console.WriteLine("Packing..."); string contentDir = Path.GetFullPath(paths.Length == 0 ? Environment.CurrentDirectory : paths[0]); Pack(pkg, contentDir); string outputPath; string infoPath = Path.Combine(contentDir, "rantpkg.json"); if (!File.Exists(infoPath)) { throw new FileNotFoundException("rantpkg.json missing from root directory."); } var info = JsonConvert.DeserializeObject <PackInfo>(File.ReadAllText(infoPath)); pkg.Title = info.Title; pkg.Authors = info.Authors; pkg.Version = RantPackageVersion.Parse(!string.IsNullOrWhiteSpace(CmdLine.Property("version")) ? CmdLine.Property("version") : info.Version); pkg.Description = info.Description; pkg.ID = info.ID; pkg.Tags = info.Tags; foreach (var dep in info.Dependencies) { pkg.AddDependency(dep); } // -out property overrides rantpkg.json's output path if (!string.IsNullOrWhiteSpace(CmdLine.Property("out"))) { outputPath = Path.Combine(CmdLine.Property("out"), $"{pkg.ID}-{pkg.Version}.rantpkg"); Directory.CreateDirectory(CmdLine.Property("out")); } // Otherwise, use rantpkg.json's "out" property else if (!string.IsNullOrWhiteSpace(info.OutputPath)) { outputPath = Path.Combine(contentDir, info.OutputPath, $"{pkg.ID}-{pkg.Version}.rantpkg"); Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } // If it doesn't have one, put it in the package content directory else { outputPath = Path.Combine(Directory.GetParent(contentDir).FullName, $"{pkg.ID}-{pkg.Version}.rantpkg"); } Console.WriteLine($"Compression: {(compress ? "yes" : "no")}"); Console.WriteLine(compress ? "Compressing and saving..." : "Saving..."); pkg.Save(outputPath, compress); Console.WriteLine("\nPackage saved to " + outputPath.Replace('\\', '/')); Console.ResetColor(); }