rollup-plugin-copy-assets
Advanced tools
Comparing version 1.1.0 to 2.0.0
@@ -0,0 +0,0 @@ # rollup-plugin-copy-assets |
{ | ||
"name": "rollup-plugin-copy-assets", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Copy additional assets into the output directory of your rollup bundle.", | ||
@@ -8,15 +8,15 @@ "main": "dist/rollup-plugin-copy-assets.js", | ||
"jsnext:main": "dist/rollup-plugin-copy-assets.module.js", | ||
"files": [ | ||
"dist", | ||
"src", | ||
"README.md" | ||
], | ||
"files": ["dist", "src", "README.md"], | ||
"scripts": { | ||
"test": "npm run lint && mocha ./test/tests.js --require babel-core/register", | ||
"pretest": "npm run build", | ||
"build": "npm run build:cjs && npm run build:module", | ||
"coverage": "lcov-badge-generator -o ./coverage/coverage.svg ./coverage/lcov.info", | ||
"test": "yarn lint && jest", | ||
"posttest": "yarn coverage", | ||
"build": "yarn build:cjs && yarn build:module", | ||
"build:cjs": "rollup -c -o ./dist/rollup-plugin-copy-assets.js -f cjs", | ||
"build:module": "rollup -c -o ./dist/rollup-plugin-copy-assets.module.js -f es", | ||
"prebuild": "rimraf dist/*", | ||
"lint": "eslint ./src" | ||
"format": "prettier --write 'rollup.config.js' '.{babel,eslint,prettier}rc' 'package.json' './{src,test}**/*.js'", | ||
"lint": "eslint ./src", | ||
"lint:fix": "eslint ./src --fix", | ||
"lint-staged": "lint-staged" | ||
}, | ||
@@ -27,9 +27,3 @@ "repository": { | ||
}, | ||
"keywords": [ | ||
"rollup-plugin", | ||
"bundle", | ||
"copy", | ||
"rollup", | ||
"assets" | ||
], | ||
"keywords": ["rollup-plugin", "bundle", "copy", "rollup", "assets"], | ||
"author": "Matt Bengston <bengston.matthew@gmail.com> (https://bengsfort.github.io)", | ||
@@ -42,19 +36,34 @@ "license": "MIT", | ||
"devDependencies": { | ||
"babel-core": "^6.26.0", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.6.1", | ||
"eslint": "^4.19.0", | ||
"eslint-config-google": "^0.9.1", | ||
"mocha": "^5.0.4", | ||
"rollup": "^0.67.3", | ||
"rollup-plugin-babel": "^3.0.3", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^3.4.0" | ||
"@babel/core": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"@babel/register": "^7.4.0", | ||
"babel-jest": "^24.7.1", | ||
"eslint": "^5.16.0", | ||
"eslint-plugin-jest": "^22.5.1", | ||
"growl": "^1.10.5", | ||
"husky": "^1.3.1", | ||
"jest": "^24.7.1", | ||
"lcov-badge-generator": "^1.0.5", | ||
"lint-staged": "^8.1.5", | ||
"prettier": "^1.16.4", | ||
"rollup": "^1.9.0", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^9.3.4", | ||
"rollup-plugin-node-resolve": "^4.2.1" | ||
}, | ||
"peerDependencies": { | ||
"rollup": ">=0.67.0" | ||
"rollup": ">=1.1.2" | ||
}, | ||
"dependencies": { | ||
"fs-extra": "^5.0.0" | ||
"fs-extra": "^7.0.1" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": ["prettier --write", "yarn lint", "git add"], | ||
"*.json": ["prettier --write", "git add"] | ||
} | ||
} |
# rollup-plugin-copy-assets | ||
![build status](https://api.travis-ci.org/bengsfort/rollup-plugin-copy-assets.svg?branch=master) [![npm version](https://badge.fury.io/js/rollup-plugin-copy-assets.svg)](https://www.npmjs.com/package/rollup-plugin-copy-assets) | ||
![build status](https://api.travis-ci.org/bengsfort/rollup-plugin-copy-assets.svg?branch=master) ![coverage](coverage/coverage.svg) [![npm version](https://badge.fury.io/js/rollup-plugin-copy-assets.svg)](https://www.npmjs.com/package/rollup-plugin-copy-assets) | ||
@@ -10,2 +10,6 @@ Copy additional assets into the output directory of your rollup bundle. | ||
```shell | ||
# add with yarn | ||
yarn add --dev rollup-plugin-copy-assets | ||
# or npm | ||
npm install --save-dev rollup-plugin-copy-assets | ||
@@ -18,12 +22,17 @@ ``` | ||
// rollup.config.js | ||
import copy from 'rollup-plugin-copy-assets'; | ||
import copy from "rollup-plugin-copy-assets"; | ||
export default { | ||
entry: 'src/index.js', | ||
dest: 'dist/bundle.js', | ||
input: "src/index.js", | ||
output: { | ||
file: "dist/bundle.js", | ||
format: "cjs", | ||
}, | ||
plugins: [ | ||
copy({ | ||
assets: [ | ||
'./src/assets', | ||
'./src/external/buffer.bin', | ||
// You can include directories | ||
"src/assets", | ||
// You can also include files | ||
"src/external/buffer.bin", | ||
], | ||
@@ -35,3 +44,3 @@ }), | ||
On final bundle generation the provided files will be copied over into the output folder of your rollup bundle. | ||
On final bundle generation the provided files will be copied over into the output folder of your rollup bundle, maintaining the original hierarchy and relativity to the input file: | ||
@@ -62,2 +71,2 @@ ```bash | ||
MIT | ||
MIT |
@@ -1,5 +0,5 @@ | ||
'use strict'; | ||
"use strict"; | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
@@ -9,21 +9,50 @@ /** | ||
* @param {Object} options The options object. | ||
* @param {string[]} options.assets A list of paths to include, relative to the kk | ||
* @return {Object} The rollup code object. | ||
*/ | ||
export default function copy(options = {}) { | ||
export default function copy(options = { assets: [] }) { | ||
const { assets } = options; | ||
let basedir = ''; | ||
let basedir = ""; | ||
return { | ||
name: 'copy-assets', | ||
options: function options(options) { | ||
name: "copy-assets", | ||
options({ input }) { | ||
// Cache the base directory so we can figure out where to put assets. | ||
basedir = path.dirname(options.input); | ||
if (Array.isArray(input)) { | ||
basedir = path.dirname(input[0]); | ||
} else { | ||
basedir = path.dirname(input); | ||
} | ||
}, | ||
generateBundle: ({ file, dir }) => { | ||
async generateBundle({ file, dir }) { | ||
const outputDirectory = dir || path.dirname(file); | ||
return Promise.all(assets.map((asset) => fs.copy( | ||
asset, | ||
path.join(outputDirectory, path.relative(basedir, asset)) | ||
))); | ||
return Promise.all( | ||
assets.map(async asset => { | ||
try { | ||
const target = path.join(outputDirectory, path.basename(asset)); | ||
const normalizedAssetPath = path.normalize(basedir, asset); | ||
const assetPath = path.join( | ||
normalizedAssetPath, | ||
path.basename(asset) | ||
); | ||
const targetIsDir = path.extname(target) === ""; | ||
const targetExists = await fs.pathExists(target); | ||
if (targetIsDir) { | ||
if (targetExists) await fs.emptyDir(target); | ||
} else { | ||
if (targetExists) { | ||
await fs.mkdirs(path.dirname(target)); | ||
await fs.remove(target); | ||
} | ||
} | ||
return await fs.copy(assetPath, target, { | ||
overwrite: true, | ||
errorOnExist: false, | ||
}); | ||
} catch (e) { | ||
this.warn(`Could not copy ${asset} because of an error: ${e}`); | ||
} | ||
}) | ||
); | ||
}, | ||
}; | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
69
157113
16
4541
+ Addedfs-extra@7.0.1(transitive)
- Removedfs-extra@5.0.0(transitive)
Updatedfs-extra@^7.0.1