public async Task<CompilerResult> CompileAsync(string sourceFileName, string targetFileName)
        {
            if (RequireMatchingFileName &&
                Path.GetFileName(targetFileName) != Path.GetFileNameWithoutExtension(sourceFileName) + TargetExtension &&
                Path.GetFileName(targetFileName) != Path.GetFileNameWithoutExtension(sourceFileName) + ".min" + TargetExtension)
                throw new ArgumentException(ServiceName + " cannot compile to a targetFileName with a different name.  Only the containing directory can be different.", "targetFileName");

            var mapFileName = GetMapFileName(sourceFileName, targetFileName);

            var scriptArgs = GetArguments(sourceFileName, targetFileName, mapFileName);

            var errorOutputFile = Path.GetTempFileName();

            var cmdArgs = string.Format("\"{0}\" \"{1}\"", NodePath, CompilerPath);

            cmdArgs = string.Format("/c \"{0} {1} > \"{2}\" 2>&1\"", cmdArgs, scriptArgs, errorOutputFile);

            ProcessStartInfo start = new ProcessStartInfo("cmd")
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.GetDirectoryName(sourceFileName),
                Arguments = cmdArgs,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            try
            {
                ProjectHelpers.CheckOutFileFromSourceControl(targetFileName);

                mapFileName = mapFileName ?? targetFileName + ".map";

                if (GenerateSourceMap)
                    ProjectHelpers.CheckOutFileFromSourceControl(mapFileName);

                using (var process = await start.ExecuteAsync())
                {
                    if (targetFileName != null)
                        await MoveOutputContentToCorrectTarget(targetFileName);

                    return await ProcessResult(
                                     process,
                                     (await FileHelpers.ReadAllTextRetry(errorOutputFile)).Trim(),
                                     sourceFileName,
                                     targetFileName,
                                     mapFileName
                                 );
                }
            }
            finally
            {
                File.Delete(errorOutputFile);

                if (!GenerateSourceMap)
                    File.Delete(mapFileName);
            }
        }
Ejemplo n.º 2
0
        public async Task<CompilerResult> Compile(string sourceFileName, string targetFileName)
        {
            if (!CheckPrerequisites(sourceFileName))
                return null;

            var scriptArgs = GetArguments(sourceFileName, targetFileName);

            var errorOutputFile = Path.GetTempFileName();

            var cmdArgs = string.Format("\"{0}\" \"{1}\"", NodePath, CompilerPath);

            cmdArgs = string.Format("/c \"{0} {1} > \"{2}\" 2>&1\"", cmdArgs, scriptArgs, errorOutputFile);

            ProcessStartInfo start = new ProcessStartInfo("cmd")
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.GetDirectoryName(sourceFileName),
                Arguments = cmdArgs,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            try
            {
                if (!ProjectHelpers.CheckOutFileFromSourceControl(sourceFileName))
                {
                    // Someone else have this file checked out
                    Logger.Log("Could not check the file out of source control");
                    return null;
                }

                ProjectHelpers.CheckOutFileFromSourceControl(targetFileName);

                using (var process = await start.ExecuteAsync())
                {
                    return ProcessResult(
                                            process,
                                            File.ReadAllText(errorOutputFile).Trim(),
                                            sourceFileName,
                                            targetFileName
                                        );
                }
            }
            finally
            {
                File.Delete(errorOutputFile);
            }
        }
        public async Task<CompilerResult> Compile(string sourceFileName, string targetFileName)
        {
            var scriptArgs = GetArguments(sourceFileName, targetFileName);

            var errorOutputFile = Path.GetTempFileName();

            var cmdArgs = string.Format("\"{0}\" \"{1}\"", NodePath, CompilerPath);

            cmdArgs = string.Format("/c \"{0} {1} > \"{2}\" 2>&1\"", cmdArgs, scriptArgs, errorOutputFile);

            ProcessStartInfo start = new ProcessStartInfo("cmd")
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.GetDirectoryName(sourceFileName),
                Arguments = cmdArgs,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            try
            {
                using (var process = await start.ExecuteAsync())
                {
                    string errorText = "";

                    // Subjected to change, depending on https://github.com/andrew/node-sass/issues/207
                    if (File.Exists(errorOutputFile))
                        errorText = File.ReadAllText(errorOutputFile).Trim();

                    return ProcessResult(process, errorText, sourceFileName, targetFileName);
                }
            }
            finally
            {
                File.Delete(errorOutputFile);
            }
        }
