Exemplo n.º 1
0
        /// <summary>
        /// The main method of the task.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The return code.</returns>
        private int Main(string[] args)
        {
            var arguments = new List<string>();

            arguments.AddRange(args);

            var configuration = GetConfigurationFromArguments(arguments);

            if (configuration.Help)
                return -1;

            if (arguments.Count == 0)
            {
                WriteHelp();
                return -1;
            }

            string inputDirectoryPath, inputFilePattern;

            if (Directory.Exists(arguments[0]))
            {
                inputDirectoryPath = arguments[0];
                inputFilePattern = "*.less";
            }
            else
            {
                inputDirectoryPath = Path.GetDirectoryName(arguments[0]);
                if (string.IsNullOrEmpty(inputDirectoryPath)) inputDirectoryPath = "." + Path.DirectorySeparatorChar;
                inputFilePattern = Path.GetFileName(arguments[0]);
                if (!Path.HasExtension(inputFilePattern)) inputFilePattern = Path.ChangeExtension(inputFilePattern, "less");
            }

            var outputDirectoryPath = string.Empty;
            var outputFilename = string.Empty;
            if (arguments.Count > 1)
            {
                if (Directory.Exists(arguments[1]))
                {
                    outputDirectoryPath = arguments[1];
                }
                else
                {
                    outputDirectoryPath = Path.GetDirectoryName(arguments[1]);
                    outputFilename = Path.GetFileName(arguments[1]);

                    if (!Path.HasExtension(outputFilename))
                        outputFilename = Path.ChangeExtension(outputFilename, "css");
                }
            }

            if (string.IsNullOrEmpty(outputDirectoryPath))
            {
                outputDirectoryPath = inputDirectoryPath;
            }
            else
            {
                Directory.CreateDirectory(outputDirectoryPath);
            }

            if (HasWildcards(inputFilePattern))
            {
                if (!string.IsNullOrEmpty(outputFilename))
                {
                    Log.LogError("Output filename patterns/filenames are not supported when using input wildcards. You may only specify an output directory (end the output in a directory seperator)");
                    return -1;
                }
                outputFilename = string.Empty;
            }

            var filenames = Directory.GetFiles(inputDirectoryPath, inputFilePattern);
            if (filenames.Count() == 0)
            {
                Log.LogError("No files found matching pattern '{0}'", inputFilePattern);
                return -1;
            }

            var engineFactory = new EngineFactory(configuration);
            var containerFactory = new dotlessCompilerContainerFactory(this);
            var engine = engineFactory.GetEngine(containerFactory);
            foreach (var filename in filenames)
            {
                var inputFile = new FileInfo(filename);

                var outputFile =
                    string.IsNullOrEmpty(outputFilename) ?
                        Path.Combine(outputDirectoryPath, Path.ChangeExtension(inputFile.Name, "css")) :
                        Path.Combine(outputDirectoryPath, outputFilename);

                var outputFilePath = Path.GetFullPath(outputFile);

                var returnCode = CompileImpl(engine, inputFile.FullName, outputFilePath);
                if (returnCode != 0)
                {
                    // IF not zero
                    // THEN return the failure code
                    return returnCode;
                }
            }

            return ReturnCode;
        }
Exemplo n.º 2
0
        /// <summary>
        /// The main method of the task.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>The return code.</returns>
        private int Main(string[] args)
        {
            var arguments = new List <string>();

            arguments.AddRange(args);

            var configuration = GetConfigurationFromArguments(arguments);

            if (configuration.Help)
            {
                return(-1);
            }

            if (arguments.Count == 0)
            {
                WriteHelp();
                return(-1);
            }

            string inputDirectoryPath, inputFilePattern;

            if (Directory.Exists(arguments[0]))
            {
                inputDirectoryPath = arguments[0];
                inputFilePattern   = "*.less";
            }
            else
            {
                inputDirectoryPath = Path.GetDirectoryName(arguments[0]);
                if (string.IsNullOrEmpty(inputDirectoryPath))
                {
                    inputDirectoryPath = "." + Path.DirectorySeparatorChar;
                }
                inputFilePattern = Path.GetFileName(arguments[0]);
                if (!Path.HasExtension(inputFilePattern))
                {
                    inputFilePattern = Path.ChangeExtension(inputFilePattern, "less");
                }
            }

            var outputDirectoryPath = string.Empty;
            var outputFilename      = string.Empty;

            if (arguments.Count > 1)
            {
                if (Directory.Exists(arguments[1]))
                {
                    outputDirectoryPath = arguments[1];
                }
                else
                {
                    outputDirectoryPath = Path.GetDirectoryName(arguments[1]);
                    outputFilename      = Path.GetFileName(arguments[1]);

                    if (!Path.HasExtension(outputFilename))
                    {
                        outputFilename = Path.ChangeExtension(outputFilename, "css");
                    }
                }
            }

            if (string.IsNullOrEmpty(outputDirectoryPath))
            {
                outputDirectoryPath = inputDirectoryPath;
            }
            else
            {
                Directory.CreateDirectory(outputDirectoryPath);
            }

            if (HasWildcards(inputFilePattern))
            {
                if (!string.IsNullOrEmpty(outputFilename))
                {
                    Log.LogError("Output filename patterns/filenames are not supported when using input wildcards. You may only specify an output directory (end the output in a directory seperator)");
                    return(-1);
                }
                outputFilename = string.Empty;
            }

            var filenames = Directory.GetFiles(inputDirectoryPath, inputFilePattern);

            if (filenames.Count() == 0)
            {
                Log.LogError("No files found matching pattern '{0}'", inputFilePattern);
                return(-1);
            }

            var engineFactory    = new EngineFactory(configuration);
            var containerFactory = new dotlessCompilerContainerFactory(this);
            var engine           = engineFactory.GetEngine(containerFactory);

            foreach (var filename in filenames)
            {
                var inputFile = new FileInfo(filename);

                var outputFile =
                    string.IsNullOrEmpty(outputFilename) ?
                    Path.Combine(outputDirectoryPath, Path.ChangeExtension(inputFile.Name, "css")) :
                    Path.Combine(outputDirectoryPath, outputFilename);

                var outputFilePath = Path.GetFullPath(outputFile);

                var returnCode = CompileImpl(engine, inputFile.FullName, outputFilePath);
                if (returnCode != 0)
                {
                    // IF not zero
                    // THEN return the failure code
                    return(returnCode);
                }
            }

            return(ReturnCode);
        }