Esempio n. 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);
              }
        }
Esempio n. 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());
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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();
            }
              }
        }
Esempio n. 8
0
 public RJSRunner(RJSConfig config, Options options)
 {
     this.config = config;
       this.options = options;
 }
Esempio n. 9
0
 public RJSConfigBuilder(Options options)
 {
     this.options = options;
     extensionIncludes = new[] { ".js", options.ViewExtension };
 }
Esempio n. 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);
                    }
                }
            }
        }