Exemplo n.º 1
0
 static IEnumerable <string> PrepareScriptModules(VariableDictionary variables, string workingDirectory)
 {
     foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
     {
         if (SpecialVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.FSharp)
         {
             var libraryScriptModuleName = SpecialVariables.GetLibraryScriptModuleName(variableName);
             var name           = new string(libraryScriptModuleName.Where(char.IsLetterOrDigit).ToArray());
             var moduleFileName = $"{name}.fsx";
             var moduleFilePath = Path.Combine(workingDirectory, moduleFileName);
             Log.VerboseFormat("Writing script module '{0}' as f# module {1}. Import this module via `#load \"{1}\"`.", libraryScriptModuleName, moduleFileName, name);
             CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), Encoding.UTF8);
             yield return(moduleFileName);
         }
     }
 }
Exemplo n.º 2
0
 static IEnumerable <string> PrepareScriptModules(IVariables variables, string workingDirectory)
 {
     foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
     {
         if (SpecialVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.Python)
         {
             var libraryScriptModuleName = SpecialVariables.GetLibraryScriptModuleName(variableName);
             var name           = new string(libraryScriptModuleName.Where(x => char.IsLetterOrDigit(x) || x == '_').ToArray());
             var moduleFileName = $"{name}.py";
             Log.VerboseFormat("Writing script module '{0}' as python module {1}. Import this module via `import {2}`.", libraryScriptModuleName, moduleFileName, name);
             var moduleFilePath = Path.Combine(workingDirectory, moduleFileName);
             CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), Encoding.UTF8);
             yield return(name);
         }
     }
 }
Exemplo n.º 3
0
 static IEnumerable <string> PrepareScriptModules(IVariables variables, string workingDirectory)
 {
     foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
     {
         if (SpecialVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.Bash)
         {
             var libraryScriptModuleName = SpecialVariables.GetLibraryScriptModuleName(variableName);
             var name           = new string(libraryScriptModuleName.Where(char.IsLetterOrDigit).ToArray());
             var moduleFileName = $"{name}.sh";
             var moduleFilePath = Path.Combine(workingDirectory, moduleFileName);
             Log.VerboseFormat("Writing script module '{0}' as bash script {1}. Import this via `source {1}`.", libraryScriptModuleName, moduleFileName, name);
             Encoding utf8WithoutBom = new UTF8Encoding(false);
             CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), utf8WithoutBom);
             EnsureValidUnixFile(moduleFilePath);
             yield return(moduleFilePath);
         }
     }
 }
Exemplo n.º 4
0
        static string[] WriteScriptModules(VariableDictionary variables, string parentDirectory, StringBuilder output)
        {
            var scriptModules = new List <string>();

            foreach (var variableName in variables.GetNames().Where(SpecialVariables.IsLibraryScriptModule))
            {
                if (SpecialVariables.GetLibraryScriptModuleLanguage(variables, variableName) == ScriptSyntax.PowerShell)
                {
                    var libraryScriptModuleName = SpecialVariables.GetLibraryScriptModuleName(variableName);
                    var name           = "Library_" + new string(libraryScriptModuleName.Where(char.IsLetterOrDigit).ToArray()) + "_" + DateTime.Now.Ticks;
                    var moduleFileName = $"{name}.psm1";
                    var moduleFilePath = Path.Combine(parentDirectory, moduleFileName);
                    Log.VerboseFormat("Writing script module '{0}' as PowerShell module {1}. This module will be automatically imported - functions will automatically be in scope.", libraryScriptModuleName, moduleFileName, name);
                    CalamariFileSystem.OverwriteFile(moduleFilePath, variables.Get(variableName), Encoding.UTF8);
                    output.AppendLine($"Import-ScriptModule '{libraryScriptModuleName.EscapeSingleQuotedString()}' '{moduleFilePath.EscapeSingleQuotedString()}'");
                    output.AppendLine();
                    scriptModules.Add(moduleFilePath);
                }
            }

            return(scriptModules.ToArray());
        }