Skip to content

Commit

Permalink
Merge 0b12363 into 22b6de5
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Dec 23, 2021
2 parents 22b6de5 + 0b12363 commit 4c25f91
Show file tree
Hide file tree
Showing 20 changed files with 7 additions and 420 deletions.
1 change: 0 additions & 1 deletion lib/Serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class Serverless {
// information such as options when the user enters --help
this.cli.setLoadedPlugins(this.pluginManager.getPlugins());
this.cli.setLoadedCommands(this.pluginManager.getCommands());
await this.pluginManager.updateAutocompleteCacheFile();
}
async eventuallyFallbackToLocal() {
if (
Expand Down
33 changes: 0 additions & 33 deletions lib/classes/PluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ const path = require('path');
const config = require('@serverless/utils/config');
const cjsResolve = require('ncjsm/resolve/sync');
const _ = require('lodash');
const crypto = require('crypto');
const isModuleNotFoundError = require('ncjsm/is-module-not-found-error');
const ServerlessError = require('../serverless-error');
const resolveCliInput = require('../cli/resolve-input');
const writeFile = require('../utils/fs/writeFile');
const getCacheFilePath = require('../utils/getCacheFilePath');
const getCommandSuggestion = require('../utils/getCommandSuggestion');
const renderCommandHelp = require('../cli/render-help/command');
const { storeLocally: storeTelemetryLocally, send: sendTelemetry } = require('../utils/telemetry');
Expand Down Expand Up @@ -756,36 +753,6 @@ class PluginManager {
}
}

updateAutocompleteCacheFile() {
const commands = _.clone(this.getCommands());
const cacheFile = {
commands: {},
validationHash: '',
};

Object.entries(commands).forEach(([commandName, commandObj]) => {
const command = commandObj;
if (!command.options) {
command.options = {};
}
if (!command.commands) {
command.commands = {};
}
cacheFile.commands[commandName] = Object.keys(command.options)
.map((option) => `--${option}`)
.concat(Object.keys(command.commands));
});

const serverlessConfigFileHash = crypto
.createHash('sha256')
.update(JSON.stringify(this.serverless.configurationInput || null))
.digest('hex');
cacheFile.validationHash = serverlessConfigFileHash;
const cacheFilePath = getCacheFilePath(this.serverless.serviceDir);

return writeFile(cacheFilePath, cacheFile);
}

convertShortcutsIntoOptions(command) {
if (command.options) {
Object.entries(command.options).forEach(([optionKey, optionObject]) => {
Expand Down
32 changes: 1 addition & 31 deletions lib/cli/commands-schema/no-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ commands.set('', {
usage: 'Template url for the service.',
},
},
lifecycleEvents: ['initializeService', 'setupAws', 'autoUpdate', 'tabCompletion', 'end'],
lifecycleEvents: ['initializeService', 'setupAws', 'autoUpdate', 'end'],
});

commands.set('config', {
Expand Down Expand Up @@ -71,36 +71,6 @@ commands.set('config credentials', {
lifecycleEvents: ['config'],
});

(() => {
const isHidden = process.platform === 'win32';
const noSupportNotice = '<tab> completion is not supported on Windows';

commands.set('config tabcompletion install', {
usage: 'Install a <tab> completion for chosen shell',
isHidden,
noSupportNotice,
options: {
shell: {
usage:
'Shell for which <tab> completion should be installed. ' +
'Supported options: bash (default), zsh, fish ',
shortcut: 's',
},
location: {
usage: 'Custom location for shell config',
shortcut: 'l',
},
},
lifecycleEvents: ['install'],
});
commands.set('config tabcompletion uninstall', {
usage: 'Uninstall a <tab> completion',
isHidden,
noSupportNotice,
lifecycleEvents: ['uninstall'],
});
})();

commands.set('create', {
usage: 'Create new Serverless service',
options: {
Expand Down
75 changes: 0 additions & 75 deletions lib/plugins/config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
'use strict';

const BbPromise = require('bluebird');
const config = require('@serverless/utils/config');
const ServerlessError = require('../serverless-error');
const cliCommandsSchema = require('../cli/commands-schema');
const muteConsoleLog = require('../utils/log/muteConsoleLog');
const tabtabOptions = require('../utils/tabCompletion/tabtabOptions');
const isNpmPackageWritable = require('../utils/npmPackage/isWritable');
const isNpmGlobalPackage = require('../utils/npmPackage/isGlobal');
const renderCommandHelp = require('../cli/render-help/command');
const { legacy, log } = require('@serverless/utils/log');

// class wide constants
const validProviders = new Set(['aws']);
const validShells = new Set(['bash', 'zsh', 'fish']);

// TODO: update to look like the list in the "create" plugin
// once more than one provider is supported
Expand Down Expand Up @@ -42,23 +38,9 @@ class Config {
},
};

this.commands.config.commands.tabcompletion = {
type: 'container',
commands: {
install: {
...cliCommandsSchema.get('config tabcompletion install'),
},
uninstall: {
...cliCommandsSchema.get('config tabcompletion uninstall'),
},
},
};

this.hooks = {
'config:config': async () => this.updateConfig(),
'before:config:credentials:config': () => this.validate(),
'config:tabcompletion:install:install': async () => this.tabtabCompletionInstall(),
'config:tabcompletion:uninstall:uninstall': async () => this.tabtabCompletionUninstall(),
};
}

Expand Down Expand Up @@ -126,63 +108,6 @@ class Config {
);
}
}

async tabtabCompletionInstall() {
return BbPromise.try(() => {
const shell = this.serverless.processedInput.options.shell || 'bash';

if (!validShells.has(shell)) {
throw new ServerlessError(
`Shell "${shell}" is not supported. Supported shells: ${Array.from(validShells)}.`,
'TABCOMPLETION_INVALID_SHELL_ARGUMENT'
);
}
const location = (() => {
if (this.serverless.processedInput.options.location) {
return this.serverless.processedInput.options.location;
}
const { BASH_LOCATION, FISH_LOCATION, ZSH_LOCATION } = require('tabtab/lib/constants');
switch (shell) {
case 'bash':
return BASH_LOCATION;
case 'zsh':
return ZSH_LOCATION;
case 'fish':
return FISH_LOCATION;
default:
throw new Error('Unexpected shell choice');
}
})();
const { install } = require('tabtab/lib/installer');
return muteConsoleLog(() =>
tabtabOptions.reduce(
(previousOperation, options) =>
previousOperation.then(() => install(Object.assign({ location }, options))),
BbPromise.resolve()
)
).then(() => {
legacy.log(`Tab autocompletion setup for ${shell}. Make sure to reload your SHELL.`);
log.notice.success(
`Tab autocompletion setup for ${shell}. Make sure to reload your SHELL.`
);
});
});
}

async tabtabCompletionUninstall() {
return BbPromise.try(() => {
const { uninstall } = require('tabtab/lib/installer');
return muteConsoleLog(() =>
tabtabOptions.reduce(
(previousOperation, options) => previousOperation.then(() => uninstall(options)),
BbPromise.resolve()
)
).then(() => {
legacy.log('Tab autocompletion uninstalled (for all configured shells).');
log.notice.success('Tab autocompletion uninstalled (for all configured shells).');
});
});
}
}

module.exports = Config;
60 changes: 0 additions & 60 deletions lib/utils/autocomplete.js

This file was deleted.

17 changes: 0 additions & 17 deletions lib/utils/getCacheFile.js

This file was deleted.

13 changes: 0 additions & 13 deletions lib/utils/getCacheFilePath.js

This file was deleted.

33 changes: 0 additions & 33 deletions lib/utils/log/muteConsoleLog.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/utils/tabCompletion/isSupported.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/utils/tabCompletion/promptDisabledConfigPropertyName.js

This file was deleted.

3 changes: 0 additions & 3 deletions lib/utils/tabCompletion/tabtabOptions.js

This file was deleted.

13 changes: 0 additions & 13 deletions lib/utils/telemetry/generatePayload.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const path = require('path');
const os = require('os');
const fs = require('fs');
const crypto = require('crypto');
const resolveSync = require('ncjsm/resolve/sync');
const _ = require('lodash');
Expand All @@ -21,16 +19,6 @@ const AWS = require('aws-sdk');

const configValidationModeValues = new Set(['off', 'warn', 'error']);

const checkIsTabAutocompletionInstalled = () => {
try {
return fs
.readdirSync(path.resolve(os.homedir(), '.config/tabtab'))
.some((filename) => filename.startsWith('serverless.'));
} catch {
return false;
}
};

const getServiceConfig = ({ configuration, options, variableSources }) => {
const providerName = isObject(configuration.provider)
? configuration.provider.name
Expand Down Expand Up @@ -258,7 +246,6 @@ module.exports = ({
return 'local:direct';
})(),
isAutoUpdateEnabled: Boolean(userConfig.get('autoUpdate.enabled')),
isTabAutocompletionInstalled: checkIsTabAutocompletionInstalled(),
notificationsMode: getNotificationsMode(),
timestamp: Date.now(),
timezone,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"semver": "^7.3.5",
"signal-exit": "^3.0.6",
"strip-ansi": "^6.0.1",
"tabtab": "^3.0.2",
"tar": "^6.1.11",
"timers-ext": "^0.1.7",
"type": "^2.5.0",
Expand Down
Loading

0 comments on commit 4c25f91

Please sign in to comment.