Skip to content

Commit

Permalink
Make original excludes and includes relative (#29)
Browse files Browse the repository at this point in the history
* Make original excludes and includes relative
* Add test for exclamation mark prefixed path

Fixes #21
  • Loading branch information
jogold authored Jul 5, 2017
1 parent 1abecf2 commit 63613b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
15 changes: 13 additions & 2 deletions src/lib/service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
const path = require('path');
const R = require('ramda');

const appendPath = (p, e) => R.over(R.lensPath(p), R.append(e));
const makeRelative = R.replace(/[^!]+$/, R.concat('../'));
const makeAllRelative = p => R.when(R.has(p), R.over(R.lensProp(p), R.map(makeRelative)));
const makePackageRelative = R.compose(makeAllRelative('include'), makeAllRelative('exclude'));

const setPackage = R.pipe(
makePackageRelative,
R.over(R.lensProp('exclude'), R.append('**')),
R.assoc('individually', true)
);

const fnPath = R.compose(R.replace(/\.[^.]+$/, '.js'), R.prop('handler'));

const setFnsPackage = R.map(fn => appendPath(['package', 'include'], fnPath(fn))(fn));
const setFnsPackage = R.map(
R.pipe(
R.over(R.lensProp('package'), makePackageRelative),
R.converge(
R.over(R.lensPath(['package', 'include'])),
[R.compose(R.append, fnPath), R.identity]
)
)
);

const setFnsArtifacts = (serverlessPath, fns) => R.map(
R.over(
Expand Down
2 changes: 1 addition & 1 deletion test/fns.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const originalFns = {
},
post: {
handler: 'functions/post.handler',
package: { exclude: ['*.sql'] },
package: { exclude: ['*.sql', '!test.sql'] },
},
};

Expand Down
14 changes: 7 additions & 7 deletions test/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ test('service package with existing package and include/exclude', () => {
};
const expectedPackage = {
individually: true,
include: ['node_modules/**'],
exclude: ['*.txt', '**'],
include: ['../node_modules/**'],
exclude: ['../*.txt', '**'],
};
expect(service.setPackage(existingPackage)).toEqual(expectedPackage);
});
Expand All @@ -44,22 +44,22 @@ test('setFnsPackage', () => {
firstGet: {
handler: 'functions/first/get.handler',
package: {
include: ['node_modules/**', 'functions/first/get.js'],
exclude: ['abc.js'],
include: ['../node_modules/**', 'functions/first/get.js'],
exclude: ['../abc.js'],
},
},
secondGet: {
handler: 'functions/second/get.handler',
package: {
include: ['node_modules/**', 'functions/second/get.js'],
exclude: ['abc.js'],
include: ['../node_modules/**', 'functions/second/get.js'],
exclude: ['../abc.js'],
},
},
post: {
handler: 'functions/post.handler',
package: {
include: ['functions/post.js'],
exclude: ['*.sql'],
exclude: ['../*.sql', '!../test.sql'],
},
},
};
Expand Down

0 comments on commit 63613b4

Please sign in to comment.