@git.zone/tswatch 2.1.1 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@git.zone/tswatch',
6
- version: '2.1.0',
6
+ version: '2.1.3',
7
7
  description: 'A development tool for automatically watching and re-compiling TypeScript projects upon detecting file changes, enhancing developer workflows.'
8
8
  };
9
9
  //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxtQkFBbUI7SUFDekIsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLGdKQUFnSjtDQUM5SixDQUFBIn0=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@git.zone/tswatch",
3
- "version": "2.1.1",
3
+ "version": "2.1.5",
4
4
  "private": false,
5
5
  "description": "A development tool for automatically watching and re-compiling TypeScript projects upon detecting file changes, enhancing developer workflows.",
6
6
  "main": "dist_ts/index.js",
@@ -13,8 +13,8 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@git.zone/tsbuild": "^2.6.4",
16
- "@git.zone/tstest": "^2.3.1",
17
- "@types/node": "^24.0.4"
16
+ "@git.zone/tstest": "^2.3.2",
17
+ "@types/node": "^22"
18
18
  },
19
19
  "dependencies": {
20
20
  "@api.global/typedserver": "^3.0.74",
@@ -22,7 +22,7 @@
22
22
  "@git.zone/tsrun": "^1.3.3",
23
23
  "@push.rocks/early": "^4.0.4",
24
24
  "@push.rocks/lik": "^6.2.2",
25
- "@push.rocks/smartchok": "^1.0.34",
25
+ "@push.rocks/smartchok": "^1.1.1",
26
26
  "@push.rocks/smartcli": "^4.0.11",
27
27
  "@push.rocks/smartdelay": "^3.0.5",
28
28
  "@push.rocks/smartfile": "^11.2.5",
package/readme.hints.md CHANGED
@@ -0,0 +1,44 @@
1
+ # tswatch Project Hints
2
+
3
+ ## Core Architecture
4
+ - tswatch is a TypeScript file watcher with multiple operation modes
5
+ - Main class `TsWatch` orchestrates different watch modes
6
+ - `Watcher` class handles individual file watching and command execution
7
+
8
+ ## Available Watch Modes
9
+ 1. **npm/node** (default): Runs `npm test` on changes
10
+ 2. **test**: Runs `npm run test2` on changes
11
+ 3. **element**: Web component development with dev server on port 3002
12
+ 4. **service**: Runs `npm run startTs` for service projects
13
+ 5. **website**: Full website mode with bundling and asset processing
14
+ 6. **echo**: Test mode that runs `npm -v` (for testing)
15
+
16
+ ## Key Implementation Details
17
+ - Uses `@push.rocks/smartchok` for file watching
18
+ - Uses `@git.zone/tsbundle` for bundling with esbuild
19
+ - Uses `@api.global/typedserver` for development server in element mode
20
+ - Element/website modes watch multiple `ts*/` directories
21
+ - All modes support both command execution and function callbacks
22
+
23
+ ## CLI Entry Points
24
+ - `cli.js` -> Main CLI entry point
25
+ - `ts/tswatch.cli.ts` -> CLI implementation with smartcli
26
+ - Default command triggers npm mode
27
+
28
+ ## Project Structure Expectations
29
+ - `ts/` - Backend TypeScript files
30
+ - `ts_web/` - Frontend TypeScript files (element/website modes)
31
+ - `html/` - HTML templates (element/website modes)
32
+ - `assets/` - Static assets (website mode only)
33
+ - `dist_watch/` - Output for element mode
34
+ - `dist_serve/` - Output for website mode
35
+
36
+ ## Development Server Details
37
+ - Port: 3002
38
+ - Features: CORS, gzip compression, live reload injection
39
+ - Only available in element mode via `typedserver` property
40
+
41
+ ## Common Issues to Watch For
42
+ - The test mode runs `test2` script, not `test`
43
+ - Website mode restarts the entire server process on backend changes
44
+ - Element mode rebuilds and reloads on any ts* folder change
package/readme.md CHANGED
@@ -1,183 +1,213 @@
1
1
  # @git.zone/tswatch
2
2
 
3
- A development tool for watching and re-compiling TypeScript projects automatically upon detecting changes.
3
+ A TypeScript file watcher that automatically recompiles and executes your project when files change. Designed to streamline development workflows for various TypeScript project types.
4
4
 
5
- ## Install
5
+ ## Features
6
6
 
7
- To install `@git.zone/tswatch`, ensure that you have a Node.js environment set up with npm. You can install the package globally or locally within a project using npm:
7
+ - 🔄 **Automatic recompilation** on file changes
8
+ - 🚀 **Multiple project modes**: npm packages, web elements, services, and websites
9
+ - 🌐 **Built-in development server** with live reload for web projects
10
+ - ⚡ **Fast bundling** with esbuild integration
11
+ - 🛠️ **Flexible CLI and programmatic API**
12
+ - 📦 **Zero configuration** for standard project structures
8
13
 
9
- ```bash
10
- npm install @git.zone/tswatch
11
- ```
12
-
13
- This command will install the package and enable you to use the `tswatch` command in your terminal to watch TypeScript projects.
14
-
15
- ## Usage
16
-
17
- `@git.zone/tswatch` is a powerful tool designed to streamline your development workflow by monitoring your TypeScript files and automatically recompiling them when changes are detected. This utility is particularly helpful during the development phase of a TypeScript project, ensuring your project remains up-to-date, reflecting the latest changes seamlessly.
18
-
19
- ### Getting Started with tswatch
14
+ ## Prerequisites
20
15
 
21
- To get started, we will explore setting up a basic watcher, integrating tswatch into a Node.js environment, utilizing advanced features, and handling multiple watchers.
16
+ - Node.js (v14 or higher)
17
+ - pnpm (recommended) or npm
22
18
 
23
- ### Setting Up a Basic Watcher
19
+ ## Installation
24
20
 
25
- #### Step 1: Basic Command-Line Interface Usage
21
+ Install `@git.zone/tswatch` globally or as a development dependency:
26
22
 
27
- After installing `@git.zone/tswatch`, you can start a watcher on your TypeScript project using its command-line interface (CLI). Here's how to initiate a watcher for different project types:
28
-
29
- ```typescript
30
- import { runCli } from '@git.zone/tswatch';
23
+ ```bash
24
+ # Global installation
25
+ pnpm install -g @git.zone/tswatch
31
26
 
32
- (async () => {
33
- await runCli();
34
- })();
27
+ # As a dev dependency
28
+ pnpm install --save-dev @git.zone/tswatch
35
29
  ```
36
30
 
37
- The CLI supports several commands to watch different project types such as `element`, `npm`, `service`, and `website`. Here's how to use them:
31
+ ## Quick Start
38
32
 
39
- - **NPM Projects**: Watch a Node.js NPM project:
33
+ ```bash
34
+ # Watch and run tests on changes (default behavior)
35
+ tswatch
40
36
 
41
- ```bash
42
- tswatch npm
43
- ```
37
+ # Watch a web element project with dev server
38
+ tswatch element
44
39
 
45
- This command will start a watcher for your node module projects. Whenever changes are detected, the specified npm scripts are executed.
40
+ # Watch a service project
41
+ tswatch service
42
+ ```
46
43
 
47
- - **Element Projects**: Watch an element-based architecture:
44
+ ## CLI Commands
48
45
 
49
- ```bash
50
- tswatch element
51
- ```
46
+ ### `tswatch` or `tswatch npm`
47
+ Watches TypeScript files and runs `npm test` on changes. This is the default mode.
52
48
 
53
- This command sets up a development server with live reloading and bundles TypeScript files to a `dist_watch` directory.
49
+ ```bash
50
+ tswatch
51
+ # or explicitly
52
+ tswatch npm
53
+ ```
54
54
 
55
- - **Service Projects**: Watch a service project:
55
+ ### `tswatch element`
56
+ Sets up a development environment for web components/elements:
57
+ - Starts a dev server on port 3002
58
+ - Bundles TypeScript to `dist_watch/`
59
+ - Enables live reload
60
+ - Watches all `ts*/` folders
56
61
 
57
- ```bash
58
- tswatch service
59
- ```
62
+ ```bash
63
+ tswatch element
64
+ ```
60
65
 
61
- Watches TypeScript files in a service pattern, restarting the service when changes are detected.
66
+ ### `tswatch service`
67
+ Watches TypeScript files in `./ts/` and runs `npm run startTs` on changes. Ideal for backend services.
62
68
 
63
- - **Website Projects**: Perfect for full website projects:
69
+ ```bash
70
+ tswatch service
71
+ ```
64
72
 
65
- ```bash
66
- tswatch website
67
- ```
73
+ ### `tswatch website`
74
+ Full website development mode:
75
+ - Bundles TypeScript files to `dist_serve/`
76
+ - Processes HTML files
77
+ - Handles assets
78
+ - Runs `npm run startTs` for server-side code
68
79
 
69
- Similar to element projects but specifically designed for full websites, recompiling TypeScript files for web deployment scenarios.
80
+ ```bash
81
+ tswatch website
82
+ ```
70
83
 
71
- #### Step 2: Integration into a Node.js Environment
84
+ ### `tswatch test`
85
+ Runs `npm run test2` whenever files change. Useful for projects with custom test scripts.
72
86
 
73
- You can integrate `@git.zone/tswatch` directly into a Node.js project for automatic file watching and recompiling:
87
+ ```bash
88
+ tswatch test
89
+ ```
74
90
 
75
- ```typescript
76
- import { TsWatch } from '@git.zone/tswatch';
91
+ ## Project Structure
77
92
 
78
- const startWatch = async () => {
79
- // Initialize watch instance for a node project
80
- const watchInstance = new TsWatch('node');
81
- await watchInstance.start();
82
- };
93
+ tswatch expects certain project structures depending on the mode:
83
94
 
84
- // Optionally, stop the watcher gracefully
85
- const stopWatch = async (watchInstance: TsWatch) => {
86
- await watchInstance.stop();
87
- };
95
+ ### NPM/Node Projects
96
+ ```
97
+ project/
98
+ ├── ts/ # TypeScript source files
99
+ ├── test/ # Test files
100
+ └── package.json # With "test" script
88
101
  ```
89
102
 
90
- This setup will establish a node environment watch, automatically recompiling files as changes occur.
103
+ ### Element Projects
104
+ ```
105
+ project/
106
+ ├── ts/ # Backend TypeScript
107
+ ├── ts_web/ # Frontend TypeScript
108
+ ├── html/ # HTML templates
109
+ │ └── index.ts # Entry point
110
+ └── dist_watch/ # Output directory (auto-created)
111
+ ```
91
112
 
92
- ### Advanced Usage: Enhancing Workflow with tswatch
113
+ ### Website Projects
114
+ ```
115
+ project/
116
+ ├── ts/ # Backend TypeScript
117
+ ├── ts_web/ # Frontend TypeScript
118
+ │ └── index.ts # Entry point
119
+ ├── html/ # HTML files
120
+ │ └── index.html
121
+ ├── assets/ # Static assets
122
+ └── dist_serve/ # Output directory
123
+ ```
93
124
 
94
- #### Starting a TypedServer with Watch Integration
125
+ ## Programmatic API
95
126
 
96
- For projects requiring a development server, integrate `typedserver` for handling HTTP server tasks:
127
+ ### Basic Usage
97
128
 
98
129
  ```typescript
99
130
  import { TsWatch } from '@git.zone/tswatch';
100
131
 
101
- const startTypedServer = async () => {
102
- const watchInstance = new TsWatch('element');
103
- await watchInstance.start();
132
+ // Create and start a watcher
133
+ const watcher = new TsWatch('node');
134
+ await watcher.start();
104
135
 
105
- // Serve a local directory using a typedserver with CORS and compression
106
- const server = watchInstance.typedserver;
107
- if (server) {
108
- await server.start();
109
- }
110
- };
136
+ // Stop when done
137
+ await watcher.stop();
111
138
  ```
112
139
 
113
- This code watches for changes and serves the project locally, providing reload capabilities for smooth development.
114
-
115
- #### Step 3: Custom Watchers
116
-
117
- Beyond built-in commands, you can create custom watchers for detailed control over file monitoring and execution responses:
140
+ ### Custom Watchers
118
141
 
119
142
  ```typescript
120
143
  import { Watcher } from '@git.zone/tswatch';
121
144
 
122
- const customWatcherSetup = async () => {
123
- const customWatcher = new Watcher({
124
- filePathToWatch: '/path/to/watch',
125
- commandToExecute: 'npm run custom-script',
126
- });
145
+ const customWatcher = new Watcher({
146
+ filePathToWatch: './src',
147
+ commandToExecute: 'npm run build',
148
+ timeout: 5000 // Optional timeout in ms
149
+ });
127
150
 
128
- // Start and stop the custom watcher as needed
129
- await customWatcher.start();
130
- await customWatcher.stop();
131
- };
151
+ await customWatcher.start();
132
152
  ```
133
153
 
134
- Define specific file paths and custom shell commands with the options provided by the `Watcher` class.
135
-
136
- #### Step 4: Handling Multiple Watchers
137
-
138
- To handle multiple directories or file sets, use the `ObjectMap` utility, efficiently managing multiple `Watcher` instances within the `TsWatch` framework:
154
+ ### Using Function Callbacks
139
155
 
140
156
  ```typescript
141
- import { TsWatch } from '@git.zone/tswatch';
157
+ const watcher = new Watcher({
158
+ filePathToWatch: './src',
159
+ functionToCall: async () => {
160
+ console.log('Files changed!');
161
+ // Your custom logic here
162
+ }
163
+ });
164
+ ```
142
165
 
143
- const setupMultipleWatchers = async () => {
144
- const tsWatchInstance = new TsWatch('node');
166
+ ## Development Server
145
167
 
146
- // View active watchers through instance mapping
147
- tsWatchInstance.watcherMap.forEach((watcher) => {
148
- console.log(`Watcher listening on: ${watcher.toString()}`);
149
- });
168
+ Element mode includes a built-in development server:
150
169
 
151
- // Initiate all watchers
152
- await tsWatchInstance.start();
153
- };
154
- ```
170
+ - **Port**: 3002
171
+ - **Features**: CORS enabled, gzip compression, live reload
172
+ - **Serve directory**: `./dist_watch/`
155
173
 
156
- Incorporate this setup for efficiently managing complex projects with varied sources and parallel build tasks.
174
+ Access your project at `http://localhost:3002` when running in element mode.
157
175
 
158
- #### Handling Timeout and Cleanup
176
+ ## Configuration Tips
159
177
 
160
- `@git.zone/tswatch` includes functions to manage process exits and timeout scenarios robustly:
178
+ 1. **TypeScript Config**: Ensure your `tsconfig.json` is properly configured for your target environment
179
+ 2. **Package Scripts**: Define appropriate scripts in `package.json`:
180
+ - `test`: For npm mode
181
+ - `startTs`: For service/website modes
182
+ - `build`: For general compilation
161
183
 
162
- ```typescript
163
- import { Watcher } from '@git.zone/tswatch';
184
+ 3. **File Organization**: Keep TypeScript files in `ts/` (backend) and `ts_web/` (frontend) directories
164
185
 
165
- const watcherWithTimeout = () => {
166
- new Watcher({
167
- filePathToWatch: './src/',
168
- timeout: 10000, // 10 seconds timeout
169
- commandToExecute: 'echo "Task completed"',
170
- }).start();
171
- };
172
- ```
186
+ ## Common Use Cases
173
187
 
174
- The `timeout` option ensures processes don't run indefinitely, aiding development and potential automated testing scenarios.
188
+ ### Developing a Node.js Library
189
+ ```bash
190
+ tswatch npm
191
+ ```
192
+ Automatically runs tests when you modify source files.
175
193
 
176
- ### Conclusion
194
+ ### Building a Web Component
195
+ ```bash
196
+ tswatch element
197
+ ```
198
+ Get instant feedback with live reload while developing custom elements.
177
199
 
178
- By providing flexible configurations, a robust CLI, and deep integration capabilities, `@git.zone/tswatch` serves as a comprehensive solution for automating and optimizing your TypeScript development processes. Whether managing server-side environments or advanced web apps, using this tool will ensure your projects are always ready with the latest changes.
200
+ ### Creating a Backend Service
201
+ ```bash
202
+ tswatch service
203
+ ```
204
+ Automatically restart your service on code changes.
179
205
 
180
- Explore the various features and tailor the tool to fit your unique project requirements, leading to faster and more efficient development workflows.
206
+ ### Full-Stack Web Application
207
+ ```bash
208
+ tswatch website
209
+ ```
210
+ Handle both frontend and backend compilation with asset processing.
181
211
 
182
212
  ## License and Legal Information
183
213
 
@@ -3,6 +3,6 @@
3
3
  */
4
4
  export const commitinfo = {
5
5
  name: '@git.zone/tswatch',
6
- version: '2.1.1',
6
+ version: '2.1.3',
7
7
  description: 'A development tool for automatically watching and re-compiling TypeScript projects upon detecting file changes, enhancing developer workflows.'
8
8
  }