Ejemplo n.º 1
0
func server(c *config.Config, q *registry.Queue) error {
	tasks := []string{
		"update:check@0",
		"clean@0",
		"recess@0",
		"sass@0",
		"watch@0",
	}
	if err := q.RunTasks(c, tasks); err != nil {
		return err
	}

	sc, err := readServeConfig(c)
	if err != nil {
		return err
	}
	if err := configureExts(); err != nil {
		return fmt.Errorf("configure exts failed")
	}

	if *config.Verbose {
		log.Printf("proxy url: %s (serve base: %+v)\n", sc.url, sc.base)
		log.Printf("proxy mappings: %+v\n", sc.proxy)
	}

	http.Handle("/scenarios/", wrapHandler(c, q, scenariosHandler))
	http.Handle("/test", wrapHandler(c, q, testHandler))
	http.Handle("/utils.js", wrapHandler(c, q, scenariosHandler))
	http.Handle("/angular-scenario.js", wrapHandler(c, q, angularScenarioHandler))
	http.Handle("/scripts/", wrapHandler(c, q, appHandler))
	http.Handle("/styles/", wrapHandler(c, q, stylesHandler))
	http.Handle("/fonts/", wrapHandler(c, q, appHandler))
	http.Handle("/images/", wrapHandler(c, q, appHandler))
	http.Handle("/components/", wrapHandler(c, q, appHandler))
	http.Handle("/views/", wrapHandler(c, q, appHandler))

	p, err := NewProxy(sc)
	if err != nil {
		return fmt.Errorf("cannot prepare proxy: %s", err)
	}
	http.Handle("/", p)

	for _, proxyURL := range sc.proxy {
		log.Printf("%sserving app at http://%s/...%s\n", colors.Yellow, proxyURL.host, colors.Reset)
	}
	if err := http.ListenAndServe(fmt.Sprintf(":%d", *config.Port), nil); err != nil {
		return fmt.Errorf("server listener failed: %s", err)
	}
	return nil
}
Ejemplo n.º 2
0
func updateCheck(c *config.Config, q *registry.Queue) error {
	// Check update-check file before updating again
	shouldCheck, err := checkShouldCheckUpdate()
	if err != nil {
		return err
	}
	if !shouldCheck {
		return nil
	}

	// Fetch last commits, both localy & remotely
	latestSha, err := fetchLatestCommit()
	if err != nil {
		return err
	}
	currentSha, err := fetchCurrentCommit()
	if err != nil {
		return err
	}

	// Couldn't retrieve current/latest commit, ignore update
	if latestSha == "" || currentSha == "" {
		if *config.Verbose {
			log.Printf("local or remote version was not retrieved correctly\n")
		}
		return nil
	}

	if err := writeCheckUpdate(); err != nil {
		return err
	}

	// No update, return directly
	if latestSha == currentSha {
		if *config.Verbose {
			log.Printf("same version detected\n")
		}
		return nil
	}

	// Ask for update
	if utils.Ask("There's a new CB version. Do you want to auto-update it?") {
		return q.RunTasks(c, []string{"update@0"})
	}

	return nil
}
Ejemplo n.º 3
0
func initTask(c *config.Config, q *registry.Queue) error {
	// Check for updates
	if err := q.RunTasks(c, []string{"update:check"}); err != nil {
		return err
	}

	// Retrieve the current working directory
	cur, err := os.Getwd()
	if err != nil {
		return fmt.Errorf("getwd failed: %s", err)
	}

	// Go back one folder if we're inside the client one
	if filepath.Base(cur) == "client" {
		cur = filepath.Dir(cur)
		if pathErr := os.Chdir(cur); pathErr != nil {
			return fmt.Errorf("chdir to root folder failed: %s", err)
		}
	}

	// Prepare some paths and start copying from the root templates folder
	parts := strings.Split(q.CurTask, ":")
	base := utils.PackagePath(filepath.Join(selfPkg, parts[1]))
	appname := filepath.Base(cur)

	if err := copyFiles(c, appname, base, cur, cur); err != nil {
		return fmt.Errorf("copy files failed: %s", err)
	}

	// Post-init steps
	if err := postInit(); err != nil {
		return fmt.Errorf("post init failed: %s", err)
	}

	return nil
}