lib/plugins/plugin/install/install.js/PluginInstall/addPluginToServerlessFile
class PluginInstall:  addPluginToServerlessFile() {
    return this.getServerlessFilePath().then(serverlessFilePath => {
      if (_.last(_.split(serverlessFilePath, '.')) === 'js') {
        this.serverless.cli.log(`
          Can't automatically add plugin into "serverless.js" file.
          Please make it manually.
        `);
        return BbPromise.resolve();
      }

      const checkIsArrayPluginsObject = (pluginsObject) =>
        _.isNil(pluginsObject) || _.isArray(pluginsObject);
      // pluginsObject type determined based on the value loaded during the serverless init.
      if (_.last(_.split(serverlessFilePath, '.')) === 'json') {
        return fse.readJsonAsync(serverlessFilePath).then(serverlessFileObj => {
          const newServerlessFileObj = serverlessFileObj;
          const isArrayPluginsObject = checkIsArrayPluginsObject(newServerlessFileObj.plugins);
          // null modules property is not supported
          let plugins = isArrayPluginsObject ? newServerlessFileObj.plugins || [] :
            newServerlessFileObj.plugins.modules;

          if (_.isNil(plugins)) {
            throw new Error('plugins modules property must be present');
          }

          plugins.push(this.options.pluginName);
          plugins = _.sortedUniq(plugins);

          if (isArrayPluginsObject) {
            newServerlessFileObj.plugins = plugins;
          } else {
            newServerlessFileObj.plugins.modules = plugins;
          }

          return fse.writeJsonAsync(serverlessFilePath, newServerlessFileObj);
        });
      }

      return this.serverless.yamlParser
        .parse(serverlessFilePath)
        .then((serverlessFileObj) =>
          yamlAstParser.addNewArrayItem(serverlessFilePath,
            checkIsArrayPluginsObject(serverlessFileObj.plugins) ?
              'plugins' : 'plugins.modules', this.options.pluginName));
    });
  }