@webpieces/dev-config 0.0.0-dev
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/README.md +306 -0
- package/bin/set-version.sh +86 -0
- package/bin/setup-claude-patterns.sh +51 -0
- package/bin/start.sh +107 -0
- package/bin/stop.sh +65 -0
- package/bin/use-local-webpieces.sh +89 -0
- package/bin/use-published-webpieces.sh +33 -0
- package/config/eslint/base.mjs +91 -0
- package/config/typescript/tsconfig.base.json +25 -0
- package/eslint-plugin/__tests__/catch-error-pattern.test.ts +360 -0
- package/eslint-plugin/__tests__/max-file-lines.test.ts +195 -0
- package/eslint-plugin/__tests__/max-method-lines.test.ts +246 -0
- package/eslint-plugin/index.d.ts +14 -0
- package/eslint-plugin/index.js +19 -0
- package/eslint-plugin/index.js.map +1 -0
- package/eslint-plugin/index.ts +18 -0
- package/eslint-plugin/rules/catch-error-pattern.d.ts +11 -0
- package/eslint-plugin/rules/catch-error-pattern.js +196 -0
- package/eslint-plugin/rules/catch-error-pattern.js.map +1 -0
- package/eslint-plugin/rules/catch-error-pattern.ts +281 -0
- package/eslint-plugin/rules/max-file-lines.d.ts +12 -0
- package/eslint-plugin/rules/max-file-lines.js +257 -0
- package/eslint-plugin/rules/max-file-lines.js.map +1 -0
- package/eslint-plugin/rules/max-file-lines.ts +272 -0
- package/eslint-plugin/rules/max-method-lines.d.ts +12 -0
- package/eslint-plugin/rules/max-method-lines.js +257 -0
- package/eslint-plugin/rules/max-method-lines.js.map +1 -0
- package/eslint-plugin/rules/max-method-lines.ts +304 -0
- package/package.json +54 -0
- package/patterns/CLAUDE.md +293 -0
- package/patterns/claude.patterns.md +798 -0
package/README.md
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# @webpieces/dev-config
|
|
2
|
+
|
|
3
|
+
Development configuration, scripts, and patterns for WebPieces projects.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides shareable development tools for projects using the WebPieces framework:
|
|
8
|
+
|
|
9
|
+
- **Executable scripts** for common development tasks
|
|
10
|
+
- **ESLint configuration** with WebPieces patterns and best practices
|
|
11
|
+
- **Jest preset** for testing TypeScript projects
|
|
12
|
+
- **Base TypeScript configuration** with decorator support
|
|
13
|
+
- **Claude Code patterns** for AI-assisted development
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install --save-dev @webpieces/dev-config
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
### 1. Executable Scripts
|
|
24
|
+
|
|
25
|
+
All scripts are available as npm bin commands after installation.
|
|
26
|
+
|
|
27
|
+
#### Available Commands
|
|
28
|
+
|
|
29
|
+
| Command | Description |
|
|
30
|
+
|---------|-------------|
|
|
31
|
+
| `wp-start` | Start the WebPieces development server |
|
|
32
|
+
| `wp-stop` | Stop the running server |
|
|
33
|
+
| `wp-set-version` | Update package versions across the monorepo |
|
|
34
|
+
| `wp-use-local` | Switch to local WebPieces packages for development |
|
|
35
|
+
| `wp-use-published` | Switch back to published npm packages |
|
|
36
|
+
| `wp-setup-patterns` | Create symlinks for Claude Code pattern files |
|
|
37
|
+
|
|
38
|
+
#### Usage in package.json
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"scripts": {
|
|
43
|
+
"start": "wp-start 8080",
|
|
44
|
+
"stop": "wp-stop",
|
|
45
|
+
"dev:local": "wp-use-local",
|
|
46
|
+
"postinstall": "wp-setup-patterns"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### Local Development with wp-use-local
|
|
52
|
+
|
|
53
|
+
To develop against a local copy of webpieces-ts:
|
|
54
|
+
|
|
55
|
+
1. Set the `WEBPIECES_ROOT` environment variable:
|
|
56
|
+
```bash
|
|
57
|
+
export WEBPIECES_ROOT=/path/to/webpieces-ts
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
2. Build webpieces-ts:
|
|
61
|
+
```bash
|
|
62
|
+
cd $WEBPIECES_ROOT
|
|
63
|
+
npm run build
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
3. Switch to local packages:
|
|
67
|
+
```bash
|
|
68
|
+
wp-use-local
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
4. To switch back to published packages:
|
|
72
|
+
```bash
|
|
73
|
+
wp-use-published
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 2. ESLint Configuration
|
|
77
|
+
|
|
78
|
+
Import the base configuration in your `eslint.config.mjs`:
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
import webpiecesConfig from '@webpieces/dev-config/eslint';
|
|
82
|
+
import nx from '@nx/eslint-plugin';
|
|
83
|
+
|
|
84
|
+
export default [
|
|
85
|
+
...webpiecesConfig, // WebPieces base rules
|
|
86
|
+
...nx.configs['flat/typescript'],
|
|
87
|
+
{
|
|
88
|
+
// Project-specific overrides
|
|
89
|
+
files: ['**/*.ts'],
|
|
90
|
+
rules: {
|
|
91
|
+
// Your custom rules
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
];
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The base configuration includes:
|
|
98
|
+
|
|
99
|
+
- TypeScript-specific rules aligned with WebPieces patterns
|
|
100
|
+
- Relaxed rules for test files
|
|
101
|
+
- Consistent code quality standards
|
|
102
|
+
- Support for decorators and metadata
|
|
103
|
+
|
|
104
|
+
### 3. Jest Preset
|
|
105
|
+
|
|
106
|
+
Use the Jest preset in your `jest.config.js`:
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
module.exports = {
|
|
110
|
+
preset: '@webpieces/dev-config/jest',
|
|
111
|
+
// Project-specific overrides
|
|
112
|
+
roots: ['<rootDir>/src'],
|
|
113
|
+
collectCoverageFrom: [
|
|
114
|
+
'src/**/*.ts',
|
|
115
|
+
'!src/**/*.spec.ts',
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The preset includes:
|
|
121
|
+
|
|
122
|
+
- `ts-jest` for TypeScript support
|
|
123
|
+
- Decorator and metadata support enabled
|
|
124
|
+
- Sensible test file patterns (`*.spec.ts`, `*.test.ts`)
|
|
125
|
+
- Coverage configuration
|
|
126
|
+
|
|
127
|
+
### 4. TypeScript Configuration
|
|
128
|
+
|
|
129
|
+
Extend the base TypeScript config in your `tsconfig.json`:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"extends": "@webpieces/dev-config/tsconfig",
|
|
134
|
+
"compilerOptions": {
|
|
135
|
+
"baseUrl": ".",
|
|
136
|
+
"paths": {
|
|
137
|
+
// Project-specific path mappings
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"include": ["src/**/*"]
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The base configuration includes:
|
|
145
|
+
|
|
146
|
+
- Decorator support (`experimentalDecorators`, `emitDecoratorMetadata`)
|
|
147
|
+
- Strict type checking
|
|
148
|
+
- ES2021 target with CommonJS modules
|
|
149
|
+
- Source maps enabled
|
|
150
|
+
|
|
151
|
+
### 5. Claude Code Patterns
|
|
152
|
+
|
|
153
|
+
The package includes WebPieces coding patterns and guidelines for Claude Code.
|
|
154
|
+
|
|
155
|
+
#### Setup
|
|
156
|
+
|
|
157
|
+
Run the setup command to create symlinks in your `.claude` directory:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
wp-setup-patterns
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
This creates:
|
|
164
|
+
- `.claude/CLAUDE.md` - Claude Code guidelines
|
|
165
|
+
- `.claude/claude.patterns.md` - Detailed coding patterns
|
|
166
|
+
|
|
167
|
+
These files will auto-update when you upgrade `@webpieces/dev-config`.
|
|
168
|
+
|
|
169
|
+
#### Adding to postinstall
|
|
170
|
+
|
|
171
|
+
Add to your `package.json` to automatically set up patterns after install:
|
|
172
|
+
|
|
173
|
+
```json
|
|
174
|
+
{
|
|
175
|
+
"scripts": {
|
|
176
|
+
"postinstall": "wp-setup-patterns"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Auto-Sync Behavior
|
|
182
|
+
|
|
183
|
+
When you upgrade `@webpieces/dev-config`, all configurations automatically update:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
npm update @webpieces/dev-config
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Your ESLint, Jest, and TypeScript configurations will use the latest version without manual intervention, as they reference files from `node_modules/@webpieces/dev-config`.
|
|
190
|
+
|
|
191
|
+
## Version Management
|
|
192
|
+
|
|
193
|
+
The package follows semantic versioning:
|
|
194
|
+
|
|
195
|
+
- **Major versions** (2.0.0): Breaking changes to configuration or script behavior
|
|
196
|
+
- **Minor versions** (1.1.0): New features, additional scripts, or non-breaking config changes
|
|
197
|
+
- **Patch versions** (1.0.1): Bug fixes and documentation updates
|
|
198
|
+
|
|
199
|
+
## Examples
|
|
200
|
+
|
|
201
|
+
### Full Project Setup
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# Install the package
|
|
205
|
+
npm install --save-dev @webpieces/dev-config
|
|
206
|
+
|
|
207
|
+
# Set up Claude patterns
|
|
208
|
+
npx wp-setup-patterns
|
|
209
|
+
|
|
210
|
+
# Create eslint.config.mjs
|
|
211
|
+
cat > eslint.config.mjs << 'EOF'
|
|
212
|
+
import webpiecesConfig from '@webpieces/dev-config/eslint';
|
|
213
|
+
export default [...webpiecesConfig];
|
|
214
|
+
EOF
|
|
215
|
+
|
|
216
|
+
# Create jest.config.js
|
|
217
|
+
cat > jest.config.js << 'EOF'
|
|
218
|
+
module.exports = {
|
|
219
|
+
preset: '@webpieces/dev-config/jest',
|
|
220
|
+
};
|
|
221
|
+
EOF
|
|
222
|
+
|
|
223
|
+
# Create tsconfig.json
|
|
224
|
+
cat > tsconfig.json << 'EOF'
|
|
225
|
+
{
|
|
226
|
+
"extends": "@webpieces/dev-config/tsconfig",
|
|
227
|
+
"include": ["src/**/*"]
|
|
228
|
+
}
|
|
229
|
+
EOF
|
|
230
|
+
|
|
231
|
+
# Add scripts to package.json
|
|
232
|
+
npm pkg set scripts.start="wp-start 8080"
|
|
233
|
+
npm pkg set scripts.stop="wp-stop"
|
|
234
|
+
npm pkg set scripts.postinstall="wp-setup-patterns"
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Using in webpieces-ts itself
|
|
238
|
+
|
|
239
|
+
The webpieces-ts monorepo uses its own dev-config package via workspace protocol:
|
|
240
|
+
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"devDependencies": {
|
|
244
|
+
"@webpieces/dev-config": "workspace:*"
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
This ensures webpieces-ts uses the same tools as consuming projects (dogfooding).
|
|
250
|
+
|
|
251
|
+
## Troubleshooting
|
|
252
|
+
|
|
253
|
+
### Scripts not found
|
|
254
|
+
|
|
255
|
+
If bin commands like `wp-start` are not found:
|
|
256
|
+
|
|
257
|
+
1. Ensure the package is installed: `npm list @webpieces/dev-config`
|
|
258
|
+
2. Check that npm created symlinks: `ls -la node_modules/.bin/wp-*`
|
|
259
|
+
3. Try reinstalling: `npm install`
|
|
260
|
+
|
|
261
|
+
### Claude patterns not showing
|
|
262
|
+
|
|
263
|
+
If `.claude/CLAUDE.md` doesn't exist:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
# Run the setup command manually
|
|
267
|
+
npx wp-setup-patterns
|
|
268
|
+
|
|
269
|
+
# Or check if the files exist in node_modules
|
|
270
|
+
ls -la node_modules/@webpieces/dev-config/patterns/
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Local development not working
|
|
274
|
+
|
|
275
|
+
If `wp-use-local` fails:
|
|
276
|
+
|
|
277
|
+
1. Ensure `WEBPIECES_ROOT` is set: `echo $WEBPIECES_ROOT`
|
|
278
|
+
2. Build webpieces-ts: `cd $WEBPIECES_ROOT && npm run build`
|
|
279
|
+
3. Check that dist exists: `ls $WEBPIECES_ROOT/dist/packages/`
|
|
280
|
+
|
|
281
|
+
## Contributing
|
|
282
|
+
|
|
283
|
+
This package is part of the [webpieces-ts](https://github.com/deanhiller/webpieces-ts) monorepo.
|
|
284
|
+
|
|
285
|
+
To modify scripts or configurations:
|
|
286
|
+
|
|
287
|
+
1. Edit files in `packages/tooling/dev-config/`
|
|
288
|
+
2. Build: `npx nx build dev-config`
|
|
289
|
+
3. Test in webpieces-ts itself (dogfooding)
|
|
290
|
+
4. Submit a pull request
|
|
291
|
+
|
|
292
|
+
## License
|
|
293
|
+
|
|
294
|
+
Apache-2.0
|
|
295
|
+
|
|
296
|
+
## Related Packages
|
|
297
|
+
|
|
298
|
+
- [@webpieces/core-context](https://www.npmjs.com/package/@webpieces/core-context) - Context management
|
|
299
|
+
- [@webpieces/http-server](https://www.npmjs.com/package/@webpieces/http-server) - HTTP server
|
|
300
|
+
- [@webpieces/http-routing](https://www.npmjs.com/package/@webpieces/http-routing) - Routing and controllers
|
|
301
|
+
- [@webpieces/http-filters](https://www.npmjs.com/package/@webpieces/http-filters) - Filter chain
|
|
302
|
+
|
|
303
|
+
## Support
|
|
304
|
+
|
|
305
|
+
- GitHub Issues: https://github.com/deanhiller/webpieces-ts/issues
|
|
306
|
+
- Documentation: https://github.com/deanhiller/webpieces-ts#readme
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
# Set version script for webpieces packages
|
|
5
|
+
# Path-agnostic version that works from both workspace and node_modules
|
|
6
|
+
|
|
7
|
+
# Detect project root
|
|
8
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
9
|
+
|
|
10
|
+
if [[ "$SCRIPT_DIR" == *"node_modules/@webpieces/dev-config"* ]]; then
|
|
11
|
+
# Running in consumer project
|
|
12
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
13
|
+
else
|
|
14
|
+
# Running in webpieces-ts workspace
|
|
15
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
cd "$PROJECT_ROOT" || exit 1
|
|
19
|
+
|
|
20
|
+
# Read base version from VERSION file
|
|
21
|
+
BASE_VERSION=$(cat VERSION | tr -d '[:space:]')
|
|
22
|
+
|
|
23
|
+
# Get build number from environment or default to 'dev'
|
|
24
|
+
BUILD_NUMBER=${BUILD_NUMBER:-dev}
|
|
25
|
+
|
|
26
|
+
# Construct full version
|
|
27
|
+
if [ "$BUILD_NUMBER" = "dev" ]; then
|
|
28
|
+
FULL_VERSION="0.0.0-dev"
|
|
29
|
+
else
|
|
30
|
+
FULL_VERSION="${BASE_VERSION}.${BUILD_NUMBER}"
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
echo "📦 Setting version to: $FULL_VERSION"
|
|
34
|
+
echo " Base version: $BASE_VERSION"
|
|
35
|
+
echo " Build number: $BUILD_NUMBER"
|
|
36
|
+
|
|
37
|
+
# Update all package.json files in packages/
|
|
38
|
+
update_package() {
|
|
39
|
+
local pkg_file=$1
|
|
40
|
+
echo " Updating: $pkg_file"
|
|
41
|
+
|
|
42
|
+
# Create temp file
|
|
43
|
+
local tmp_file=$(mktemp)
|
|
44
|
+
|
|
45
|
+
# Update version
|
|
46
|
+
jq --arg ver "$FULL_VERSION" '.version=$ver' "$pkg_file" > "$tmp_file"
|
|
47
|
+
|
|
48
|
+
# Update @webpieces/* dependencies to match
|
|
49
|
+
jq --arg ver "$FULL_VERSION" '
|
|
50
|
+
if .dependencies then
|
|
51
|
+
.dependencies |= with_entries(
|
|
52
|
+
if .key | startswith("@webpieces/") then
|
|
53
|
+
.value = $ver
|
|
54
|
+
else
|
|
55
|
+
.
|
|
56
|
+
end
|
|
57
|
+
)
|
|
58
|
+
else
|
|
59
|
+
.
|
|
60
|
+
end
|
|
61
|
+
' "$tmp_file" > "$tmp_file.2"
|
|
62
|
+
|
|
63
|
+
# Move back
|
|
64
|
+
mv "$tmp_file.2" "$pkg_file"
|
|
65
|
+
rm -f "$tmp_file"
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# Update source package.json files
|
|
69
|
+
echo "📝 Updating source package.json files..."
|
|
70
|
+
for pkg in packages/core/*/package.json packages/http/*/package.json packages/tooling/*/package.json; do
|
|
71
|
+
if [ -f "$pkg" ]; then
|
|
72
|
+
update_package "$pkg"
|
|
73
|
+
fi
|
|
74
|
+
done
|
|
75
|
+
|
|
76
|
+
# Update dist package.json files if they exist
|
|
77
|
+
if [ -d "dist/packages" ]; then
|
|
78
|
+
echo "📝 Updating dist package.json files..."
|
|
79
|
+
for pkg in dist/packages/core/*/package.json dist/packages/http/*/package.json dist/packages/tooling/*/package.json; do
|
|
80
|
+
if [ -f "$pkg" ]; then
|
|
81
|
+
update_package "$pkg"
|
|
82
|
+
fi
|
|
83
|
+
done
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
echo "✅ Version set to $FULL_VERSION for all packages"
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
# Setup Claude pattern files by creating symlinks
|
|
5
|
+
# This script runs as postinstall to make Claude documentation available
|
|
6
|
+
|
|
7
|
+
# Detect project root
|
|
8
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
9
|
+
|
|
10
|
+
if [[ "$SCRIPT_DIR" == *"node_modules/@webpieces/dev-config"* ]]; then
|
|
11
|
+
# Running in consumer project (from node_modules)
|
|
12
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
13
|
+
PATTERNS_DIR="$SCRIPT_DIR/../patterns"
|
|
14
|
+
else
|
|
15
|
+
# Running in webpieces-ts workspace
|
|
16
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
17
|
+
PATTERNS_DIR="$PROJECT_ROOT/packages/tooling/dev-config/patterns"
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
cd "$PROJECT_ROOT" || exit 1
|
|
21
|
+
|
|
22
|
+
echo "🔗 Setting up Claude pattern files..."
|
|
23
|
+
|
|
24
|
+
# Create .claude directory if it doesn't exist
|
|
25
|
+
mkdir -p .claude
|
|
26
|
+
|
|
27
|
+
# Check if patterns exist
|
|
28
|
+
if [ ! -f "$PATTERNS_DIR/CLAUDE.md" ]; then
|
|
29
|
+
echo "⚠️ Warning: CLAUDE.md not found in patterns directory"
|
|
30
|
+
echo " Expected: $PATTERNS_DIR/CLAUDE.md"
|
|
31
|
+
else
|
|
32
|
+
# Create relative symlink to CLAUDE.md
|
|
33
|
+
echo " Creating symlink for CLAUDE.md..."
|
|
34
|
+
ln -sf "$PATTERNS_DIR/CLAUDE.md" .claude/CLAUDE.md
|
|
35
|
+
echo " ✅ .claude/CLAUDE.md"
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
if [ ! -f "$PATTERNS_DIR/claude.patterns.md" ]; then
|
|
39
|
+
echo "⚠️ Warning: claude.patterns.md not found in patterns directory"
|
|
40
|
+
echo " Expected: $PATTERNS_DIR/claude.patterns.md"
|
|
41
|
+
else
|
|
42
|
+
# Create relative symlink to claude.patterns.md
|
|
43
|
+
echo " Creating symlink for claude.patterns.md..."
|
|
44
|
+
ln -sf "$PATTERNS_DIR/claude.patterns.md" .claude/claude.patterns.md
|
|
45
|
+
echo " ✅ .claude/claude.patterns.md"
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
echo ""
|
|
49
|
+
echo "✅ Claude pattern files are available in .claude/"
|
|
50
|
+
echo " These files are symlinked from @webpieces/dev-config"
|
|
51
|
+
echo " They will auto-update when you upgrade the package"
|
package/bin/start.sh
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Start script for webpieces-ts server
|
|
4
|
+
# Path-agnostic version that works from both workspace and node_modules
|
|
5
|
+
|
|
6
|
+
PORT=${1:-8080}
|
|
7
|
+
LOG_FILE="tmp/server.log"
|
|
8
|
+
PID_FILE="/tmp/webpieces-ts-server.pid"
|
|
9
|
+
|
|
10
|
+
echo "Starting webpieces-ts server on port $PORT..."
|
|
11
|
+
echo "Logs: $LOG_FILE"
|
|
12
|
+
|
|
13
|
+
# Check if already running
|
|
14
|
+
if [ -f "$PID_FILE" ]; then
|
|
15
|
+
if kill -0 $(cat "$PID_FILE") 2>/dev/null; then
|
|
16
|
+
echo "❌ Server is already running (PID: $(cat $PID_FILE))"
|
|
17
|
+
exit 1
|
|
18
|
+
else
|
|
19
|
+
echo "⚠️ Removing stale PID file"
|
|
20
|
+
rm -f "$PID_FILE"
|
|
21
|
+
fi
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null ; then
|
|
25
|
+
echo "❌ Port $PORT is already in use"
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Detect project root based on where script is running from
|
|
30
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
31
|
+
|
|
32
|
+
if [[ "$SCRIPT_DIR" == *"node_modules/@webpieces/dev-config"* ]]; then
|
|
33
|
+
# Running in consumer project (from node_modules)
|
|
34
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
35
|
+
else
|
|
36
|
+
# Running in webpieces-ts workspace
|
|
37
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
echo "Project root: $PROJECT_ROOT"
|
|
41
|
+
cd "$PROJECT_ROOT" || exit 1
|
|
42
|
+
|
|
43
|
+
# Build the server
|
|
44
|
+
echo "Building server..."
|
|
45
|
+
npx nx build example-app
|
|
46
|
+
|
|
47
|
+
if [ $? -ne 0 ]; then
|
|
48
|
+
echo "❌ Build failed"
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
echo "✅ Build completed successfully"
|
|
53
|
+
|
|
54
|
+
# Create symlinks for @webpieces libraries (required for production build)
|
|
55
|
+
echo "Creating @webpieces library symlinks..."
|
|
56
|
+
rm -rf node_modules/@webpieces/*
|
|
57
|
+
mkdir -p node_modules/@webpieces
|
|
58
|
+
|
|
59
|
+
# Create symlinks to dist packages
|
|
60
|
+
ln -sf "$(pwd)/dist/packages/core/core-context" node_modules/@webpieces/core-context
|
|
61
|
+
ln -sf "$(pwd)/dist/packages/core/core-meta" node_modules/@webpieces/core-meta
|
|
62
|
+
ln -sf "$(pwd)/dist/packages/http/http-routing" node_modules/@webpieces/http-routing
|
|
63
|
+
ln -sf "$(pwd)/dist/packages/http/http-filters" node_modules/@webpieces/http-filters
|
|
64
|
+
ln -sf "$(pwd)/dist/packages/http/http-server" node_modules/@webpieces/http-server
|
|
65
|
+
|
|
66
|
+
echo "✅ Symlinks created successfully"
|
|
67
|
+
|
|
68
|
+
# Create tmp directory for logs
|
|
69
|
+
mkdir -p tmp
|
|
70
|
+
|
|
71
|
+
# Run the production build (with reflect-metadata loaded first)
|
|
72
|
+
echo "Starting server..."
|
|
73
|
+
NODE_ENV=development PORT=$PORT node -r reflect-metadata dist/apps/example-app/src/server.js > $LOG_FILE 2>&1 &
|
|
74
|
+
SERVER_PID=$!
|
|
75
|
+
|
|
76
|
+
# Save PID
|
|
77
|
+
echo $SERVER_PID > $PID_FILE
|
|
78
|
+
|
|
79
|
+
echo "Started server with PID: $SERVER_PID"
|
|
80
|
+
echo "Waiting for server to be ready..."
|
|
81
|
+
|
|
82
|
+
# Monitor log for ready message
|
|
83
|
+
for i in {1..60}; do
|
|
84
|
+
if grep -q "listening on" $LOG_FILE 2>/dev/null; then
|
|
85
|
+
echo "✅ Server is ready on port $PORT"
|
|
86
|
+
echo "✅ Process PID: $SERVER_PID"
|
|
87
|
+
echo "✅ Tail logs with: tail -f $LOG_FILE"
|
|
88
|
+
exit 0
|
|
89
|
+
fi
|
|
90
|
+
|
|
91
|
+
# Check if process is still alive
|
|
92
|
+
if ! kill -0 $SERVER_PID 2>/dev/null; then
|
|
93
|
+
echo "❌ Server process died unexpectedly!"
|
|
94
|
+
echo "Last 20 lines of log:"
|
|
95
|
+
tail -n 20 $LOG_FILE
|
|
96
|
+
exit 1
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
sleep 1
|
|
100
|
+
done
|
|
101
|
+
|
|
102
|
+
echo "⚠️ Server started but ready message not seen"
|
|
103
|
+
echo "Last 20 lines of log:"
|
|
104
|
+
tail -n 20 $LOG_FILE
|
|
105
|
+
echo ""
|
|
106
|
+
echo "Server may still be starting. Check logs with: tail -f $LOG_FILE"
|
|
107
|
+
exit 0
|
package/bin/stop.sh
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Stop script for webpieces-ts server
|
|
4
|
+
# Path-agnostic version that works from both workspace and node_modules
|
|
5
|
+
|
|
6
|
+
PID_FILE="/tmp/webpieces-ts-server.pid"
|
|
7
|
+
|
|
8
|
+
echo "Stopping webpieces-ts server..."
|
|
9
|
+
|
|
10
|
+
# Check if PID file exists
|
|
11
|
+
if [ ! -f "$PID_FILE" ]; then
|
|
12
|
+
echo "⚠️ No PID file found. Server may not be running."
|
|
13
|
+
echo "Checking for any running server processes..."
|
|
14
|
+
|
|
15
|
+
# Try to find and kill any running server processes
|
|
16
|
+
pkill -f "node -r reflect-metadata dist/apps/example-app/src/server.js"
|
|
17
|
+
|
|
18
|
+
if [ $? -eq 0 ]; then
|
|
19
|
+
echo "✅ Killed running server process(es)"
|
|
20
|
+
else
|
|
21
|
+
echo "❌ No running server found"
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
exit 0
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
# Read PID
|
|
28
|
+
SERVER_PID=$(cat "$PID_FILE")
|
|
29
|
+
|
|
30
|
+
# Check if process is running
|
|
31
|
+
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
|
|
32
|
+
echo "⚠️ Process $SERVER_PID is not running (stale PID file)"
|
|
33
|
+
rm -f "$PID_FILE"
|
|
34
|
+
exit 0
|
|
35
|
+
fi
|
|
36
|
+
|
|
37
|
+
# Try graceful shutdown first (SIGTERM)
|
|
38
|
+
echo "Sending SIGTERM to process $SERVER_PID..."
|
|
39
|
+
kill "$SERVER_PID"
|
|
40
|
+
|
|
41
|
+
# Wait up to 10 seconds for graceful shutdown
|
|
42
|
+
for i in {1..10}; do
|
|
43
|
+
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
|
|
44
|
+
echo "✅ Server stopped gracefully"
|
|
45
|
+
rm -f "$PID_FILE"
|
|
46
|
+
exit 0
|
|
47
|
+
fi
|
|
48
|
+
sleep 1
|
|
49
|
+
done
|
|
50
|
+
|
|
51
|
+
# If still running, force kill (SIGKILL)
|
|
52
|
+
echo "⚠️ Server didn't stop gracefully, forcing shutdown..."
|
|
53
|
+
kill -9 "$SERVER_PID" 2>/dev/null
|
|
54
|
+
|
|
55
|
+
# Wait a bit more
|
|
56
|
+
sleep 1
|
|
57
|
+
|
|
58
|
+
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
|
|
59
|
+
echo "✅ Server stopped (forced)"
|
|
60
|
+
rm -f "$PID_FILE"
|
|
61
|
+
exit 0
|
|
62
|
+
else
|
|
63
|
+
echo "❌ Failed to stop server"
|
|
64
|
+
exit 1
|
|
65
|
+
fi
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
# Switch to local webpieces packages for development
|
|
5
|
+
# This script links to local dist/ packages instead of published npm packages
|
|
6
|
+
|
|
7
|
+
# Detect project root
|
|
8
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
9
|
+
|
|
10
|
+
if [[ "$SCRIPT_DIR" == *"node_modules/@webpieces/dev-config"* ]]; then
|
|
11
|
+
# Running in consumer project
|
|
12
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
13
|
+
else
|
|
14
|
+
# Running in webpieces-ts workspace
|
|
15
|
+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
cd "$PROJECT_ROOT" || exit 1
|
|
19
|
+
|
|
20
|
+
echo "🔗 Switching to local @webpieces packages..."
|
|
21
|
+
|
|
22
|
+
# Check if WEBPIECES_ROOT environment variable is set
|
|
23
|
+
if [ -z "$WEBPIECES_ROOT" ]; then
|
|
24
|
+
echo "❌ WEBPIECES_ROOT environment variable not set"
|
|
25
|
+
echo " Please set it to your webpieces-ts directory:"
|
|
26
|
+
echo " export WEBPIECES_ROOT=/path/to/webpieces-ts"
|
|
27
|
+
exit 1
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
if [ ! -d "$WEBPIECES_ROOT/dist/packages" ]; then
|
|
31
|
+
echo "❌ webpieces-ts dist/ directory not found at: $WEBPIECES_ROOT/dist/packages"
|
|
32
|
+
echo " Have you built webpieces-ts? Run: npm run build"
|
|
33
|
+
exit 1
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
# Remove existing @webpieces packages
|
|
37
|
+
echo " Removing published @webpieces packages..."
|
|
38
|
+
rm -rf node_modules/@webpieces/*
|
|
39
|
+
mkdir -p node_modules/@webpieces
|
|
40
|
+
|
|
41
|
+
# Create symlinks to local dist packages
|
|
42
|
+
echo " Creating symlinks to local packages..."
|
|
43
|
+
|
|
44
|
+
# Core packages
|
|
45
|
+
if [ -d "$WEBPIECES_ROOT/dist/packages/core/core-context" ]; then
|
|
46
|
+
ln -sf "$WEBPIECES_ROOT/dist/packages/core/core-context" node_modules/@webpieces/core-context
|
|
47
|
+
echo " ✅ core-context"
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
if [ -d "$WEBPIECES_ROOT/dist/packages/core/core-meta" ]; then
|
|
51
|
+
ln -sf "$WEBPIECES_ROOT/dist/packages/core/core-meta" node_modules/@webpieces/core-meta
|
|
52
|
+
echo " ✅ core-meta"
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
# HTTP packages
|
|
56
|
+
if [ -d "$WEBPIECES_ROOT/dist/packages/http/http-routing" ]; then
|
|
57
|
+
ln -sf "$WEBPIECES_ROOT/dist/packages/http/http-routing" node_modules/@webpieces/http-routing
|
|
58
|
+
echo " ✅ http-routing"
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
if [ -d "$WEBPIECES_ROOT/dist/packages/http/http-filters" ]; then
|
|
62
|
+
ln -sf "$WEBPIECES_ROOT/dist/packages/http/http-filters" node_modules/@webpieces/http-filters
|
|
63
|
+
echo " ✅ http-filters"
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
if [ -d "$WEBPIECES_ROOT/dist/packages/http/http-server" ]; then
|
|
67
|
+
ln -sf "$WEBPIECES_ROOT/dist/packages/http/http-server" node_modules/@webpieces/http-server
|
|
68
|
+
echo " ✅ http-server"
|
|
69
|
+
fi
|
|
70
|
+
|
|
71
|
+
if [ -d "$WEBPIECES_ROOT/dist/packages/http/http-client" ]; then
|
|
72
|
+
ln -sf "$WEBPIECES_ROOT/dist/packages/http/http-client" node_modules/@webpieces/http-client
|
|
73
|
+
echo " ✅ http-client"
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
if [ -d "$WEBPIECES_ROOT/dist/packages/http/http-api" ]; then
|
|
77
|
+
ln -sf "$WEBPIECES_ROOT/dist/packages/http/http-api" node_modules/@webpieces/http-api
|
|
78
|
+
echo " ✅ http-api"
|
|
79
|
+
fi
|
|
80
|
+
|
|
81
|
+
# Tooling packages
|
|
82
|
+
if [ -d "$WEBPIECES_ROOT/dist/packages/tooling/dev-config" ]; then
|
|
83
|
+
ln -sf "$WEBPIECES_ROOT/dist/packages/tooling/dev-config" node_modules/@webpieces/dev-config
|
|
84
|
+
echo " ✅ dev-config"
|
|
85
|
+
fi
|
|
86
|
+
|
|
87
|
+
echo ""
|
|
88
|
+
echo "✅ Successfully switched to local @webpieces packages from: $WEBPIECES_ROOT"
|
|
89
|
+
echo " To switch back to published packages, run: wp-use-published"
|