public static int Main(string[] args) { var arguments = new List<string>(); arguments.AddRange(args); var configuration = GetConfigurationFromArguments(arguments); configuration.LogLevel = LogLevel.Warn; if(configuration.Help) return -1; if (arguments.Count == 0) { WriteHelp(); return -1; } string inputDirectoryPath, inputFilePattern; if (Directory.Exists(arguments[0])) { inputDirectoryPath = arguments[0]; inputFilePattern = "*.less"; } else { inputDirectoryPath = Path.GetDirectoryName(arguments[0]); if (string.IsNullOrEmpty(inputDirectoryPath)) inputDirectoryPath = "." + Path.DirectorySeparatorChar; inputFilePattern = Path.GetFileName(arguments[0]); if (!Path.HasExtension(inputFilePattern)) inputFilePattern = Path.ChangeExtension(inputFilePattern, "less"); } var outputDirectoryPath = string.Empty; var outputFilename = string.Empty; if (arguments.Count > 1) { if (Directory.Exists(arguments[1])) { outputDirectoryPath = arguments[1]; } else { outputDirectoryPath = Path.GetDirectoryName(arguments[1]); outputFilename = Path.GetFileName(arguments[1]); if (!Path.HasExtension(outputFilename)) outputFilename = Path.ChangeExtension(outputFilename, "css"); } } if (string.IsNullOrEmpty(outputDirectoryPath)) { outputDirectoryPath = inputDirectoryPath; } else { Directory.CreateDirectory(outputDirectoryPath); } if (HasWildcards(inputFilePattern)) { if (!string.IsNullOrEmpty(outputFilename)) { Console.WriteLine("Output filename patterns/filenames are not supported when using input wildcards. You may only specify an output directory (end the output in a directory seperator)"); return -1; } outputFilename = string.Empty; } var filenames = Directory.GetFiles(inputDirectoryPath, inputFilePattern); using (var watcher = new Watcher() { Watch = configuration.Watch }) { if (watcher.Watch && HasWildcards(inputFilePattern)) { CompilationFactoryDelegate factoryDelegate = (input) => CreationImpl(new EngineFactory(configuration).GetEngine(), input, Path.GetFullPath(outputDirectoryPath)); watcher.SetupDirectoryWatcher(Path.GetFullPath(inputDirectoryPath), inputFilePattern, factoryDelegate); } foreach (var filename in filenames) { var inputFile = new FileInfo(filename); var outputFile = string.IsNullOrEmpty(outputFilename) ? Path.Combine(outputDirectoryPath, Path.ChangeExtension(inputFile.Name, "css")) : Path.Combine(outputDirectoryPath, outputFilename); var outputFilePath = Path.GetFullPath(outputFile); CompilationDelegate compilationDelegate = () => CompileImpl(new EngineFactory(configuration).GetEngine(), inputFile.FullName, outputFilePath); Console.WriteLine("[Compile]"); var files = compilationDelegate(); if (watcher.Watch) watcher.SetupWatchers(files, compilationDelegate); } if (configuration.Watch) { WriteAbortInstructions(); } else if (filenames.Count() == 0) { Console.WriteLine("No files found matching pattern '{0}'", inputFilePattern); return -1; } while (watcher.Watch && Console.ReadKey(true).Key != ConsoleKey.Enter) { System.Threading.Thread.Sleep(200); } } return returnCode; }
public static int Main(string[] args) { var arguments = new List <string>(); arguments.AddRange(args); var configuration = GetConfigurationFromArguments(arguments); if (configuration.Help) { return(-1); } if (arguments.Count == 0) { WriteHelp(); return(-1); } var inputDirectoryPath = Path.GetDirectoryName(arguments[0]); if (string.IsNullOrEmpty(inputDirectoryPath)) { inputDirectoryPath = "." + Path.DirectorySeparatorChar; } var inputFilePattern = Path.GetFileName(arguments[0]); var outputDirectoryPath = string.Empty; var outputFilename = string.Empty; if (string.IsNullOrEmpty(inputFilePattern)) { inputFilePattern = "*.less"; } if (!Path.HasExtension(inputFilePattern)) { inputFilePattern = Path.ChangeExtension(inputFilePattern, "less"); } if (arguments.Count > 1) { outputDirectoryPath = Path.GetDirectoryName(arguments[1]); outputFilename = Path.GetFileName(arguments[1]); if (!Path.HasExtension(outputFilename)) { outputFilename = Path.ChangeExtension(outputFilename, "css"); } } if (string.IsNullOrEmpty(outputDirectoryPath)) { outputDirectoryPath = inputDirectoryPath; } else { Directory.CreateDirectory(outputDirectoryPath); } if (HasWildcards(inputFilePattern)) { if (!string.IsNullOrEmpty(outputFilename)) { Console.WriteLine("Output filename patterns/filenames are not supported when using input wildcards. You may only specify an output directory (end the output in a directory seperator)"); return(-1); } outputFilename = string.Empty; } var filenames = Directory.GetFiles(inputDirectoryPath, inputFilePattern); var engine = new EngineFactory(configuration).GetEngine(); using (var watcher = new Watcher() { Watch = configuration.Watch }) { if (watcher.Watch && HasWildcards(inputFilePattern)) { CompilationFactoryDelegate factoryDelegate = (input) => CreationImpl(engine, input, Path.GetFullPath(outputDirectoryPath)); watcher.SetupDirectoryWatcher(Path.GetFullPath(inputDirectoryPath), inputFilePattern, factoryDelegate); } foreach (var filename in filenames) { var inputFile = new FileInfo(filename); var outputFile = string.IsNullOrEmpty(outputFilename) ? Path.Combine(outputDirectoryPath, Path.ChangeExtension(inputFile.Name, "css")) : Path.Combine(outputDirectoryPath, outputFilename); var outputFilePath = Path.GetFullPath(outputFile); CompilationDelegate compilationDelegate = () => CompileImpl(engine, inputFile.FullName, outputFilePath); Console.WriteLine("[Compile]"); var files = compilationDelegate(); if (watcher.Watch) { watcher.SetupWatchers(files, compilationDelegate); } } if (configuration.Watch) { WriteAbortInstructions(); } else if (filenames.Count() == 0) { Console.WriteLine("No files found matching pattern '{0}'", inputFilePattern); return(-1); } while (watcher.Watch && Console.ReadKey(true).Key != ConsoleKey.Enter) { System.Threading.Thread.Sleep(200); } } return(returnCode); }
public static int Main(string[] args) { var arguments = new List<string>(); arguments.AddRange(args); var configuration = GetConfigurationFromArguments(arguments); if(configuration.Help) return -1; if (arguments.Count == 0) { WriteHelp(); return -1; } var inputDirectoryPath = Path.GetDirectoryName(arguments[0]); if(string.IsNullOrEmpty(inputDirectoryPath)) inputDirectoryPath = "." + Path.DirectorySeparatorChar; var inputFilePattern = Path.GetFileName(arguments[0]); var outputDirectoryPath = string.Empty; var outputFilename = string.Empty; if (string.IsNullOrEmpty(inputFilePattern)) inputFilePattern = "*.less"; if (!Path.HasExtension(inputFilePattern)) inputFilePattern = Path.ChangeExtension(inputFilePattern, "less"); if (arguments.Count > 1) { outputDirectoryPath = Path.GetDirectoryName(arguments[1]); outputFilename = Path.GetFileName(arguments[1]); outputFilename = Path.ChangeExtension(outputFilename, "css"); } if (string.IsNullOrEmpty(outputDirectoryPath)) { outputDirectoryPath = inputDirectoryPath; } else { Directory.CreateDirectory(outputDirectoryPath); } if (HasWildcards(inputFilePattern)) outputFilename = string.Empty; var filenames = Directory.GetFiles(inputDirectoryPath, inputFilePattern); var engine = new EngineFactory(configuration).GetEngine(); using (var watcher = new Watcher() { Watch = configuration.Watch }) { if (watcher.Watch && HasWildcards(inputFilePattern)) { CompilationFactoryDelegate factoryDelegate = (input) => CreationImpl(engine, input, Path.GetFullPath(outputDirectoryPath)); watcher.SetupDirectoryWatcher(Path.GetFullPath(inputDirectoryPath), inputFilePattern, factoryDelegate); } foreach (var filename in filenames) { var inputFile = new FileInfo(filename); var outputFile = string.IsNullOrEmpty(outputFilename) ? Path.Combine(outputDirectoryPath, Path.ChangeExtension(inputFile.Name, "css")) : Path.Combine(outputDirectoryPath, outputFilename); var outputFilePath = Path.GetFullPath(outputFile); CompilationDelegate compilationDelegate = () => CompileImpl(engine, inputFile.FullName, outputFilePath); Console.WriteLine("[Compile]"); var files = compilationDelegate(); if (watcher.Watch) watcher.SetupWatchers(files, compilationDelegate); } if (configuration.Watch) WriteAbortInstructions(); while (watcher.Watch && Console.ReadKey(true).Key != ConsoleKey.Enter) { System.Threading.Thread.Sleep(200); } } return returnCode; }
public static void Main(string[] args) { var arguments = new List <string>(); arguments.AddRange(args); var configuration = GetConfigurationFromArguments(arguments); if (configuration.Help) { return; } if (arguments.Count == 0) { WriteHelp(); return; } var inputDirectoryPath = Path.GetDirectoryName(arguments[0]); if (string.IsNullOrEmpty(inputDirectoryPath)) { inputDirectoryPath = ".\\"; } var inputFilePattern = Path.GetFileName(arguments[0]); var outputDirectoryPath = string.Empty; var outputFilename = string.Empty; if (string.IsNullOrEmpty(inputFilePattern)) { inputFilePattern = "*.less"; } if (!Path.HasExtension(inputFilePattern)) { inputFilePattern = Path.ChangeExtension(inputFilePattern, "less"); } if (arguments.Count > 1) { outputDirectoryPath = Path.GetDirectoryName(arguments[1]); outputFilename = Path.GetFileName(arguments[1]); outputFilename = Path.ChangeExtension(outputFilename, "css"); } else { outputDirectoryPath = inputDirectoryPath; } if (HasWildcards(inputFilePattern)) { outputFilename = string.Empty; } var filenames = Directory.GetFiles(inputDirectoryPath, inputFilePattern); var engine = new EngineFactory(configuration).GetEngine(); using (var watcher = new Watcher() { Watch = configuration.Watch }) { if (watcher.Watch && HasWildcards(inputFilePattern)) { CompilationFactoryDelegate factoryDelegate = (input) => CreationImpl(engine, input, Path.GetFullPath(outputDirectoryPath)); watcher.SetupDirectoryWatcher(Path.GetFullPath(inputDirectoryPath), inputFilePattern, factoryDelegate); } foreach (var filename in filenames) { var inputFile = new FileInfo(filename); var pathbuilder = new System.Text.StringBuilder(outputDirectoryPath + "\\"); if (string.IsNullOrEmpty(outputFilename)) { pathbuilder.Append(Path.ChangeExtension(inputFile.Name, "css")); } else { pathbuilder.Append(outputFilename); } var outputFilePath = Path.GetFullPath(pathbuilder.ToString()); CompilationDelegate compilationDelegate = () => CompileImpl(engine, inputFile.FullName, outputFilePath); Console.WriteLine("[Compile]"); var files = compilationDelegate(); if (watcher.Watch) { watcher.SetupWatchers(files, compilationDelegate); } } if (configuration.Watch) { WriteAbortInstructions(); } while (watcher.Watch && Console.ReadKey(true).Key != ConsoleKey.Enter) { System.Threading.Thread.Sleep(200); } } }