Skip to content

Commit

Permalink
feat: add buildSpecValues.artifactFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
brettstack committed Mar 29, 2020
1 parent 9d49831 commit e19b1a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ custom:
version: 0.1
frontend:
...
buildSpecValues: # optional
artifactBaseDirectory: 'dist' # optional
artifactFiles: ['**/*'] # optional
```
### 🔒 Securing your GitHub Personal Access Token Secret
Expand Down Expand Up @@ -104,6 +107,22 @@ frontend:
- node_modules/**/*
```

### buildSpecValues (optional)

Specify values in the `buildSpec`. Useful so that you don't need to provide your own custom `buildSpec` if you just need to override some values that are commonly different between projects.

#### artifactBaseDirectory (optional)

Sets `frontend.artifacts.baseDirectory` in `buildSpec`.

**Default:** dist

#### artifactFiles (optional)

Sets `frontend.artifacts.baseDirectory` in `buildSpec`.

**Default:** ['**/*']

## Limitations and future considerations

This plugin is currently only written with a basic single branch setup in mind. In the future we'd like to add support for all of Amplify Console's features including:
Expand Down
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@ class ServerlessAmplifyPlugin {
return src.slice('amplify:'.length)
}

getArtifactFilesYaml(artifactFiles) {
return artifactFiles
.map(artifactFile => `
- '${artifactFile}'`)
.join('')
}

addAmplify() {
const { service } = this.serverless
const { custom, provider, serviceObject } = service
const { amplify } = custom
const { defaultBuildSpecOverrides = {} } = amplify
const { buildSpecValues = {} } = amplify
const {
baseDirectory = 'dist'
} = defaultBuildSpecOverrides
artifactBaseDirectory = 'dist',
artifactFiles = ['**/*'],
} = buildSpecValues
const {
repository,
accessTokenSecretName = 'AmplifyGithub',
Expand All @@ -49,9 +57,8 @@ frontend:
commands:
- npm run build
artifacts:
baseDirectory: ${baseDirectory}
files:
- '**/*'
baseDirectory: ${artifactBaseDirectory}
files:${this.getArtifactFilesYaml(artifactFiles)}
cache:
paths:
- node_modules/**/*`,
Expand Down
10 changes: 6 additions & 4 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ artifacts:
}
})
})
it('creates buildSpec based on defaultBuildSpecOverrides', () => {
it('creates buildSpec based on buildSpecValues', () => {
const amplifyConfig = {
defaultBuildSpecOverrides: {
baseDirectory: 'public'
buildSpecValues: {
artifactBaseDirectory: 'public',
artifactFiles: ['index.js', 'dist/**/*']
}
}
const serverless = makeMockServerless({
Expand All @@ -227,7 +228,8 @@ frontend:
artifacts:
baseDirectory: public
files:
- '**/*'
- 'index.js'
- 'dist/**/*'
cache:
paths:
- node_modules/**/*`)
Expand Down

0 comments on commit e19b1a8

Please sign in to comment.