filemanager-webpack-plugin
Advanced tools
Comparing version 1.0.9 to 1.0.10
172
lib/index.js
'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
var asyncGenerator = function () { | ||
@@ -144,2 +154,52 @@ function AwaitValue(value) { | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
var cpr = require('cpr'); | ||
@@ -188,9 +248,24 @@ var rimraf = require('rimraf'); | ||
if (this.options.verbose && Object.keys(this.options[stage]).length) { | ||
console.log('FileManagerPlugin: processing ' + stage + ' event'); | ||
} | ||
var operationList = []; | ||
if (this.options[stage] && Array.isArray(this.options[stage])) { | ||
this.options[stage].map(function (opts) { | ||
return _this.parseFileOptions(opts); | ||
return operationList.push.apply(operationList, toConsumableArray(_this.parseFileOptions(opts, true))); | ||
}); | ||
} else { | ||
this.parseFileOptions(this.options[stage]); | ||
operationList.push.apply(operationList, toConsumableArray(this.parseFileOptions(this.options[stage]))); | ||
} | ||
if (operationList.length) { | ||
operationList.reduce(function (previous, fn) { | ||
return previous.then(function (retVal) { | ||
return fn(retVal); | ||
}); | ||
}, Promise.resolve()); | ||
} | ||
} | ||
@@ -204,2 +279,4 @@ }, { | ||
var commandOrder = []; | ||
for (var i = 0; i < optKeys.length; i++) { | ||
@@ -213,36 +290,89 @@ | ||
case 'copy': | ||
var _loop = function _loop(key) { | ||
fileOptions.forEach(function (command) { | ||
var command = fileOptions[key]; | ||
if (!command.source || !command.destination) return; | ||
if (!command.source || !command.destination) return { | ||
v: void 0 | ||
}; | ||
cpr(command.source, command.destination, _this2.cprOptions, function (err, files) { | ||
// handle error | ||
commandOrder.push(function () { | ||
return new Promise(function (resolve, reject) { | ||
if (_this2.options.verbose) { | ||
console.log(' - FileManagerPlugin: Start copy source: ' + command.source + ' to destination: ' + command.destination); | ||
} | ||
cpr(command.source, command.destination, _this2.cprOptions, function (err, files) { | ||
if (_this2.options.verbose) { | ||
console.log(' - FileManagerPlugin: Finished copy source: ' + command.source + ' to destination: ' + command.destination); | ||
} | ||
resolve(err); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
for (var key in fileOptions) { | ||
var _ret = _loop(key); | ||
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; | ||
} | ||
break; | ||
case 'move': | ||
var _loop2 = function _loop2(key) { | ||
fileOptions.forEach(function (command) { | ||
var command = fileOptions[key]; | ||
if (!command.source || !command.destination) return; | ||
if (!command.source || !command.destination) return { | ||
v: void 0 | ||
}; | ||
mv(command.source, command.destination, function (err) { | ||
// handle error | ||
commandOrder.push(function () { | ||
return new Promise(function (resolve, reject) { | ||
mv(command.source, command.destination, function (err) { | ||
resolve(err); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
for (var key in fileOptions) { | ||
var _ret2 = _loop2(key); | ||
if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v; | ||
} | ||
break; | ||
case 'delete': | ||
var _loop3 = function _loop3(key) { | ||
fileOptions.forEach(function (path) { | ||
var path = fileOptions[key]; | ||
rimraf(path, {}, function (response) { | ||
// handle error | ||
commandOrder.push(function () { | ||
return new Promise(function (resolve, reject) { | ||
if (_this2.options.verbose) { | ||
console.log(' - FileManagerPlugin: Starting delete path ' + path); | ||
} | ||
rimraf(path, {}, function (response) { | ||
if (_this2.options.verbose && response === null) { | ||
console.log(' - FileManagerPlugin: Finished delete path ' + path); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
for (var key in fileOptions) { | ||
_loop3(key); | ||
} | ||
break; | ||
@@ -255,2 +385,4 @@ | ||
} | ||
return commandOrder; | ||
} | ||
@@ -264,6 +396,2 @@ }, { | ||
if (_this3.options.verbose) { | ||
console.log("FileManagerPlugin: onStart"); | ||
} | ||
_this3.checkOptions("onStart"); | ||
@@ -274,6 +402,2 @@ }); | ||
if (_this3.options.verbose) { | ||
console.log("FileManagerPlugin: onEnd"); | ||
} | ||
_this3.checkOptions("onEnd"); | ||
@@ -280,0 +404,0 @@ |
{ | ||
"name": "filemanager-webpack-plugin", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "This Webpack plugin allows you to copy, move, delete files and directories before and after builds", | ||
@@ -29,4 +29,6 @@ "main": "lib/index.js", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-es2015-rollup": "^3.0.0", | ||
"babel-preset-es2017": "^6.24.1", | ||
"eslint": "^4.5.0", | ||
@@ -33,0 +35,0 @@ "rollup": "^0.49.1", |
@@ -8,3 +8,19 @@ import babel from 'rollup-plugin-babel'; | ||
babel({ | ||
"presets": ["es2015-rollup"] | ||
"presets": [ | ||
[ | ||
"es2015", | ||
{ | ||
"modules": false | ||
} | ||
] | ||
], | ||
"plugins": [ | ||
"external-helpers", | ||
["transform-runtime", { | ||
"helpers": false, | ||
"polyfill": false, | ||
"regenerator": true, | ||
"moduleName": "rollup-regenerator-runtime" | ||
}] | ||
] | ||
}), | ||
@@ -11,0 +27,0 @@ nodeResolve({ |
@@ -41,14 +41,31 @@ const cpr = require('cpr'); | ||
if (this.options.verbose && Object.keys(this.options[stage]).length) { | ||
console.log(`FileManagerPlugin: processing ${stage} event`); | ||
} | ||
let operationList = []; | ||
if (this.options[stage] && Array.isArray(this.options[stage])) { | ||
this.options[stage].map(opts => this.parseFileOptions(opts)); | ||
this.options[stage].map(opts => operationList.push(...this.parseFileOptions(opts, true))); | ||
} else { | ||
this.parseFileOptions(this.options[stage]); | ||
operationList.push(...this.parseFileOptions(this.options[stage])); | ||
} | ||
if(operationList.length) { | ||
operationList.reduce((previous, fn) => { | ||
return previous.then(retVal => fn(retVal)); | ||
}, Promise.resolve()); | ||
} | ||
} | ||
parseFileOptions(options) { | ||
parseFileOptions(options, preserveOrder = false) { | ||
const optKeys = Object.keys(options); | ||
let commandOrder = []; | ||
for (let i = 0; i < optKeys.length; i++) { | ||
@@ -63,13 +80,30 @@ | ||
fileOptions.forEach(command => { | ||
for(let key in fileOptions) { | ||
const command = fileOptions[key]; | ||
if (!command.source || !command.destination) | ||
return; | ||
cpr(command.source, command.destination, this.cprOptions, (err, files) => { | ||
// handle error | ||
}); | ||
commandOrder.push(() => new Promise((resolve, reject) => { | ||
}); | ||
if (this.options.verbose) { | ||
console.log(` - FileManagerPlugin: Start copy source: ${command.source} to destination: ${command.destination}`) | ||
} | ||
cpr(command.source, command.destination, this.cprOptions, (err, files) => { | ||
if (this.options.verbose) { | ||
console.log(` - FileManagerPlugin: Finished copy source: ${command.source} to destination: ${command.destination}`) | ||
} | ||
resolve(err); | ||
}); | ||
})); | ||
} | ||
break; | ||
@@ -80,12 +114,16 @@ | ||
fileOptions.forEach(command => { | ||
for(let key in fileOptions) { | ||
const command = fileOptions[key]; | ||
if (!command.source || !command.destination) | ||
return; | ||
mv(command.source, command.destination, (err) => { | ||
// handle error | ||
}); | ||
commandOrder.push(() => new Promise((resolve, reject) => { | ||
mv(command.source, command.destination, (err) => { | ||
resolve(err); | ||
}); | ||
})); | ||
}); | ||
} | ||
@@ -96,10 +134,23 @@ break; | ||
fileOptions.forEach(path => { | ||
for(let key in fileOptions) { | ||
rimraf(path, { }, (response) => { | ||
// handle error | ||
}); | ||
const path = fileOptions[key]; | ||
}); | ||
commandOrder.push(() => new Promise((resolve, reject) => { | ||
if (this.options.verbose) { | ||
console.log(` - FileManagerPlugin: Starting delete path ${path}`) | ||
} | ||
rimraf(path, { }, (response) => { | ||
if (this.options.verbose && response === null) { | ||
console.log(` - FileManagerPlugin: Finished delete path ${path}`) | ||
} | ||
resolve(); | ||
}); | ||
})); | ||
} | ||
break; | ||
@@ -114,2 +165,4 @@ | ||
return commandOrder; | ||
} | ||
@@ -122,6 +175,2 @@ | ||
if (this.options.verbose) { | ||
console.log("FileManagerPlugin: onStart"); | ||
} | ||
this.checkOptions("onStart"); | ||
@@ -133,6 +182,2 @@ | ||
if (this.options.verbose) { | ||
console.log("FileManagerPlugin: onEnd"); | ||
} | ||
this.checkOptions("onEnd"); | ||
@@ -139,0 +184,0 @@ |
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
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
28487
478
14