Skip to content

Commit

Permalink
refactor: Seprate internal and plugin output sections
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Nov 2, 2021
1 parent 533f709 commit 7bb2520
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/Serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ class Serverless {
}

this.serviceOutputs = new Map();
this.servicePluginOutputs = new Map();

// trigger the plugin lifecycle when there's something which should be processed
await this.pluginManager.run(this.processedInput.commands);
Expand All @@ -478,10 +479,10 @@ class Serverless {
} else if (!content) {
throw new TypeError('Section content cannot be empty string');
}
if (this.serviceOutputs.has(sectionName)) {
if (this.serviceOutputs.has(sectionName) || this.servicePluginOutputs.has(sectionName)) {
throw new TypeError(`Section content for "${sectionName}" was already set`);
}
this.serviceOutputs.set(sectionName, content);
this.servicePluginOutputs.set(sectionName, content);
}

setProvider(name, provider) {
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/aws/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class AwsDeploy {
);
writeText();
writeServiceOutputs(this.serverless.serviceOutputs);
writeServiceOutputs(this.serverless.servicePluginOutputs);
},
};
}
Expand Down
20 changes: 10 additions & 10 deletions lib/plugins/aws/info/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ module.exports = {

legacy.consoleLog(message);
if (this.serverless.processedInput.commands.join(' ') === 'info') {
this.serverless.addServiceOutputSection('service', this.serverless.service.service);
this.serverless.addServiceOutputSection('stage', this.provider.getStage());
this.serverless.addServiceOutputSection('region', this.provider.getRegion());
this.serverless.addServiceOutputSection('stack', this.provider.naming.getStackName());
this.serverless.serviceOutputs.set('service', this.serverless.service.service);
this.serverless.serviceOutputs.set('stage', this.provider.getStage());
this.serverless.serviceOutputs.set('region', this.provider.getRegion());
this.serverless.serviceOutputs.set('stack', this.provider.naming.getStackName());
}

return message;
Expand All @@ -50,7 +50,7 @@ module.exports = {
}
outputSectionItems.push(`${apiKeyInfo.name}: ${apiKeyInfo.value}${description}`);
});
this.serverless.addServiceOutputSection('api keys', outputSectionItems);
this.serverless.serviceOutputs.set('api keys', outputSectionItems);
} else {
apiKeysMessage += '\n None';
}
Expand Down Expand Up @@ -123,9 +123,9 @@ module.exports = {
}

if (outputSectionItems.length > 1) {
this.serverless.addServiceOutputSection('endpoints', outputSectionItems);
this.serverless.serviceOutputs.set('endpoints', outputSectionItems);
} else if (outputSectionItems.length) {
this.serverless.addServiceOutputSection('endpoint', outputSectionItems[0]);
this.serverless.serviceOutputs.set('endpoint', outputSectionItems[0]);
}
legacy.consoleLog(endpointsMessage);
return endpointsMessage;
Expand All @@ -145,7 +145,7 @@ module.exports = {
}`
);
});
this.serverless.addServiceOutputSection('functions', outputSectionItems);
this.serverless.serviceOutputs.set('functions', outputSectionItems);
} else {
functionsMessage += '\n None';
}
Expand All @@ -164,7 +164,7 @@ module.exports = {
layersMessage += `\n ${l.name}: ${l.arn}`;
outputSectionItems.push(`${l.name}: ${l.arn}`);
});
this.serverless.addServiceOutputSection('layers', outputSectionItems);
this.serverless.serviceOutputs.set('layers', outputSectionItems);
} else {
layersMessage += '\n None';
}
Expand All @@ -190,7 +190,7 @@ module.exports = {
outputSectionItems.push(`${output.OutputKey}: ${output.OutputValue}`);
});

this.serverless.addServiceOutputSection('\nStack Outputs', outputSectionItems);
this.serverless.serviceOutputs.set('\nStack Outputs', outputSectionItems);
}

return message;
Expand Down
1 change: 1 addition & 0 deletions lib/plugins/aws/info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class AwsInfo {
'finalize': () => {
if (this.serverless.processedInput.commands.join(' ') !== 'info') return;
writeServiceOutputs(this.serverless.serviceOutputs);
writeServiceOutputs(this.serverless.servicePluginOutputs);
},
};
}
Expand Down

0 comments on commit 7bb2520

Please sign in to comment.