owl

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 7 Imported by: 1

README

Owl

⚠️ This library is under development

Owl is an golang library to create project generators for any framework or language. This is a personal project that you can use. There is no warranty if you have an error or bug publish an issue or make a pull request to improve this library.

Owl logo

Features

Owl is a template based library, what it means? It copy a template and then run init scripts that resides in that template.

  • Copy a local template
  • Run preconfigured template scripts
  • Ignore specific files with .owlignore file
  • Copy a remote template

Example of use

Go main file

package main

import (
	"flag"
	"fmt"
	"os"
	"path"

	"github.com/4strodev/owl"
	"github.com/4strodev/owl/template"
)

var (
	projectName     string
	moduleName      string
	projectTemplate string
	verboseOutput   bool
)

func main() {
	flag.StringVar(&projectName, "name", "my-app", "-name <project name>")
	flag.StringVar(&projectTemplate, "template", "go-cli", "-template <project template>")
	flag.StringVar(&moduleName, "module", "", "-template <project template>")
	flag.BoolVar(&verboseOutput, "verbose", false, "-verbose")
	flag.Parse()

	if moduleName == "" {
		fmt.Printf("Set go module name: ")
		fmt.Scanln(&moduleName)
	}

	project := owl.NewProject(
		owl.ProjectConfig{
			Name:         projectName,
			TemplateName: projectTemplate,
			LocalTemplatesDirs: []string{
				path.Join(os.Getenv("HOME"), "Templates"),
			},
			VerboseOutput: verboseOutput,
		}, template.TemplateConfig{
			ConfigName: "owl_config",
			ConfigType: "toml",
			Context: map[string]any{
				"ModuleName": moduleName,
			},
		},
	)

	err := project.Create()
	if err != nil {
		switch err.Error() {
		case owl.DIR_EXISTS:
			fmt.Printf("Folder %s already exists\n", projectName)
		case owl.TEMPLATE_NOT_FOUND:
			fmt.Printf("Template '%s' not found\n", project.Config.TemplateName)
		default:
			fmt.Printf("Error creating project: %s\n", err)
		}
		os.Exit(1)
	}
}

See example_template to know how to create a template.

TODO

  • Doc page (intended to do with hugo and use github pages)

Documentation

Index

Constants

View Source
const (
	// Permission MODES
	DIR_MODE int = 0755

	// FS errors
	DIR_EXISTS          string = "Directory exists"
	TEMPLATE_NOT_PASSED string = "No template passed"
	TEMPLATE_NOT_FOUND  string = "No template found"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Project

type Project struct {
	Config ProjectConfig
	// contains filtered or unexported fields
}

Contains the config the fs api and template info fs: It manage all fs operations copy files and directories, read files, etc. Config: It saves project config: project name, templates directories, template name... template: saves the template struct that manage template operations: read template content, load and run template scripts.

func NewProject

func NewProject(projectConfig ProjectConfig, templateConfig template.TemplateConfig) *Project

Generates a new projects giving the project config and and a template config

func (*Project) Create

func (self *Project) Create() error

Create the instantiated project

func (*Project) CreateRootFolder

func (self *Project) CreateRootFolder(path string) error

Create the root folder of the project

type ProjectConfig

type ProjectConfig struct {
	Name string

	TemplateName       string
	LocalTemplatesDirs []string
	VerboseOutput      bool
	// contains filtered or unexported fields
}

Contains the project's config

Directories

Path Synopsis
example_template

Jump to

Keyboard shortcuts

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