From 2dc766fa6e4e32210b41651693a2c67248d172eb Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 4 Mar 2025 11:44:55 +0000 Subject: [PATCH] feat(cli): Enhance CLI with new process management commands --- changelog.md | 7 + package.json | 1 + pnpm-lock.yaml | 89 +++++++++++ ts/00_commitinfo_data.ts | 2 +- ts/classes.processmonitor.ts | 4 +- ts/cli.ts | 287 ++++++++++++++++++++++++++++++++++- ts/plugins.ts | 6 +- 7 files changed, 383 insertions(+), 13 deletions(-) diff --git a/changelog.md b/changelog.md index 1b3fcd8..a36fce2 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-03-04 - 1.5.0 - feat(cli) +Enhance CLI with new process management commands + +- Added comprehensive CLI commands for process management including start, stop, restart, list, describe and logs. +- Implemented memory string parsing for process memory limits. +- Enhanced CLI output with formatted table listings for active processes. + ## 2025-03-03 - 1.4.0 - feat(core) Introduced process management features using ProcessWrapper and enhanced configuration. diff --git a/package.json b/package.json index 1017903..c3d6747 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@push.rocks/npmextra": "^5.1.2", "@push.rocks/projectinfo": "^5.0.2", "@push.rocks/smartcli": "^4.0.11", + "@push.rocks/smartdaemon": "^2.0.6", "@push.rocks/smartpath": "^5.0.18", "pidusage": "^4.0.0", "ps-tree": "^1.2.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1bfdc73..97a54fa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: '@push.rocks/smartcli': specifier: ^4.0.11 version: 4.0.11 + '@push.rocks/smartdaemon': + specifier: ^2.0.6 + version: 2.0.6 '@push.rocks/smartpath': specifier: ^5.0.18 version: 5.0.18 @@ -749,6 +752,9 @@ packages: '@push.rocks/smartcrypto@2.0.4': resolution: {integrity: sha512-1+/5bsjyataf5uUkUNnnVXGRAt+gHVk1KDzozjTqgqJxHvQk1d9fVDohL6CxUhUucTPtu5VR5xNBiV8YCDuGyw==} + '@push.rocks/smartdaemon@2.0.6': + resolution: {integrity: sha512-yFbZIT8Vb8fCdihM+kUnSluYmTzfARuZEs7Mbh+GjNJ9H+gbfyCt30BKocsPBUDkuliSAv/RlbYLILACNZlX8w==} + '@push.rocks/smartdata@5.2.12': resolution: {integrity: sha512-vp0nz1P/SJcoFhyfZoewPbFSameWnuMuCkySvnb41TcCi1PFHA//KOYImdti/qURSOYwVoTKboDrnx1/ffHp7g==} @@ -776,6 +782,9 @@ packages: '@push.rocks/smartfile@11.2.0': resolution: {integrity: sha512-0Gw6DvCQ2D/BXNN6airSC7hoSBut0p/uNWf2+rqO+D6VLhIJ/QUBvF6xm/LnpPI/zcF8YlDn/GEriInB5DUtEw==} + '@push.rocks/smartfm@2.2.2': + resolution: {integrity: sha512-kLrBv/vWXJmB558LI5C79fWXLKOnno998vnp3opfB+uyznT2E6LkcpKsxdjwe1V/r+Z5GlhXPOWmGgHPCzUR6w==} + '@push.rocks/smartguard@3.1.0': resolution: {integrity: sha512-J23q84f1O+TwFGmd4lrO9XLHUh2DaLXo9PN/9VmTWYzTkQDv5JehmifXVI0esophXcCIfbdIu6hbt7/aHlDF4A==} @@ -878,6 +887,9 @@ packages: '@push.rocks/smartstring@4.0.15': resolution: {integrity: sha512-NTNeOjWyg+aHtBTiQEyXamr7oTvYZ3wS1fudHo9ua7CLrykpK+i+RxFyJaLg1zB5x9xQF3NLEQecB14HPFX8Cg==} + '@push.rocks/smartsystem@3.0.1': + resolution: {integrity: sha512-+W9AiSJWcRAjthqDFT8rDli2+5k3bk8c9Psndy3uKN2YbaQkMZwWptZRI3WgpXMG9NhsjF8XrkyiH/xHv9AxzQ==} + '@push.rocks/smarttime@4.1.1': resolution: {integrity: sha512-Ha/3J/G+zfTl4ahpZgF6oUOZnUjpLhrBja0OQ2cloFxF9sKT8I1COaSqIfBGDtoK2Nly4UD4aTJ3JcJNOg/kgA==} @@ -978,6 +990,10 @@ packages: resolution: {integrity: sha512-FCRg5p5NFTyZnPsvy2sbheVGz67Zeno7VoZARrcP0O+hFtVPnQKnJ73ze11G+MKZ3dVCmYCh1Li+73R6Lx8XJA==} deprecated: This package has been deprecated in favour of the new package at @push.rocks/smartmime + '@pushrocks/smartnetwork@3.0.2': + resolution: {integrity: sha512-XKVeTzf22IRgAvY9m8naFlsjh5yYVCU4/Dqi7XnxQUVfrnrcNIJVo+9JIYjQetLbHiUOHAnthlZVP5yXppOxyw==} + deprecated: This package has been deprecated in favour of the new package at @push.rocks/smartnetwork + '@pushrocks/smartpath@4.0.3': resolution: {integrity: sha512-KWz4DWOrB0sPfk6L4i+CPOo+UK5HXNaLI7ZAaqJe1nEWoDrpyeds1dNDaqVAmSgX4riLGxVpslKH5MnABCPsPg==} deprecated: This package has been deprecated in favour of the new package at @push.rocks/smartpath @@ -2252,6 +2268,10 @@ packages: resolution: {integrity: sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==} engines: {node: '>= 0.10.0'} + extend-shallow@2.0.1: + resolution: {integrity: sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=} + engines: {node: '>=0.10.0'} + extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} @@ -2478,6 +2498,10 @@ packages: graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + gray-matter@4.0.3: + resolution: {integrity: sha512-5v6yZd4JK3eMI3FqqCouswVqwugaA9r4dNZB1wwcmrD02QkV5H0y7XBQW8QwQqEaZY1pM9aqORSORhJRdNK44Q==} + engines: {node: '>=6.0'} + gunzip-maybe@1.4.2: resolution: {integrity: sha512-4haO1M4mLO91PW57BMsDFf75UmwoRX0GkdD+Faw+Lr+r/OZrOCS0pIBwOL1xCKQqnQzbNFGgK2V2CpBUPeFNTw==} hasBin: true @@ -2647,6 +2671,10 @@ packages: engines: {node: '>=8'} hasBin: true + is-extendable@0.1.1: + resolution: {integrity: sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=} + engines: {node: '>=0.10.0'} + is-extglob@2.1.1: resolution: {integrity: sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=} engines: {node: '>=0.10.0'} @@ -3727,6 +3755,10 @@ packages: sax@1.4.1: resolution: {integrity: sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==} + section-matter@1.0.0: + resolution: {integrity: sha512-vfD3pmTzGpufjScBh50YHKzEu2lxBWhVEHsNGoEXmCmn2hKGfeNLYMzCJpe8cD7gqX7TJluOVpBkAequ6dgMmA==} + engines: {node: '>=4'} + semver@6.3.1: resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==} hasBin: true @@ -3903,6 +3935,10 @@ packages: resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} engines: {node: '>=12'} + strip-bom-string@1.0.0: + resolution: {integrity: sha1-5SEekiQ2n7uB1jOi8ABE3IztrZI=} + engines: {node: '>=0.10.0'} + strip-final-newline@2.0.0: resolution: {integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==} engines: {node: '>=6'} @@ -5527,6 +5563,17 @@ snapshots: '@types/node-forge': 1.3.11 node-forge: 1.3.1 + '@push.rocks/smartdaemon@2.0.6': + dependencies: + '@push.rocks/lik': 6.1.0 + '@push.rocks/smartfile': 11.2.0 + '@push.rocks/smartfm': 2.2.2 + '@push.rocks/smartlog': 3.0.7 + '@push.rocks/smartlog-destination-local': 9.0.2 + '@push.rocks/smartpath': 5.0.18 + '@push.rocks/smartshell': 3.2.3 + '@push.rocks/smartsystem': 3.0.1 + '@push.rocks/smartdata@5.2.12(@aws-sdk/credential-providers@3.758.0)(socks@2.8.4)': dependencies: '@push.rocks/lik': 6.1.0 @@ -5619,6 +5666,10 @@ snapshots: glob: 11.0.1 js-yaml: 4.1.0 + '@push.rocks/smartfm@2.2.2': + dependencies: + gray-matter: 4.0.3 + '@push.rocks/smartguard@3.1.0': dependencies: '@push.rocks/smartpromise': 4.2.3 @@ -5911,6 +5962,14 @@ snapshots: strip-indent: 4.0.0 url: 0.11.4 + '@push.rocks/smartsystem@3.0.1': + dependencies: + '@pushrocks/lik': 6.0.2 + '@pushrocks/smartenv': 5.0.5 + '@pushrocks/smartnetwork': 3.0.2 + '@pushrocks/smartpromise': 3.1.10 + systeminformation: 5.25.11 + '@push.rocks/smarttime@4.1.1': dependencies: '@push.rocks/lik': 6.1.0 @@ -6119,6 +6178,16 @@ snapshots: '@types/mime-types': 2.1.4 mime-types: 2.1.35 + '@pushrocks/smartnetwork@3.0.2': + dependencies: + '@pushrocks/smartping': 1.0.8 + '@pushrocks/smartpromise': 3.1.10 + '@pushrocks/smartstring': 4.0.7 + '@types/default-gateway': 3.0.1 + isopen: 1.3.0 + public-ip: 6.0.2 + systeminformation: 5.25.11 + '@pushrocks/smartpath@4.0.3': {} '@pushrocks/smartpath@5.0.5': {} @@ -7663,6 +7732,10 @@ snapshots: transitivePeerDependencies: - supports-color + extend-shallow@2.0.1: + dependencies: + is-extendable: 0.1.1 + extend@3.0.2: {} extract-zip@2.0.1: @@ -7935,6 +8008,13 @@ snapshots: graceful-fs@4.2.11: {} + gray-matter@4.0.3: + dependencies: + js-yaml: 3.14.1 + kind-of: 6.0.3 + section-matter: 1.0.0 + strip-bom-string: 1.0.0 + gunzip-maybe@1.4.2: dependencies: browserify-zlib: 0.1.4 @@ -8126,6 +8206,8 @@ snapshots: is-docker@2.2.1: {} + is-extendable@0.1.1: {} + is-extglob@2.1.1: {} is-fullwidth-code-point@3.0.0: {} @@ -9436,6 +9518,11 @@ snapshots: sax@1.4.1: {} + section-matter@1.0.0: + dependencies: + extend-shallow: 2.0.1 + kind-of: 6.0.3 + semver@6.3.1: {} semver@7.7.1: {} @@ -9671,6 +9758,8 @@ snapshots: dependencies: ansi-regex: 6.1.0 + strip-bom-string@1.0.0: {} + strip-final-newline@2.0.0: {} strip-indent@4.0.0: diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index f58e36b..da40de4 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tspm', - version: '1.4.0', + version: '1.5.0', description: 'a no fuzz process manager' } diff --git a/ts/classes.processmonitor.ts b/ts/classes.processmonitor.ts index c8af963..c4b719a 100644 --- a/ts/classes.processmonitor.ts +++ b/ts/classes.processmonitor.ts @@ -1,5 +1,5 @@ import * as plugins from './plugins.js'; -import { ProcessWrapper } from './classes.processwrapper.js'; +import { ProcessWrapper, type IProcessLog } from './classes.processwrapper.js'; export interface IMonitorConfig { name?: string; // Optional name to identify the instance @@ -161,7 +161,7 @@ export class ProcessMonitor { /** * Get the current logs from the process */ - public getLogs(limit?: number): Array<{ timestamp: Date, type: string, message: string }> { + public getLogs(limit?: number): IProcessLog[] { if (!this.processWrapper) { return []; } diff --git a/ts/cli.ts b/ts/cli.ts index 409e375..58db4af 100644 --- a/ts/cli.ts +++ b/ts/cli.ts @@ -1,29 +1,300 @@ import * as plugins from './plugins.js'; import * as paths from './paths.js'; +import { Tspm, IProcessConfig } from './classes.tspm.js'; export const run = async () => { const tspmProjectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir); + const tspm = new Tspm(); const smartcliInstance = new plugins.smartcli.Smartcli(); smartcliInstance.addVersion(tspmProjectinfo.npm.version); + // Default command - show help and list processes smartcliInstance.standardCommand().subscribe({ - next: (argvArg) => { - console.log(`Please specify a command.`) + next: async (argvArg) => { + console.log(`TSPM - TypeScript Process Manager v${tspmProjectinfo.npm.version}`); + console.log('Usage: tspm [command] [options]'); + console.log('\nCommands:'); + console.log(' start