@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,11 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
 
4
- const {
5
- loadConfig,
6
- validateConfig,
7
- checkAndWarnGitInclusion,
8
- } = require('@hubspot/cli-lib');
9
4
  const { uploadFolder } = require('@hubspot/cli-lib/fileManager');
10
5
  const { uploadFile } = require('@hubspot/cli-lib/api/fileManager');
11
6
  const { getCwd, convertToUnixPath } = require('@hubspot/cli-lib/path');
@@ -22,28 +17,22 @@ const {
22
17
  addConfigOptions,
23
18
  addAccountOptions,
24
19
  addUseEnvironmentOptions,
25
- setLogLevel,
26
20
  getAccountId,
27
21
  } = require('../../lib/commonOpts');
28
- const { logDebugInfo } = require('../../lib/debugInfo');
29
- const { validateAccount } = require('../../lib/validation');
22
+ const { loadAndValidateOptions } = require('../../lib/validation');
30
23
  const { trackCommandUsage } = require('../../lib/usageTracking');
24
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
25
+
26
+ const i18nKey = 'cli.commands.filemanager.subcommands.upload';
27
+ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
31
28
 
32
29
  exports.command = 'upload <src> <dest>';
33
- exports.describe =
34
- 'Upload a folder or file from your computer to the HubSpot File Manager';
30
+ exports.describe = i18n(`${i18nKey}.describe`);
35
31
 
