@uxf/scripts 11.28.2 → 11.32.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/package.json +4 -4
- package/src/GitLab.js +1 -1
- package/src/shared/load-page-imports.js +13 -3
- package/src/uxf-unused/cli.js +3 -2
- package/src/uxf-unused/index.js +39 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/scripts",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.32.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"author": "",
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"axios": "1.
|
|
31
|
-
"cheerio": "1.0.0
|
|
32
|
-
"dayjs": "1.11.
|
|
30
|
+
"axios": "1.7.5",
|
|
31
|
+
"cheerio": "1.0.0",
|
|
32
|
+
"dayjs": "1.11.13",
|
|
33
33
|
"fast-glob": "3.3.2",
|
|
34
34
|
"madge": "8.0.0",
|
|
35
35
|
"yargs": "17.7.2"
|
package/src/GitLab.js
CHANGED
|
@@ -5,7 +5,14 @@ const fs = require("fs");
|
|
|
5
5
|
|
|
6
6
|
function getTSConfig() {
|
|
7
7
|
const tsConfigPath = path.resolve(process.cwd(), "tsconfig.json");
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
if (fs.existsSync(tsConfigPath)) {
|
|
10
|
+
console.log("TS config loaded: " + tsConfigPath);
|
|
11
|
+
return tsConfigPath;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
console.log("TS config not found.");
|
|
15
|
+
return undefined;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
function getTree(subtree, tree, destination, viewedFiles = []) {
|
|
@@ -33,7 +40,7 @@ function getTree(subtree, tree, destination, viewedFiles = []) {
|
|
|
33
40
|
}
|
|
34
41
|
|
|
35
42
|
module.exports = function loadPageImports(directory, fileExtensions = ["ts", "tsx"]) {
|
|
36
|
-
const pages = fg.sync(directory);
|
|
43
|
+
const pages = fg.sync(directory).map(path.normalize);
|
|
37
44
|
|
|
38
45
|
return madge(process.cwd(), { tsConfig: getTSConfig(), fileExtensions }).then((res) => {
|
|
39
46
|
const tree = res.obj();
|
|
@@ -42,7 +49,10 @@ module.exports = function loadPageImports(directory, fileExtensions = ["ts", "ts
|
|
|
42
49
|
const filesOnPath = [];
|
|
43
50
|
getTree([currentValue], tree, filesOnPath);
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
const uniqueImports = Array.from(new Set(filesOnPath.flat(Number.POSITIVE_INFINITY)));
|
|
53
|
+
uniqueImports.sort();
|
|
54
|
+
|
|
55
|
+
previousValue[currentValue] = uniqueImports;
|
|
46
56
|
|
|
47
57
|
return previousValue;
|
|
48
58
|
}, {});
|
package/src/uxf-unused/cli.js
CHANGED
|
@@ -10,18 +10,19 @@ module.exports = async () => {
|
|
|
10
10
|
.option("p", { alias: "pagesDirectory", default: "src/pages/**/*.(ts|tsx)" })
|
|
11
11
|
.option("f", { alias: "allFilesDirectory", default: "src/**/*.(ts|tsx)" })
|
|
12
12
|
.option("r", { alias: "removeFiles", boolean: true, default: false })
|
|
13
|
+
.option("d", { alias: "debug", boolean: true, default: false })
|
|
13
14
|
.option("h", { alias: "help" })
|
|
14
15
|
.strict(false)
|
|
15
16
|
.exitProcess(false);
|
|
16
17
|
|
|
17
18
|
try {
|
|
18
|
-
const { help, pagesDirectory, allFilesDirectory, removeFiles } = cli.parse(argv.slice(2));
|
|
19
|
+
const { help, pagesDirectory, allFilesDirectory, removeFiles, debug } = cli.parse(argv.slice(2));
|
|
19
20
|
|
|
20
21
|
if (Boolean(help)) {
|
|
21
22
|
return 0;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
await require("./index")(pagesDirectory, allFilesDirectory, removeFiles);
|
|
25
|
+
await require("./index")(pagesDirectory, allFilesDirectory, removeFiles, debug);
|
|
25
26
|
} catch (e) {
|
|
26
27
|
console.error(e);
|
|
27
28
|
return 1;
|
package/src/uxf-unused/index.js
CHANGED
|
@@ -8,22 +8,52 @@ function unique(value, index, array) {
|
|
|
8
8
|
return array.indexOf(value) === index;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
async function main(pagesDirectory, allFilesDirectory, shouldRemoveFiles) {
|
|
11
|
+
async function main(pagesDirectory, allFilesDirectory, shouldRemoveFiles, isDebug = false) {
|
|
12
12
|
const pageImports = await loadPageImports(pagesDirectory);
|
|
13
13
|
|
|
14
|
+
if (isDebug) {
|
|
15
|
+
fs.writeFileSync(
|
|
16
|
+
path.resolve(process.cwd(), "uxf-unused-1-page-imports.json"),
|
|
17
|
+
JSON.stringify(pageImports, null, " "),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
const pages = Object.keys(pageImports);
|
|
15
22
|
|
|
16
23
|
const usedFiles = Object.values(pageImports).flat().filter(unique).map(path.normalize);
|
|
24
|
+
|
|
25
|
+
if (isDebug) {
|
|
26
|
+
fs.writeFileSync(
|
|
27
|
+
path.resolve(process.cwd(), "uxf-unused-2-used-files.json"),
|
|
28
|
+
JSON.stringify(usedFiles, null, " "),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
const allFiles = fg.sync(allFilesDirectory).map(path.normalize);
|
|
18
33
|
|
|
19
|
-
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
if (isDebug) {
|
|
35
|
+
fs.writeFileSync(
|
|
36
|
+
path.resolve(process.cwd(), "uxf-unused-3-all-files.json"),
|
|
37
|
+
JSON.stringify(allFiles, null, " "),
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const unusedFiles = allFiles.filter((e) => !usedFiles.includes(e) && !pages.includes(e));
|
|
42
|
+
unusedFiles.sort();
|
|
43
|
+
|
|
44
|
+
if (isDebug) {
|
|
45
|
+
fs.writeFileSync(
|
|
46
|
+
path.resolve(process.cwd(), "uxf-unused-4-unused-files.json"),
|
|
47
|
+
JSON.stringify(unusedFiles, null, " "),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
unusedFiles.forEach((unusedFile) => {
|
|
52
|
+
if (shouldRemoveFiles) {
|
|
53
|
+
fs.rmSync(unusedFile);
|
|
54
|
+
}
|
|
55
|
+
console.log(unusedFile);
|
|
56
|
+
});
|
|
27
57
|
}
|
|
28
58
|
|
|
29
59
|
module.exports = main;
|