@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,51 +1,51 @@
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
 
9
- const { validateAccount } = require('../../../lib/validation');
4
+ const { loadAndValidateOptions } = require('../../../lib/validation');
10
5
  const { trackCommandUsage } = require('../../../lib/usageTracking');
11
- const { setLogLevel, getAccountId } = require('../../../lib/commonOpts');
12
- const { logDebugInfo } = require('../../../lib/debugInfo');
6
+ const { getAccountId } = require('../../../lib/commonOpts');
13
7
  const { deleteSchema } = require('@hubspot/cli-lib/api/schema');
8
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
9
+
10
+ const i18nKey =
11
+ 'cli.commands.customObject.subcommands.schema.subcommands.delete';
14
12
 
15
13
  exports.command = 'delete <name>';
16
- exports.describe = 'Delete a custom object schema';
14
+ exports.describe = i18n(`${i18nKey}.describe`);
17
15
 
18
16
  exports.handler = async options => {
19
17
  let { name } = options;
20
18
 
21
- setLogLevel(options);
22
- logDebugInfo(options);
23
- loadConfig(options.config);
24
- checkAndWarnGitInclusion();
19
+ await loadAndValidateOptions(options);
25
20
 
26
- if (!(validateConfig() && (await validateAccount(options)))) {
27
- process.exit(1);
28
- }
29
21
  const accountId = getAccountId(options);
30
22
 
31
23
  trackCommandUsage('custom-object-schema-delete', null, accountId);
32
24
 
33
25
  try {
34
26
  await deleteSchema(accountId, name);
35
- logger.success(`Successfully initiated deletion of ${name}`);
27
+ logger.success(
28
+ i18n(`${i18nKey}.success.delete`, {
29
+ name,
30
+ })
31
+ );
36
32
  } catch (e) {
37
33
  logErrorInstance(e);
38
- logger.error(`Unable to delete ${name}`);
34
+ logger.error(
35
+ i18n(`${i18nKey}.errors.delete`, {
36
+ name,
37
+ })
38
+ );
39
39
  }
40
40
  };
41
41
 
42
42
  exports.builder = yargs => {
43
43
  yargs.example([
44
- ['$0 schema delete schemaName', 'Delete `schemaName` schema'],
44
+ ['$0 schema delete schemaName', i18n(`${i18nKey}.examples.default`)],
45
45
  ]);
46
46
 
47
47
  yargs.positional('name', {
48
- describe: 'Name of the target schema',
48
+ describe: i18n(`${i18nKey}.positionals.name.describe`),
49
49
  type: 'string',
50
50
  });
51
51
  };
@@ -1,56 +1,49 @@
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
 
9
- const { validateAccount } = require('../../../lib/validation');
4
+ const { loadAndValidateOptions } = require('../../../lib/validation');
10
5
  const { trackCommandUsage } = require('../../../lib/usageTracking');
11
- const { setLogLevel, getAccountId } = require('../../../lib/commonOpts');
12
- const { logDebugInfo } = require('../../../lib/debugInfo');
6
+ const { getAccountId } = require('../../../lib/commonOpts');
13
7
  const { downloadSchemas, getResolvedPath } = require('@hubspot/cli-lib/schema');
8
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
9
+
10
+ const i18nKey =
11
+ 'cli.commands.customObject.subcommands.schema.subcommands.fetchAll';
14
12
 
15
13
  exports.command = 'fetch-all [dest]';
16
- exports.describe = 'Fetch all custom object schemas for an account';
14
+ exports.describe = i18n(`${i18nKey}.describe`);
17
15
 
18
16
  exports.handler = async options => {
19
- setLogLevel(options);
20
- logDebugInfo(options);
21
- loadConfig(options.config);
22
- checkAndWarnGitInclusion();
17
+ await loadAndValidateOptions(options);
23
18
 
24
- if (!(validateConfig() && (await validateAccount(options)))) {
25
- process.exit(1);
26
- }
27
19
  const accountId = getAccountId(options);
28
20
 
29
21
  trackCommandUsage('custom-object-schema-fetch-all', null, accountId);
30
22
 
31
23
  try {
32
24
  await downloadSchemas(accountId, options.dest);
33
- logger.success(`Saved schemas to ${getResolvedPath(options.dest)}`);
25
+ logger.success(
26
+ i18n(`${i18nKey}.success.fetch`, {
27
+ path: getResolvedPath(options.dest),
28
+ })
29
+ );
34
30
  } catch (e) {
35
31
  logErrorInstance(e);
36
- logger.error('Unable to fetch schemas');
32
+ logger.error(i18n(`${i18nKey}.errors.fetch`));
37
33
  }
38
34
  };
