public static void WriteConfiguration(RJSConfig info, Options options) { options.Log(info.Config); using (var file = File.Create(info.BuildFilePath)) using (var writer = new StreamWriter(file)) { writer.Write(info.Config.ToString()); } }
public void Run() { if (File.Exists(config.OutputPath)) { options.Log("Deleting old output file.", true); var info = new FileInfo(config.OutputPath); using (info.Create()) { //effectively deletes the contents of the file //calling delete seamed to break the following optimizer code, not sure why } } if (!File.Exists(config.OptimizerPath)) { using (var stream = IO.ReadFromResource("r.js")) using (var file = File.OpenWrite(config.OptimizerPath)) { stream.CopyTo(file); } } if (options.Loader == Options.LoaderOptions.Almond) { if (!File.Exists(config.AlmondPath)) { using (var stream = IO.ReadFromResource("almond-custom.js")) using (var file = File.OpenWrite(config.AlmondPath)) { stream.CopyTo(file); } } } var command = "/C node \"" + config.OptimizerPath + "\" -o \"" + config.BuildFilePath + "\""; var process = new Process { StartInfo = new ProcessStartInfo { FileName = "cmd.exe", Arguments = command, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true, }, EnableRaisingEvents = true }; process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data); process.ErrorDataReceived += (s, e) => Console.Error.WriteLine(e.Data); process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); process.CancelOutputRead(); process.CancelErrorRead(); }
public static void WriteConfiguration(RJSConfig info, Options options) { options.Log(info.Config); using (var file = File.Create(info.BuildFilePath)) { using (var writer = new StreamWriter(file)) { writer.Write(info.Config.ToString()); } } }
static JObject ReadConfigFromResource(Options options) { options.Log("Using default base configuration."); using(var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Optimizer.optimizer.base.js")) using(var streamReader = new StreamReader(stream)) using(var jsonReader = new JsonTextReader(streamReader)) { return JObject.Load(jsonReader); } }
static JObject ReadConfigFromFile(string path, Options options) { options.Log("Reading configuration from " + path); using(var reader = File.OpenRead(path)) using(var streamReader = new StreamReader(reader)) using(var jsonReader = new JsonTextReader(streamReader)) { return JObject.Load(jsonReader); } }
static JObject ReadConfigFromFile(string path, Options options) { options.Log("Reading configuration from " + path); using (var reader = File.OpenRead(path)) { using (var streamReader = new StreamReader(reader)) { using (var jsonReader = new JsonTextReader(streamReader)) { return(JObject.Load(jsonReader)); } } } }
static JObject ReadConfigFromResource(Options options) { options.Log("Using default base configuration."); using (var stream = ReadFromResource("optimizer.base.js")) { using (var streamReader = new StreamReader(stream)) { using (var jsonReader = new JsonTextReader(streamReader)) { return(JObject.Load(jsonReader)); } } } }
void BuildConfig(RJSConfig info) { var config = info.Config; if (options.Loader == Options.LoaderOptions.Almond) { options.Log("Configuring for deploy with almond (custom)."); JSON.EnsureProperty(config, "name", amdPath + "/" + almondName); JSON.EnsureProperty(config, "mainConfigFile", info.MainPath); JSON.EnsureProperty(config, "wrap", true); } else { options.Log("Configuring for deploy with require."); JSON.EnsureProperty(config, "name", "main"); } var insertRequire = JSON.EnsureArray(config, "insertRequire"); insertRequire.Add("main"); JSON.EnsureProperty(config, "baseUrl", info.BaseUrl); JSON.EnsureProperty(config, "out", info.OutputPath); var include = JSON.EnsureArray(config, "include"); if (include.Count < 1) { foreach (var item in info.Includes) { include.Add(item); } } }
static JObject ReadConfigFromFile(string path, Options options) { options.Log("Reading configuration from " + path); using (var reader = File.OpenRead(path)) { using (var streamReader = new StreamReader(reader)) { var json = streamReader.ReadToEnd(); //allows i.e. module.exports = { } instead of a plain json, so you'd have intellisense in VS2012 var index = 0; if ((index = json.IndexOf("{")) >= 0) json = json.Substring(index); json = Regex.Replace(json, "\\%LANG\\%", options.Lang, RegexOptions.IgnoreCase); //replace // comments with /* comments */ var jsonFixed = Regex.Replace(json, "(.*)//(.*)\r\n", "$1/*$2*/\r\n", RegexOptions.Multiline); return JObject.Parse(jsonFixed); } } }
static JObject ReadConfigFromResource(Options options) { options.Log("Using default base configuration."); using (var stream = ReadFromResource("optimizer.base.js")) { using (var streamReader = new StreamReader(stream)) { using (var jsonReader = new JsonTextReader(streamReader)) { return JObject.Load(jsonReader); } } } }