smartsass/ts/index.ts

49 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-03-05 17:29:46 +00:00
import * as plugins from './smartsass.plugins'
// interfaces
import { Result } from 'node-sass'
export interface ISmartsassConstructorOptions {
2017-03-11 23:55:34 +00:00
entryFilePath: string,
includePaths?: string[]
2017-03-05 17:29:46 +00:00
}
export class Smartsass {
2017-03-11 23:55:34 +00:00
includePaths = []
2017-03-05 17:29:46 +00:00
entryFilePath: string
constructor(optionsArg: ISmartsassConstructorOptions) {
this.entryFilePath = optionsArg.entryFilePath
2017-03-11 23:55:34 +00:00
if(optionsArg.includePaths) {
for (let includePath of optionsArg.includePaths) {
this.includePaths.push(includePath)
}
}
2017-03-05 17:29:46 +00:00
}
/**
* renders the Smartsass classes' entryfile and returns result as string
*/
render() {
let done = plugins.smartq.defer<plugins.sass.Result>()
plugins.sass.render({
2017-03-11 23:55:34 +00:00
file: this.entryFilePath,
includePaths: this.includePaths
2017-03-05 17:29:46 +00:00
}, function (err, result) {
if (err) {
console.log(err)
done.reject(err)
}
done.resolve(result)
})
return done.promise
}
/**
* renders and stores
*/
async renderAndStore (outputFilePath: string) {
let result = await this.render()
await plugins.smartfile.memory.toFs(result.css.toString(), outputFilePath)
}
}