@hubspot/cli 3.0.9 → 3.0.10-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +6 -0
  2. package/bin/cli.js +3 -2
  3. package/commands/accounts/list.js +18 -26
  4. package/commands/accounts/rename.js +13 -24
  5. package/commands/accounts.js +4 -1
  6. package/commands/app/deploy.js +22 -28
  7. package/commands/auth.js +30 -13
  8. package/commands/config/set/allowUsageTracking.js +15 -31
  9. package/commands/config/set/defaultAccount.js +22 -32
  10. package/commands/config/set/defaultMode.js +23 -42
  11. package/commands/config/set/httpTimeout.js +10 -28
  12. package/commands/config/set.js +4 -1
  13. package/commands/config.js +4 -1
  14. package/commands/create/api-sample.js +14 -12
  15. package/commands/create/module.js +19 -6
  16. package/commands/create/project.js +8 -1
  17. package/commands/create/template.js +19 -4
  18. package/commands/create.js +23 -8
  19. package/commands/customObject/create.js +22 -24
  20. package/commands/customObject/schema/create.js +30 -28
  21. package/commands/customObject/schema/delete.js +20 -20
  22. package/commands/customObject/schema/fetch-all.js +17 -24
  23. package/commands/customObject/schema/fetch.js +29 -24
  24. package/commands/customObject/schema/list.js +8 -17
  25. package/commands/customObject/schema/update.js +31 -29
  26. package/commands/customObject/schema.js +4 -1
  27. package/commands/customObject.js +10 -21
  28. package/commands/fetch.js +15 -30
  29. package/commands/filemanager/fetch.js +13 -25
  30. package/commands/filemanager/upload.js +47 -35
  31. package/commands/filemanager.js +4 -1
  32. package/commands/functions/deploy.js +34 -37
  33. package/commands/functions/list.js +9 -24
  34. package/commands/functions/server.js +13 -29
  35. package/commands/functions.js +4 -1
  36. package/commands/hubdb/clear.js +25 -21
  37. package/commands/hubdb/create.js +25 -22
  38. package/commands/hubdb/delete.js +19 -20
  39. package/commands/hubdb/fetch.js +15 -20
  40. package/commands/hubdb.js +4 -1
  41. package/commands/init.js +23 -11
  42. package/commands/lint.js +14 -23
  43. package/commands/list.js +19 -25
  44. package/commands/logs.js +41 -135
  45. package/commands/mv.js +21 -25
  46. package/commands/open.js +7 -5
  47. package/commands/project/create.js +111 -0
  48. package/commands/project/deploy.js +30 -34
  49. package/commands/project/listBuilds.js +160 -0
  50. package/commands/project/logs.js +192 -0
  51. package/commands/project/upload.js +108 -55
  52. package/commands/project.js +7 -8
  53. package/commands/remove.js +12 -20
  54. package/commands/sandbox/create.js +16 -11
  55. package/commands/secrets/addSecret.js +18 -21
  56. package/commands/secrets/deleteSecret.js +18 -21
  57. package/commands/secrets/listSecrets.js +10 -19
  58. package/commands/secrets/updateSecret.js +18 -21
  59. package/commands/secrets.js +4 -1
  60. package/commands/server.js +13 -5
  61. package/commands/{marketplaceValidate/validateTheme.js → theme/marketplace-validate.js} +26 -24
  62. package/commands/theme.js +5 -3
  63. package/commands/upload.js +66 -45
  64. package/commands/watch.js +33 -55
  65. package/lib/__tests__/serverlessLogs.js +8 -9
  66. package/lib/commonOpts.js +14 -11
  67. package/lib/enums/exitCodes.js +14 -0
  68. package/lib/projects.js +246 -235
  69. package/lib/prompts/projects.js +8 -5
  70. package/lib/prompts/sandboxes.js +5 -2
  71. package/lib/prompts.js +26 -27
  72. package/lib/serverlessLogs.js +11 -12
  73. package/lib/ui.js +48 -0
  74. package/lib/validation.js +2 -1
  75. package/package.json +9 -7
  76. package/commands/project/init.js +0 -108
