-
Notifications
You must be signed in to change notification settings - Fork 9
/
nodejs.go
47 lines (38 loc) · 1.07 KB
/
nodejs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package source
import (
"context"
"os"
"path/filepath"
"github.com/spf13/cobra"
"namespacelabs.dev/foundation/internal/cli/fncobra"
"namespacelabs.dev/foundation/internal/nodejs"
"namespacelabs.dev/foundation/internal/parsing/module"
"namespacelabs.dev/foundation/std/cfg"
)
func newNodejsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "node",
Short: "Run nodejs.",
}
return fncobra.CmdWithEnv(cmd, func(ctx context.Context, env cfg.Context, args []string) error {
relPath, err := relCwd(ctx)
if err != nil {
return err
}
return nodejs.RunNodejs(ctx, env, relPath, "node", &nodejs.RunNodejsOpts{Args: args, IsInteractive: true})
})
}
func relCwd(ctx context.Context) (string, error) {
root, err := module.FindRoot(ctx, ".")
if err != nil {
return "", err
}
cwd, err := os.Getwd()
if err != nil {
return "", err
}
return filepath.Rel(root.Abs(), cwd)
}