Skip to content

Commit

Permalink
fix(cli): don't use folders for default HTML files in collect (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojizero authored Sep 17, 2020
1 parent c353ee8 commit 3d22230
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/cli/src/collect/fallback-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,29 @@ class FallbackServer {
* @return {Array<{file: string, depth: number}>}
*/
static readHtmlFilesInDirectory(directory, depth) {
const filesAndFolders = fs.readdirSync(directory);
const htmlFiles = filesAndFolders
.filter(file => file.endsWith('.html'))
.map(file => ({file, depth: 0}));
const filesAndFolders = fs.readdirSync(directory, {withFileTypes: true});

const files = filesAndFolders.filter(fileOrDir => fileOrDir.isFile()).map(file => file.name);
const folders = filesAndFolders
.filter(fileOrDir => fileOrDir.isDirectory())
.map(dir => dir.name);

const htmlFiles = files.filter(file => file.endsWith('.html')).map(file => ({file, depth: 0}));

if (depth === 0) return htmlFiles;

for (const fileOrFolder of filesAndFolders) {
for (const folder of folders) {
// Don't recurse into hidden folders, things that look like files, or dependency folders
if (fileOrFolder.includes('.')) continue;
if (IGNORED_FOLDERS_FOR_AUTOFIND.has(fileOrFolder)) continue;
if (folder.includes('.')) continue;
if (IGNORED_FOLDERS_FOR_AUTOFIND.has(folder)) continue;

try {
const fullPath = path.join(directory, fileOrFolder);
const fullPath = path.join(directory, folder);
if (!fs.statSync(fullPath).isDirectory()) continue;

htmlFiles.push(
...FallbackServer.readHtmlFilesInDirectory(fullPath, depth - 1).map(({file, depth}) => {
return {file: `${fileOrFolder}/${file}`, depth: depth + 1};
return {file: `${folder}/${file}`, depth: depth + 1};
})
);
} catch (err) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>autorun should not see this page</title>
</head>
<body>
test
</body>
</html>

0 comments on commit 3d22230

Please sign in to comment.