@hubspot/cli 6.4.0 → 7.0.0-beta.0

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 (205) hide show
  1. package/bin/cli.js +110 -16
  2. package/bin/hs +2 -0
  3. package/bin/hscms +2 -0
  4. package/bin/silenceErrors.d.ts +2 -0
  5. package/bin/silenceErrors.js +12 -0
  6. package/commands/{accounts → account}/clean.js +10 -11
  7. package/commands/{accounts → account}/info.js +10 -16
  8. package/commands/{accounts → account}/list.js +16 -16
  9. package/commands/{accounts → account}/remove.js +12 -15
  10. package/commands/{accounts → account}/rename.js +4 -7
  11. package/commands/{accounts → account}/use.js +8 -14
  12. package/commands/account.js +26 -0
  13. package/commands/auth.js +30 -24
  14. package/commands/cms/getReactModule.js +70 -0
  15. package/commands/cms/lighthouseScore.js +19 -21
  16. package/commands/cms.js +4 -3
  17. package/commands/completion.js +22 -0
  18. package/commands/config/set.js +22 -24
  19. package/commands/config.js +2 -2
  20. package/commands/create.js +6 -3
  21. package/commands/customObject/create.js +19 -15
  22. package/commands/customObject/schema/create.js +15 -16
  23. package/commands/customObject/schema/delete.js +29 -11
  24. package/commands/customObject/schema/fetch-all.js +14 -11
  25. package/commands/customObject/schema/fetch.js +22 -14
  26. package/commands/customObject/schema/list.js +3 -6
  27. package/commands/customObject/schema/update.js +28 -18
  28. package/commands/customObject/schema.js +1 -1
  29. package/commands/customObject.js +3 -4
  30. package/commands/doctor.js +4 -2
  31. package/commands/feedback.js +2 -0
  32. package/commands/fetch.js +13 -13
  33. package/commands/filemanager/fetch.js +6 -7
  34. package/commands/filemanager/upload.js +10 -12
  35. package/commands/filemanager.js +1 -8
  36. package/commands/{functions → function}/deploy.js +13 -13
  37. package/commands/{functions → function}/list.js +7 -9
  38. package/commands/{functions → function}/server.js +5 -8
  39. package/commands/function.js +16 -0
  40. package/commands/hubdb/clear.js +14 -10
  41. package/commands/hubdb/create.js +37 -13
  42. package/commands/hubdb/delete.js +31 -10
  43. package/commands/hubdb/fetch.js +14 -9
  44. package/commands/hubdb.js +2 -3
  45. package/commands/init.js +37 -14
  46. package/commands/lint.js +6 -7
  47. package/commands/list.js +5 -7
  48. package/commands/logs.js +24 -15
  49. package/commands/module/marketplace-validate.js +6 -9
  50. package/commands/module.js +2 -1
  51. package/commands/mv.js +11 -13
  52. package/commands/open.js +11 -10
  53. package/commands/project/add.js +2 -5
  54. package/commands/project/cloneApp.js +28 -32
  55. package/commands/project/create.js +8 -10
  56. package/commands/project/deploy.js +19 -16
  57. package/commands/project/dev.js +17 -18
  58. package/commands/project/download.js +18 -15
  59. package/commands/project/listBuilds.js +36 -32
  60. package/commands/project/logs.js +6 -8
  61. package/commands/project/migrateApp.js +27 -27
  62. package/commands/project/open.js +9 -11
  63. package/commands/project/upload.js +30 -32
  64. package/commands/project/watch.js +17 -24
  65. package/commands/project.js +3 -4
  66. package/commands/remove.js +14 -13
  67. package/commands/sandbox/create.js +12 -15
  68. package/commands/sandbox/delete.js +19 -20
  69. package/commands/sandbox.js +4 -8
  70. package/commands/{secrets → secret}/addSecret.js +25 -12
  71. package/commands/secret/deleteSecret.js +71 -0
  72. package/commands/{secrets → secret}/listSecrets.js +7 -9
  73. package/commands/{secrets → secret}/updateSecret.js +21 -13
  74. package/commands/secret.js +22 -0
  75. package/commands/theme/generate-selectors.js +8 -8
  76. package/commands/theme/marketplace-validate.js +10 -13
  77. package/commands/theme/preview.js +7 -10
  78. package/commands/theme.js +3 -1
  79. package/commands/upload.js +32 -26
  80. package/commands/watch.js +19 -20
  81. package/lang/en.lyaml +200 -126
  82. package/lib/DevServerManager.js +1 -1
  83. package/lib/LocalDevManager.js +4 -4
  84. package/lib/buildAccount.js +5 -11
  85. package/lib/commonOpts.d.ts +15 -6
  86. package/lib/commonOpts.js +53 -39
  87. package/lib/configOptions.d.ts +13 -1
  88. package/lib/configOptions.js +54 -57
  89. package/lib/constants.d.ts +1 -4
  90. package/lib/dependencyManagement.d.ts +4 -1
  91. package/lib/dependencyManagement.js +2 -2
  92. package/lib/developerTestAccounts.d.ts +5 -1
  93. package/lib/developerTestAccounts.js +45 -39
  94. package/lib/doctor/DiagnosticInfoBuilder.js +8 -4
  95. package/lib/doctor/Doctor.js +11 -6
  96. package/lib/generateSelectors.d.ts +19 -0
  97. package/lib/generateSelectors.js +23 -23
  98. package/lib/localDev.js +3 -2
  99. package/lib/marketplaceValidate.d.ts +6 -1
  100. package/lib/marketplaceValidate.js +76 -77
  101. package/lib/oauth.d.ts +2 -1
  102. package/lib/oauth.js +49 -37
  103. package/lib/polling.d.ts +8 -0
  104. package/lib/polling.js +9 -12
  105. package/lib/projects/ProjectLogsManager.d.ts +20 -0
  106. package/lib/projects/ProjectLogsManager.js +105 -0
  107. package/lib/projects/buildAndDeploy.d.ts +16 -0
  108. package/lib/projects/buildAndDeploy.js +342 -0
  109. package/lib/projects/index.d.ts +24 -0
  110. package/lib/projects/index.js +256 -0
  111. package/lib/projects/structure.d.ts +78 -0
  112. package/lib/projects/structure.js +151 -0
  113. package/lib/projects/upload.d.ts +8 -0
  114. package/lib/projects/upload.js +107 -0
  115. package/lib/projects/urls.d.ts +4 -0
  116. package/lib/projects/urls.js +27 -0
  117. package/lib/{projectsWatch.js → projects/watch.js} +3 -3
  118. package/lib/prompts/accountNamePrompt.d.ts +11 -0
  119. package/lib/prompts/accountNamePrompt.js +45 -46
  120. package/lib/prompts/accountsPrompt.d.ts +1 -1
  121. package/lib/prompts/accountsPrompt.js +21 -19
  122. package/lib/prompts/cmsFieldPrompt.d.ts +1 -1
  123. package/lib/prompts/cmsFieldPrompt.js +23 -24
  124. package/lib/prompts/createApiSamplePrompt.d.ts +17 -0
  125. package/lib/prompts/createApiSamplePrompt.js +47 -44
  126. package/lib/prompts/createFunctionPrompt.d.ts +7 -0
  127. package/lib/prompts/createFunctionPrompt.js +17 -20
  128. package/lib/prompts/createModulePrompt.d.ts +8 -0
  129. package/lib/prompts/createModulePrompt.js +29 -17
  130. package/lib/prompts/createProjectPrompt.d.ts +13 -0
  131. package/lib/prompts/createProjectPrompt.js +48 -49
  132. package/lib/prompts/createTemplatePrompt.d.ts +8 -0
  133. package/lib/prompts/createTemplatePrompt.js +15 -17
  134. package/lib/prompts/downloadProjectPrompt.d.ts +8 -0
  135. package/lib/prompts/downloadProjectPrompt.js +25 -23
  136. package/lib/prompts/installPublicAppPrompt.d.ts +1 -1
  137. package/lib/prompts/installPublicAppPrompt.js +21 -19
  138. package/lib/prompts/personalAccessKeyPrompt.d.ts +28 -0
  139. package/lib/prompts/personalAccessKeyPrompt.js +46 -52
  140. package/lib/prompts/previewPrompt.d.ts +14 -0
  141. package/lib/prompts/previewPrompt.js +24 -24
  142. package/lib/prompts/projectAddPrompt.d.ts +9 -0
  143. package/lib/prompts/projectAddPrompt.js +11 -14
  144. package/lib/prompts/projectDevTargetAccountPrompt.d.ts +6 -1
  145. package/lib/prompts/projectDevTargetAccountPrompt.js +87 -69
  146. package/lib/prompts/projectsLogsPrompt.d.ts +11 -0
  147. package/lib/prompts/projectsLogsPrompt.js +8 -11
  148. package/lib/prompts/promptUtils.d.ts +7 -6
  149. package/lib/prompts/promptUtils.js +21 -8
  150. package/lib/prompts/sandboxesPrompt.d.ts +8 -0
  151. package/lib/prompts/sandboxesPrompt.js +43 -45
  152. package/lib/prompts/secretPrompt.d.ts +12 -0
  153. package/lib/prompts/secretPrompt.js +32 -19
  154. package/lib/prompts/selectHubDBTablePrompt.d.ts +12 -0
  155. package/lib/prompts/selectHubDBTablePrompt.js +69 -0
  156. package/lib/prompts/selectPublicAppPrompt.d.ts +8 -0
  157. package/lib/prompts/selectPublicAppPrompt.js +28 -27
  158. package/lib/prompts/setAsDefaultAccountPrompt.d.ts +1 -1
  159. package/lib/prompts/setAsDefaultAccountPrompt.js +12 -14
  160. package/lib/prompts/uploadPrompt.d.ts +8 -0
  161. package/lib/prompts/uploadPrompt.js +18 -18
  162. package/lib/sandboxSync.js +5 -2
  163. package/lib/sandboxes.js +12 -7
  164. package/lib/ui/index.d.ts +1 -1
  165. package/lib/ui/index.js +1 -1
  166. package/lib/usageTracking.d.ts +21 -2
  167. package/lib/usageTracking.js +53 -81
  168. package/lib/validation.d.ts +11 -1
  169. package/lib/validation.js +98 -91
  170. package/package.json +12 -6
  171. package/types/Projects.d.ts +43 -0
  172. package/types/Projects.js +2 -0
  173. package/types/Prompts.d.ts +25 -0
  174. package/types/Prompts.js +2 -0
  175. package/commands/accounts.js +0 -30
  176. package/commands/cms/reactModules.js +0 -60
  177. package/commands/functions.js +0 -24
  178. package/commands/secrets/deleteSecret.js +0 -46
  179. package/commands/secrets.js +0 -23
  180. package/lib/ProjectLogsManager.js +0 -91
  181. package/lib/projectStructure.js +0 -116
  182. package/lib/projects.d.ts +0 -4
  183. package/lib/projects.js +0 -681
  184. package/lib/projectsWatch.d.ts +0 -1
  185. package/lib/prompts/cleanUploadPrompt.d.ts +0 -1
  186. package/lib/prompts/cleanUploadPrompt.js +0 -20
  187. /package/commands/{accounts → account}/clean.d.ts +0 -0
  188. /package/commands/{accounts → account}/info.d.ts +0 -0
  189. /package/commands/{accounts → account}/list.d.ts +0 -0
  190. /package/commands/{accounts → account}/remove.d.ts +0 -0
  191. /package/commands/{accounts → account}/rename.d.ts +0 -0
  192. /package/commands/{accounts → account}/use.d.ts +0 -0
  193. /package/commands/{accounts.d.ts → account.d.ts} +0 -0
  194. /package/commands/cms/{reactModules.d.ts → getReactModule.d.ts} +0 -0
  195. /package/commands/{functions.d.ts → completion.d.ts} +0 -0
  196. /package/commands/{functions/list.d.ts → function/deploy.d.ts} +0 -0
  197. /package/commands/{functions/server.d.ts → function/list.d.ts} +0 -0
  198. /package/commands/{secrets.d.ts → function/server.d.ts} +0 -0
  199. /package/commands/{functions/deploy.d.ts → function.d.ts} +0 -0
  200. /package/commands/{secrets/deleteSecret.d.ts → secret/addSecret.d.ts} +0 -0
  201. /package/commands/{secrets/listSecrets.d.ts → secret/deleteSecret.d.ts} +0 -0
  202. /package/commands/{secrets/updateSecret.d.ts → secret/listSecrets.d.ts} +0 -0
  203. /package/{lib/ProjectLogsManager.d.ts → commands/secret/updateSecret.d.ts} +0 -0
  204. /package/commands/{secrets/addSecret.d.ts → secret.d.ts} +0 -0
  205. /package/lib/{projectStructure.d.ts → projects/watch.d.ts} +0 -0
