Exemple #1
0
        static void Main(string[] args)
        {
            try {
            var hasNode = IO.ExistsOnPath("node.exe");
            if (!hasNode) {
              Console.WriteLine("Exiting - Node is not installed.");
              Console.WriteLine("Please visit http://nodejs.org/ to install nodejs.");
              return;
            }

            var options = new Options();
            if(CommandLineParser.Default.ParseArguments(args, options)) {
            #if DEBUG
            options.Verbose = true;
            #endif

              var configBuilder = new RJSConfigBuilder(options);
              var config = configBuilder.Build();

              if(options.Build || options.Generate) {
            IO.WriteConfiguration(config, options);
              }

              if(options.Build && !options.Generate) {
            var runner = new RJSRunner(config, options);
            runner.Run();
              }
            }
              } catch(Exception ex) {
            Console.WriteLine(ex.Message);
              }
        }
Exemple #2
0
        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());
            }
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
        public static JObject GetBaseConfiguration(Options options)
        {
            if(!string.IsNullOrEmpty(options.ConfigurationSource)) {
                var fullPath = options.ConfigurationSource;
                if(!Path.IsPathRooted(fullPath)) {
                    fullPath = Path.Combine(Directory.GetCurrentDirectory(), fullPath);
                }

                return ReadConfigFromFile(fullPath, options);
            }

            var configPath = Path.Combine(Directory.GetCurrentDirectory(), "optimizer.base.js");
            if(File.Exists(configPath)) {
                return ReadConfigFromFile(configPath, options);
            }

            return ReadConfigFromResource(options);
        }
Exemple #6
0
        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);
                }
            }
        }
Exemple #7
0
        static void Main(string[] args)
        {
            var options = new Options();
              if(CommandLineParser.Default.ParseArguments(args, options)) {
            #if DEBUG
            options.Verbose = true;
            #endif

            var configBuilder = new RJSConfigBuilder(options);
            var config = configBuilder.Build();

            if(options.Build || options.Generate) {
              IO.WriteConfiguration(config, options);
            }

            if(options.Build && !options.Generate) {
              var runner = new RJSRunner(config, options);
              runner.Run();
            }
              }
        }
Exemple #8
0
 public RJSRunner(RJSConfig config, Options options)
 {
     this.config = config;
       this.options = options;
 }
 public RJSConfigBuilder(Options options)
 {
     this.options = options;
     extensionIncludes = new[] { ".js", options.ViewExtension };
 }
Exemple #10
0
        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);
                    }
                }
            }
        }