-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtractorDir.js
61 lines (54 loc) · 1.82 KB
/
ExtractorDir.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
// Load modules
const Extractor = require('./Extractor');
const FileExtractor = require('./ExtractorFile');
const fs = require('fs');
class DirExtractor extends Extractor {
constructor(chatSession) {
super(chatSession);
}
extract(path, recursive = true) {
try {
const files = fs.readdirSync(path);
for (const file of files) {
if (
(file !== 'node_modules') &&
(file !== 'temp') &&
(file !== 'archive') &&
(file !== 'ideas') &&
(file !== 'charts') &&
(file !== 'chats') &&
(file !== 'package-lock.json') &&
(file !== '.idea') &&
(file !== '.gitignore') &&
(file !== '.git') &&
(file !== '.terraform') &&
(file !== '.editorconfig') &&
(file !== '.pre-commit-config.yaml') &&
(file !== '.releaserc.json') &&
(file !== 'CHANGELOG.md') &&
(file !== 'LICENSE')
) {
const filePath = path + '/' + file;
const stats = fs.statSync(filePath);
if (stats.isDirectory() && recursive) {
this.extract(filePath);
}
else if (stats.isFile()) {
const messageLog = new FileExtractor(this.chatSession).extract(filePath);
// Push the file to the message log
if (messageLog !== null) {
this.addMessageToTempMessageLog(filePath);
this.tempMessageLog.push(...messageLog);
// Append message to chat file
this.chatSession.appendMessageToFile('\n- ' + filePath + '\n');
}
}
}
}
return this.tempMessageLog;
} catch (error) {
throw new Error(`\nFailed to extract text from directory: ${error.message}\n`);
}
}
}
module.exports = DirExtractor;