From 5f32cd5111ec4b6655a371333c7792b6aa1942b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 18 Aug 2022 18:25:09 +0200 Subject: [PATCH 1/5] chore(sls): hotfix compat for sls v3 --- index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.js b/index.js index b6a4d31..d571b02 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,18 @@ class ServerlessFullstackPlugin { } } }; + + // Serverless v3 hotfix/compat. + // @note; Better refactor all the cliOptions getters below instead + const isv3 = this.serverless.version.split('.')[0] === '3'; + if (isv3) { + const _cliOptions = [...this.cliOptions.param]; + _cliOptions.forEach((k) => { + const key = k.replace('no-', ''); + const val = !k.includes('no'); + this.cliOptions[key] = val; + }); + } } validateConfig() { From 88ee712a3fc269ae503e4af458bd631e69b09119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 18 Aug 2022 21:34:29 +0200 Subject: [PATCH 2/5] refactor(cli-opts): refactor cli opts v2/v3 compat as a getter method --- index.js | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index d571b02..77ef742 100644 --- a/index.js +++ b/index.js @@ -50,18 +50,6 @@ class ServerlessFullstackPlugin { } } }; - - // Serverless v3 hotfix/compat. - // @note; Better refactor all the cliOptions getters below instead - const isv3 = this.serverless.version.split('.')[0] === '3'; - if (isv3) { - const _cliOptions = [...this.cliOptions.param]; - _cliOptions.forEach((k) => { - const key = k.replace('no-', ''); - const val = !k.includes('no'); - this.cliOptions[key] = val; - }); - } } validateConfig() { @@ -123,7 +111,7 @@ class ServerlessFullstackPlugin { generateClient() { const clientCommand = this.options.clientCommand; const clientSrcPath = this.options.clientSrcPath || '.'; - if (clientCommand && this.cliOptions['generate-client'] !== false) { + if (clientCommand && this.getCLIOptions('generate-client') !== false) { const args = clientCommand.split(' '); const command = args.shift(); return new BbPromise(this.performClientGeneration.bind(this, command, args, clientSrcPath)); @@ -162,7 +150,7 @@ class ServerlessFullstackPlugin { processDeployment() { - if(this.cliOptions['client-deploy'] !== false) { + if(this.getCLIOptions('client-deploy') !== false) { let region, distributionFolder, clientPath, @@ -201,7 +189,7 @@ class ServerlessFullstackPlugin { const deployDescribe = ['This deployment will:']; - if (this.cliOptions['delete-contents'] !== false) { + if (this.getCLIOptions('delete-contents') !== false) { deployDescribe.push(`- Remove all existing files from bucket '${bucketName}'`); } deployDescribe.push( @@ -219,7 +207,7 @@ class ServerlessFullstackPlugin { .then(exists => { if (exists) { this.serverless.cli.log(`Bucket found...`); - if (this.cliOptions['delete-contents'] === false) { + if (this.getCLIOptions('delete-contents') === false) { this.serverless.cli.log(`Keeping current bucket contents...`); return BbPromise.resolve(); } @@ -245,7 +233,7 @@ class ServerlessFullstackPlugin { return BbPromise.resolve(); }) .then(() => { - if (this.cliOptions['invalidate-distribution'] === false) { + if (this.getCLIOptions('invalidate-distribution') === false) { this.serverless.cli.log(`Skipping cloudfront invalidation...`); } else { return invalidateCloudfrontDistribution(this.serverless, invalidationPaths); @@ -573,6 +561,31 @@ class ServerlessFullstackPlugin { } return stage; } + + /** + * Serverless v3 hotfix/compat. + * @param {the cli option} param + * @returns Boolean + */ + getCLIOptions(param) { + // v3 + const isv3 = this.serverless.version.split('.')[0] === '3'; + if (isv3) { + const cliOptionsParams = Array.isArray(this.cliOptions?.param) ? [...this.cliOptions.param] : []; + const cliOptions = {...this.cliOptions} + + // Build key/value cli options from param array + cliOptionsParams.forEach((k) => { + const key = k.replace('no-', ''); + const val = !k.includes('no'); + cliOptions[key] = val; + }); + return cliOptions[param] + } + + // v2 + return this.cliOptions[param] + } } module.exports = ServerlessFullstackPlugin; From 4b15130858f8428888ffc3ebe096e57beb64f0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 18 Aug 2022 21:34:45 +0200 Subject: [PATCH 3/5] chore: bump to v0.8.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b532c6f..59569c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fullstack-serverless", - "version": "0.8.0", + "version": "0.8.1", "engines": { "node": ">=4.0" }, From bc9da6ca7a067270f073d211f8313215c01174d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 18 Aug 2022 21:37:34 +0200 Subject: [PATCH 4/5] Revert "chore: bump to v0.8.1" This reverts commit 4b15130858f8428888ffc3ebe096e57beb64f0bc. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 59569c8..b532c6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fullstack-serverless", - "version": "0.8.1", + "version": "0.8.0", "engines": { "node": ">=4.0" }, From 0b2b7047cb323a889ae154aaea3041a6ae44aba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Thu, 18 Aug 2022 23:02:30 +0200 Subject: [PATCH 5/5] docs(cli-opts): add v3 cli opts explanation & example --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 9f61b80..62625db 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,22 @@ echo "error page" >> client/dist/error.html **Third**, run the plugin (this can take several minutes the first time), and visit your new website! +Serverless v2 cli params + ```bash serverless deploy [--no-delete-contents] [--no-generate-client] ``` +Serverless v3 cli params + +> Serverless v3 forbids free-form cli options. +> Therefore options can now only be passed as `--param="option=value"`. +> For the sake of simplicity, all v2 options are still available and passable through the `param` argument. + +```bash +serverless deploy [--param="no-delete-contents"] [--param="generate-client"] +``` + The plugin should output the location of your newly deployed static site to the console. **Note:** *See [Command-line Parameters](#command-line-parameters) for details on command above*