feat(server): use UtilityWebsiteServer for dev server, add domain option, update docs, and bump dependencies
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@git.zone/tswatch',
|
||||
version: '3.2.1',
|
||||
version: '3.3.0',
|
||||
description: 'A development tool for automatically watching and re-compiling TypeScript projects upon detecting file changes, enhancing developer workflows.'
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ export interface IServerConfig {
|
||||
serveDir?: string;
|
||||
/** Whether to inject live reload script (default: true) */
|
||||
liveReload?: boolean;
|
||||
/** Domain name for the dev server (default: 'localhost') */
|
||||
domain?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@ import { logger } from './tswatch.logging.js';
|
||||
export class TsWatch {
|
||||
public config: interfaces.ITswatchConfig;
|
||||
public watcherMap = new plugins.lik.ObjectMap<Watcher>();
|
||||
public typedserver: plugins.typedserver.TypedServer | null = null;
|
||||
public utilityWebsiteServer: plugins.typedserver.utilityservers.UtilityWebsiteServer | null = null;
|
||||
|
||||
private tsbundle = new plugins.tsbundle.TsBundle();
|
||||
private customBundleHandler = new plugins.tsbundle.CustomBundleHandler();
|
||||
@@ -75,8 +75,8 @@ export class TsWatch {
|
||||
});
|
||||
|
||||
// Start server after watchers are ready
|
||||
if (this.typedserver) {
|
||||
await this.typedserver.start();
|
||||
if (this.utilityWebsiteServer) {
|
||||
await this.utilityWebsiteServer.start(this.config.server?.port || 3002);
|
||||
logger.log('ok', `Dev server started on port ${this.config.server?.port || 3002}`);
|
||||
}
|
||||
}
|
||||
@@ -91,14 +91,14 @@ export class TsWatch {
|
||||
|
||||
logger.log('info', `Setting up dev server on port ${port}, serving ${serveDir}`);
|
||||
|
||||
this.typedserver = new plugins.typedserver.TypedServer({
|
||||
cors: true,
|
||||
injectReload: serverConfig.liveReload !== false,
|
||||
this.utilityWebsiteServer = new plugins.typedserver.utilityservers.UtilityWebsiteServer({
|
||||
domain: serverConfig.domain || 'localhost',
|
||||
serveDir: plugins.path.join(paths.cwd, serveDir),
|
||||
port: port,
|
||||
compression: true,
|
||||
cors: true,
|
||||
spaFallback: true,
|
||||
noCache: true,
|
||||
injectReload: serverConfig.liveReload !== false,
|
||||
securityHeaders: {
|
||||
crossOriginOpenerPolicy: 'same-origin',
|
||||
crossOriginEmbedderPolicy: 'require-corp',
|
||||
@@ -159,8 +159,8 @@ export class TsWatch {
|
||||
logger.log('ok', `[${name}] bundle complete`);
|
||||
|
||||
// Trigger reload if configured and server is running
|
||||
if (bundleConfig.triggerReload !== false && this.typedserver) {
|
||||
await this.typedserver.reload();
|
||||
if (bundleConfig.triggerReload !== false && this.utilityWebsiteServer?.typedserver) {
|
||||
await this.utilityWebsiteServer.typedserver.reload();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -211,8 +211,8 @@ export class TsWatch {
|
||||
* stops the execution of any active Watchers
|
||||
*/
|
||||
public async stop() {
|
||||
if (this.typedserver) {
|
||||
await this.typedserver.stop();
|
||||
if (this.utilityWebsiteServer) {
|
||||
await this.utilityWebsiteServer.stop();
|
||||
}
|
||||
await this.watcherMap.forEach(async (watcher) => {
|
||||
await watcher.stop();
|
||||
|
||||
@@ -23,7 +23,6 @@ import * as smartlog from '@push.rocks/smartlog';
|
||||
import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local';
|
||||
import * as smartshell from '@push.rocks/smartshell';
|
||||
import * as smartwatch from '@push.rocks/smartwatch';
|
||||
import * as taskbuffer from '@push.rocks/taskbuffer';
|
||||
|
||||
export {
|
||||
lik,
|
||||
@@ -37,5 +36,4 @@ export {
|
||||
smartlogDestinationLocal,
|
||||
smartshell,
|
||||
smartwatch,
|
||||
taskbuffer,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user