/// <summary> /// based on the extension, create the required compiler and compile /// </summary> /// <param name="path"></param> public CompileResults Process(OrangeJob job) { ICompiler compiler = null; // ensure we got a valid path if (String.IsNullOrEmpty(job.Path)) { throw new Exception("The path passed to Orange Compiler must be a valid LESS, CoffeeScript, or Sass file"); } FileInfo f = new FileInfo(job.Path); // OutputPath can be relative - calculate the correct absolute path var targetFile = Path.Combine(job.OutputPath, Path.GetFileName(job.Path)); string outPath = targetFile.Substring(0, targetFile.LastIndexOf('.')); string outExt = ""; switch (job.Type) { case OrangeJob.JobType.Compile: outExt = (f.Extension.ToLower() == ".coffee" || f.Extension.ToLower() == ".ts") ? ".js" : ".css"; break; case OrangeJob.JobType.Minify: outExt = (f.Extension.ToLower() == ".css") ? ".min.css" : ".min.js"; break; case OrangeJob.JobType.Optimize: outExt = f.Extension.ToLower(); break; } switch (f.Extension.ToLower()) { case ".ts": compiler = new TypeScriptCompiler(); break; case ".js": compiler = new JsMinifier(); break; case ".css": compiler = new CssMinifier(); break; case ".less": compiler = new LessCompiler(); break; case ".sass": compiler = new SassCompiler(); break; case ".scss": compiler = new ScssCompiler(); break; case ".coffee": compiler = new CoffeeCompiler(); break; case ".png": case ".gif": case ".tiff": case ".bmp": compiler = new PNGCompressor(); break; case ".jpg": case ".jpeg": compiler = new JPGCompressor(); break; default: throw new NotImplementedException(); } // create the compiled source outPath += outExt; bool exists = File.Exists(outPath); compiler.OutputDataReceived += (sender, e) => { this.OnOutputDataReceived(sender, e); }; var results = compiler.Compile(job.Path, outPath); if (results == null) { results = new CompileResults() { Success = true, InputPath = job.Path, OutputPath = outPath, IsNewFile = !exists }; } return(results); }
/// <summary> /// based on the extension, create the required compiler and compile /// </summary> /// <param name="path"></param> public CompileResults Process(OrangeJob job) { ICompiler compiler = null; // ensure we got a valid path if (String.IsNullOrEmpty(job.Path)) throw new Exception("The path passed to Orange Compiler must be a valid LESS, CoffeeScript, or Sass file"); FileInfo f = new FileInfo(job.Path); // OutputPath can be relative - calculate the correct absolute path var targetFile = Path.Combine(job.OutputPath, Path.GetFileName(job.Path)); string outPath = targetFile.Substring(0, targetFile.LastIndexOf('.')); string outExt = ""; switch (job.Type) { case OrangeJob.JobType.Compile: outExt = (f.Extension.ToLower() == ".coffee" || f.Extension.ToLower() == ".ts") ? ".js" : ".css"; break; case OrangeJob.JobType.Minify: outExt = (f.Extension.ToLower() == ".css") ? ".min.css" : ".min.js"; break; case OrangeJob.JobType.Optimize: outExt = f.Extension.ToLower(); break; } switch (f.Extension.ToLower()) { case ".ts": compiler = new TypeScriptCompiler(); break; case ".js": compiler = new JsMinifier(); break; case ".css": compiler = new CssMinifier(); break; case ".less": compiler = new LessCompiler(); break; case ".sass": compiler = new SassCompiler(); break; case ".scss": compiler = new ScssCompiler(); break; case ".coffee": compiler = new CoffeeCompiler(); break; case ".png": case ".gif": case ".tiff": case ".bmp": compiler = new PNGCompressor(); break; case ".jpg": case ".jpeg": compiler = new JPGCompressor(); break; default: throw new NotImplementedException(); } // create the compiled source outPath += outExt; bool exists = File.Exists(outPath); compiler.OutputDataReceived += (sender, e) => { this.OnOutputDataReceived(sender, e); }; var results = compiler.Compile(job.Path, outPath); if (results == null) { results = new CompileResults() { Success = true, InputPath = job.Path, OutputPath = outPath, IsNewFile = !exists }; } return results; }