From 111a4103731a2c08ea2b8356a5deb18a426298d4 Mon Sep 17 00:00:00 2001 From: Choong Zin Jye Date: Tue, 30 Apr 2019 10:06:32 +0800 Subject: [PATCH 1/2] feat: Support packaging functions individually (closes #42 #107) --- src/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.ts b/src/index.ts index 27e1769b..e9b47706 100644 --- a/src/index.ts +++ b/src/index.ts @@ -202,6 +202,18 @@ export class TypeScriptPlugin { serverlessFolder, path.basename(this.serverless.service.package.artifact) ) + + this.serverless.service.getAllFunctions().forEach(name => { + if (this.serverless.service.functions[name].package.artifact) { + this.serverless.service.functions[name].package.artifact = path.join( + this.originalServicePath, + serverlessFolder, + path.basename( + this.serverless.service.functions[name].package.artifact + ) + ) + } + }) } async cleanup(): Promise { From 2e1c82656d922b5b80df30eeb86f12d2a9995bf0 Mon Sep 17 00:00:00 2001 From: Choong Zin Jye Date: Mon, 13 May 2019 09:16:26 +0800 Subject: [PATCH 2/2] taking care of function individual package 'include' and 'exclude' --- src/index.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e9b47706..e2ceeb6c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -149,7 +149,7 @@ export class TypeScriptPlugin { await this.linkOrCopy(path.resolve('package.json'), outPkgPath, 'file') } - // include any "extras" from the "include" section + // include any "extras" from the "include" section of the main service if (this.serverless.service.package.include && this.serverless.service.package.include.length > 0) { const files = await globby(this.serverless.service.package.include) @@ -166,6 +166,25 @@ export class TypeScriptPlugin { } } } + + // include any "extras" from the "include" section of each function + for (const fnName in this.functions) { + const fn = this.functions[fnName] + if (fn.package.include !== undefined) { + for (const filename of fn.package.include) { + const destFileName = path.resolve(path.join(buildFolder, filename)) + const dirname = path.dirname(destFileName) + + if (!fs.existsSync(dirname)) { + fs.mkdirpSync(dirname) + } + + if (!fs.existsSync(destFileName)) { + fs.copySync(path.resolve(filename), path.resolve(path.join(buildFolder, filename))) + } + } + } + } } async moveArtifacts(): Promise {