@hubspot/cli 7.0.1-experimental.0 → 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.
- package/README.md +3 -2
- package/bin/cli.js +30 -3
- package/commands/customObject/create.js +4 -1
- package/commands/hubdb/create.js +2 -2
- package/commands/project/deploy.js +1 -1
- package/commands/project/dev.js +4 -3
- package/commands/sandbox/create.js +5 -10
- package/commands/theme/preview.js +3 -2
- package/lang/en.lyaml +6 -2
- package/lib/DevServerManager.d.ts +40 -1
- package/lib/DevServerManager.js +39 -30
- package/lib/LocalDevManager.js +7 -6
- package/lib/buildAccount.js +3 -3
- package/lib/commonOpts.d.ts +0 -7
- package/lib/commonOpts.js +0 -14
- package/lib/dependencyManagement.d.ts +9 -4
- package/lib/dependencyManagement.js +45 -49
- package/lib/errorHandlers/index.js +5 -2
- package/lib/localDev.js +1 -7
- package/lib/projects/structure.d.ts +2 -71
- package/lib/projects/structure.js +6 -10
- package/lib/projects/upload.js +2 -1
- package/lib/projects/watch.d.ts +3 -0
- package/lib/projects/watch.js +73 -70
- package/lib/sandboxSync.d.ts +4 -1
- package/lib/sandboxSync.js +67 -68
- package/lib/sandboxes.d.ts +20 -1
- package/lib/sandboxes.js +77 -175
- package/package.json +10 -9
- package/types/Projects.d.ts +68 -0
- package/types/Projects.js +7 -0
- package/types/Sandboxes.d.ts +3 -0
- package/types/Sandboxes.js +2 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @hubspot/cli
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@hubspot/cli) [](https://www.npmjs.com/package/@hubspot/cli) [](https://www.npmjs.com/package/@hubspot/cli?activeTab=versions)
|
|
4
4
|
|
|
5
5
|
A CLI for HubSpot developers to enable local development and automation. [Learn more about building on HubSpot](https://developers.hubspot.com).
|
|
6
6
|
|
|
@@ -58,14 +58,15 @@ There are two ways that the tools can authenticate with HubSpot.
|
|
|
58
58
|
3. Select `OAuth2` and follow the steps
|
|
59
59
|
|
|
60
60
|
_**Note:** The Account ID used should be the Test Account ID (not the developer app ID). Client ID and Client Secret are from the developer app._
|
|
61
|
+
|
|
61
62
|
### Exit Codes
|
|
62
63
|
|
|
63
64
|
The CLI will exit with one of the following exit codes:
|
|
65
|
+
|
|
64
66
|
- `0`: A successful run
|
|
65
67
|
- `1`: There was a config problem or an internal error
|
|
66
68
|
- `2`: There are warnings or validation issues
|
|
67
69
|
|
|
68
|
-
|
|
69
70
|
## Changelog
|
|
70
71
|
|
|
71
72
|
The best way to stay up to date is to check out the [Github Releases](https://github.com/HubSpot/hubspot-cli/releases) and also follow our [developer changelog posts](https://developers.hubspot.com/changelog) for an easier to read breakdown of major changes.
|
package/bin/cli.js
CHANGED
|
@@ -5,16 +5,16 @@ const updateNotifier = require('update-notifier');
|
|
|
5
5
|
const chalk = require('chalk');
|
|
6
6
|
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
7
7
|
const { addUserAgentHeader } = require('@hubspot/local-dev-lib/http');
|
|
8
|
-
const { loadConfig, configFileExists, getConfigPath, validateConfig, } = require('@hubspot/local-dev-lib/config');
|
|
8
|
+
const { loadConfig, getAccountId, configFileExists, getConfigPath, validateConfig, } = require('@hubspot/local-dev-lib/config');
|
|
9
9
|
const { logError } = require('../lib/errorHandlers/index');
|
|
10
|
-
const { setLogLevel, getCommandName
|
|
10
|
+
const { setLogLevel, getCommandName } = require('../lib/commonOpts');
|
|
11
11
|
const { validateAccount } = require('../lib/validation');
|
|
12
12
|
const { trackHelpUsage, trackConvertFieldsUsage, } = require('../lib/usageTracking');
|
|
13
13
|
const { getIsInProject } = require('../lib/projects');
|
|
14
14
|
const pkg = require('../package.json');
|
|
15
15
|
const { i18n } = require('../lib/lang');
|
|
16
16
|
const { EXIT_CODES } = require('../lib/enums/exitCodes');
|
|
17
|
-
const { UI_COLORS, uiCommandReference } = require('../lib/ui');
|
|
17
|
+
const { UI_COLORS, uiCommandReference, uiDeprecatedTag } = require('../lib/ui');
|
|
18
18
|
const { checkAndWarnGitInclusion } = require('../lib/ui/git');
|
|
19
19
|
const removeCommand = require('../commands/remove');
|
|
20
20
|
const initCommand = require('../commands/init');
|
|
@@ -141,6 +141,32 @@ const SKIP_CONFIG_VALIDATION = {
|
|
|
141
141
|
init: { target: true },
|
|
142
142
|
auth: { target: true },
|
|
143
143
|
};
|
|
144
|
+
const handleDeprecatedEnvVariables = options => {
|
|
145
|
+
// HUBSPOT_PORTAL_ID is deprecated, but we'll still support it for now
|
|
146
|
+
// The HubSpot GH Deploy Action still uses HUBSPOT_PORTAL_ID
|
|
147
|
+
if (options.useEnv &&
|
|
148
|
+
process.env.HUBSPOT_PORTAL_ID &&
|
|
149
|
+
!process.env.HUBSPOT_ACCOUNT_ID) {
|
|
150
|
+
uiDeprecatedTag(i18n(`${i18nKey}.handleDeprecatedEnvVariables.portalEnvVarDeprecated`, {
|
|
151
|
+
configPath: getConfigPath(),
|
|
152
|
+
}));
|
|
153
|
+
process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Auto-injects the derivedAccountId flag into all commands
|
|
158
|
+
*/
|
|
159
|
+
const injectAccountIdMiddleware = async (options) => {
|
|
160
|
+
const { account } = options;
|
|
161
|
+
// Preserves the original --account flag for certain commands.
|
|
162
|
+
options.providedAccountId = account;
|
|
163
|
+
if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) {
|
|
164
|
+
options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
options.derivedAccountId = getAccountId(account);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
144
170
|
const loadConfigMiddleware = async (options) => {
|
|
145
171
|
// Skip this when no command is provided
|
|
146
172
|
if (!options._.length) {
|
|
@@ -213,6 +239,7 @@ const argv = yargs
|
|
|
213
239
|
.middleware([
|
|
214
240
|
setLogLevel,
|
|
215
241
|
setRequestHeaders,
|
|
242
|
+
handleDeprecatedEnvVariables,
|
|
216
243
|
loadConfigMiddleware,
|
|
217
244
|
injectAccountIdMiddleware,
|
|
218
245
|
checkAndWarnGitInclusionMiddleware,
|
|
@@ -16,7 +16,11 @@ exports.describe = i18n(`${i18nKey}.describe`);
|
|
|
16
16
|
exports.handler = async (options) => {
|
|
17
17
|
const { path, name: providedName, derivedAccountId } = options;
|
|
18
18
|
let definitionPath = path;
|
|
19
|
+
let name = providedName;
|
|
19
20
|
trackCommandUsage('custom-object-batch-create', null, derivedAccountId);
|
|
21
|
+
if (!name) {
|
|
22
|
+
name = await (0, promptUtils_1.inputPrompt)(i18n(`${i18nKey}.inputName`));
|
|
23
|
+
}
|
|
20
24
|
if (!definitionPath) {
|
|
21
25
|
definitionPath = await (0, promptUtils_1.inputPrompt)(i18n(`${i18nKey}.inputPath`));
|
|
22
26
|
}
|
|
@@ -25,7 +29,6 @@ exports.handler = async (options) => {
|
|
|
25
29
|
if (!objectJson) {
|
|
26
30
|
process.exit(EXIT_CODES.ERROR);
|
|
27
31
|
}
|
|
28
|
-
const name = providedName || (await (0, promptUtils_1.inputPrompt)(i18n(`${i18nKey}.inputSchema`)));
|
|
29
32
|
try {
|
|
30
33
|
await batchCreateObjects(derivedAccountId, name, objectJson);
|
|
31
34
|
logger.success(i18n(`${i18nKey}.success.objectsCreated`));
|
package/commands/hubdb/create.js
CHANGED
|
@@ -42,9 +42,9 @@ exports.handler = async (options) => {
|
|
|
42
42
|
trackCommandUsage('hubdb-create', null, derivedAccountId);
|
|
43
43
|
let filePath;
|
|
44
44
|
try {
|
|
45
|
-
const
|
|
45
|
+
const filePath = 'path' in options
|
|
46
46
|
? path.resolve(getCwd(), options.path)
|
|
47
|
-
: await selectPathPrompt(options);
|
|
47
|
+
: path.resolve(getCwd(), (await selectPathPrompt(options)).path);
|
|
48
48
|
if (!checkAndConvertToJson(filePath)) {
|
|
49
49
|
process.exit(EXIT_CODES.ERROR);
|
|
50
50
|
}
|
|
@@ -75,7 +75,7 @@ exports.handler = async (options) => {
|
|
|
75
75
|
default: latestBuild.buildId === deployedBuildId
|
|
76
76
|
? undefined
|
|
77
77
|
: latestBuild.buildId,
|
|
78
|
-
validate:
|
|
78
|
+
validate: buildId => validateBuildId(buildId, deployedBuildId, latestBuild.buildId, projectName, derivedAccountId),
|
|
79
79
|
});
|
|
80
80
|
buildIdToDeploy = deployBuildIdPromptResponse.buildId;
|
|
81
81
|
}
|
package/commands/project/dev.js
CHANGED
|
@@ -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 {
|
|
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[
|
|
39
|
-
const hasPublicApps = !!componentTypes[
|
|
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,
|
|
@@ -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 {
|
|
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 && !
|
|
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
|
-
?
|
|
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 !==
|
|
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
|
|
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 ===
|
|
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
|
@@ -7,6 +7,8 @@ en:
|
|
|
7
7
|
cliUpdateNotification: "HubSpot CLI version {{#cyan}}{{#bold}}{currentVersion}{{/bold}}{{/cyan}} is outdated.\nRun {{ updateCommand }} to upgrade to version {{#cyan}}{{#bold}}{latestVersion}{{/bold}}{{/cyan}}"
|
|
8
8
|
srcIsProject: "\"{{ src }}\" is in a project folder. Did you mean \"hs project {{command}}\"?"
|
|
9
9
|
setDefaultAccountMoved: "This command has moved. Try `hs accounts use` instead"
|
|
10
|
+
handleDeprecatedEnvVariables:
|
|
11
|
+
portalEnvVarDeprecated: "The HUBSPOT_PORTAL_ID environment variable is deprecated. Please use HUBSPOT_ACCOUNT_ID instead."
|
|
10
12
|
loadConfigMiddleware:
|
|
11
13
|
configFileExists: "A configuration file already exists at {{ configPath }}. To specify a new configuration file, delete the existing one and try again."
|
|
12
14
|
completion:
|
|
@@ -214,8 +216,8 @@ en:
|
|
|
214
216
|
describe: "Schema name to add the object instance to"
|
|
215
217
|
success:
|
|
216
218
|
objectsCreated: "Objects created"
|
|
217
|
-
|
|
218
|
-
inputPath: "[--path]
|
|
219
|
+
inputName: "[--name] Enter the name of the schema for the custom object(s) you'd like to create:"
|
|
220
|
+
inputPath: "[--path] Enter the path to the JSON file containing the object definitions:"
|
|
219
221
|
schema:
|
|
220
222
|
describe: "Commands for managing custom object schemas."
|
|
221
223
|
subcommands:
|
|
@@ -1418,6 +1420,7 @@ en:
|
|
|
1418
1420
|
failure:
|
|
1419
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}}."
|
|
1420
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."
|
|
1421
1424
|
limit:
|
|
1422
1425
|
developer:
|
|
1423
1426
|
one: "{{#bold}}{{ accountName }}{{/bold}} reached the limit of {{ limit }} development sandbox.
|
|
@@ -1477,6 +1480,7 @@ en:
|
|
|
1477
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 }}."
|
|
1478
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."
|
|
1479
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."
|
|
1480
1484
|
errorHandlers:
|
|
1481
1485
|
index:
|
|
1482
1486
|
errorOccurred: "Error: {{ error }}"
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
|
|
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;
|
package/lib/DevServerManager.js
CHANGED
|
@@ -1,34 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
123
|
+
const Manager = new DevServerManager();
|
|
124
|
+
exports.default = Manager;
|
|
125
|
+
module.exports = Manager;
|
package/lib/LocalDevManager.js
CHANGED
|
@@ -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,
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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(
|
|
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(
|
|
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;
|
package/lib/buildAccount.js
CHANGED
|
@@ -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 {
|
|
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 =
|
|
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(
|
|
115
|
+
handleSandboxCreateError(err, env, name, accountId);
|
|
116
116
|
}
|
|
117
117
|
if (isDeveloperTestAccount) {
|
|
118
118
|
handleDeveloperTestAccountCreateError(err, env, accountId, portalLimit);
|
package/lib/commonOpts.d.ts
CHANGED
|
@@ -24,13 +24,6 @@ export declare function getCommandName(argv: Arguments<{
|
|
|
24
24
|
export declare function getAccountId(options: Arguments<{
|
|
25
25
|
account?: number | string;
|
|
26
26
|
}>): number | null;
|
|
27
|
-
/**
|
|
28
|
-
* Auto-injects the derivedAccountId flag into all commands
|
|
29
|
-
*/
|
|
30
|
-
export declare function injectAccountIdMiddleware(options: Arguments<{
|
|
31
|
-
derivedAccountId?: number | null;
|
|
32
|
-
account?: number | string;
|
|
33
|
-
}>): Promise<void>;
|
|
34
27
|
export declare function getCmsPublishMode(options: Arguments<{
|
|
35
28
|
cmsPublishMode?: CmsPublishMode;
|
|
36
29
|
}>): CmsPublishMode;
|
package/lib/commonOpts.js
CHANGED
|
@@ -10,7 +10,6 @@ exports.addUseEnvironmentOptions = addUseEnvironmentOptions;
|
|
|
10
10
|
exports.setLogLevel = setLogLevel;
|
|
11
11
|
exports.getCommandName = getCommandName;
|
|
12
12
|
exports.getAccountId = getAccountId;
|
|
13
|
-
exports.injectAccountIdMiddleware = injectAccountIdMiddleware;
|
|
14
13
|
exports.getCmsPublishMode = getCmsPublishMode;
|
|
15
14
|
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
16
15
|
const files_1 = require("@hubspot/local-dev-lib/constants/files");
|
|
@@ -94,19 +93,6 @@ function getAccountId(options) {
|
|
|
94
93
|
}
|
|
95
94
|
return (0, config_1.getAccountId)(account);
|
|
96
95
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Auto-injects the derivedAccountId flag into all commands
|
|
99
|
-
*/
|
|
100
|
-
async function injectAccountIdMiddleware(options) {
|
|
101
|
-
const { account } = options;
|
|
102
|
-
// Preserves the original --account flag for certain commands.
|
|
103
|
-
options.providedAccountId = account;
|
|
104
|
-
if (options.useEnv && process.env.HUBSPOT_ACCOUNT_ID) {
|
|
105
|
-
options.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
options.derivedAccountId = (0, config_1.getAccountId)(account);
|
|
109
|
-
}
|
|
110
96
|
function getCmsPublishMode(options) {
|
|
111
97
|
// 1. --cmsPublishMode
|
|
112
98
|
const { cmsPublishMode } = options;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
export declare function isGloballyInstalled(command:
|
|
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
|
|
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>;
|