redate-cli 0.3.0 → 0.3.1
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 +1 -1
- package/src/core.js +31 -21
- package/src/redate.js +1 -1
package/package.json
CHANGED
package/src/core.js
CHANGED
|
@@ -24,52 +24,62 @@ const fileHandlers = {
|
|
|
24
24
|
|
|
25
25
|
export async function redate(paths) {
|
|
26
26
|
const config = getConfig();
|
|
27
|
+
const result = {
|
|
28
|
+
totalFiles: 0,
|
|
29
|
+
processed: 0,
|
|
30
|
+
skippedNoDate: 0,
|
|
31
|
+
errors: []
|
|
32
|
+
};
|
|
27
33
|
|
|
28
34
|
for (const p of paths) {
|
|
29
35
|
if (!fs.existsSync(p)) {
|
|
30
|
-
|
|
36
|
+
result.errors.push(`Path does not exist: ${p}`);
|
|
31
37
|
continue;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
const stats = fs.statSync(p);
|
|
35
41
|
|
|
36
42
|
if (stats.isFile()) {
|
|
37
|
-
await processFile(p, config);
|
|
43
|
+
await processFile(p, config, result);
|
|
38
44
|
} else if (stats.isDirectory()) {
|
|
39
|
-
await processFiles(p, config);
|
|
45
|
+
await processFiles(p, config, result);
|
|
40
46
|
}
|
|
41
47
|
}
|
|
48
|
+
|
|
49
|
+
return result;
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
|
|
45
|
-
export async function processFiles(folderPath, config) {
|
|
46
|
-
if (!config
|
|
47
|
-
config = getConfig();
|
|
48
|
-
}
|
|
53
|
+
export async function processFiles(folderPath, config, result) {
|
|
54
|
+
if (!config) config = getConfig();
|
|
49
55
|
const files = fs.readdirSync(folderPath);
|
|
56
|
+
|
|
50
57
|
for (const file of files) {
|
|
51
58
|
const filePath = path.join(folderPath, file);
|
|
52
|
-
|
|
53
59
|
if (!fs.statSync(filePath).isFile()) continue;
|
|
54
60
|
|
|
55
|
-
await processFile(filePath, config);
|
|
61
|
+
await processFile(filePath, config, result);
|
|
56
62
|
}
|
|
57
63
|
}
|
|
64
|
+
export async function processFile(filePath, config, result) {
|
|
65
|
+
result.totalFiles += 1;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const date = await getDateFromFile(filePath);
|
|
69
|
+
if (!date) {
|
|
70
|
+
result.skippedNoDate += 1;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
58
73
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
config = getConfig();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const date = await getDateFromFile(filePath);
|
|
65
|
-
if (!date) return;
|
|
66
|
-
|
|
67
|
-
const originalName = path.basename(filePath);
|
|
68
|
-
const newFileName = formatFileName(date, originalName, config);
|
|
74
|
+
const originalName = path.basename(filePath);
|
|
75
|
+
const newFileName = formatFileName(date, originalName, config);
|
|
69
76
|
|
|
70
|
-
|
|
77
|
+
applyFileHandling(filePath, newFileName, config);
|
|
71
78
|
|
|
72
|
-
|
|
79
|
+
result.processed += 1;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
result.errors.push(`Error processing file ${filePath}: ${err.message}`);
|
|
82
|
+
}
|
|
73
83
|
}
|
|
74
84
|
function applyFileHandling(srcPath, newFileName, config) {
|
|
75
85
|
const dir = path.dirname(srcPath);
|