39
35
 
40
36
  exports.builder = yargs => {
41
37
  yargs.example([
42
- [
43
- '$0 custom-object schema fetch-all',
44
- 'Fetch all schemas for an account and put them in the current working directory',
45
- ],
38
+ ['$0 custom-object schema fetch-all', i18n(`${i18nKey}.examples.default`)],
46
39
  [
47
40
  '$0 custom-object schema fetch-all my/folder',
48
- 'Fetch all schemas for an account and put them in a directory named my/folder',
41
+ i18n(`${i18nKey}.examples.specifyPath`),
49
42
  ],
50
43
  ]);
51
44
 
52
45
  yargs.positional('dest', {
53
- describe: 'Local folder where schemas will be written',
46
+ describe: i18n(`${i18nKey}.positionals.dest.describe`),
54
47
  type: 'string',
55
48
  });
56
49
  };
@@ -1,10 +1,5 @@
1
1
  const path = require('path');
2
- const {
3
- loadConfig,
4
- validateConfig,
5
- checkAndWarnGitInclusion,
6
- isConfigFlagEnabled,
7
- } = require('@hubspot/cli-lib');
2
+ const { isConfigFlagEnabled } = require('@hubspot/cli-lib');
8
3
  const { logger } = require('@hubspot/cli-lib/logger');
9
4
  const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');
10
5
  const { ConfigFlags } = require('@hubspot/cli-lib/lib/constants');
@@ -12,25 +7,22 @@ const { downloadSchema, getResolvedPath } = require('@hubspot/cli-lib/schema');
12
7
  const { fetchSchema } = require('@hubspot/cli-lib/api/fileTransport');
13
8
  const { getCwd } = require('@hubspot/cli-lib/path');
14
9
 
15
- const { validateAccount } = require('../../../lib/validation');
10
+ const { loadAndValidateOptions } = require('../../../lib/validation');
16
11
  const { trackCommandUsage } = require('../../../lib/usageTracking');
17
- const { setLogLevel, getAccountId } = require('../../../lib/commonOpts');
18
- const { logDebugInfo } = require('../../../lib/debugInfo');
12
+ const { getAccountId } = require('../../../lib/commonOpts');
13
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
14
+
15
+ const i18nKey =
16
+ 'cli.commands.customObject.subcommands.schema.subcommands.fetch';
19
17
 
20
18
  exports.command = 'fetch <name> [dest]';
21
- exports.describe = 'Fetch a custom object schema';
19
+ exports.describe = i18n(`${i18nKey}.describe`);
22
20
 
23
21
  exports.handler = async options => {
24
22
  let { name, dest } = options;
25
23
 
26
- setLogLevel(options);
27
- logDebugInfo(options);
28
- loadConfig(options.config);
29
- checkAndWarnGitInclusion();
24
+ await loadAndValidateOptions(options);
30
25
 
31
- if (!(validateConfig() && (await validateAccount(options)))) {
32
- process.exit(1);
33
- }
34
26
  const accountId = getAccountId(options);
35
27
 
36
28
  trackCommandUsage('custom-object-schema-fetch', null, accountId);
@@ -39,14 +31,27 @@ exports.handler = async options => {
39
31
  if (isConfigFlagEnabled(ConfigFlags.USE_CUSTOM_OBJECT_HUBFILE)) {
40
32
  const fullpath = path.resolve(getCwd(), dest);
41
33
  await fetchSchema(accountId, name, fullpath);
42
- logger.success(`The schema "${name}" has been saved to "${fullpath}"`);
34
+ logger.success(
35
+ i18n(`${i18nKey}.success.save`, {
36
+ name,
37
+ path: fullpath,
38
+ })
39
+ );
43
40
  } else {
44
41
  await downloadSchema(accountId, name, dest);
45
- logger.success(`Saved schema to ${getResolvedPath(dest, name)}`);
42
+ logger.success(
43
+ i18n(`${i18nKey}.success.savedToPath`, {
44
+ path: getResolvedPath(dest, name),
45
+ })
46
+ );
46
47
  }
47
48
  } catch (e) {
48
49
  logErrorInstance(e);
49
- logger.error(`Unable to fetch ${name}`);
50
+ logger.error(
51
+ i18n(`${i18nKey}.errors.fetch`, {
52
+ name,
53
+ })
54
+ );
50
55
  }
51
56
  };
