tswatch/dist_ts/tswatch.classes.tswatch.js

136 lines
11 KiB
JavaScript
Raw Normal View History

2022-03-14 21:04:11 +00:00
import * as plugins from './tswatch.plugins.js';
import * as paths from './tswatch.paths.js';
2023-08-26 12:56:09 +00:00
import * as interfaces from './interfaces/index.js';
2022-03-14 21:04:11 +00:00
import { Watcher } from './tswatch.classes.watcher.js';
export class TsWatch {
2020-05-22 07:25:34 +00:00
constructor(watchmodeArg) {
this.watcherMap = new plugins.lik.ObjectMap();
this.watchmode = watchmodeArg;
}
/**
* starts the TsWatch instance
*/
async start() {
2022-04-21 21:41:45 +00:00
const tsbundle = new plugins.tsbundle.TsBundle();
const htmlHandler = new plugins.tsbundle.HtmlHandler();
2020-05-22 07:25:34 +00:00
switch (this.watchmode) {
case 'test':
2022-03-14 21:04:11 +00:00
this.watcherMap.add(new Watcher({
2020-05-22 07:25:34 +00:00
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test2',
2021-03-08 00:26:44 +00:00
timeout: null,
2020-05-22 07:25:34 +00:00
}));
break;
case 'gitzone_npm':
2022-03-14 21:04:11 +00:00
this.watcherMap.add(new Watcher({
2020-05-22 07:25:34 +00:00
filePathToWatch: paths.cwd,
commandToExecute: 'npm run test',
2021-03-08 00:26:44 +00:00
timeout: null,
2020-05-22 07:25:34 +00:00
}));
break;
case 'gitzone_element':
// lets create a standard server
console.log('bundling TypeScript files to "dist_watch" Note: This is for development only!');
2023-03-31 11:10:29 +00:00
this.typedserver = new plugins.typedserver.TypedServer({
cors: true,
2022-03-18 15:36:13 +00:00
injectReload: true,
serveDir: plugins.path.join(paths.cwd, './dist_watch/'),
port: 3002,
2024-01-09 10:27:52 +00:00
enableCompression: true,
preferredCompressionMethod: 'gzip',
2022-03-18 15:36:13 +00:00
});
2022-04-21 21:41:45 +00:00
const bundleAndReloadElement = async () => {
await tsbundle.build(paths.cwd, './html/index.ts', './dist_watch/bundle.js', {
2022-08-02 13:38:04 +00:00
bundler: 'esbuild',
2022-03-18 15:36:13 +00:00
});
2023-03-31 11:10:29 +00:00
await this.typedserver.reload();
2022-03-18 15:36:13 +00:00
};
this.watcherMap.add(new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'),
functionToCall: async () => {
2022-04-21 21:41:45 +00:00
await bundleAndReloadElement();
},
timeout: null,
}));
this.watcherMap.add(new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './html/'),
functionToCall: async () => {
2022-08-02 13:38:04 +00:00
await htmlHandler.processHtml({
from: plugins.path.join(paths.cwd, './html/index.html'),
to: plugins.path.join(paths.cwd, './dist_watch/index.html'),
minify: false,
});
2022-04-21 21:41:45 +00:00
await bundleAndReloadElement();
2022-03-18 15:36:13 +00:00
},
timeout: null,
}));
2020-05-22 07:25:34 +00:00
break;
case 'gitzone_website':
2022-03-14 21:04:11 +00:00
this.watcherMap.add(new Watcher({
2020-05-22 07:25:34 +00:00
filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
commandToExecute: 'npm run startTs',
2021-03-08 00:26:44 +00:00
timeout: null,
2020-05-22 07:25:34 +00:00
}));
2022-04-21 21:41:45 +00:00
const bundleAndReloadWebsite = async () => {
await tsbundle.build(paths.cwd, './ts_web/index.ts', './dist_serve/bundle.js', {
2022-08-02 13:38:04 +00:00
bundler: 'esbuild',
2022-04-21 21:41:45 +00:00
});
};
2022-03-18 15:36:13 +00:00
this.watcherMap.add(new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'),
2022-04-21 21:41:45 +00:00
functionToCall: async () => {
await bundleAndReloadWebsite();
},
timeout: null,
}));
this.watcherMap.add(new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './html/'),
functionToCall: async () => {
2022-08-02 13:38:04 +00:00
await htmlHandler.processHtml({
from: plugins.path.join(paths.cwd, './html/index.html'),
to: plugins.path.join(paths.cwd, './dist_serve/index.html'),
minify: false,
});
2022-04-21 21:41:45 +00:00
await bundleAndReloadWebsite();
},
2022-03-18 15:36:13 +00:00
timeout: null,
}));
2020-05-22 07:25:34 +00:00
break;
case 'gitzone_service':
2022-03-14 21:04:11 +00:00
this.watcherMap.add(new Watcher({
2020-05-22 07:25:34 +00:00
filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
commandToExecute: 'npm run startTs',
2021-03-08 00:26:44 +00:00
timeout: null,
2020-05-22 07:25:34 +00:00
}));
break;
case 'echoSomething':
2022-03-14 21:04:11 +00:00
const tsWatchInstanceEchoSomething = new Watcher({
2020-05-22 07:25:34 +00:00
filePathToWatch: plugins.path.join(paths.cwd, './ts'),
commandToExecute: 'npm -v',
2021-03-08 00:26:44 +00:00
timeout: null,
2020-05-22 07:25:34 +00:00
});
this.watcherMap.add(tsWatchInstanceEchoSomething);
break;
default:
break;
}
this.watcherMap.forEach(async (watcher) => {
await watcher.start();
});
2023-03-31 11:10:29 +00:00
if (this.typedserver) {
await this.typedserver.start();
2020-05-22 07:25:34 +00:00
}
}
/**
* stops the execution of any active Watchers
*/
async stop() {
2023-03-31 11:10:29 +00:00
if (this.typedserver) {
await this.typedserver.stop();
2020-05-22 07:25:34 +00:00
}
this.watcherMap.forEach(async (watcher) => {
await watcher.stop();
});
}
}
2024-01-09 10:27:52 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHN3YXRjaC5jbGFzc2VzLnRzd2F0Y2guanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy90c3dhdGNoLmNsYXNzZXMudHN3YXRjaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLHNCQUFzQixDQUFDO0FBQ2hELE9BQU8sS0FBSyxLQUFLLE1BQU0sb0JBQW9CLENBQUM7QUFDNUMsT0FBTyxLQUFLLFVBQVUsTUFBTSx1QkFBdUIsQ0FBQztBQUVwRCxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sOEJBQThCLENBQUM7QUFFdkQsTUFBTSxPQUFPLE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