Esempio n. 1
0
        /// <summary>
        /// Creates a deploymentjob from the command line options specified.
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        static DeploymentJob CreateJob(CommandLineOptions options)
        {
            var job = new DeploymentJob
            {
                S3BucketName = options.S3Bucket,
                AwsKey = options.AwsKey,
                AwsSecretKey = options.AwsSecretKey,
            };

            job.WebAppRoot = new DirectoryInfo(options.AppPath);
            if (!job.WebAppRoot.Exists)
            {
                Console.WriteLine(string.Format("No directory found for --{1} argument value of {0}.", options.AppPath, options.Reflect(o=> o.AppPath).Attribute<OptionAttribute>().LongName));
                ExitCode.InputError.Exit();
            }

            if (options.BinaryAssetsSearchPatterns.HasItems())
            {
                job.BinaryAssetsSearchPatterns = options.BinaryAssetsSearchPatterns.Select(p => p.Trim()).ToArray();
            }
            else
            {
                job.BinaryAssetsSearchPatterns = ((string)options.Reflect(o => o.BinaryAssetsSearchPatterns).Attribute<DefaultValueAttribute>().Value).Split(',');
            }

            if (options.IgnoreDirectories.HasItems())
            {
                job.DirectoriesToIgnore = options.IgnoreDirectories.Select(d => d.Trim().Replace('/',Path.DirectorySeparatorChar).StartWithout(Path.DirectorySeparatorChar.ToString())).ToArray();
            }
            else
            {
                job.DirectoriesToIgnore = new string[] { "bin", "obj" };
            }

            if (options.JavaPath.HasChars() && !File.Exists(options.JavaPath))
            {
                Console.WriteLine("javapath argument '" + options.JavaPath + "' was invalid because the file could not be found.");
                ExitCode.InputError.Exit();
            }
            else if ( !options.JavaPath.HasChars() )
            {
                Console.WriteLine("Searching for java.exe...");
                options.JavaPath = LocateJava();
                if (!options.JavaPath.HasChars())
                    Console.WriteLine(string.Format("Warning: java.exe could not be found.  Please specify command arg {0}.  Without it, Google Closure can't be used to minify javascript.  Please install Java JRE or specify the path to the java.exe file.  Otherwise you are missing out on better compression!", "javapath"));
            }

            job.JavaPath = options.JavaPath;

            job.AddEveryCss = options.AddEachCss;
            job.AddEveryJs = options.AddEachJs;
            if (options.AssetVersion.HasValue)
            {
                job.AssetVersion = options.AssetVersion.Value;
            }
            else
            {
                job.AutoUpdateAssetVersion = true;
            }

            return job;
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            Console.WriteLine("stevepotter.me's Asset Booster");
            var options = new CommandLineOptions();
            ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
            if (!parser.ParseArguments(args, options))
                ExitCode.InputError.Exit();

            //setup the job
            DeploymentJob job = CreateJob(options);
            try
            {
                Console.WriteLine("Uploading to S3 bucket '" + options.S3Bucket + "'.");
                job.Execute();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Report("Error: ", true, false, false));
                ExitCode.ProcessingError.Exit();
            }
            return (int)ExitCode.Success;
        }