diff --git a/transpiler.go b/transpiler.go index 879f0ee..f00f3f0 100644 --- a/transpiler.go +++ b/transpiler.go @@ -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 diff --git a/transpiler_test.go b/transpiler_test.go index b9c618f..990ea46 100644 --- a/transpiler_test.go +++ b/transpiler_test.go @@ -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)