49 lines
3.2 KiB
JavaScript
49 lines
3.2 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const plugins = require("./smartbrowser.plugins");
|
|
/**
|
|
* class smartbrowser controls a browser-sync instance for you
|
|
*/
|
|
class Smartbrowser {
|
|
constructor(optionsArg) {
|
|
this.bsInstance = plugins.browserSync.create();
|
|
this.bsConfig = {
|
|
server: {}
|
|
};
|
|
this.bsStatus = 'idle';
|
|
this.bsConfig.server.baseDir = optionsArg.webroot;
|
|
this.bsConfig.files = optionsArg.watchFiles;
|
|
}
|
|
/**
|
|
* starts the server and returns the browserSync instance in a resolved Promise
|
|
*/
|
|
start() {
|
|
let done = plugins.smartq.defer();
|
|
if (this.bsStatus === 'idle') {
|
|
this.bsStatus = 'starting';
|
|
let localDone = plugins.smartq.defer();
|
|
this.bsStarted = localDone.promise;
|
|
this.bsInstance.init(this.bsConfig, () => {
|
|
this.bsStatus = 'running';
|
|
localDone.resolve();
|
|
done.resolve(this.bsInstance);
|
|
});
|
|
}
|
|
else {
|
|
this.bsStarted.then(() => { done.resolve(this.bsInstance); });
|
|
}
|
|
return done.promise;
|
|
}
|
|
/**
|
|
* stops the smartbrowser instance
|
|
*/
|
|
stop() {
|
|
let done = plugins.smartq.defer();
|
|
this.bsInstance.exit();
|
|
this.bsStatus = 'idle';
|
|
done.resolve();
|
|
return done.promise;
|
|
}
|
|
}
|
|
exports.Smartbrowser = Smartbrowser;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGtEQUFpRDtBQWdCakQ7O0dBRUc7QUFDSDtJQU9FLFlBQWEsVUFBZ0M7UUFON0MsZUFBVSxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsTUFBTSxFQUFFLENBQUE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