Skip to content
Snippets Groups Projects
Verified Commit 2e10a070 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: first implementation

parent 9a61b756
No related branches found
No related tags found
No related merge requests found
#############################################################################################
#############################################################################################
##
## INIT-TARGETS
##
#############################################################################################
#############################################################################################
ifeq ($(GIT),)
$(error $(ERRORMARKER) Git is not defined, check your Makefile if git.mk is included)
endif
# @see .PHONY https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets
.PHONY: update-makefiles
ifeq ($(QUIET),)
_COPYVERBOSE = -v
endif
## update standard makefiles
update-makefiles:
$(ECHOMARKER) "update standard makefiles"
$(QUIET) $(eval TEMPD := $(shell mktemp -d))
$(QUIET) $(GIT) clone --quiet --depth=1 https://gitlab.schukai.com/schukai/utilities/makefile.git/ "$(TEMPD)"
$(QUIET) $(CP) -r $(_COPYVERBOSE) $(TEMPD)/makefiles/* $(MAKEFILE_IMPORT_PATH)
$(QUIET) $(CP) -r $(_COPYVERBOSE) $(TEMPD)/Makefile $(PROJECT_ROOT)Makefile.example
$(QUIET) $(RM) -rf $(TEMPD)
#############################################################################################
#############################################################################################
##
## VARIABLES-TARGETS
##
#############################################################################################
#############################################################################################
.PHONY: variables
## Print all variables
variables:
$(ECHOMARKER) "print all variables"
$(QUIET) $(foreach v, $(.VARIABLES), $(if $(filter file,$(origin $(v))), $(info $(INFO)$(v)$(RESET)=$($(v))$(RESET))))
\ No newline at end of file
#############################################################################################
#############################################################################################
##
## VARIABLES-TARGETS
##
#############################################################################################
#############################################################################################
ifeq ($(VERSION_BIN),)
$(error "$(VERSION_BIN) is not installed. Please check your makefile and include the version.mk")
endif
ifeq ($(GIT),)
$(error $(ERRORMARKER) Git is not defined, check your Makefile if git.mk is included)
endif
ifeq ($(GIT_CHGLOG_BIN),)
$(error $(ERRORMARKER) Chglog is not defined, check your Makefile if changelog.mk is included)
endif
$(VERSION_BIN):
$(QUIET) $(MKDIR) -p $(VENDOR_PATH)
$(QUIET) $(WGET) -O $(VERSION_BIN) http://download.schukai.com/tools/version/version-$(shell uname -s | tr [:upper:] [:lower:])-$(shell echo `uname -m | sed s/aarch64/arm64/ | sed s/x86_64/amd64/`)
$(QUIET) $(CHMOD) u+x $(VERSION_BIN)
.PHONY: next-patch-version
next-patch-version: check-clean-repo $(VERSION_BIN)
$(ECHOMARKER) "Creating next version"
$(QUIET) $(VERSION_BIN) patch --path $(RELEASE_FILE) --selector "version"
$(QUIET) $(GIT) add $(RELEASE_FILE) && $(GIT) commit -m "Bump version to $$(cat $(RELEASE_FILE) | jq -r .version)"
.PHONY: next-minor-version
next-minor-version: check-clean-repo $(VERSION_BIN)
$(ECHOMARKER) "Creating next minor version"
$(QUIET) $(VERSION_BIN) minor --path $(RELEASE_FILE) --selector "version"
$(QUIET) $(GIT) add $(RELEASE_FILE) && $(GIT) commit -m "Bump version to $$( cat $(RELEASE_FILE) | jq -r .version)"
.PHONY: next-major-version
next-major-version: check-clean-repo $(VERSION_BIN)
$(ECHOMARKER) "Creating next minor version"
$(QUIET) $(VERSION_BIN) major --path $(RELEASE_FILE) --selector "version"
$(QUIET) $(GIT) add $(RELEASE_FILE) && $(GIT) commit -m "Bump version to $$(cat $(RELEASE_FILE) | jq -r .version)"
.PHONY: check-clean-repo
check-clean-repo:
$(QUIET) $(GIT) diff-index --quiet HEAD || (echo "There are uncommitted changes after running make. Please commit or stash them before running make."; exit 1)
## tag repository with next patch version
tag-patch-version: $(GIT_CHGLOG_CONFIG_DIR)/config.yml $(GIT_CHGLOG_CONFIG_DIR)/CHANGELOG.tpl.md next-patch-version
$(ECHOMARKER) "Tagging patch version"
$(eval PROJECT_VERSION := $(shell cat $(RELEASE_FILE) | jq -r .version))
$(GIT_CHGLOG_BIN) --next-tag v$(PROJECT_VERSION) -o $(CHANGELOG_FILE)
$(QUIET) $(GIT) add $(CHANGELOG_FILE) && $(GIT) commit -m "Update changelog"
$(QUIET) $(GIT) tag -a v$(PROJECT_VERSION) -m "Version $(PROJECT_VERSION)"
## tag repository with next minor version
tag-minor-version: $(GIT_CHGLOG_CONFIG_DIR)/config.yml $(GIT_CHGLOG_CONFIG_DIR)/CHANGELOG.tpl.md next-minor-version
$(ECHOMARKER) "Tagging minor version"
$(eval PROJECT_VERSION := $(shell cat $(RELEASE_FILE) | jq -r .version))
$(GIT_CHGLOG_BIN) --next-tag v$(PROJECT_VERSION) -o $(CHANGELOG_FILE)
$(QUIET) $(GIT) add $(CHANGELOG_FILE) && $(GIT) commit -m "Update changelog"
$(QUIET) $(GIT) tag -a v$(PROJECT_VERSION) -m "Version $(PROJECT_VERSION)"
## tag repository with next major version
tag-major-version: $(GIT_CHGLOG_CONFIG_DIR)/config.yml $(GIT_CHGLOG_CONFIG_DIR)/CHANGELOG.tpl.md next-major-version
$(ECHOMARKER) "Tagging major version"
$(eval PROJECT_VERSION := $(shell cat $(RELEASE_FILE) | jq -r .version))
$(GIT_CHGLOG_BIN) --next-tag v$(PROJECT_VERSION) -o $(CHANGELOG_FILE)
$(QUIET) $(GIT) add $(CHANGELOG_FILE) && $(GIT) commit -m "Update changelog"
$(QUIET) $(GIT) tag -a v$(PROJECT_VERSION) -m "Version $(PROJECT_VERSION)"
#############################################################################################
#############################################################################################
##
## TERMINAL CHECK
##
#############################################################################################
#############################################################################################
# Executable Programs the Installed be have to
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "Missing $(exec) in PATH; please install")))
\ No newline at end of file
#############################################################################################
#############################################################################################
##
## COMMANDS
##
#############################################################################################
#############################################################################################
# Use bash instead of sh
## Sets the shell used
SHELL = bash
# path and binaries
AWK ?= awk
CP ?= cp
CD ?= cd
KILL ?= kill
MV ?= mv
RM ?= rm
MKDIR ?= mkdir
SED ?= sed
FIND ?= find
SORT ?= sort
TOUCH ?= touch
WGET ?= wget
CHMOD ?= chmod
RSYNC ?= rsync
XARGS ?= xargs
GREP ?= grep
MAKE ?= make
LN ?= ln
TOUCH ?= touch
TEST ?= test
JQ ?= jq
EXECUTABLES = $(EXECUTABLES:-) $(JQ) $(AWK) $(CP) $(KILL) $(MV) $(SED) $(FIND) $(SORT) $(TOUCH) $(WGET) $(CHMOD) $(RSYNC) $(XARGS) $(GREP) $(MAKE) $(LN)
\ No newline at end of file
#############################################################################################
#############################################################################################
##
## VERSIONS
##
#############################################################################################
#############################################################################################
VERSION_BIN ?= $(VENDOR_PATH)version
RELEASE_FILE ?= $(PROJECT_ROOT)release.json
ifeq ("$(wildcard $(RELEASE_FILE))","")
$(shell echo '{"version":"0.1.0"}' > $(RELEASE_FILE))
endif
PROJECT_VERSION ?= $(shell cat $(RELEASE_FILE) | jq -r .version)
PROJECT_BUILD_DATE ?= $(shell $(VERSION_BIN) date)
mem.prof 0 → 100644
File added
parser.go 0 → 100644
package data
import "github.com/volker-schukai/tokenizer"
const (
PipeSymbol = iota + 1 // |
PipeCmdDelimiter
PipeQuote
PipeReflectionIsNil
PipeCmdStatic
PipeCmdIndex
PipeCmdToUpper
PipeCmdToLower
PipeCmdEmpty
PipeCmdEquals
PipeCmdTrim
PipeCmdRawUrlEncode
PipeCmdNot
PipeCmdToInteger
PipeCmdToString
PipeCmdToFloat
PipeCmdToBoolean
PipeCmdToNumber
PipeCmdToJSON
PipeCmdFromJSON
PipeCmdUCFirst
PipeCmdUCWords
PipeCmdLength
PipeCmdBase64Encode
PipeCmdBase64Decode
PipeCmdHTMLSpecialChars
PipeCmdHTMLEntityEncode
PipeCmdHTMLEntityDecode
PipeCmdPlaintext
PipeCmdMD5
PipeCmdSHA1
PipeCmdSHA256
PipeCmdSplit
PipeCmdReplace
PipeCmdJoin
PipeCmdNop
PipeCmdStringPad
PipeCmdStringRepeat
PipeCmdReverse
PipeCmdSubstring
PipeCmdWordwrap
PipeCmdPrefix
PipeCmdSuffix
PipeCmdUrlEncode
PipeCmdUrlDecode
PipeCmdChar
PipeCmdFloor
PipeCmdCeil
PipeCmdRound
PipeCmdAdd
PipeCmdSubtract
PipeCmdMultiply
PipeCmdDivide
PipeCmdModulo
)
func initTokenizer() *tokenizer.Tokenizer {
parser := tokenizer.New()
parser.AllowKeywordUnderscore().AllowNumbersInKeyword()
parser.DefineTokens(PipeSymbol, []string{"|"})
parser.DefineTokens(PipeCmdDelimiter, []string{":"})
parser.DefineTokens(PipeCmdStatic, []string{"static"})
parser.DefineTokens(PipeCmdIndex, []string{"index", "dataset"})
parser.DefineTokens(PipeReflectionIsNil, []string{"isnull", "isnil"})
parser.DefineTokens(PipeCmdNop, []string{"nop"})
parser.DefineTokens(PipeCmdEquals, []string{"eq", "equals", "equal", "?"}) // tested
parser.DefineTokens(PipeCmdEmpty, []string{"empty"}) // tested
parser.DefineTokens(PipeCmdNot, []string{"not", "!"}) // tested
parser.DefineTokens(PipeCmdToInteger, []string{"tointeger", "int", "toint"}) // tested
parser.DefineTokens(PipeCmdToString, []string{"tostring", "str"})
parser.DefineTokens(PipeCmdToFloat, []string{"tofloat", "float"})
parser.DefineTokens(PipeCmdToBoolean, []string{"toboolean", "tobool", "bool"})
parser.DefineTokens(PipeCmdToNumber, []string{"tonumber", "number"})
parser.DefineTokens(PipeCmdToJSON, []string{"tojson", "json", "encodejson", "jsonencode"})
parser.DefineTokens(PipeCmdFromJSON, []string{"fromjson", "decodejson", "jsondecode"})
parser.DefineTokens(PipeCmdToUpper, []string{"toupper", "upper", "strtoupper"}) // tested
parser.DefineTokens(PipeCmdToLower, []string{"tolower", "lower", "strtolower"}) // tested
parser.DefineTokens(PipeCmdChar, []string{"char", "chr"})
parser.DefineTokens(PipeCmdFloor, []string{"floor", "rounddown"})
parser.DefineTokens(PipeCmdCeil, []string{"ceil", "roundup"})
parser.DefineTokens(PipeCmdRound, []string{"round"})
parser.DefineTokens(PipeCmdAdd, []string{"add", "+"})
parser.DefineTokens(PipeCmdSubtract, []string{"subtract", "sub", "-"})
parser.DefineTokens(PipeCmdMultiply, []string{"multiply", "mul", "*"})
parser.DefineTokens(PipeCmdDivide, []string{"divide", "div", "/"})
parser.DefineTokens(PipeCmdModulo, []string{"modulo", "mod", "%"})
parser.DefineTokens(PipeCmdUrlEncode, []string{"urlencoded", "urlencode", "url_encode"})
parser.DefineTokens(PipeCmdUrlDecode, []string{"urldecoded", "urldecoded", "url_decode"})
parser.DefineTokens(PipeCmdRawUrlEncode, []string{"rawurlencode", "rawurlencoded"})
parser.DefineTokens(PipeCmdUCFirst, []string{"ucfirst", "ucfirst"})
parser.DefineTokens(PipeCmdUCWords, []string{"ucwords", "ucwords"})
parser.DefineTokens(PipeCmdLength, []string{"length", "len"})
parser.DefineTokens(PipeCmdBase64Encode, []string{"base64encode", "base64_encode", "base64"})
parser.DefineTokens(PipeCmdBase64Decode, []string{"base64decode", "base64_decode"})
parser.DefineTokens(PipeCmdHTMLSpecialChars, []string{"htmlspecialchars", "html_special_chars"})
parser.DefineTokens(PipeCmdHTMLEntityEncode, []string{"htmlentities", "html_entity_encode"})
parser.DefineTokens(PipeCmdHTMLEntityDecode, []string{"html_entity_decode", "html_entity_decode"})
parser.DefineTokens(PipeCmdPlaintext, []string{"plaintext", "text", "plain", "strip_tags"})
parser.DefineTokens(PipeCmdTrim, []string{"trim"})
parser.DefineTokens(PipeCmdMD5, []string{"md5"})
parser.DefineTokens(PipeCmdSHA1, []string{"sha1"})
parser.DefineTokens(PipeCmdSHA256, []string{"sha256"})
parser.DefineTokens(PipeCmdStringPad, []string{"strpad", "stringpad"})
parser.DefineTokens(PipeCmdStringRepeat, []string{"strrepeat", "stringrepeat"})
parser.DefineTokens(PipeCmdReverse, []string{"reverse", "strrev"})
parser.DefineTokens(PipeCmdSubstring, []string{"substr", "substring"})
parser.DefineTokens(PipeCmdWordwrap, []string{"wordwrap"})
parser.DefineTokens(PipeCmdPrefix, []string{"prefix"})
parser.DefineTokens(PipeCmdSuffix, []string{"suffix"})
parser.DefineTokens(PipeCmdSplit, []string{"split"})
parser.DefineTokens(PipeCmdReplace, []string{"replace"})
parser.DefineTokens(PipeCmdJoin, []string{"join"})
parser.DefineStringToken(PipeQuote, `"`, `"`).SetEscapeSymbol(tokenizer.BackSlash)
return parser
}
## Project directory in which the Makefiles should be located
MAKEFILE_IMPORT_PATH=$(PROJECT_ROOT)makefiles/
{"version":"0.1.0"}
This diff is collapsed.
This diff is collapsed.
util.go 0 → 100644
package data
import (
"bytes"
"unicode"
)
func inArray(needle any, hystack any) bool {
switch key := needle.(type) {
case string:
for _, item := range hystack.([]string) {
if key == item {
return true
}
}
case int:
for _, item := range hystack.([]int) {
if key == item {
return true
}
}
case int64:
for _, item := range hystack.([]int64) {
if key == item {
return true
}
}
default:
return false
}
return false
}
func wordWrap(str string, width uint, br string) string {
init := make([]byte, 0, len(str))
buf := bytes.NewBuffer(init)
var current uint
var wordbuf, spacebuf bytes.Buffer
for _, char := range str {
if char == '\n' {
if wordbuf.Len() == 0 {
if current+uint(spacebuf.Len()) > width {
current = 0
} else {
current += uint(spacebuf.Len())
spacebuf.WriteTo(buf)
}
spacebuf.Reset()
} else {
current += uint(spacebuf.Len() + wordbuf.Len())
spacebuf.WriteTo(buf)
spacebuf.Reset()
wordbuf.WriteTo(buf)
wordbuf.Reset()
}
buf.WriteRune(char)
current = 0
} else if unicode.IsSpace(char) {
if spacebuf.Len() == 0 || wordbuf.Len() > 0 {
current += uint(spacebuf.Len() + wordbuf.Len())
spacebuf.WriteTo(buf)
spacebuf.Reset()
wordbuf.WriteTo(buf)
wordbuf.Reset()
}
spacebuf.WriteRune(char)
} else {
wordbuf.WriteRune(char)
if current+uint(spacebuf.Len()+wordbuf.Len()) > width && uint(wordbuf.Len()) < width {
buf.WriteString(br)
current = 0
spacebuf.Reset()
}
}
}
if wordbuf.Len() == 0 {
if current+uint(spacebuf.Len()) <= width {
spacebuf.WriteTo(buf)
}
} else {
spacebuf.WriteTo(buf)
wordbuf.WriteTo(buf)
}
return buf.String()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment