Skip to content

Commit

Permalink
Drop glob (#19)
Browse files Browse the repository at this point in the history
* Drop glob

Signed-off-by: Matteo Collina <hello@matteocollina.com>

* Add Node v20

Signed-off-by: Matteo Collina <hello@matteocollina.com>

---------

Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina authored Dec 13, 2023
1 parent e23b2ea commit 718eb83
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions help-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@
"tape": "^5.0.0"
},
"dependencies": {
"glob": "^8.0.0",
"readable-stream": "^3.6.0"
}
}
32 changes: 0 additions & 32 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 718eb83

Please sign in to comment.