Exemplo n.º 1
0
func serv(c *cli.Context) error {
	if c.Bool("static") {
		ctx := newContext(c, false)
		builder.Read(ctx)

		dstDir := ctx.DstDir()
		if !com.IsDir(dstDir) {
			log15.Crit("Server|Dest|'%s' is not directory", dstDir)
		}
		log15.Info("Server|Static|%s", dstDir)
		s := server.New(dstDir)
		s.SetPrefix(ctx.Source.Meta.Path)
		s.Run(c.String("addr"))
		return nil
	}
	builder.After(func(ctx *builder.Context) {
		if s == nil {
			s = server.New(ctx.DstDir())
			go s.Run(c.String("addr"))
		}
		if ctx.Source != nil && ctx.Source.Meta != nil {
			s.SetPrefix(ctx.Source.Meta.Path)
		}
	})

	if c.Bool("profile") {
		go http.ListenAndServe("localhost:6060", nil)
		for {
			build(newContext(c, false), false)
			time.Sleep(time.Second)
		}
	} else {
		if c.Bool("no-watch") {
			buildHangUp(newContext(c, true))
			return nil
		}
		build(newContext(c, true), true)
	}

	return nil
}
Exemplo n.º 2
0
func docServ(c *cli.Context) error {
	if !c.Bool("no-server") {
		builder.After(func(ctx *builder.Context) {
			if s == nil {
				s = server.New(ctx.DstDir())
				go s.Run(c.String("addr"))
			}
			if ctx.Source != nil && ctx.Source.Meta != nil {
				s.SetPrefix(ctx.Source.Meta.Path)
			}
		})
	}
	buildContext := newContext(c, false)
	buildContext.From = "doc/source"
	buildContext.To = "doc/dest"
	buildContext.ThemeName = "doc/theme"
	buildContext.Tree.Dest = buildContext.DstDir()
	buildContext.Sync = sync.NewSyncer(buildContext.DstDir())
	build(buildContext, !c.Bool("no-server"))
	return nil
}