@idomatic/core 1.0.6 → 1.0.7

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 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(config);
13
+ await runInitScan();
19
14
  } else {
20
15
  console.log("Only --init-scan is supported in MVP for now.");
21
16
  }
@@ -1,10 +1,12 @@
1
- import ignoredFiles from "./ignoredFiles.js";
1
+ import excludeFiles from "./excludeFiles.js";
2
2
 
3
3
  const defaultConfig = {
4
+ attributeName: "id",
4
5
  prefix: "auto-id-",
5
- skipTags: [],
6
- extensions: ["js", "jsx", "ts", "tsx"],
7
- ignoreFiles: ignoredFiles,
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;
@@ -1,4 +1,4 @@
1
- const ignoredFiles = [
1
+ const excludeFiles = [
2
2
  "node_modules",
3
3
  "bun_modules",
4
4
  ".next",
@@ -11,4 +11,4 @@ const ignoredFiles = [
11
11
  "public",
12
12
  ];
13
13
 
14
- export default ignoredFiles;
14
+ export default excludeFiles;
package/lib/core.js CHANGED
@@ -1,3 +1,4 @@
1
+ // core.js
1
2
  import path from "path";
2
3
  import { pathToFileURL } from "url";
3
4
  import resolveFrom from "resolve-from";
@@ -22,15 +23,8 @@ export async function processFile(filePath, config) {
22
23
  }
23
24
 
24
25
  try {
25
- // Resolve the package's path from the current working directory
26
26
  const resolvedPath = resolveFrom(process.cwd(), parserPackage);
27
- console.log(`Resolved ${parserPackage} to: ${resolvedPath}`);
28
-
29
- // Convert to a file URL for dynamic import
30
27
  const resolvedURL = pathToFileURL(resolvedPath).href;
31
- console.log(`Resolved URL: ${resolvedURL}`);
32
-
33
- // Dynamically import the parser module
34
28
  const parser = await import(resolvedURL);
35
29
  await parser.default(filePath, config);
36
30
  console.log(`✅ Updated: ${filePath}`);
@@ -38,6 +32,5 @@ export async function processFile(filePath, config) {
38
32
  console.error(
39
33
  `❌ Failed to load parser "${parserPackage}" for ${filePath}`
40
34
  );
41
- console.error(err);
42
35
  }
43
36
  }
@@ -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(config) {
5
- const patterns = config.extensions.map((ext) => `**/*.${ext}`);
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.ignoreFiles.map((dir) => `${dir}/**`),
11
+ ignore: config.excludeFiles.map((dir) => `${dir}/**`),
9
12
  });
10
13
 
11
14
  console.log(`📂 Found ${files.length} files. Scanning...`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idomatic/core",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "idomatic": "./bin/index.js"
package/utils/files.js CHANGED
@@ -1,4 +1,4 @@
1
- const normalizeIgnoreFiles = (input) => {
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 normalizeIgnoreFiles;
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;