Skip to content

Commit 31a971f

Browse files
authored
Merge pull request #11 from kopertop/feature/support-includes
Add in package/includes to final build product.
2 parents 3cda001 + 7e7d60a commit 31a971f

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ The default `tsconfig.json` file used by the plugin looks like this:
4444

4545
> Note: Don't confuse the [`tsconfig.json`](tsconfig.json) in this repository with the one mentioned above.
4646

47+
## Including extra files
48+
49+
All files from `package/include` will be included in the final build file. See [Exclude/Include](https://serverless.com/framework/docs/providers/aws/guide/packaging#exclude--include)
50+
4751
## Help & Community [![Slack Status](https://slack.graph.cool/badge.svg)](https://slack.graph.cool)
4852

4953
Join our [Slack community](http://slack.graph.cool/) if you run into issues or have questions. We love talking to you!

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
"aws lambda"
2525
],
2626
"devDependencies": {
27-
"@types/fs-extra": "^2.0.0",
27+
"@types/fs-extra": "2.0.0",
2828
"@types/lodash": "^4.14.62",
2929
"tslint": "^5.1.0"
3030
},
3131
"dependencies": {
32-
"fs-p": "^2.0.0",
32+
"fs-p": "2.0.0",
33+
"globby": "^6.1.0",
3334
"lodash": "^4.17.4",
3435
"typescript": "^2.2.2"
3536
}

src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as path from 'path'
22
import * as fs from 'fs-p'
33
import * as _ from 'lodash'
4+
import * as globby from 'globby'
5+
46
import { ServerlessOptions, ServerlessInstance } from './types'
57
import * as typescript from './typescript'
68

@@ -53,6 +55,24 @@ class ServerlessPlugin {
5355

5456
// include node_modules into build
5557
fs.symlinkSync(path.resolve('node_modules'), path.resolve(path.join(buildFolder, 'node_modules')))
58+
59+
// include any "extras" from the "include" section
60+
if (this.serverless.service.package.include && this.serverless.service.package.include.length > 0){
61+
const files = await globby(this.serverless.service.package.include)
62+
63+
for (const filename of files) {
64+
const destFileName = path.resolve(path.join(buildFolder, filename))
65+
const dirname = path.dirname(destFileName)
66+
67+
if (!fs.existsSync(dirname)) {
68+
fs.mkdirpSync(dirname)
69+
}
70+
71+
if (!fs.existsSync(destFileName)) {
72+
fs.copySync(path.resolve(filename), path.resolve(path.join(buildFolder, filename)))
73+
}
74+
}
75+
}
5676
}
5777

5878
async afterCreateDeploymentArtifacts(): Promise<void> {

0 commit comments

Comments
 (0)