smartsass/ts/index.ts

65 lines
1.5 KiB
TypeScript
Raw Normal View History

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