diff --git a/README.md b/README.md index 7fb8c0a..4ac8b03 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 15a6432..0c4e8b1 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -11,8 +11,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", @@ -136,9 +137,9 @@ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==" }, "node_modules/@types/node": { - "version": "18.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.0.tgz", - "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA==" + "version": "18.0.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.1.tgz", + "integrity": "sha512-CmR8+Tsy95hhwtZBKJBs0/FFq4XX7sDZHlGGf+0q+BRZfMbOTkzkj0AFAuTyXbObDIoanaBBW0+KEW+m3N16Wg==" }, "node_modules/@types/ps-tree": { "version": "1.1.2", @@ -490,6 +491,20 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/globby-cp": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/globby-cp/-/globby-cp-1.0.1.tgz", + "integrity": "sha512-rpn1OV5iBaWP/cXVfkz3UNWF27KtTsnbBsmPpQen8YgN9RGry3g6oQZgHiCfU1tjusHLQ5cQn0P6unL9Ruskgw==", + "dependencies": { + "fs-extra": "^10.1.0", + "globby": "^13.1.2", + "minimist": "^1.2.6" + }, + "bin": { + "gcp": "src/main/js/cli.js", + "globby-cp": "src/main/js/cli.js" + } + }, "node_modules/got": { "version": "11.8.5", "resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz", @@ -1267,9 +1282,9 @@ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==" }, "@types/node": { - "version": "18.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.0.tgz", - "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA==" + "version": "18.0.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.1.tgz", + "integrity": "sha512-CmR8+Tsy95hhwtZBKJBs0/FFq4XX7sDZHlGGf+0q+BRZfMbOTkzkj0AFAuTyXbObDIoanaBBW0+KEW+m3N16Wg==" }, "@types/ps-tree": { "version": "1.1.2", @@ -1525,6 +1540,16 @@ "slash": "^4.0.0" } }, + "globby-cp": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/globby-cp/-/globby-cp-1.0.1.tgz", + "integrity": "sha512-rpn1OV5iBaWP/cXVfkz3UNWF27KtTsnbBsmPpQen8YgN9RGry3g6oQZgHiCfU1tjusHLQ5cQn0P6unL9Ruskgw==", + "requires": { + "fs-extra": "^10.1.0", + "globby": "^13.1.2", + "minimist": "^1.2.6" + } + }, "got": { "version": "11.8.5", "resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz", diff --git a/package.json b/package.json index a07011b..9b4beb2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/main/js/goods.mjs b/src/main/js/goods.mjs index eabe44c..7443893 100644 --- a/src/main/js/goods.mjs +++ b/src/main/js/goods.mjs @@ -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' diff --git a/src/test/js/test.mjs b/src/test/js/test.mjs index 71e00ec..4c718c1 100644 --- a/src/test/js/test.mjs +++ b/src/test/js/test.mjs @@ -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 { @@ -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 ($) => {