Skip to content

Commit

Permalink
Merge pull request #25 from CloudCannon/ignore-score-for-ignored-folders
Browse files Browse the repository at this point in the history
Ignore score for ignored folders
  • Loading branch information
rphillips-cc authored Oct 2, 2024
2 parents 1cbdf26 + 33de402 commit 9d44bc1
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 17 deletions.
83 changes: 66 additions & 17 deletions src/ssgs/ssg.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,15 @@ export default class Ssg {
* @returns {boolean}
*/
isConfigPath(filePath) {
return this.configPaths().some(
(configPath) => filePath === configPath || filePath.endsWith(`/${configPath}`),
);
const configPaths = this.configPaths();

for (let i = 0; i < configPaths.length; i++) {
if (filePath === configPaths[i] || filePath.endsWith(`/${configPaths[i]}`)) {
return true;
}
}

return false;
}

/**
Expand All @@ -242,11 +248,51 @@ export default class Ssg {
* @returns {number}
*/
getPathScore(filePath) {
if (this.isInIgnoredFolder(filePath)) {
return 0;
}

return this.isConfigPath(filePath) ? 1 : 0;
}

/**
* Checks if we should skip a file at this path
* Checks if a file at this path in inside an ignored folder.
*
* @param filePath {string}
* @returns {boolean}
*/
isInIgnoredFolder(filePath) {
const ignoredFolders = this.ignoredFolders();

for (let i = 0; i < ignoredFolders.length; i++) {
if (filePath.startsWith(ignoredFolders[i]) || filePath.includes(`/${ignoredFolders[i]}`)) {
return true;
}
}

return false;
}

/**
* Checks if a file at this path is ignored.
*
* @param filePath {string}
* @returns {boolean}
*/
isIgnoredFile(filePath) {
const ignoredFiles = this.ignoredFiles();

for (let i = 0; i < ignoredFiles.length; i++) {
if (filePath === ignoredFiles[i] || filePath.endsWith(`/${ignoredFiles[i]}`)) {
return true;
}
}

return false;
}

/**
* Checks if we should skip a file at this path.
*
* @param filePath {string}
* @returns {boolean}
Expand All @@ -256,10 +302,8 @@ export default class Ssg {
filePath.includes('.config.') ||
filePath.includes('/.') ||
filePath.startsWith('.') ||
this.ignoredFolders().some(
(folder) => filePath.startsWith(folder) || filePath.includes(`/${folder}`),
) ||
this.ignoredFiles().some((file) => filePath === file || filePath.endsWith(`/${file}`))
this.isInIgnoredFolder(filePath) ||
this.isIgnoredFile(filePath)
);
}

Expand All @@ -280,12 +324,19 @@ export default class Ssg {
* @returns {boolean}
*/
isPartialPath(filePath) {
return this.partialFolders().some(
(partialFolder) =>
filePath === partialFolder ||
filePath.includes(`/${partialFolder}`) ||
filePath.startsWith(partialFolder),
);
const partialFolders = this.partialFolders();

for (let i = 0; i < partialFolders.length; i++) {
if (
filePath === partialFolders[i] ||
filePath.includes(`/${partialFolders[i]}`) ||
filePath.startsWith(partialFolders[i])
) {
return true;
}
}

return false;
}

/**
Expand Down Expand Up @@ -507,9 +558,7 @@ export default class Ssg {
if (filePaths.includes('package.json')) {
const useYarn = filePaths.includes('yarn.lock');
const usePnpm = filePaths.includes('pnpm-lock.yaml');
const useNpm =
filePaths.includes('package-lock.json') ||
(!useYarn && !usePnpm);
const useNpm = filePaths.includes('package-lock.json') || (!useYarn && !usePnpm);

if (useNpm) {
commands.install.push({
Expand Down
25 changes: 25 additions & 0 deletions toolproof_tests/eleventy/not-hugo.toolproof.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Eleventy site not Hugo

steps:
- step: I have a "src/.github/ISSUE_TEMPLATE/config.yml" file with the content ""
- step: I have a "src/eleventy.config.js" file with the content ""
- ref: ./../core/run_gadget.toolproof.yml
- snapshot: stdout
snapshot_content: |-
╎{
╎ "ssg": "eleventy",
╎ "config": {
╎ "collections_config": {},
╎ "paths": {
╎ "static": "",
╎ "uploads": "uploads"
╎ },
╎ "timezone": "Pacific/Auckland",
╎ "markdown": {
╎ "engine": "commonmark",
╎ "options": {
╎ "html": true
╎ }
╎ }
╎ }
╎}

0 comments on commit 9d44bc1

Please sign in to comment.