@idomatic/core 1.0.0
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/BUGS.MD +1 -0
- package/README.md +0 -0
- package/bin/index.js +21 -0
- package/const/defaultConfig.js +10 -0
- package/const/ignoredFiles.js +14 -0
- package/lib/config.js +22 -0
- package/lib/core.js +31 -0
- package/lib/scan.js +25 -0
- package/package.json +20 -0
- package/utils/files.js +25 -0
package/BUGS.MD
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1. Generate unique id instead of incrementing
|
package/README.md
ADDED
|
File without changes
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import runInitScan from "../lib/scan.js";
|
|
6
|
+
import loadConfig from "../lib/config.js";
|
|
7
|
+
|
|
8
|
+
// Node.js doesn't provide __dirname in ESM, so we define it manually
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
|
|
12
|
+
const args = process.argv.slice(2);
|
|
13
|
+
const isInitScan = args.includes("--init-scan");
|
|
14
|
+
|
|
15
|
+
const config = await loadConfig();
|
|
16
|
+
|
|
17
|
+
if (isInitScan) {
|
|
18
|
+
await runInitScan(config);
|
|
19
|
+
} else {
|
|
20
|
+
console.log("Only --init-scan is supported in MVP for now.");
|
|
21
|
+
}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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;
|
package/lib/core.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
const parserMap = {
|
|
4
|
+
".js": "@idomatic/parser-js",
|
|
5
|
+
".jsx": "@idomatic/parser-js",
|
|
6
|
+
".ts": "@idomatic/parser-js",
|
|
7
|
+
".tsx": "@idomatic/parser-js",
|
|
8
|
+
".html": "@idomatic/parser-html",
|
|
9
|
+
".vue": "@idomatic/parser-html",
|
|
10
|
+
".ng.html": "@idomatic/parser-html",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export async function processFile(filePath, config) {
|
|
14
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
15
|
+
const parserPackage = parserMap[ext];
|
|
16
|
+
|
|
17
|
+
if (!parserPackage) {
|
|
18
|
+
console.warn(`⛔ Skipping unsupported file: ${filePath}`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const parser = await import(parserPackage);
|
|
24
|
+
await parser.default(filePath, config);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error(
|
|
27
|
+
`❌ Failed to load parser "${parserPackage}" for ${filePath}`
|
|
28
|
+
);
|
|
29
|
+
console.error(err);
|
|
30
|
+
}
|
|
31
|
+
}
|
package/lib/scan.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { globby } from "globby";
|
|
2
|
+
import { processFile } from "./core.js";
|
|
3
|
+
|
|
4
|
+
async function runInitScan(config) {
|
|
5
|
+
const patterns = config.extensions.map((ext) => `**/*.${ext}`);
|
|
6
|
+
const files = await globby(patterns, {
|
|
7
|
+
gitignore: true,
|
|
8
|
+
ignore: config.ignoreFiles.map((dir) => `${dir}/**`),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
console.log(`📂 Found ${files.length} files. Scanning...`);
|
|
12
|
+
|
|
13
|
+
for (const file of files) {
|
|
14
|
+
try {
|
|
15
|
+
await processFile(file, config);
|
|
16
|
+
console.log(`✅ Updated: ${file}`);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.warn(`❌ Error in: ${file}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
console.log("🎉 Init scan complete!");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default runInitScan;
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@idomatic/core",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"idomatic": "./bin/index.js"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"globby": "^14.1.0"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"idomatic",
|
|
13
|
+
"cli",
|
|
14
|
+
"ids",
|
|
15
|
+
"precommit",
|
|
16
|
+
"parser"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Amar Smajlovic"
|
|
20
|
+
}
|
package/utils/files.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const normalizeIgnoreFiles = (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 normalizeIgnoreFiles;
|