update to latest standards

This commit is contained in:
2017-04-09 12:35:53 +02:00
parent c9fd889dd3
commit 43bc078ace
15 changed files with 2958 additions and 193 deletions

View File

@ -4,8 +4,8 @@ import * as plugins from './smartbrowser.plugins'
* the options interface of a Smartbrowser instance
*/
export interface ISmartbrowserOptions {
webroot: string
watchFiles: string[]
webroot: string
watchFiles: string[]
}
@ -18,45 +18,45 @@ export type bsStatus = 'idle' | 'starting' | 'running'
* class smartbrowser controls a browser-sync instance for you
*/
export class Smartbrowser {
bsInstance = plugins.browserSync.create()
bsConfig: plugins.browserSync.Options = {
server: {}
}
bsStatus: bsStatus = 'idle'
bsStarted: plugins.q.Promise<void>
constructor(optionsArg: ISmartbrowserOptions) {
this.bsConfig.server.baseDir = optionsArg.webroot
this.bsConfig.files = optionsArg.watchFiles
}
bsInstance = plugins.browserSync.create()
bsConfig: plugins.browserSync.Options = {
server: {}
}
bsStatus: bsStatus = 'idle'
bsStarted: Promise<void>
constructor (optionsArg: ISmartbrowserOptions) {
this.bsConfig.server.baseDir = optionsArg.webroot
this.bsConfig.files = optionsArg.watchFiles
}
/**
* starts the server and returns the browserSync instance in a resolved Promise
*/
start(): plugins.q.Promise<plugins.browserSync.BrowserSyncInstance> {
let done = plugins.q.defer<plugins.browserSync.BrowserSyncInstance>()
if (this.bsStatus === 'idle') {
this.bsStatus = 'starting'
let localDone = plugins.q.defer<void>()
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
/**
* starts the server and returns the browserSync instance in a resolved Promise
*/
start (): Promise<plugins.browserSync.BrowserSyncInstance> {
let done = plugins.smartq.defer<plugins.browserSync.BrowserSyncInstance>()
if (this.bsStatus === 'idle') {
this.bsStatus = 'starting'
let localDone = plugins.smartq.defer<void>()
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(): plugins.q.Promise<void> {
let done = plugins.q.defer<void>()
this.bsInstance.exit()
this.bsStatus = 'idle'
done.resolve()
return done.promise
}
/**
* stops the smartbrowser instance
*/
stop (): Promise<void> {
let done = plugins.smartq.defer<void>()
this.bsInstance.exit()
this.bsStatus = 'idle'
done.resolve()
return done.promise
}
}

View File

@ -1,3 +1,3 @@
import 'typings-global'
export import browserSync = require('browser-sync')
export import q = require('q')
export import smartq = require('smartq')