ldx 1.0.0 → 1.0.1
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 +131 -2
- package/ldx.js +102 -0
- package/package.json +37 -9
package/README.md
CHANGED
|
@@ -1,3 +1,132 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# LDX - Logging Developer Experience
|
|
2
|
+
A lightweight tool to enhance your development workflow by processing command output with customizable transformations.
|
|
3
3
|
|
|
4
|
+
## Features
|
|
5
|
+
|
|
6
|
+
- **Custom static transformations**: Define string patterns in your command output and replace them with custom messages.
|
|
7
|
+
|
|
8
|
+
- **Custom dynamic transformations**: Supports function-based transformations
|
|
9
|
+
|
|
10
|
+
- **Easy Integration**: Works seamlessly with any command-line tool or script.
|
|
11
|
+
|
|
12
|
+
- **Developer-Friendly**: Improves readability and reduces noise in logs.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
To install LDX globally, run:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm install -g ldx
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Alternatively, you can install it locally in your project:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm install --save-dev ldx
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### 1. Create a Configuration File
|
|
30
|
+
|
|
31
|
+
Create a `ldx.config.js` file in your project's root directory. This file defines the patterns and transformations for your command output.
|
|
32
|
+
|
|
33
|
+
Example:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
module.exports = {
|
|
37
|
+
// Simple string replacement
|
|
38
|
+
"Test match 1": "✅ Test match 1 processed",
|
|
39
|
+
|
|
40
|
+
// Function-based processing
|
|
41
|
+
"Function match": (line) => `Processed: ${line}`,
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Run Commands with LDX
|
|
46
|
+
|
|
47
|
+
Use LDX to run your commands and transform their output:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
ldx <your-command>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For example:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ldx pnpm run dev
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Configuration Options
|
|
60
|
+
|
|
61
|
+
### String Matching
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
module.exports = {
|
|
65
|
+
"String contained in output line": "Replacement text for the entire line"
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Function Processing
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
module.exports = {
|
|
73
|
+
"String contained in output line": (line) => {
|
|
74
|
+
// Custom processing logic
|
|
75
|
+
return `Formatted: ${line}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Error Handling
|
|
81
|
+
|
|
82
|
+
- Missing configuration files
|
|
83
|
+
|
|
84
|
+
- Invalid configuration types
|
|
85
|
+
|
|
86
|
+
- Function processing errors
|
|
87
|
+
|
|
88
|
+
## Testing
|
|
89
|
+
|
|
90
|
+
Run tests with:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pnpm test
|
|
94
|
+
```
|
|
95
|
+
## Usage examples
|
|
96
|
+
|
|
97
|
+
### Basic Usage
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
ldx echo "Testing LDX tool"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### With package manager scripts
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
ldx pnpm run dev
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### With complex commands
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
ldx docker-compose up
|
|
113
|
+
```
|
|
114
|
+
## Development
|
|
115
|
+
|
|
116
|
+
1. Clone the repository
|
|
117
|
+
|
|
118
|
+
2. Install dependencies:
|
|
119
|
+
```bash
|
|
120
|
+
pnpm i
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
3. Make changes
|
|
124
|
+
|
|
125
|
+
4. Run tests:
|
|
126
|
+
```bash
|
|
127
|
+
pnpm test
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Contributing
|
|
131
|
+
|
|
132
|
+
Contributions are welcome! Please open issues or pull requests in this repo.
|
package/ldx.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { resolve } = require("node:path");
|
|
4
|
+
const { spawn } = require("child_process");
|
|
5
|
+
|
|
6
|
+
// Load configuration
|
|
7
|
+
const project = resolve(process.cwd(), "ldx.config.js");
|
|
8
|
+
let config;
|
|
9
|
+
try {
|
|
10
|
+
config = require(project);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
console.error("Oops, no ldx.config.js file found!");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
console.log(
|
|
17
|
+
"Thank you for using LDX! Collaborate or report issues at https://github.com/leog/ldx \n"
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// Function to execute the command and process output
|
|
21
|
+
function executeAndProcessCommand() {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const command = process.argv.slice(2);
|
|
24
|
+
if (command.length === 0) {
|
|
25
|
+
reject(new Error("No command provided."));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const child = spawn(command[0], command.slice(1));
|
|
30
|
+
|
|
31
|
+
// Handle stdout
|
|
32
|
+
if (child.stdout) {
|
|
33
|
+
child.stdout.on("data", (data) => {
|
|
34
|
+
const lines = data.toString().split("\n");
|
|
35
|
+
lines.forEach((line) => {
|
|
36
|
+
const processedLine = processOutput(line);
|
|
37
|
+
if (processedLine) {
|
|
38
|
+
console.log(processedLine); // Output the processed line
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Handle process exit
|
|
45
|
+
child.on("close", (code) => {
|
|
46
|
+
if (code !== 0) {
|
|
47
|
+
reject(new Error(`Command failed with exit code ${code}`));
|
|
48
|
+
} else {
|
|
49
|
+
resolve();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Function to process each line of output
|
|
56
|
+
function processOutput(line) {
|
|
57
|
+
// Check static matches first (O(n) lookup, but optimized for small n)
|
|
58
|
+
const match = Object.entries(config).find(([key]) => line.includes(key));
|
|
59
|
+
|
|
60
|
+
if (match) {
|
|
61
|
+
const [key, value] = match;
|
|
62
|
+
|
|
63
|
+
// Handle string values
|
|
64
|
+
if (typeof value === "string") {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Handle array values
|
|
69
|
+
if (typeof value === "function") {
|
|
70
|
+
try {
|
|
71
|
+
return value(line);
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.warn("LDX: provided function errored: ", e.message);
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Handle invalid configurations
|
|
79
|
+
console.warn(
|
|
80
|
+
`Invalid configuration for key: ${key}. Expected string or function.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// No match found
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Export functions for testing
|
|
89
|
+
module.exports = {
|
|
90
|
+
processOutput,
|
|
91
|
+
executeAndProcessCommand,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Execute the command if this script is run directly
|
|
95
|
+
/* v8 ignore start */
|
|
96
|
+
if (require.main === module) {
|
|
97
|
+
// Main execution
|
|
98
|
+
executeAndProcessCommand()
|
|
99
|
+
.then(() => console.log("Command executed successfully."))
|
|
100
|
+
.catch((error) => console.error("Error executing command:", error));
|
|
101
|
+
}
|
|
102
|
+
/* v8 ignore end */
|
package/package.json
CHANGED
|
@@ -1,12 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ldx",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "ldx.js",
|
|
5
|
+
"bin": {
|
|
6
|
+
"ldx": "ldx.js"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/leog/ldx.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"transform",
|
|
14
|
+
"output",
|
|
15
|
+
"logging",
|
|
16
|
+
"developer",
|
|
17
|
+
"experience",
|
|
18
|
+
"dx"
|
|
19
|
+
],
|
|
20
|
+
"files": [
|
|
21
|
+
"package.json",
|
|
22
|
+
"ldx.js",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Leo Giovanetti",
|
|
27
|
+
"email": "hello@leog.me",
|
|
28
|
+
"url": "https://x.com/leog"
|
|
7
29
|
},
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
30
|
+
"license": "Apache-2.0",
|
|
31
|
+
"description": "Enhancing logging developer experience",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@vitest/coverage-v8": "3.0.9",
|
|
34
|
+
"mock-require": "^3.0.3",
|
|
35
|
+
"vitest": "^3.0.9"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"test": "vitest --coverage"
|
|
39
|
+
}
|
|
40
|
+
}
|