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 9f9f1c1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
33 changes: 33 additions & 0 deletions transpiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,39 @@ func Start(opts Options) (*Transpiler, error) {
return t, nil
}

// Version returns version information about the Dart Sass frameworks used
// in dartSassEmbeddedFilename.
func Version(dartSassEmbeddedFilename string) (DartSassVersion, error) {
var v DartSassVersion
bin, err := safeexec.LookPath(dartSassEmbeddedFilename)
if err != nil {
return v, err
}

cmd := exec.Command(bin, "--version")
cmd.Stderr = os.Stderr

out, err := cmd.Output()
if err != nil {
return v, err
}

if err := json.Unmarshal(out, &v); err != nil {
return v, err
}

return v, nil

}

type DartSassVersion struct {
ProtocolVersion string `json:"protocolVersion"`
CompilerVersion string `json:"compilerVersion"`
ImplementationVersion string `json:"implementationVersion"`
ImplementationName string `json:"implementationName"`
ID int `json:"id"`
}

// 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.ProtocolVersion, qt.Equals, "1.1.0")

}

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

0 comments on commit 9f9f1c1

Please sign in to comment.