import * as plugins from './tswatch.plugins.js'; import * as paths from './tswatch.paths.js'; import './interfaces/index.js'; import { Watcher } from './tswatch.classes.watcher.js'; export class TsWatch { constructor(watchmodeArg) { this.watcherMap = new plugins.lik.ObjectMap(); this.watchmode = watchmodeArg; } /** * starts the TsWatch instance */ async start() { const tsbundle = new plugins.tsbundle.TsBundle(); const htmlHandler = new plugins.tsbundle.HtmlHandler(); switch (this.watchmode) { case 'test': this.watcherMap.add(new Watcher({ filePathToWatch: paths.cwd, commandToExecute: 'npm run test2', timeout: null, })); break; case 'gitzone_npm': this.watcherMap.add(new Watcher({ filePathToWatch: paths.cwd, commandToExecute: 'npm run test', timeout: null, })); break; case 'gitzone_element': // lets create a standard server console.log('bundling TypeScript files to "dist_watch" Note: This is for development only!'); const smartserve = new plugins.smartserve.SmartServe({ injectReload: true, serveDir: plugins.path.join(paths.cwd, './dist_watch/'), port: 3002, }); const bundleAndReloadElement = async () => { await tsbundle.build(paths.cwd, './html/index.ts', './dist_watch/bundle.js', { bundler: 'esbuild' }); await smartserve.reload(); }; this.watcherMap.add(new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'), functionToCall: async () => { await bundleAndReloadElement(); }, timeout: null, })); this.watcherMap.add(new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, './html/'), functionToCall: async () => { await htmlHandler.copyHtml(plugins.path.join(paths.cwd, './html/index.html'), plugins.path.join(paths.cwd, './dist_watch/index.html')); await bundleAndReloadElement(); }, timeout: null, })); await smartserve.start(); /* const parcel = new plugins.smartparcel.Parcel( plugins.path.join(process.cwd(), './html/index.html'), plugins.path.join(process.cwd(), './dist_watch'), 'index.html' ); await parcel.watchAndServe(); */ break; case 'gitzone_website': this.watcherMap.add(new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, './ts/'), commandToExecute: 'npm run startTs', timeout: null, })); const bundleAndReloadWebsite = async () => { await tsbundle.build(paths.cwd, './ts_web/index.ts', './dist_serve/bundle.js', { bundler: 'esbuild' }); }; this.watcherMap.add(new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'), functionToCall: async () => { await bundleAndReloadWebsite(); }, timeout: null, })); this.watcherMap.add(new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, './html/'), functionToCall: async () => { await htmlHandler.copyHtml(plugins.path.join(paths.cwd, './html/index.html'), plugins.path.join(paths.cwd, './dist_serve/index.html')); await bundleAndReloadWebsite(); }, timeout: null, })); // client directory /* const parcelWebsite = new plugins.smartparcel.Parcel( plugins.path.join(process.cwd(), './html/index.html'), plugins.path.join(process.cwd(), './dist_serve'), 'bundle.js' ); await parcelWebsite.watchAndServe(); */ break; case 'gitzone_service': this.watcherMap.add(new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, './ts/'), commandToExecute: 'npm run startTs', timeout: null, })); break; case 'echoSomething': const tsWatchInstanceEchoSomething = new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, './ts'), commandToExecute: 'npm -v', timeout: null, }); this.watcherMap.add(tsWatchInstanceEchoSomething); break; default: break; } this.watcherMap.forEach(async (watcher) => { await watcher.start(); }); if (this.smartserve) { await this.smartserve.start(); } } /** * stops the execution of any active Watchers */ async stop() { if (this.smartserve) { await this.smartserve.stop(); } this.watcherMap.forEach(async (watcher) => { await watcher.stop(); }); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHN3YXRjaC5jbGFzc2VzLnRzd2F0Y2guanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90c3dhdGNoLmNsYXNzZXMudHN3YXRjaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLHNCQUFzQixDQUFDO0FBQ2hELE9BQU8sS0FBSyxLQUFLLE1BQU0sb0JBQW9CLENBQUM7QUFDNUMsT0FBNEIsdUJBQXVCLENBQUM7QUFFcEQsT0FBTyxFQUFFLE9BQU8sRUFBRSxNQUFNLDhC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