utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContentInsideFunction

func AddContentInsideFunction(filePath, functionName, newContent string) error

Function to add a new configuration before the closing of the Config structure in the source file

func AddEnvConfigFromString

func AddEnvConfigFromString(newConfig, workDirectory string) error

Function to add a new configuration before the closing of the Config structure in the source file

func AddGoConfigFromString

func AddGoConfigFromString(newConfig, workDirectory string) error

Function to add a new configuration before the closing of the Config structure in the source file

func AskConfirm

func AskConfirm(question string) (bool, error)

func AskData

func AskData(question string) (string, error)

func AskDataWithValidation

func AskDataWithValidation(questionTitle string, validator survey.Validator) (string, error)

func CheckAllGoFilesInDirectory

func CheckAllGoFilesInDirectory(dirPath string) error

func CheckPackageNameInFile

func CheckPackageNameInFile(filePath string, expectedPackageName string) (bool, error)

this function checks if a certain package name exists in a file (golang file)

func CheckSyntaxGoFile

func CheckSyntaxGoFile(filePath string) (bool, error)

this function checks if is a valid go file

func CheckZipIntegrity

func CheckZipIntegrity(zipPath string) error

func CopyFileOrDirectory

func CopyFileOrDirectory(sourcePath string, destPath string) error

Copy file or directory (with contents) to new location

func CreateFileFromTemplate

func CreateFileFromTemplate(templatePath, finalPath string) error

Create files from templates wich only needs to changes %%PACKAGE_NAME%%

func CreateFileFromTemplateWithCustomReplace

func CreateFileFromTemplateWithCustomReplace(templatePath, finalPath string, replaces map[string]string) error

Create files from templates that has many placeholders to replace

func DownloadFile

func DownloadFile(url string, destPath string) error

Download file from url to destination

func ExtendFile

func ExtendFile(filePath, newContent string) error

Function to extend file content by adding new content at the bottom of the file

func ExtractImports

func ExtractImports(code string) []string

ExtractImports extracts import statements from Go code.

func ExtractPackageLine

func ExtractPackageLine(code string) string

ExtractPackageLine extracts the line containing the "package" declaration from Go code.

func FileOrDirectoryExists

func FileOrDirectoryExists(filePath string) bool

Check file or directory exists

func FunctionExistsInFile

func FunctionExistsInFile(filePath string, functionName string) (bool, error)

this function checks if a certain function exists in a file (golang file)

func GetDependenciesInstallationOrder

func GetDependenciesInstallationOrder(dependencyFilePath string) ([]string, error)

func GetExecutablePath

func GetExecutablePath() (string, error)

Get this executable path

func GetMD5Hash

func GetMD5Hash(data string) string

func GetThisModuleName

func GetThisModuleName() (string, error)

func ImportBaseContent

func ImportBaseContent(sourcePath, finalPath string) error

func InitGoModules

func InitGoModules(ApplicationName, basePath string) error

func InstallNeededPackages

func InstallNeededPackages(basePath string) error

func IsGithubUrl

func IsGithubUrl(url string) bool

chech if is an github url (package style like github.com/unknowns24/mks)

func IsUrl

func IsUrl(url string) bool

chech if is an url or not (accepts http and https)

func ListDirectories

func ListDirectories(dirPath string) ([]string, error)

func ListDirectoriesAndFiles

func ListDirectoriesAndFiles(dirPath string) ([]string, error)

func ListFiles

func ListFiles(dirPath string) ([]string, error)

func MakeTemporalDirectory

func MakeTemporalDirectory() (string, error)

Make temporary directory with random name and return path

func MoveFileOrDirectory

func MoveFileOrDirectory(sourcePath string, destPath string) error

move file or directory (with contents) to new location

func ParsePromptFile

func ParsePromptFile(promptFilePath string, placeholdersToReplace *map[string]string, extendsFilesToSkip *[]string) error

func ReadFile

func ReadFile(filePath string) (string, error)

Read file content and return it

func ReadFileWithCustomReplace

func ReadFileWithCustomReplace(filePath string, replaces map[string]string) (string, error)

Read file content, replace placeholder with its values in memory and returns modified content

func RemovePackageAndImports

func RemovePackageAndImports(code string) string

RemovePackageAndImports removes the package declaration and all import statements from Go code.

func SanitizeFileName

func SanitizeFileName(input string) string

func SliceContainsElement

func SliceContainsElement(slice []string, target string) bool

func TempFileWithDummyPlaceholder

func TempFileWithDummyPlaceholder(filePath string) (string, error)

func Unzip

func Unzip(src, dest string) error

Unzip file to destination

func ValidateAllDependenciesInstalled

func ValidateAllDependenciesInstalled(dependsFilePath string) (bool, []string, error)
	This functions will return a boolean true if all dependencies are installed on templates addons folder
 	or false if at least one of that dependencies are missing, the second parameter will be the slice with
	the missing ones. Error indicates that something happend during the function execution.

func ValidateTemplateName

func ValidateTemplateName(templateName string) error

func ZipDirectoryContent

func ZipDirectoryContent(outputzipfilepath, directoryPath string) error

Types

type MksTemplatePath

type MksTemplatePath struct {
	Folders       []string
	FileName      string
	FileExtension string
}

func ProcessMksCustomFilesPath

func ProcessMksCustomFilesPath(fileName string) (MksTemplatePath, error)

type Prompt

type Prompt struct {
	Type        string `json:"type"`
	Prompt      string `json:"prompt"`
	Default     string `json:"default"`
	Validate    string `json:"validate"`
	ExtendFile  string `json:"extendFile"`
	Placeholder string `json:"placeholder"`
}

type PromptsFileFormat

type PromptsFileFormat struct {
	Prompts []Prompt `json:"prompts"`
}

Jump to

Keyboard shortcuts

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