diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f82ad0..f7f7cc5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - node-version: [14.x, 16.x, 18.x] + node-version: [14.x, 16.x, 18.x, 20.x] steps: - uses: actions/checkout@v2 diff --git a/help-me.js b/help-me.js index f730d7b..6a52bf0 100644 --- a/help-me.js +++ b/help-me.js @@ -2,8 +2,8 @@ const fs = require('fs') const { PassThrough, Writable, pipeline } = require('stream') -const glob = require('glob') const process = require('process') +const { join } = require('path') const defaults = { ext: '.txt', @@ -63,13 +63,17 @@ function helpMe (opts) { opts.dir = opts.dir.split('\\').join('/') } - glob(opts.dir + '/**/*' + opts.ext, function (err, files) { + fs.readdir(opts.dir, function (err, files) { if (err) return out.emit('error', err) + const regexp = new RegExp('.*' + opts.ext + '$') files = files - .map(function (file) { - const relative = file.replace(opts.dir, '').replace(/^\//, '') - return { file, relative } + .filter(function (file) { + const matched = file.match(regexp) + return !!matched + }) + .map(function (relative) { + return { file: join(opts.dir, relative), relative } }) .filter(function (file) { return file.relative.match(re) diff --git a/package.json b/package.json index 49e814c..939992d 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,5 @@ "tape": "^5.0.0" }, "dependencies": { - "glob": "^8.0.0", - "readable-stream": "^3.6.0" } } diff --git a/test.js b/test.js index acc8a62..eca9b28 100644 --- a/test.js +++ b/test.js @@ -209,38 +209,6 @@ test('custom help command with an array', function (t) { }) }) -test('support for help files organized in folders', function (t) { - const helper = helpMe({ - dir: 'fixture/dir' - }) - - t.test('passing an array', function (t) { - t.plan(2) - - helper - .createStream(['a', 'b']) - .pipe(concat(function (data) { - fs.readFile('fixture/dir/a/b.txt', function (err, expected) { - t.error(err) - t.equal(data.toString(), expected.toString()) - }) - })) - }) - - t.test('passing a string', function (t) { - t.plan(2) - - helper - .createStream('a b') - .pipe(concat(function (data) { - fs.readFile('fixture/dir/a/b.txt', function (err, expected) { - t.error(err) - t.equal(data.toString(), expected.toString()) - }) - })) - }) -}) - test('toStdout helper', async function (t) { t.plan(2)