Skip to content

Commit

Permalink
feat(tools): add csp-evaluator-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ngalaiko committed Sep 6, 2024
1 parent 55ef3d1 commit 5dbc9b1
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ updates:
directory: tools/sgmdformat
schedule:
interval: weekly

- package-ecosystem: npm
directory: tools/sgcspevaluatorcli
schedule:
interval: weekly
5 changes: 5 additions & 0 deletions tools/sgcspevaluatorcli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@einride/csp-evaluator-cli": "1.0.0"
}
}
51 changes: 51 additions & 0 deletions tools/sgcspevaluatorcli/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package sgcspevaluatorcli

import (
"context"
_ "embed"
"os"
"os/exec"
"path/filepath"

"go.einride.tech/sage/sg"
"go.einride.tech/sage/sgtool"
)

const name = "csp"

//go:embed package.json
var packageJSONContent []byte

func Command(ctx context.Context, args ...string) *exec.Cmd {
sg.Deps(ctx, PrepareCommand)
return sg.Command(ctx, sg.FromBinDir(name), args...)
}

func PrepareCommand(ctx context.Context) error {
sg.Logger(ctx).Println("installing packages...")
toolDir := sg.FromToolsDir(name)
if err := os.MkdirAll(toolDir, 0o755); err != nil {
return err
}
packageJSONPath := filepath.Join(toolDir, "package.json")
if err := os.WriteFile(packageJSONPath, packageJSONContent, 0o600); err != nil {
return err
}
cmd := sg.Command(
ctx,
"npm",
"--silent",
"install",
"--prefix",
toolDir,
"--no-save",
"--no-audit",
"--ignore-script",
)
if err := cmd.Run(); err != nil {
return err
}
binary := filepath.Join(toolDir, "node_modules", ".bin", name)
_, err := sgtool.CreateSymlink(binary)
return err
}

0 comments on commit 5dbc9b1

Please sign in to comment.