Ejemplo n.º 4
0
        private async Task<CompressionResult> CompressFile(string fileName)
        {
            string targetFile = Path.ChangeExtension(Path.GetTempFileName(), Path.GetExtension(fileName));

            ProcessStartInfo start = new ProcessStartInfo("cmd")
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), @"Resources\tools\"),
                Arguments = GetArguments(fileName, targetFile),
                UseShellExecute = false,
                CreateNoWindow = true,
            };

            try
            {
                using (var process = await start.ExecuteAsync())
                {
                    return new CompressionResult(fileName, targetFile);
                }
            }
            catch
            {
                CompressionResult result = new CompressionResult(fileName, targetFile);
                File.Delete(targetFile);
                return result;
            }
        }
        public async Task<CompilerResult> CompileAsync(string sourceFileName, string targetFileName)
        {
            if (WEIgnore.TestWEIgnore(sourceFileName, this is ILintCompiler ? "linter" : "compiler", ServiceName.ToLowerInvariant()))
            {
                Logger.Log(String.Format(CultureInfo.CurrentCulture, "{0}: The file {1} is ignored by .weignore. Skipping..", ServiceName, Path.GetFileName(sourceFileName)));
                return await CompilerResultFactory.GenerateResult(sourceFileName, targetFileName, string.Empty, false, string.Empty, Enumerable.Empty<CompilerError>(), true);
            }

            if (RequireMatchingFileName &&
                Path.GetFileName(targetFileName) != Path.GetFileNameWithoutExtension(sourceFileName) + TargetExtension &&
                Path.GetFileName(targetFileName) != Path.GetFileNameWithoutExtension(sourceFileName) + ".min" + TargetExtension)
                throw new ArgumentException(ServiceName + " cannot compile to a targetFileName with a different name.  Only the containing directory can be different.", "targetFileName");

            string mapFileName = GetMapFileName(sourceFileName, targetFileName),
                   tempTarget = Path.GetTempFileName(),
                   scriptArgs = await GetArguments(sourceFileName, tempTarget, mapFileName),
                   errorOutputFile = Path.GetTempFileName(),
                   cmdArgs = string.Format("\"{0}\" \"{1}\"", NodePath, CompilerPath);

            cmdArgs = string.Format("/c \"{0} {1} > \"{2}\" 2>&1\"", cmdArgs, scriptArgs, errorOutputFile);

            ProcessStartInfo start = new ProcessStartInfo("cmd")
            {
                WindowStyle = ProcessWindowStyle.Hidden,
                WorkingDirectory = Path.GetDirectoryName(sourceFileName),
                Arguments = cmdArgs,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            try
            {
                mapFileName = mapFileName ?? targetFileName + ".map";
                using (var process = await start.ExecuteAsync())
                {
                    if (targetFileName != null)
                        await MoveOutputContentToCorrectTarget(targetFileName);

                    // Another ugly hack for https://github.com/jashkenas/coffeescript/issues/3526
                    if (ServiceName.ToLowerInvariant().IndexOf("coffeescript") >= 0 || ServiceName.ToLowerInvariant().IndexOf("livescript") >= 0)
                    {
                        tempTarget = Path.Combine(Path.GetDirectoryName(tempTarget), Path.GetFileName(targetFileName));
                        mapFileName = Path.ChangeExtension(tempTarget, ".map");
                    }

                    return await ProcessResult(
                                     process,
                                     (await FileHelpers.ReadAllTextRetry(errorOutputFile)).Trim(),
                                     sourceFileName,
                                     tempTarget,
                                     targetFileName,
                                     mapFileName
                                 );
                }
            }
            finally
            {
                File.Delete(errorOutputFile);
                File.Delete(tempTarget);

                if (ManagedSourceMap && !GenerateSourceMap)
                    File.Delete(mapFileName);
            }
        }