@@ -1,46 +1,45 @@
1
- const {
2
- loadConfig,
3
- validateConfig,
4
- checkAndWarnGitInclusion,
5
- } = require('@hubspot/cli-lib');
6
1
  const { logger } = require('@hubspot/cli-lib/logger');
7
2
  const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
8
3
  const { deleteTable } = require('@hubspot/cli-lib/api/hubdb');
9
- const { validateAccount } = require('../../lib/validation');
4
+ const { loadAndValidateOptions } = require('../../lib/validation');
10
5
  const { trackCommandUsage } = require('../../lib/usageTracking');
11
6
 
12
7
  const {
13
8
  addConfigOptions,
14
9
  addAccountOptions,
15
10
  addUseEnvironmentOptions,
16
- setLogLevel,
17
11
  getAccountId,
18
12
  } = require('../../lib/commonOpts');
19
- const { logDebugInfo } = require('../../lib/debugInfo');
13
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
14
+
15
+ const i18nKey = 'cli.commands.hubdb.subcommands.delete';
20
16
 
21
17
  exports.command = 'delete <tableId>';
22
- exports.describe = 'delete a HubDB table';
18
+ exports.describe = i18n(`${i18nKey}.describe`);
23
19
 
24
20
  exports.handler = async options => {
25
- const { config: configPath, tableId } = options;
21
+ const { tableId } = options;
26
22
 
27
- setLogLevel(options);
28
- logDebugInfo(options);
29
- loadConfig(configPath, options);
30
- checkAndWarnGitInclusion();
23
+ await loadAndValidateOptions(options);
31
24
 
32
- if (!(validateConfig() && (await validateAccount(options)))) {
33
- process.exit(1);
34
- }
35
25
  const accountId = getAccountId(options);
36
26
 
37
27
  trackCommandUsage('hubdb-delete', {}, accountId);
38
28
 
39
29
  try {
40
30
  await deleteTable(accountId, tableId);
41
- logger.log(`The table ${tableId} was deleted from ${accountId}`);
31
+ logger.success(
32
+ i18n(`${i18nKey}.success.delete`, {
33
+ accountId,
34
+ tableId,
35
+ })
36
+ );
42
37
  } catch (e) {
43
- logger.error(`Deleting the table ${tableId} failed`);
38
+ logger.error(
39
+ i18n(`${i18nKey}.errors.delete`, {
40
+ tableId,
41
+ })
42
+ );
44
43
  logErrorInstance(e);
45
44
  }
46
45
  };
@@ -51,7 +50,7 @@ exports.builder = yargs => {
51
50
  addUseEnvironmentOptions(yargs, true);
52
51
 
53
52
  yargs.positional('tableId', {
54
- describe: 'HubDB Table ID',
53
+ describe: i18n(`${i18nKey}.positionals.tableId.describe`),
55
54
  type: 'string',
56
55
  });
57
56
  };
@@ -1,38 +1,28 @@
1
- const {
2
- loadConfig,
3
- validateConfig,
4
- checkAndWarnGitInclusion,
5
- } = require('@hubspot/cli-lib');
6
1
  const { logger } = require('@hubspot/cli-lib/logger');
7
2
  const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
8
3
  const { downloadHubDbTable } = require('@hubspot/cli-lib/hubdb');
9
4
 
10
- const { validateAccount } = require('../../lib/validation');
5
+ const { loadAndValidateOptions } = require('../../lib/validation');
11
6
  const { trackCommandUsage } = require('../../lib/usageTracking');
12
7
 
13
8
  const {
14
9
  addConfigOptions,
15
10
  addAccountOptions,
16
11
  addUseEnvironmentOptions,
17
- setLogLevel,
18
12
  getAccountId,
19
13
  } = require('../../lib/commonOpts');