52
57
 
@@ -54,21 +59,21 @@ exports.builder = yargs => {
54
59
  yargs.example([
55
60
  [
56
61
  '$0 custom-object schema fetch schemaName',
57
- 'Fetch `schemaId` schema and put it in the current working directory',
62
+ i18n(`${i18nKey}.examples.default`),
58
63
  ],
59
64
  [
60
65
  '$0 custom-object schema fetch schemaName my/folder',
61
- 'Fetch `schemaId` schema and put it in a directory named my/folder',
66
+ i18n(`${i18nKey}.examples.specifyPath`),
62
67
  ],
63
68
  ]);
64
69
 
65
70
  yargs.positional('name', {
66
- describe: 'Name of the target schema',
71
+ describe: i18n(`${i18nKey}.positionals.name.describe`),
67
72
  type: 'string',
68
73
  });
69
74
 
70
75
  yargs.positional('dest', {
71
- describe: 'Local folder where schema will be written',
76
+ describe: i18n(`${i18nKey}.positionals.dest.describe`),
72
77
  type: 'string',
73
78
  });
74
79
  };
@@ -1,29 +1,20 @@
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
 
9
- const { validateAccount } = require('../../../lib/validation');
4
+ const { loadAndValidateOptions } = require('../../../lib/validation');
10
5
  const { trackCommandUsage } = require('../../../lib/usageTracking');
11
- const { setLogLevel, getAccountId } = require('../../../lib/commonOpts');
12
- const { logDebugInfo } = require('../../../lib/debugInfo');
6
+ const { getAccountId } = require('../../../lib/commonOpts');
13
7
  const { listSchemas } = require('@hubspot/cli-lib/schema');
8
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
9
+
10
+ const i18nKey = 'cli.commands.customObject.subcommands.schema.subcommands.list';
14
11
 
15
12
  exports.command = 'list';
16
- exports.describe = 'List schemas available on your account';
13
+ exports.describe = i18n(`${i18nKey}.describe`);
17
14
 
18
15
  exports.handler = async options => {
19
- setLogLevel(options);
20
- logDebugInfo(options);
21
- loadConfig(options.config);
22
- checkAndWarnGitInclusion();
16
+ await loadAndValidateOptions(options);
23
17
 
24
- if (!(validateConfig() && (await validateAccount(options)))) {
25
- process.exit(1);
26
- }
27
18
  const accountId = getAccountId(options);
28
19
 
29
20
  trackCommandUsage('custom-object-schema-list', null, accountId);
@@ -32,6 +23,6 @@ exports.handler = async options => {
32
23
  await listSchemas(accountId);
33
24
  } catch (e) {
34
25
  logErrorInstance(e);
35
- logger.error(`Unable to list schemas`);
26
+ logger.error(i18n(`${i18nKey}.errors.list`));
36
27
  }
37
28
  };
@@ -1,65 +1,67 @@
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 { getAbsoluteFilePath } = require('@hubspot/cli-lib/path');
9
- const { validateAccount, isFileValidJSON } = require('../../../lib/validation');
10
- const { trackCommandUsage } = require('../../../lib/usageTracking');
11
4
  const {
12
- addTestingOptions,
13
- setLogLevel,
14
- getAccountId,
15
- } = require('../../../lib/commonOpts');
5
+ isFileValidJSON,
6
+ loadAndValidateOptions,
7
+ } = require('../../../lib/validation');
8
+ const { trackCommandUsage } = require('../../../lib/usageTracking');
9
+ const { addTestingOptions, getAccountId } = require('../../../lib/commonOpts');
16
10
  const { ENVIRONMENTS, ConfigFlags } = require('@hubspot/cli-lib/lib/constants');
17
11
  const { getEnv, isConfigFlagEnabled } = require('@hubspot/cli-lib');
18
- const { logDebugInfo } = require('../../../lib/debugInfo');
19
12
  const { updateSchema } = require('@hubspot/cli-lib/api/schema');
