Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for SLS v0.5 + support for relocating paths #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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 => {
Expand All @@ -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
Expand Down