Skip to content

Commit

Permalink
feat: pull in new globSource (#3889)
Browse files Browse the repository at this point in the history
* feat: pull in new globSource

The new globSource module has a simpler api.

Old:

```js
await ipfs.addAll(globSource('*', {
  recursive: true,
  cwd: './somedir'
})
```

New:

```js
await ipfs.addAll(globSource('./somedir', '**/*'))
```

See the [minimatch](https://www.npmjs.com/package/minimatch) docs for
more on what the pattern supports.

BREAKING CHANGE: the globSource api has changed from `globSource(dir, opts)` to `globSource(dir, pattern, opts)`
  • Loading branch information
achingbrain authored Sep 23, 2021
1 parent 3dcf3ec commit 32394c4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
- [Instance Utils](#instance-utils)
- [Static Types and Utils](#static-types-and-utils)
- [Glob source](#glob-source)
- [`globSource(path, [options])`](#globsourcepath-options)
- [`globSource(path, pattern, [options])`](#globsourcepath-pattern-options)
- [Example](#example-1)
- [URL source](#url-source)
- [`urlSource(url)`](#urlsourceurl)
Expand Down Expand Up @@ -182,25 +182,25 @@ import { CID } from 'ipfs-http-client'

A utility to allow files on the file system to be easily added to IPFS.

##### `globSource(path, [options])`
##### `globSource(path, pattern, [options])`

- `path`: A path to a single file or directory to glob from
- `pattern`: A pattern to match files under `path`
- `options`: Optional options
- `options.recursive`: If `path` is a directory, use option `{ recursive: true }` to add the directory and all its sub-directories.
- `options.ignore`: To exclude file globs from the directory, use option `{ ignore: ['ignore/this/folder/**', 'and/this/file'] }`.
- `options.hidden`: Hidden/dot files (files or folders starting with a `.`, for example, `.git/`) are not included by default. To add them, use the option `{ hidden: true }`.

Returns an async iterable that yields `{ path, content }` objects suitable for passing to `ipfs.add`.

##### Example

```js
import { create, globSource } from 'ipfs-http-client'
const ipfs = create()
import { create, globSource } from 'ipfs'

const file = await ipfs.add(globSource('./docs', { recursive: true }))
console.log(file)
const ipfs = await create()

for await (const file of ipfs.addAll(globSource('./docs', '**/*'))) {
console.log(file)
}
/*
{
path: 'docs/assets/anchor.js',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"err-code": "^3.0.1",
"ipfs-core-types": "^0.7.3",
"ipfs-core-utils": "^0.10.5",
"ipfs-utils": "^8.1.4",
"ipfs-utils": "^9.0.1",
"it-first": "^1.0.6",
"it-last": "^1.0.4",
"merge-options": "^3.0.4",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/* eslint-env browser */

import { Multibases } from 'ipfs-core-utils/multibases'
Expand Down Expand Up @@ -42,6 +41,7 @@ import { createResolve } from './resolve.js'
import { createStart } from './start.js'
import { createStop } from './stop.js'
import { createVersion } from './version.js'
import globSourceImport from 'ipfs-utils/src/files/glob-source.js'

/**
* @typedef {import('./types').EndpointConfig} EndpointConfig
Expand Down Expand Up @@ -142,5 +142,5 @@ export function create (options = {}) {

export { CID } from 'multiformats/cid'
export { Multiaddr as multiaddr } from 'multiaddr'
export { default as globSource } from 'ipfs-utils/src/files/glob-source.js'
export { default as urlSource } from 'ipfs-utils/src/files/url-source.js'
export const globSource = globSourceImport

0 comments on commit 32394c4

Please sign in to comment.