36
32
  exports.handler = async options => {
37
- const { config: configPath, src, dest } = options;
38
-
39
- setLogLevel(options);
40
- logDebugInfo(options);
41
- loadConfig(configPath, options);
42
- checkAndWarnGitInclusion();
33
+ const { src, dest } = options;
43
34
 
44
- if (!validateConfig() || !(await validateAccount(options))) {
45
- process.exit(1);
46
- }
35
+ await loadAndValidateOptions(options);
47
36
 
48
37
  const accountId = getAccountId(options);
49
38
  const absoluteSrcPath = path.resolve(getCwd(), src);
@@ -52,16 +41,24 @@ exports.handler = async options => {
52
41
  try {
53
42
  stats = fs.statSync(absoluteSrcPath);
54
43
  if (!stats.isFile() && !stats.isDirectory()) {
55
- logger.error(`The path "${src}" is not a path to a file or folder`);
44
+ logger.error(
45
+ i18n(`${i18nKey}.errors.invalidPath`, {
46
+ path: src,
47
+ })
48
+ );
56
49
  return;
57
50
  }
58
51
  } catch (e) {
59
- logger.error(`The path "${src}" is not a path to a file or folder`);
52
+ logger.error(
53
+ i18n(`${i18nKey}.errors.invalidPath`, {
54
+ path: src,
55
+ })
56
+ );
60
57
  return;
61
58
  }
62
59
 
63
60
  if (!dest) {
64
- logger.error('A destination path needs to be passed');
61
+ logger.error(i18n(`${i18nKey}.errors.destinationRequired`));
65
62
  return;
66
63
  }
67
64
  const normalizedDest = convertToUnixPath(dest);
@@ -77,26 +74,36 @@ exports.handler = async options => {
77
74
  );
78
75
  if (srcDestIssues.length) {
79
76
  srcDestIssues.forEach(({ message }) => logger.error(message));
80
- process.exit(1);
77
+ process.exit(EXIT_CODES.ERROR);
81
78
  }
82
79
 
83
80
  if (stats.isFile()) {
84
81
  if (shouldIgnoreFile(absoluteSrcPath)) {
85
- logger.error(`The file "${src}" is being ignored via an .hsignore rule`);
82
+ logger.error(
83
+ i18n(`${i18nKey}.errors.fileIgnored`, {
84
+ path: src,
85
+ })
86
+ );
86
87
  return;
87
88
  }
88
89
 
89
90
  uploadFile(accountId, absoluteSrcPath, normalizedDest)
90
91
  .then(() => {
91
92
  logger.success(
92
- 'Uploaded file from "%s" to "%s" in the File Manager of account %s',
93
- src,
94
- normalizedDest,
95
- accountId
93
+ i18n(`${i18nKey}.success.upload`, {
94
+ accountId,
95
+ dest: normalizedDest,
96
+ src,
97
+ })
96
98
  );
97
99
  })
98
100
  .catch(error => {
99
- logger.error('Uploading file "%s" to "%s" failed', src, normalizedDest);
101
+ logger.error(
102
+ i18n(`${i18nKey}.errors.upload`, {
103
+ dest: normalizedDest,
104
+ src,
105
+ })
106
+ );
100
107
  logApiUploadErrorInstance(
101
108
  error,
102
109
  new ApiErrorContext({
@@ -108,16 +115,22 @@ exports.handler = async options => {
108
115
  });
109
116
  } else {
110
117
  logger.log(
111
- `Uploading files from "${src}" to "${dest}" in the File Manager of account ${accountId}`
118
+ i18n(`${i18nKey}.logs.uploading`, {
119
+ accountId,
120
+ dest,
121
+ src,
122
+ })
112
123
  );
113
124
  uploadFolder(accountId, absoluteSrcPath, dest)
114
125
  .then(() => {
115
126
  logger.success(
116
- `Uploading files to "${dest}" in the File Manager is complete`
127
+ i18n(`${i18nKey}.success.uploadComplete`, {
128
+ dest,
129
+ })
117
130
  );
118
131
  })
119
132
  .catch(error => {
120
- logger.error('Uploading failed');
133
+ logger.error(i18n(`${i18nKey}.errors.uploadingFailed`));
121
134
  logErrorInstance(error, {
122
135
  accountId,
123
136
  });
@@ -131,12 +144,11 @@ exports.builder = yargs => {
131
144
  addUseEnvironmentOptions(yargs, true);
132
145
 
133
146
  yargs.positional('src', {
134
- describe:
135
- 'Path to the local file, relative to your current working directory',
147
+ describe: i18n(`${i18nKey}.positionals.src.describe`),
136
148
  type: 'string',
137
149
  });
138
150
  yargs.positional('dest', {
139
- describe: 'Path in HubSpot Design Tools, can be a net new path',
151
+ describe: i18n(`${i18nKey}.positionals.dest.describe`),
140
152
  type: 'string',
141
153
  });
142
154
  };
@@ -5,9 +5,12 @@ const {
5
5
  } = require('../lib/commonOpts');
6
6
  const upload = require('./filemanager/upload');
7
7
  const fetch = require('./filemanager/fetch');
8
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
9
+
10
+ const i18nKey = 'cli.commands.filemanager';
8
11
 
9
12
  exports.command = 'filemanager';
10
- exports.describe = 'Commands for working with the File Manager';
13
+ exports.describe = i18n(`${i18nKey}.describe`);
11
14
 
12
15
  exports.builder = yargs => {
13
16
  addOverwriteOptions(yargs, true);
@@ -2,17 +2,10 @@ const ora = require('ora');
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 {
17
10
  logApiErrorInstance,
18
11
  ApiErrorContext,
@@ -23,14 +16,11 @@ const {
23
16
  buildPackage,
24
17
  getBuildStatus,
25
18
  } = require('@hubspot/cli-lib/api/functions');
26
- const { validateAccount } = require('../../lib/validation');
19
+ const { loadAndValidateOptions } = require('../../lib/validation');
27
20
  const { outputBuildLog } = require('../../lib/serverlessLogs');
21
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
28
22
 
29
- const makeSpinner = (actionText, functionPath, accountIdentifier) => {
30
- return ora(
31
- `${actionText} bundle for '${functionPath}' on account '${accountIdentifier}'.\n`
32
- );
33
- };
23
+ const i18nKey = 'cli.commands.functions.subcommands.deploy';
34
24
 
35
25
  const pollBuildStatus = (accountId, buildId) => {
36
26
  return new Promise((resolve, reject) => {
@@ -49,23 +39,11 @@ const pollBuildStatus = (accountId, buildId) => {
49
39
  });
50
40
  };
51
41
 
52
- const loadAndValidateOptions = async options => {
53
- setLogLevel(options);
54
- logDebugInfo(options);
55
- const { config: configPath } = options;
56
- loadConfig(configPath, options);
57
- checkAndWarnGitInclusion();
58
-
59
- if (!(validateConfig() && (await validateAccount(options)))) {
60
- process.exit(1);
61
- }
62
- };
63
-
64
42
  exports.command = 'deploy <path>';
65
43
  exports.describe = false;
66
44
 
67
45
  exports.handler = async options => {
68
- loadAndValidateOptions(options);
46
+ await loadAndValidateOptions(options);
69
47
 
70
48
  const { path: functionPath } = options;
71
49
  const accountId = getAccountId(options);
@@ -78,19 +56,26 @@ exports.handler = async options => {
78
56
  !splitFunctionPath.length ||
79
57
  splitFunctionPath[splitFunctionPath.length - 1] !== 'functions'
80
58
  ) {
81
- logger.error(`Specified path ${functionPath} is not a .functions folder.`);
59
+ logger.error(
60
+ i18n(`${i18nKey}.errors.notFunctionsFolder`, {
61
+ functionPath,
62
+ })
63
+ );
82
64
  return;
83
65
  }
84
66
 
85
67
  logger.debug(
86
- `Starting build and deploy for .functions folder with path: ${functionPath}`
68
+ i18n(`${i18nKey}.debug.startingBuildAndDeploy`, {
69
+ functionPath,
70
+ })
87
71
  );
88
72
 
89
73
  try {
90
- spinner = makeSpinner(
91
- 'Building and deploying',
92
- functionPath,
93
- accountId
74
+ spinner = ora(
75
+ i18n(`${i18nKey}.loading`, {
76
+ accountId,
77
+ functionPath,
78
+ })
94
79
  ).start();
95
80
  const buildId = await buildPackage(accountId, functionPath);
96
81
  const successResp = await pollBuildStatus(accountId, buildId);
@@ -98,17 +83,29 @@ exports.handler = async options => {
98
83
  spinner.stop();
99
84
  await outputBuildLog(successResp.cdnUrl);
100
85
  logger.success(
101
- `Built and deployed bundle from package.json for ${functionPath} on account ${accountId} in ${buildTimeSeconds}s.`
86
+ i18n(`${i18nKey}.success.deploy`, {
87
+ accountId,
88
+ buildTimeSeconds,
89
+ functionPath,
90
+ })
102
91
  );
103
92
  } catch (e) {
104
93
  spinner && spinner.stop && spinner.stop();
105
94
  if (e.statusCode === 404) {
106
- logger.error(`Unable to find package.json for function ${functionPath}.`);
95
+ logger.error(
96
+ i18n(`${i18nKey}.errors.noPackageJson`, {
97
+ functionPath,
98
+ })
99
+ );
107
100
  } else if (e.statusCode === 400) {
108
101
  logger.error(e.error.message);
109
102
  } else if (e.status === 'ERROR') {
110
103
  await outputBuildLog(e.cdnUrl);
111
- logger.error(`Build error: ${e.errorReason}`);
104
+ logger.error(
105
+ i18n(`${i18nKey}.errors.buildError`, {
106
+ details: e.errorReason,
107
+ })
108
+ );
112
109
  } else {
113
110
  logApiErrorInstance(
114
111
  accountId,
@@ -121,14 +118,14 @@ exports.handler = async options => {
121
118
 
122
119
  exports.builder = yargs => {
123
120
  yargs.positional('path', {
124
- describe: 'Path to .functions folder',
121
+ describe: i18n(`${i18nKey}.positionals.path.describe`),
125
122
  type: 'string',
126
123
  });
127
124
 
128
125
  yargs.example([
129
126
  [
130
127
  '$0 functions deploy myFunctionFolder.functions',
131
- 'Build and deploy a new bundle for all functions within the myFunctionFolder.functions folder',
128
+ i18n(`${i18nKey}.examples.default`),
132
129
  ],
133
130
  ]);
134
131
 
@@ -5,11 +5,6 @@ const {
5
5
  ApiErrorContext,
6
6
  } = require('@hubspot/cli-lib/errorHandlers');
7
7
  const { getFunctionArrays } = require('@hubspot/cli-lib/lib/functions');
8
- const {
9
- loadConfig,
10
- validateConfig,
11
- checkAndWarnGitInclusion,
12
- } = require('@hubspot/cli-lib');
13
8
  const {
14
9
  getTableContents,
15
10
  getTableHeader,
@@ -20,26 +15,16 @@ const {
20
15
  addAccountOptions,
21
16
  addUseEnvironmentOptions,
22
17
  getAccountId,
23
- setLogLevel,
24
18
  } = require('../../lib/commonOpts');
25
19
  const { trackCommandUsage } = require('../../lib/usageTracking');
26
- const { logDebugInfo } = require('../../lib/debugInfo');
27
- const { validateAccount } = require('../../lib/validation');
28
-
29
- const loadAndValidateOptions = async options => {
30
- setLogLevel(options);
31
- logDebugInfo(options);
32
- const { config: configPath } = options;
33
- loadConfig(configPath, options);
34
- checkAndWarnGitInclusion();
20
+ const { loadAndValidateOptions } = require('../../lib/validation');
21
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
35
22
 
36
- if (!(validateConfig() && (await validateAccount(options)))) {
37
- process.exit(1);
38
- }
39
- };
23
+ const i18nKey = 'cli.commands.functions.subcommands.list';
24
+ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
40
25
 
41
26
  exports.command = 'list';
42
- exports.describe = 'List currently deployed functions';
27
+ exports.describe = i18n(`${i18nKey}.describe`);
43
28
 
44
29
  exports.handler = async options => {
45
30
  loadAndValidateOptions(options);
@@ -49,15 +34,15 @@ exports.handler = async options => {
49
34
 
50
35
  trackCommandUsage('functions-list', { json, compact }, accountId);
51
36
 
52
- logger.debug('Getting currently deployed functions');
37
+ logger.debug(i18n(`${i18nKey}.debug.gettingFunctions`));
53
38
 
54
39
  const routesResp = await getRoutes(accountId).catch(async e => {
55
40
  await logApiErrorInstance(accountId, e, new ApiErrorContext({ accountId }));
56
- process.exit();
41
+ process.exit(EXIT_CODES.SUCCESS);
57
42
  });
58
43
 
59
44
  if (!routesResp.objects.length) {
60
- return logger.info('No functions found.');
45
+ return logger.info(i18n(`${i18nKey}.info.noFunctions`));
61
46
  }
62
47
 
63
48
  if (options.json) {
@@ -78,7 +63,7 @@ exports.builder = yargs => {
78
63
 
79
64
  yargs.options({
80
65
  json: {
81
- describe: 'output raw json data',
66
+ describe: i18n(`${i18nKey}.options.json.describe`),
82
67
  type: 'boolean',
83
68
  },
84
69
  });
@@ -1,38 +1,22 @@
1
1
  const {
2
2
  addAccountOptions,
3
3
  addConfigOptions,
4
- setLogLevel,
5
4
  getAccountId,
6
5
  addUseEnvironmentOptions,
7
6
  } = require('../../lib/commonOpts');
8
7
  const { trackCommandUsage } = require('../../lib/usageTracking');
9
- const { logDebugInfo } = require('../../lib/debugInfo');
10
- const {
11
- loadConfig,
12
- validateConfig,
13
- checkAndWarnGitInclusion,
14
- } = require('@hubspot/cli-lib');
15
8
  const { logger } = require('@hubspot/cli-lib/logger');
16
9
  const { start: startTestServer } = require('@hubspot/serverless-dev-runtime');
17
- const { validateAccount } = require('../../lib/validation');
18
-
19
- const loadAndValidateOptions = async options => {
20
- setLogLevel(options);
21
- logDebugInfo(options);
22
- const { config: configPath } = options;
23
- loadConfig(configPath, options);
24
- checkAndWarnGitInclusion();
10
+ const { loadAndValidateOptions } = require('../../lib/validation');
11
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
25
12
 
26
- if (!(validateConfig() && (await validateAccount(options)))) {
27
- process.exit(1);
28
- }
29
- };
13
+ const i18nKey = 'cli.commands.functions.subcommands.server';
30
14
 
31
15
  exports.command = 'server <path>';
32
16
  exports.describe = false;
33
17
 
34
18
  exports.handler = async options => {
35
- loadAndValidateOptions(options);
19
+ await loadAndValidateOptions(options);
36
20
 
37
21
  const { path: functionPath } = options;
38
22
  const accountId = getAccountId(options);
@@ -40,7 +24,9 @@ exports.handler = async options => {
40
24
  trackCommandUsage('functions-server', { functionPath }, accountId);
41
25
 
42
26
  logger.debug(
43
- `Starting local test server for .functions folder with path: ${functionPath}`
27
+ i18n(`${i18nKey}.debug.startingServer`, {
28
+ functionPath,
29
+ })
44
30
  );
45
31
 
46
32
  startTestServer({
@@ -51,28 +37,26 @@ exports.handler = async options => {
51
37
 
52
38
  exports.builder = yargs => {
53
39
  yargs.positional('path', {
54
- describe: 'Path to local .functions folder',
40
+ describe: i18n(`${i18nKey}.positionals.path.describe`),
55
41
  type: 'string',
56
42
  });
57
43
  yargs.option('port', {
58
- describe: 'port to run the test server on',
44
+ describe: i18n(`${i18nKey}.options.port.describe`),
59
45
  type: 'string',
60
46
  default: 5432,
61
47
  });
62
48
  yargs.option('contact', {
63
- describe: 'pass contact data to the test function',
49
+ describe: i18n(`${i18nKey}.options.contact.describe`),
64
50
  type: 'boolean',
65
51
  default: true,
66
52
  });
67
53
  yargs.option('watch', {
68
- describe:
69
- 'watch the specified .functions folder for changes and restart the server',
54
+ describe: i18n(`${i18nKey}.options.watch.describe`),
70
55
  type: 'boolean',
71
56
  default: true,
72
57
  });
73
58
  yargs.option('log-output', {
74
- describe:
75
- 'output the response body from the serverless function execution (It is suggested not to use this in production environments as it can reveal any secure data returned by the function in logs)',
59
+ describe: i18n(`${i18nKey}.options.logOutput.describe`),
76
60
  type: 'boolean',
77
61
  default: false,
78
62
  });
@@ -80,7 +64,7 @@ exports.builder = yargs => {
80
64
  yargs.example([
81
65
  [
82
66
  '$0 functions server ./tmp/myFunctionFolder.functions',
83
- 'Run a local function test server.',
67
+ i18n(`${i18nKey}.examples.default`),
84
68
  ],
85
69
  ]);
86
70
 
@@ -2,9 +2,12 @@ const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
2
2
  const list = require('./functions/list');
3
3
  const deploy = require('./functions/deploy');
4
4
  const server = require('./functions/server');
5
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
6
+
7
+ const i18nKey = 'cli.commands.functions';
5
8
 
6
9
  exports.command = 'functions';
7
- exports.describe = 'Commands for working with functions';
10
+ exports.describe = i18n(`${i18nKey}.describe`);
8
11
 
9
12
  exports.builder = yargs => {
10
13
  addConfigOptions(yargs, true);
@@ -1,39 +1,29 @@
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 { clearHubDbTableRows } = require('@hubspot/cli-lib/hubdb');
9
4
  const { publishTable } = require('@hubspot/cli-lib/api/hubdb');
10
5
 
11
- const { validateAccount } = require('../../lib/validation');
6
+ const { loadAndValidateOptions } = require('../../lib/validation');
12
7
  const { trackCommandUsage } = require('../../lib/usageTracking');
13
8
 
14
9
  const {
15
10
  addConfigOptions,
16
11
  addAccountOptions,
17
12
  addUseEnvironmentOptions,
18
- setLogLevel,
19
13
  getAccountId,
20
14
  } = require('../../lib/commonOpts');
21
- const { logDebugInfo } = require('../../lib/debugInfo');
15
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
16
+
17
+ const i18nKey = 'cli.commands.hubdb.subcommands.clear';
22
18
 
23
19
  exports.command = 'clear <tableId>';
24
- exports.describe = 'clear all rows in a HubDB table';
20
+ exports.describe = i18n(`${i18nKey}.describe`);
25
21
 
26
22
  exports.handler = async options => {
27
- const { config: configPath, tableId } = options;
23
+ const { tableId } = options;
28
24
 
29
- setLogLevel(options);
30
- logDebugInfo(options);
31
- loadConfig(configPath);
32
- checkAndWarnGitInclusion();
25
+ await loadAndValidateOptions(options);
33
26
 
34
- if (!(validateConfig() && (await validateAccount(options)))) {
35
- process.exit(1);
36
- }
37
27
  const accountId = getAccountId(options);
38
28
 
39
29
  trackCommandUsage('hubdb-clear', {}, accountId);
@@ -41,11 +31,25 @@ exports.handler = async options => {
41
31
  try {
42
32
  const { deletedRowCount } = await clearHubDbTableRows(accountId, tableId);
43
33
  if (deletedRowCount > 0) {
44
- logger.log(`Removed ${deletedRowCount} rows from HubDB table ${tableId}`);
34
+ logger.log(
35
+ i18n(`${i18nKey}.logs.removedRows`, {
36
+ deletedRowCount,
37
+ tableId,
38
+ })
39
+ );
45
40
  const { rowCount } = await publishTable(accountId, tableId);
46
- logger.log(`HubDB table ${tableId} now contains ${rowCount} rows`);
41
+ logger.log(
42
+ i18n(`${i18nKey}.logs.rowCount`, {
43
+ rowCount,
44
+ tableId,
45
+ })
46
+ );
47
47
  } else {
48
- logger.log(`HubDB table ${tableId} is already empty`);
48
+ logger.log(
49
+ i18n(`${i18nKey}.logs.emptyTable`, {
50
+ tableId,
51
+ })
52
+ );
49
53
  }
50
54
  } catch (e) {
51
55
  logErrorInstance(e);
@@ -58,7 +62,7 @@ exports.builder = yargs => {
58
62
  addUseEnvironmentOptions(yargs, true);
59
63
 
60
64
  yargs.positional('tableId', {
61
- describe: 'HubDB Table ID',
65
+ describe: i18n(`${i18nKey}.positionals.tableId.describe`),
62
66
  type: 'string',
63
67
  });
64
68
  };
@@ -1,39 +1,34 @@
1
1
  const path = require('path');
2
- const {
3
- loadConfig,
4
- validateConfig,
5
- checkAndWarnGitInclusion,
6
- } = require('@hubspot/cli-lib');
2
+
7
3
  const { logger } = require('@hubspot/cli-lib/logger');
8
4
  const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
9
5
  const { getCwd } = require('@hubspot/cli-lib/path');
10
6
  const { createHubDbTable } = require('@hubspot/cli-lib/hubdb');
11
7
 
12
- const { validateAccount, isFileValidJSON } = require('../../lib/validation');
8
+ const {
9
+ isFileValidJSON,
10
+ loadAndValidateOptions,
11
+ } = require('../../lib/validation');
13
12
  const { trackCommandUsage } = require('../../lib/usageTracking');
14
13
  const {
15
14
  addConfigOptions,
16
15
  addAccountOptions,
17
16
  addUseEnvironmentOptions,
18
- setLogLevel,
19
17
  getAccountId,
20
18
  } = require('../../lib/commonOpts');
21
- const { logDebugInfo } = require('../../lib/debugInfo');
19
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
20
+
21
+ const i18nKey = 'cli.commands.hubdb.subcommands.create';
22
+ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
22
23
 
23
24
  exports.command = 'create <src>';
24
- exports.describe = 'Create a HubDB table';
25
+ exports.describe = i18n(`${i18nKey}.describe`);
25
26
 
26
27
  exports.handler = async options => {
27
- const { config: configPath, src } = options;
28
+ const { src } = options;
28
29
 
29
- setLogLevel(options);
30
- logDebugInfo(options);
31
- loadConfig(configPath, options);
32
- checkAndWarnGitInclusion();
30
+ await loadAndValidateOptions(options);
33
31
 
34
- if (!(validateConfig() && (await validateAccount(options)))) {
35
- process.exit(1);
36
- }
37
32
  const accountId = getAccountId(options);
38
33
 
39
34
  trackCommandUsage('hubdb-create', {}, accountId);
@@ -41,18 +36,26 @@ exports.handler = async options => {
41
36
  try {
42
37
  const filePath = path.resolve(getCwd(), src);
43
38
  if (!isFileValidJSON(filePath)) {
44
- process.exit(1);
39
+ process.exit(EXIT_CODES.ERROR);
45
40
  }
46
41
 
47
42
  const table = await createHubDbTable(
48
43
  accountId,
49
44
  path.resolve(getCwd(), src)
50
45
  );
51
- logger.log(
52
- `The table ${table.tableId} was created in ${accountId} with ${table.rowCount} rows`
46
+ logger.success(
47
+ i18n(`${i18nKey}.success.create`, {
48
+ accountId,
49
+ rowCount: table.rowCount,
50
+ tableId: table.tableId,
51
+ })
53
52
  );
54
53
  } catch (e) {
55
- logger.error(`Creating the table at "${src}" failed`);
54
+ logger.error(
55
+ i18n(`${i18nKey}.errors.create`, {
56
+ src,
57
+ })
58
+ );
56
59
  logErrorInstance(e);
57
60
  }
58
61
  };
@@ -63,7 +66,7 @@ exports.builder = yargs => {
63
66
  addUseEnvironmentOptions(yargs, true);
64
67
 
65
68
  yargs.positional('src', {
66
- describe: 'local path to file used for import',
69
+ describe: i18n(`${i18nKey}.positionals.src.describe`),
67
70
  type: 'string',
68
71
  });
69
72
  };