Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include Fake lib
- #r @"..\FAKE\tools\FakeLib.dll"
- #load @"..\fsharplibs\IniReader.fsx"
- open System
- open System.Runtime
- open System.Text
- open System.Text.RegularExpressions
- open System.IO
- open System.Linq
- open Core.Printf
- open Microsoft.FSharp.Reflection
- open Fake
- let (|?) lhs rhs = (if lhs = null then rhs else lhs)
- let fileToProcess = (Environment.GetCommandLineArgs().FirstOrDefault()) |? "deployment_plan.ini"
- let fstArg = Environment.GetCommandLineArgs().ElementAtOrDefault(1)
- let config = if fstArg = null then None else Some fstArg
- let sndArg = Environment.GetCommandLineArgs().ElementAtOrDefault(2)
- let folder = if sndArg = null then None else Some sndArg
- let simpleTemplatingEngine
- (openingSep: string)
- (closingSep: string)
- (data: Map<string, string>)
- (file: string) =
- printf "%s" (openingSep + "\s*\"([^\"]+)\"\s*,\s*\"([^\"]+)\"\s*" + closingSep)
- let searchFor = new Regex(openingSep + "\"(\w+)\",\"(\w+)\"" + closingSep, RegexOptions.Compiled ||| RegexOptions.CultureInvariant)
- let me (mtch: Match) =
- let key = mtch.Captures.[1].Value
- let defaults = mtch.Captures.[2].Value
- let newValue = Map.tryFind key data
- match newValue with
- | Some(found) -> found
- | _ -> defaults
- searchFor.Replace(file, new MatchEvaluator(me))
- let processTemplate templateFile data outputFileName = File.WriteAllText( outputFileName, simpleTemplatingEngine (@"%%\(") (@"\)%%") data (File.ReadAllText(templateFile)) )
- let parseList (str: string) =
- str.Trim().Trim('"').Split(',').Select( fun f -> f.Trim().Trim('"') )
- let clearGlobal (str: string) =
- str.Trim().Trim('"')
- //main essentialy...
- let build_folder_structure (config: IniReader.IniFile) (configOverride: string option) (folderSuffixOverride: string option)=
- let getGlobal kv = config.Globals.FirstOrDefault((fun k v -> k.Trim().Compare(kv, StringComparer.OrdinalIgnoreCase))) |? failwithf "Missing global option: %s" kv
- let getLocal sect kv =
- config.Sections.FirstOrDefault(
- (fun s k v -> s.Trim().Compare(sect, StringComparer.OrdinalIgnoreCase) && k.Trim().Compare(kv, StringComparer.OrdinalIgnoreCase) )
- ) |? failwithf "Missing section %s option %s" sect kv
- let getOGlobal = config.Globals.FirstOrDefault((fun k v -> k.Trim().Compare(kv, StringComparer.OrdinalIgnoreCase))) |? ""
- let getOLocal sect kv =
- config.Sections.FirstOrDefault(
- (fun s k v -> s.Trim().Compare(sect, StringComparer.OrdinalIgnoreCase) && k.Trim().Compare(kv, StringComparer.OrdinalIgnoreCase) )
- ) |? ""
- let pages = getGlobal "pages" |> parseList
- let services = getGlobal "services" |> parseList
- if (List.isEmpty pages && List.isEmpty services) then
- failwith "No pages or services are defined"
- let configuration = getGlobal "configuration" |> clearGlobal
- let configurationfoldersuffix = getGlobal "configurationfoldersuffix" |> clearGlobal
- let pagesfolder = getGlobal "configuration" |> clearGlobal
- let servicesfolder = getGlobal "configuration" |> clearGlobal
- let pagespool= getOGlobal "pagespool" |> clearGlobal
- let pagespoolusername= getOGlobal "pagespoolusername" |> clearGlobal
- let pagespoolpassword= getOGlobal "pagespoolpassword" |> clearGlobal
- let defaultserviceboot= getOGlobal "defaultserviceboot" |> clearGlobal
- let defaultserviceusername= getOGlobal "defaultserviceusername" |> clearGlobal
- let defaultserviceuserpassword= getOGlobal "defaultserviceuserpassword" |> clearGlobal
- build_folder_structure (IniReader.readIni(fileToProcess)) config folder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement