@idomatic/core 1.1.66 ā 1.1.68
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 +4 -6
- package/lib/core.js +6 -6
- package/lib/scan.js +13 -6
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import runInitScan from "../lib/scan.js";
|
|
3
|
-
import runInitScanDry from "../lib/scanDry.js";
|
|
4
3
|
|
|
5
4
|
const args = process.argv.slice(2);
|
|
5
|
+
const isDry = args[0] === "scan" && args[1] === "--dry";
|
|
6
6
|
|
|
7
|
-
if (args[0] === "scan"
|
|
8
|
-
await
|
|
9
|
-
} else if (args[0] === "scan") {
|
|
10
|
-
await runInitScan();
|
|
7
|
+
if (args[0] === "scan") {
|
|
8
|
+
await runInitScan(isDry);
|
|
11
9
|
} else {
|
|
12
|
-
console.log("Unsupported command
|
|
10
|
+
console.log("ā Unsupported command.\nš Use: 'scan' or 'scan --dry'");
|
|
13
11
|
}
|
package/lib/core.js
CHANGED
|
@@ -12,26 +12,26 @@ const parserMap = {
|
|
|
12
12
|
".ng.html": "@idomatic/parser-html",
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
export async function processFile(filePath, config) {
|
|
15
|
+
export async function processFile(filePath, config, dry = false) {
|
|
16
16
|
const ext = path.extname(filePath).toLowerCase();
|
|
17
17
|
const parserPackage = parserMap[ext];
|
|
18
18
|
|
|
19
19
|
if (!parserPackage) {
|
|
20
20
|
console.warn(`ā Skipping unsupported file: ${filePath}`);
|
|
21
|
-
return;
|
|
21
|
+
return false;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
try {
|
|
25
25
|
const resolvedPath = resolveFrom(process.cwd(), parserPackage);
|
|
26
26
|
const resolvedURL = pathToFileURL(resolvedPath).href;
|
|
27
27
|
const parser = await import(resolvedURL);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
28
|
+
|
|
29
|
+
const result = await parser.default(filePath, config, dry);
|
|
30
|
+
return result;
|
|
32
31
|
} catch (err) {
|
|
33
32
|
console.error(
|
|
34
33
|
`ā Failed to load parser "${parserPackage}" for ${filePath}`
|
|
35
34
|
);
|
|
35
|
+
return false;
|
|
36
36
|
}
|
|
37
37
|
}
|
package/lib/scan.js
CHANGED
|
@@ -2,7 +2,7 @@ import { globby } from "globby";
|
|
|
2
2
|
import { processFile } from "./core.js";
|
|
3
3
|
import getUserConfig from "./readConfig.js";
|
|
4
4
|
|
|
5
|
-
async function runInitScan() {
|
|
5
|
+
export default async function runInitScan(isDry = false) {
|
|
6
6
|
const config = getUserConfig();
|
|
7
7
|
|
|
8
8
|
const patterns = config.includeExtensions.map((ext) => `**/*.${ext}`);
|
|
@@ -11,17 +11,24 @@ async function runInitScan() {
|
|
|
11
11
|
ignore: config.excludeFiles.map((dir) => `${dir}/**`),
|
|
12
12
|
});
|
|
13
13
|
|
|
14
|
-
console.log(
|
|
14
|
+
console.log(
|
|
15
|
+
`š Found ${files.length} files. ${
|
|
16
|
+
isDry ? "Dry scanning..." : "Scanning..."
|
|
17
|
+
}`
|
|
18
|
+
);
|
|
15
19
|
|
|
16
20
|
for (const file of files) {
|
|
17
21
|
try {
|
|
18
|
-
await processFile(file, config);
|
|
22
|
+
const updated = await processFile(file, config, isDry);
|
|
23
|
+
if (updated) {
|
|
24
|
+
console.log(
|
|
25
|
+
`${isDry ? "[Dry Run] Would update" : "ā
Updated"}: ${file}`
|
|
26
|
+
);
|
|
27
|
+
}
|
|
19
28
|
} catch (e) {
|
|
20
|
-
console.warn(`ā Error in: ${file}
|
|
29
|
+
console.warn(`ā Error in: ${file}`, e);
|
|
21
30
|
}
|
|
22
31
|
}
|
|
23
32
|
|
|
24
33
|
console.log("š Init scan complete!");
|
|
25
34
|
}
|
|
26
|
-
|
|
27
|
-
export default runInitScan;
|