Skip to content
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
35 changes: 30 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,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));
Expand Down Expand Up @@ -150,7 +150,7 @@ class ServerlessFullstackPlugin {

processDeployment() {

if(this.cliOptions['client-deploy'] !== false) {
if(this.getCLIOptions('client-deploy') !== false) {
let region,
distributionFolder,
clientPath,
Expand Down Expand Up @@ -189,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(
Expand All @@ -207,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();
}
Expand All @@ -233,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);
Expand Down Expand Up @@ -561,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;