-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·69 lines (64 loc) · 2.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
const { getAllFilesWithExtension, processFile, convertCsvToMarkdown } = require("./util/files");
const { cleanMarkdownLinks } = require("./util/modification");
const { cleanPath } = require("./util/paths");
const nodePath = require("path");
const sourceDir = process.argv[2];
const destDir = process.argv[3];
/**
* Checks if both a source and destination directory were provided.
*/
if (!sourceDir || !destDir) {
console.error("Usage: notion-export-cleaner <source_directory> <destination_directory>");
process.exit(1);
}
(async () => {
try {
// Process and copy all CSV files
const csvFiles = (await getAllFilesWithExtension(sourceDir, ".csv"))
.filter(path => !path.includes("_all.csv"));
csvFiles.forEach(path => {
const cleanedPath = path.replace(sourceDir, "");
console.log(`- ${cleanedPath}`);
const result = cleanPath(cleanedPath);
console.log("\x1b[31m%s\x1b[0m", `+ ${result}`);
convertCsvToMarkdown(
path,
nodePath.join(destDir, result),
);
});
// Process and copy all Markdown files
const markdownFiles = await getAllFilesWithExtension(sourceDir, ".md");
markdownFiles.forEach(path => {
const cleanedPath = path.replace(sourceDir, "");
console.log(`- ${cleanedPath}`);
const result = cleanPath(cleanedPath);
console.log("\x1b[33m%s\x1b[0m", `+ ${result}`);
processFile(
path,
nodePath.join(destDir, result),
[
cleanMarkdownLinks,
]
);
});
// Copy all other files
const otherFiles = (await getAllFilesWithExtension(sourceDir, null))
.filter(path => !path.includes(".csv") &&
!path.includes(".md") &&
!path.includes(".DSStore"));
otherFiles.forEach(path => {
const cleanedPath = path.replace(sourceDir, "");
console.log(`- ${cleanedPath}`);
const result = cleanPath(cleanedPath);
console.log("\x1b[32m%s\x1b[0m", `+ ${result}`);
processFile(
path,
nodePath.join(destDir, result),
[]
);
});
} catch (error) {
console.error("An error occurred:", error.message);
}
})();