2018-10-28 00:48:43 +00:00
|
|
|
import * as plugins from './tswatch.plugins';
|
2019-05-08 22:08:40 +00:00
|
|
|
import * as paths from './tswatch.paths';
|
|
|
|
import * as interfaces from './interfaces';
|
2018-10-28 00:48:43 +00:00
|
|
|
|
2019-05-08 22:08:40 +00:00
|
|
|
import { Watcher } from './tswatch.classes.watcher';
|
2018-10-28 18:28:08 +00:00
|
|
|
|
2018-10-28 00:48:43 +00:00
|
|
|
export class TsWatch {
|
2019-05-08 22:08:40 +00:00
|
|
|
public watchmode: interfaces.TWatchModes;
|
2020-05-22 07:25:34 +00:00
|
|
|
public watcherMap = new plugins.lik.ObjectMap<Watcher>();
|
2019-10-14 12:53:55 +00:00
|
|
|
public smartserve: plugins.smartserve.SmartServe;
|
2018-10-28 00:48:43 +00:00
|
|
|
|
2019-05-08 22:08:40 +00:00
|
|
|
constructor(watchmodeArg: interfaces.TWatchModes) {
|
2019-05-13 07:48:35 +00:00
|
|
|
this.watchmode = watchmodeArg;
|
2018-10-28 00:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-08 22:08:40 +00:00
|
|
|
* starts the TsWatch instance
|
2018-10-28 00:48:43 +00:00
|
|
|
*/
|
2019-05-13 07:48:35 +00:00
|
|
|
public async start() {
|
2019-05-08 22:08:40 +00:00
|
|
|
switch (this.watchmode) {
|
|
|
|
case 'test':
|
2019-10-12 13:07:44 +00:00
|
|
|
this.watcherMap.add(
|
|
|
|
new Watcher({
|
|
|
|
filePathToWatch: paths.cwd,
|
|
|
|
commandToExecute: 'npm run test2',
|
2020-07-04 10:35:16 +00:00
|
|
|
timeout: null,
|
2019-10-12 13:07:44 +00:00
|
|
|
})
|
|
|
|
);
|
2019-05-08 22:08:40 +00:00
|
|
|
break;
|
|
|
|
case 'gitzone_npm':
|
2019-10-12 13:07:44 +00:00
|
|
|
this.watcherMap.add(
|
|
|
|
new Watcher({
|
|
|
|
filePathToWatch: paths.cwd,
|
|
|
|
commandToExecute: 'npm run test',
|
2020-07-04 10:35:16 +00:00
|
|
|
timeout: null,
|
2019-10-12 13:07:44 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'gitzone_element':
|
2019-10-12 16:09:41 +00:00
|
|
|
// lets create a standard server
|
2020-03-13 17:48:19 +00:00
|
|
|
console.log(
|
|
|
|
'bundling TypeScript files to "dist_watch" Note: This is for development only!'
|
|
|
|
);
|
2020-07-07 18:30:17 +00:00
|
|
|
const parcel = new plugins.smartparcel.Parcel(
|
2020-07-04 10:35:16 +00:00
|
|
|
plugins.path.join(process.cwd(), './html/index.html'),
|
|
|
|
plugins.path.join(process.cwd(), './dist_watch'),
|
|
|
|
'index.html'
|
|
|
|
);
|
2020-03-13 17:43:57 +00:00
|
|
|
await parcel.start();
|
2019-05-08 22:08:40 +00:00
|
|
|
break;
|
|
|
|
case 'gitzone_website':
|
2019-05-13 07:48:35 +00:00
|
|
|
this.watcherMap.add(
|
|
|
|
new Watcher({
|
|
|
|
filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
|
2019-10-12 13:07:44 +00:00
|
|
|
commandToExecute: 'npm run startTs',
|
2020-07-04 10:35:16 +00:00
|
|
|
timeout: null,
|
2019-05-13 07:48:35 +00:00
|
|
|
})
|
|
|
|
);
|
2019-10-12 13:07:44 +00:00
|
|
|
|
2019-05-13 07:48:35 +00:00
|
|
|
// client directory
|
2020-07-07 18:30:17 +00:00
|
|
|
const parcelWebsite = new plugins.smartparcel.Parcel(
|
2020-07-04 10:35:16 +00:00
|
|
|
plugins.path.join(process.cwd(), './ts_web/index.ts'),
|
|
|
|
plugins.path.join(process.cwd(), './dist_serve'),
|
|
|
|
'bundle.js'
|
2019-10-12 13:07:44 +00:00
|
|
|
);
|
2020-07-04 10:35:16 +00:00
|
|
|
await parcelWebsite.start();
|
2020-07-04 10:49:00 +00:00
|
|
|
break;
|
2019-10-14 12:57:43 +00:00
|
|
|
case 'gitzone_service':
|
2020-03-13 17:48:19 +00:00
|
|
|
this.watcherMap.add(
|
|
|
|
new Watcher({
|
|
|
|
filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
|
|
|
|
commandToExecute: 'npm run startTs',
|
2020-07-04 10:35:16 +00:00
|
|
|
timeout: null,
|
2020-03-13 17:48:19 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
break;
|
2019-05-13 07:48:35 +00:00
|
|
|
case 'echoSomething':
|
|
|
|
const tsWatchInstanceEchoSomething = new Watcher({
|
2019-10-12 15:34:05 +00:00
|
|
|
filePathToWatch: plugins.path.join(paths.cwd, './ts'),
|
2019-05-13 07:48:35 +00:00
|
|
|
commandToExecute: 'npm -v',
|
2020-07-04 10:35:16 +00:00
|
|
|
timeout: null,
|
2019-05-08 22:08:40 +00:00
|
|
|
});
|
2019-05-13 07:48:35 +00:00
|
|
|
this.watcherMap.add(tsWatchInstanceEchoSomething);
|
2019-05-08 22:08:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2018-10-28 00:48:43 +00:00
|
|
|
}
|
2020-07-04 10:35:16 +00:00
|
|
|
this.watcherMap.forEach(async (watcher) => {
|
2019-05-08 22:08:40 +00:00
|
|
|
await watcher.start();
|
|
|
|
});
|
2019-10-14 12:53:55 +00:00
|
|
|
if (this.smartserve) {
|
|
|
|
await this.smartserve.start();
|
|
|
|
}
|
2018-10-28 00:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-05-08 22:08:40 +00:00
|
|
|
* stops the execution of any active Watchers
|
2018-10-28 00:48:43 +00:00
|
|
|
*/
|
2019-05-13 07:48:35 +00:00
|
|
|
public async stop() {
|
2019-10-14 12:53:55 +00:00
|
|
|
if (this.smartserve) {
|
|
|
|
await this.smartserve.stop();
|
|
|
|
}
|
2020-07-04 10:35:16 +00:00
|
|
|
this.watcherMap.forEach(async (watcher) => {
|
2019-05-08 22:08:40 +00:00
|
|
|
await watcher.stop();
|
2019-05-13 07:48:35 +00:00
|
|
|
});
|
2018-10-28 00:48:43 +00:00
|
|
|
}
|
|
|
|
}
|