Example #1
0
File: gen.go Project: eZanmoto/Bake
// GenTo generates the project p to dest.
func (p *Project) GenTo(dest string) error {
	templPath, err := env.TemplatesPath()
	if err != nil {
		return err
	}

	langRoot := path.Join(templPath, p.lang)

	filePaths := joinAll(langRoot, append(p.types, baseInclFile))
	incls, err := ParseInclFiles(filePaths...)
	if err != nil {
		return err
	}
	root := fs.NewDir("{ProjectName}", incls.Children()...)

	return p.genDirConts(fs.NewDir("").AddNode(root), langRoot, "")
}
Example #2
0
func printTypesFor(lang string) {
	tmplDir, err := env.TemplatesPath()
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		os.Exit(2)
	}

	langDir := path.Join(tmplDir, lang)

	fis, err := ioutil.ReadDir(langDir)
	if len(fis) <= 2 {
		fmt.Fprintf(os.Stderr, "'%s' is not fully supported\n", lang)
		os.Exit(2)
	}

	typeNames := make([]string, len(fis)-2)
	i := 0
	for _, fi := range fis {
		name := fi.Name()
		if name != "base" && name != "{ProjectName}" {
			typeNames[i] = name
			i++
		}
	}

	for _, name := range typeNames {
		file, err := os.Open(path.Join(langDir, name))
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			os.Exit(2)
		}
		defer file.Close()

		descr, err := bufio.NewReader(file).ReadString('\n')
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			os.Exit(2)
		}

		fmt.Printf("%s\t%s", name, descr)
	}
}