diff --git a/README.md b/README.md index dbcea723..8ebd0ff8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Serverless.d.ts b/src/Serverless.d.ts index ec7d7049..3803a84f 100644 --- a/src/Serverless.d.ts +++ b/src/Serverless.d.ts @@ -12,6 +12,11 @@ declare namespace Serverless { provider: { name: string } + custom: { + typescriptPlugin: { + enabled: boolean + } + } functions: { [key: string]: Serverless.Function } diff --git a/src/index.ts b/src/index.ts index a249ce58..151c0d78 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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() @@ -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() {