@idomatic/core 1.1.1 → 1.1.3
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 +122 -0
- package/lib/readConfig.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
idomatic
|
|
2
|
+
idomatic is a CLI tool that automatically adds id attributes to your HTML/JSX/TSX components. It helps improve your testing and QA processes by ensuring that key elements always have unique, predictable identifiers.
|
|
3
|
+
|
|
4
|
+
Note: idomatic is optimized for React and HTML-based projects (including Vue and Angular). You can choose your framework during setup, and the tool will create a default configuration accordingly.
|
|
5
|
+
|
|
6
|
+
Features
|
|
7
|
+
Automatic ID Injection: Scans your project files and injects id attributes into components that are missing them.
|
|
8
|
+
|
|
9
|
+
Configurable Behavior: Customize the prefix, specify file extensions, exclude certain tags, and more.
|
|
10
|
+
|
|
11
|
+
Dry Run and Write Modes: Preview changes before actually updating your files.
|
|
12
|
+
|
|
13
|
+
Framework Specific Defaults: Pre-populated configurations for React (JS/TSX) or HTML-based projects (HTML/Vue/Angular).
|
|
14
|
+
|
|
15
|
+
Easy Integration: Use with your existing build or CI/CD processes.
|
|
16
|
+
|
|
17
|
+
Installation
|
|
18
|
+
You can install idomatic using your favorite package manager. For example:
|
|
19
|
+
|
|
20
|
+
bash
|
|
21
|
+
Copy
|
|
22
|
+
|
|
23
|
+
# Using npm
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
npm install --save-dev @idomatic/core`
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
# Using yarn
|
|
30
|
+
|
|
31
|
+
```shell
|
|
32
|
+
yarn add --dev @idomatic/core
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
# Using bun
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
bun add --dev @idomatic/core
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Additionally, if you haven't set up the configuration for idomatic, you can run the initializer:
|
|
42
|
+
|
|
43
|
+
```shell
|
|
44
|
+
npx idomatic --init
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This command will guide you through selecting your framework and create a default configuration file (.idomatic.config.json) in your project's root.
|
|
48
|
+
|
|
49
|
+
Usage
|
|
50
|
+
CLI Commands
|
|
51
|
+
After installation and configuration, you can run idomatic using the following commands:
|
|
52
|
+
|
|
53
|
+
Dry Run: Preview the changes without modifying any files.
|
|
54
|
+
|
|
55
|
+
```shell
|
|
56
|
+
npx idomatic scan --dry
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Write Mode: Apply the changes to your files.
|
|
60
|
+
|
|
61
|
+
```shell
|
|
62
|
+
npx idomatic scan --write
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
If you run npx idomatic scan without any flags, a usage message will be shown.
|
|
66
|
+
|
|
67
|
+
Configuration File
|
|
68
|
+
The configuration file .idomatic.config.json is created during the setup process. Here is an example configuration for a React project:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
{
|
|
72
|
+
"attributeName": "id",
|
|
73
|
+
"prefix": "auto-id-",
|
|
74
|
+
"excludeTags": ["html", "head", "script"],
|
|
75
|
+
"includeExtensions": ["js", "jsx", "ts", "tsx"],
|
|
76
|
+
"excludeFiles": []
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
You can customize these values to better suit your project’s needs. For HTML/Vue/Angular projects, the includeExtensions field will be set to ["html", "vue", "ng.html"].
|
|
81
|
+
|
|
82
|
+
How It Works
|
|
83
|
+
Setup:
|
|
84
|
+
Run the setup command (npx idomatic --init) to choose your framework and create a configuration file.
|
|
85
|
+
|
|
86
|
+
Scanning:
|
|
87
|
+
The tool uses your configuration to search for files matching the specified extensions.
|
|
88
|
+
|
|
89
|
+
Dry Run: Lists the files that would be processed without modifying them.
|
|
90
|
+
|
|
91
|
+
Write Mode: Processes each file, adding id attributes where needed.
|
|
92
|
+
|
|
93
|
+
Parsing:
|
|
94
|
+
Depending on the file type, idomatic imports the appropriate parser (@idomatic/parser-js for JavaScript/JSX/TSX or @idomatic/parser-html for HTML-based files) to modify your code using an Abstract Syntax Tree (AST).
|
|
95
|
+
|
|
96
|
+
Example
|
|
97
|
+
Imagine you have a React component without an id attribute:
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
function Button() {
|
|
101
|
+
return <button>Click me</button>;
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
After running idomatic in write mode, the component might be transformed to:
|
|
106
|
+
|
|
107
|
+
```js
|
|
108
|
+
function Button() {
|
|
109
|
+
return (
|
|
110
|
+
<button id="auto-id-123e4567-e89b-12d3-a456-426614174000">Click me</button>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The generated id includes a prefix (from the configuration) and a unique identifier.
|
|
116
|
+
|
|
117
|
+
Contributing
|
|
118
|
+
Contributions are welcome! Feel free to open issues or pull requests on GitHub.
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```
|
package/lib/readConfig.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
|
|
4
4
|
export default function getUserConfig() {
|
|
5
|
-
const configFilePath = path.join(process.cwd(), ".
|
|
5
|
+
const configFilePath = path.join(process.cwd(), ".idomatic.config.json");
|
|
6
6
|
|
|
7
7
|
if (fs.existsSync(configFilePath)) {
|
|
8
8
|
try {
|
|
@@ -11,10 +11,10 @@ export default function getUserConfig() {
|
|
|
11
11
|
return userConfig;
|
|
12
12
|
} catch (err) {
|
|
13
13
|
console.error(
|
|
14
|
-
"Error reading the .
|
|
14
|
+
"Error reading the .idomatic.config.json file. Using default config."
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
} else {
|
|
18
|
-
console.warn("No .
|
|
18
|
+
console.warn("No .idomatic.config.json file found. Using default config.");
|
|
19
19
|
}
|
|
20
20
|
}
|