20
- const { logDebugInfo } = require('../../lib/debugInfo');
14
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
15
+
16
+ const i18nKey = 'cli.commands.hubdb.subcommands.fetch';
21
17
 
22
18
  exports.command = 'fetch <tableId> [dest]';
23
- exports.describe = 'fetch a HubDB table';
19
+ exports.describe = i18n(`${i18nKey}.describe`);
24
20
 
25
21
  exports.handler = async options => {
26
- const { config: configPath, tableId, dest } = options;
22
+ const { tableId, dest } = options;
27
23
 
28
- setLogLevel(options);
29
- logDebugInfo(options);
30
- loadConfig(configPath, options);
31
- checkAndWarnGitInclusion();
24
+ await loadAndValidateOptions(options);
32
25
 
33
- if (!(validateConfig() && (await validateAccount(options)))) {
34
- process.exit(1);
35
- }
36
26
  const accountId = getAccountId(options);
37
27
 
38
28
  trackCommandUsage('hubdb-fetch', {}, accountId);
@@ -40,7 +30,12 @@ exports.handler = async options => {
40
30
  try {
41
31
  const { filePath } = await downloadHubDbTable(accountId, tableId, dest);
42
32
 
43
- logger.log(`Downloaded HubDB table ${tableId} to ${filePath}`);
33
+ logger.success(
34
+ i18n(`${i18nKey}.success.fetch`, {
35
+ path: filePath,
36
+ tableId,
37
+ })
38
+ );
44
39
  } catch (e) {
45
40
  logErrorInstance(e);
46
41
  }
@@ -52,12 +47,12 @@ exports.builder = yargs => {
52
47
  addUseEnvironmentOptions(yargs, true);
53
48
 
54
49
  yargs.positional('tableId', {
55
- describe: 'HubDB Table ID',
50
+ describe: i18n(`${i18nKey}.positionals.tableId.describe`),
56
51
  type: 'string',
57
52
  });
58
53
 
59
54
  yargs.positional('dest', {
60
- describe: 'Local destination folder to fetch table to',
55
+ describe: i18n(`${i18nKey}.positionals.dest.describe`),
61
56
  type: 'string',
62
57
  });
63
58
  };
package/commands/hubdb.js CHANGED
@@ -3,9 +3,12 @@ const createCommand = require('./hubdb/create');
3
3
  const fetchCommand = require('./hubdb/fetch');
4
4
  const deleteCommand = require('./hubdb/delete');
5
5
  const clearCommand = require('./hubdb/clear');
6
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
7
+
8
+ const i18nKey = 'cli.commands.hubdb';
6
9
 
7
10
  exports.command = 'hubdb';
8
- exports.describe = 'Manage HubDB tables';
11
+ exports.describe = i18n(`${i18nKey}.describe`);
9
12
 
10
13
  exports.builder = yargs => {
11
14
  addConfigOptions(yargs, true);
package/commands/init.js CHANGED
@@ -18,6 +18,7 @@ const {
18
18
  API_KEY_AUTH_METHOD,
19
19
  ENVIRONMENTS,
20
20
  } = require('@hubspot/cli-lib/lib/constants');
21
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
21
22
  const { logger } = require('@hubspot/cli-lib/logger');
22
23
  const {
23
24
  updateConfigWithPersonalAccessKey,
@@ -34,6 +35,9 @@ const {
34
35
  } = require('../lib/prompts');
35
36
  const { logDebugInfo } = require('../lib/debugInfo');
36
37
  const { authenticateWithOauth } = require('../lib/oauth');
38
+ const { EXIT_CODES } = require('../lib/enums/exitCodes');
39
+
40
+ const i18nKey = 'cli.commands.init';
37
41
 
38
42
  const TRACKING_STATUS = {
39
43
  STARTED: 'started',
@@ -82,7 +86,9 @@ const CONFIG_CREATION_FLOWS = {
82
86
  };
83
87
 
84
88
  exports.command = 'init';
85
- exports.describe = `initialize ${DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME} for a HubSpot account`;
89
+ exports.describe = i18n(`${i18nKey}.describe`, {
90
+ configName: DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
91
+ });
86
92
 
87
93
  exports.handler = async options => {
88
94
  const { auth: authType = PERSONAL_ACCESS_KEY_AUTH_METHOD.value, c } = options;
@@ -95,11 +101,13 @@ exports.handler = async options => {
95
101
  const env = options.qa ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD;
96
102
 
97
103
  if (fs.existsSync(configPath)) {
98
- logger.error(`The config file '${configPath}' already exists.`);
99
- logger.info(
100
- 'To update an existing config file, use the "hs auth" command.'
104
+ logger.error(
105
+ i18n(`${i18nKey}.errors.configFileExists`, {
106
+ configPath,
107
+ })
101
108
  );
102
- process.exit(1);
109
+ logger.info(i18n(`${i18nKey}.info.updateConfig`));
110
+ process.exit(EXIT_CODES.ERROR);
103
111
  }
104
112
 
105
113
  trackAuthAction('init', authType, TRACKING_STATUS.STARTED);
@@ -111,12 +119,15 @@ exports.handler = async options => {
111
119
  const configPath = getConfigPath();
112
120
 
113
121
  logger.success(
114
- `The config file "${configPath}" was created using "${authType}" for account ${name ||
115
- accountId}.`
122
+ i18n(`${i18nKey}.success.configFileCreated`, {
123
+ configPath,
124
+ authType,
125
+ account: name || accountId,
126
+ })
116
127
  );
117
128
 
118
129
  trackAuthAction('init', authType, TRACKING_STATUS.COMPLETE, accountId);
119
- process.exit();
130
+ process.exit(EXIT_CODES.SUCCESS);
120
131
  } catch (err) {
121
132
  logErrorInstance(err);
122
133
  trackAuthAction('init', authType, TRACKING_STATUS.ERROR);
@@ -125,8 +136,7 @@ exports.handler = async options => {
125
136
 
126
137
  exports.builder = yargs => {
127
138
  yargs.option('auth', {
128
- describe:
129
- 'specify auth method to use ["personalaccesskey", "oauth2", "apikey"]',
139
+ describe: i18n(`${i18nKey}.options.auth.describe`),
130
140
  type: 'string',
131
141
  choices: [
132
142
  `${PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
@@ -134,7 +144,9 @@ exports.builder = yargs => {
134
144
  `${API_KEY_AUTH_METHOD.value}`,
135
145
  ],
136
146
  default: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
137
- defaultDescription: `"${PERSONAL_ACCESS_KEY_AUTH_METHOD.value}": \nAn access token tied to a specific user account. This is the recommended way of authenticating with local development tools.`,
147
+ defaultDescription: i18n(`${i18nKey}.options.auth.defaultDescription`, {
148
+ defaultType: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
149
+ }),
138
150
  });
139
151
 
140
152
  addConfigOptions(yargs, true);
package/commands/lint.js CHANGED
@@ -2,36 +2,21 @@ const {
2
2
  lint,
3
3
  printHublValidationResult,
4
4
  } = require('@hubspot/cli-lib/validate');
5
- const {
6
- loadConfig,
7
- validateConfig,
8
- checkAndWarnGitInclusion,
9
- } = require('@hubspot/cli-lib');
10
5
  const { logger } = require('@hubspot/cli-lib/logger');
11
6
  const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
12
7
 
13
8
  const {
14
9
  addConfigOptions,
15
10
  addAccountOptions,
16
- setLogLevel,
17
11
  getAccountId,
18
12
  } = require('../lib/commonOpts');
19
- const { logDebugInfo } = require('../lib/debugInfo');
20
13
  const { resolveLocalPath } = require('../lib/filesystem');
21
- const { validateAccount } = require('../lib/validation');
22
14
  const { trackCommandUsage } = require('../lib/usageTracking');
15
+ const { loadAndValidateOptions } = require('../lib/validation');
16
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
23
17
 
24
- const loadAndValidateOptions = async options => {
25
- setLogLevel(options);
26
- logDebugInfo(options);
27
- const { config: configPath } = options;
28
- loadConfig(configPath);
29
- checkAndWarnGitInclusion();
30
-
31
- if (!(validateConfig() && (await validateAccount(options)))) {
32
- process.exit(1);
33
- }
34
- };
18
+ const i18nKey = 'cli.commands.lint';
19
+ const { EXIT_CODES } = require('../lib/enums/exitCodes');
35
20
 
36
21
  exports.command = 'lint <path>';
37
22
  // Hiding since this command is still experimental
@@ -44,7 +29,9 @@ exports.handler = async options => {
44
29
 
45
30
  const accountId = getAccountId(options);
46
31
  const localPath = resolveLocalPath(lintPath);
47
- const groupName = `Linting "${localPath}"`;
32
+ const groupName = i18n(`${i18nKey}.groupName`, {
33
+ path: localPath,
34
+ });
48
35
 
49
36
  trackCommandUsage('lint', {}, accountId);
50
37
 
@@ -57,17 +44,21 @@ exports.handler = async options => {
57
44
  } catch (err) {
58
45
  logger.groupEnd(groupName);
59
46
  logErrorInstance(err, { accountId });
60
- process.exit(1);
47
+ process.exit(EXIT_CODES.ERROR);
61
48
  }
62
49
  logger.groupEnd(groupName);
63
- logger.log(`${count} issues found`);
50
+ logger.log(
51
+ i18n(`${i18nKey}.issuesFound`, {
52
+ count,
53
+ })
54
+ );
64
55
  };
65
56
 
66
57
  exports.builder = yargs => {
67
58
  addConfigOptions(yargs, true);
68
59
  addAccountOptions(yargs, true);
69
60
  yargs.positional('path', {
70
- describe: 'Local folder to lint',
61
+ describe: i18n(`${i18nKey}.positionals.path.describe`),
71
62
  type: 'string',
72
63
  });
73
64
  return yargs;
package/commands/list.js CHANGED
@@ -2,19 +2,12 @@ const chalk = require('chalk');
2
2
  const {
3
3
  addAccountOptions,
4
4
  addConfigOptions,
5
- setLogLevel,
6
5
  getAccountId,
7
6
  addUseEnvironmentOptions,
8
7
  } = require('../lib/commonOpts');
9
8
  const { trackCommandUsage } = require('../lib/usageTracking');
10
- const { logDebugInfo } = require('../lib/debugInfo');
11
- const { validateAccount } = require('../lib/validation');
12
9
  const { isPathFolder } = require('../lib/filesystem');
13
- const {
14
- loadConfig,
15
- validateConfig,
16
- checkAndWarnGitInclusion,
17
- } = require('@hubspot/cli-lib');
10
+
18
11
  const { logger } = require('@hubspot/cli-lib/logger');
19
12
  const {
20
13
  logApiErrorInstance,
@@ -27,24 +20,17 @@ const {
27
20
  HUBSPOT_FOLDER,
28
21
  MARKETPLACE_FOLDER,
29
22
  } = require('@hubspot/cli-lib/lib/constants');
23
+ const { loadAndValidateOptions } = require('../lib/validation');
24
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
30
25
 
31
- const loadAndValidateOptions = async options => {
32
- setLogLevel(options);
33
- logDebugInfo(options);
34
- const { config: configPath } = options;
35
- loadConfig(configPath, options);
36
- checkAndWarnGitInclusion();
37
-
38
- if (!(validateConfig() && (await validateAccount(options)))) {
39
- process.exit(1);
40
- }
41
- };
26
+ const i18nKey = 'cli.commands.list';
27
+ const { EXIT_CODES } = require('../lib/enums/exitCodes');
42
28
 
43
29
  exports.command = 'list [path]';
44
- exports.describe = 'list remote contents of a directory';
30
+ exports.describe = i18n(`${i18nKey}.describe`);
45
31
 
46
32
  exports.handler = async options => {
47
- loadAndValidateOptions(options);
33
+ await loadAndValidateOptions(options);
48
34
 
49
35
  const { path } = options;
50
36
  const directoryPath = path || '/';
@@ -53,7 +39,11 @@ exports.handler = async options => {
53
39
 
54
40
  trackCommandUsage('list', {}, accountId);
55
41
 
56
- logger.debug(`Getting contents of ${directoryPath}`);
42
+ logger.debug(
43
+ i18n(`${i18nKey}.gettingPathContents`, {
44
+ path: directoryPath,
45
+ })
46
+ );
57
47
 
58
48
  try {
59
49
  contentsResp = await getDirectoryContentsByPath(accountId, directoryPath);
@@ -63,7 +53,7 @@ exports.handler = async options => {
63
53
  e,
64
54
  new ApiErrorContext({ accountId, directoryPath })
65
55
  );
66
- process.exit();
56
+ process.exit(EXIT_CODES.SUCCESS);
67
57
  }
68
58
 
69
59
  if (contentsResp.children.length) {
@@ -98,13 +88,17 @@ exports.handler = async options => {
98
88
 
99
89
  logger.log(folderContentsOutput);
100
90
  } else {
101
- logger.info(`No files found in ${directoryPath}`);
91
+ logger.info(
92
+ i18n(`${i18nKey}.noFilesFoundInPath`, {
93
+ path: directoryPath,
94
+ })
95
+ );
102
96
  }
103
97
  };
104
98
 
105
99
  exports.builder = yargs => {
106
100
  yargs.positional('path', {
107
- describe: 'Remote directory to list contents',
101
+ describe: i18n(`${i18nKey}.positionals.path.describe`),
108
102
  type: 'string',
109
103
  });
110
104
  yargs.example([['$0 list'], ['$0 list /'], ['$0 list serverless']]);
package/commands/logs.js CHANGED
@@ -1,51 +1,31 @@
1
- const ora = require('ora');
1
+ const Spinnies = require('spinnies');
2
2
  const {
3
3
  addAccountOptions,
4
4
  addConfigOptions,
5
- setLogLevel,
6
5
  getAccountId,
7
6
  addUseEnvironmentOptions,
8
7
  } = require('../lib/commonOpts');
9
8
  const { trackCommandUsage } = require('../lib/usageTracking');
10
- const { logDebugInfo } = require('../lib/debugInfo');
11
- const {
12
- loadConfig,
13
- validateConfig,
14
- checkAndWarnGitInclusion,
15
- } = require('@hubspot/cli-lib');
16
9
  const { logger } = require('@hubspot/cli-lib/logger');
17
- const {
18
- logServerlessFunctionApiErrorInstance,
19
- ApiErrorContext,
20
- } = require('@hubspot/cli-lib/errorHandlers');
21
10
  const { outputLogs } = require('@hubspot/cli-lib/lib/logs');
22
- const {
23
- getFunctionByPath,
24
- getAppFunctionLogs,
25
- getLatestAppFunctionLogs,
26
- } = require('@hubspot/cli-lib/api/functions');
27
11
  const {
28
12
  getFunctionLogs,
29
13
  getLatestFunctionLog,
30
14
  } = require('@hubspot/cli-lib/api/results');
31
- const { validateAccount } = require('../lib/validation');
32
15
  const { tailLogs } = require('../lib/serverlessLogs');
16
+ const { loadAndValidateOptions } = require('../lib/validation');
17
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
33
18
 
34
- const loadAndValidateOptions = async options => {
35
- setLogLevel(options);
36
- logDebugInfo(options);
37
- const { config: configPath } = options;
38
- loadConfig(configPath, options);
39
- checkAndWarnGitInclusion();
19
+ const i18nKey = 'cli.commands.logs';
40
20
 
41
- if (!(validateConfig() && (await validateAccount(options)))) {
42
- process.exit(1);
43
- }
44
- };
45
-
46
- const handleLatestLogsError = e => {
21
+ const handleLogsError = (e, accountId, functionPath) => {
47
22
  if (e.statusCode === 404) {
48
- logger.log('No logs found.');
23
+ logger.error(
24
+ i18n(`${i18nKey}.errors.noLogsFound`, {
25
+ accountId,
26
+ functionPath,
27
+ })
28
+ );
49
29
  }
50
30
  };
51
31
 
@@ -53,100 +33,49 @@ const endpointLog = async (accountId, options) => {
53
33
  const { latest, follow, compact, endpoint: functionPath } = options;
54
34
 
55
35
  logger.debug(
56
- `Getting ${
57
- latest ? 'latest ' : ''
58
- }logs for function with path: ${functionPath}`
59
- );
60
-
61
- const functionResp = await getFunctionByPath(accountId, functionPath).catch(
62
- async e => {
63
- await logServerlessFunctionApiErrorInstance(
64
- accountId,
65
- e,
66
- new ApiErrorContext({ accountId, functionPath })
67
- );
68
- process.exit();
69
- }
36
+ i18n(`${i18nKey}.gettingLogs`, {
37
+ latest,
38
+ functionPath,
39
+ })
70
40
  );
71
- const functionId = functionResp.id;
72
-
73
- logger.debug(`Retrieving logs for functionId: ${functionResp.id}`);
74
41
 
75
42
  let logsResp;
76
43
 
77
44
  if (follow) {
78
- const spinner = ora(
79
- `Waiting for log entries for '${functionPath}' on account '${accountId}'.\n`
80
- );
81
- const tailCall = after => getFunctionLogs(accountId, functionId, { after });
82
- const fetchLatest = () => {
83
- try {
84
- getLatestFunctionLog(accountId, functionId);
85
- } catch (e) {
86
- handleLatestLogsError(e);
87
- }
88
- };
45
+ const spinnies = new Spinnies();
89
46
 
90
- await tailLogs({
91
- accountId,
92
- compact,
93
- spinner,
94
- tailCall,
95
- fetchLatest,
47
+ spinnies.add('tailLogs', {
48
+ text: i18n(`${i18nKey}.tailLogs`),
96
49
  });
97
- } else if (latest) {
98
- try {
99
- logsResp = await getLatestFunctionLog(accountId, functionResp.id);
100
- } catch (e) {
101
- handleLatestLogsError(e);
102
- }
103
- } else {
104
- logsResp = await getFunctionLogs(accountId, functionResp.id, options);
105
- }
106
-
107
- if (logsResp) {
108
- return outputLogs(logsResp, options);
109
- }
110
- };
111
-
112
- const appFunctionLog = async (accountId, options) => {
113
- const { latest, follow, compact, functionName, appPath } = options;
114
-
115
- let logsResp;
116
-
117
- if (follow) {
118
- const spinner = ora(
119
- `Waiting for log entries for "${functionName}" on account "${accountId}".\n`
120
- );
121
50
  const tailCall = after =>
122
- getAppFunctionLogs(accountId, functionName, appPath, { after });
51
+ getFunctionLogs(accountId, functionPath, { after });
123
52
  const fetchLatest = () => {
124
53
  try {
125
- getLatestAppFunctionLogs(accountId, functionName, appPath);
54
+ return getLatestFunctionLog(accountId, functionPath);
126
55
  } catch (e) {
127
- handleLatestLogsError(e);
56
+ handleLogsError(e, accountId, functionPath);
128
57
  }
129
58
  };
130
59
 
131
60
  await tailLogs({
132
61
  accountId,
133
62
  compact,
134
- spinner,
63
+ spinnies,
135
64
  tailCall,
136
65
  fetchLatest,
137
66
  });
138
67
  } else if (latest) {
139
68
  try {
140
- logsResp = await getLatestAppFunctionLogs(
141
- accountId,
142
- functionName,
143
- appPath
144
- );
69
+ logsResp = await getLatestFunctionLog(accountId, functionPath);
145
70
  } catch (e) {
146
- handleLatestLogsError(e);
71
+ handleLogsError(e, accountId, functionPath);
147
72
  }
148
73
  } else {
149
- logsResp = await getAppFunctionLogs(accountId, functionName, appPath, {});
74
+ try {
75
+ logsResp = await getFunctionLogs(accountId, functionPath, options);
76
+ } catch (e) {
77
+ handleLogsError(e, accountId, functionPath);
78
+ }
150
79
  }
151
80
 
152
81
  if (logsResp) {
@@ -155,58 +84,44 @@ const appFunctionLog = async (accountId, options) => {
155
84
  };
156
85
 
157
86
  exports.command = 'logs [endpoint]';
158
- exports.describe = 'get logs for a function';
87
+ exports.describe = i18n(`${i18nKey}.describe`);
159
88
 
160
89
  exports.handler = async options => {
161
- loadAndValidateOptions(options);
90
+ await loadAndValidateOptions(options);
162
91
 
163
- const { latest, functionName } = options;
92
+ const { latest } = options;
164
93
 
165
94
  const accountId = getAccountId(options);
166
95
 
167
96
  trackCommandUsage('logs', { latest }, accountId);
168
97
 
169
- if (functionName) {
170
- appFunctionLog(accountId, options);
171
- } else {
172
- endpointLog(accountId, options);
173
- }
98
+ endpointLog(accountId, options);
174
99
  };
175
100
 
176
101
  exports.builder = yargs => {
177
102
  yargs.positional('endpoint', {
178
- describe: 'Serverless function endpoint',
103
+ describe: i18n(`${i18nKey}.positionals.endpoint.describe`),
179
104
  type: 'string',
180
105
  });
181
106
  yargs
182
107
  .options({
183
- appPath: {
184
- describe: 'path to the app',
185
- type: 'string',
186
- hidden: true,
187
- },
188
- functionName: {
189
- describe: 'app function name',
190
- type: 'string',
191
- hidden: true,
192
- },
193
108
  latest: {
194
109
  alias: 'l',
195
- describe: 'retrieve most recent log only',
110
+ describe: i18n(`${i18nKey}.options.latest.describe`),
196
111
  type: 'boolean',
197
112
  },
198
113
  compact: {
199
- describe: 'output compact logs',
114
+ describe: i18n(`${i18nKey}.options.compact.describe`),
200
115
  type: 'boolean',
201
116
  },
202
117
  follow: {
203
118
  alias: ['t', 'tail', 'f'],
204
- describe: 'follow logs',
119
+ describe: i18n(`${i18nKey}.options.follow.describe`),
205
120
  type: 'boolean',
206
121
  },
207
122
  limit: {
208
123
  alias: ['limit', 'n', 'max-count'],
209
- describe: 'limit the number of logs to output',
124
+ describe: i18n(`${i18nKey}.options.limit.describe`),
210
125
  type: 'number',
211
126
  },
212
127
  })
@@ -214,18 +129,9 @@ exports.builder = yargs => {
214
129
  .conflicts('functionName', 'endpoint');
215
130
 
216
131
  yargs.example([
217
- [
218
- '$0 logs my-endpoint',
219
- 'Get 5 most recent logs for function residing at /_hcms/api/my-endpoint',
220
- ],
221
- [
222
- '$0 logs my-endpoint --limit=10',
223
- 'Get 10 most recent logs for function residing at /_hcms/api/my-endpoint',
224
- ],
225
- [
226
- '$0 logs my-endpoint --follow',
227
- 'Poll for and output logs for function residing at /_hcms/api/my-endpoint immediately upon new execution',
228
- ],
132
+ ['$0 logs my-endpoint', i18n(`${i18nKey}.examples.default`)],
133
+ ['$0 logs my-endpoint --limit=10', i18n(`${i18nKey}.examples.limit`)],
134
+ ['$0 logs my-endpoint --follow', i18n(`${i18nKey}.examples.follow`)],
229
135
  ]);
230
136
 
231
137
  addConfigOptions(yargs, true);