Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit 620b264

Browse files
refactor: tidy up
1 parent 687204a commit 620b264

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class ServerlessNextJsPlugin {
5656
return userConfig === undefined ? defaults[param] : userConfig;
5757
}
5858

59+
getPluginConfigValues(...params) {
60+
return params.map(p => this.getPluginConfigValue(p));
61+
}
62+
5963
printStackOutput() {
6064
const awsInfo = this.serverless.pluginManager.getPlugins().find(plugin => {
6165
return plugin.constructor.name === "AwsInfo";

lib/addCustomStackResources.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ const normaliseSrc = (staticDir, src) =>
2424
.join("");
2525

2626
const getStaticRouteProxyResources = async function(bucketName) {
27-
const staticDir = this.getPluginConfigValue("staticDir");
28-
const routes = this.getPluginConfigValue("routes");
27+
const [staticDir, routes] = this.getPluginConfigValues("staticDir", "routes");
2928

3029
if (!staticDir) {
3130
return {};
@@ -34,6 +33,7 @@ const getStaticRouteProxyResources = async function(bucketName) {
3433
const baseResource = await loadYml(
3534
path.join(__dirname, "../resources/api-gw-proxy.yml")
3635
);
36+
3737
const result = {
3838
Resources: {}
3939
};

lib/build.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ const overrideTargetIfNotServerless = nextConfiguration => {
2121
module.exports = async function() {
2222
const pluginBuildDir = this.pluginBuildDir;
2323
const nextConfigDir = pluginBuildDir.nextConfigDir;
24-
const pageConfig = this.getPluginConfigValue("pageConfig");
25-
const customHandler = this.getPluginConfigValue("customHandler");
26-
const routes = this.getPluginConfigValue("routes");
24+
25+
const [pageConfig, customHandler, routes] = this.getPluginConfigValues(
26+
"pageConfig",
27+
"customHandler",
28+
"routes"
29+
);
2730

2831
logger.log("Started building next app ...");
2932

@@ -61,13 +64,10 @@ module.exports = async function() {
6164

6265
await rewritePageHandlers(nextPages, customHandler);
6366

64-
const service = this.serverless.service;
65-
66-
this.nextPages = nextPages;
67-
6867
nextPages.forEach(page => {
6968
const functionName = page.functionName;
70-
service.functions[functionName] = page.serverlessFunction[functionName];
69+
this.serverless.service.functions[functionName] =
70+
page.serverlessFunction[functionName];
7171
});
7272

7373
this.serverless.service.setFunctionNames();

lib/uploadStaticAssets.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ module.exports = function() {
66

77
let { nextConfiguration, staticAssetsBucket } = this.configuration;
88

9-
const bucketNameFromConfig = this.getPluginConfigValue("assetsBucketName");
10-
const staticDir = this.getPluginConfigValue("staticDir");
11-
const uploadBuildAssets = this.getPluginConfigValue("uploadBuildAssets");
9+
const [
10+
bucketNameFromConfig,
11+
staticDir,
12+
uploadBuildAssets
13+
] = this.getPluginConfigValues(
14+
"assetsBucketName",
15+
"staticDir",
16+
"uploadBuildAssets"
17+
);
1218

1319
if (bucketNameFromConfig) {
1420
staticAssetsBucket = bucketNameFromConfig;

0 commit comments

Comments
 (0)