Skip to content

Commit

Permalink
Add a Version utility func
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Dec 6, 2022
1 parent b86ad77 commit 791a230
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions transpiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package godartsass

import (
"bytes"
"encoding/binary"
"encoding/json"
"errors"
Expand Down Expand Up @@ -72,6 +73,24 @@ func Start(opts Options) (*Transpiler, error) {
return t, nil
}

// Version returns the version of the embedded Dart Sass frameworks as a JSON.
func Version(dartSassEmbeddedFilename string) (string, error) {
bin, err := safeexec.LookPath(dartSassEmbeddedFilename)
if err != nil {
return "", err
}
cmd := exec.Command(bin, "--version")
cmd.Stderr = os.Stderr

var buf bytes.Buffer
cmd.Stdout = &buf

if err := cmd.Run(); err != nil {
return "", err
}
return buf.String(), nil
}

// Transpiler controls transpiling of SCSS into CSS.
type Transpiler struct {
opts Options
Expand Down
10 changes: 10 additions & 0 deletions transpiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ func TestHasScheme(t *testing.T) {
c.Assert(hasScheme("foo"), qt.Equals, false)
}

func TestVersion(t *testing.T) {
c := qt.New(t)

version, err := Version(getSassEmbeddedFilename())
c.Assert(err, qt.IsNil)
c.Assert(version, qt.Not(qt.Equals), "")
c.Assert(version, qt.Contains, "protocolVersion")

}

func newTestTranspiler(c *qt.C, opts Options) (*Transpiler, func()) {
opts.DartSassEmbeddedFilename = getSassEmbeddedFilename()
transpiler, err := Start(opts)
Expand Down

0 comments on commit 791a230

Please sign in to comment.