{"id":715,"url":"https://github.com/sindresorhus/cpy","last_synced_at":"2025-05-14T18:05:18.793Z","repository":{"id":18192306,"uuid":"21312138","full_name":"sindresorhus/cpy","owner":"sindresorhus","description":"Copy files","archived":false,"fork":false,"pushed_at":"2024-07-26T15:25:18.000Z","size":132,"stargazers_count":429,"open_issues_count":19,"forks_count":64,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-14T06:56:36.998Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-06-28T22:24:36.000Z","updated_at":"2025-05-08T02:23:25.000Z","dependencies_parsed_at":"2024-02-22T18:05:52.062Z","dependency_job_id":"5e1afddb-518c-474d-a637-83d17fe62e25","html_url":"https://github.com/sindresorhus/cpy","commit_stats":{"total_commits":122,"total_committers":30,"mean_commits":4.066666666666666,"dds":0.3688524590163934,"last_synced_commit":"cedf94cf7e222e9cd4e1df1ca87e4ef454126bc7"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/cpy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198514,"owners_count":22030965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:29.502Z","updated_at":"2025-05-14T18:05:13.785Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","JavaScript","Repository","Uncategorized","目录","Filesystem","包","Libraries"],"sub_categories":["Filesystem","Uncategorized","文件系统","Command-line apps","命令行程序"],"readme":"# cpy\n\n\u003e Copy files\n\n**IMPORTANT:** This package has a lot of problems and I unfortunately don't have time to fix them. I would recommend against using this package until these problems are resolved. Help welcome (see the issue tracker) 🙏\n\n## Why\n\n- Fast by [cloning](https://stackoverflow.com/questions/71629903/node-js-why-we-should-use-copyfile-ficlone-and-copyfile-ficlone-force-what-is) the files whenever possible.\n- Resilient by using [graceful-fs](https://github.com/isaacs/node-graceful-fs).\n- User-friendly by accepting [globs](https://github.com/sindresorhus/globby#globbing-patterns) and creating non-existent destination directories.\n- User-friendly error messages.\n- Progress reporting.\n\n## Install\n\n```sh\nnpm install cpy\n```\n\n## Usage\n\n```js\nimport cpy from 'cpy';\n\nawait cpy([\n\t'source/*.png', // Copy all .png files\n\t'!source/goat.png', // Ignore goat.png\n], 'destination');\n\n// Copy node_modules to destination/node_modules\nawait cpy('node_modules', 'destination');\n\n// Copy node_modules content to destination\nawait cpy('node_modules/**', 'destination');\n\n// Copy node_modules structure but skip all files except package.json files\nawait cpy('node_modules/**/*.json', 'destination');\n\n// Copy all png files into destination without keeping directory structure\nawait cpy('**/*.png', 'destination', {flat: true});\n\nconsole.log('Files copied!');\n```\n\n## API\n\n### cpy(source, destination, options?)\n\nReturns a `Promise\u003cstring[]\u003e` with the destination file paths.\n\n#### source\n\nType: `string | string[]`\n\nFiles to copy.\n\nIf any of the files do not exist, an error will be thrown (does not apply to globs).\n\n#### destination\n\nType: `string`\n\nDestination directory.\n\n#### options\n\nType: `object`\n\nOptions are passed to [globby](https://github.com/sindresorhus/globby#options).\n\nIn addition, you can specify the below options.\n\n##### cwd\n\nType: `string`\\\nDefault: `process.cwd()`\n\nWorking directory to find source files.\n\n##### overwrite\n\nType: `boolean`\\\nDefault: `true`\n\nOverwrite existing files.\n\n##### flat\n\nType: `boolean`\\\nDefault: `false`\n\nFlatten directory structure. All copied files will be put in the same directory.\n\n```js\nimport cpy from 'cpy';\n\nawait cpy('src/**/*.js', 'destination', {\n\tflat: true\n});\n```\n\n##### rename\n\nType: `string | Function`\n\nFilename or function returning a filename used to rename every file in `source`.\n\n```js\nimport cpy from 'cpy';\n\nawait cpy('foo.js', 'destination', {\n\t// The `basename` is the filename with extension.\n\trename: basename =\u003e `prefix-${basename}`\n});\n\nawait cpy('foo.js', 'destination', {\n\trename: 'new-name'\n});\n```\n\n##### concurrency\n\nType: `number`\\\nDefault: `(os.cpus().length || 1) * 2`\n\nNumber of files being copied concurrently.\n\n##### ignoreJunk\n\nType: `boolean`\\\nDefault: `true`\n\nIgnores [junk](https://github.com/sindresorhus/junk) files.\n\n##### filter\n\nType: `Function`\n\nFunction to filter files to copy.\n\nReceives a source file object as the first argument.\n\nReturn true to include, false to exclude. You can also return a Promise that resolves to true or false.\n\n```js\nimport cpy from 'cpy';\n\nawait cpy('foo', 'destination', {\n\tfilter: file =\u003e file.extension !== 'nocopy'\n});\n```\n\n##### Source file object\n\n###### path\n\nType: `string`\\\nExample: `'/tmp/dir/foo.js'`\n\nResolved path to the file.\n\n###### relativePath\n\nType: `string`\\\nExample: `'dir/foo.js'` if `cwd` was `'/tmp'`\n\nRelative path to the file from `cwd`.\n\n###### name\n\nType: `string`\\\nExample: `'foo.js'`\n\nFilename with extension.\n\n###### nameWithoutExtension\n\nType: `string`\\\nExample: `'foo'`\n\nFilename without extension.\n\n###### extension\n\nType: `string`\\\nExample: `'js'`\n\nFile extension.\n\n## Progress reporting\n\n### cpy.on('progress', handler)\n\n#### handler(progress)\n\nType: `Function`\n\n##### progress\n\n```js\n{\n\tcompletedFiles: number,\n\ttotalFiles: number,\n\tcompletedSize: number,\n\tpercent: number,\n\tsourcePath: string,\n\tdestinationPath: string,\n}\n```\n\n- `completedSize` is in bytes\n- `percent` is a value between `0` and `1`\n- `sourcePath` is the absolute source path of the current file being copied.\n- `destinationPath` is The absolute destination path of the current file being copied.\n\nNote that the `.on()` method is available only right after the initial `cpy` call, so make sure you add a `handler` before awaiting the promise:\n\n```js\nimport cpy from 'cpy';\n\nawait cpy(source, destination).on('progress', progress =\u003e {\n\t// …\n});\n```\n\n## Related\n\n- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - CLI for this module\n- [copy-file](https://github.com/sindresorhus/copy-file) - Copy a single file\n- [move-file](https://github.com/sindresorhus/move-file) - Move a file\n- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fcpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fcpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fcpy/lists"}