Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
rachfop committed May 2, 2024
1 parent e64c99d commit bfde1e7
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions src/Sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Repo {
this.repo = repo;
this.ref = ref;
this.filePaths = [];
this.usedRepos = new Set();
}
}
// File is the class that contains a filename and lines of the file
Expand Down Expand Up @@ -206,11 +207,11 @@ class Sync {
// Overwrite the files to the target directories
await this.writeFiles(splicedFiles);
// Delete the sync_repos directory
this.reportUnusedRepos(usedRepos);
await this.cleanUp();
this.progress.updateOperation("done");
this.progress.stop();
this.logger.info("snipsync operation complete");
this.reportUnusedRepos();
return;
}
// clear is the method that will remove snippets from target merge files
Expand Down Expand Up @@ -283,6 +284,21 @@ class Sync {
});
return result.data;
}
async reportUnusedRepos(usedRepos) {
const configRepos = new Set(
this.origins.map((origin) => `${origin.owner}/${origin.repo}`)
);
const unusedRepos = new Set(
[...configRepos].filter((repo) => !usedRepos.has(repo))
);
if (unusedRepos.size > 0) {
this.logger.warn("Unused repositories:");
for (const repo of unusedRepos) {
this.logger.warn(`- ${repo}`);
}
}
}
// extractSnippets returns an array of code snippets that are found in the repositories
async extractSnippets(repositories, usedRepos) {
const snippets = [];
this.progress.updateOperation("extracting snippets");
Expand All @@ -291,6 +307,9 @@ class Sync {
this.progress.updateTotal(filePaths.length);
const extractRootPath = join(rootDir, extractionDir);
for (const item of filePaths) {
if (fileSnips.length > 0) {
usedRepos.add(`${owner}/${repo}`);
}
const ext = determineExtension(item.name);
let itemPath = join(item.directory, item.name);
if (rtype == "remote") {
Expand All @@ -314,16 +333,27 @@ class Sync {
fileSnips.push(snip);
}
});
if (fileSnips.length > 0) {
usedRepos.add(`${owner}/${repo}`);
}
snippets.push(...fileSnips);
this.progress.increment();
}
})
);
return snippets;
}
reportUnusedRepos(usedRepos) {
const configRepos = new Set(
this.origins.map((origin) => `${origin.owner}/${origin.repo}`)
);
const unusedRepos = new Set(
[...configRepos].filter((repo) => !usedRepos.has(repo))
);
if (unusedRepos.size > 0) {
this.logger.warn("Unused repositories:");
for (const repo of unusedRepos) {
this.logger.warn(`- ${repo}`);
}
}
}
// getTargetFilesInfos identifies the paths to the target write files
async getTargetFilesInfos() {
this.progress.updateOperation("gathering information of target files");
Expand Down Expand Up @@ -457,20 +487,6 @@ class Sync {
}
return;
}
reportUnusedRepos() {
const configRepos = new Set(
this.origins.map((origin) => `${origin.owner}/${origin.repo}`)
);
const unusedRepos = new Set(
[...configRepos].filter((repo) => !this.usedRepos.has(repo))
);
if (unusedRepos.size > 0) {
this.logger.warn("Unused repositories:");
for (const repo of unusedRepos) {
this.logger.warn(`- ${repo}`);
}
}
}
// cleanUp deletes temporary files and folders
async cleanUp() {
this.progress.updateOperation("cleaning up");
Expand Down

0 comments on commit bfde1e7

Please sign in to comment.