commands

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Action = func(c *cli.Context) error {
	in, err := ioutil.ReadFile("package.json")
	if err != nil {
		log.Fatalln("Failed to read package.json:", err)
		os.Exit(1)
	}

	var property property
	if err := json.Unmarshal(in, &property); err != nil {
		log.Fatalln("Failed to parse package.json:", err)
		os.Exit(1)
	}

	var lazyload lazyloadProperty
	if err := json.Unmarshal(in, &lazyload); err != nil {
		log.Fatalln("Failed to parse package.json:", err)
		os.Exit(1)
	}

	var buf bytes.Buffer
	if err := json.Indent(&buf, lazyload.Scripts, "", "  "); err != nil {
		log.Fatalln("Failed to parse package.json:", err)
		os.Exit(1)
	}
	scriptsJSON := buf.String()

	keys := extractKeys(scriptsJSON)

	selects, err := listSelects(property, keys)
	if err != nil {
		log.Fatalln("Failed to make selects:", err)
		os.Exit(1)
	}

	templates := &promptui.SelectTemplates{
		Label:    "{{ . }}?",
		Active:   "▸ {{ .Alias | yellow }} [{{ .Command | cyan }}]",
		Inactive: "  {{ .Alias }} [{{ .Command | faint }}]",
		Selected: "✔ {{ .Alias | yellow }} [{{ .Command | cyan }}]",
	}

	prompt := promptui.Select{
		Label:     "Select npm run script",
		Items:     selects,
		Templates: templates,
		Size:      15,
	}

	i, _, err := prompt.Run()

	if err != nil {
		log.Fatalln("Failed to:", err)
		os.Exit(1)
	}

	if isKeyword(selects[i].Alias) {
		out, _ := exec.Command("npm", selects[i].Alias).CombinedOutput()
		fmt.Println(string(out))
		return nil
	}

	out, _ := exec.Command("npm", "run-script", selects[i].Alias).CombinedOutput()
	fmt.Println(string(out))

	return nil
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL