public void Process(ToolContext context) { foreach (WorkfileContext workContext in context.Workfiles) { string extension = Path.GetExtension(workContext.Workfile.Name).ToLower(); if (extension == ".css" || extension == ".js") { string compressed = null; using (var stream = new FileStream(workContext.Workfile.FullName, FileMode.Open, FileAccess.Read, FileShare.None)) { using (var reader = new StreamReader(stream)) { switch (extension) { case ".css": compressed = CssCompressor.Compress(reader.ReadToEnd()); break; case ".js": compressed = JavaScriptCompressor.Compress(reader.ReadToEnd()); break; } } } using (var writer = new StreamWriter(workContext.Workfile.FullName, false)) { writer.Write(compressed); } } } }
public void Process(ToolContext context) { foreach (WorkfileContext workContext in context.Workfiles) { Directory.SetCurrentDirectory(workContext.OriginalSource.DirectoryName); if (Path.GetExtension(workContext.Workfile.Name).ToLower() == ".less") { string compressed = null; using (var reader = new StreamReader(workContext.Workfile.FullName, true)) { var engine = new EngineFactory(new DotlessConfiguration() { CacheEnabled = false, MinifyOutput = false, Web = false, }).GetEngine(); compressed = engine.TransformToCss(reader.ReadToEnd(), null); IEnumerable<string> l = engine.GetImports(); } string newFileName = Path.Combine(workContext.Workfile.DirectoryName, Path.GetFileNameWithoutExtension(workContext.Workfile.Name)) + ".css"; workContext.Workfile.MoveTo(newFileName); using (var writer = new StreamWriter(newFileName, false)) { writer.Write(compressed); } } } }
public void Process(ToolContext context) { long totalLength = 0; foreach (WorkfileContext workContext in context.Workfiles) totalLength += workContext.Workfile.Length; if (totalLength > maxLength) throw new InvalidOperationException("Google Closure plugin only supports bundles up to 200K. That's because this plugin is hacky."); foreach (WorkfileContext workContext in context.Workfiles) { var request = WebRequest.Create("http://closure-compiler.appspot.com/compile"); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; using (var fileReader = new StreamReader(workContext.Workfile.FullName)) { var data = string.Format( postFormat, HttpUtility.UrlEncode(fileReader.ReadToEnd()), "WHITESPACE_ONLY", "text", "compiled_code" ); using (var dataStream = new StreamWriter(request.GetRequestStream())) { dataStream.Write(data); } } using (var responseStream = request.GetResponse().GetResponseStream()) { var streamReader = new StreamReader(responseStream); using (var writer = new StreamWriter(workContext.Workfile.FullName, false)) { writer.Write(streamReader.ReadToEnd()); } } } }
public void Process(ToolContext context) { // Combine and save workfiles into target output file using (var writer = new StreamWriter(context.OutputFile.FullName, false, Encoding.UTF8, 1024)) { foreach (WorkfileContext workfile in context.Workfiles) { using (var reader = new StreamReader(workfile.Workfile.FullName, true)) { char[] buffer = new char[1024]; int numRead = 0; while ((numRead = reader.Read(buffer, 0, buffer.Length)) > 0) { writer.Write(buffer, 0, numRead); } } writer.WriteLine(); } } }