ldx 1.0.1 → 1.0.2
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 +109 -12
- package/ldx.js +52 -2
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# LDX - Logging Developer Experience
|
|
2
|
+
|
|
2
3
|
A lightweight tool to enhance your development workflow by processing command output with customizable transformations.
|
|
3
4
|
|
|
4
5
|
## Features
|
|
@@ -12,6 +13,7 @@ A lightweight tool to enhance your development workflow by processing command ou
|
|
|
12
13
|
- **Developer-Friendly**: Improves readability and reduces noise in logs.
|
|
13
14
|
|
|
14
15
|
## Installation
|
|
16
|
+
|
|
15
17
|
To install LDX globally, run:
|
|
16
18
|
|
|
17
19
|
```bash
|
|
@@ -27,7 +29,7 @@ pnpm install --save-dev ldx
|
|
|
27
29
|
## Usage
|
|
28
30
|
|
|
29
31
|
### 1. Create a Configuration File
|
|
30
|
-
|
|
32
|
+
|
|
31
33
|
Create a `ldx.config.js` file in your project's root directory. This file defines the patterns and transformations for your command output.
|
|
32
34
|
|
|
33
35
|
Example:
|
|
@@ -36,7 +38,7 @@ Example:
|
|
|
36
38
|
module.exports = {
|
|
37
39
|
// Simple string replacement
|
|
38
40
|
"Test match 1": "✅ Test match 1 processed",
|
|
39
|
-
|
|
41
|
+
|
|
40
42
|
// Function-based processing
|
|
41
43
|
"Function match": (line) => `Processed: ${line}`,
|
|
42
44
|
};
|
|
@@ -77,13 +79,62 @@ module.exports = {
|
|
|
77
79
|
}
|
|
78
80
|
```
|
|
79
81
|
|
|
82
|
+
## Requirements
|
|
83
|
+
|
|
84
|
+
- Node.js >= 18.0.0
|
|
85
|
+
|
|
80
86
|
## Error Handling
|
|
81
87
|
|
|
82
|
-
|
|
88
|
+
LDX provides clear error messages for common issues:
|
|
89
|
+
|
|
90
|
+
### Missing Configuration File
|
|
91
|
+
|
|
92
|
+
If `ldx.config.js` is not found in your project root:
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
Oops, no ldx.config.js file found!
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Solution**: Create a `ldx.config.js` file in your project root. You can copy `ldx.config.example.js` as a starting point.
|
|
99
|
+
|
|
100
|
+
### Invalid Configuration
|
|
101
|
+
|
|
102
|
+
If your configuration has invalid values:
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
LDX: Configuration error - Invalid value type for key "myKey". Expected string or function, got number.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Solution**: Ensure all configuration values are either strings or functions.
|
|
109
|
+
|
|
110
|
+
### Empty Configuration
|
|
111
|
+
|
|
112
|
+
If your configuration object is empty:
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
LDX: Configuration error - Configuration cannot be empty.
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Solution**: Add at least one pattern-transformation pair to your configuration.
|
|
119
|
+
|
|
120
|
+
### Command Not Found
|
|
121
|
+
|
|
122
|
+
If the command you're trying to run doesn't exist:
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
Error executing command: Failed to start command: spawn xyz ENOENT
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**Solution**: Verify the command exists and is in your PATH.
|
|
129
|
+
|
|
130
|
+
### Function Processing Errors
|
|
83
131
|
|
|
84
|
-
|
|
132
|
+
If a transformer function throws an error, LDX will:
|
|
85
133
|
|
|
86
|
-
|
|
134
|
+
1. Log a warning: `LDX: provided function errored: <error message>`
|
|
135
|
+
2. Output the original unprocessed line (to prevent data loss)
|
|
136
|
+
|
|
137
|
+
**Solution**: Add try-catch blocks in your transformer functions for graceful error handling.
|
|
87
138
|
|
|
88
139
|
## Testing
|
|
89
140
|
|
|
@@ -92,6 +143,7 @@ Run tests with:
|
|
|
92
143
|
```bash
|
|
93
144
|
pnpm test
|
|
94
145
|
```
|
|
146
|
+
|
|
95
147
|
## Usage examples
|
|
96
148
|
|
|
97
149
|
### Basic Usage
|
|
@@ -111,22 +163,67 @@ ldx pnpm run dev
|
|
|
111
163
|
```bash
|
|
112
164
|
ldx docker-compose up
|
|
113
165
|
```
|
|
166
|
+
|
|
114
167
|
## Development
|
|
115
168
|
|
|
116
169
|
1. Clone the repository
|
|
117
170
|
|
|
118
171
|
2. Install dependencies:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
pnpm i
|
|
175
|
+
```
|
|
122
176
|
|
|
123
177
|
3. Make changes
|
|
124
178
|
|
|
125
179
|
4. Run tests:
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
pnpm test
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Releasing
|
|
186
|
+
|
|
187
|
+
This project uses [standard-version](https://github.com/conventional-changelog/standard-version) for automated versioning and changelog generation based on [Conventional Commits](https://www.conventionalcommits.org/).
|
|
188
|
+
|
|
189
|
+
### Commit Message Format
|
|
190
|
+
|
|
191
|
+
```text
|
|
192
|
+
<type>(<scope>): <description>
|
|
193
|
+
|
|
194
|
+
[optional body]
|
|
195
|
+
|
|
196
|
+
[optional footer(s)]
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Types: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `chore`, `ci`, `build`
|
|
200
|
+
|
|
201
|
+
Examples:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
git commit -m "feat: add support for regex patterns"
|
|
205
|
+
git commit -m "fix: handle empty lines in output"
|
|
206
|
+
git commit -m "docs: update configuration examples"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Creating a Release
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Automatic version bump based on commits (recommended)
|
|
213
|
+
pnpm release
|
|
214
|
+
|
|
215
|
+
# Specific version bumps
|
|
216
|
+
pnpm release:patch # 1.0.2 -> 1.0.3
|
|
217
|
+
pnpm release:minor # 1.0.2 -> 1.1.0
|
|
218
|
+
pnpm release:major # 1.0.2 -> 2.0.0
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
After running the release command:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
git push --follow-tags origin main && npm publish
|
|
225
|
+
```
|
|
129
226
|
|
|
130
227
|
## Contributing
|
|
131
228
|
|
|
132
|
-
Contributions are welcome! Please open issues or pull requests in this repo.
|
|
229
|
+
Contributions are welcome! Please open issues or pull requests in this repo.
|
package/ldx.js
CHANGED
|
@@ -13,6 +13,35 @@ try {
|
|
|
13
13
|
process.exit(1);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
// Validate configuration
|
|
17
|
+
function validateConfig(cfg) {
|
|
18
|
+
if (!cfg || typeof cfg !== "object" || Array.isArray(cfg)) {
|
|
19
|
+
return { valid: false, error: "Configuration must be a non-null object." };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const entries = Object.entries(cfg);
|
|
23
|
+
if (entries.length === 0) {
|
|
24
|
+
return { valid: false, error: "Configuration cannot be empty." };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const [key, value] of entries) {
|
|
28
|
+
if (typeof value !== "string" && typeof value !== "function") {
|
|
29
|
+
return {
|
|
30
|
+
valid: false,
|
|
31
|
+
error: `Invalid value type for key "${key}". Expected string or function, got ${typeof value}.`,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return { valid: true };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const validation = validateConfig(config);
|
|
40
|
+
if (!validation.valid) {
|
|
41
|
+
console.error(`LDX: Configuration error - ${validation.error}`);
|
|
42
|
+
process.exit(1);
|
|
43
|
+
}
|
|
44
|
+
|
|
16
45
|
console.log(
|
|
17
46
|
"Thank you for using LDX! Collaborate or report issues at https://github.com/leog/ldx \n"
|
|
18
47
|
);
|
|
@@ -28,6 +57,11 @@ function executeAndProcessCommand() {
|
|
|
28
57
|
|
|
29
58
|
const child = spawn(command[0], command.slice(1));
|
|
30
59
|
|
|
60
|
+
// Handle spawn errors (e.g., command not found)
|
|
61
|
+
child.on("error", (error) => {
|
|
62
|
+
reject(new Error(`Failed to start command: ${error.message}`));
|
|
63
|
+
});
|
|
64
|
+
|
|
31
65
|
// Handle stdout
|
|
32
66
|
if (child.stdout) {
|
|
33
67
|
child.stdout.on("data", (data) => {
|
|
@@ -41,6 +75,21 @@ function executeAndProcessCommand() {
|
|
|
41
75
|
});
|
|
42
76
|
}
|
|
43
77
|
|
|
78
|
+
// Handle stderr
|
|
79
|
+
if (child.stderr) {
|
|
80
|
+
child.stderr.on("data", (data) => {
|
|
81
|
+
const lines = data.toString().split("\n");
|
|
82
|
+
lines.forEach((line) => {
|
|
83
|
+
const processedLine = processOutput(line);
|
|
84
|
+
if (processedLine) {
|
|
85
|
+
console.error(processedLine); // Output processed error line to stderr
|
|
86
|
+
} else if (line.trim()) {
|
|
87
|
+
console.error(line); // Pass through unmatched non-empty lines
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
44
93
|
// Handle process exit
|
|
45
94
|
child.on("close", (code) => {
|
|
46
95
|
if (code !== 0) {
|
|
@@ -65,13 +114,13 @@ function processOutput(line) {
|
|
|
65
114
|
return value;
|
|
66
115
|
}
|
|
67
116
|
|
|
68
|
-
// Handle
|
|
117
|
+
// Handle function values
|
|
69
118
|
if (typeof value === "function") {
|
|
70
119
|
try {
|
|
71
120
|
return value(line);
|
|
72
121
|
} catch (e) {
|
|
73
122
|
console.warn("LDX: provided function errored: ", e.message);
|
|
74
|
-
return
|
|
123
|
+
return line; // Return original line on error to prevent data loss
|
|
75
124
|
}
|
|
76
125
|
}
|
|
77
126
|
|
|
@@ -89,6 +138,7 @@ function processOutput(line) {
|
|
|
89
138
|
module.exports = {
|
|
90
139
|
processOutput,
|
|
91
140
|
executeAndProcessCommand,
|
|
141
|
+
validateConfig,
|
|
92
142
|
};
|
|
93
143
|
|
|
94
144
|
// Execute the command if this script is run directly
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ldx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "ldx.js",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18.0.0"
|
|
7
|
+
},
|
|
5
8
|
"bin": {
|
|
6
9
|
"ldx": "ldx.js"
|
|
7
10
|
},
|
|
@@ -32,9 +35,15 @@
|
|
|
32
35
|
"devDependencies": {
|
|
33
36
|
"@vitest/coverage-v8": "3.0.9",
|
|
34
37
|
"mock-require": "^3.0.3",
|
|
38
|
+
"standard-version": "^9.5.0",
|
|
35
39
|
"vitest": "^3.0.9"
|
|
36
40
|
},
|
|
37
41
|
"scripts": {
|
|
38
|
-
"test": "vitest --coverage"
|
|
42
|
+
"test": "vitest --coverage",
|
|
43
|
+
"release": "standard-version",
|
|
44
|
+
"release:minor": "standard-version --release-as minor",
|
|
45
|
+
"release:major": "standard-version --release-as major",
|
|
46
|
+
"release:patch": "standard-version --release-as patch",
|
|
47
|
+
"release:first": "standard-version --first-release"
|
|
39
48
|
}
|
|
40
|
-
}
|
|
49
|
+
}
|