Skip to content

Commit 8d65633

Browse files
committed
init
1 parent a1ec162 commit 8d65633

File tree

20 files changed

+6326
-0
lines changed

20 files changed

+6326
-0
lines changed

.babelrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
['@babel/preset-env', { targets: { node: '8.3' } }]
4+
]
5+
}

.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
extends: 'airbnb-base',
3+
rules: {
4+
'comma-dangle': ['error', 'never'],
5+
'object-curly-newline': ['error', { multiline: true, consistent: true }],
6+
semi: ['error', 'never']
7+
},
8+
env: {
9+
jest: true
10+
}
11+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
coverage
3+
dist

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- 12
4+
- 10
5+
- 8
6+
script:
7+
- jest --ci --coverage && codecov

index.d.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import rollup from 'rollup';
2+
import fs from 'fs-extra';
3+
import globby from 'globby';
4+
5+
interface Target extends globby.GlobbyOptions {
6+
/**
7+
* Path or glob of what to copy.
8+
*/
9+
readonly src: string | readonly string[];
10+
11+
/**
12+
* One or more destinations where to copy.
13+
*/
14+
readonly dest: string | readonly string[];
15+
16+
/**
17+
* Change destination file or folder name.
18+
*/
19+
readonly rename?: string | Function;
20+
21+
/**
22+
* Modify file contents.
23+
*/
24+
readonly transform?: Function;
25+
}
26+
27+
interface CopyOptions extends globby.GlobbyOptions, fs.CopyOptions {
28+
/**
29+
* Copy items once. Useful in watch mode.
30+
* @default false
31+
*/
32+
readonly copyOnce?: boolean;
33+
34+
/**
35+
* Remove the directory structure of copied files.
36+
* @default true
37+
*/
38+
readonly flatten?: boolean;
39+
40+
/**
41+
* Rollup hook the plugin should use.
42+
* @default 'buildEnd'
43+
*/
44+
readonly hook?: string;
45+
46+
/**
47+
* Array of targets to copy.
48+
* @default []
49+
*/
50+
readonly targets?: readonly Target[];
51+
52+
/**
53+
* Output copied items to console.
54+
* @default false
55+
*/
56+
readonly verbose?: boolean;
57+
}
58+
59+
/**
60+
* Copy files and folders using Rollup
61+
*/
62+
export default function copy(options?: CopyOptions): rollup.Plugin;

jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
roots: [
3+
'<rootDir>/src',
4+
'<rootDir>/tests'
5+
],
6+
watchPathIgnorePatterns: [
7+
'<rootDir>/tests/fixtures/build',
8+
'<rootDir>/tests/fixtures/dist',
9+
'<rootDir>/tests/fixtures/src/index.js'
10+
]
11+
}

package.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "rollup-plugin-copy",
3+
"description": "Copy files and folders using Rollup",
4+
"version": "3.3.0",
5+
"author": "Vlad Shcherbin <vlad.shcherbin@gmail.com>",
6+
"repository": "vladshcherbin/rollup-plugin-copy",
7+
"main": "dist/index.commonjs.js",
8+
"module": "dist/index.module.js",
9+
"types": "index.d.ts",
10+
"scripts": {
11+
"clean": "rimraf coverage dist",
12+
"build": "rollup -c",
13+
"lint": "eslint src tests",
14+
"postpublish": "yarn clean",
15+
"prepublishOnly": "yarn lint && yarn test && yarn clean && yarn build",
16+
"test": "jest"
17+
},
18+
"dependencies": {
19+
"@types/fs-extra": "^8.0.1",
20+
"colorette": "^1.1.0",
21+
"fs-extra": "^8.1.0",
22+
"globby": "10.0.1",
23+
"is-plain-object": "^3.0.0"
24+
},
25+
"devDependencies": {
26+
"@babel/core": "^7.8.3",
27+
"@babel/preset-env": "^7.8.3",
28+
"babel-jest": "^24.9.0",
29+
"codecov": "^3.6.1",
30+
"eslint": "^6.8.0",
31+
"eslint-config-airbnb-base": "^14.0.0",
32+
"eslint-plugin-import": "^2.20.0",
33+
"jest": "^24.9.0",
34+
"replace-in-file": "^5.0.2",
35+
"rimraf": "^3.0.0",
36+
"rollup": "^1.29.0",
37+
"rollup-plugin-auto-external": "^2.0.0",
38+
"rollup-plugin-babel": "^4.3.3"
39+
},
40+
"files": [
41+
"dist",
42+
"index.d.ts",
43+
"readme.md"
44+
],
45+
"keywords": [
46+
"rollup",
47+
"rollup-plugin",
48+
"copy",
49+
"cp",
50+
"asset",
51+
"assets",
52+
"file",
53+
"files",
54+
"folder",
55+
"folders",
56+
"glob"
57+
],
58+
"engines": {
59+
"node": ">=8.3"
60+
},
61+
"license": "MIT"
62+
}

