common

package
v0.0.0-...-372bc1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const CONTENT_END = "}}"
View Source
const CONTENT_START = "{{"

Variables

View Source
var GetFirstFilePathInRootDir = func(rootDirPath string) (string, error) {
	firstFilePath := ""
	err := filepath.WalkDir(rootDirPath, func(s string, d fs.DirEntry, err error) error {
		if err != nil {
			return err
		}
		if !d.IsDir() {
			firstFilePath = s
			return filepath.SkipDir
		}
		return nil
	})
	return firstFilePath, err
}
View Source
var GetFirstLineOfFirstFile = func(templateMap map[string]string) (string, string, error) {
	storePath := filepath.Join(templateMap[globals.KEY_ALTER_PATH], globals.STORE_DIRNAME)
	if !IsDir(storePath) {
		err := fmt.Errorf("store-path %s does not exist", storePath)
		return "", "", err
	}

	firstFilePath, err := GetFirstFilePathInRootDir(storePath)
	if err != nil {
		return "", "", err
	}

	wordList, err := GetWordsFromFile(firstFilePath)
	if err != nil {
		return "", "", err
	}
	firstWordInFirstFile := wordList[0]

	return firstFilePath, firstWordInFirstFile, nil
}
View Source
var GetMoveItemMap = func(templateMap map[string]string) (map[string]globals.MoveItemDetailsT, error) {
	moveItemMap := make(map[string]globals.MoveItemDetailsT)
	moveItems := templateMap[globals.KEY_MOVE_ITEMS]
	moveItemParts := strings.Split(moveItems, ":")

	lastIndexOfMoveItems := len(moveItemParts) - 1
	index := 0
	for _, moveItemVal := range moveItemParts {
		isLastItem := false
		if index == lastIndexOfMoveItems {
			isLastItem = true
		}

		moveItemKey := strings.Replace(moveItemVal, ".", "_", -1)
		MoveItemDetails := globals.MoveItemDetailsT{Key: moveItemKey, Index: index, IsLastItem: isLastItem, IsFirstItem: index == 0}

		moveItemMap[moveItemVal] = MoveItemDetails
		index++
	}
	return moveItemMap, nil
}
View Source
var GetWordsFromFile = func(filePath string) ([]string, error) {
	file, err := os.Open(filePath)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	scanner := bufio.NewScanner(file)

	scanner.Split(bufio.ScanWords)

	// Scan all words from the file.
	var words []string
	for scanner.Scan() {

		words = append(words, scanner.Text())
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}
	return words, nil
}
View Source
var NewRecord = func(filename string) *Record {
	return &Record{
		Filename: filename,
		Contents: make([]string, 0),
	}
}
View Source
var PrependToFile = func(filename, content string) error {
	record := NewRecord(filename)
	err := record.Prepend(content)
	if err != nil {
		return err
	}
	return nil
}

Functions

func CopyDir

func CopyDir(dst, src string) error

CopyDir copies the content of src to dst. src should be a full path.

func CreateFiles

func CreateFiles(infoList globals.ScaffoldInfoTListT) error

func GetNamedPath

func GetNamedPath(dirPath string, searchPathFragment string) (string, error)

func GetRecipePath

func GetRecipePath(absPathToRecipe string, reset bool) string

func IsDir

func IsDir(path string) bool

func IsFile

func IsFile(path string) bool

func ReadJsonFile

func ReadJsonFile(filePath string) (map[string]interface{}, error)

func ReplaceUsingTemplateMap

func ReplaceUsingTemplateMap(templateMap map[string]string, dirpath string) error

func RunTemplate

func RunTemplate(templateText string, tmplRootData globals.SubstitionTemplateT) (string, error)

func RunTemplateExpt

func RunTemplateExpt(data map[string]map[string][]string, templateText string, templateMap map[string]string, substitutionTemplate globals.SubstitionTemplateT) (string, error)

Types

type Record

type Record struct {
	Filename string
	Contents []string
}

func (*Record) Prepend

func (r *Record) Prepend(content string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL