Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #13: Updated runner.js to get files with a glob #14

Merged
merged 2 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions lib/runner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-underscore-dangle */
const fs = require('fs-extra');
const glob = require('glob');
const Path = require('path');
const readlineSync = require('readline-sync');
const util = require('util');
Expand All @@ -11,7 +12,6 @@ const log = require('fancy-log');
const cssRewrite = require('./processors/css').plugin;
const htmlRewrite = require('./processors/html').plugin;

const readdir = util.promisify(fs.readdir);
const stat = util.promisify(fs.stat);
const mkdir = util.promisify(fs.mkdirs);
const copy = util.promisify(fs.copy);
Expand All @@ -22,28 +22,21 @@ const regex = {
any: /(:?)/
};

const getFilesRecursive = async (path) => {
const getFiles = async (path) => {
const stats = await stat(path);

if (stats.isSymbolicLink()) {
return [];
}

if (stats && stats.isDirectory()) {
// TODO: this could be done with a glob and avoid the recursive call, and regex file checks.
const files = await readdir(path);

const promises = files.map((file) => {
const fullpath = Path.resolve(path, file);

return getFilesRecursive(fullpath);
});
const files = glob.sync(path.concat('/**/*.*'));

const promises = files.map((file) => Path.resolve(file));
const result = await Promise.all(promises);
const flattened = result.reduce((acc, val) => acc.concat(val), []);
return flattened;
}

return result;
}
return [path];
};

Expand Down Expand Up @@ -79,7 +72,7 @@ module.exports = {
other: []
};

const files = await getFilesRecursive(dir);
const files = await getFiles(dir);

const split = Math.max(_split || 1, 1);
const partitionNumber = Math.min(split, Math.max(_partitionNumber || 1, 1));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"del": "^6.0.0",
"fancy-log": "^1.3.3",
"fs-extra": "^8.1.0",
"glob": "^7.1.6",
"meow": "^7.1.1",
"path": "^0.12.7",
"readline-sync": "^1.4.10",
Expand Down