readme.md

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# rollup-plugin-copy
2+
3+
[![Build Status](https://travis-ci.org/vladshcherbin/rollup-plugin-copy.svg?branch=master)](https://travis-ci.org/vladshcherbin/rollup-plugin-copy)
4+
[![Codecov](https://codecov.io/gh/vladshcherbin/rollup-plugin-copy/branch/master/graph/badge.svg)](https://codecov.io/gh/vladshcherbin/rollup-plugin-copy)
5+
6+
Copy files and folders, with glob support.
7+
8+
## Installation
9+
10+
```bash
11+
# yarn
12+
yarn add rollup-plugin-copy -D
13+
14+
# npm
15+
npm install rollup-plugin-copy -D
16+
```
17+
18+
## Usage
19+
20+
```js
21+
// rollup.config.js
22+
import copy from 'rollup-plugin-copy'
23+
24+
export default {
25+
input: 'src/index.js',
26+
output: {
27+
file: 'dist/app.js',
28+
format: 'cjs'
29+
},
30+
plugins: [
31+
copy({
32+
targets: [
33+
{ src: 'src/index.html', dest: 'dist/public' },
34+
{ src: ['assets/fonts/arial.woff', 'assets/fonts/arial.woff2'], dest: 'dist/public/fonts' },
35+
{ src: 'assets/images/**/*', dest: 'dist/public/images' }
36+
]
37+
})
38+
]
39+
}
40+
```
41+
42+
### Configuration
43+
44+
There are some useful options:
45+
46+
#### targets
47+
48+
Type: `Array` | Default: `[]`
49+
50+
Array of targets to copy. A target is an object with properties:
51+
52+
- **src** (`string` `Array`): Path or glob of what to copy
53+
- **dest** (`string` `Array`): One or more destinations where to copy
54+
- **rename** (`string` `Function`): Change destination file or folder name
55+
- **transform** (`Function`): Modify file contents
56+
57+
Each object should have **src** and **dest** properties, **rename** and **transform** are optional. [globby](https://github.com/sindresorhus/globby) is used inside, check it for [glob pattern](https://github.com/sindresorhus/globby#globbing-patterns) examples.
58+
59+
##### File
60+
61+
```js
62+
copy({
63+
targets: [{ src: 'src/index.html', dest: 'dist/public' }]
64+
})
65+
```
66+
67+
##### Folder
68+
69+
```js
70+
copy({
71+
targets: [{ src: 'assets/images', dest: 'dist/public' }]
72+
})
73+
```
74+
75+
##### Glob
76+
77+
```js
78+
copy({
79+
targets: [{ src: 'assets/*', dest: 'dist/public' }]
80+
})
81+
```
82+
83+
##### Glob: multiple items
84+
85+
```js
86+
copy({
87+
targets: [{ src: ['src/index.html', 'src/styles.css', 'assets/images'], dest: 'dist/public' }]
88+
})
89+
```
90+
91+
##### Glob: negated patterns
92+
93+
```js
94+
copy({
95+
targets: [{ src: ['assets/images/**/*', '!**/*.gif'], dest: 'dist/public/images' }]
96+
})
97+
```
98+
99+
##### Multiple targets
100+
101+
```js
102+
copy({
103+
targets: [
104+
{ src: 'src/index.html', dest: 'dist/public' },
105+
{ src: 'assets/images/**/*', dest: 'dist/public/images' }
106+
]
107+
})
108+
```
109+
110+
##### Multiple destinations
111+
112+
```js
113+
copy({
114+
targets: [{ src: 'src/index.html', dest: ['dist/public', 'build/public'] }]
115+
})
116+
```
117+
118+
##### Rename with a string
119+
120+
```js
121+
copy({
122+
targets: [{ src: 'src/app.html', dest: 'dist/public', rename: 'index.html' }]
123+
})
124+
```
125+
126+
##### Rename with a function
127+
128+
```js
129+
copy({
130+
targets: [{
131+
src: 'assets/docs/*',
132+
dest: 'dist/public/docs',
133+
rename: (name, extension) => `${name}-v1.${extension}`
134+
}]
135+
})
136+
```
137+
138+
##### Transform file contents
139+
140+
```js
141+
copy({
142+
targets: [{
143+
src: 'src/index.html',
144+
dest: 'dist/public',
145+
transform: (contents) => contents.toString().replace('__SCRIPT__', 'app.js')
146+
}]
147+
})
148+
```
149+
150+
#### verbose
151+
152+
Type: `boolean` | Default: `false`
153+
154+
Output copied items to console.
155+
156+
```js
157+
copy({
158+
targets: [{ src: 'assets/*', dest: 'dist/public' }],
159+
verbose: true
160+
})
161+
```
162+
163+
#### hook
164+
165+
Type: `string` | Default: `buildEnd`
166+
167+
[Rollup hook](https://rollupjs.org/guide/en/#hooks) the plugin should use. By default, plugin runs when rollup has finished bundling, before bundle is written to disk.
168+
169+
```js
170+
copy({
171+
targets: [{ src: 'assets/*', dest: 'dist/public' }],
172+
hook: 'writeBundle'
173+
})
174+
```
175+
176+
#### copyOnce
177+
178+
Type: `boolean` | Default: `false`
179+
180+
Copy items once. Useful in watch mode.
181+
182+
```js
183+
copy({
184+
targets: [{ src: 'assets/*', dest: 'dist/public' }],
185+
copyOnce: true
186+
})
187+
```
188+
189+
#### flatten
190+
191+
Type: `boolean` | Default: `true`
192+
193+
Remove the directory structure of copied files.
194+
195+
```js
196+
copy({
197+
targets: [{ src: 'assets/**/*', dest: 'dist/public' }],
198+
flatten: false
199+
})
200+
```
201+
202+
All other options are passed to packages, used inside:
203+
- [globby](https://github.com/sindresorhus/globby)
204+
- [fs-extra copy function](https://github.com/jprichardson/node-fs-extra/blob/7.0.0/docs/copy.md)
205+
206+
## Original Author
207+
208+
[Cédric Meuter](https://github.com/meuter)
209+
210+
## License
211+
212+
MIT

0 commit comments

Comments
 (0)