func (g *Gaudi) copyRelativeFiles(filePath, destination string) bool { // File cannot be absolute if util.IsFile(filePath) && filePath[0] == '/' { util.LogError("File '" + filePath + "' cannot be an absolute path") } // Check if the relative file exists absolutePath := g.ApplicationDir + "/" + filePath if util.IsFile(absolutePath) { // Move file to the build context (and keep the same file tree) directories := strings.Split(filePath, "/") if len(directories) > 1 { os.MkdirAll(destination+strings.Join(directories[0:len(directories)-1], "/"), 0755) } err := util.Copy(destination+filePath, absolutePath) if err != nil { util.LogError(err) } return true } return false }
func (gaudi *Gaudi) build() { // Retrieve application Path currentDirctory, _ := os.Getwd() err := os.MkdirAll(PARSED_TEMPLATE_DIR, 0700) if err != nil { util.LogError(err) } // Retrieve includes includes := getIncludes() for _, currentContainer := range gaudi.All { // Check if the container has a type if currentContainer.Type == "" { util.LogError("Container " + currentContainer.Name + " should have a field called 'type'.") } if !currentContainer.IsGaudiManaged() { continue } // Check if the beforeScript is a file beforeScript := currentContainer.BeforeScript if len(beforeScript) != 0 { copied := gaudi.copyRelativeFiles(beforeScript, PARSED_TEMPLATE_DIR+currentContainer.Name+"/") if copied { currentContainer.BeforeScript = "./" + currentContainer.BeforeScript } } // Check if the afterScript is a file afterScript := currentContainer.AfterScript if len(afterScript) != 0 { copied := gaudi.copyRelativeFiles(afterScript, PARSED_TEMPLATE_DIR+currentContainer.Name+"/") if copied { currentContainer.AfterScript = "./" + currentContainer.AfterScript } } templateDir, isCustom := gaudi.GetContainerTemplate(currentContainer) files, err := ioutil.ReadDir(templateDir) if err != nil { util.LogError("Application '" + currentContainer.Type + "' is not supported. Check http://gaudi.io/components.html for a list of supported applications.") } err = os.MkdirAll(PARSED_TEMPLATE_DIR+currentContainer.Name, 0755) if err != nil { util.LogError(err) } sourceTemplateDir := TEMPLATE_DIR + currentContainer.Type if isCustom { sourceTemplateDir = templateDir } // Parse & copy files for _, file := range files { gaudi.parseTemplate(sourceTemplateDir, PARSED_TEMPLATE_DIR, file, includes, currentContainer) } // Copy all files marked as Add for fileToAdd := range currentContainer.Add { filePath := currentDirctory + "/" + fileToAdd directories := strings.Split(fileToAdd, "/") if len(directories) > 1 { os.MkdirAll(PARSED_TEMPLATE_DIR+currentContainer.Name+"/"+strings.Join(directories[0:len(directories)-1], "/"), 0755) } err := util.Copy(PARSED_TEMPLATE_DIR+currentContainer.Name+"/"+fileToAdd, filePath) if err != nil { util.LogError(err) } } } }