20
13
  const {
21
14
  updateSchema: updateSchemaFromHubFile,
22
15
  } = require('@hubspot/cli-lib/api/fileTransport');
23
16
  const { getHubSpotWebsiteOrigin } = require('@hubspot/cli-lib/lib/urls');
17
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
18
+
19
+ const i18nKey =
20
+ 'cli.commands.customObject.subcommands.schema.subcommands.update';
21
+ const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
24
22
 
25
23
  exports.command = 'update <name> <definition>';
26
- exports.describe = 'Update an existing custom object schema';
24
+ exports.describe = i18n(`${i18nKey}.describe`);
27
25
 
28
26
  exports.handler = async options => {
29
27
  const { definition, name } = options;
30
- setLogLevel(options);
31
- logDebugInfo(options);
32
- const { config: configPath } = options;
33
- loadConfig(configPath);
34
- checkAndWarnGitInclusion();
35
28
 
36
- if (!(validateConfig() && (await validateAccount(options)))) {
37
- process.exit(1);
38
- }
29
+ await loadAndValidateOptions(options);
30
+
39
31
  const accountId = getAccountId(options);
40
32
 
41
33
  trackCommandUsage('custom-object-schema-update', null, accountId);
42
34
 
43
35
  const filePath = getAbsoluteFilePath(definition);
44
36
  if (!isFileValidJSON(filePath)) {
45
- process.exit(1);
37
+ process.exit(EXIT_CODES.ERROR);
46
38
  }
47
39
 
48
40
  try {
49
41
  if (isConfigFlagEnabled(ConfigFlags.USE_CUSTOM_OBJECT_HUBFILE)) {
50
42
  await updateSchemaFromHubFile(accountId, filePath);
51
- logger.success(`Your schema has been updated in account "${accountId}"`);
43
+ logger.success(
44
+ i18n(`${i18nKey}.success.update`, {
45
+ accountId,
46
+ })
47
+ );
52
48
  } else {
53
49
  const res = await updateSchema(accountId, name, filePath);
54
50
  logger.success(
55
- `Schema can be viewed at ${getHubSpotWebsiteOrigin(
56
- getEnv() === 'qa' ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD
57
- )}/contacts/${accountId}/objects/${res.objectTypeId}`
51
+ i18n(`${i18nKey}.success.viewAtUrl`, {
52
+ url: `${getHubSpotWebsiteOrigin(
53
+ getEnv() === 'qa' ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD
54
+ )}/contacts/${accountId}/objects/${res.objectTypeId}`,
55
+ })
58
56
  );
59
57
  }
60
58
  } catch (e) {
61
59
  logErrorInstance(e, { accountId });
62
- logger.error(`Schema update from ${definition} failed`);
60
+ logger.error(
61
+ i18n(`${i18nKey}.errors.update`, {
62
+ definition,
63
+ })
64
+ );
63
65
  }
64
66
  };
65
67
 
@@ -67,12 +69,12 @@ exports.builder = yargs => {
67
69
  addTestingOptions(yargs, true);
68
70
 
69
71
  yargs.positional('name', {
70
- describe: 'Name of the target schema',
72
+ describe: i18n(`${i18nKey}.positionals.name.describe`),
71
73
  type: 'string',
72
74
  });
73
75
 
74
76
  yargs.positional('definition', {
75
- describe: 'Local path to the JSON file containing the schema definition',
77
+ describe: i18n(`${i18nKey}.positionals.definition.describe`),
76
78
  type: 'string',
77
79
  });
78
80
  };
@@ -4,9 +4,12 @@ const fetchAllCommand = require('./schema/fetch-all');
4
4
  const deleteCommand = require('./schema/delete');
5
5
  const listCommand = require('./schema/list');
6
6
  const updateSchema = require('./schema/update');
7
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
8
+
9
+ const i18nKey = 'cli.commands.customObject.subcommands.schema';
7
10
 
8
11
  exports.command = 'schema';
