2018-04-08 23:03:39 +00:00
|
|
|
import * as q from 'smartq';
|
|
|
|
import * as smartchok from 'smartchok';
|
2016-10-21 15:48:52 +00:00
|
|
|
|
2018-04-08 23:03:39 +00:00
|
|
|
import * as plugins from './npmts.plugins';
|
|
|
|
import * as cli from './npmts.cli';
|
2016-10-02 18:35:13 +00:00
|
|
|
|
2018-04-08 23:03:39 +00:00
|
|
|
import { INpmtsConfig } from './npmts.config';
|
2016-09-22 21:23:16 +00:00
|
|
|
|
2018-04-08 23:03:39 +00:00
|
|
|
let npmtsSmartchok: smartchok.Smartchok = null;
|
2016-09-25 18:22:10 +00:00
|
|
|
export let run = (configArg: INpmtsConfig) => {
|
2018-04-08 23:03:39 +00:00
|
|
|
let done = q.defer();
|
2017-08-31 18:48:30 +00:00
|
|
|
if (configArg.watch && npmtsSmartchok === null) {
|
2018-04-08 23:03:39 +00:00
|
|
|
let pathsToWatch: string[] = [];
|
2017-08-31 18:48:30 +00:00
|
|
|
for (let key in configArg.ts) {
|
2018-04-08 23:03:39 +00:00
|
|
|
pathsToWatch.push(key);
|
2016-09-22 21:23:16 +00:00
|
|
|
}
|
2017-08-31 18:48:30 +00:00
|
|
|
for (let key in configArg.testTs) {
|
2018-04-08 23:03:39 +00:00
|
|
|
pathsToWatch.push(key);
|
2017-08-31 18:48:30 +00:00
|
|
|
}
|
2018-04-08 23:03:39 +00:00
|
|
|
npmtsSmartchok = new smartchok.Smartchok(pathsToWatch);
|
|
|
|
npmtsSmartchok.getObservableFor('change').then(changeObservableArg => {
|
|
|
|
plugins.beautylog.info('now watching...');
|
2017-08-31 18:48:30 +00:00
|
|
|
changeObservableArg.subscribe(() => {
|
2018-04-08 23:03:39 +00:00
|
|
|
cli.run();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
npmtsSmartchok.start();
|
|
|
|
done.resolve(configArg);
|
2017-08-31 18:48:30 +00:00
|
|
|
} else {
|
2018-04-08 23:03:39 +00:00
|
|
|
plugins.beautylog.info('not watching');
|
|
|
|
done.resolve(configArg);
|
2017-08-31 18:48:30 +00:00
|
|
|
}
|
2018-04-08 23:03:39 +00:00
|
|
|
return done.promise;
|
|
|
|
};
|