Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RunCommand = &cli.Command{ Name: "run", Usage: "Run npm script and expose port", UsageText: "localhost run [start]", Action: func(ctx context.Context, c *cli.Command) error { scriptName := c.Args().First() if scriptName == "" { return cli.ShowSubcommandHelp(c) } cwd, err := os.Getwd() if err != nil { return util.WrapError(err, "unable to find current working directory") } pkgJsonPath := filepath.Join(cwd, "package.json") jsonBytes, err := os.ReadFile(pkgJsonPath) if err != nil { return util.WrapError(err, "error reading package.json") } pkg := new(PkgJson) err = json.Unmarshal(jsonBytes, pkg) if err != nil { return util.WrapError(err, "error parsing package.json (%s)", pkgJsonPath) } scriptCommand, hasScriptCommand := pkg.Scripts[scriptName] if !hasScriptCommand { return fmt.Errorf("unable to find npm script: %s", scriptName) } scriptCommand = strings.TrimSpace(scriptCommand) cmd := exec.Command("sh", "-c", scriptCommand) cmd.Env = os.Environ() cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err = cmd.Run() return err }, }
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.