Skip to content

Commit

Permalink
Support package.include and package.exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Feb 26, 2018
1 parent b8f6f8a commit 9bec03e
Show file tree
Hide file tree
Showing 9 changed files with 1,355 additions and 61 deletions.
20 changes: 18 additions & 2 deletions lib/packageModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const _ = require('lodash');
const path = require('path');
const archiver = require('archiver');
const fs = require('fs');
const glob = require('glob');
const globby = require('globby');
const semver = require('semver');

function setArtifactPath(funcName, func, artifactPath) {
Expand Down Expand Up @@ -34,11 +34,27 @@ function zip(directory, name) {

const output = fs.createWriteStream(artifactFilePath);

const files = glob.sync('**', {
const exclude = _.get(this.serverless, 'service.package.exclude', []);
const include = _.get(this.serverless, 'service.package.include', []);

const patterns = _.concat(
['**'],
_.map(exclude, pattern => {
if (pattern.charAt(0) !== '!') {
return `!${pattern}`;
} else {
return pattern.substring(1);
}
}),
include
);

const files = globby.sync(patterns, {
cwd: directory,
dot: true,
silent: true,
follow: true,
nodir: true,
});

if (_.isEmpty(files)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const BbPromise = require('bluebird');
const path = require('path');
const fse = require('fs-extra');
const glob = require('glob');
const globby = require('globby');
const lib = require('./index');
const _ = require('lodash');

Expand All @@ -30,8 +30,8 @@ module.exports = {
};

const getEntryExtension = fileName => {
const files = glob.sync(`${fileName}.*`, {
cwd: this.serverless.config.servicePath,
const files = globby.sync(`${fileName}.*`, {
cwd: this.serverless.config.servicePath || process.cwd(),
nodir: true
});

Expand Down

0 comments on commit 9bec03e

Please sign in to comment.