Skip to content

Commit

Permalink
Merge 5946d50 into 53a14be
Browse files Browse the repository at this point in the history
  • Loading branch information
hibes committed Aug 8, 2020
2 parents 53a14be + 5946d50 commit cb3baaf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@0ti.me/index-generator",
"version": "0.1.2",
"version": "0.1.3",
"description": "A library which provides tooling to generate an index.js file based on a configured file-path",
"license": "GPL-3.0",
"main": "src/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/lib/defaults.js
Expand Up @@ -3,6 +3,7 @@ const path = require('path');

module.exports = {
configFilePath: path.resolve(process.cwd(), 'config'),
filesMatchingPattern: /.*\.js$/,
indexFilename: 'index.js',
outputFilePath: (config) =>
path.resolve(
Expand Down
8 changes: 6 additions & 2 deletions src/lib/list-files-sync.js
@@ -1,14 +1,18 @@
const reduceToTypesSync = require('./reduce-to-types-sync');

module.exports = ({ directory }) => {
module.exports = ({ directory, filesMatchingRegex }) => {
const types = { directories: [directory], files: [] };

while (types.directories.length > 0) {
const currentDirectory = types.directories.pop();
const newTypes = reduceToTypesSync(currentDirectory);

types.directories = types.directories.concat(newTypes.directories);
types.files = types.files.concat(newTypes.files);
types.files = types.files.concat(
newTypes.files.filter((each) =>
new RegExp(filesMatchingRegex).test(each),
),
);
}

return types.files;
Expand Down
1 change: 1 addition & 0 deletions test/unit/lib/defaults.js
Expand Up @@ -11,6 +11,7 @@ d(me, () => {
expect(Object.keys(defaults).sort()).to.deep.equal(
[
'configFilePath',
'filesMatchingPattern',
'indexFilename',
'outputFilePath',
'overwrite',
Expand Down
5 changes: 3 additions & 2 deletions test/unit/lib/list-files-sync.js
@@ -1,4 +1,4 @@
const { d, expect, tquire } = deps;
const { d, expect, tquire, uuid } = deps;

const proxyquire = require('proxyquire').noPreserveCache().noCallThru();

Expand All @@ -24,7 +24,8 @@ d(me, () => {

describe('given a single folder with files', () => {
const args = { directory: Symbol() };
const files = [Symbol()];
const file = `${uuid()}.js`;
const files = [file];

const returnValue = {
directories: [],
Expand Down

0 comments on commit cb3baaf

Please sign in to comment.