Compile() 개인적인 메소드

private Compile ( CompilerContext context, FileInfo coffeeScriptFileInfo, List includedRequiredFiles ) : JurassicCoffee.Core.Diagnostics.CompilationRecord
context CompilerContext
coffeeScriptFileInfo System.IO.FileInfo
includedRequiredFiles List
리턴 JurassicCoffee.Core.Diagnostics.CompilationRecord
예제 #1
0
        private static void CompileFile(string workingDirectory, bool compress, bool require, string externalCompilationScriptPath, DirectoryInfo outputDirectory, string fileExtension, FileInfo inputFile)
        {
            var outputFile = Path.Combine(outputDirectory.FullName, Regex.Replace(inputFile.Name, inputFile.Extension + "$", fileExtension, RegexOptions.IgnoreCase));
            System.Console.WriteLine("coffee: {0}", inputFile);
            System.Console.WriteLine("output: {0}", outputFile);

            try
            {
                using (var inputStream = new StreamReader(inputFile.OpenRead()))
                {
                    using (var outputStream = new StreamWriter(File.Open(outputFile, FileMode.Create, FileAccess.Write)))
                    {
                        var compiler = new CoffeeCompiler();

                        if (!string.IsNullOrEmpty(externalCompilationScriptPath))
                            compiler.CoffeeCompilerScriptPath = externalCompilationScriptPath;

                        if (compress)
                            compiler.PostCompilationActions.Add(Core.Plugins.YahooYuiCompressor.Compress);

                        if (!require)
                            compiler.PreCompilationActions.Clear();

                        compiler.Compile(workingDirectory, inputStream, outputStream);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            var input = args.FirstOrDefault();
            var output = string.Empty;
            var workingDirectory = string.Empty;
            var compress = false;
            var require = true;
            var externalCompilationScriptPath = string.Empty;

            var p = new OptionSet {
                { "o|output=", "set output file", f => output = f },
                { "w|workingdir=", "set working directory", w => workingDirectory = w },
                { "c|compression","enable compression", c => compress = true },
                { "d|disableimport","disable #= require statements", d => require = false },
                { "e|external=", "set .js coffee compilation script", e => externalCompilationScriptPath = e },
                { "h|?|help","this help text", c => input = string.Empty }
            };

             p.Parse(args);

            if (string.IsNullOrEmpty(input) || !File.Exists(input)) {
                System.Console.WriteLine("[!] cannot find {0}", input);
                PrintHelp(p);
                return;
            }

            var inputFileInfo = new FileInfo(input);

            workingDirectory = string.IsNullOrEmpty(workingDirectory) ? inputFileInfo.Directory.FullName : workingDirectory;

            output = string.IsNullOrEmpty(output) ? Regex.Replace(inputFileInfo.FullName, inputFileInfo.Extension + "$", ".js", RegexOptions.IgnoreCase) : output;

            if (!string.IsNullOrEmpty(externalCompilationScriptPath)) {
                if (!File.Exists(externalCompilationScriptPath)) {
                    System.Console.WriteLine("[!] cannot find {0}", externalCompilationScriptPath);
                    PrintHelp(p);
                    return;
                }
                System.Console.WriteLine("compiling with script: {0}", externalCompilationScriptPath);
            }

            System.Console.WriteLine("compiling: {0}",input);
            System.Console.WriteLine("output: {0}", output);
            System.Console.WriteLine("workingDirectory: {0}", workingDirectory);
            System.Console.WriteLine("compression: {0}", compress);
            System.Console.WriteLine("imports: {0}", require);
            try
            {
                using (var inputStream = new StreamReader(File.OpenRead(input)))
                {
                    using(var outputStream = new StreamWriter(File.Open(output, FileMode.Create)))
                    {

                        var compiler = new CoffeeCompiler();

                        if (!string.IsNullOrEmpty(externalCompilationScriptPath))
                            compiler.CoffeeCompilerScriptPath = externalCompilationScriptPath;

                        if(compress)
                            compiler.PostCompilationActions.Add(Core.Plugins.YahooYuiCompressor.Compress);

                        if(!require)
                            compiler.PreCompilationActions.Clear();

                            compiler.Compile(workingDirectory, inputStream, outputStream);

                    }
                }

            } catch(Exception ex) {
                System.Console.WriteLine(ex.Message);
            }
        }