Skip to content

Commit

Permalink
use yarn to create deployment artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
tommedema committed Aug 22, 2018
1 parent a87a3bd commit e0f97a0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ build/Release

# Dependency directories
node_modules/
prod_node_modules/
jspm_packages/

# TypeScript v1 declaration files
Expand Down
9 changes: 3 additions & 6 deletions packages/sls-random/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ plugins:
- serverless-plugin-scripts

package:
exclude:
- ./**
- '!dist/**'
- '!node_modules/**'
artifact: dist/artifact.zip

provider:
name: aws
Expand All @@ -31,11 +28,11 @@ provider:
custom:
scripts:
hooks:
'before:deploy:createDeploymentArtifacts': yarn run build
'before:deploy:createDeploymentArtifacts': yarn run build && ../../scripts/sls-package.sh

functions:

fetchRandomNumber:
handler: dist/index.fetchRandomNumber
handler: index.fetchRandomNumber
events:
- http: GET number
28 changes: 28 additions & 0 deletions scripts/sls-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#! /bin/sh

# this is assumed to run from a sls-package, e.g. at packages/sls-random
# see https://github.com/yarnpkg/yarn/issues/6293#issuecomment-414779476
cwd=$PWD

# install production deps for the entire workspace
cd ../..
yarn install --production
cd $cwd

# dupe node_modules
mkdir -p dist
rm -fr dist/node_modules
cp -RL node_modules dist/node_modules

# cleanup .bin
rm -rf dist/node_modules/.bin

# back to development
cd ../../
yarn install
cd $cwd

# prepare artifact
cd dist
zip -r artifact.zip *
cd ..
19 changes: 5 additions & 14 deletions tsconfig.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [
"es6"
],
"lib": ["es6"],
"moduleResolution": "node",

"rootDir": "./",
"baseUrl": "packages/",
"paths": {
"@org/*": ["./*/src"]
},
"typeRoots": [
"./node_modules/@types",
"./packages/types"
],

"typeRoots": ["./node_modules/@types", "./packages/types"],

"composite": true,
"declaration": true,
"declarationMap": true,
Expand All @@ -34,9 +29,5 @@
"resolveJsonModule": true,
"esModuleInterop": true
},
"exclude": [
"**/dist",
"**/node_modules",
"**/test"
]
}
"exclude": ["**/dist", "**/node_modules", "**/prod_node_modules", "**/test"]
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,8 @@ aws-lambda@^0.1.2:
dotenv "^0.4.0"

aws-sdk@^*, aws-sdk@^2.228.0:
version "2.297.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.297.0.tgz#2fe085076f6fd488285ef7cfaf883fdaa47acee9"
version "2.298.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.298.0.tgz#53259d06ca3bcde69d11f3b24b1c05088939c67f"
dependencies:
buffer "4.9.1"
events "1.1.1"
Expand Down

0 comments on commit e0f97a0

Please sign in to comment.