9
- exports.describe = 'Manage custom object schemas';
12
+ exports.describe = i18n(`${i18nKey}.describe`);
10
13
  exports.builder = yargs => {
11
14
  yargs
12
15
  .command(listCommand)
@@ -1,11 +1,12 @@
1
1
  const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
2
2
  const schemaCommand = require('./customObject/schema');
3
3
  const createCommand = require('./customObject/create');
4
- const chalk = require('chalk');
4
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
5
+
6
+ const i18nKey = 'cli.commands.customObject';
5
7
 
6
8
  exports.command = ['custom-object', 'custom', 'co'];
7
- exports.describe =
8
- 'Manage Custom Objects. This feature is currently in beta and the CLI contract is subject to change';
9
+ exports.describe = i18n(`${i18nKey}.describe`);
9
10
 
10
11
  exports.builder = yargs => {
11
12
  addConfigOptions(yargs, true);
@@ -16,26 +17,14 @@ exports.builder = yargs => {
16
17
  .command(createCommand)
17
18
  .demandCommand(1, '');
18
19
 
20
+ console.warn(i18n(`${i18nKey}.warning`));
21
+ console.warn(i18n(`${i18nKey}.betaMessage`));
19
22
  console.warn(
20
- chalk.reset.yellow(
21
- '***************************** WARNING WARNING WARNING ****************************'
22
- )
23
- );
24
- console.warn(
25
- chalk.reset.yellow(
26
- 'The Custom Object CLI is currently in beta and is subject to change.'
27
- )
28
- );
29
- console.warn(
30
- chalk.reset.yellow(
31
- 'See https://developers.hubspot.com/docs/api/crm/crm-custom-objects to find out more.'
32
- )
33
- );
34
- console.warn(
35
- chalk.reset.yellow(
36
- '***************************** WARNING WARNING WARNING ****************************'
37
- )
23
+ i18n(`${i18nKey}.seeMoreLink`, {
24
+ link: 'https://developers.hubspot.com/docs/api/crm/crm-custom-objects',
25
+ })
38
26
  );
27
+ console.warn(i18n(`${i18nKey}.warning`));
39
28
 
40
29
  return yargs;
41
30
  };
package/commands/fetch.js CHANGED
@@ -1,9 +1,4 @@
1
1
  const { downloadFileOrFolder } = require('@hubspot/cli-lib/fileMapper');
2
- const {
3
- loadConfig,
4
- validateConfig,
5
- checkAndWarnGitInclusion,
6
- } = require('@hubspot/cli-lib');
7
2
  const { logger } = require('@hubspot/cli-lib/logger');
8
3
 
9
4
  const {
@@ -14,39 +9,30 @@ const {
14
9
  addUseEnvironmentOptions,
15
10
  getAccountId,
16
11
  getMode,
17
- setLogLevel,
18
12
  } = require('../lib/commonOpts');
19
13
  const { resolveLocalPath } = require('../lib/filesystem');
20
- const { validateAccount, validateMode } = require('../lib/validation');
21
- const { logDebugInfo } = require('../lib/debugInfo');
14
+ const { validateMode, loadAndValidateOptions } = require('../lib/validation');
22
15
  const { trackCommandUsage } = require('../lib/usageTracking');
16
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
17
+
18
+ const i18nKey = 'cli.commands.fetch';
19
+ const { EXIT_CODES } = require('../lib/enums/exitCodes');
23
20
 
24
21
  exports.command = 'fetch <src> [dest]';
25
- exports.describe =
26
- 'Fetch a file, directory or module from HubSpot and write to a path on your computer';
22
+ exports.describe = i18n(`${i18nKey}.describe`);
27
23
 
28
24
  exports.handler = async options => {
29
- const { config: configPath, src, dest } = options;
30
-
31
- setLogLevel(options);
32
- logDebugInfo(options);
25
+ const { src, dest } = options;
33
26
 
34
- loadConfig(configPath);
35
- checkAndWarnGitInclusion();
27
+ await loadAndValidateOptions(options);
36
28
 
37
- if (
38
- !(
39
- validateConfig() &&
40
- (await validateAccount(options)) &&
41
- validateMode(options)
42
- )
43
- ) {
44
- process.exit(1);
29
+ if (!validateMode(options)) {
30
+ process.exit(EXIT_CODES.ERROR);
45
31
  }
46
32
 
47
33
  if (typeof src !== 'string') {
48
- logger.error('A source to fetch is required');
49
- process.exit(1);
34
+ logger.error(i18n(`${i18nKey}.errors.sourceRequired`));
35
+ process.exit(EXIT_CODES.ERROR);
50
36
  }
51
37
 
52
38
  const accountId = getAccountId(options);
@@ -72,19 +58,18 @@ exports.builder = yargs => {
72
58
  addUseEnvironmentOptions(yargs, true);
73
59
 
74
60
  yargs.positional('src', {
75
- describe: 'Path in HubSpot Design Tools',
61
+ describe: i18n(`${i18nKey}.positionals.src.describe`),
76
62
  type: 'string',
77
63
  });
78
64
 
79
65
  yargs.positional('dest', {
80
- describe:
81
- 'Local directory you would like the files to be placed in, relative to your current working directory',
66
+ describe: i18n(`${i18nKey}.positionals.dest.describe`),
82
67
  type: 'string',
83
68
  });
84
69
 
85
70
  yargs.options({
86
71
  staging: {
87
- describe: 'Retrieve staged changes for project',
72
+ describe: i18n(`${i18nKey}.options.staging.describe`),
88
73
  type: 'boolean',
89
74
  default: false,
90
75
  hidden: true,
@@ -1,8 +1,3 @@
1
- const {
2
- loadConfig,
3
- validateConfig,
4
- checkAndWarnGitInclusion,
5
- } = require('@hubspot/cli-lib');
6
1
  const { downloadFileOrFolder } = require('@hubspot/cli-lib/fileManager');
7
2
  const { logger } = require('@hubspot/cli-lib/logger');
8
3
  const { resolveLocalPath } = require('../../lib/filesystem');
@@ -11,32 +6,26 @@ const {
11
6
  addConfigOptions,
12
7
  addAccountOptions,
13
8
  addUseEnvironmentOptions,
14
- setLogLevel,
15
9
  getAccountId,
16
10
  } = require('../../lib/commonOpts');
17
- const { logDebugInfo } = require('../../lib/debugInfo');
18
- const { validateAccount } = require('../../lib/validation');
11
+ const { loadAndValidateOptions } = require('../../lib/validation');
19
12
  const { trackCommandUsage } = require('../../lib/usageTracking');
13
+ const { i18n } = require('@hubspot/cli-lib/lib/lang');
14
+
15
+ const i18nKey = 'cli.commands.filemanager.subcommands.fetch';
16
+ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
20
17
 
21
18
  exports.command = 'fetch <src> [dest]';
22
- exports.describe =
23
- 'Download a folder or file from the HubSpot File Manager to your computer';
19
+ exports.describe = i18n(`${i18nKey}.describe`);
24
20
 
25
21
  exports.handler = async options => {
26
- let { config: configPath, src, dest } = options;
22
+ let { src, dest } = options;
27
23
 
28
- setLogLevel(options);
29
- logDebugInfo(options);
30
- loadConfig(configPath, options);
31
- checkAndWarnGitInclusion();
32
-
33
- if (!validateConfig() || !(await validateAccount(options))) {
34
- process.exit(1);
35
- }
24
+ await loadAndValidateOptions(options);
36
25
 
37
26
  if (typeof src !== 'string') {
38
- logger.error('A source to fetch is required');
39
- process.exit(1);
27
+ logger.error(i18n(`${i18nKey}.errors.sourceRequired`));
28
+ process.exit(EXIT_CODES.ERROR);
40
29
  }
41
30
 
42
31
  dest = resolveLocalPath(dest);
@@ -55,17 +44,16 @@ exports.builder = yargs => {
55
44
  addUseEnvironmentOptions(yargs, true);
56
45
 
57
46
  yargs.positional('src', {
58
- describe: 'Path in HubSpot Design Tools',
47
+ describe: i18n(`${i18nKey}.positionals.src.describe`),
59
48
  type: 'string',
60
49
  });
61
50
  yargs.positional('dest', {
62
- describe:
63
- 'Path to the local directory you would like the files to be placed, relative to your current working directory. If omitted, this argument will default to your current working directory',
51
+ describe: i18n(`${i18nKey}.positionals.dest.describe`),
64
52
  type: 'string',
65
53
  });
66
54
  yargs.option('include-archived', {
67
55
  alias: ['i'],
68
- describe: 'Include files that have been marked as "archived"',
56
+ describe: i18n(`${i18nKey}.options.includeArchived.describe`),
69
57
  type: 'boolean',
70
58
  });
71
59
  };