smartbrowser/dist/index.js

63 lines
4.0 KiB
JavaScript
Raw Normal View History

2016-09-19 18:00:19 +00:00
"use strict";
2017-04-09 14:05:24 +00:00
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
2017-04-09 10:35:53 +00:00
Object.defineProperty(exports, "__esModule", { value: true });
2016-09-19 18:00:19 +00:00
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() {
2017-04-09 14:05:24 +00:00
return __awaiter(this, void 0, void 0, function* () {
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 yield done.promise;
});
2016-09-19 18:00:19 +00:00
}
/**
* stops the smartbrowser instance
*/
stop() {
2017-04-09 14:05:24 +00:00
return __awaiter(this, void 0, void 0, function* () {
this.bsInstance.exit();
this.bsStatus = 'idle';
});
}
reload() {
return __awaiter(this, void 0, void 0, function* () {
this.bsInstance.reload();
});
2016-09-19 18:00:19 +00:00
}
}
exports.Smartbrowser = Smartbrowser;
2017-04-09 14:05:24 +00:00
//# sourceMappingURL=data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