@hubspot/cli 7.0.1 → 7.0.2-experimental.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.
@@ -14,7 +14,8 @@ const SpinniesManager = require('../../lib/ui/SpinniesManager');
14
14
  const LocalDevManager = require('../../lib/LocalDevManager');
15
15
  const { isSandbox, isDeveloperTestAccount, isStandardAccount, isAppDeveloperAccount, } = require('../../lib/accountTypes');
16
16
  const { getValidEnv } = require('@hubspot/local-dev-lib/environment');
17
- const { findProjectComponents, getProjectComponentTypes, COMPONENT_TYPES, } = require('../../lib/projects/structure');
17
+ const { ComponentTypes } = require('../../types/Projects');
18
+ const { findProjectComponents, getProjectComponentTypes, } = require('../../lib/projects/structure');
18
19
  const { confirmDefaultAccountIsTarget, suggestRecommendedNestedAccount, checkIfDefaultAccountIsSupported, createSandboxForLocalDev, createDeveloperTestAccountForLocalDev, createNewProjectForLocalDev, createInitialBuildForNewProject, useExistingDevTestAccount, checkIfAccountFlagIsSupported, checkIfParentAccountIsAuthed, } = require('../../lib/localDev');
19
20
  const i18nKey = 'commands.project.subcommands.dev';
20
21
  exports.command = 'dev';
