@git.zone/tswatch 2.1.2 → 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.
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/package.json +3 -3
- package/readme.hints.md +44 -0
- package/readme.md +148 -118
- package/ts/00_commitinfo_data.ts +1 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@git.zone/tswatch',
|
|
6
|
-
version: '2.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
|
};
|
|
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.
|
|
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.
|
|
17
|
-
"@types/node": "^
|
|
16
|
+
"@git.zone/tstest": "^2.3.2",
|
|
17
|
+
"@types/node": "^22"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@api.global/typedserver": "^3.0.74",
|
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
|
|
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
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
16
|
+
- Node.js (v14 or higher)
|
|
17
|
+
- pnpm (recommended) or npm
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
## Installation
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
Install `@git.zone/tswatch` globally or as a development dependency:
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
import { runCli } from '@git.zone/tswatch';
|
|
23
|
+
```bash
|
|
24
|
+
# Global installation
|
|
25
|
+
pnpm install -g @git.zone/tswatch
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})();
|
|
27
|
+
# As a dev dependency
|
|
28
|
+
pnpm install --save-dev @git.zone/tswatch
|
|
35
29
|
```
|
|
36
30
|
|
|
37
|
-
|
|
31
|
+
## Quick Start
|
|
38
32
|
|
|
39
|
-
|
|
33
|
+
```bash
|
|
34
|
+
# Watch and run tests on changes (default behavior)
|
|
35
|
+
tswatch
|
|
40
36
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```
|
|
37
|
+
# Watch a web element project with dev server
|
|
38
|
+
tswatch element
|
|
44
39
|
|
|
45
|
-
|
|
40
|
+
# Watch a service project
|
|
41
|
+
tswatch service
|
|
42
|
+
```
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
## CLI Commands
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
```
|
|
46
|
+
### `tswatch` or `tswatch npm`
|
|
47
|
+
Watches TypeScript files and runs `npm test` on changes. This is the default mode.
|
|
52
48
|
|
|
53
|
-
|
|
49
|
+
```bash
|
|
50
|
+
tswatch
|
|
51
|
+
# or explicitly
|
|
52
|
+
tswatch npm
|
|
53
|
+
```
|
|
54
54
|
|
|
55
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
```bash
|
|
63
|
+
tswatch element
|
|
64
|
+
```
|
|
60
65
|
|
|
61
|
-
|
|
66
|
+
### `tswatch service`
|
|
67
|
+
Watches TypeScript files in `./ts/` and runs `npm run startTs` on changes. Ideal for backend services.
|
|
62
68
|
|
|
63
|
-
|
|
69
|
+
```bash
|
|
70
|
+
tswatch service
|
|
71
|
+
```
|
|
64
72
|
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
80
|
+
```bash
|
|
81
|
+
tswatch website
|
|
82
|
+
```
|
|
70
83
|
|
|
71
|
-
|
|
84
|
+
### `tswatch test`
|
|
85
|
+
Runs `npm run test2` whenever files change. Useful for projects with custom test scripts.
|
|
72
86
|
|
|
73
|
-
|
|
87
|
+
```bash
|
|
88
|
+
tswatch test
|
|
89
|
+
```
|
|
74
90
|
|
|
75
|
-
|
|
76
|
-
import { TsWatch } from '@git.zone/tswatch';
|
|
91
|
+
## Project Structure
|
|
77
92
|
|
|
78
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
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
|
-
|
|
125
|
+
## Programmatic API
|
|
95
126
|
|
|
96
|
-
|
|
127
|
+
### Basic Usage
|
|
97
128
|
|
|
98
129
|
```typescript
|
|
99
130
|
import { TsWatch } from '@git.zone/tswatch';
|
|
100
131
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
132
|
+
// Create and start a watcher
|
|
133
|
+
const watcher = new TsWatch('node');
|
|
134
|
+
await watcher.start();
|
|
104
135
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (server) {
|
|
108
|
-
await server.start();
|
|
109
|
-
}
|
|
110
|
-
};
|
|
136
|
+
// Stop when done
|
|
137
|
+
await watcher.stop();
|
|
111
138
|
```
|
|
112
139
|
|
|
113
|
-
|
|
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
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
129
|
-
await customWatcher.start();
|
|
130
|
-
await customWatcher.stop();
|
|
131
|
-
};
|
|
151
|
+
await customWatcher.start();
|
|
132
152
|
```
|
|
133
153
|
|
|
134
|
-
|
|
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
|
-
|
|
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
|
-
|
|
144
|
-
const tsWatchInstance = new TsWatch('node');
|
|
166
|
+
## Development Server
|
|
145
167
|
|
|
146
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
```
|
|
170
|
+
- **Port**: 3002
|
|
171
|
+
- **Features**: CORS enabled, gzip compression, live reload
|
|
172
|
+
- **Serve directory**: `./dist_watch/`
|
|
155
173
|
|
|
156
|
-
|
|
174
|
+
Access your project at `http://localhost:3002` when running in element mode.
|
|
157
175
|
|
|
158
|
-
|
|
176
|
+
## Configuration Tips
|
|
159
177
|
|
|
160
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
188
|
+
### Developing a Node.js Library
|
|
189
|
+
```bash
|
|
190
|
+
tswatch npm
|
|
191
|
+
```
|
|
192
|
+
Automatically runs tests when you modify source files.
|
|
175
193
|
|
|
176
|
-
###
|
|
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
|
-
|
|
200
|
+
### Creating a Backend Service
|
|
201
|
+
```bash
|
|
202
|
+
tswatch service
|
|
203
|
+
```
|
|
204
|
+
Automatically restart your service on code changes.
|
|
179
205
|
|
|
180
|
-
|
|
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
|
|
package/ts/00_commitinfo_data.ts
CHANGED