Skip to content

Commit

Permalink
feat: add copy helper
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jul 5, 2022
1 parent ce2d345 commit 21457f3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ temporaryFile() // '/private/var/folders/p0/p7xckky93s30rshd51gs4pdc0000gn
temporaryDirectory() // '/private/var/folders/p0/p7xckky93s30rshd51gs4pdc0000gn/T/1b7e9277860eb90b94aad816d4f66f8e'
```

### `copy`
Provides [`globby`-boosted copying API](https://github.com/antongolub/globby-cp).
```js
import {copy} from 'zx-extra'

await copy({
from: 'src/**/*.js',
to: 'dist/',
baseFrom, // process.cwd()
baseTo, // process.cwd(),
debug, // () => {}
ignoreFiles // undefined
})
```

### `ctx`
[async_hooks](https://nodejs.org/api/async_hooks.html)-driven scope isolator.
Creates a separate zx-context for the specified function.
Expand Down
39 changes: 32 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
"dependencies": {
"@qiwi/deep-proxy": "^2.0.2",
"@types/ip": "^1.1.0",
"@types/node": "^18.0.0",
"@types/node": "^18.0.1",
"@types/semver": "^7.3.10",
"globby-cp": "^1.0.1",
"ip": "^1.1.8",
"is-reachable": "^5.2.1",
"npm-run-path": "^5.1.0",
Expand Down
1 change: 1 addition & 0 deletions src/main/js/goods.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * as tempy from 'tempy'
export { default as ip } from 'ip'
export { semver } from './semver.mjs'
export { default as tcping } from 'is-reachable'
export { copy } from 'globby-cp'
14 changes: 13 additions & 1 deletion src/test/js/test.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {strict as assert} from 'node:assert'
import {$, semver, createHook, ip, tempy, tcping, sleep, ctx} from '../../main/js/index.mjs'
import {$, semver, createHook, ip, tempy, tcping, sleep, ctx, copy, fs, path} from '../../main/js/index.mjs'

// $.raw
{
Expand Down Expand Up @@ -123,6 +123,18 @@ import {$, semver, createHook, ip, tempy, tcping, sleep, ctx} from '../../main/j
assert(!(await tcping('unknown:1234')))
}

// copy
{
const from = tempy.temporaryDirectory()
const to = tempy.temporaryDirectory()
const footxt = path.resolve(from, 'foo.txt')

await fs.outputFile(footxt, 'foo')

await copy({from: footxt, to})
assert.equal((await fs.readFile(path.resolve(to, 'foo.txt'))).toString('utf-8').trim(), 'foo')
}

// ctx()
{
await ctx(async ($) => {
Expand Down

0 comments on commit 21457f3

Please sign in to comment.