@@ -35,8 +36,8 @@ exports.handler = async (options) => {
35
36
  const components = await findProjectComponents(projectDir);
36
37
  const runnableComponents = components.filter(component => component.runnable);
37
38
  const componentTypes = getProjectComponentTypes(runnableComponents);
38
- const hasPrivateApps = !!componentTypes[COMPONENT_TYPES.privateApp];
39
- const hasPublicApps = !!componentTypes[COMPONENT_TYPES.publicApp];
39
+ const hasPrivateApps = !!componentTypes[ComponentTypes.PrivateApp];
40
+ const hasPublicApps = !!componentTypes[ComponentTypes.PublicApp];
40
41
  if (runnableComponents.length === 0) {
41
42
  logger.error(i18n(`${i18nKey}.errors.noRunnableComponents`, {
42
43
  projectDir,
@@ -22,15 +22,15 @@ exports.handler = async (options) => {
22
22
  const { forceCreate, message, derivedAccountId } = options;
23
23
  const accountConfig = getAccountConfig(derivedAccountId);
24
24
  const accountType = accountConfig && accountConfig.accountType;
25
- trackCommandUsage('project-upload', { type: accountType }, derivedAccountId);
26
25
  const { projectConfig, projectDir } = await getProjectConfig();
26
+ trackCommandUsage('project-upload', { type: accountType }, derivedAccountId);
27
27
  validateProjectConfig(projectConfig, projectDir);
28
28
  await ensureProjectExists(derivedAccountId, projectConfig.name, {
29
29
  forceCreate,
30
30
  uploadCommand: true,
31
31
  });
32
32
  try {
33
- const result = await handleProjectUpload(derivedAccountId, projectConfig, projectDir, pollProjectBuildAndDeploy, message);
33
+ const result = await handleProjectUpload(derivedAccountId, projectConfig, projectDir, pollProjectBuildAndDeploy, message, options.translate);
34
34
  if (result.uploadError) {
35
35
  if (isSpecifiedError(result.uploadError, {
36
36
  subCategory: PROJECT_ERROR_TYPES.PROJECT_LOCKED,
@@ -80,6 +80,11 @@ exports.builder = yargs => {
80
80
  type: 'string',
81
81
  default: '',
82
82
  },
83
+ translate: {
84
+ hidden: true,
85
+ type: 'boolean',
86
+ default: false,
87
+ },
83
88
  });
84
89
  yargs.example([['$0 project upload', i18n(`${i18nKey}.examples.default`)]]);
85
90
  addConfigOptions(yargs);
@@ -6,7 +6,7 @@ const { i18n } = require('../../lib/lang');
6
6
  const { EXIT_CODES } = require('../../lib/enums/exitCodes');
7
7
  const { getAccountConfig, getEnv } = require('@hubspot/local-dev-lib/config');
8
8
  const { uiFeatureHighlight, uiBetaTag } = require('../../lib/ui');
9
- const { sandboxTypeMap, getAvailableSyncTypes, syncTypes, validateSandboxUsageLimits, } = require('../../lib/sandboxes');
9
+ const { SANDBOX_TYPE_MAP, getAvailableSyncTypes, SYNC_TYPES, validateSandboxUsageLimits, } = require('../../lib/sandboxes');
10
10
  const { getValidEnv } = require('@hubspot/local-dev-lib/environment');
11
11
  const { logger } = require('@hubspot/local-dev-lib/logger');
12
12
  const { trackCommandUsage } = require('../../lib/usageTracking');
@@ -38,7 +38,7 @@ exports.handler = async (options) => {
38
38
  }
39
39
  let typePrompt;
40
40
  let namePrompt;
41
- if ((type && !sandboxTypeMap[type.toLowerCase()]) || !type) {
41
+ if ((type && !SANDBOX_TYPE_MAP[type.toLowerCase()]) || !type) {
42
42
  if (!force) {
43
43
  typePrompt = await sandboxTypePrompt();
44
44
  }
@@ -48,7 +48,7 @@ exports.handler = async (options) => {
48
48
  }
49
49
  }
50
50
  const sandboxType = type
51
- ? sandboxTypeMap[type.toLowerCase()]
51
+ ? SANDBOX_TYPE_MAP[type.toLowerCase()]
52
52
  : typePrompt.type;
53
53
  // Check usage limits and exit if parent portal has no available sandboxes for the selected type
54
54
  try {
@@ -107,17 +107,12 @@ exports.handler = async (options) => {
107
107
  const sandboxAccountConfig = getAccountConfig(result.sandbox.sandboxHubId);
108
108
  // For v1 sandboxes, keep sync here. Once we migrate to v2, this will be handled by BE automatically
109
109
  const handleSyncSandbox = async (syncTasks) => {
110
- await syncSandbox({
111
- accountConfig: sandboxAccountConfig,
112
- parentAccountConfig: accountConfig,
113
- env,
114
- syncTasks,
115
- });
110
+ await syncSandbox(sandboxAccountConfig, accountConfig, env, syncTasks);
116
111
  };
117
112
  try {
118
113
  let availableSyncTasks = await getAvailableSyncTypes(accountConfig, sandboxAccountConfig);
119
114
  if (!contactRecordsSyncPromptResult) {
120
- availableSyncTasks = availableSyncTasks.filter(t => t.type !== syncTypes.OBJECT_RECORDS);
115
+ availableSyncTasks = availableSyncTasks.filter(t => t.type !== SYNC_TYPES.OBJECT_RECORDS);
121
116
  }
122
117
  await handleSyncSandbox(availableSyncTasks);
123
118
  }
@@ -17,7 +17,8 @@ const { ApiErrorContext, logError } = require('../../lib/errorHandlers/index');
17
17
  const { handleExit, handleKeypress } = require('../../lib/process');
18
18
  const { getThemeJSONPath } = require('@hubspot/local-dev-lib/cms/themes');
19
19
  const { getProjectConfig } = require('../../lib/projects');
20
- const { findProjectComponents, COMPONENT_TYPES, } = require('../../lib/projects/structure');
20
+ const { findProjectComponents } = require('../../lib/projects/structure');
21
+ const { ComponentTypes } = require('../../types/Projects');
21
22
  const { preview } = require('@hubspot/theme-preview-dev-server');
22
23
  const { hasFeature } = require('../../lib/hasFeature');
23
24
  const i18nKey = 'commands.theme.subcommands.preview';
@@ -73,7 +74,7 @@ const determineSrcAndDest = async (options) => {
73
74
  let themeJsonPath = getThemeJSONPath();
74
75
  if (!themeJsonPath) {
75
76
  const projectComponents = await findProjectComponents(projectDir);
76
- const themeComponents = projectComponents.filter(c => c.type === COMPONENT_TYPES.hublTheme);
77
+ const themeComponents = projectComponents.filter(c => c.type === ComponentTypes.HublTheme);
77
78
  if (themeComponents.length === 0) {
78
79
  logger.error(i18n(`${i18nKey}.errors.noThemeComponents`));
79
80
  process.exit(EXIT_CODES.ERROR);
package/lang/en.lyaml CHANGED
@@ -1420,6 +1420,7 @@ en:
1420
1420
  failure:
1421
1421
  invalidUser: "Couldn't create {{#bold}}{{ accountName }}{{/bold}} because your account has been removed from {{#bold}}{{ parentAccountName }}{{/bold}} or your permission set doesn't allow you to create the sandbox. To update your permissions, contact a super admin in {{#bold}}{{ parentAccountName }}{{/bold}}."
1422
1422
  403Gating: "Couldn't create {{#bold}}{{ accountName }}{{/bold}} because {{#bold}}{{ parentAccountName }}{{/bold}} does not have access to development sandboxes. To opt in to the CRM Development Beta and use development sandboxes, visit https://app.hubspot.com/l/product-updates/in-beta?update=13899236."
1423
+ usageLimitsFetch: "Unable to fetch sandbox usage limits. Please try again."
1423
1424
  limit:
1424
1425
  developer:
1425
1426
  one: "{{#bold}}{{ accountName }}{{/bold}} reached the limit of {{ limit }} development sandbox.
@@ -1479,6 +1480,7 @@ en:
1479
1480
  syncInProgress: "Couldn't run the sync because there's another sync in progress. Wait for the current sync to finish and then try again. To check the sync status, visit the sync activity log: {{ url }}."
1480
1481
  notSuperAdmin: "Couldn't run the sync because you are not a super admin in {{ account }}. Ask the account owner for super admin access to the sandbox."
1481
1482
  objectNotFound: "Couldn't sync the sandbox because {{#bold}}{{ account }}{{/bold}} may have been deleted through the UI. Run {{#bold}}hs sandbox delete{{/bold}} to remove this account from the config. "
1483
+ syncTypeFetch: "Unable to fetch available sandbox sync types. Please try again."
1482
1484
  errorHandlers:
1483
1485
  index:
1484
1486
  errorOccurred: "Error: {{ error }}"
@@ -1 +1,40 @@
1
- export {};
1
+ import { ProjectConfig, ComponentTypes, Component } from '../types/Projects';
2
+ type DevServerInterface = {
3
+ setup?: Function;
4
+ start?: (options: object) => Promise<void>;
5
+ fileChange?: (filePath: string, event: string) => Promise<void>;
6
+ cleanup?: () => Promise<void>;
7
+ };
8
+ type ComponentsByType = {
9
+ [key in ComponentTypes]?: {
10
+ [key: string]: Component;
11
+ };
12
+ };
13
+ declare class DevServerManager {
14
+ private initialized;
15
+ private started;
16
+ private componentsByType;
17
+ private devServers;
18
+ constructor();
19
+ iterateDevServers(callback: (serverInterface: DevServerInterface, compatibleComponents: {
20
+ [key: string]: Component;
21
+ }) => Promise<void>): Promise<void>;
22
+ arrangeComponentsByType(components: Component[]): ComponentsByType;
23
+ setup({ components, onUploadRequired, accountId, setActiveApp, }: {
24
+ components: Component[];
25
+ onUploadRequired: () => void;
26
+ accountId: number;
27
+ setActiveApp: (appUid: string | undefined) => Promise<void>;
28
+ }): Promise<void>;
29
+ start({ accountId, projectConfig, }: {
30
+ accountId: number;
31
+ projectConfig: ProjectConfig;
32
+ }): Promise<void>;
33
+ fileChange({ filePath, event, }: {
34
+ filePath: string;
35
+ event: string;
36
+ }): Promise<void>;
37
+ cleanup(): Promise<void>;
38
+ }
39
+ declare const Manager: DevServerManager;
40
+ export default Manager;
@@ -1,34 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // @ts-nocheck
4
- const { logger } = require('@hubspot/local-dev-lib/logger');
5
- const { COMPONENT_TYPES } = require('./projects/structure');
6
- const { i18n } = require('./lang');
7
- const { promptUser } = require('./prompts/promptUtils');
8
- const { DevModeInterface } = require('@hubspot/ui-extensions-dev-server');
9
- const { startPortManagerServer, stopPortManagerServer, requestPorts, } = require('@hubspot/local-dev-lib/portManager');
10
- const { getHubSpotApiOrigin, getHubSpotWebsiteOrigin, } = require('@hubspot/local-dev-lib/urls');
11
- const { getAccountConfig } = require('@hubspot/local-dev-lib/config');
3
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
4
+ const lang_1 = require("./lang");
5
+ const promptUtils_1 = require("./prompts/promptUtils");
6
+ const ui_extensions_dev_server_1 = require("@hubspot/ui-extensions-dev-server");
7
+ const portManager_1 = require("@hubspot/local-dev-lib/portManager");
8
+ const urls_1 = require("@hubspot/local-dev-lib/urls");
9
+ const config_1 = require("@hubspot/local-dev-lib/config");
10
+ const Projects_1 = require("../types/Projects");
12
11
  const i18nKey = 'lib.DevServerManager';
13
12
  const SERVER_KEYS = {
14
13
  privateApp: 'privateApp',
15
14
  publicApp: 'publicApp',
16
15
  };
17
16
  class DevServerManager {
17
+ initialized;
18
+ started;
19
+ componentsByType;
20
+ devServers;
18
21
  constructor() {
19
22
  this.initialized = false;
20
23
  this.started = false;
21
24
  this.componentsByType = {};
22
- this.server = null;
23
- this.path = null;
24
25
  this.devServers = {
25
26
  [SERVER_KEYS.privateApp]: {
26
- componentType: COMPONENT_TYPES.privateApp,
27
- serverInterface: DevModeInterface,
27
+ componentType: Projects_1.ComponentTypes.PrivateApp,
28
+ serverInterface: ui_extensions_dev_server_1.DevModeInterface,
28
29
  },
29
30
  [SERVER_KEYS.publicApp]: {
30
- componentType: COMPONENT_TYPES.publicApp,
31
- serverInterface: DevModeInterface,
31
+ componentType: Projects_1.ComponentTypes.PublicApp,
32
+ serverInterface: ui_extensions_dev_server_1.DevModeInterface,
32
33
  },
33
34
  };
34
35
  }
@@ -42,7 +43,7 @@ class DevServerManager {
42
43
  await callback(devServer.serverInterface, compatibleComponents);
43
44
  }
44
45
  else {
45
- logger.debug(i18n(`${i18nKey}.noCompatibleComponents`, { serverKey }));
46
+ logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.noCompatibleComponents`, { serverKey }));
46
47
  }
47
48
  }
48
49
  }
@@ -51,24 +52,30 @@ class DevServerManager {
51
52
  if (!acc[component.type]) {
52
53
  acc[component.type] = {};
53
54
  }
54
- acc[component.type][component.config.name] = component;
55
+ if ('name' in component.config && component.config.name) {
56
+ acc[component.type][component.config.name] = component;
57
+ }
55
58
  return acc;
56
59
  }, {});
57
60
  }
58
- async setup({ components, onUploadRequired, accountId, setActiveApp }) {
61
+ async setup({ components, onUploadRequired, accountId, setActiveApp, }) {
59
62
  this.componentsByType = this.arrangeComponentsByType(components);
60
- const { env } = getAccountConfig(accountId);
61
- await startPortManagerServer();
63
+ let env;
64
+ const accountConfig = (0, config_1.getAccountConfig)(accountId);
65
+ if (accountConfig) {
66
+ env = accountConfig.env;
67
+ }
68
+ await (0, portManager_1.startPortManagerServer)();
62
69
  await this.iterateDevServers(async (serverInterface, compatibleComponents) => {
63
70
  if (serverInterface.setup) {
64
71
  await serverInterface.setup({
65
72
  components: compatibleComponents,
66
73
  onUploadRequired,
67
- promptUser,
68
- logger,
74
+ promptUser: promptUtils_1.promptUser,
75
+ logger: logger_1.logger,
69
76
  urls: {
70
- api: getHubSpotApiOrigin(env),
71
- web: getHubSpotWebsiteOrigin(env),
77
+ api: (0, urls_1.getHubSpotApiOrigin)(env),
78
+ web: (0, urls_1.getHubSpotWebsiteOrigin)(env),
72
79
  },
73
80
  setActiveApp,
74
81
  });
@@ -76,24 +83,24 @@ class DevServerManager {
76
83
  });
77
84
  this.initialized = true;
78
85
  }
79
- async start({ accountId, projectConfig }) {
86
+ async start({ accountId, projectConfig, }) {
80
87
  if (this.initialized) {
81
88
  await this.iterateDevServers(async (serverInterface) => {
82
89
  if (serverInterface.start) {
83
90
  await serverInterface.start({
84
91
  accountId,
85
92
  projectConfig,
86
- requestPorts,
93
+ requestPorts: portManager_1.requestPorts,
87
94
  });
88
95
  }
89
96
  });
90
97
  }
91
98
  else {
92
- throw new Error(i18n(`${i18nKey}.notInitialized`));
99
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.notInitialized`));
93
100
  }
94
101
  this.started = true;
95
102
  }
96
- fileChange({ filePath, event }) {
103
+ async fileChange({ filePath, event, }) {
97
104
  if (this.started) {
98
105
  this.iterateDevServers(async (serverInterface) => {
99
106
  if (serverInterface.fileChange) {
@@ -109,8 +116,10 @@ class DevServerManager {
109
116
  await serverInterface.cleanup();
110
117
  }
111
118
  });
112
- await stopPortManagerServer();
119
+ await (0, portManager_1.stopPortManagerServer)();
113
120
  }
114
121
  }
115
122
  }
116
- module.exports = new DevServerManager();
123
+ const Manager = new DevServerManager();
124
+ exports.default = Manager;
125
+ module.exports = Manager;
@@ -16,7 +16,8 @@ const DevServerManager = require('./DevServerManager');
16
16
  const { EXIT_CODES } = require('./enums/exitCodes');
17
17
  const { getProjectDetailUrl } = require('./projects/urls');
18
18
  const { getAccountHomeUrl } = require('./localDev');
19
- const { CONFIG_FILES, COMPONENT_TYPES, getAppCardConfigs, } = require('./projects/structure');
19
+ const { CONFIG_FILES, getAppCardConfigs } = require('./projects/structure');
20
+ const { ComponentTypes } = require('../types/Projects');
20
21
  const { UI_COLORS, uiCommandReference, uiAccountDescription, uiBetaTag, uiLink, uiLine, } = require('./ui');
21
22
  const { logError } = require('./errorHandlers/index');
22
23
  const { installPublicAppPrompt } = require('./prompts/installPublicAppPrompt');
@@ -62,7 +63,7 @@ class LocalDevManager {
62
63
  this.activeApp = this.runnableComponents.find(component => {
63
64
  return component.config.uid === appUid;
64
65
  });
65
- if (this.activeApp.type === COMPONENT_TYPES.publicApp) {
66
+ if (this.activeApp.type === ComponentTypes.PublicApp) {
66
67
  try {
67
68
  await this.setActivePublicAppData();
68
69
  await this.checkActivePublicAppInstalls();
@@ -131,7 +132,7 @@ class LocalDevManager {
131
132
  projectName: this.projectConfig.name,
132
133
  })));
133
134
  logger.log(uiLink(i18n(`${i18nKey}.viewProjectLink`), getProjectDetailUrl(this.projectConfig.name, this.targetProjectAccountId)));
134
- if (this.activeApp.type === COMPONENT_TYPES.publicApp) {
135
+ if (this.activeApp.type === ComponentTypes.PublicApp) {
135
136
  logger.log(uiLink(i18n(`${i18nKey}.viewTestAccountLink`), getAccountHomeUrl(this.targetAccountId)));
136
137
  }
137
138
  logger.log();
@@ -198,7 +199,7 @@ class LocalDevManager {
198
199
  let warning = reason;
199
200
  if (!reason) {
200
201
  warning =
201
- this.activeApp.type === COMPONENT_TYPES.publicApp &&
202
+ this.activeApp.type === ComponentTypes.PublicApp &&
202
203
  this.publicAppActiveInstalls > 0
203
204
  ? i18n(`${i18nKey}.uploadWarning.defaultPublicAppWarning`, {
204
205
  installCount: this.publicAppActiveInstalls,
@@ -244,7 +245,7 @@ class LocalDevManager {
244
245
  const deployedComponentNames = this.deployedBuild.subbuildStatuses.map(subbuildStatus => subbuildStatus.buildName);
245
246
  const missingComponents = [];
246
247
  this.runnableComponents.forEach(({ type, config, path }) => {
247
- if (Object.values(COMPONENT_TYPES).includes(type)) {
248
+ if (Object.values(ComponentTypes).includes(type)) {
248
249
  const cardConfigs = getAppCardConfigs(config, path);
249
250
  if (!deployedComponentNames.includes(config.name)) {
250
251
  missingComponents.push(`${i18n(`${i18nKey}.uploadWarning.appLabel`)} ${config.name}`);
@@ -269,7 +270,7 @@ class LocalDevManager {
269
270
  ignoreInitial: true,
270
271
  });
271
272
  const configPaths = this.runnableComponents
272
- .filter(({ type }) => Object.values(COMPONENT_TYPES).includes(type))
273
+ .filter(({ type }) => Object.values(ComponentTypes).includes(type))
273
274
  .map(component => {
274
275
  const appConfigPath = path.join(component.path, CONFIG_FILES[component.type]);
275
276
  return appConfigPath;
@@ -13,7 +13,7 @@ const { debugError, logError } = require('./errorHandlers/index');
13
13
  const { createDeveloperTestAccount, } = require('@hubspot/local-dev-lib/api/developerTestAccounts');
14
14
  const { HUBSPOT_ACCOUNT_TYPES, } = require('@hubspot/local-dev-lib/constants/config');
15
15
  const { createSandbox } = require('@hubspot/local-dev-lib/api/sandboxHubs');
16
- const { sandboxApiTypeMap, handleSandboxCreateError } = require('./sandboxes');
16
+ const { SANDBOX_API_TYPE_MAP, handleSandboxCreateError, } = require('./sandboxes');
17
17
  const { handleDeveloperTestAccountCreateError, } = require('./developerTestAccounts');
18
18
  async function saveAccountToConfig({ env, personalAccessKey, accountName, accountId, force = false, }) {
19
19
  if (!personalAccessKey) {
@@ -87,7 +87,7 @@ force = false, }) {
87
87
  let resultAccountId;
88
88
  try {
89
89
  if (isSandbox) {
90
- const sandboxApiType = sandboxApiTypeMap[accountType]; // API expects sandbox type as 1 or 2.
90
+ const sandboxApiType = SANDBOX_API_TYPE_MAP[accountType]; // API expects sandbox type as 1 or 2.
91
91
  const { data } = await createSandbox(accountId, name, sandboxApiType);
92
92
  result = { name, ...data };
93
93
  resultAccountId = result.sandbox.sandboxHubId;
@@ -112,7 +112,7 @@ force = false, }) {
112
112
  }),
113
113
  });
114
114
  if (isSandbox) {
115
- handleSandboxCreateError({ err, env, accountConfig, name, accountId });
115
+ handleSandboxCreateError(err, env, name, accountId);
116
116
  }
117
117
  if (isDeveloperTestAccount) {
118
118
  handleDeveloperTestAccountCreateError(err, env, accountId, portalLimit);
@@ -1,6 +1,11 @@
1
- export declare function isGloballyInstalled(command: any): Promise<boolean>;
2
- export declare function getLatestCliVersion(): {
1
+ export declare function isGloballyInstalled(command: string): Promise<boolean>;
2
+ export declare function getLatestCliVersion(): Promise<{
3
3
  latest: string;
4
4
  next: string;
5
- };
6
- export declare function hasMissingPackages(directory: any): Promise<boolean>;
5
+ }>;
6
+ export declare function installPackages({ packages, installLocations, }: {
7
+ packages?: string[];
8
+ installLocations?: string[];
9
+ }): Promise<void>;
10
+ export declare function getProjectPackageJsonLocations(): Promise<string[]>;
11
+ export declare function hasMissingPackages(directory: string): Promise<boolean>;
@@ -1,32 +1,36 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.isGloballyInstalled = isGloballyInstalled;
4
7
  exports.getLatestCliVersion = getLatestCliVersion;
8
+ exports.installPackages = installPackages;
9
+ exports.getProjectPackageJsonLocations = getProjectPackageJsonLocations;
5
10
  exports.hasMissingPackages = hasMissingPackages;
6
- // @ts-nocheck
7
- const { logger } = require('@hubspot/local-dev-lib/logger');
8
- const { getProjectConfig } = require('./projects');
9
- const { exec: execAsync } = require('child_process');
10
- const { walk } = require('@hubspot/local-dev-lib/fs');
11
- const path = require('path');
12
- const { uiLink } = require('./ui');
13
- const util = require('util');
14
- const { i18n } = require('./lang');
15
- const SpinniesManager = require('./ui/SpinniesManager');
16
- const fs = require('fs');
17
- const pkg = require('../package.json');
11
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
12
+ const projects_1 = require("./projects");
13
+ const child_process_1 = require("child_process");
14
+ const fs_1 = require("@hubspot/local-dev-lib/fs");
15
+ const path_1 = __importDefault(require("path"));
16
+ const ui_1 = require("./ui");
17
+ const util_1 = __importDefault(require("util"));
18
+ const lang_1 = require("./lang");
19
+ const SpinniesManager_1 = __importDefault(require("./ui/SpinniesManager"));
20
+ const fs_2 = __importDefault(require("fs"));
21
+ const package_json_1 = __importDefault(require("../package.json"));
18
22
  const DEFAULT_PACKAGE_MANAGER = 'npm';
19
23
  const i18nKey = `commands.project.subcommands.installDeps`;
20
24
  class NoPackageJsonFilesError extends Error {
21
25
  constructor(projectName) {
22
- super(i18n(`${i18nKey}.noPackageJsonInProject`, {
26
+ super((0, lang_1.i18n)(`${i18nKey}.noPackageJsonInProject`, {
23
27
  projectName,
24
- link: uiLink('Learn how to create a project from scratch.', 'https://developers.hubspot.com/beta-docs/guides/crm/intro/create-a-project'),
28
+ link: (0, ui_1.uiLink)('Learn how to create a project from scratch.', 'https://developers.hubspot.com/beta-docs/guides/crm/intro/create-a-project'),
25
29
  }));
26
30
  }
27
31
  }
28
32
  async function isGloballyInstalled(command) {
29
- const exec = util.promisify(execAsync);
33
+ const exec = util_1.default.promisify(child_process_1.exec);
30
34
  try {
31
35
  await exec(`${command} --version`);
32
36
  return true;
@@ -36,28 +40,28 @@ async function isGloballyInstalled(command) {
36
40
  }
37
41
  }
38
42
  async function getLatestCliVersion() {
39
- const exec = util.promisify(execAsync);
40
- const { stdout } = await exec(`npm info ${pkg.name} dist-tags --json`);
43
+ const exec = util_1.default.promisify(child_process_1.exec);
44
+ const { stdout } = await exec(`npm info ${package_json_1.default.name} dist-tags --json`);
41
45
  const { latest, next } = JSON.parse(stdout);
42
46
  return { latest, next };
43
47
  }
44
- async function installPackages({ packages, installLocations }) {
48
+ async function installPackages({ packages, installLocations, }) {
45
49
  const installDirs = installLocations || (await getProjectPackageJsonLocations());
46
50
  await Promise.all(installDirs.map(async (dir) => {
47
- await installPackagesInDirectory(packages, dir);
51
+ await installPackagesInDirectory(dir, packages);
48
52
  }));
49
53
  }
50
- async function installPackagesInDirectory(packages, directory) {
54
+ async function installPackagesInDirectory(directory, packages) {
51
55
  const spinner = `installingDependencies-${directory}`;
52
- const relativeDir = path.relative(process.cwd(), directory);
53
- SpinniesManager.init();
54
- SpinniesManager.add(spinner, {
56
+ const relativeDir = path_1.default.relative(process.cwd(), directory);
57
+ SpinniesManager_1.default.init();
58
+ SpinniesManager_1.default.add(spinner, {
55
59
  text: packages && packages.length
56
- ? i18n(`${i18nKey}.addingDependenciesToLocation`, {
60
+ ? (0, lang_1.i18n)(`${i18nKey}.addingDependenciesToLocation`, {
57
61
  dependencies: `[${packages.join(', ')}]`,
58
62
  directory: relativeDir,
59
63
  })
60
- : i18n(`${i18nKey}.installingDependencies`, {
64
+ : (0, lang_1.i18n)(`${i18nKey}.installingDependencies`, {
61
65
  directory: relativeDir,
62
66
  }),
63
67
  });
@@ -65,23 +69,23 @@ async function installPackagesInDirectory(packages, directory) {
65
69
  if (packages) {
66
70
  installCommand = `${installCommand} ${packages.join(' ')}`;
67
71
  }
68
- logger.debug(`Running ${installCommand}`);
72
+ logger_1.logger.debug(`Running ${installCommand}`);
69
73
  try {
70
- const exec = util.promisify(execAsync);
74
+ const exec = util_1.default.promisify(child_process_1.exec);
71
75
  await exec(installCommand, { cwd: directory });
72
- SpinniesManager.succeed(spinner, {
73
- text: i18n(`${i18nKey}.installationSuccessful`, {
76
+ SpinniesManager_1.default.succeed(spinner, {
77
+ text: (0, lang_1.i18n)(`${i18nKey}.installationSuccessful`, {
74
78
  directory: relativeDir,
75
79
  }),
76
80
  });
77
81
  }
78
82
  catch (e) {
79
- SpinniesManager.fail(spinner, {
80
- text: i18n(`${i18nKey}.installingDependenciesFailed`, {
83
+ SpinniesManager_1.default.fail(spinner, {
84
+ text: (0, lang_1.i18n)(`${i18nKey}.installingDependenciesFailed`, {
81
85
  directory: relativeDir,
82
86
  }),
83
87
  });
84
- throw new Error(i18n(`${i18nKey}.installingDependenciesFailed`, {
88
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.installingDependenciesFailed`, {
85
89
  directory: relativeDir,
86
90
  }), {
87
91
  cause: e,
@@ -89,24 +93,24 @@ async function installPackagesInDirectory(packages, directory) {
89
93
  }
90
94
  }
91
95
  async function getProjectPackageJsonLocations() {
92
- const projectConfig = await getProjectConfig();
96
+ const projectConfig = await (0, projects_1.getProjectConfig)();
93
97
  if (!projectConfig ||
94
98
  !projectConfig.projectDir ||
95
99
  !projectConfig.projectConfig) {
96
- throw new Error(i18n(`${i18nKey}.noProjectConfig`));
100
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.noProjectConfig`));
97
101
  }
98
102
  const { projectDir, projectConfig: { srcDir, name }, } = projectConfig;
99
103
  if (!(await isGloballyInstalled(DEFAULT_PACKAGE_MANAGER))) {
100
- throw new Error(i18n(`${i18nKey}.packageManagerNotInstalled`, {
104
+ throw new Error((0, lang_1.i18n)(`${i18nKey}.packageManagerNotInstalled`, {
101
105
  packageManager: DEFAULT_PACKAGE_MANAGER,
102
- link: uiLink(DEFAULT_PACKAGE_MANAGER, 'https://docs.npmjs.com/downloading-and-installing-node-js-and-npm'),
106
+ link: (0, ui_1.uiLink)(DEFAULT_PACKAGE_MANAGER, 'https://docs.npmjs.com/downloading-and-installing-node-js-and-npm'),
103
107
  }));
104
108
  }
105
- if (!fs.existsSync(projectConfig.projectDir) ||
106
- !fs.existsSync(path.join(projectDir, srcDir))) {
109
+ if (!fs_2.default.existsSync(projectConfig.projectDir) ||
110
+ !fs_2.default.existsSync(path_1.default.join(projectDir, srcDir))) {
107
111
  throw new NoPackageJsonFilesError(name);
108
112
  }
109
- const packageJsonFiles = (await walk(path.join(projectDir, srcDir))).filter(file => file.includes('package.json') &&
113
+ const packageJsonFiles = (await (0, fs_1.walk)(path_1.default.join(projectDir, srcDir))).filter(file => file.includes('package.json') &&
110
114
  !file.includes('node_modules') &&
111
115
  !file.includes('.vite'));
112
116
  if (packageJsonFiles.length === 0) {
@@ -114,23 +118,15 @@ async function getProjectPackageJsonLocations() {
114
118
  }
115
119
  const packageParentDirs = [];
116
120
  packageJsonFiles.forEach(packageJsonFile => {
117
- const parentDir = path.dirname(packageJsonFile);
121
+ const parentDir = path_1.default.dirname(packageJsonFile);
118
122
  packageParentDirs.push(parentDir);
119
123
  });
120
124
  return packageParentDirs;
121
125
  }
122
126
  async function hasMissingPackages(directory) {
123
- const exec = util.promisify(execAsync);
127
+ const exec = util_1.default.promisify(child_process_1.exec);
124
128
  const { stdout } = await exec(`npm install --ignore-scripts --dry-run`, {
125
129
  cwd: directory,
126
130
  });
127
131
  return !stdout?.includes('up to date in');
128
132
  }
129
- module.exports = {
130
- isGloballyInstalled,
131
- installPackages,
132
- DEFAULT_PACKAGE_MANAGER,
133
- getProjectPackageJsonLocations,
134
- getLatestCliVersion,
135
- hasMissingPackages,
136
- };
@@ -11,6 +11,7 @@ const index_1 = require("@hubspot/local-dev-lib/errors/index");
11
11
  const suppressError_1 = require("./suppressError");
12
12
  const lang_1 = require("../lang");
13
13
  const util_1 = __importDefault(require("util"));
14
+ const axios_1 = require("axios");
14
15
  const i18nKey = 'lib.errorHandlers.index';
15
16
  function logError(error, context) {
16
17
  debugError(error, context);
@@ -49,9 +50,11 @@ function debugError(error, context) {
49
50
  else {
50
51
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorOccurred`, { error: String(error) }));
51
52
  }
52
- if (error instanceof Error) {
53
+ if (error instanceof Error && error.cause) {
53
54
  logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.errorCause`, {
54
- cause: util_1.default.inspect(error.cause, false, null, true),
55
+ cause: (0, axios_1.isAxiosError)(error.cause)
56
+ ? `${error.cause}`
57
+ : util_1.default.inspect(error.cause, false, null, true),
55
58
  }));
56
59
  }
57
60
  if (context) {
package/lib/localDev.js CHANGED
@@ -142,13 +142,7 @@ const createSandboxForLocalDev = async (accountId, accountConfig, env) => {
142
142
  const sandboxAccountConfig = getAccountConfig(result.sandbox.sandboxHubId);
143
143
  const syncTasks = await getAvailableSyncTypes(accountConfig, sandboxAccountConfig);
144
144
  // For v1 sandboxes, keep sync here. Once we migrate to v2, this will be handled by BE automatically
145
- await syncSandbox({
146
- accountConfig: sandboxAccountConfig,
147
- parentAccountConfig: accountConfig,
148
- env,
149
- syncTasks,
150
- slimInfoMessage: true,
151
- });
145
+ await syncSandbox(sandboxAccountConfig, accountConfig, env, syncTasks, true);
152
146
  return targetAccountId;
153
147
  }
154
148
  catch (err) {