@idomatic/core 1.1.62 → 1.1.63
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/lib/core.js +35 -0
- package/lib/readConfig.js +20 -0
- package/lib/scan.js +28 -0
- package/lib/scanDry.js +27 -0
- package/package.json +3 -19
package/lib/core.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,34 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idomatic/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.63",
|
|
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
8
|
"files": [
|
|
18
|
-
"
|
|
19
|
-
"
|
|
9
|
+
"bin",
|
|
10
|
+
"lib"
|
|
20
11
|
],
|
|
21
|
-
"scripts": {
|
|
22
|
-
"clean": "rm -rf dist",
|
|
23
|
-
"build": "tsup src/index.ts --dts --format esm"
|
|
24
|
-
},
|
|
25
12
|
"dependencies": {
|
|
26
13
|
"globby": "^14.1.0",
|
|
27
14
|
"resolve-from": "^5.0.0"
|
|
28
15
|
},
|
|
29
|
-
"devDependencies": {
|
|
30
|
-
"tsup": "^7.2.0"
|
|
31
|
-
},
|
|
32
16
|
"keywords": [
|
|
33
17
|
"idomatic",
|
|
34
18
|
"cli",
|