Skip to content

Commit 36ef63f

Browse files
committed
1 parent c93035a commit 36ef63f

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9-
9+
- Adding basic v3 cli compatibility thanks to @somq
1010

1111
## [0.8.0] - 2021-1-28
1212
Thanks @pecirep, @miguel-a-calles-mba, @superandrew213

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,22 @@ echo "error page" >> client/dist/error.html
9797

9898
**Third**, run the plugin (this can take several minutes the first time), and visit your new website!
9999

100+
Serverless v2 cli params
101+
100102
```bash
101103
serverless deploy [--no-delete-contents] [--no-generate-client]
102104
```
103105

106+
Serverless v3 cli params
107+
108+
> Serverless v3 forbids free-form cli options.
109+
> Therefore options can now only be passed as `--param="option=value"`.
110+
> For the sake of simplicity, all v2 options are still available and passable through the `param` argument.
111+
112+
```bash
113+
serverless deploy [--param="no-delete-contents"] [--param="generate-client"]
114+
```
115+
104116
The plugin should output the location of your newly deployed static site to the console.
105117

106118
**Note:** *See [Command-line Parameters](#command-line-parameters) for details on command above*
@@ -635,4 +647,4 @@ Use this parameter if you do not want to invalidate the CloudFront distribution.
635647
Forked from the [**serverless-api-cloudfront**](https://github.com/Droplr/serverless-api-cloudfront/)
636648
Borrowed heavily from the [**serverless-finch**](https://github.com/fernando-mc/serverless-finch/)
637649
Initial CloudFormation template from [**Full Stack Serverless Web Apps with AWS**](https://medium.com/99xtechnology/full-stack-serverless-web-apps-with-aws-189d87da024a/)
638-
Inspiration from [**serverless-stack.com**](https://serverless-stack.com/)
650+
Inspiration from [**serverless-stack.com**](https://serverless-stack.com/)

index.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ServerlessFullstackPlugin {
6767
return this.validateConfig()
6868
.then(() => {
6969
bucketName = this.getBucketName(this.options.bucketName);
70-
return (this.cliOptions.confirm === false || this.options.noConfirm === true) ? true : new Confirm(`Are you sure you want to delete bucket '${bucketName}'?`).run();
70+
return (this.getCLIOptions('confirm') === false || this.options.noConfirm === true) ? true : new Confirm(`Are you sure you want to delete bucket '${bucketName}'?`).run();
7171
})
7272
.then(goOn => {
7373
if (goOn) {
@@ -111,7 +111,7 @@ class ServerlessFullstackPlugin {
111111
generateClient() {
112112
const clientCommand = this.options.clientCommand;
113113
const clientSrcPath = this.options.clientSrcPath || '.';
114-
if (clientCommand && this.cliOptions['generate-client'] !== false) {
114+
if (clientCommand && this.getCLIOptions('generate-client') !== false) {
115115
const args = clientCommand.split(' ');
116116
const command = args.shift();
117117
return new BbPromise(this.performClientGeneration.bind(this, command, args, clientSrcPath));
@@ -150,7 +150,7 @@ class ServerlessFullstackPlugin {
150150

151151
processDeployment() {
152152

153-
if(this.cliOptions['client-deploy'] !== false) {
153+
if(this.getCLIOptions('client-deploy') !== false) {
154154
let region,
155155
distributionFolder,
156156
clientPath,
@@ -189,15 +189,15 @@ class ServerlessFullstackPlugin {
189189

190190
const deployDescribe = ['This deployment will:'];
191191

192-
if (this.cliOptions['delete-contents'] !== false) {
192+
if (this.getCLIOptions('delete-contents') !== false) {
193193
deployDescribe.push(`- Remove all existing files from bucket '${bucketName}'`);
194194
}
195195
deployDescribe.push(
196196
`- Upload all files from '${distributionFolder}' to bucket '${bucketName}'`
197197
);
198198

199199
deployDescribe.forEach(m => this.serverless.cli.log(m));
200-
return (this.cliOptions.confirm === false || this.options.noConfirm === true) ? true : new Confirm(`Do you want to proceed?`).run();
200+
return (this.getCLIOptions('confirm') === false || this.options.noConfirm === true) ? true : new Confirm(`Do you want to proceed?`).run();
201201
})
202202
.then(goOn => {
203203
if (goOn) {
@@ -207,7 +207,7 @@ class ServerlessFullstackPlugin {
207207
.then(exists => {
208208
if (exists) {
209209
this.serverless.cli.log(`Bucket found...`);
210-
if (this.cliOptions['delete-contents'] === false) {
210+
if (this.getCLIOptions('delete-contents') === false) {
211211
this.serverless.cli.log(`Keeping current bucket contents...`);
212212
return BbPromise.resolve();
213213
}
@@ -233,7 +233,7 @@ class ServerlessFullstackPlugin {
233233
return BbPromise.resolve();
234234
})
235235
.then(() => {
236-
if (this.cliOptions['invalidate-distribution'] === false) {
236+
if (this.getCLIOptions('invalidate-distribution') === false) {
237237
this.serverless.cli.log(`Skipping cloudfront invalidation...`);
238238
} else {
239239
return invalidateCloudfrontDistribution(this.serverless, invalidationPaths);
@@ -561,6 +561,31 @@ class ServerlessFullstackPlugin {
561561
}
562562
return stage;
563563
}
564+
565+
/**
566+
* Serverless v3 hotfix/compat.
567+
* @param {the cli option} param
568+
* @returns Boolean
569+
*/
570+
getCLIOptions(param) {
571+
// v3
572+
const isv3 = this.serverless.version.split('.')[0] === '3';
573+
if (isv3) {
574+
const cliOptionsParams = Array.isArray(this.cliOptions?.param) ? [...this.cliOptions.param] : [];
575+
const cliOptions = {...this.cliOptions}
576+
577+
// Build key/value cli options from param array
578+
cliOptionsParams.forEach((k) => {
579+
const key = k.replace('no-', '');
580+
const val = !k.includes('no');
581+
cliOptions[key] = val;
582+
});
583+
return cliOptions[param]
584+
}
585+
586+
// v2
587+
return this.cliOptions[param]
588+
}
564589
}
565590

566-
module.exports = ServerlessFullstackPlugin;
591+
module.exports = ServerlessFullstackPlugin;

0 commit comments

Comments
 (0)