Exemplo n.º 1
0
func build(ctx *cli.Context) {
	wd, _ := os.Getwd()
	src := wd
	if f := ctx.String(sourceFlagName); f != "" {
		src = f
	}
	app := bongo.New()
	err := app.Run(src)
	if err != nil {
		log.Println(err)
	}

}
Exemplo n.º 2
0
func serve(ctx *cli.Context) {
	wd, _ := os.Getwd()
	src := wd
	if f := ctx.String(sourceFlagName); f != "" {
		src = f
	}
	app := bongo.New()
	err := app.Run(src)
	if err != nil {
		log.Println(err)
	}
	files, err := bongo.NewLoader().Load(src)
	if err != nil {
		log.Fatal(err)
	}
	watch, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal(err)
	}
	defer watch.Close()
	for _, file := range files {
		watch.Add(file)
	}
	go func() {
		dir := filepath.Join(src, bongo.OutputDir)
		log.Println("serving website", dir, "  at  http://localhost:8000")
		log.Fatal(http.ListenAndServe(":8000", http.FileServer(http.Dir(dir))))
	}()
	for {
		select {
		case event := <-watch.Events:
			if event.Op&(fsnotify.Rename|fsnotify.Create|fsnotify.Write) > 0 {
				log.Printf("detected change %s  Rebuilding...\n", event.Name)
				app.Run(src)
			}
		case err := <-watch.Errors:
			if err != nil {
				log.Println(err)
			}
		default:
			continue
		}
	}

}
Exemplo n.º 3
0
func main() {
	docsDir := "docs"
	app := bongo.New()
	if err := app.Run(docsDir); err != nil {
		log.Fatal(err)
	}

	docsSite := filepath.Join(docsDir, bongo.OutputDir)
	ghPages := filepath.Join(docsDir, "gh-pages", "bongo")

	err := filepath.Walk(docsSite, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		if info.IsDir() {
			return nil
		}
		out := strings.TrimPrefix(path, docsSite)
		dest := filepath.Join(ghPages, out)

		os.MkdirAll(filepath.Dir(dest), 0755)

		b, err := ioutil.ReadFile(path)
		if err != nil {
			return err
		}
		err = ioutil.WriteFile(dest, b, info.Mode())
		if err != nil {
			return err
		}
		return nil
	})
	if err != nil {
		log.Println(err)
	}
}