@idomatic/core 1.0.6 → 1.0.8
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/bin/index.js +1 -6
- package/const/defaultConfig.js +6 -4
- package/const/ignoredFiles.js +2 -2
- package/lib/core.js +0 -8
- package/lib/readConfig.js +25 -0
- package/lib/scan.js +6 -3
- package/package.json +1 -1
- package/utils/files.js +2 -2
- package/lib/config.js +0 -22
package/bin/index.js
CHANGED
|
@@ -3,19 +3,14 @@
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import runInitScan from "../lib/scan.js";
|
|
6
|
-
import loadConfig from "../lib/config.js";
|
|
7
6
|
|
|
8
|
-
// Node.js doesn't provide __dirname in ESM, so we define it manually
|
|
9
7
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
8
|
|
|
12
9
|
const args = process.argv.slice(2);
|
|
13
10
|
const isInitScan = args.includes("--init-scan");
|
|
14
11
|
|
|
15
|
-
const config = await loadConfig();
|
|
16
|
-
|
|
17
12
|
if (isInitScan) {
|
|
18
|
-
await runInitScan(
|
|
13
|
+
await runInitScan();
|
|
19
14
|
} else {
|
|
20
15
|
console.log("Only --init-scan is supported in MVP for now.");
|
|
21
16
|
}
|
package/const/defaultConfig.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import excludeFiles from "./excludeFiles.js";
|
|
2
2
|
|
|
3
3
|
const defaultConfig = {
|
|
4
|
+
attributeName: "id",
|
|
4
5
|
prefix: "auto-id-",
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// pattern: "[component]-[tag]-[index]",
|
|
7
|
+
excludeTags: [], //html,head,script...
|
|
8
|
+
includeExtensions: ["js", "jsx", "ts", "tsx"],
|
|
9
|
+
excludeFiles: excludeFiles,
|
|
8
10
|
};
|
|
9
11
|
|
|
10
12
|
export default defaultConfig;
|
package/const/ignoredFiles.js
CHANGED
package/lib/core.js
CHANGED
|
@@ -22,15 +22,8 @@ export async function processFile(filePath, config) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
|
-
// Resolve the package's path from the current working directory
|
|
26
25
|
const resolvedPath = resolveFrom(process.cwd(), parserPackage);
|
|
27
|
-
console.log(`Resolved ${parserPackage} to: ${resolvedPath}`);
|
|
28
|
-
|
|
29
|
-
// Convert to a file URL for dynamic import
|
|
30
26
|
const resolvedURL = pathToFileURL(resolvedPath).href;
|
|
31
|
-
console.log(`Resolved URL: ${resolvedURL}`);
|
|
32
|
-
|
|
33
|
-
// Dynamically import the parser module
|
|
34
27
|
const parser = await import(resolvedURL);
|
|
35
28
|
await parser.default(filePath, config);
|
|
36
29
|
console.log(`✅ Updated: ${filePath}`);
|
|
@@ -38,6 +31,5 @@ export async function processFile(filePath, config) {
|
|
|
38
31
|
console.error(
|
|
39
32
|
`❌ Failed to load parser "${parserPackage}" for ${filePath}`
|
|
40
33
|
);
|
|
41
|
-
console.error(err);
|
|
42
34
|
}
|
|
43
35
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import defaultConfigs from "./defaultConfigs.js";
|
|
4
|
+
|
|
5
|
+
const defaultFallback = defaultConfigs.react;
|
|
6
|
+
|
|
7
|
+
export default function getUserConfig() {
|
|
8
|
+
const configFilePath = path.join(process.cwd(), ".idomaticsrc.json");
|
|
9
|
+
|
|
10
|
+
if (fs.existsSync(configFilePath)) {
|
|
11
|
+
try {
|
|
12
|
+
const configContent = fs.readFileSync(configFilePath, "utf-8");
|
|
13
|
+
const userConfig = JSON.parse(configContent);
|
|
14
|
+
return userConfig;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
console.error(
|
|
17
|
+
"Error reading the .idomaticsrc.json file. Using default config."
|
|
18
|
+
);
|
|
19
|
+
return defaultFallback;
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
console.warn("No .idomaticsrc.json file found. Using default config.");
|
|
23
|
+
return defaultFallback;
|
|
24
|
+
}
|
|
25
|
+
}
|
package/lib/scan.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { globby } from "globby";
|
|
2
2
|
import { processFile } from "./core.js";
|
|
3
|
+
import getUserConfig from "./readConfig.js";
|
|
3
4
|
|
|
4
|
-
async function runInitScan(
|
|
5
|
-
const
|
|
5
|
+
async function runInitScan() {
|
|
6
|
+
const config = getUserConfig();
|
|
7
|
+
|
|
8
|
+
const patterns = config.includeExtensions.map((ext) => `**/*.${ext}`);
|
|
6
9
|
const files = await globby(patterns, {
|
|
7
10
|
gitignore: true,
|
|
8
|
-
ignore: config.
|
|
11
|
+
ignore: config.excludeFiles.map((dir) => `${dir}/**`),
|
|
9
12
|
});
|
|
10
13
|
|
|
11
14
|
console.log(`📂 Found ${files.length} files. Scanning...`);
|
package/package.json
CHANGED
package/utils/files.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const normalizeExcludeFiles = (input) => {
|
|
2
2
|
if (
|
|
3
3
|
!input ||
|
|
4
4
|
input === "" ||
|
|
@@ -22,4 +22,4 @@ const normalizeIgnoreFiles = (input) => {
|
|
|
22
22
|
.filter(Boolean);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
export default
|
|
25
|
+
export default normalizeExcludeFiles;
|
package/lib/config.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import defaultConfig from "../const/defaultConfig.js";
|
|
4
|
-
import normalizeIgnoreFiles from "../utils/files.js";
|
|
5
|
-
|
|
6
|
-
async function loadConfig() {
|
|
7
|
-
const configPath = path.join(process.cwd(), ".idsrc.json");
|
|
8
|
-
|
|
9
|
-
if (fs.existsSync(configPath)) {
|
|
10
|
-
const userConfig = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
11
|
-
return {
|
|
12
|
-
...defaultConfig,
|
|
13
|
-
ignoreFiles:
|
|
14
|
-
normalizeIgnoreFiles(userConfig.ignoreFiles) ||
|
|
15
|
-
defaultConfig.ignoreFiles,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return defaultConfig;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default loadConfig;
|