From e82bf76563d7cc0ea45b9f0d9846f4b2a0b1fd40 Mon Sep 17 00:00:00 2001 From: Kamil Burzynski Date: Wed, 17 Feb 2016 08:46:11 +0100 Subject: [PATCH 1/2] Added support for custom relocation paths --- index.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 32c94e6..ac94008 100644 --- a/index.js +++ b/index.js @@ -254,31 +254,41 @@ module.exports = function(ServerlessPlugin) { compressPaths = [], ignore = ['.DS_Store'], stats, - fullPath; + fullPath, + srcPath, + destPath, + destDirPath; // Skip if undefined if (!_this.config.includePaths) return compressPaths; // Collect includePaths _this.config.includePaths.forEach(p => { + if( p.src && p.dest ){ + srcPath = p.src; + destPath = p.dest; + destDirPath = p.dest; + } else { + srcPath = p; + destPath = p; + destDirPath = path.basename( p ); + } try { - fullPath = path.resolve(path.join(_this.evt.data.pathDist, p)); + fullPath = path.resolve(path.join(_this.evt.data.pathDist, srcPath)); stats = fs.lstatSync(fullPath); } catch (e) { - console.error('Cant find includePath ', p, e); + console.error('Cant find includePath ', srcPath, e); throw e; } if (stats.isFile()) { compressPaths.push({ - name: p, + name: destPath, path: fullPath }); } else if (stats.isDirectory()) { - let dirname = path.basename(p); - wrench .readdirSyncRecursive(fullPath) .forEach(file => { @@ -290,7 +300,7 @@ module.exports = function(ServerlessPlugin) { let filePath = [fullPath, file].join('/'); if (fs.lstatSync(filePath).isFile()) { - let pathInZip = path.join(dirname, file); + let pathInZip = path.join(destDirPath, file); compressPaths.push({ name: pathInZip, path: filePath From 5c9f39cc44fca029a98a5a2296def478ea19e837 Mon Sep 17 00:00:00 2001 From: Kamil Burzynski Date: Wed, 17 Feb 2016 10:52:40 +0100 Subject: [PATCH 2/2] Updates for v0.5 --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ac94008..9242977 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,7 @@ module.exports = function(ServerlessPlugin) { } // Get function - let func = this.S.state.getFunctions({ paths: [evt.options.path] })[0], + let func = this.S.getProject().getFunction( evt.options.path ), component = func.getComponent(), optimizer; @@ -77,7 +77,7 @@ module.exports = function(ServerlessPlugin) { } // Optimize: Nodejs - if (component.runtime === 'nodejs') { + if (component.getRuntime().getName() === 'nodejs') { optimizer = new OptimizeNodejs(this.S, evt, component, func); return optimizer.optimize() .then(function(evt) {