@m00nbyte/rollup-plugin-copy-assets 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/cjs/index.min.js +8 -0
- package/dist/es/index.min.js +8 -0
- package/dist/es/package.json +1 -0
- package/dist/index.d.ts +13 -0
- package/package.json +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 m00nbyte
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# rollup-plugin-copy-assets
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.org/package/@m00nbyte/rollup-plugin-copy-assets) [](https://www.npmjs.org/package/@m00nbyte/rollup-plugin-copy-assets)
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Copy files and directories with full control
|
|
10
|
+
- Multiple source and destination paths
|
|
11
|
+
- Concurrent operations with configurable limits
|
|
12
|
+
- Watch mode support for automatic re-copying
|
|
13
|
+
- Preserve or flatten directory structures
|
|
14
|
+
- Verbose logging options
|
|
15
|
+
- Overwrite control for existing files
|
|
16
|
+
- TypeScript support
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -D @m00nbyte/rollup-plugin-copy-assets
|
|
22
|
+
yarn add -D @m00nbyte/rollup-plugin-copy-assets
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
// rollup.config.js
|
|
29
|
+
import copy from '@m00nbyte/rollup-plugin-copy-assets';
|
|
30
|
+
|
|
31
|
+
export default {
|
|
32
|
+
plugins: [
|
|
33
|
+
copy([
|
|
34
|
+
{
|
|
35
|
+
source: 'src/favicon.ico',
|
|
36
|
+
destination: 'dist/favicon.ico'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
source: 'src/images',
|
|
40
|
+
destination: 'dist/assets/images'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
source: ['README.md', 'LICENSE'],
|
|
44
|
+
destination: ['dist', 'build']
|
|
45
|
+
}
|
|
46
|
+
])
|
|
47
|
+
]
|
|
48
|
+
};
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Advanced Configuration
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
// Using the options object format
|
|
55
|
+
export default {
|
|
56
|
+
plugins: [
|
|
57
|
+
copy({
|
|
58
|
+
assets: [
|
|
59
|
+
{
|
|
60
|
+
source: 'src/assets',
|
|
61
|
+
destination: ['dist/assets', 'public/assets']
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
source: ['src/fonts', 'src/icons'],
|
|
65
|
+
destination: 'dist/static'
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
verbose: true, // Enable detailed logging
|
|
69
|
+
overwrite: true, // Overwrite existing files
|
|
70
|
+
concurrency: 5, // Limit concurrent operations
|
|
71
|
+
flatten: false // Preserve directory structure
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## API Reference
|
|
78
|
+
|
|
79
|
+
The plugin accepts either an array of assets or a configuration object:
|
|
80
|
+
|
|
81
|
+
#### Array Format (Simple)
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
copy([{ source: 'src/file.txt', destination: 'dist/file.txt' }]);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Object Format (Advanced)
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
copy({
|
|
91
|
+
assets: [...],
|
|
92
|
+
verbose: boolean,
|
|
93
|
+
overwrite: boolean,
|
|
94
|
+
concurrency: number,
|
|
95
|
+
flatten: boolean
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Asset Object
|
|
100
|
+
|
|
101
|
+
| Property | Type | Required | Description |
|
|
102
|
+
| ----------- | ------------------ | -------- | ------------------------------------------------- |
|
|
103
|
+
| source | string \| string[] | Yes | Single file/directory or array of sources to copy |
|
|
104
|
+
| destination | string \| string[] | Yes | Single or multiple destination paths |
|
|
105
|
+
|
|
106
|
+
### Options
|
|
107
|
+
|
|
108
|
+
| Option | Type | Default | Description |
|
|
109
|
+
| ----------- | ------- | ------- | ------------------------------------------------------------------------- |
|
|
110
|
+
| verbose | boolean | true | Enable detailed console output |
|
|
111
|
+
| overwrite | boolean | true | Overwrite existing files at destination |
|
|
112
|
+
| concurrency | number | 10 | Maximum concurrent copy operations |
|
|
113
|
+
| flatten | boolean | false | Copy files directly to destination without preserving directory structure |
|
|
114
|
+
|
|
115
|
+
## Error Handling
|
|
116
|
+
|
|
117
|
+
The plugin is designed to be resilient:
|
|
118
|
+
|
|
119
|
+
- Missing source files are logged as warnings but don't stop the build
|
|
120
|
+
- Copy failures are logged but allow other operations to continue
|
|
121
|
+
- File permissions errors are caught and reported
|
|
122
|
+
|
|
123
|
+
## Best Practices
|
|
124
|
+
|
|
125
|
+
- Use absolute paths for clarity when working with nested directories
|
|
126
|
+
- Set appropriate concurrency based on your system capabilities (default 10)
|
|
127
|
+
- Enable verbose logging during development, disable in production
|
|
128
|
+
- Consider file size when setting concurrency for large files
|
|
129
|
+
- Test flatten behavior with your specific directory structure
|
|
130
|
+
|
|
131
|
+
## Performance Tips
|
|
132
|
+
|
|
133
|
+
- Higher concurrency values improve performance but use more system resources
|
|
134
|
+
- Use flatten: true when you don't need directory structure (faster)
|
|
135
|
+
- Copy entire directories instead of individual files when possible
|
|
136
|
+
- Consider file size when setting concurrency limits
|
|
137
|
+
|
|
138
|
+
## Contribution
|
|
139
|
+
|
|
140
|
+
Feel free to submit issues or pull requests.
|
|
141
|
+
|
|
142
|
+
## Like my work?
|
|
143
|
+
|
|
144
|
+
This project needs a :star: from you.
|
|
145
|
+
Don't forget to leave a star.
|
|
146
|
+
|
|
147
|
+
<a href="https://www.buymeacoffee.com/m00nbyte" target="_blank">
|
|
148
|
+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" width="217" height="60">
|
|
149
|
+
</a>
|
|
150
|
+
|
|
151
|
+
## [Changelog](CHANGELOG.md)
|
|
152
|
+
|
|
153
|
+
## [License](LICENSE)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Ⓒ 2026 m00nbyte
|
|
3
|
+
|
|
4
|
+
package: @m00nbyte/rollup-plugin-copy-assets
|
|
5
|
+
version: 1.0.3
|
|
6
|
+
date: Thu, 01 Jan 2026 14:19:44 GMT
|
|
7
|
+
*/
|
|
8
|
+
"use strict";var fs=require("fs-extra"),path=require("path"),module$1=require("module"),_documentCurrentScript="undefined"!=typeof document?document.currentScript:null;const rollup=module$1.createRequire("undefined"==typeof document?require("url").pathToFileURL(__filename).href:_documentCurrentScript&&_documentCurrentScript.src||new URL("index.min.js",document.baseURI).href)("rollup");function errorHandler(e){throw new Error(`@m00nbyte/rollup-plugin-copy-assets | ${e}`)}const copy=e=>{const o=Array.isArray(e),r=o?e:e.assets,t={verbose:!0,overwrite:!0,concurrency:10,flatten:!1},s=o?t:{...t,...e},[n=0,c=0]=rollup.VERSION.split(".").map(Number);0===n&&c<60&&errorHandler("Requires rollup 0.60.0 or higher.");const{verbose:a,overwrite:i,concurrency:l,flatten:p}=s;let u="";async function d(e,o,r,t){const s=path.resolve(r,o),n=""!==path.extname(o);let c;if(n)c=s;else if(p||t)c=t?s:path.join(s,path.basename(e));else{const o=path.relative(u||process.cwd(),e);c=path.join(s,o)}try{if(await fs.ensureDir(path.dirname(c)),i&&n&&await fs.pathExists(c)&&await fs.remove(c),await fs.copy(e,c,{overwrite:i}),!await fs.pathExists(c))throw new Error("Copy operation failed - target does not exist");a&&console.log(`\u2713 Copied: ${path.relative(process.cwd(),e)} \u2192 ${path.relative(process.cwd(),c)}`)}catch(o){const r=`Error copying ${e} to ${c}: ${o.message}`;a&&console.error(r)}}return{name:"copy-assets",options({input:e}){if(!e)return;let o;Array.isArray(e)?o=e[0]:"string"==typeof e?o=e:"object"==typeof e&&(o=Object.values(e)[0]),o&&(u=path.dirname(o),a&&console.log(`Base directory set to: ${u}`))},buildStart(){for(const{source:e}of r){const o=Array.isArray(e)?e:[e];for(const e of o)try{this.addWatchFile(e)}catch(e){}}},async generateBundle({file:e,dir:o}){const t=o||path.dirname(e);a&&console.log(`Output directory: ${t}`);const s=[];for(const{source:e,destination:o}of r){const r=Array.isArray(e)?e:[e],n=Array.isArray(o)?o:[o];for(const e of r)try{const o=await fs.stat(e).catch((()=>null));if(!o){a&&console.warn(`Source not found: ${e}`);continue}const r=o.isDirectory();p&&r&&a&&console.warn(`Flatten mode: Source directory "${e}" will be copied directly to destination`);for(const o of n)s.push({src:e,dest:o,outputDir:t,isDir:r})}catch(o){a&&console.error(`Error processing source ${e}: ${o.message}`)}}s.length>0?(a&&console.log(`Processing ${s.length} copy operations with concurrency: ${l}`),await async function(e,o){for(let r=0;r<e.length;r+=o){const t=e.slice(r,r+o);await Promise.all(t.map((e=>d(e.src,e.dest,e.outputDir,e.isDir))))}}(s,l),a&&console.log("All copy operations completed")):a&&console.log("No copy operations to process")},watchChange(e){a&&console.log(`File changed: ${e}`)}}};module.exports=copy;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Ⓒ 2026 m00nbyte
|
|
3
|
+
|
|
4
|
+
package: @m00nbyte/rollup-plugin-copy-assets
|
|
5
|
+
version: 1.0.3
|
|
6
|
+
date: Thu, 01 Jan 2026 14:19:44 GMT
|
|
7
|
+
*/
|
|
8
|
+
import o from"fs-extra";import e from"path";import{createRequire as r}from"module";const t=r(import.meta.url)("rollup"),s=r=>{const s=Array.isArray(r),n=s?r:r.assets,c={verbose:!0,overwrite:!0,concurrency:10,flatten:!1},i=s?c:{...c,...r},[a=0,l=0]=t.VERSION.split(".").map(Number);0===a&&l<60&&function(o){throw new Error("@m00nbyte/rollup-plugin-copy-assets | Requires rollup 0.60.0 or higher.")}();const{verbose:p,overwrite:u,concurrency:y,flatten:f}=i;let d="";async function m(r,t,s,n){const c=e.resolve(s,t),i=""!==e.extname(t);let a;if(i)a=c;else if(f||n)a=n?c:e.join(c,e.basename(r));else{const o=e.relative(d||process.cwd(),r);a=e.join(c,o)}try{if(await o.ensureDir(e.dirname(a)),u&&i&&await o.pathExists(a)&&await o.remove(a),await o.copy(r,a,{overwrite:u}),!await o.pathExists(a))throw new Error("Copy operation failed - target does not exist");p&&console.log(`\u2713 Copied: ${e.relative(process.cwd(),r)} \u2192 ${e.relative(process.cwd(),a)}`)}catch(o){const e=`Error copying ${r} to ${a}: ${o.message}`;p&&console.error(e)}}return{name:"copy-assets",options({input:o}){if(!o)return;let r;Array.isArray(o)?r=o[0]:"string"==typeof o?r=o:"object"==typeof o&&(r=Object.values(o)[0]),r&&(d=e.dirname(r),p&&console.log(`Base directory set to: ${d}`))},buildStart(){for(const{source:o}of n){const e=Array.isArray(o)?o:[o];for(const o of e)try{this.addWatchFile(o)}catch(o){}}},async generateBundle({file:r,dir:t}){const s=t||e.dirname(r);p&&console.log(`Output directory: ${s}`);const c=[];for(const{source:e,destination:r}of n){const t=Array.isArray(e)?e:[e],n=Array.isArray(r)?r:[r];for(const e of t)try{const r=await o.stat(e).catch((()=>null));if(!r){p&&console.warn(`Source not found: ${e}`);continue}const t=r.isDirectory();f&&t&&p&&console.warn(`Flatten mode: Source directory "${e}" will be copied directly to destination`);for(const o of n)c.push({src:e,dest:o,outputDir:s,isDir:t})}catch(o){p&&console.error(`Error processing source ${e}: ${o.message}`)}}c.length>0?(p&&console.log(`Processing ${c.length} copy operations with concurrency: ${y}`),await async function(o,e){for(let r=0;r<o.length;r+=e){const t=o.slice(r,r+e);await Promise.all(t.map((o=>m(o.src,o.dest,o.outputDir,o.isDir))))}}(c,y),p&&console.log("All copy operations completed")):p&&console.log("No copy operations to process")},watchChange(o){p&&console.log(`File changed: ${o}`)}}};export{s as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Asset {
|
|
2
|
+
source: string | string[];
|
|
3
|
+
destination: string | string[];
|
|
4
|
+
}
|
|
5
|
+
interface CopyPluginOptions {
|
|
6
|
+
assets: Asset[];
|
|
7
|
+
verbose?: boolean;
|
|
8
|
+
overwrite?: boolean;
|
|
9
|
+
concurrency?: number;
|
|
10
|
+
flatten?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare const copy: (config: Asset[] | CopyPluginOptions) => object;
|
|
13
|
+
export default copy;
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@m00nbyte/rollup-plugin-copy-assets",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Copies files and directories from multiple sources to several destinations",
|
|
5
|
+
"author": "m00nbyte <office@moonbyte.at>",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"rollup",
|
|
8
|
+
"plugin",
|
|
9
|
+
"rollup-plugin",
|
|
10
|
+
"copy",
|
|
11
|
+
"assets",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"main": "dist/cjs/index.min.js",
|
|
16
|
+
"module": "dist/es/index.min.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/es/index.min.js",
|
|
21
|
+
"default": "./dist/cjs/index.min.js"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18.12.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"start": "cross-env NODE_ENV=development rollup -c -w",
|
|
31
|
+
"build": "cross-env NODE_ENV=production rollup -c",
|
|
32
|
+
"deploy": "yarn build && yarn publish",
|
|
33
|
+
"test": "yarn build && npx mocha test"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"url": "git+ssh://git@github.com/m00nbyte/rollup-plugin-copy-assets.git"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/m00nbyte/rollup-plugin-copy-assets#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/m00nbyte/rollup-plugin-copy-assets/issues"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@rollup/pluginutils": "^5.1.0",
|
|
47
|
+
"fs-extra": "^11.2.0",
|
|
48
|
+
"path": "^0.12.7",
|
|
49
|
+
"rollup": "^4.18.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@babel/core": "^7.24.6",
|
|
53
|
+
"@babel/eslint-parser": "^7.24.6",
|
|
54
|
+
"@babel/plugin-external-helpers": "^7.24.6",
|
|
55
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
56
|
+
"@babel/plugin-proposal-decorators": "^7.24.6",
|
|
57
|
+
"@babel/plugin-proposal-do-expressions": "^7.24.6",
|
|
58
|
+
"@babel/plugin-proposal-export-default-from": "^7.24.6",
|
|
59
|
+
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
|
|
60
|
+
"@babel/plugin-proposal-function-bind": "^7.24.6",
|
|
61
|
+
"@babel/plugin-proposal-function-sent": "^7.24.6",
|
|
62
|
+
"@babel/plugin-proposal-json-strings": "^7.18.6",
|
|
63
|
+
"@babel/plugin-proposal-logical-assignment-operators": "^7.20.7",
|
|
64
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
65
|
+
"@babel/plugin-proposal-numeric-separator": "^7.18.6",
|
|
66
|
+
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
67
|
+
"@babel/plugin-proposal-pipeline-operator": "^7.24.6",
|
|
68
|
+
"@babel/plugin-proposal-throw-expressions": "^7.24.6",
|
|
69
|
+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
70
|
+
"@babel/plugin-syntax-import-meta": "^7.10.4",
|
|
71
|
+
"@babel/preset-env": "^7.24.6",
|
|
72
|
+
"@babel/preset-typescript": "^7.24.6",
|
|
73
|
+
"@rollup-extras/plugin-clean": "^1.3.9",
|
|
74
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
75
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
76
|
+
"@rollup/plugin-dynamic-import-vars": "^2.1.2",
|
|
77
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
78
|
+
"@rollup/plugin-strip": "^3.0.4",
|
|
79
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
80
|
+
"@types/fs-extra": "^11.0.4",
|
|
81
|
+
"assert": "^2.1.0",
|
|
82
|
+
"async": "^3.2.6",
|
|
83
|
+
"cross-env": "^7.0.3",
|
|
84
|
+
"mocha": "^10.4.0",
|
|
85
|
+
"rollup": "^4.18.0",
|
|
86
|
+
"rollup-plugin-filesize": "^10.0.0",
|
|
87
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
88
|
+
"rollup-plugin-progress": "^1.1.2",
|
|
89
|
+
"rollup-plugin-strip-code": "^0.2.7",
|
|
90
|
+
"rollup-plugin-tsconfig-paths": "^1.5.2",
|
|
91
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
92
|
+
"rollup-plugin-visualizer": "^5.12.0",
|
|
93
|
+
"typescript": "^5.4.5"
|
|
94
|
+
}
|
|
95
|
+
}
|