Exemplo n.º 1
0
func doForm(c *config.Config, q *registry.Queue, mode string) error {
	if !templates.IsRegistered(mode) {
		return fmt.Errorf("unrecognized template mode: %s", mode)
	}
	templates.SetMode(mode)

	filename := q.NextTask()
	if filename == "" {
		return fmt.Errorf("validator filename not passed as an argument")
	}
	q.RemoveNextTask()

	form, err := parseForm(filename)
	if err != nil {
		return fmt.Errorf("parse form failed: %s", err)
	}

	result := strings.Replace(form.Build(), "'", `'"'"'`, -1)
	args := []string{
		"-c", fmt.Sprintf(`echo -n '%s' | xsel -bi`, result),
	}
	output, err := utils.Exec("bash", args)
	if err != nil {
		fmt.Println(output)
		return fmt.Errorf("bash error: %s", err)
	}

	return nil
}
Exemplo n.º 2
0
func push(c *config.Config, q *registry.Queue) error {
	scriptsPath := utils.PackagePath(selfPkg)
	host := c.GetRequired("push")

	// FTP User & password
	user := q.NextTask()
	if user == "" {
		return fmt.Errorf("ftp user required as the first argument")
	}
	q.RemoveNextTask()

	password, err := gopass.GetPass(fmt.Sprintf("Enter \"%s\" password: "******"cannot read password: %s", err)
	}
	if password == "" {
		return fmt.Errorf("ftp password is required")
	}

	// Hash local files
	log.Printf("Hashing local files... ")
	localHashes, err := hashLocalFiles()
	if err != nil {
		return fmt.Errorf("hash local files failed: %s", err)
	}
	log.Printf("Hashing local files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	// Hash remote files
	log.Printf("Hashing remote files... ")
	remoteHashes, err := retrieveRemoteHashes(scriptsPath, user, password, host)
	if err != nil {
		return fmt.Errorf("retrieve remote hashes failed: %s", err)
	}
	log.Printf("Hashing remote files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	if err := saveLocalHashes(localHashes); err != nil {
		return fmt.Errorf("save local hashes failed: %s", err)
	}

	// Prepare FTP commands
	log.Printf("Preparing FTP commands... ")
	if err := prepareFTPCommands(localHashes, remoteHashes); err != nil {
		return fmt.Errorf("prepare FTP commands failed: %s", err)
	}
	log.Printf("Preparing FTP commands... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	// Upload files
	log.Printf("Uploading files... ")
	if err := uploadFiles(scriptsPath, user, password, host); err != nil {
		return fmt.Errorf("uploading files failed: %s", err)
	}
	log.Printf("Uploading files... %s[SUCCESS]%s\n", colors.Green, colors.Reset)

	return nil
}
Exemplo n.º 3
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
}
Exemplo n.º 4
0
func service(c *config.Config, q *registry.Queue) error {
	name := q.NextTask()
	if name == "" {
		return fmt.Errorf("first arg should be the name of the service")
	}
	q.RemoveNextTask()
	module := q.NextTask()
	if module == "" {
		return fmt.Errorf("second arg should be the module of the service")
	}
	q.RemoveNextTask()

	data := &serviceData{
		Name:     name,
		Module:   module,
		Filename: filepath.Join(strings.Split(module, ".")...),
	}
	if err := writeServiceFile(data); err != nil {
		return fmt.Errorf("write service failed: %s", err)
	}
	if err := writeServiceTestFile(data); err != nil {
		return fmt.Errorf("write service test failed: %s", err)
	}

	return nil
}
Exemplo n.º 5
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
}
Exemplo n.º 6
0
func build(c *config.Config, q *registry.Queue) error {
	q.AddTasks([]string{
		"update:check@0",
		"clean@0",
		"dist:prepare@0",
		"recess:build@0",
		"sass:build@0",
		"imagemin@0",
		"minignore@0",
		"ngmin@0",
		"compilejs@0",
		"concat@0",
		"htmlmin@0",
		"ngtemplates@0",
		"cacherev@0",
		"dist:copy@0",
	})

	deploy := c.GetDefault("deploy.mode", "")
	if len(deploy) > 0 {
		q.AddTask(fmt.Sprintf("deploy:%s", deploy))
	}
	return nil
}
Exemplo n.º 7
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
}
Exemplo n.º 8
0
func controller_noview(c *config.Config, q *registry.Queue) error {
	name := q.NextTask()
	if name == "" {
		return fmt.Errorf("first arg should be the name of the controller")
	}
	q.RemoveNextTask()
	if !strings.Contains(name, "Ctrl") {
		name = name + "Ctrl"
	}
	module := q.NextTask()
	if module == "" {
		return fmt.Errorf("second arg should be the module of the controller")
	}
	q.RemoveNextTask()
	route := q.NextTask()
	q.RemoveNextTask()

	data := &controllerData{
		Name:     name,
		Module:   module,
		Route:    route,
		Filename: filepath.Join(strings.Split(module, ".")...),
		AppPath:  c.GetDefault("paths.app", filepath.Join("app", "scripts", "app.js")),
	}
	if err := writeControllerFile(data); err != nil {
		return fmt.Errorf("write controller failed: %s", err)
	}
	if err := writeControllerTestFile(data); err != nil {
		return fmt.Errorf("write controller test failed: %s", err)
	}
	if route != "" {
		if err := writeControllerRouteFile(data); err != nil {
			return fmt.Errorf("write route failed: %s", err)
		}
	}

	return nil
}
Exemplo n.º 9
0
func e2eCompiled(c *config.Config, q *registry.Queue) error {
	q.AddTask("server:angular:compiled")
	return nil
}
Exemplo n.º 10
0
func e2e(c *config.Config, q *registry.Queue) error {
	q.AddTask("server")
	return nil
}