fix(core): Refactor watch modes and update dependencies

This commit is contained in:
Philipp Kunz 2024-12-04 21:58:32 +01:00
parent 95c57d489d
commit 7611268fb9
8 changed files with 7011 additions and 2607 deletions

View File

@ -1,5 +1,13 @@
# Changelog # Changelog
## 2024-12-04 - 2.0.26 - fix(core)
Refactor watch modes and update dependencies
- Updated dependencies in package.json
- Refactored watch mode names in interfaces and classes
- Refactored CLI commands to use new watch mode names
- Added import for smartfile in tswatch.plugins.ts
## 2024-10-27 - 2.0.25 - fix(typescript) ## 2024-10-27 - 2.0.25 - fix(typescript)
Remove unnecessary reference types in TypeScript declaration files Remove unnecessary reference types in TypeScript declaration files

View File

@ -16,20 +16,21 @@
"build": "(tsbuild --web --allowimplicitany)" "build": "(tsbuild --web --allowimplicitany)"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.1.85", "@git.zone/tsbuild": "^2.2.0",
"@git.zone/tstest": "^1.0.90", "@git.zone/tstest": "^1.0.90",
"@push.rocks/tapbundle": "^5.3.0", "@push.rocks/tapbundle": "^5.5.3",
"@types/node": "^22.8.1" "@types/node": "^22.10.1"
}, },
"dependencies": { "dependencies": {
"@api.global/typedserver": "^3.0.51", "@api.global/typedserver": "^3.0.51",
"@git.zone/tsbundle": "^2.1.0", "@git.zone/tsbundle": "^2.1.0",
"@git.zone/tsrun": "^1.2.49", "@git.zone/tsrun": "^1.3.3",
"@push.rocks/early": "^4.0.4", "@push.rocks/early": "^4.0.4",
"@push.rocks/lik": "^6.1.0", "@push.rocks/lik": "^6.1.0",
"@push.rocks/smartchok": "^1.0.34", "@push.rocks/smartchok": "^1.0.34",
"@push.rocks/smartcli": "^4.0.11", "@push.rocks/smartcli": "^4.0.11",
"@push.rocks/smartdelay": "^3.0.5", "@push.rocks/smartdelay": "^3.0.5",
"@push.rocks/smartfile": "^11.0.21",
"@push.rocks/smartlog": "^3.0.7", "@push.rocks/smartlog": "^3.0.7",
"@push.rocks/smartlog-destination-local": "^9.0.2", "@push.rocks/smartlog-destination-local": "^9.0.2",
"@push.rocks/smartshell": "^3.0.6", "@push.rocks/smartshell": "^3.0.6",

9380
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@git.zone/tswatch', name: '@git.zone/tswatch',
version: '2.0.25', version: '2.0.26',
description: 'watch typescript projects during development' description: 'watch typescript projects during development'
} }

View File

@ -1,7 +1,7 @@
export type TWatchModes = export type TWatchModes =
| 'test' | 'test'
| 'gitzone_npm' | 'node'
| 'gitzone_service' | 'service'
| 'gitzone_element' | 'element'
| 'gitzone_website' | 'website'
| 'echoSomething'; | 'echo';

View File

