Skip to content
This repository has been archived by the owner on Jul 2, 2020. It is now read-only.

Commit

Permalink
feat: support serverless.yml package include & exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar committed Dec 11, 2019
1 parent c7a5b44 commit 048e5af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as co from 'co';
import { join, resolve } from 'path';
import * as archiver from 'archiver';
import * as ora from 'ora';
import * as globby from 'globby';
// const { buildByNcc } = require('./ncc');

export class Package extends CommandBase {
Expand Down Expand Up @@ -62,15 +63,23 @@ export class Package extends CommandBase {
},
'package:midway-copyFile': async () => {
const timeTick = this.tick();
const paths = ['src', 'tsconfig.json', 'package.json'];
for (const path of paths) {
await copy(join(this.servicePath, path), join(this.midwayBuildPath, path));
}
const spinner = ora(' - Package files copying').start();
const packageObj: any = this.serverless.service.package || {};
const include = await globby(['src', 'tsconfig.json', 'package.json'].concat(packageObj.include || []));
const exclude = await globby(packageObj.exclude || []);
const paths = include.filter((filePath: string) => {
return exclude.indexOf(filePath) === -1;
});
await Promise.all(paths.map((path: string) => {
return copy(join(this.servicePath, path), join(this.midwayBuildPath, path));
}));
spinner.stop();
this.serverless.cli.log(` - File copy complete (${timeTick()}ms)`);
},
'package:midway-layerInstall': async () => {
// serverless.yml - layers
const timeTick = this.tick();
const spinner = ora(' - Layers installing').start();
const funcLayers = [];
if (this.serverless.service.functions) {
for (const func in this.serverless.service.functions) {
Expand All @@ -85,6 +94,7 @@ export class Package extends CommandBase {
if (npmList && npmList.length) {
await this.npmInstall(npmList);
}
spinner.stop();
this.serverless.cli.log(` - layers install complete (${timeTick()}ms)`);
},
'package:midway-depInstall': async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@ layers:
package:
include:
exclude:
- src/**
- tsconfig.json
- test/**
- ./*.zip
excludeDevDependencies: false
artifact: path/to/my-artifact.zip # Own package that should be used. You must provide this file.

0 comments on commit 048e5af

Please sign in to comment.