helpers

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package helpers contains helper functions used across commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteCommandC

func ExecuteCommandC(root *cobra.Command, args ...string) (c *cobra.Command, err error)

ExecuteCommandC is a @DEPRECATED function, not used anymore.

func GetAllResources

func GetAllResources(fs afero.Fs, path string) []string

GetAllResources returns a slice of resource names as string.

func GetAllRoutes added in v0.9.0

func GetAllRoutes(fs afero.Fs, path string) []string

GetAllRoutes return a slice of all routes names as string.

func GetResourceContentMap

func GetResourceContentMap(fs afero.Fs, resources []string, path string) map[string][]string

GetResourceContentMap returns a map of resources and relative contents.

func GetResourceMetadataMap

func GetResourceMetadataMap(fs afero.Fs, resources []string, path string) map[string][]string

GetResourceMetadataMap returns a map of metadata and relative name.

func GetResourceRouteFilename

func GetResourceRouteFilename(txt string, s *config.SveltinSettings) string

GetResourceRouteFilename returns a string representing the index and slug routes for a resource.

func InitStartersTemplatesMap added in v0.8.1

func InitStartersTemplatesMap() map[string]config.StarterTemplate

InitStartersTemplatesMap creates a map[string]string containining project name and repo url used by the `sveltin new` command to clone the starter project.

func IsValidFileForContent

func IsValidFileForContent(f fs.FileInfo) bool

IsValidFileForContent checks is the provided FileInfo has valid extension (.svelte, .svx, .mdx) to be used as content file.

func MakeFileContent

func MakeFileContent(efs *embed.FS, content builder.Content) []byte

MakeFileContent executes the template file with all its data and functions and returns the content file as []byte

func NewMenuItems added in v0.10.0

func NewMenuItems(resources []string, content map[string][]string) *tpltypes.MenuItems

NewMenuItems return a NoPageItems.

func NewNoPageItems

func NewNoPageItems(resources []string, content map[string][]string) *tpltypes.NoPageItems

NewNoPageItems return a NoPageItems.

func PrepareContent

func PrepareContent(name string, resources map[string]string, templateID string, data *config.TemplateData) builder.Content

PrepareContent returns a builder.Content struct used by the builder director.

func PublicPageFilename

func PublicPageFilename(pageType string) string

PublicPageFilename returns the filename string for a public page based on the page type (svelte or markdown).

func ResourceExists

func ResourceExists(fs afero.Fs, name string, s *config.SveltinSettings) error

ResourceExists return nil if a Resource identified by name exists.

func RunPMCommand

func RunPMCommand(pmName string, pmCmd string, mode string, packages []string, silentMode bool) error

RunPMCommand executes package manager (npm, pnpm, yarn) commands.

func WriteContentToDisk

func WriteContentToDisk(fs afero.Fs, saveAs string, fileContent []byte) error

WriteContentToDisk saves content file to the file system.

Types

type TplConfig added in v0.10.0

type TplConfig struct {
	PathToTplFile string
	Funcs         template.FuncMap
	Data          config.TemplateData
}

TplConfig is the struct representing all is needed by a template file (path to the template, functions map and template data).

func BuildTemplate added in v0.3.0

func BuildTemplate(tplPath string, funcs template.FuncMap, data *config.TemplateData) *TplConfig

BuildTemplate creates TplConfig struct with all is needed for a golang template to be executed

func (*TplConfig) Run added in v0.10.0

func (tplConfig *TplConfig) Run(embedFS *embed.FS) []byte

Run executes the templates and return the content as []byte.

Directories

Path Synopsis
Package factory ...
Package factory ...

Jump to

Keyboard shortcuts

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