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",

9300
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,7 +41,11 @@ export class TsWatch {
}) })
); );
break; break;
case 'gitzone_element': case 'element':
(async () => {
/**
* this strategy runs a standard server and bundles the ts files to a dist_watch directory
*/
// lets create a standard server // lets create a standard server
console.log( console.log(
'bundling TypeScript files to "dist_watch" Note: This is for development only!' 'bundling TypeScript files to "dist_watch" Note: This is for development only!'
@ -67,6 +74,28 @@ export class TsWatch {
timeout: null, 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',
});
for (const tsfolder of tsfolders) {
this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, `./${tsfolder}/`),
functionToCall: async () => {
await smartshellInstance.exec(`npm run build`);
await this.typedserver.reload();
},
timeout: null,
})
);
}
this.watcherMap.add( this.watcherMap.add(
new Watcher({ new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './html/'), filePathToWatch: plugins.path.join(paths.cwd, './html/'),
@ -81,20 +110,31 @@ export class TsWatch {
timeout: null, timeout: null,
}) })
); );
})();
break; break;
case 'gitzone_website': case 'website':
this.watcherMap.add( (async () => {
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, './ts/'),
commandToExecute: 'npm run startTs',
timeout: null,
})
);
const bundleAndReloadWebsite = async () => { const bundleAndReloadWebsite = async () => {
await tsbundle.build(paths.cwd, './ts_web/index.ts', './dist_serve/bundle.js', { await tsbundle.build(paths.cwd, './ts_web/index.ts', './dist_serve/bundle.js', {
bundler: 'esbuild', bundler: 'esbuild',
}); });
}; };
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',
});
for (const tsfolder of tsfolders) {
this.watcherMap.add(
new Watcher({
filePathToWatch: plugins.path.join(paths.cwd, `./${tsfolder}/`),
commandToExecute: `npm run startTs`,
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, './ts_web/'),
@ -118,8 +158,9 @@ export class TsWatch {
timeout: null, 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,