Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable the plugin #174

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ The default `tsconfig.json` file used by the plugin looks like this:

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)

### Disable the plugin


You can disable plugin passing the following command line option to serverless:

```yaml
--typescript-plugin [disabled|off|false]
```

Adding a typescriptPlugin section to the custom section of your serverless.yml to set default value if needed:

```yaml
custom:
typescriptPlugin:
enabled: false
```

## Usage

Expand Down
5 changes: 5 additions & 0 deletions src/Serverless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ declare namespace Serverless {
provider: {
name: string
}
custom: {
typescriptPlugin: {
enabled: boolean
}
}
functions: {
[key: string]: Serverless.Function
}
Expand Down
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class TypeScriptPlugin {
this.serverless = serverless
this.options = options

if (!this.isEnabled()) {
this.serverless.cli.log('Typescript plugin is disabled.')
return
}

this.hooks = {
'before:run:run': async () => {
await this.compileTs()
Expand Down Expand Up @@ -93,7 +98,21 @@ export class TypeScriptPlugin {
this.originalServicePath,
this.serverless.service.provider.name,
this.functions
)
)
}

isEnabled() {
const cliOption = this.options['typescript-plugin']
if (cliOption === 'disabled' || cliOption === 'off' || cliOption === 'false') {
return false
}

const custom = this.serverless.service.custom
if (custom && custom.typescriptPlugin && (!custom.typescriptPlugin.enabled || custom.typescriptPlugin.enabled.toString() === 'false')) {
return false
}

return true
}

prepare() {
Expand Down