package/commands/auth.js CHANGED
@@ -8,13 +8,13 @@ const { ENVIRONMENTS, } = require('@hubspot/local-dev-lib/constants/environments
8
8
  const { DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME, } = require('@hubspot/local-dev-lib/constants/config');
9
9
  const { i18n } = require('../lib/lang');
10
10
  const { getAccessToken, updateConfigWithAccessToken, } = require('@hubspot/local-dev-lib/personalAccessKey');
11
- const { updateAccountConfig, writeConfig, getConfig, getConfigPath, loadConfig, } = require('@hubspot/local-dev-lib/config');
11
+ const { updateAccountConfig, writeConfig, getConfigPath, loadConfig, getConfigDefaultAccount, } = require('@hubspot/local-dev-lib/config');
12
12
  const { commaSeparatedValues, toKebabCase, } = require('@hubspot/local-dev-lib/text');
13
13
  const { promptUser } = require('../lib/prompts/promptUtils');
14
14
  const { personalAccessKeyPrompt, OAUTH_FLOW, } = require('../lib/prompts/personalAccessKeyPrompt');
15
15
  const { cliAccountNamePrompt } = require('../lib/prompts/accountNamePrompt');
16
16
  const { setAsDefaultAccountPrompt, } = require('../lib/prompts/setAsDefaultAccountPrompt');
17
- const { addConfigOptions, setLogLevel, getAccountId, addTestingOptions, } = require('../lib/commonOpts');
17
+ const { addConfigOptions, setLogLevel, getAccountId, addTestingOptions, addGlobalOptions, } = require('../lib/commonOpts');
18
18
  const { trackAuthAction, trackCommandUsage } = require('../lib/usageTracking');
19
19
  const { authenticateWithOauth } = require('../lib/oauth');
20
20
  const { EXIT_CODES } = require('../lib/enums/exitCodes');
@@ -31,21 +31,23 @@ const ALLOWED_AUTH_METHODS = [
31
31
  PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
32
32
  ];
33
33
  const SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT = commaSeparatedValues(ALLOWED_AUTH_METHODS);
34
- exports.command = 'auth [type] [--account]';
34
+ exports.command = 'auth';
35
35
  exports.describe = i18n(`${i18nKey}.describe`, {
36
36
  supportedProtocols: SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT,
37
37
  });
38
38
  exports.handler = async (options) => {
39
- const { type, config: c, qa, account } = options;
40
- const authType = (type && type.toLowerCase()) || PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
39
+ const { authType: authTypeFlagValue, config: configFlagValue, qa, providedAccountId, } = options;
40
+ const authType = (authTypeFlagValue && authTypeFlagValue.toLowerCase()) ||
41
+ PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
41
42
  setLogLevel(options);
42
- if (!getConfigPath(c)) {
43
+ const env = qa ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD;
44
+ // Needed to load deprecated config
45
+ loadConfig(configFlagValue);
46
+ checkAndWarnGitInclusion(getConfigPath());
47
+ if (!getConfigPath(configFlagValue)) {
43
48
  logger.error(i18n(`${i18nKey}.errors.noConfigFileFound`));
44
49
  process.exit(EXIT_CODES.ERROR);
45
50
  }
46
- const env = qa ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD;
47
- loadConfig(c);
48
- checkAndWarnGitInclusion(getConfigPath());
49
51
  trackCommandUsage('auth');
50
52
  trackAuthAction('auth', authType, TRACKING_STATUS.STARTED);
51
53
  let configData;
@@ -64,7 +66,10 @@ exports.handler = async (options) => {
64
66
  successAuthMethod = OAUTH_AUTH_METHOD.name;
65
67
  break;
66
68
  case PERSONAL_ACCESS_KEY_AUTH_METHOD.value:
67
- configData = await personalAccessKeyPrompt({ env, account });
69
+ configData = await personalAccessKeyPrompt({
70
+ env,
71
+ account: providedAccountId,
72
+ });
68
73
  try {
69
74
  token = await getAccessToken(configData.personalAccessKey, env);
70
75
  defaultName = toKebabCase(token.hubName);
@@ -110,9 +115,8 @@ exports.handler = async (options) => {
110
115
  }));
111
116
  }
112
117
  else {
113
- const config = getConfig();
114
118
  logger.info(i18n(`lib.prompts.setAsDefaultAccountPrompt.keepingCurrentDefault`, {
115
- accountName: config.defaultPortal,
119
+ accountName: getConfigDefaultAccount(),
116
120
  }));
117
121
  }
118
122
  logger.success(i18n(`${i18nKey}.success.configFileUpdated`, {
@@ -130,25 +134,27 @@ exports.handler = async (options) => {
130
134
  process.exit(EXIT_CODES.SUCCESS);
131
135
  };
132
136
  exports.builder = yargs => {
133
- yargs.positional('type', {
134
- describe: i18n(`${i18nKey}.positionals.type.describe`),
135
- type: 'string',
136
- choices: [
137
- `${PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
138
- `${OAUTH_AUTH_METHOD.value}`,
139
- ],
140
- default: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
141
- defaultDescription: i18n(`${i18nKey}.positionals.type.defaultDescription`, {
142
- authMethod: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
143
- }),
144
- });
145
137
  yargs.options({
138
+ 'auth-type': {
139
+ describe: i18n(`${i18nKey}.options.authType.describe`),
140
+ type: 'string',
141
+ choices: [
142
+ `${PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
143
+ `${OAUTH_AUTH_METHOD.value}`,
144
+ ],
145
+ default: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
146
+ defaultDescription: i18n(`${i18nKey}.options.authType.defaultDescription`, {
147
+ authMethod: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
148
+ }),
149
+ },
146
150
  account: {
147
151
  describe: i18n(`${i18nKey}.options.account.describe`),
148
152
  type: 'string',
153
+ alias: 'a',
149
154
  },
150
155
  });
151
156
  addConfigOptions(yargs);
152
157
  addTestingOptions(yargs);
158
+ addGlobalOptions(yargs);
153
159
  return yargs;
154
160
  };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const { getCwd } = require('@hubspot/local-dev-lib/path');
7
+ const { logger } = require('@hubspot/local-dev-lib/logger');
8
+ const { retrieveDefaultModule } = require('@hubspot/local-dev-lib/cms/modules');
9
+ const { i18n } = require('../../lib/lang');
10
+ const { logError } = require('../../lib/errorHandlers/index');
11
+ const { trackCommandUsage } = require('../../lib/usageTracking');
12
+ const { listPrompt } = require('../../lib/prompts/promptUtils');
13
+ const { EXIT_CODES } = require('../../lib/enums/exitCodes');
14
+ const i18nKey = 'commands.cms.subcommands.getReactModule';
15
+ exports.command = 'get-react-module [name] [dest]';
16
+ exports.describe = i18n(`${i18nKey}.describe`);
17
+ exports.handler = async (options) => {
18
+ const { name, dest } = options;
19
+ trackCommandUsage('get-react-modules');
20
+ let moduleToRetrieve = name;
21
+ if (!moduleToRetrieve) {
22
+ let availableModules;
23
+ try {
24
+ availableModules = await retrieveDefaultModule(null, '');
25
+ }
26
+ catch (e) {
27
+ logError(e);
28
+ }
29
+ const moduleChoice = await listPrompt(i18n(`${i18nKey}.selectModulePrompt`), {
30
+ choices: availableModules.map(module => module.name),
31
+ });
32
+ moduleToRetrieve = moduleChoice;
33
+ }
34
+ const destPath = dest
35
+ ? path.join(path.resolve(getCwd(), dest), `${moduleToRetrieve}`)
36
+ : path.join(getCwd(), `${moduleToRetrieve}`);
37
+ if (fs.existsSync(destPath)) {
38
+ logger.error(i18n(`${i18nKey}.errors.pathExists`, {
39
+ path: destPath,
40
+ }));
41
+ return;
42
+ }
43
+ try {
44
+ await retrieveDefaultModule(moduleToRetrieve, destPath);
45
+ logger.success(i18n(`${i18nKey}.success.moduleDownloaded`, {
46
+ moduleName: moduleToRetrieve,
47
+ path: destPath,
48
+ }));
49
+ }
50
+ catch (e) {
51
+ if (e.cause && e.cause.code === 'ERR_BAD_REQUEST') {
52
+ logger.error(i18n(`${i18nKey}.errors.invalidName`));
53
+ }
54
+ else {
55
+ logError(e);
56
+ }
57
+ }
58
+ process.exit(EXIT_CODES.SUCCESS);
59
+ };
60
+ exports.builder = yargs => {
61
+ yargs.positional('name', {
62
+ describe: i18n(`${i18nKey}.positionals.name.describe`),
63
+ type: 'string',
64
+ });
65
+ yargs.positional('dest', {
66
+ describe: i18n(`${i18nKey}.positionals.dest.describe`),
67
+ type: 'string',
68
+ });
69
+ return yargs;
70
+ };
@@ -2,10 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // @ts-nocheck
4
4
  const SpinniesManager = require('../../lib/ui/SpinniesManager');
5
- const { addAccountOptions, addConfigOptions, addUseEnvironmentOptions, getAccountId, } = require('../../lib/commonOpts');
5
+ const { addAccountOptions, addConfigOptions, addUseEnvironmentOptions, } = require('../../lib/commonOpts');
6
6
  const { logger } = require('@hubspot/local-dev-lib/logger');
7
7
  const { getTableContents, getTableHeader } = require('../../lib/ui/table');
8
- const { loadAndValidateOptions } = require('../../lib/validation');
9
8
  const { promptUser } = require('../../lib/prompts/promptUtils');
10
9
  const { i18n } = require('../../lib/lang');
11
10
  const { fetchThemes } = require('@hubspot/local-dev-lib/api/designManager');
@@ -53,15 +52,14 @@ const selectTheme = async (accountId) => {
53
52
  return selectedTheme;
54
53
  };
55
54
  exports.handler = async (options) => {
56
- await loadAndValidateOptions(options);
57
- const accountId = getAccountId(options);
58
- const includeDesktopScore = options.target === 'desktop' || !options.verbose;
59
- const includeMobileScore = options.target === 'mobile' || !options.verbose;
60
- let themeToCheck = options.theme;
55
+ const { target, verbose, theme, derivedAccountId } = options;
56
+ const includeDesktopScore = target === 'desktop' || !verbose;
57
+ const includeMobileScore = target === 'mobile' || !verbose;
58
+ let themeToCheck = theme;
61
59
  if (themeToCheck) {
62
60
  let isValidTheme = true;
63
61
  try {
64
- const { data: result } = await fetchThemes(accountId, {
62
+ const { data: result } = await fetchThemes(derivedAccountId, {
65
63
  name: encodeURIComponent(themeToCheck),
66
64
  });
67
65
  isValidTheme = result && result.total;
@@ -75,13 +73,13 @@ exports.handler = async (options) => {
75
73
  }
76
74
  }
77
75
  else {
78
- themeToCheck = await selectTheme(accountId);
76
+ themeToCheck = await selectTheme(derivedAccountId);
79
77
  logger.log();
80
78
  }
81
79
  // Kick off the scoring
82
80
  let requestResult;
83
81
  try {
84
- const { data } = await requestLighthouseScore(accountId, {
82
+ const { data } = await requestLighthouseScore(derivedAccountId, {
85
83
  themePath: themeToCheck,
86
84
  });
87
85
  requestResult = data;
@@ -102,14 +100,14 @@ exports.handler = async (options) => {
102
100
  const checkScoreStatus = async () => {
103
101
  let desktopScoreStatus = 'COMPLETED';
104
102
  if (includeDesktopScore) {
105
- const { data } = await getLighthouseScoreStatus(accountId, {
103
+ const { data } = await getLighthouseScoreStatus(derivedAccountId, {
106
104
  themeId: requestResult.desktopId,
107
105
  });
108
106
  desktopScoreStatus = data;
109
107
  }
110
108
  let mobileScoreStatus = 'COMPLETED';
111
109
  if (includeDesktopScore) {
112
- const { data } = await getLighthouseScoreStatus(accountId, {
110
+ const { data } = await getLighthouseScoreStatus(derivedAccountId, {
113
111
  themeId: requestResult.mobileId,
114
112
  });
115
113
  mobileScoreStatus = data;
@@ -132,24 +130,24 @@ exports.handler = async (options) => {
132
130
  let mobileScoreResult = {};
133
131
  let verboseViewAverageScoreResult = {};
134
132
  try {
135
- const params = { isAverage: !options.verbose };
133
+ const params = { isAverage: !verbose };
136
134
  if (includeDesktopScore) {
137
- const { data } = await getLighthouseScore(accountId, {
135
+ const { data } = await getLighthouseScore(derivedAccountId, {
138
136
  ...params,
139
137
  desktopId: requestResult.desktopId,
140
138
  });
141
139
  desktopScoreResult = data;
142
140
  }
143
141
  if (includeMobileScore) {
144
- const { data } = await getLighthouseScore(accountId, {
142
+ const { data } = await getLighthouseScore(derivedAccountId, {
145
143
  ...params,
146
144
  mobileId: requestResult.mobileId,
147
145
  });
148
146
  mobileScoreResult = data;
149
147
  }
150
148
  // This is needed to show the average scores above the verbose output
151
- if (options.verbose) {
152
- const { data } = await getLighthouseScore(accountId, {
149
+ if (verbose) {
150
+ const { data } = await getLighthouseScore(derivedAccountId, {
153
151
  ...params,
154
152
  isAverage: true,
155
153
  desktopId: includeDesktopScore ? requestResult.desktopId : null,
@@ -162,8 +160,8 @@ exports.handler = async (options) => {
162
160
  logger.error(i18n(`${i18nKey}.errors.failedToGetLighthouseScore`));
163
161
  process.exit(EXIT_CODES.ERROR);
164
162
  }
165
- if (options.verbose) {
166
- logger.log(`${themeToCheck} ${options.target} scores`);
163
+ if (verbose) {
164
+ logger.log(`${themeToCheck} ${target} scores`);
167
165
  const tableHeader = getTableHeader(DEFAULT_TABLE_HEADER);
168
166
  const scores = verboseViewAverageScoreResult.scores
169
167
  ? verboseViewAverageScoreResult.scores[0]
@@ -183,7 +181,7 @@ exports.handler = async (options) => {
183
181
  'Template path',
184
182
  ...DEFAULT_TABLE_HEADER,
185
183
  ]);
186
- const scoreResult = options.target === 'desktop' ? desktopScoreResult : mobileScoreResult;
184
+ const scoreResult = target === 'desktop' ? desktopScoreResult : mobileScoreResult;
187
185
  const templateTableData = scoreResult.scores.map(score => {
188
186
  return [
189
187
  score.templatePath,
@@ -209,7 +207,7 @@ exports.handler = async (options) => {
209
207
  });
210
208
  }
211
209
  logger.log();
212
- logger.info(i18n(`${i18nKey}.info.targetDeviceNote`, { target: options.target }));
210
+ logger.info(i18n(`${i18nKey}.info.targetDeviceNote`, { target }));
213
211
  }
214
212
  else {
215
213
  logger.log(`Theme: ${themeToCheck}`);
package/commands/cms.js CHANGED
@@ -2,20 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // @ts-nocheck
4
4
  const { i18n } = require('../lib/lang');
5
- const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
5
+ const { addConfigOptions, addAccountOptions, addGlobalOptions, } = require('../lib/commonOpts');
6
6
  const lighthouseScore = require('./cms/lighthouseScore');
7
7
  const convertFields = require('./cms/convertFields');
8
- const reactModules = require('./cms/reactModules');
8
+ const getReactModule = require('./cms/getReactModule');
9
9
  const i18nKey = 'commands.cms';
10
10
  exports.command = 'cms';
11
11
  exports.describe = i18n(`${i18nKey}.describe`);
12
12
  exports.builder = yargs => {
13
13
  addConfigOptions(yargs);
14
14
  addAccountOptions(yargs);
15
+ addGlobalOptions(yargs);
15
16
  yargs
16
17
  .command(lighthouseScore)
17
18
  .command(convertFields)
18
- .command(reactModules)
19
+ .command(getReactModule)
19
20
  .demandCommand(1, '');
20
21
  return yargs;
21
22
  };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // @ts-nocheck
4
+ const yargsParser = require('yargs-parser');
5
+ const { i18n } = require('../lib/lang');
6
+ const { trackCommandUsage } = require('../lib/usageTracking');
7
+ const i18nKey = 'commands.completion';
8
+ exports.command = 'completion';
9
+ exports.describe = i18n(`${i18nKey}.describe`);
10
+ exports.handler = async () => {
11
+ await trackCommandUsage('completion');
12
+ };
13
+ exports.builder = yargs => {
14
+ const { help } = yargsParser(process.argv.slice(2));
15
+ if (!help) {
16
+ yargs.completion();
17
+ }
18
+ yargs.example([
19
+ ['$0 completion >> ~/.zshrc', i18n(`${i18nKey}.examples.default`)],
20
+ ]);
21
+ return yargs;
22
+ };
@@ -1,37 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // @ts-nocheck
4
- const { loadAndValidateOptions } = require('../../lib/validation');
5
4
  const { i18n } = require('../../lib/lang');
6
- const { getAccountId } = require('../../lib/commonOpts');
7
5
  const { trackCommandUsage } = require('../../lib/usageTracking');
8
6
  const { promptUser } = require('../../lib/prompts/promptUtils');
9
7
  const { EXIT_CODES } = require('../../lib/enums/exitCodes');
10
- const { setDefaultMode, setHttpTimeout, setAllowUsageTracking, } = require('../../lib/configOptions');
8
+ const { setDefaultCmsPublishMode, setHttpTimeout, setAllowUsageTracking, } = require('../../lib/configOptions');
11
9
  const i18nKey = 'commands.config.subcommands.set';
12
10
  exports.command = 'set';
13
11
  exports.describe = i18n(`${i18nKey}.describe`);
14
12
  const selectOptions = async () => {
15
- const { mode } = await promptUser([
13
+ const { cmsPublishMode } = await promptUser([
16
14
  {
17
15
  type: 'list',
18
16
  look: false,
19
- name: 'mode',
17
+ name: 'cmsPublishMode',
20
18
  pageSize: 20,
21
19
  message: i18n(`${i18nKey}.promptMessage`),
22
20
  choices: [
23
- { name: 'Default mode', value: { defaultMode: '' } },
21
+ {
22
+ name: 'Default CMS publish mode',
23
+ value: { defaultCmsPublishMode: '' },
24
+ },
24
25
  { name: 'Allow usage tracking', value: { allowUsageTracking: '' } },
25
26
  { name: 'HTTP timeout', value: { httpTimeout: '' } },
26
27
  ],
27
28
  },
28
29
  ]);
29
- return mode;
30
+ return cmsPublishMode;
30
31
  };
31
32
  const handleConfigUpdate = async (accountId, options) => {
32
- const { allowUsageTracking, defaultMode, httpTimeout } = options;
33
- if (typeof defaultMode !== 'undefined') {
34
- await setDefaultMode({ defaultMode, accountId });
33
+ const { allowUsageTracking, defaultCmsPublishMode, httpTimeout } = options;
34
+ if (typeof defaultCmsPublishMode !== 'undefined') {
35
+ await setDefaultCmsPublishMode({ defaultCmsPublishMode, accountId });
35
36
  return true;
36
37
  }
37
38
  else if (typeof httpTimeout !== 'undefined') {
@@ -45,37 +46,34 @@ const handleConfigUpdate = async (accountId, options) => {
45
46
  return false;
46
47
  };
47
48
  exports.handler = async (options) => {
48
- await loadAndValidateOptions(options);
49
- const accountId = getAccountId(options);
50
- trackCommandUsage('config-set', null, accountId);
51
- const configUpdated = await handleConfigUpdate(accountId, options);
49
+ const { derivedAccountId } = options;
50
+ trackCommandUsage('config-set', null, derivedAccountId);
51
+ const configUpdated = await handleConfigUpdate(derivedAccountId, options);
52
52
  if (!configUpdated) {
53
53
  const selectedOptions = await selectOptions();
54
- await handleConfigUpdate(accountId, selectedOptions);
54
+ await handleConfigUpdate(derivedAccountId, selectedOptions);
55
55
  }
56
56
  process.exit(EXIT_CODES.SUCCESS);
57
57
  };
58
58
  exports.builder = yargs => {
59
59
  yargs
60
60
  .options({
61
- defaultMode: {
61
+ 'default-cms-publish-mode': {
62
62
  describe: i18n(`${i18nKey}.options.defaultMode.describe`),
63
63
  type: 'string',
64
64
  },
65
- allowUsageTracking: {
65
+ 'allow-usage-tracking': {
66
66
  describe: i18n(`${i18nKey}.options.allowUsageTracking.describe`),
67
67
  type: 'boolean',
68
68
  },
69
- httpTimeout: {
69
+ 'http-timeout': {
70
70
  describe: i18n(`${i18nKey}.options.httpTimeout.describe`),
71
71
  type: 'string',
72
72
  },
73
73
  })
74
- .conflicts('defaultMode', 'allowUsageTracking')
75
- .conflicts('defaultMode', 'httpTimeout')
76
- .conflicts('allowUsageTracking', 'httpTimeout');
77
- yargs.example([['$0 config set', i18n(`${i18nKey}.examples.default`)]]);
78
- //TODO remove this when "hs accounts use" is fully rolled out
79
- yargs.strict(false);
74
+ .conflicts('defaultCmsPublishMode', 'allowUsageTracking')
75
+ .conflicts('defaultCmsPublishMode', 'httpTimeout')
76
+ .conflicts('allowUsageTracking', 'httpTimeout')
77
+ .example([['$0 config set', i18n(`${i18nKey}.examples.default`)]]);
80
78
  return yargs;
81
79
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // @ts-nocheck
4
- const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
4
+ const { addConfigOptions, addGlobalOptions } = require('../lib/commonOpts');
5
5
  const { i18n } = require('../lib/lang');
6
6
  const set = require('./config/set');
7
7
  const i18nKey = 'commands.config';
@@ -9,7 +9,7 @@ exports.command = 'config';
9
9
  exports.describe = i18n(`${i18nKey}.describe`);
10
10
  exports.builder = yargs => {
11
11
  addConfigOptions(yargs);
12
- addAccountOptions(yargs);
12
+ addGlobalOptions(yargs);
13
13
  yargs.command(set).demandCommand(1, '');
14
14
  return yargs;
15
15
  };
@@ -27,7 +27,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  const fs = require('fs-extra');
28
28
  const { logError } = require('../lib/errorHandlers/index');
29
29
  const { logger } = require('@hubspot/local-dev-lib/logger');
30
- const { setLogLevel, getAccountId } = require('../lib/commonOpts');
30
+ const { setLogLevel, addGlobalOptions, addConfigOptions, } = require('../lib/commonOpts');
31
31
  const { resolveLocalPath } = require('../lib/filesystem');
32
32
  const { trackCommandUsage } = require('../lib/usageTracking');
33
33
  const assets = require('./create/index');
@@ -36,7 +36,7 @@ const i18nKey = 'commands.create';
36
36
  const SUPPORTED_ASSET_TYPES = Object.keys(assets)
37
37
  .filter(t => !assets[t].hidden)
38
38
  .join(', ');
39
- exports.command = 'create <type> [name] [dest] [--internal]';
39
+ exports.command = 'create <type> [name] [dest]';
40
40
  exports.describe = i18n(`${i18nKey}.describe`, {
41
41
  supportedAssetTypes: SUPPORTED_ASSET_TYPES,
42
42
  });
@@ -63,7 +63,8 @@ exports.handler = async (options) => {
63
63
  const asset = assets[assetType];
64
64
  const argsToPass = { assetType, name, dest, getInternalVersion, options };
65
65
  dest = argsToPass.dest = resolveLocalPath(asset.dest(argsToPass));
66
- trackCommandUsage('create', { assetType }, getAccountId(options));
66
+ const { derivedAccountId } = options;
67
+ trackCommandUsage('create', { assetType }, derivedAccountId);
67
68
  try {
68
69
  await fs.ensureDir(dest);
69
70
  }
@@ -99,5 +100,7 @@ exports.builder = yargs => {
99
100
  type: 'boolean',
100
101
  hidden: true,
101
102
  });
103
+ addConfigOptions(yargs);
104
+ addGlobalOptions(yargs);
102
105
  return yargs;
103
106
  };
@@ -1,46 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // @ts-nocheck
4
+ const promptUtils_1 = require("../../lib/prompts/promptUtils");
4
5
  const { logger } = require('@hubspot/local-dev-lib/logger');
5
6
  const { logError } = require('../../lib/errorHandlers/index');
6
7
  const { getAbsoluteFilePath } = require('@hubspot/local-dev-lib/path');
7
- const { checkAndConvertToJson, loadAndValidateOptions, } = require('../../lib/validation');
8
+ const { checkAndConvertToJson } = require('../../lib/validation');
8
9
  const { trackCommandUsage } = require('../../lib/usageTracking');
9
- const { getAccountId } = require('../../lib/commonOpts');
10
10
  const { batchCreateObjects, } = require('@hubspot/local-dev-lib/api/customObjects');
11
11
  const { i18n } = require('../../lib/lang');
12
12
  const i18nKey = 'commands.customObject.subcommands.create';
13
13
  const { EXIT_CODES } = require('../../lib/enums/exitCodes');
14
- exports.command = 'create <name> <definition>';
14
+ exports.command = 'create [name]';
15
15
  exports.describe = i18n(`${i18nKey}.describe`);
16
16
  exports.handler = async (options) => {
17
- const { definition, name } = options;
18
- await loadAndValidateOptions(options);
19
- const accountId = getAccountId(options);
20
- trackCommandUsage('custom-object-batch-create', null, accountId);
21
- const filePath = getAbsoluteFilePath(definition);
17
+ const { path, name: providedName, derivedAccountId } = options;
18
+ let definitionPath = path;
19
+ trackCommandUsage('custom-object-batch-create', null, derivedAccountId);
20
+ if (!definitionPath) {
21
+ definitionPath = await (0, promptUtils_1.inputPrompt)(i18n(`${i18nKey}.inputPath`));
22
+ }
23
+ const filePath = getAbsoluteFilePath(definitionPath);
22
24
  const objectJson = checkAndConvertToJson(filePath);
23
25
  if (!objectJson) {
24
26
  process.exit(EXIT_CODES.ERROR);
25
27
  }
28
+ const name = providedName || (await (0, promptUtils_1.inputPrompt)(i18n(`${i18nKey}.inputSchema`)));
26
29
  try {
27
- await batchCreateObjects(accountId, name, objectJson);
30
+ await batchCreateObjects(derivedAccountId, name, objectJson);
28
31
  logger.success(i18n(`${i18nKey}.success.objectsCreated`));
29
32
  }
30
33
  catch (e) {
31
- logError(e, { accountId });
34
+ logError(e, { accountId: derivedAccountId });
32
35
  logger.error(i18n(`${i18nKey}.errors.creationFailed`, {
33
- definition,
36
+ definition: definitionPath,
34
37
  }));
35
38
  }
36
39
  };
37
40
  exports.builder = yargs => {
38
- yargs.positional('name', {
41
+ yargs
42
+ .positional('name', {
39
43
  describe: i18n(`${i18nKey}.positionals.name.describe`),
40
44
  type: 'string',
41
- });
42
- yargs.positional('definition', {
43
- describe: i18n(`${i18nKey}.positionals.definition.describe`),
45
+ })
46
+ .option('path', {
47
+ describe: i18n(`${i18nKey}.options.path.describe`),
44
48
  type: 'string',
45
49
  });
46
50
  };
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const { logger } = require('@hubspot/local-dev-lib/logger');
5
5
  const { logError } = require('../../../lib/errorHandlers/index');
6
6
  const { getAbsoluteFilePath } = require('@hubspot/local-dev-lib/path');
7
- const { checkAndConvertToJson, loadAndValidateOptions, } = require('../../../lib/validation');
7
+ const { checkAndConvertToJson } = require('../../../lib/validation');
8
8
  const { trackCommandUsage } = require('../../../lib/usageTracking');
9
- const { addTestingOptions, getAccountId } = require('../../../lib/commonOpts');
9
+ const { addTestingOptions } = require('../../../lib/commonOpts');
10
10
  const { getEnv, isConfigFlagEnabled, } = require('@hubspot/local-dev-lib/config');
11
11
  const { ENVIRONMENTS, } = require('@hubspot/local-dev-lib/constants/environments');
12
12
  const { CONFIG_FLAGS } = require('../../../lib/constants');
@@ -16,43 +16,42 @@ const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
16
16
  const { i18n } = require('../../../lib/lang');
17
17
  const i18nKey = 'commands.customObject.subcommands.schema.subcommands.create';
18
18
  const { EXIT_CODES } = require('../../../lib/enums/exitCodes');
19
- exports.command = 'create <definition>';
19
+ exports.command = 'create';
20
20
  exports.describe = i18n(`${i18nKey}.describe`);
21
21
  exports.handler = async (options) => {
22
- const { definition } = options;
23
- await loadAndValidateOptions(options);
24
- const accountId = getAccountId(options);
25
- trackCommandUsage('custom-object-schema-create', null, accountId);
26
- const filePath = getAbsoluteFilePath(definition);
22
+ const { path, derivedAccountId } = options;
23
+ trackCommandUsage('custom-object-schema-create', null, derivedAccountId);
24
+ const filePath = getAbsoluteFilePath(path);
27
25
  const schemaJson = checkAndConvertToJson(filePath);
28
26
  if (!schemaJson) {
29
27
  process.exit(EXIT_CODES.ERROR);
30
28
  }
31
29
  try {
32
30
  if (isConfigFlagEnabled(CONFIG_FLAGS.USE_CUSTOM_OBJECT_HUBFILE)) {
33
- await createSchemaFromHubFile(accountId, filePath);
31
+ await createSchemaFromHubFile(derivedAccountId, filePath);
34
32
  logger.success(i18n(`${i18nKey}.success.schemaCreated`, {
35
- accountId,
33
+ accountId: derivedAccountId,
36
34
  }));
37
35
  }
38
36
  else {
39
- const { data } = await createObjectSchema(accountId, schemaJson);
37
+ const { data } = await createObjectSchema(derivedAccountId, schemaJson);
40
38
  logger.success(i18n(`${i18nKey}.success.schemaViewable`, {
41
- url: `${getHubSpotWebsiteOrigin(getEnv() === 'qa' ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD)}/contacts/${accountId}/objects/${data.objectTypeId}`,
39
+ url: `${getHubSpotWebsiteOrigin(getEnv() === 'qa' ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD)}/contacts/${derivedAccountId}/objects/${data.objectTypeId}`,
42
40
  }));
43
41
  }
44
42
  }
45
43
  catch (e) {
46
- logError(e, { accountId });
44
+ logError(e, { accountId: derivedAccountId });
47
45
  logger.error(i18n(`${i18nKey}.errors.creationFailed`, {
48
- definition,
46
+ definition: path,
49
47
  }));
50
48
  }
51
49
  };
52
50
  exports.builder = yargs => {
53
51
  addTestingOptions(yargs);
54
- yargs.positional('definition', {
55
- describe: i18n(`${i18nKey}.positionals.definition.describe`),
52
+ yargs.option('path', {
53
+ describe: i18n(`${i18nKey}.options.definition.describe`),
56
54
  type: 'string',
55
+ required: true,
57
56
  });
58
57
  };