@ -21,6 +21,9 @@ export class TsWatch {
const htmlHandler = new plugins.tsbundle.HtmlHandler(); const htmlHandler = new plugins.tsbundle.HtmlHandler();
switch (this.watchmode) { switch (this.watchmode) {
case 'test': case 'test':
/**
* this strategy runs test whenever there is a change in the ts directory
*/
this.watcherMap.add( this.watcherMap.add(
new Watcher({ new Watcher({
filePathToWatch: paths.cwd, filePathToWatch: paths.cwd,
@ -29,7 +32,7 @@ export class TsWatch {
}) })
); );
break; break;
case 'gitzone_npm': case 'node':
this.watcherMap.add( this.watcherMap.add(
new Watcher({ new Watcher({
filePathToWatch: paths.cwd, filePathToWatch: paths.cwd,
@ -38,88 +41,126 @@ export class TsWatch {
}) })
); );
break; break;
case 'gitzone_element': case 'element':
// lets create a standard server (async () => {
console.log( /**
'bundling TypeScript files to "dist_watch" Note: This is for development only!' * this strategy runs a standard server and bundles the ts files to a dist_watch directory
); */
this.typedserver = new plugins.typedserver.TypedServer({ // lets create a standard server
cors: true, console.log(
injectReload: true, 'bundling TypeScript files to "dist_watch" Note: This is for development only!'
serveDir: plugins.path.join(paths.cwd, './dist_watch/'), );
port: 3002, this.typedserver = new plugins.typedserver.TypedServer({
enableCompression: true, cors: true,
preferredCompressionMethod: 'gzip', injectReload: true,
}); serveDir: plugins.path.join(paths.cwd, './dist_watch/'),
port: 3002,
enableCompression: true,
preferredCompressionMethod: 'gzip',
});
const bundleAndReloadElement = async () => { const bundleAndReloadElement = async () => {
await tsbundle.build(paths.cwd, './html/index.ts', './dist_watch/bundle.js', { await tsbundle.build(paths.cwd, './html/index.ts', './dist_watch/bundle.js', {
bundler: 'esbuild', bundler: 'esbuild',
});
await this.typedserver.reload();
};
this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'),
functionToCall: async () => {
await bundleAndReloadElement();
},
timeout: null,
})
);
// lets get the other ts folders
let tsfolders = await plugins.smartfile.fs.listFolders(paths.cwd);
tsfolders = tsfolders.filter(
(itemArg) => itemArg.startsWith('ts') && itemArg !== 'ts_web'
);
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
}); });
await this.typedserver.reload(); for (const tsfolder of tsfolders) {
}; this.watcherMap.add(
this.watcherMap.add( new Watcher({
new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, `./${tsfolder}/`),
filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'), functionToCall: async () => {
functionToCall: async () => { await smartshellInstance.exec(`npm run build`);
await bundleAndReloadElement(); await this.typedserver.reload();
}, },
timeout: null, timeout: null,
}) })
); );
this.watcherMap.add( }
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './html/'), this.watcherMap.add(
functionToCall: async () => { new Watcher({
await htmlHandler.processHtml({ filePathToWatch: plugins.path.join(paths.cwd, './html/'),
from: plugins.path.join(paths.cwd, './html/index.html'), functionToCall: async () => {
to: plugins.path.join(paths.cwd, './dist_watch/index.html'), await htmlHandler.processHtml({
minify: false, from: plugins.path.join(paths.cwd, './html/index.html'),
}); to: plugins.path.join(paths.cwd, './dist_watch/index.html'),
await bundleAndReloadElement(); minify: false,
}, });
timeout: null, await bundleAndReloadElement();
}) },
); timeout: null,
})
);
})();
break; break;
case 'gitzone_website': case 'website':
this.watcherMap.add( (async () => {
new Watcher({ const bundleAndReloadWebsite = async () => {
filePathToWatch: plugins.path.join(paths.cwd, './ts/'), await tsbundle.build(paths.cwd, './ts_web/index.ts', './dist_serve/bundle.js', {
commandToExecute: 'npm run startTs', bundler: 'esbuild',
timeout: null, });
}) };
); let tsfolders = await plugins.smartfile.fs.listFolders(paths.cwd);
const bundleAndReloadWebsite = async () => { tsfolders = tsfolders.filter(
await tsbundle.build(paths.cwd, './ts_web/index.ts', './dist_serve/bundle.js', { (itemArg) => itemArg.startsWith('ts') && itemArg !== 'ts_web'
bundler: 'esbuild', );
const smartshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
}); });
}; for (const tsfolder of tsfolders) {
this.watcherMap.add( this.watcherMap.add(
new Watcher({ new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'), filePathToWatch: plugins.path.join(paths.cwd, `./${tsfolder}/`),
functionToCall: async () => { commandToExecute: `npm run startTs`,
await bundleAndReloadWebsite(); timeout: null,
}, })
timeout: null, );
}) }
); this.watcherMap.add(
this.watcherMap.add( new Watcher({
new Watcher({ filePathToWatch: plugins.path.join(paths.cwd, './ts_web/'),
filePathToWatch: plugins.path.join(paths.cwd, './html/'), functionToCall: async () => {
functionToCall: async () => { await bundleAndReloadWebsite();
await htmlHandler.processHtml({ },
from: plugins.path.join(paths.cwd, './html/index.html'), timeout: null,
to: plugins.path.join(paths.cwd, './dist_serve/index.html'), })
minify: false, );
}); this.watcherMap.add(
await bundleAndReloadWebsite(); new Watcher({
}, filePathToWatch: plugins.path.join(paths.cwd, './html/'),
timeout: null, functionToCall: async () => {
}) await htmlHandler.processHtml({
); from: plugins.path.join(paths.cwd, './html/index.html'),
to: plugins.path.join(paths.cwd, './dist_serve/index.html'),
minify: false,
});
await bundleAndReloadWebsite();
},
timeout: null,
})
);
})();
break; break;
case 'gitzone_service': case 'service':
this.watcherMap.add( this.watcherMap.add(
new Watcher({ new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts/'), filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
@ -128,7 +169,7 @@ export class TsWatch {
}) })
); );
break; break;
case 'echoSomething': case 'echo':
const tsWatchInstanceEchoSomething = new Watcher({ const tsWatchInstanceEchoSomething = new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts'), filePathToWatch: plugins.path.join(paths.cwd, './ts'),
commandToExecute: 'npm -v', commandToExecute: 'npm -v',

View File

@ -13,19 +13,19 @@ tswatchCli.standardCommand().subscribe((argvArg => {
tswatchCli.addCommand('element').subscribe(async (argvArg) => { tswatchCli.addCommand('element').subscribe(async (argvArg) => {
logger.log('info', `running watch task for a gitzone element project`); logger.log('info', `running watch task for a gitzone element project`);
const tsWatch = new TsWatch('gitzone_element'); const tsWatch = new TsWatch('element');
await tsWatch.start(); await tsWatch.start();
}); });
tswatchCli.addCommand('npm').subscribe(async (argvArg) => { tswatchCli.addCommand('npm').subscribe(async (argvArg) => {
logger.log('info', `running watch task for a gitzone element project`); logger.log('info', `running watch task for a gitzone element project`);
const tsWatch = new TsWatch('gitzone_npm'); const tsWatch = new TsWatch('node');
await tsWatch.start(); await tsWatch.start();
}); });
tswatchCli.addCommand('service').subscribe(async (argvArg) => { tswatchCli.addCommand('service').subscribe(async (argvArg) => {
logger.log('info', `running test task`); logger.log('info', `running test task`);
const tsWatch = new TsWatch('gitzone_service'); const tsWatch = new TsWatch('service');
await tsWatch.start(); await tsWatch.start();
}); });
@ -37,7 +37,7 @@ tswatchCli.addCommand('test').subscribe(async (argvArg) => {
tswatchCli.addCommand('website').subscribe(async (argvArg) => { tswatchCli.addCommand('website').subscribe(async (argvArg) => {
logger.log('info', `running watch task for a gitzone website project`); logger.log('info', `running watch task for a gitzone website project`);
const tsWatch = new TsWatch('gitzone_website'); const tsWatch = new TsWatch('website');
await tsWatch.start(); await tsWatch.start();
}); });

View File

@ -20,6 +20,7 @@ import * as lik from '@push.rocks/lik';
import * as smartchok from '@push.rocks/smartchok'; import * as smartchok from '@push.rocks/smartchok';
import * as smartcli from '@push.rocks/smartcli'; import * as smartcli from '@push.rocks/smartcli';
import * as smartdelay from '@push.rocks/smartdelay'; import * as smartdelay from '@push.rocks/smartdelay';
import * as smartfile from '@push.rocks/smartfile';
import * as smartlog from '@push.rocks/smartlog'; import * as smartlog from '@push.rocks/smartlog';
import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local'; import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local';
import * as smartshell from '@push.rocks/smartshell'; import * as smartshell from '@push.rocks/smartshell';
@ -30,6 +31,7 @@ export {
smartchok, smartchok,
smartcli, smartcli,
smartdelay, smartdelay,
smartfile,
smartlog, smartlog,
smartlogDestinationLocal, smartlogDestinationLocal,
smartshell, smartshell,