@idomatic/core 1.1.61 → 1.1.62

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/package.json CHANGED
@@ -1,14 +1,34 @@
1
1
  {
2
2
  "name": "@idomatic/core",
3
- "version": "1.1.61",
3
+ "version": "1.1.62",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "idomatic": "./bin/index.js"
7
7
  },
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "./bin": "./bin/index.js"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "bin"
20
+ ],
21
+ "scripts": {
22
+ "clean": "rm -rf dist",
23
+ "build": "tsup src/index.ts --dts --format esm"
24
+ },
8
25
  "dependencies": {
9
26
  "globby": "^14.1.0",
10
27
  "resolve-from": "^5.0.0"
11
28
  },
29
+ "devDependencies": {
30
+ "tsup": "^7.2.0"
31
+ },
12
32
  "keywords": [
13
33
  "idomatic",
14
34
  "cli",
package/BUGS.MD DELETED
@@ -1 +0,0 @@
1
- 1. Generate unique id instead of incrementing
package/README.md DELETED
@@ -1,104 +0,0 @@
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
-
8
- Automatic ID Injection: Scans your project files and injects id attributes into components that are missing them.
9
-
10
- Configurable Behavior: Customize the prefix, specify file extensions, exclude certain tags, and more.
11
-
12
- Dry Run and Write Modes: Preview changes before actually updating your files.
13
-
14
- Framework Specific Defaults: Pre-populated configurations for React (JS/TSX) or HTML-based projects (HTML/Vue/Angular).
15
-
16
- Easy Integration: Use with your existing build or CI/CD processes.
17
-
18
- ## Installation
19
-
20
- To install idomatic, simply run the initializer command:
21
-
22
- ```shell
23
- npm init @idomatic
24
- ```
25
-
26
- This command will guide you through selecting your framework and automatically install the necessary configuration file and parser for your project. The default configuration file (e.g., .idomatic.config.json) will be created in your project's root.
27
-
28
- ## Usage
29
-
30
- CLI Commands
31
- After installation and configuration, you can run idomatic using the following commands:
32
-
33
- Dry Run: Preview the changes without modifying any files.
34
-
35
- ```shell
36
- npx idomatic scan --dry
37
- ```
38
-
39
- Write Mode: Apply the changes to your files.
40
-
41
- ```shell
42
- npx idomatic scan --write
43
- ```
44
-
45
- If you run npx idomatic scan without any flags, a usage message will be shown.
46
-
47
- Configuration File
48
- The configuration file .idomatic.config.json is created during the setup process. Here is an example configuration for a React project:
49
-
50
- ```js
51
- {
52
- "attributeName": "id",
53
- "prefix": "auto-id-",
54
- "excludeTags": ["html", "head", "script"],
55
- "includeExtensions": ["js", "jsx", "ts", "tsx"],
56
- "excludeFiles": []
57
- }
58
- ```
59
-
60
- 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"].
61
-
62
- ⚠️ Angular Users:
63
- It is recommended to use templateUrl with a separate .html file rather than defining inline templates in .ts files.
64
- idomatic processes external HTML templates correctly but does not support inline templates in Angular components. Using templateUrl ensures your component's HTML is picked up during scanning.
65
-
66
- ## How It Works
67
-
68
- Setup:
69
- Run the setup command (e.g npm init @idomatic) to choose your framework and create a configuration file.
70
-
71
- Scanning:
72
- The tool uses your configuration to search for files matching the specified extensions.
73
-
74
- Dry Run: Lists the files that would be processed without modifying them.
75
-
76
- Write Mode: Processes each file, adding id attributes where needed.
77
-
78
- Parsing:
79
- 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).
80
-
81
- ## Example
82
-
83
- Imagine you have a React component without an id attribute:
84
-
85
- ```js
86
- function Button() {
87
- return <button>Click me</button>;
88
- }
89
- ```
90
-
91
- After running idomatic in write mode, the component might be transformed to:
92
-
93
- ```js
94
- function Button() {
95
- return (
96
- <button id="auto-id-123e4567-e89b-12d3-a456-426614174000">Click me</button>
97
- );
98
- }
99
- ```
100
-
101
- The generated id includes a prefix (from the configuration) and a unique identifier.
102
-
103
- Contributing
104
- Contributions are welcome! Feel free to open issues or pull requests on GitHub.
@@ -1,12 +0,0 @@
1
- import excludeFiles from "./excludeFiles.js";
2
-
3
- const defaultConfig = {
4
- attributeName: "id",
5
- prefix: "auto-id-",
6
- // pattern: "[component]-[tag]-[index]",
7
- excludeTags: [], //html,head,script...
8
- includeExtensions: ["js", "jsx", "ts", "tsx"],
9
- excludeFiles: excludeFiles,
10
- };
11
-
12
- export default defaultConfig;
@@ -1,14 +0,0 @@
1
- const excludeFiles = [
2
- "node_modules",
3
- "bun_modules",
4
- ".next",
5
- "dist",
6
- "out",
7
- "build",
8
- ".git",
9
- ".vercel",
10
- ".turbo",
11
- "public",
12
- ];
13
-
14
- export default excludeFiles;
package/lib/core.js DELETED
@@ -1,35 +0,0 @@
1
- import path from "path";
2
- import { pathToFileURL } from "url";
3
- import resolveFrom from "resolve-from";
4
-
5
- const parserMap = {
6
- ".js": "@idomatic/parser-js",
7
- ".jsx": "@idomatic/parser-js",
8
- ".ts": "@idomatic/parser-js",
9
- ".tsx": "@idomatic/parser-js",
10
- ".html": "@idomatic/parser-html",
11
- ".vue": "@idomatic/parser-html",
12
- ".ng.html": "@idomatic/parser-html",
13
- };
14
-
15
- export async function processFile(filePath, config) {
16
- const ext = path.extname(filePath).toLowerCase();
17
- const parserPackage = parserMap[ext];
18
-
19
- if (!parserPackage) {
20
- console.warn(`⛔ Skipping unsupported file: ${filePath}`);
21
- return;
22
- }
23
-
24
- try {
25
- const resolvedPath = resolveFrom(process.cwd(), parserPackage);
26
- const resolvedURL = pathToFileURL(resolvedPath).href;
27
- const parser = await import(resolvedURL);
28
- await parser.default(filePath, config);
29
- console.log(`✅ Updated: ${filePath}`);
30
- } catch (err) {
31
- console.error(
32
- `❌ Failed to load parser "${parserPackage}" for ${filePath}`
33
- );
34
- }
35
- }
package/lib/readConfig.js DELETED
@@ -1,20 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- export default function getUserConfig() {
5
- const configFilePath = path.join(process.cwd(), ".idomatic.config.json");
6
-
7
- if (fs.existsSync(configFilePath)) {
8
- try {
9
- const configContent = fs.readFileSync(configFilePath, "utf-8");
10
- const userConfig = JSON.parse(configContent);
11
- return userConfig;
12
- } catch (err) {
13
- console.error(
14
- "Error reading the .idomatic.config.json file. Using default config."
15
- );
16
- }
17
- } else {
18
- console.warn("No .idomatic.config.json file found. Using default config.");
19
- }
20
- }
package/lib/scan.js DELETED
@@ -1,28 +0,0 @@
1
- import { globby } from "globby";
2
- import { processFile } from "./core.js";
3
- import getUserConfig from "./readConfig.js";
4
-
5
- async function runInitScan() {
6
- const config = getUserConfig();
7
-
8
- const patterns = config.includeExtensions.map((ext) => `**/*.${ext}`);
9
- const files = await globby(patterns, {
10
- gitignore: true,
11
- ignore: config.excludeFiles.map((dir) => `${dir}/**`),
12
- });
13
-
14
- console.log(`📂 Found ${files.length} files. Scanning...`);
15
-
16
- for (const file of files) {
17
- try {
18
- await processFile(file, config);
19
- console.log(`✅ Updated: ${file}`);
20
- } catch (e) {
21
- console.warn(`❌ Error in: ${file}`);
22
- }
23
- }
24
-
25
- console.log("🎉 Init scan complete!");
26
- }
27
-
28
- export default runInitScan;
package/lib/scanDry.js DELETED
@@ -1,27 +0,0 @@
1
- import { globby } from "globby";
2
- import { processFile } from "./core.js";
3
- import getUserConfig from "./readConfig.js";
4
-
5
- async function runInitScan() {
6
- const config = getUserConfig();
7
-
8
- const patterns = config.includeExtensions.map((ext) => `**/*.${ext}`);
9
- const files = await globby(patterns, {
10
- gitignore: true,
11
- ignore: config.excludeFiles.map((dir) => `${dir}/**`),
12
- });
13
-
14
- console.log(`📂 Found ${files.length} files. Scanning...`);
15
-
16
- for (const file of files) {
17
- try {
18
- console.log(`[Dry Run] Would process: ${file}`);
19
- } catch (e) {
20
- console.warn(`❌ Error in: ${file}`);
21
- }
22
- }
23
-
24
- console.log("🎉 Init scan complete!");
25
- }
26
-
27
- export default runInitScan;
package/utils/files.js DELETED
@@ -1,25 +0,0 @@
1
- const normalizeExcludeFiles = (input) => {
2
- if (
3
- !input ||
4
- input === "" ||
5
- (Array.isArray(input) && input.every((i) => i === ""))
6
- ) {
7
- return null;
8
- }
9
-
10
- const arr = Array.isArray(input)
11
- ? input
12
- : typeof input === "string"
13
- ? [input]
14
- : [];
15
-
16
- return arr
17
- .map((pattern) => {
18
- if (typeof pattern !== "string" || pattern.trim() === "") return null;
19
- if (pattern.includes("*")) return pattern;
20
- return `${pattern.replace(/\/+$/, "")}/**`;
21
- })
22
- .filter(Boolean);
23
- };
24
-
25
- export default normalizeExcludeFiles;