@hubspot/cli 4.1.7-beta.2 → 4.1.7
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.
|
@@ -18,6 +18,7 @@ const { getConfig, getEnv } = require('@hubspot/cli-lib');
|
|
|
18
18
|
const { deleteSandboxPrompt } = require('../../lib/prompts/sandboxesPrompt');
|
|
19
19
|
const {
|
|
20
20
|
removeSandboxAccountFromConfig,
|
|
21
|
+
updateDefaultAccount,
|
|
21
22
|
} = require('@hubspot/cli-lib/lib/config');
|
|
22
23
|
const {
|
|
23
24
|
selectAndSetAsDefaultAccountPrompt,
|
|
@@ -38,13 +39,26 @@ exports.describe = i18n(`${i18nKey}.describe`);
|
|
|
38
39
|
exports.handler = async options => {
|
|
39
40
|
await loadAndValidateOptions(options, false);
|
|
40
41
|
|
|
41
|
-
const { account } = options;
|
|
42
|
+
const { account, force } = options;
|
|
42
43
|
const config = getConfig();
|
|
43
44
|
|
|
44
45
|
let accountPrompt;
|
|
45
46
|
if (!account) {
|
|
46
|
-
|
|
47
|
+
if (!force) {
|
|
48
|
+
accountPrompt = await deleteSandboxPrompt(config);
|
|
49
|
+
} else {
|
|
50
|
+
// Account is required, throw error if force flag is present and no account is specified
|
|
51
|
+
logger.log('');
|
|
52
|
+
logger.error(i18n(`${i18nKey}.failure.noAccount`));
|
|
53
|
+
process.exit(EXIT_CODES.ERROR);
|
|
54
|
+
}
|
|
55
|
+
if (!accountPrompt) {
|
|
56
|
+
logger.log('');
|
|
57
|
+
logger.error(i18n(`${i18nKey}.failure.noSandboxAccounts`));
|
|
58
|
+
process.exit(EXIT_CODES.ERROR);
|
|
59
|
+
}
|
|
47
60
|
}
|
|
61
|
+
|
|
48
62
|
const sandboxAccountId = getAccountId({
|
|
49
63
|
account: account || accountPrompt.account,
|
|
50
64
|
});
|
|
@@ -54,31 +68,36 @@ exports.handler = async options => {
|
|
|
54
68
|
|
|
55
69
|
trackCommandUsage('sandbox-delete', null, sandboxAccountId);
|
|
56
70
|
|
|
71
|
+
const baseUrl = getHubSpotWebsiteOrigin(
|
|
72
|
+
getEnv(sandboxAccountId) === 'qa' ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD
|
|
73
|
+
);
|
|
74
|
+
|
|
57
75
|
let parentAccountId;
|
|
58
76
|
for (const portal of config.portals) {
|
|
59
77
|
if (portal.portalId === sandboxAccountId) {
|
|
60
78
|
if (portal.parentAccountId) {
|
|
61
79
|
parentAccountId = portal.parentAccountId;
|
|
62
|
-
} else {
|
|
80
|
+
} else if (!force) {
|
|
63
81
|
const parentAccountPrompt = await deleteSandboxPrompt(config, true);
|
|
64
82
|
parentAccountId = getAccountId({
|
|
65
83
|
account: parentAccountPrompt.account,
|
|
66
84
|
});
|
|
85
|
+
} else {
|
|
86
|
+
logger.error(i18n(`${i18nKey}.failure.noParentAccount`));
|
|
87
|
+
process.exit(EXIT_CODES.ERROR);
|
|
67
88
|
}
|
|
68
89
|
}
|
|
69
90
|
}
|
|
70
91
|
|
|
92
|
+
const url = `${baseUrl}/sandboxes/${parentAccountId}`;
|
|
93
|
+
const command = `hs auth ${
|
|
94
|
+
getEnv(sandboxAccountId) === 'qa' ? '--qa' : ''
|
|
95
|
+
} --account=${parentAccountId}`;
|
|
96
|
+
|
|
71
97
|
if (!getAccountId({ account: parentAccountId })) {
|
|
72
|
-
const baseUrl = getHubSpotWebsiteOrigin(
|
|
73
|
-
getEnv(sandboxAccountId) === 'qa' ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD
|
|
74
|
-
);
|
|
75
|
-
const url = `${baseUrl}/sandboxes/${parentAccountId}`;
|
|
76
|
-
const command = `hs auth ${
|
|
77
|
-
getEnv(sandboxAccountId) === 'qa' ? '--qa' : ''
|
|
78
|
-
} --account=${parentAccountId}`;
|
|
79
98
|
logger.log('');
|
|
80
99
|
logger.error(
|
|
81
|
-
i18n(`${i18nKey}.noParentPortalAvailable`, {
|
|
100
|
+
i18n(`${i18nKey}.failure.noParentPortalAvailable`, {
|
|
82
101
|
parentAccountId,
|
|
83
102
|
url,
|
|
84
103
|
command,
|
|
@@ -103,17 +122,19 @@ exports.handler = async options => {
|
|
|
103
122
|
}
|
|
104
123
|
|
|
105
124
|
try {
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
if (!force) {
|
|
126
|
+
const { confirmSandboxDeletePrompt: confirmed } = await promptUser([
|
|
127
|
+
{
|
|
128
|
+
name: 'confirmSandboxDeletePrompt',
|
|
129
|
+
type: 'confirm',
|
|
130
|
+
message: i18n(`${i18nKey}.confirm`, {
|
|
131
|
+
account: account || accountPrompt.account,
|
|
132
|
+
}),
|
|
133
|
+
},
|
|
134
|
+
]);
|
|
135
|
+
if (!confirmed) {
|
|
136
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
137
|
+
}
|
|
117
138
|
}
|
|
118
139
|
|
|
119
140
|
await deleteSandbox(parentAccountId, sandboxAccountId);
|
|
@@ -133,8 +154,11 @@ exports.handler = async options => {
|
|
|
133
154
|
const promptDefaultAccount = removeSandboxAccountFromConfig(
|
|
134
155
|
sandboxAccountId
|
|
135
156
|
);
|
|
136
|
-
if (promptDefaultAccount) {
|
|
157
|
+
if (promptDefaultAccount && !force) {
|
|
137
158
|
await selectAndSetAsDefaultAccountPrompt(getConfig());
|
|
159
|
+
} else {
|
|
160
|
+
// If force is specified, skip prompt and set the parent account id as the default account
|
|
161
|
+
updateDefaultAccount(parentAccountId);
|
|
138
162
|
}
|
|
139
163
|
process.exit(EXIT_CODES.SUCCESS);
|
|
140
164
|
} catch (err) {
|
|
@@ -156,7 +180,7 @@ exports.handler = async options => {
|
|
|
156
180
|
) {
|
|
157
181
|
logger.log('');
|
|
158
182
|
logger.warn(
|
|
159
|
-
i18n(`${i18nKey}.objectNotFound`, {
|
|
183
|
+
i18n(`${i18nKey}.failure.objectNotFound`, {
|
|
160
184
|
account: account || accountPrompt.account,
|
|
161
185
|
})
|
|
162
186
|
);
|
|
@@ -165,8 +189,11 @@ exports.handler = async options => {
|
|
|
165
189
|
const promptDefaultAccount = removeSandboxAccountFromConfig(
|
|
166
190
|
sandboxAccountId
|
|
167
191
|
);
|
|
168
|
-
if (promptDefaultAccount) {
|
|
192
|
+
if (promptDefaultAccount && !force) {
|
|
169
193
|
await selectAndSetAsDefaultAccountPrompt(getConfig());
|
|
194
|
+
} else {
|
|
195
|
+
// If force is specified, skip prompt and set the parent account id as the default account
|
|
196
|
+
updateDefaultAccount(parentAccountId);
|
|
170
197
|
}
|
|
171
198
|
process.exit(EXIT_CODES.SUCCESS);
|
|
172
199
|
} else {
|
|
@@ -181,6 +208,11 @@ exports.builder = yargs => {
|
|
|
181
208
|
describe: i18n(`${i18nKey}.options.account.describe`),
|
|
182
209
|
type: 'string',
|
|
183
210
|
});
|
|
211
|
+
yargs.option('f', {
|
|
212
|
+
type: 'boolean',
|
|
213
|
+
alias: 'force',
|
|
214
|
+
describe: i18n(`${i18nKey}.examples.force`),
|
|
215
|
+
});
|
|
184
216
|
|
|
185
217
|
yargs.example([
|
|
186
218
|
[
|
|
@@ -15,6 +15,18 @@ const mapSandboxAccountChoices = portals =>
|
|
|
15
15
|
};
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
const mapNonSandboxAccountChoices = portals =>
|
|
19
|
+
portals
|
|
20
|
+
.filter(
|
|
21
|
+
p => p.sandboxAccountType === null || p.sandboxAccountType === undefined
|
|
22
|
+
)
|
|
23
|
+
.map(p => {
|
|
24
|
+
return {
|
|
25
|
+
name: `${p.name} (${p.portalId})`,
|
|
26
|
+
value: p.name || p.portalId,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
18
30
|
const createSandboxPrompt = () => {
|
|
19
31
|
return promptUser([
|
|
20
32
|
{
|
|
@@ -32,6 +44,12 @@ const createSandboxPrompt = () => {
|
|
|
32
44
|
};
|
|
33
45
|
|
|
34
46
|
const deleteSandboxPrompt = (config, promptParentAccount = false) => {
|
|
47
|
+
const choices = promptParentAccount
|
|
48
|
+
? mapNonSandboxAccountChoices(config.portals)
|
|
49
|
+
: mapSandboxAccountChoices(config.portals);
|
|
50
|
+
if (!choices.length) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
35
53
|
return promptUser([
|
|
36
54
|
{
|
|
37
55
|
name: 'account',
|
|
@@ -43,7 +61,7 @@ const deleteSandboxPrompt = (config, promptParentAccount = false) => {
|
|
|
43
61
|
type: 'list',
|
|
44
62
|
look: false,
|
|
45
63
|
pageSize: 20,
|
|
46
|
-
choices
|
|
64
|
+
choices,
|
|
47
65
|
default: config.defaultPortal,
|
|
48
66
|
},
|
|
49
67
|
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cli",
|
|
3
|
-
"version": "4.1.7
|
|
3
|
+
"version": "4.1.7",
|
|
4
4
|
"description": "CLI for working with HubSpot",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"url": "https://github.com/HubSpot/hubspot-cms-tools"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@hubspot/cli-lib": "4.1.7
|
|
12
|
-
"@hubspot/serverless-dev-runtime": "4.1.7
|
|
11
|
+
"@hubspot/cli-lib": "4.1.7",
|
|
12
|
+
"@hubspot/serverless-dev-runtime": "4.1.7",
|
|
13
13
|
"archiver": "^5.3.0",
|
|
14
14
|
"chalk": "^4.1.2",
|
|
15
15
|
"cli-progress": "^3.11.2",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ef2292568ec8308feb0c5841e4d3dd25a64d1050"
|
|
42
42
|
}
|