Exemplo n.º 1
0
        static public void BuildConfiguration(string[] args)
        {
            string argumentValueFromParameterName(string parameterName) =>
            args
            .Select(arg => Regex.Match(arg, parameterName + "=(.*)", RegexOptions.IgnoreCase))
            .FirstOrDefault(match => match.Success)
            ?.Groups[1].Value;

            var outputArgument = argumentValueFromParameterName("--output");

            var loweredElmOutputArgument = argumentValueFromParameterName("--lowered-elm-output");

            var frontendWebElmMakeCommandAppendix = argumentValueFromParameterName("--frontend-web-elm-make-appendix");

            var(configZipArchive, loweredElmAppFiles) = BuildConfigurationZipArchive(frontendWebElmMakeCommandAppendix);

            if (0 < loweredElmOutputArgument?.Length)
            {
                Console.WriteLine("I write the lowered Elm app to '" + loweredElmOutputArgument + "'.");

                foreach (var file in loweredElmAppFiles)
                {
                    var outputPath = Path.Combine(new[] { loweredElmOutputArgument }.Concat(file.Key).ToArray());
                    Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                    File.WriteAllBytes(outputPath, file.Value.ToArray());
                }
            }

            var configZipArchiveFileId =
                CommonConversion.StringBase16FromByteArray(CommonConversion.HashSHA256(configZipArchive));

            var webAppConfigFileId =
                Composition.GetHash(Composition.FromTree(Composition.TreeFromSetOfBlobsWithCommonOSPath(
                                                             ZipArchive.EntriesFromZipArchive(configZipArchive), System.Text.Encoding.UTF8)));

            Console.WriteLine(
                "I built zip archive " + configZipArchiveFileId + " containing web app config " + webAppConfigFileId + ".");

            if (outputArgument == null)
            {
                Console.WriteLine("I did not see a path for output, so I don't attempt to save the configuration to a file.");
            }
            else
            {
                Directory.CreateDirectory(Path.GetDirectoryName(outputArgument));
                File.WriteAllBytes(outputArgument, configZipArchive);

                Console.WriteLine("I saved zip arcchive " + configZipArchiveFileId + " to '" + outputArgument + "'");
            }
        }
Exemplo n.º 2
0
        static public void BuildConfiguration(
            string outputOption,
            string loweredElmOutputOption,
            string frontendWebElmMakeCommandAppendixOption,
            Action <string> verboseLogWriteLine)
        {
            var(compileConfigZipArchive, loweredElmAppFiles) =
                Kalmit.PersistentProcess.WebHost.BuildConfigurationFromArguments.BuildConfigurationZipArchive(
                    frontendWebElmMakeCommandAppendixOption, verboseLogWriteLine);

            if (0 < loweredElmOutputOption?.Length)
            {
                Console.WriteLine("I write the lowered Elm app to '" + loweredElmOutputOption + "'.");

                foreach (var file in loweredElmAppFiles)
                {
                    var outputPath = Path.Combine(new[] { loweredElmOutputOption }.Concat(file.Key).ToArray());
                    Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                    File.WriteAllBytes(outputPath, file.Value.ToArray());
                }
            }

            var configZipArchive = compileConfigZipArchive();

            var configZipArchiveFileId =
                CommonConversion.StringBase16FromByteArray(CommonConversion.HashSHA256(configZipArchive));

            var webAppConfigFileId =
                Composition.GetHash(Composition.FromTree(Composition.TreeFromSetOfBlobsWithCommonFilePath(
                                                             Kalmit.ZipArchive.EntriesFromZipArchive(configZipArchive))));

            Console.WriteLine(
                "I built zip archive " + configZipArchiveFileId + " containing web app config " + webAppConfigFileId + ".");

            if (outputOption == null)
            {
                Console.WriteLine("I did not see a path for output, so I don't attempt to save the configuration to a file.");
            }
            else
            {
                Directory.CreateDirectory(Path.GetDirectoryName(outputOption));
                File.WriteAllBytes(outputOption, configZipArchive);

                Console.WriteLine("I saved zip archive " + configZipArchiveFileId + " to '" + outputOption + "'");
            }
        }
Exemplo n.º 3
0
 static public byte[] HashFromSerialRepresentation(byte[] serialized) =>
 CommonConversion.HashSHA256(serialized);