@hubspot/cli 7.2.0-experimental.0 → 7.2.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/bin/cli.js +52 -3
- package/commands/account/auth.d.ts +10 -0
- package/commands/account/auth.js +154 -0
- package/commands/account/createOverride.d.ts +10 -0
- package/commands/account/createOverride.js +62 -0
- package/commands/account/list.js +4 -0
- package/commands/account.js +4 -0
- package/commands/auth.js +9 -5
- package/commands/config/migrate.d.ts +10 -0
- package/commands/config/migrate.js +86 -0
- package/commands/config/set.d.ts +12 -0
- package/commands/config/set.js +30 -29
- package/commands/config.d.ts +4 -1
- package/commands/config.js +45 -10
- package/commands/create/api-sample.js +4 -14
- package/commands/customObject/create.d.ts +0 -11
- package/commands/customObject/create.js +28 -37
- package/commands/customObject/schema/create.d.ts +0 -10
- package/commands/customObject/schema/create.js +42 -40
- package/commands/customObject/schema/delete.d.ts +0 -11
- package/commands/customObject/schema/delete.js +27 -34
- package/commands/customObject/schema/fetch-all.d.ts +0 -10
- package/commands/customObject/schema/fetch-all.js +24 -31
- package/commands/customObject/schema/fetch.d.ts +0 -11
- package/commands/customObject/schema/fetch.js +42 -34
- package/commands/customObject/schema/list.d.ts +0 -7
- package/commands/customObject/schema/list.js +14 -23
- package/commands/customObject/schema/update.d.ts +0 -11
- package/commands/customObject/schema/update.js +46 -44
- package/commands/customObject/schema.d.ts +1 -5
- package/commands/customObject/schema.js +11 -49
- package/commands/customObject.d.ts +1 -4
- package/commands/customObject.js +21 -54
- package/commands/filemanager/fetch.d.ts +0 -12
- package/commands/filemanager/fetch.js +30 -33
- package/commands/filemanager/upload.d.ts +0 -11
- package/commands/filemanager/upload.js +47 -53
- package/commands/filemanager.d.ts +1 -4
- package/commands/filemanager.js +7 -41
- package/commands/init.js +15 -26
- package/commands/project/add.js +16 -62
- package/commands/project/cloneApp.js +3 -3
- package/commands/project/create.js +15 -70
- package/commands/project/dev.d.ts +0 -7
- package/commands/project/dev.js +75 -96
- package/commands/project/migrateApp.js +3 -3
- package/commands/project/upload.js +2 -7
- package/commands/sandbox/create.d.ts +0 -12
- package/commands/sandbox/create.js +72 -90
- package/commands/sandbox/delete.d.ts +0 -11
- package/commands/sandbox/delete.js +95 -112
- package/commands/sandbox.d.ts +1 -4
- package/commands/sandbox.js +10 -44
- package/commands/theme/generate-selectors.d.ts +0 -9
- package/commands/theme/generate-selectors.js +43 -61
- package/commands/theme/marketplace-validate.d.ts +0 -10
- package/commands/theme/marketplace-validate.js +26 -32
- package/commands/theme/preview.d.ts +0 -16
- package/commands/theme/preview.js +97 -104
- package/commands/theme.d.ts +1 -4
- package/commands/theme.js +10 -44
- package/lang/en.lyaml +67 -39
- package/lib/LocalDevManager.d.ts +2 -2
- package/lib/buildAccount.d.ts +3 -2
- package/lib/configMigrate.d.ts +2 -0
- package/lib/configMigrate.js +83 -0
- package/lib/constants.d.ts +3 -0
- package/lib/constants.js +4 -1
- package/lib/doctor/Diagnosis.d.ts +1 -0
- package/lib/doctor/Diagnosis.js +7 -0
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +1 -6
- package/lib/doctor/DiagnosticInfoBuilder.js +1 -5
- package/lib/doctor/Doctor.d.ts +1 -1
- package/lib/doctor/Doctor.js +14 -6
- package/lib/localDev.d.ts +1 -2
- package/lib/marketplaceValidate.d.ts +2 -2
- package/lib/projects/buildAndDeploy.js +1 -4
- package/lib/projects/index.d.ts +5 -1
- package/lib/projects/index.js +62 -1
- package/lib/projects/upload.d.ts +1 -1
- package/lib/projects/upload.js +2 -2
- package/lib/prompts/accountNamePrompt.d.ts +1 -1
- package/lib/prompts/createProjectPrompt.d.ts +8 -6
- package/lib/prompts/createProjectPrompt.js +54 -26
- package/lib/prompts/projectAddPrompt.d.ts +3 -3
- package/lib/prompts/projectAddPrompt.js +6 -16
- package/lib/prompts/projectDevTargetAccountPrompt.d.ts +2 -3
- package/lib/prompts/sandboxesPrompt.d.ts +2 -3
- package/lib/prompts/sandboxesPrompt.js +1 -1
- package/lib/sandboxSync.js +2 -6
- package/lib/sandboxes.d.ts +5 -2
- package/lib/ui/index.d.ts +1 -1
- package/lib/ui/index.js +0 -1
- package/lib/upload.d.ts +1 -1
- package/lib/upload.js +20 -20
- package/lib/usageTracking.d.ts +1 -1
- package/lib/validation.d.ts +1 -1
- package/package.json +3 -4
- package/types/Projects.d.ts +6 -1
- package/types/Prompts.d.ts +0 -7
- package/types/Sandboxes.d.ts +0 -2
- package/types/Yargs.d.ts +0 -7
- package/lib/customObject.d.ts +0 -3
- package/lib/customObject.js +0 -15
- package/lib/projects/create.d.ts +0 -5
- package/lib/projects/create.js +0 -51
- package/lib/testUtils.d.ts +0 -12
- package/lib/testUtils.js +0 -10
|
@@ -1,207 +1,190 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const promptUtils_1 = require("../../lib/prompts/promptUtils");
|
|
21
|
-
const ui_1 = require("../../lib/ui");
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const { addAccountOptions, addConfigOptions, addUseEnvironmentOptions, addTestingOptions, } = require('../../lib/commonOpts');
|
|
5
|
+
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
6
|
+
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
7
|
+
const { logError, debugError } = require('../../lib/errorHandlers/index');
|
|
8
|
+
const { isSpecifiedError } = require('@hubspot/local-dev-lib/errors/index');
|
|
9
|
+
const { deleteSandbox } = require('@hubspot/local-dev-lib/api/sandboxHubs');
|
|
10
|
+
const { i18n } = require('../../lib/lang');
|
|
11
|
+
const { deleteSandboxPrompt } = require('../../lib/prompts/sandboxesPrompt');
|
|
12
|
+
const { getEnv, removeSandboxAccountFromConfig, updateDefaultAccount, getAccountId, getConfigAccounts, } = require('@hubspot/local-dev-lib/config');
|
|
13
|
+
const { getAccountIdentifier, } = require('@hubspot/local-dev-lib/config/getAccountIdentifier');
|
|
14
|
+
const { selectAccountFromConfig } = require('../../lib/prompts/accountsPrompt');
|
|
15
|
+
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
16
|
+
const { promptUser } = require('../../lib/prompts/promptUtils');
|
|
17
|
+
const { uiAccountDescription, uiBetaTag } = require('../../lib/ui');
|
|
18
|
+
const { getHubSpotWebsiteOrigin } = require('@hubspot/local-dev-lib/urls');
|
|
19
|
+
const { getValidEnv } = require('@hubspot/local-dev-lib/environment');
|
|
22
20
|
const i18nKey = 'commands.sandbox.subcommands.delete';
|
|
23
21
|
exports.command = 'delete';
|
|
24
|
-
exports.describe =
|
|
25
|
-
async
|
|
26
|
-
const { providedAccountId, force } =
|
|
27
|
-
|
|
22
|
+
exports.describe = exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false);
|
|
23
|
+
exports.handler = async (options) => {
|
|
24
|
+
const { providedAccountId, force } = options;
|
|
25
|
+
trackCommandUsage('sandbox-delete', null);
|
|
28
26
|
let accountPrompt;
|
|
29
27
|
if (!providedAccountId) {
|
|
30
28
|
if (!force) {
|
|
31
|
-
accountPrompt = await
|
|
29
|
+
accountPrompt = await deleteSandboxPrompt();
|
|
32
30
|
}
|
|
33
31
|
else {
|
|
34
32
|
// Account is required, throw error if force flag is present and no account is specified
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
process.exit(
|
|
33
|
+
logger.log('');
|
|
34
|
+
logger.error(i18n(`${i18nKey}.failure.noAccount`));
|
|
35
|
+
process.exit(EXIT_CODES.ERROR);
|
|
38
36
|
}
|
|
39
37
|
if (!accountPrompt) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}));
|
|
44
|
-
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
38
|
+
logger.log('');
|
|
39
|
+
logger.error(i18n(`${i18nKey}.failure.noSandboxAccounts`));
|
|
40
|
+
process.exit(EXIT_CODES.ERROR);
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
|
-
const sandboxAccountId =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
51
|
-
}
|
|
52
|
-
const isDefaultAccount = sandboxAccountId === (0, config_1.getAccountId)();
|
|
53
|
-
const baseUrl = (0, urls_1.getHubSpotWebsiteOrigin)((0, environment_1.getValidEnv)((0, config_1.getEnv)(sandboxAccountId)));
|
|
43
|
+
const sandboxAccountId = getAccountId(providedAccountId || accountPrompt.account);
|
|
44
|
+
const isDefaultAccount = sandboxAccountId === getAccountId();
|
|
45
|
+
const baseUrl = getHubSpotWebsiteOrigin(getValidEnv(getEnv(sandboxAccountId)));
|
|
54
46
|
let parentAccountId;
|
|
55
|
-
const accountsList =
|
|
47
|
+
const accountsList = getConfigAccounts();
|
|
56
48
|
for (const portal of accountsList) {
|
|
57
|
-
if (
|
|
49
|
+
if (getAccountIdentifier(portal) === sandboxAccountId) {
|
|
58
50
|
if (portal.parentAccountId) {
|
|
59
51
|
parentAccountId = portal.parentAccountId;
|
|
60
52
|
}
|
|
61
53
|
else if (!force) {
|
|
62
|
-
const parentAccountPrompt = await
|
|
63
|
-
|
|
64
|
-
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.failure.noParentAccount`, {
|
|
65
|
-
authCommand: (0, ui_1.uiCommandReference)('hs auth'),
|
|
66
|
-
}));
|
|
67
|
-
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
68
|
-
}
|
|
69
|
-
parentAccountId = (0, config_1.getAccountId)(parentAccountPrompt.account);
|
|
54
|
+
const parentAccountPrompt = await deleteSandboxPrompt(true);
|
|
55
|
+
parentAccountId = getAccountId(parentAccountPrompt.account);
|
|
70
56
|
}
|
|
71
57
|
else {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}));
|
|
75
|
-
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
58
|
+
logger.error(i18n(`${i18nKey}.failure.noParentAccount`));
|
|
59
|
+
process.exit(EXIT_CODES.ERROR);
|
|
76
60
|
}
|
|
77
61
|
}
|
|
78
62
|
}
|
|
79
63
|
const url = `${baseUrl}/sandboxes/${parentAccountId}`;
|
|
80
|
-
const command = `hs auth ${
|
|
81
|
-
if (parentAccountId && !
|
|
82
|
-
|
|
83
|
-
|
|
64
|
+
const command = `hs auth ${getEnv(sandboxAccountId) === 'qa' ? '--qa' : ''} --account=${parentAccountId}`;
|
|
65
|
+
if (parentAccountId && !getAccountId(parentAccountId)) {
|
|
66
|
+
logger.log('');
|
|
67
|
+
logger.error(i18n(`${i18nKey}.failure.noParentPortalAvailable`, {
|
|
84
68
|
parentAccountId,
|
|
85
69
|
url,
|
|
86
70
|
command,
|
|
87
71
|
}));
|
|
88
|
-
|
|
89
|
-
process.exit(
|
|
72
|
+
logger.log('');
|
|
73
|
+
process.exit(EXIT_CODES.ERROR);
|
|
90
74
|
}
|
|
91
|
-
|
|
92
|
-
account:
|
|
75
|
+
logger.debug(i18n(`${i18nKey}.debug.deleting`, {
|
|
76
|
+
account: uiAccountDescription(sandboxAccountId),
|
|
93
77
|
}));
|
|
94
78
|
if (isDefaultAccount) {
|
|
95
|
-
|
|
96
|
-
account:
|
|
79
|
+
logger.info(i18n(`${i18nKey}.defaultAccountWarning`, {
|
|
80
|
+
account: uiAccountDescription(sandboxAccountId),
|
|
97
81
|
}));
|
|
98
|
-
|
|
82
|
+
logger.log('');
|
|
99
83
|
}
|
|
100
84
|
try {
|
|
101
85
|
if (!force) {
|
|
102
|
-
const { confirmSandboxDeletePrompt: confirmed } = await
|
|
86
|
+
const { confirmSandboxDeletePrompt: confirmed } = await promptUser([
|
|
103
87
|
{
|
|
104
88
|
name: 'confirmSandboxDeletePrompt',
|
|
105
89
|
type: 'confirm',
|
|
106
|
-
message:
|
|
107
|
-
account:
|
|
90
|
+
message: i18n(`${i18nKey}.confirm`, {
|
|
91
|
+
account: uiAccountDescription(sandboxAccountId),
|
|
108
92
|
}),
|
|
109
93
|
},
|
|
110
94
|
]);
|
|
111
95
|
if (!confirmed) {
|
|
112
|
-
process.exit(
|
|
96
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
113
97
|
}
|
|
114
98
|
}
|
|
115
|
-
await
|
|
99
|
+
await deleteSandbox(parentAccountId, sandboxAccountId);
|
|
116
100
|
const deleteKey = isDefaultAccount
|
|
117
101
|
? `${i18nKey}.success.deleteDefault`
|
|
118
102
|
: `${i18nKey}.success.delete`;
|
|
119
|
-
|
|
120
|
-
|
|
103
|
+
logger.log('');
|
|
104
|
+
logger.success(i18n(deleteKey, {
|
|
121
105
|
account: providedAccountId || accountPrompt.account,
|
|
122
|
-
sandboxHubId: sandboxAccountId
|
|
106
|
+
sandboxHubId: sandboxAccountId,
|
|
123
107
|
}));
|
|
124
|
-
|
|
125
|
-
const promptDefaultAccount =
|
|
108
|
+
logger.log('');
|
|
109
|
+
const promptDefaultAccount = removeSandboxAccountFromConfig(sandboxAccountId);
|
|
126
110
|
if (promptDefaultAccount && !force) {
|
|
127
|
-
const newDefaultAccount = await
|
|
128
|
-
|
|
111
|
+
const newDefaultAccount = await selectAccountFromConfig();
|
|
112
|
+
updateDefaultAccount(newDefaultAccount);
|
|
129
113
|
}
|
|
130
114
|
else {
|
|
131
115
|
// If force is specified, skip prompt and set the parent account id as the default account
|
|
132
|
-
|
|
116
|
+
updateDefaultAccount(parentAccountId);
|
|
133
117
|
}
|
|
134
|
-
process.exit(
|
|
118
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
135
119
|
}
|
|
136
120
|
catch (err) {
|
|
137
|
-
|
|
138
|
-
if (
|
|
121
|
+
debugError(err);
|
|
122
|
+
if (isSpecifiedError(err, { statusCode: 401 })) {
|
|
139
123
|
// Intercept invalid key error
|
|
140
124
|
// This command uses the parent portal PAK to delete a sandbox, so we must specify which account needs a new key
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
account:
|
|
144
|
-
authCommand: (0, ui_1.uiCommandReference)('hs auth'),
|
|
125
|
+
logger.log('');
|
|
126
|
+
logger.error(i18n(`${i18nKey}.failure.invalidKey`, {
|
|
127
|
+
account: uiAccountDescription(parentAccountId),
|
|
145
128
|
}));
|
|
146
129
|
}
|
|
147
|
-
else if (
|
|
130
|
+
else if (isSpecifiedError(err, {
|
|
148
131
|
statusCode: 403,
|
|
149
132
|
category: 'BANNED',
|
|
150
133
|
subCategory: 'SandboxErrors.USER_ACCESS_NOT_ALLOWED',
|
|
151
134
|
})) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
accountName:
|
|
155
|
-
parentAccountName:
|
|
135
|
+
logger.log('');
|
|
136
|
+
logger.error(i18n(`${i18nKey}.failure.invalidUser`, {
|
|
137
|
+
accountName: uiAccountDescription(sandboxAccountId),
|
|
138
|
+
parentAccountName: uiAccountDescription(parentAccountId),
|
|
156
139
|
}));
|
|
157
|
-
|
|
140
|
+
logger.log('');
|
|
158
141
|
}
|
|
159
|
-
else if (
|
|
142
|
+
else if (isSpecifiedError(err, {
|
|
160
143
|
statusCode: 404,
|
|
161
144
|
category: 'OBJECT_NOT_FOUND',
|
|
162
145
|
subCategory: 'SandboxErrors.SANDBOX_NOT_FOUND',
|
|
163
146
|
})) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
account:
|
|
147
|
+
logger.log('');
|
|
148
|
+
logger.warn(i18n(`${i18nKey}.failure.objectNotFound`, {
|
|
149
|
+
account: uiAccountDescription(sandboxAccountId),
|
|
167
150
|
}));
|
|
168
|
-
|
|
169
|
-
const promptDefaultAccount =
|
|
151
|
+
logger.log('');
|
|
152
|
+
const promptDefaultAccount = removeSandboxAccountFromConfig(sandboxAccountId);
|
|
170
153
|
if (promptDefaultAccount && !force) {
|
|
171
|
-
const newDefaultAccount = await
|
|
172
|
-
|
|
154
|
+
const newDefaultAccount = await selectAccountFromConfig();
|
|
155
|
+
updateDefaultAccount(newDefaultAccount);
|
|
173
156
|
}
|
|
174
157
|
else {
|
|
175
158
|
// If force is specified, skip prompt and set the parent account id as the default account
|
|
176
|
-
|
|
159
|
+
updateDefaultAccount(parentAccountId);
|
|
177
160
|
}
|
|
178
|
-
process.exit(
|
|
161
|
+
process.exit(EXIT_CODES.SUCCESS);
|
|
179
162
|
}
|
|
180
163
|
else {
|
|
181
|
-
|
|
164
|
+
logError(err);
|
|
182
165
|
}
|
|
183
|
-
process.exit(
|
|
166
|
+
process.exit(EXIT_CODES.ERROR);
|
|
184
167
|
}
|
|
185
|
-
}
|
|
186
|
-
|
|
168
|
+
};
|
|
169
|
+
exports.builder = yargs => {
|
|
187
170
|
yargs.option('account', {
|
|
188
|
-
describe:
|
|
171
|
+
describe: i18n(`${i18nKey}.options.account.describe`),
|
|
189
172
|
type: 'string',
|
|
190
173
|
});
|
|
191
174
|
yargs.option('force', {
|
|
192
175
|
type: 'boolean',
|
|
193
176
|
alias: 'f',
|
|
194
|
-
describe:
|
|
177
|
+
describe: i18n(`${i18nKey}.options.force.describe`),
|
|
195
178
|
});
|
|
196
179
|
yargs.example([
|
|
197
180
|
[
|
|
198
181
|
'$0 sandbox delete --account=MySandboxAccount',
|
|
199
|
-
|
|
182
|
+
i18n(`${i18nKey}.examples.default`),
|
|
200
183
|
],
|
|
201
184
|
]);
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
185
|
+
addConfigOptions(yargs);
|
|
186
|
+
addAccountOptions(yargs);
|
|
187
|
+
addUseEnvironmentOptions(yargs);
|
|
188
|
+
addTestingOptions(yargs);
|
|
206
189
|
return yargs;
|
|
207
|
-
}
|
|
190
|
+
};
|
package/commands/sandbox.d.ts
CHANGED
package/commands/sandbox.js
CHANGED
|
@@ -1,50 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const del = __importStar(require("./sandbox/delete"));
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const { addGlobalOptions } = require('../lib/commonOpts');
|
|
5
|
+
const { i18n } = require('../lib/lang');
|
|
6
|
+
const { uiBetaTag } = require('../lib/ui');
|
|
7
|
+
const create = require('./sandbox/create');
|
|
8
|
+
const del = require('./sandbox/delete');
|
|
43
9
|
const i18nKey = 'commands.sandbox';
|
|
44
10
|
exports.command = ['sandbox', 'sandboxes'];
|
|
45
|
-
exports.describe =
|
|
46
|
-
|
|
47
|
-
|
|
11
|
+
exports.describe = uiBetaTag(i18n(`${i18nKey}.describe`), false);
|
|
12
|
+
exports.builder = yargs => {
|
|
13
|
+
addGlobalOptions(yargs);
|
|
48
14
|
yargs.command(create).command(del).demandCommand(1, '');
|
|
49
15
|
return yargs;
|
|
50
|
-
}
|
|
16
|
+
};
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
import { Argv, ArgumentsCamelCase } from 'yargs';
|
|
2
|
-
import { CommonArgs } from '../../types/Yargs';
|
|
3
|
-
export declare const command = "generate-selectors <path>";
|
|
4
|
-
export declare const describe: string;
|
|
5
|
-
type ThemeSelectorArgs = CommonArgs & {
|
|
6
|
-
path: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function handler(args: ArgumentsCamelCase<ThemeSelectorArgs>): Promise<void>;
|
|
9
|
-
export declare function builder(yargs: Argv): Argv<ThemeSelectorArgs>;
|
|
10
1
|
export {};
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const generateSelectors_1 = require("../../lib/generateSelectors");
|
|
13
|
-
const exitCodes_1 = require("../../lib/enums/exitCodes");
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const { i18n } = require('../../lib/lang');
|
|
6
|
+
const { logger } = require('@hubspot/local-dev-lib/logger');
|
|
7
|
+
const { findFieldsJsonPath, combineThemeCss, setPreviewSelectors, generateInheritedSelectors, generateSelectorsMap, getMaxFieldsDepth, } = require('../../lib/generateSelectors');
|
|
8
|
+
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
14
9
|
const HUBL_EXPRESSION_REGEX = new RegExp(/{%\s*(.*)\s*%}/, 'g');
|
|
15
10
|
const HUBL_VARIABLE_NAME_REGEX = new RegExp(/{%\s*set\s*(\w*)/, 'i');
|
|
16
11
|
const HUBL_STATEMENT_REGEX = new RegExp(/{{\s*[\w.(,\d\-\s)|/~]*.*}}/, 'g');
|
|
@@ -22,30 +17,28 @@ const CSS_EXPRESSION_REGEX = new RegExp(/(?!\s)([^}])*(?![.#\s,>])[^}]*}/, 'g');
|
|
|
22
17
|
const THEME_PATH_REGEX = new RegExp(/=\s*.*(theme\.(\w|\.)*)/, 'i');
|
|
23
18
|
const i18nKey = 'commands.theme.subcommands.generateSelectors';
|
|
24
19
|
exports.command = 'generate-selectors <path>';
|
|
25
|
-
exports.describe =
|
|
26
|
-
|
|
27
|
-
const { path } =
|
|
28
|
-
const fieldsJsonPath =
|
|
20
|
+
exports.describe = i18n(`${i18nKey}.describe`);
|
|
21
|
+
exports.handler = options => {
|
|
22
|
+
const { path } = options;
|
|
23
|
+
const fieldsJsonPath = findFieldsJsonPath(path);
|
|
29
24
|
if (!fieldsJsonPath) {
|
|
30
|
-
|
|
31
|
-
process.exit(
|
|
25
|
+
logger.error(i18n(`${i18nKey}.errors.fieldsNotFound`));
|
|
26
|
+
process.exit(EXIT_CODES.ERROR);
|
|
32
27
|
}
|
|
33
|
-
let fieldsJson = JSON.parse(
|
|
34
|
-
let cssString =
|
|
28
|
+
let fieldsJson = JSON.parse(fs.readFileSync(fieldsJsonPath));
|
|
29
|
+
let cssString = combineThemeCss(path);
|
|
35
30
|
/**
|
|
36
31
|
* Creates map of HubL variable names to theme field paths
|
|
37
32
|
*/
|
|
38
|
-
const HubLExpressions = cssString.match(HUBL_EXPRESSION_REGEX);
|
|
39
|
-
const hublVariableMap = HubLExpressions
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!themeFieldKey || !variableName)
|
|
44
|
-
return _hublVariableMap;
|
|
45
|
-
_hublVariableMap[variableName[1]] = themeFieldKey[1];
|
|
33
|
+
const HubLExpressions = cssString.match(HUBL_EXPRESSION_REGEX) || [];
|
|
34
|
+
const hublVariableMap = HubLExpressions.reduce((_hublVariableMap, expression) => {
|
|
35
|
+
const variableName = expression.match(HUBL_VARIABLE_NAME_REGEX);
|
|
36
|
+
const themeFieldKey = expression.match(THEME_PATH_REGEX);
|
|
37
|
+
if (!themeFieldKey || !variableName)
|
|
46
38
|
return _hublVariableMap;
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
_hublVariableMap[variableName[1]] = themeFieldKey[1];
|
|
40
|
+
return _hublVariableMap;
|
|
41
|
+
}, {});
|
|
49
42
|
/**
|
|
50
43
|
* Removes HubL variable expressions
|
|
51
44
|
*/
|
|
@@ -89,37 +82,28 @@ async function handler(args) {
|
|
|
89
82
|
const finalMap = cssExpressions.reduce((themeFieldsSelectorMap, cssExpression) => {
|
|
90
83
|
const hublStatementsPlaceholderKey = cssExpression.match(HUBL_STATEMENT_PLACEHOLDER_REGEX) || [];
|
|
91
84
|
hublStatementsPlaceholderKey.forEach(placeholderKey => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (placeholderKey in hublStatementsMap) {
|
|
95
|
-
hublStatement =
|
|
96
|
-
hublStatementsMap[placeholderKey].match(HUBL_EXPRESSIONS);
|
|
97
|
-
themeFieldPath =
|
|
98
|
-
hublStatementsMap[placeholderKey].match(/theme\.[\w|.]*/);
|
|
99
|
-
}
|
|
85
|
+
const hublStatement = hublStatementsMap[placeholderKey].match(HUBL_EXPRESSIONS);
|
|
86
|
+
const themeFieldPath = hublStatementsMap[placeholderKey].match(/theme\.[\w|.]*/, 'g');
|
|
100
87
|
const cssSelectors = cssExpression.match(CSS_SELECTORS_REGEX);
|
|
101
88
|
/**
|
|
102
89
|
* Try to match a HubL statement to any HubL Variables being used
|
|
103
90
|
*/
|
|
104
91
|
if (cssSelectors && themeFieldPath) {
|
|
105
92
|
const cssSelector = cssSelectors[1].replace(/\n/g, ' ');
|
|
106
|
-
const hublThemePath = themeFieldPath
|
|
93
|
+
const hublThemePath = themeFieldPath[0];
|
|
107
94
|
if (!themeFieldsSelectorMap[hublThemePath]) {
|
|
108
95
|
themeFieldsSelectorMap[hublThemePath] = [];
|
|
109
96
|
}
|
|
110
97
|
if (!themeFieldsSelectorMap[hublThemePath].includes(cssSelector)) {
|
|
111
|
-
themeFieldsSelectorMap[hublThemePath] =
|
|
112
|
-
themeFieldsSelectorMap[hublThemePath].concat(cssSelector);
|
|
98
|
+
themeFieldsSelectorMap[hublThemePath] = themeFieldsSelectorMap[hublThemePath].concat(cssSelector);
|
|
113
99
|
}
|
|
114
100
|
}
|
|
115
101
|
if (cssSelectors && hublStatement) {
|
|
116
|
-
const cssSelector = cssSelectors
|
|
102
|
+
const cssSelector = cssSelectors[1].replace(/\n/g, ' ');
|
|
117
103
|
const hublVariableName = Object.keys(hublVariableMap).find(_hubl => {
|
|
118
|
-
return hublStatement
|
|
119
|
-
})
|
|
120
|
-
const themeFieldKey = hublVariableName
|
|
121
|
-
? hublVariableMap[hublVariableName]
|
|
122
|
-
: undefined;
|
|
104
|
+
return hublStatement[0].includes(_hubl);
|
|
105
|
+
});
|
|
106
|
+
const themeFieldKey = hublVariableMap[hublVariableName];
|
|
123
107
|
/**
|
|
124
108
|
* If the theme path is referenced directly add selectors
|
|
125
109
|
*/
|
|
@@ -128,8 +112,7 @@ async function handler(args) {
|
|
|
128
112
|
themeFieldsSelectorMap[themeFieldKey] = [];
|
|
129
113
|
}
|
|
130
114
|
if (!themeFieldsSelectorMap[themeFieldKey].includes(cssSelector)) {
|
|
131
|
-
themeFieldsSelectorMap[themeFieldKey] =
|
|
132
|
-
themeFieldsSelectorMap[themeFieldKey].concat(cssSelector);
|
|
115
|
+
themeFieldsSelectorMap[themeFieldKey] = themeFieldsSelectorMap[themeFieldKey].concat(cssSelector);
|
|
133
116
|
}
|
|
134
117
|
}
|
|
135
118
|
}
|
|
@@ -137,33 +120,32 @@ async function handler(args) {
|
|
|
137
120
|
return themeFieldsSelectorMap;
|
|
138
121
|
}, {});
|
|
139
122
|
if (!Object.keys(finalMap).length) {
|
|
140
|
-
|
|
141
|
-
process.exit(
|
|
123
|
+
logger.error(i18n(`${i18nKey}.errors.noSelectorsFound`));
|
|
124
|
+
process.exit(EXIT_CODES.ERROR);
|
|
142
125
|
}
|
|
143
126
|
Object.keys(finalMap).forEach(themeFieldKey => {
|
|
144
127
|
const fieldKey = themeFieldKey.split('.');
|
|
145
128
|
const selectors = finalMap[themeFieldKey];
|
|
146
|
-
fieldsJson =
|
|
129
|
+
fieldsJson = setPreviewSelectors(fieldsJson, fieldKey.splice(1), selectors);
|
|
147
130
|
});
|
|
148
131
|
// Because fields can have nested inheritance we generated inherited selectors
|
|
149
132
|
// multiple times to make sure all inherted selectors are bubbled up.
|
|
150
|
-
const maxFieldsDepth =
|
|
133
|
+
const maxFieldsDepth = getMaxFieldsDepth();
|
|
151
134
|
for (let i = 0; i < maxFieldsDepth; i += 1) {
|
|
152
|
-
fieldsJson = (
|
|
135
|
+
fieldsJson = generateInheritedSelectors(fieldsJson, fieldsJson);
|
|
153
136
|
}
|
|
154
|
-
const selectorsMap =
|
|
137
|
+
const selectorsMap = generateSelectorsMap(fieldsJson);
|
|
155
138
|
const selectorsPath = `${path}/editor-preview.json`;
|
|
156
|
-
|
|
157
|
-
|
|
139
|
+
fs.writeFileSync(selectorsPath, `${JSON.stringify({ selectors: selectorsMap }, null, 2)}\n`);
|
|
140
|
+
logger.success(i18n(`${i18nKey}.success`, {
|
|
158
141
|
themePath: path,
|
|
159
142
|
selectorsPath,
|
|
160
143
|
}));
|
|
161
|
-
}
|
|
162
|
-
|
|
144
|
+
};
|
|
145
|
+
exports.builder = yargs => {
|
|
163
146
|
yargs.positional('path', {
|
|
164
|
-
describe:
|
|
147
|
+
describe: i18n(`${i18nKey}.positionals.path.describe`),
|
|
165
148
|
type: 'string',
|
|
166
|
-
required: true,
|
|
167
149
|
});
|
|
168
150
|
return yargs;
|
|
169
|
-
}
|
|
151
|
+
};
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import { Argv, ArgumentsCamelCase } from 'yargs';
|
|
2
|
-
import { CommonArgs, ConfigArgs, AccountArgs, EnvironmentArgs } from '../../types/Yargs';
|
|
3
|
-
export declare const command = "marketplace-validate <path>";
|
|
4
|
-
export declare const describe: string;
|
|
5
|
-
type CombinedArgs = CommonArgs & ConfigArgs & AccountArgs & EnvironmentArgs;
|
|
6
|
-
type ThemeValidateArgs = CombinedArgs & {
|
|
7
|
-
path: string;
|
|
8
|
-
};
|
|
9
|
-
export declare function handler(args: ArgumentsCamelCase<ThemeValidateArgs>): Promise<void>;
|
|
10
|
-
export declare function builder(yargs: Argv): Argv<ThemeValidateArgs>;
|
|
11
1
|
export {};
|