mirror of
https://github.com/serverless/serverless.git
synced 2026-02-01 16:07:28 +00:00
apply this functionality to serverless.json
This commit is contained in:
parent
75bced3a0c
commit
80cccd01e8
@ -137,7 +137,7 @@ class Plugin {
|
|||||||
).devDependencies[pluginName];
|
).devDependencies[pluginName];
|
||||||
|
|
||||||
if (pluginInstalled) {
|
if (pluginInstalled) {
|
||||||
yamlAstParser.addNewArrayItem(this.getServerlessFilePath(), 'plugins', pluginName);
|
this.addPluginToServerlessFile(pluginName);
|
||||||
this.serverless.cli.log(`Successfully installed "${pluginName}@${pluginVersion}"`);
|
this.serverless.cli.log(`Successfully installed "${pluginName}@${pluginVersion}"`);
|
||||||
} else {
|
} else {
|
||||||
const message = 'An error occurred while installing your plugin. Please try again...';
|
const message = 'An error occurred while installing your plugin. Please try again...';
|
||||||
@ -177,8 +177,7 @@ class Plugin {
|
|||||||
).devDependencies[pluginName];
|
).devDependencies[pluginName];
|
||||||
|
|
||||||
if (!pluginStillAvailable) {
|
if (!pluginStillAvailable) {
|
||||||
yamlAstParser
|
this.removePluginFromServerlessFile(pluginName);
|
||||||
.removeExistingArrayItem(this.getServerlessFilePath(), 'plugins', pluginName);
|
|
||||||
this.serverless.cli.log(`Successfully uninstalled "${pluginName}"`);
|
this.serverless.cli.log(`Successfully uninstalled "${pluginName}"`);
|
||||||
} else {
|
} else {
|
||||||
const message = 'An error occurred while uninstalling your plugin. Please try again...';
|
const message = 'An error occurred while uninstalling your plugin. Please try again...';
|
||||||
@ -235,12 +234,15 @@ class Plugin {
|
|||||||
const servicePath = this.serverless.config.servicePath;
|
const servicePath = this.serverless.config.servicePath;
|
||||||
const serverlessYmlFilePath = path.join(servicePath, 'serverless.yml');
|
const serverlessYmlFilePath = path.join(servicePath, 'serverless.yml');
|
||||||
const serverlessYamlFilePath = path.join(servicePath, 'serverless.yaml');
|
const serverlessYamlFilePath = path.join(servicePath, 'serverless.yaml');
|
||||||
|
const serverlessJsonFilePath = path.join(servicePath, 'serverless.json');
|
||||||
|
|
||||||
let serverlessFilePath;
|
let serverlessFilePath;
|
||||||
if (fs.existsSync(serverlessYmlFilePath)) {
|
if (fs.existsSync(serverlessYmlFilePath)) {
|
||||||
serverlessFilePath = serverlessYmlFilePath;
|
serverlessFilePath = serverlessYmlFilePath;
|
||||||
} else {
|
} else if (fs.existsSync(serverlessYamlFilePath)) {
|
||||||
serverlessFilePath = serverlessYamlFilePath;
|
serverlessFilePath = serverlessYamlFilePath;
|
||||||
|
} else {
|
||||||
|
serverlessFilePath = serverlessJsonFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
return serverlessFilePath;
|
return serverlessFilePath;
|
||||||
@ -252,6 +254,38 @@ class Plugin {
|
|||||||
return fetch(endpoint).then((result) => result.json()).then((json) => json);
|
return fetch(endpoint).then((result) => result.json()).then((json) => json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addPluginToServerlessFile(pluginName) {
|
||||||
|
const serverlessFilePath = this.getServerlessFilePath();
|
||||||
|
if (_.last(_.split(serverlessFilePath, '.')) === 'json') {
|
||||||
|
const serverlessFileObj = fse.readJsonSync(serverlessFilePath);
|
||||||
|
if (serverlessFileObj.plugins) {
|
||||||
|
serverlessFileObj.plugins.push(pluginName);
|
||||||
|
} else {
|
||||||
|
serverlessFileObj.plugins = [pluginName];
|
||||||
|
}
|
||||||
|
serverlessFileObj.plugins = _.sortedUniq(serverlessFileObj.plugins);
|
||||||
|
fse.writeJsonSync(serverlessFilePath, serverlessFileObj);
|
||||||
|
} else {
|
||||||
|
yamlAstParser.addNewArrayItem(serverlessFilePath, 'plugins', pluginName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removePluginFromServerlessFile(pluginName) {
|
||||||
|
const serverlessFilePath = this.getServerlessFilePath();
|
||||||
|
if (_.last(_.split(serverlessFilePath, '.')) === 'json') {
|
||||||
|
const serverlessFileObj = fse.readJsonSync(serverlessFilePath);
|
||||||
|
if (serverlessFileObj.plugins) {
|
||||||
|
serverlessFileObj.plugins.pop(pluginName);
|
||||||
|
if (_.isEmpty(serverlessFileObj.plugins)) {
|
||||||
|
_.unset(serverlessFileObj, 'plugins');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fse.writeJsonSync(serverlessFilePath, serverlessFileObj);
|
||||||
|
} else {
|
||||||
|
yamlAstParser.removeExistingArrayItem(this.getServerlessFilePath(), 'plugins', pluginName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
display(plugins) {
|
display(plugins) {
|
||||||
let message = '';
|
let message = '';
|
||||||
if (plugins && plugins.length) {
|
if (plugins && plugins.length) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user