Skip to content

Commit

Permalink
Expand ignored paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rphillips-cc committed Jun 13, 2024
1 parent 0554b2a commit 678e38f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
30 changes: 1 addition & 29 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,13 @@ const cli = meow(
},
);

/**
* Checks if we should skip a file at this path.
*
* @param filePath {string}
* @returns {boolean}
*/
function isIgnoredPath(filePath) {
return (
filePath.startsWith('.git/') ||
filePath === '.gitignore' ||
filePath.startsWith('.github/') ||
filePath.startsWith('.cloudcannon/') ||
filePath.startsWith('_cloudcannon/') ||
filePath.startsWith('cloudcannon.config.') ||
filePath.startsWith('node_modules/') ||
filePath.includes('/node_modules/') ||
filePath === 'README.md' ||
filePath === 'LICENSE' ||
filePath.endsWith('.DS_Store') ||
filePath.endsWith('.eslintrc.json') ||
filePath.endsWith('tsconfig.json') ||
filePath.endsWith('jsconfig.json') ||
filePath.endsWith('.prettierrc.json') ||
filePath.endsWith('package-lock.json') ||
filePath.endsWith('package.json')
);
}

const folderPath = cli.input[0];
if (!folderPath) {
console.error('⚠️ Please provide a folder path as input.');
cli.showHelp();
exit(1);
} else {
const crawler = new fdir().withRelativePaths().filter((filePath) => !isIgnoredPath(filePath));
const crawler = new fdir().withRelativePaths();
const filePaths = await crawler.crawl(folderPath).withPromise();
const config = await generate(filePaths, { readFile });

Expand Down
2 changes: 1 addition & 1 deletion src/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function generateCollectionsConfig(collectionPaths, source) {

for (let path of collectionPaths.paths) {
const sourcePath = stripTopPath(path, source);
const key = slugify(sourcePath) || 'pages';
const key = slugify(sourcePath, { separator: '_' }) || 'pages';
const name = titleize(
basename(sourcePath || key)
.replace(/[_-]/g, ' ')
Expand Down
3 changes: 3 additions & 0 deletions src/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const overrides = {
drafts: 'event',
draft: 'event',
data: 'data_usage',
authors: 'person',
staff: 'people',
staff_members: 'people',
};

/** @type {Array<import('@cloudcannon/configuration-types').Icon>} */
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function parseFiles(filePaths, ssg) {
}

/**
* Generates a baseline CLoudCannon configuration based on the file path provided.
* Generates a baseline CloudCannon configuration based on the file path provided.
*
* @param filePaths {string[]} List of input file paths.
* @param options {import('./types').GenerateOptions=} Options to aid generation.
Expand Down
35 changes: 33 additions & 2 deletions src/ssgs/ssg.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,32 @@ export default class Ssg {
* @returns {string[]}
*/
ignoredFolders() {
return [];
return ['.git/', '.github/', '.cloudcannon/', '_cloudcannon/', 'node_modules/'];
}

/**
* @returns {string[]}
*/
ignoredFiles() {
return [
'.DS_Store',
'.eslintrc.json',
'tsconfig.json',
'jsconfig.json',
'.prettierrc.json',
'package-lock.json',
'package.json',
'.gitignore',
'README',
'README.md',
'LICENSE',
'LICENSE.md',
'cloudcannon.config.cjs',
'cloudcannon.config.js',
'cloudcannon.config.json',
'cloudcannon.config.yml',
'cloudcannon.config.yaml',
];
}

/**
Expand Down Expand Up @@ -91,7 +116,13 @@ export default class Ssg {
* @returns {boolean}
*/
isIgnoredPath(filePath) {
return this.ignoredFolders().some((folder) => filePath.startsWith(folder));
return (
this.ignoredFolders().some(
(folder) => filePath.startsWith(folder) || filePath.includes(`/${folder}`),
) ||
this.ignoredFiles().some((file) => filePath === file || filePath.endsWith(`/${file}`)) ||
filePath.includes('.config.')
);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion test/utility.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ test('gets last element', (t) => {

test('strips top path', (t) => {
t.is(stripTopPath('src/content/index.html', 'src'), 'content/index.html');
t.is(stripTopPath('src/content/index.html', ''), 'src/content/index.html');
t.is(stripTopPath('src/index.html', 'src'), 'index.html');
t.is(stripTopPath('src/index.html', ''), 'src/index.html');
t.is(stripTopPath('src', 'src'), '');
t.is(stripTopPath('src', ''), 'src');
});

0 comments on commit 678e38f

Please sign in to comment.