Skip to content

Instantly share code, notes, and snippets.

@sl5net
Created January 13, 2019 06:03
Show Gist options
  • Save sl5net/b2639f81db51526980d4a121a3ccc5d6 to your computer and use it in GitHub Desktop.
Save sl5net/b2639f81db51526980d4a121a3ccc5d6 to your computer and use it in GitHub Desktop.
;/¯¯¯¯ configStr2minify_configFile ¯¯ 190111201847 ¯¯ 11.01.2019 20:18:47 ¯¯\
configStr2minify_configFile(configIncAhkAddress := "\config\config.inc.ahk"
, configMinifyIncAhkAddress := "\config.minify.inc.ahk" ){
; needs start with: g_config (12.01.2019 10:57, 19-01-12_10-57)
configIncAhkAddress := A_ScriptDir configIncAhkAddress
configMinifyDIR := A_ScriptDir "\inc_ahk\minify\"
configMinifyIncAhkAddress := configMinifyDIR configMinifyIncAhkAddress
; call it like (11.01.2019 20:19):
useItLike =
(
SetTimer,check_configFile_Changed,2000
g_config := {} ; <= or every name you like
configStr2minify_configFile()
# Include *i %A_ScriptDir%\minify\config.minify.inc.ahk
)
; Changes always become active on the next next call. becouse include is a preparser command. 19-01-11_18-33
; discussion here: https://stackoverflow.com/questions/54149980/remove-all-unnecessary-whitespaces-from-json-string-with-regex-in-autohotkey
doUpdate := false
FileGetTime, modifiedTime_configMinify, % configMinifyIncAhkAddress
if(!modifiedTime_configMinify){
doUpdate := true
FileCreateDir, % configMinifyDIR
if(!instr(FileExist(configMinifyDIR), "D")) ; would be true only if the file exists and is a directory.
MsgBox,262160,% "problem with :" configMinifyDIR " `n`n :(`n" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ,% ":(`n(" A_ThisFunc ":" A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ")"
}else{
FileGetTime, modifiedTime, % configIncAhkAddress
if(modifiedTime_configMinify < modifiedTime )
doUpdate := true
}
If(!doUpdate)
return
msg := doUpdate " = doUpdate (" A_ThisFunc ": " A_LineNumber " " RegExReplace(A_LineFile, ".*\\") ")"
; feedbackMsgBox( msg, msg )
; ToolTip, % msg, 1, 200, 9
if(1 && InStr(A_ComputerName,"SL5"))
sleep,1000
FileRead, configContent , % configIncAhkAddress
; configContentminify := "configContent =`n(`n" ; configContentminify .= "`n)`n"
; ((?!\bg_config\b).)*$
; configContentminify .= RegExReplace( configContent , "i)[\s\t ]*[\n\r]+([^\n\r]+)(?!\[a-z][_\d]\b)[\s\t ]*", "`n$1" )
configContentminify .= RegExReplace( configContent , "m)[\n\r]+(?![a-z]+[_\d]*)", " " )
tempFileAddress := A_ScriptDir "\" A_TickCount ".temp.txt"
FileAppend, % configContentminify, % tempFileAddress
FileCopy,% tempFileAddress, % configMinifyIncAhkAddress, 1
Sleep,20
FileDelete,% tempFileAddress
reload
; Return configMinifyIncAhkAddress
}
;\____ configStr2minify_configFile __ 190111201850 __ 11.01.2019 20:18:50 __/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment