@hubspot/cli 7.1.1 → 7.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/create/api-sample.js +14 -4
- package/commands/customObject/create.d.ts +11 -0
- package/commands/customObject/create.js +37 -28
- package/commands/customObject/schema/create.d.ts +10 -0
- package/commands/customObject/schema/create.js +40 -42
- package/commands/customObject/schema/delete.d.ts +11 -0
- package/commands/customObject/schema/delete.js +34 -27
- package/commands/customObject/schema/fetch-all.d.ts +10 -0
- package/commands/customObject/schema/fetch-all.js +31 -24
- package/commands/customObject/schema/fetch.d.ts +11 -0
- package/commands/customObject/schema/fetch.js +34 -42
- package/commands/customObject/schema/list.d.ts +7 -0
- package/commands/customObject/schema/list.js +23 -14
- package/commands/customObject/schema/update.d.ts +11 -0
- package/commands/customObject/schema/update.js +44 -46
- package/commands/customObject/schema.d.ts +5 -1
- package/commands/customObject/schema.js +49 -11
- package/commands/customObject.d.ts +4 -1
- package/commands/customObject.js +54 -21
- package/commands/filemanager/fetch.d.ts +12 -0
- package/commands/filemanager/fetch.js +33 -30
- package/commands/filemanager/upload.d.ts +11 -0
- package/commands/filemanager/upload.js +53 -47
- package/commands/filemanager.d.ts +4 -1
- package/commands/filemanager.js +41 -7
- package/commands/hubdb/clear.d.ts +11 -0
- package/commands/hubdb/clear.js +33 -30
- package/commands/hubdb/create.d.ts +10 -0
- package/commands/hubdb/create.js +46 -40
- package/commands/hubdb/delete.d.ts +10 -0
- package/commands/hubdb/delete.js +38 -35
- package/commands/hubdb/fetch.d.ts +11 -0
- package/commands/hubdb/fetch.js +30 -27
- package/commands/hubdb.d.ts +4 -1
- package/commands/hubdb.js +45 -11
- package/commands/project/add.js +62 -16
- package/commands/project/cloneApp.js +3 -3
- package/commands/project/create.js +70 -15
- package/commands/project/dev/deprecatedFlow.d.ts +5 -0
- package/commands/project/dev/deprecatedFlow.js +137 -0
- package/commands/project/dev/index.d.ts +6 -0
- package/commands/project/dev/index.js +52 -0
- package/commands/project/dev/unifiedFlow.d.ts +5 -0
- package/commands/project/dev/unifiedFlow.js +112 -0
- package/commands/project/migrateApp.js +3 -3
- package/commands/project/upload.js +7 -2
- package/commands/sandbox/create.d.ts +12 -0
- package/commands/sandbox/create.js +90 -72
- package/commands/sandbox/delete.d.ts +11 -0
- package/commands/sandbox/delete.js +112 -95
- package/commands/sandbox.d.ts +4 -1
- package/commands/sandbox.js +44 -10
- package/commands/secret/addSecret.d.ts +10 -0
- package/commands/secret/addSecret.js +32 -31
- package/commands/secret/deleteSecret.d.ts +11 -0
- package/commands/secret/deleteSecret.js +31 -29
- package/commands/secret/listSecret.d.ts +9 -0
- package/commands/secret/listSecret.js +41 -0
- package/commands/secret/updateSecret.d.ts +10 -0
- package/commands/secret/updateSecret.js +33 -31
- package/commands/secret.d.ts +4 -1
- package/commands/secret.js +46 -12
- package/commands/theme/generate-selectors.d.ts +9 -0
- package/commands/theme/generate-selectors.js +61 -43
- package/commands/theme/marketplace-validate.d.ts +10 -0
- package/commands/theme/marketplace-validate.js +32 -26
- package/commands/theme/preview.d.ts +16 -0
- package/commands/theme/preview.js +104 -97
- package/commands/theme.d.ts +4 -1
- package/commands/theme.js +44 -10
- package/lang/en.lyaml +36 -16
- package/lib/DevServerManagerV2.d.ts +34 -0
- package/lib/DevServerManagerV2.js +85 -0
- package/lib/LocalDevManager.d.ts +2 -2
- package/lib/LocalDevManagerV2.d.ts +64 -0
- package/lib/LocalDevManagerV2.js +382 -0
- package/lib/buildAccount.d.ts +2 -3
- package/lib/constants.d.ts +12 -3
- package/lib/constants.js +13 -4
- package/lib/customObject.d.ts +3 -0
- package/lib/customObject.js +15 -0
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +6 -0
- package/lib/doctor/DiagnosticInfoBuilder.js +5 -0
- package/lib/doctor/Doctor.d.ts +1 -0
- package/lib/doctor/Doctor.js +10 -0
- package/lib/localDev.d.ts +3 -2
- package/lib/localDev.js +2 -2
- package/lib/marketplaceValidate.d.ts +2 -2
- package/lib/process.d.ts +1 -0
- package/lib/process.js +11 -10
- package/lib/projects/buildAndDeploy.js +4 -1
- package/lib/projects/create.d.ts +5 -0
- package/lib/projects/create.js +51 -0
- package/lib/projects/index.d.ts +1 -5
- package/lib/projects/index.js +1 -62
- package/lib/projects/structure.d.ts +4 -0
- package/lib/projects/structure.js +9 -0
- package/lib/projects/upload.d.ts +1 -1
- package/lib/projects/upload.js +2 -2
- package/lib/prompts/createProjectPrompt.d.ts +6 -8
- package/lib/prompts/createProjectPrompt.js +26 -54
- package/lib/prompts/projectAddPrompt.d.ts +3 -3
- package/lib/prompts/projectAddPrompt.js +16 -6
- package/lib/prompts/projectDevTargetAccountPrompt.d.ts +3 -2
- package/lib/prompts/sandboxesPrompt.d.ts +3 -2
- package/lib/prompts/sandboxesPrompt.js +1 -1
- package/lib/sandboxSync.js +6 -2
- package/lib/sandboxes.d.ts +2 -5
- package/lib/testUtils.d.ts +12 -0
- package/lib/testUtils.js +10 -0
- package/lib/ui/index.d.ts +2 -2
- package/lib/ui/index.js +1 -0
- package/lib/upload.d.ts +1 -1
- package/lib/upload.js +20 -20
- package/lib/validation.d.ts +1 -1
- package/package.json +6 -5
- package/types/ProjectComponents.d.ts +38 -0
- package/types/ProjectComponents.js +3 -0
- package/types/Projects.d.ts +1 -6
- package/types/Prompts.d.ts +7 -0
- package/types/Sandboxes.d.ts +2 -0
- package/types/Yargs.d.ts +15 -0
- package/commands/project/dev.d.ts +0 -1
- package/commands/project/dev.js +0 -146
- package/commands/secret/listSecrets.d.ts +0 -1
- package/commands/secret/listSecrets.js +0 -39
|
@@ -1,11 +1,16 @@
|
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
exports.describe = exports.command = void 0;
|
|
7
|
+
exports.handler = handler;
|
|
8
|
+
exports.builder = builder;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
11
|
+
const lang_1 = require("../../lib/lang");
|
|
12
|
+
const generateSelectors_1 = require("../../lib/generateSelectors");
|
|
13
|
+
const exitCodes_1 = require("../../lib/enums/exitCodes");
|
|
9
14
|
const HUBL_EXPRESSION_REGEX = new RegExp(/{%\s*(.*)\s*%}/, 'g');
|
|
10
15
|
const HUBL_VARIABLE_NAME_REGEX = new RegExp(/{%\s*set\s*(\w*)/, 'i');
|
|
11
16
|
const HUBL_STATEMENT_REGEX = new RegExp(/{{\s*[\w.(,\d\-\s)|/~]*.*}}/, 'g');
|
|
@@ -17,28 +22,30 @@ const CSS_EXPRESSION_REGEX = new RegExp(/(?!\s)([^}])*(?![.#\s,>])[^}]*}/, 'g');
|
|
|
17
22
|
const THEME_PATH_REGEX = new RegExp(/=\s*.*(theme\.(\w|\.)*)/, 'i');
|
|
18
23
|
const i18nKey = 'commands.theme.subcommands.generateSelectors';
|
|
19
24
|
exports.command = 'generate-selectors <path>';
|
|
20
|
-
exports.describe = i18n(`${i18nKey}.describe`);
|
|
21
|
-
|
|
22
|
-
const { path } =
|
|
23
|
-
const fieldsJsonPath = findFieldsJsonPath(path);
|
|
25
|
+
exports.describe = (0, lang_1.i18n)(`${i18nKey}.describe`);
|
|
26
|
+
async function handler(args) {
|
|
27
|
+
const { path } = args;
|
|
28
|
+
const fieldsJsonPath = (0, generateSelectors_1.findFieldsJsonPath)(path);
|
|
24
29
|
if (!fieldsJsonPath) {
|
|
25
|
-
logger.error(i18n(`${i18nKey}.errors.fieldsNotFound`));
|
|
26
|
-
process.exit(EXIT_CODES.ERROR);
|
|
30
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.fieldsNotFound`));
|
|
31
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
27
32
|
}
|
|
28
|
-
let fieldsJson = JSON.parse(
|
|
29
|
-
let cssString = combineThemeCss(path);
|
|
33
|
+
let fieldsJson = JSON.parse(fs_1.default.readFileSync(fieldsJsonPath, 'utf-8'));
|
|
34
|
+
let cssString = (0, generateSelectors_1.combineThemeCss)(path) ?? '';
|
|
30
35
|
/**
|
|
31
36
|
* Creates map of HubL variable names to theme field paths
|
|
32
37
|
*/
|
|
33
|
-
const HubLExpressions = cssString.match(HUBL_EXPRESSION_REGEX)
|
|
34
|
-
const hublVariableMap = HubLExpressions
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const HubLExpressions = cssString.match(HUBL_EXPRESSION_REGEX);
|
|
39
|
+
const hublVariableMap = HubLExpressions
|
|
40
|
+
? HubLExpressions.reduce((_hublVariableMap, expression) => {
|
|
41
|
+
const variableName = expression.match(HUBL_VARIABLE_NAME_REGEX);
|
|
42
|
+
const themeFieldKey = expression.match(THEME_PATH_REGEX);
|
|
43
|
+
if (!themeFieldKey || !variableName)
|
|
44
|
+
return _hublVariableMap;
|
|
45
|
+
_hublVariableMap[variableName[1]] = themeFieldKey[1];
|
|
38
46
|
return _hublVariableMap;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}, {});
|
|
47
|
+
}, {})
|
|
48
|
+
: {};
|
|
42
49
|
/**
|
|
43
50
|
* Removes HubL variable expressions
|
|
44
51
|
*/
|
|
@@ -82,28 +89,37 @@ exports.handler = options => {
|
|
|
82
89
|
const finalMap = cssExpressions.reduce((themeFieldsSelectorMap, cssExpression) => {
|
|
83
90
|
const hublStatementsPlaceholderKey = cssExpression.match(HUBL_STATEMENT_PLACEHOLDER_REGEX) || [];
|
|
84
91
|
hublStatementsPlaceholderKey.forEach(placeholderKey => {
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
let hublStatement;
|
|
93
|
+
let themeFieldPath;
|
|
94
|
+
if (placeholderKey in hublStatementsMap) {
|
|
95
|
+
hublStatement =
|
|
96
|
+
hublStatementsMap[placeholderKey].match(HUBL_EXPRESSIONS);
|
|
97
|
+
themeFieldPath =
|
|
98
|
+
hublStatementsMap[placeholderKey].match(/theme\.[\w|.]*/);
|
|
99
|
+
}
|
|
87
100
|
const cssSelectors = cssExpression.match(CSS_SELECTORS_REGEX);
|
|
88
101
|
/**
|
|
89
102
|
* Try to match a HubL statement to any HubL Variables being used
|
|
90
103
|
*/
|
|
91
104
|
if (cssSelectors && themeFieldPath) {
|
|
92
105
|
const cssSelector = cssSelectors[1].replace(/\n/g, ' ');
|
|
93
|
-
const hublThemePath = themeFieldPath[0];
|
|
106
|
+
const hublThemePath = themeFieldPath?.[0] ?? '';
|
|
94
107
|
if (!themeFieldsSelectorMap[hublThemePath]) {
|
|
95
108
|
themeFieldsSelectorMap[hublThemePath] = [];
|
|
96
109
|
}
|
|
97
110
|
if (!themeFieldsSelectorMap[hublThemePath].includes(cssSelector)) {
|
|
98
|
-
themeFieldsSelectorMap[hublThemePath] =
|
|
111
|
+
themeFieldsSelectorMap[hublThemePath] =
|
|
112
|
+
themeFieldsSelectorMap[hublThemePath].concat(cssSelector);
|
|
99
113
|
}
|
|
100
114
|
}
|
|
101
115
|
if (cssSelectors && hublStatement) {
|
|
102
|
-
const cssSelector = cssSelectors[1]
|
|
116
|
+
const cssSelector = cssSelectors?.[1]?.replace(/\n/g, ' ') ?? '';
|
|
103
117
|
const hublVariableName = Object.keys(hublVariableMap).find(_hubl => {
|
|
104
|
-
return hublStatement[0].includes(_hubl);
|
|
105
|
-
});
|
|
106
|
-
const themeFieldKey =
|
|
118
|
+
return hublStatement && hublStatement[0].includes(_hubl);
|
|
119
|
+
}) || '';
|
|
120
|
+
const themeFieldKey = hublVariableName
|
|
121
|
+
? hublVariableMap[hublVariableName]
|
|
122
|
+
: undefined;
|
|
107
123
|
/**
|
|
108
124
|
* If the theme path is referenced directly add selectors
|
|
109
125
|
*/
|
|
@@ -112,7 +128,8 @@ exports.handler = options => {
|
|
|
112
128
|
themeFieldsSelectorMap[themeFieldKey] = [];
|
|
113
129
|
}
|
|
114
130
|
if (!themeFieldsSelectorMap[themeFieldKey].includes(cssSelector)) {
|
|
115
|
-
themeFieldsSelectorMap[themeFieldKey] =
|
|
131
|
+
themeFieldsSelectorMap[themeFieldKey] =
|
|
132
|
+
themeFieldsSelectorMap[themeFieldKey].concat(cssSelector);
|
|
116
133
|
}
|
|
117
134
|
}
|
|
118
135
|
}
|
|
@@ -120,32 +137,33 @@ exports.handler = options => {
|
|
|
120
137
|
return themeFieldsSelectorMap;
|
|
121
138
|
}, {});
|
|
122
139
|
if (!Object.keys(finalMap).length) {
|
|
123
|
-
logger.error(i18n(`${i18nKey}.errors.noSelectorsFound`));
|
|
124
|
-
process.exit(EXIT_CODES.ERROR);
|
|
140
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.noSelectorsFound`));
|
|
141
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
125
142
|
}
|
|
126
143
|
Object.keys(finalMap).forEach(themeFieldKey => {
|
|
127
144
|
const fieldKey = themeFieldKey.split('.');
|
|
128
145
|
const selectors = finalMap[themeFieldKey];
|
|
129
|
-
fieldsJson = setPreviewSelectors(fieldsJson, fieldKey.splice(1), selectors);
|
|
146
|
+
fieldsJson = (0, generateSelectors_1.setPreviewSelectors)(fieldsJson, fieldKey.splice(1), selectors);
|
|
130
147
|
});
|
|
131
148
|
// Because fields can have nested inheritance we generated inherited selectors
|
|
132
149
|
// multiple times to make sure all inherted selectors are bubbled up.
|
|
133
|
-
const maxFieldsDepth = getMaxFieldsDepth();
|
|
150
|
+
const maxFieldsDepth = (0, generateSelectors_1.getMaxFieldsDepth)();
|
|
134
151
|
for (let i = 0; i < maxFieldsDepth; i += 1) {
|
|
135
|
-
fieldsJson =
|
|
152
|
+
fieldsJson = (0, generateSelectors_1.generateInheritedSelectors)(fieldsJson);
|
|
136
153
|
}
|
|
137
|
-
const selectorsMap = generateSelectorsMap(fieldsJson);
|
|
154
|
+
const selectorsMap = (0, generateSelectors_1.generateSelectorsMap)(fieldsJson);
|
|
138
155
|
const selectorsPath = `${path}/editor-preview.json`;
|
|
139
|
-
|
|
140
|
-
logger.success(i18n(`${i18nKey}.success`, {
|
|
156
|
+
fs_1.default.writeFileSync(selectorsPath, `${JSON.stringify({ selectors: selectorsMap }, null, 2)}\n`);
|
|
157
|
+
logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.success`, {
|
|
141
158
|
themePath: path,
|
|
142
159
|
selectorsPath,
|
|
143
160
|
}));
|
|
144
|
-
}
|
|
145
|
-
|
|
161
|
+
}
|
|
162
|
+
function builder(yargs) {
|
|
146
163
|
yargs.positional('path', {
|
|
147
|
-
describe: i18n(`${i18nKey}.positionals.path.describe`),
|
|
164
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.positionals.path.describe`),
|
|
148
165
|
type: 'string',
|
|
166
|
+
required: true,
|
|
149
167
|
});
|
|
150
168
|
return yargs;
|
|
151
|
-
}
|
|
169
|
+
}
|
|
@@ -1 +1,11 @@
|
|
|
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>;
|
|
1
11
|
export {};
|
|
@@ -1,39 +1,45 @@
|
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
6
|
+
exports.describe = exports.command = void 0;
|
|
7
|
+
exports.handler = handler;
|
|
8
|
+
exports.builder = builder;
|
|
9
|
+
const SpinniesManager_1 = __importDefault(require("../../lib/ui/SpinniesManager"));
|
|
10
|
+
const commonOpts_1 = require("../../lib/commonOpts");
|
|
11
|
+
const usageTracking_1 = require("../../lib/usageTracking");
|
|
12
|
+
const marketplaceValidate_1 = require("../../lib/marketplaceValidate");
|
|
13
|
+
const lang_1 = require("../../lib/lang");
|
|
9
14
|
const i18nKey = 'commands.theme.subcommands.marketplaceValidate';
|
|
10
15
|
exports.command = 'marketplace-validate <path>';
|
|
11
|
-
exports.describe = i18n(`${i18nKey}.describe`);
|
|
12
|
-
|
|
13
|
-
const { path, derivedAccountId } =
|
|
14
|
-
trackCommandUsage('validate',
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
text: i18n(`${i18nKey}.logs.validatingTheme`, {
|
|
16
|
+
exports.describe = (0, lang_1.i18n)(`${i18nKey}.describe`);
|
|
17
|
+
async function handler(args) {
|
|
18
|
+
const { path, derivedAccountId } = args;
|
|
19
|
+
(0, usageTracking_1.trackCommandUsage)('validate', {}, derivedAccountId);
|
|
20
|
+
SpinniesManager_1.default.init();
|
|
21
|
+
SpinniesManager_1.default.add('marketplaceValidation', {
|
|
22
|
+
text: (0, lang_1.i18n)(`${i18nKey}.logs.validatingTheme`, {
|
|
18
23
|
path,
|
|
19
24
|
}),
|
|
20
25
|
});
|
|
21
26
|
const assetType = 'THEME';
|
|
22
|
-
const validationId = await kickOffValidation(derivedAccountId, assetType, path);
|
|
23
|
-
await pollForValidationFinish(derivedAccountId, validationId);
|
|
24
|
-
|
|
25
|
-
const validationResults = await fetchValidationResults(derivedAccountId, validationId);
|
|
26
|
-
processValidationErrors(i18nKey, validationResults);
|
|
27
|
-
displayValidationResults(i18nKey, validationResults);
|
|
27
|
+
const validationId = await (0, marketplaceValidate_1.kickOffValidation)(derivedAccountId, assetType, path);
|
|
28
|
+
await (0, marketplaceValidate_1.pollForValidationFinish)(derivedAccountId, validationId);
|
|
29
|
+
SpinniesManager_1.default.remove('marketplaceValidation');
|
|
30
|
+
const validationResults = await (0, marketplaceValidate_1.fetchValidationResults)(derivedAccountId, validationId);
|
|
31
|
+
(0, marketplaceValidate_1.processValidationErrors)(i18nKey, validationResults);
|
|
32
|
+
(0, marketplaceValidate_1.displayValidationResults)(i18nKey, validationResults);
|
|
28
33
|
process.exit();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
addConfigOptions(yargs);
|
|
32
|
-
addAccountOptions(yargs);
|
|
33
|
-
addUseEnvironmentOptions(yargs);
|
|
34
|
+
}
|
|
35
|
+
function builder(yargs) {
|
|
36
|
+
(0, commonOpts_1.addConfigOptions)(yargs);
|
|
37
|
+
(0, commonOpts_1.addAccountOptions)(yargs);
|
|
38
|
+
(0, commonOpts_1.addUseEnvironmentOptions)(yargs);
|
|
34
39
|
yargs.positional('path', {
|
|
35
|
-
describe: i18n(`${i18nKey}.positionals.path.describe`),
|
|
40
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.positionals.path.describe`),
|
|
36
41
|
type: 'string',
|
|
42
|
+
required: true,
|
|
37
43
|
});
|
|
38
44
|
return yargs;
|
|
39
|
-
}
|
|
45
|
+
}
|
|
@@ -1 +1,17 @@
|
|
|
1
|
+
import { Argv, ArgumentsCamelCase } from 'yargs';
|
|
2
|
+
import { CommonArgs, ConfigArgs, AccountArgs } from '../../types/Yargs';
|
|
3
|
+
export declare const command = "preview [--src] [--dest]";
|
|
4
|
+
export declare const describe: string;
|
|
5
|
+
type CombinedArgs = CommonArgs & ConfigArgs & AccountArgs;
|
|
6
|
+
type ThemePreviewArgs = CombinedArgs & {
|
|
7
|
+
src: string;
|
|
8
|
+
dest: string;
|
|
9
|
+
notify: string;
|
|
10
|
+
'no-ssl'?: boolean;
|
|
11
|
+
port?: number;
|
|
12
|
+
resetSession?: boolean;
|
|
13
|
+
generateFieldsTypes?: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare function handler(args: ArgumentsCamelCase<ThemePreviewArgs>): Promise<void>;
|
|
16
|
+
export declare function builder(yargs: Argv): Argv<ThemePreviewArgs>;
|
|
1
17
|
export {};
|
|
@@ -1,37 +1,42 @@
|
|
|
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
|
-
|
|
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
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
6
|
+
exports.describe = exports.command = void 0;
|
|
7
|
+
exports.handler = handler;
|
|
8
|
+
exports.builder = builder;
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const cli_progress_1 = __importDefault(require("cli-progress"));
|
|
12
|
+
const lang_1 = require("../../lib/lang");
|
|
13
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
14
|
+
const path_2 = require("@hubspot/local-dev-lib/path");
|
|
15
|
+
const files_1 = require("@hubspot/local-dev-lib/constants/files");
|
|
16
|
+
const themes_1 = require("@hubspot/local-dev-lib/cms/themes");
|
|
17
|
+
const theme_preview_dev_server_1 = require("@hubspot/theme-preview-dev-server");
|
|
18
|
+
const commonOpts_1 = require("../../lib/commonOpts");
|
|
19
|
+
const upload_1 = require("../../lib/upload");
|
|
20
|
+
const usageTracking_1 = require("../../lib/usageTracking");
|
|
21
|
+
const previewPrompt_1 = require("../../lib/prompts/previewPrompt");
|
|
22
|
+
const exitCodes_1 = require("../../lib/enums/exitCodes");
|
|
23
|
+
const index_1 = require("../../lib/errorHandlers/index");
|
|
24
|
+
const process_1 = require("../../lib/process");
|
|
25
|
+
const projects_1 = require("../../lib/projects");
|
|
26
|
+
const structure_1 = require("../../lib/projects/structure");
|
|
27
|
+
const Projects_1 = require("../../types/Projects");
|
|
28
|
+
const hasFeature_1 = require("../../lib/hasFeature");
|
|
24
29
|
const i18nKey = 'commands.theme.subcommands.preview';
|
|
25
30
|
exports.command = 'preview [--src] [--dest]';
|
|
26
|
-
exports.describe = i18n(`${i18nKey}.describe`);
|
|
27
|
-
|
|
31
|
+
exports.describe = (0, lang_1.i18n)(`${i18nKey}.describe`);
|
|
32
|
+
function validateSrcPath(src) {
|
|
28
33
|
const logInvalidPath = () => {
|
|
29
|
-
logger.error(i18n(`${i18nKey}.errors.invalidPath`, {
|
|
34
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.invalidPath`, {
|
|
30
35
|
path: src,
|
|
31
36
|
}));
|
|
32
37
|
};
|
|
33
38
|
try {
|
|
34
|
-
const stats =
|
|
39
|
+
const stats = fs_1.default.statSync(src);
|
|
35
40
|
if (!stats.isDirectory()) {
|
|
36
41
|
logInvalidPath();
|
|
37
42
|
return false;
|
|
@@ -42,65 +47,65 @@ const validateSrcPath = src => {
|
|
|
42
47
|
return false;
|
|
43
48
|
}
|
|
44
49
|
return true;
|
|
45
|
-
}
|
|
46
|
-
|
|
50
|
+
}
|
|
51
|
+
function handleUserInput() {
|
|
47
52
|
const onTerminate = () => {
|
|
48
|
-
logger.log(i18n(`${i18nKey}.logs.processExited`));
|
|
49
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
53
|
+
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.logs.processExited`));
|
|
54
|
+
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
50
55
|
};
|
|
51
|
-
handleExit(onTerminate);
|
|
52
|
-
handleKeypress(key => {
|
|
56
|
+
(0, process_1.handleExit)(onTerminate);
|
|
57
|
+
(0, process_1.handleKeypress)(key => {
|
|
53
58
|
if ((key.ctrl && key.name === 'c') || key.name === 'q') {
|
|
54
59
|
onTerminate();
|
|
55
60
|
}
|
|
56
61
|
});
|
|
57
|
-
}
|
|
58
|
-
|
|
62
|
+
}
|
|
63
|
+
async function determineSrcAndDest(args) {
|
|
59
64
|
let absoluteSrc;
|
|
60
65
|
let dest;
|
|
61
|
-
const { projectDir, projectConfig } = await getProjectConfig();
|
|
66
|
+
const { projectDir, projectConfig } = await (0, projects_1.getProjectConfig)();
|
|
62
67
|
if (!(projectDir && projectConfig)) {
|
|
63
68
|
// Not in a project, prompt for src and dest of traditional theme
|
|
64
|
-
const previewPromptAnswers = await previewPrompt(
|
|
65
|
-
const src =
|
|
66
|
-
dest =
|
|
67
|
-
absoluteSrc =
|
|
69
|
+
const previewPromptAnswers = await (0, previewPrompt_1.previewPrompt)(args);
|
|
70
|
+
const src = args.src || previewPromptAnswers.src;
|
|
71
|
+
dest = args.dest || previewPromptAnswers.dest;
|
|
72
|
+
absoluteSrc = path_1.default.resolve((0, path_2.getCwd)(), src);
|
|
68
73
|
if (!dest || !validateSrcPath(absoluteSrc)) {
|
|
69
|
-
process.exit(EXIT_CODES.ERROR);
|
|
74
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
else {
|
|
73
78
|
// In a project
|
|
74
|
-
let themeJsonPath = getThemeJSONPath();
|
|
79
|
+
let themeJsonPath = (0, themes_1.getThemeJSONPath)((0, path_2.getCwd)());
|
|
75
80
|
if (!themeJsonPath) {
|
|
76
|
-
const projectComponents = await findProjectComponents(projectDir);
|
|
77
|
-
const themeComponents = projectComponents.filter(c => c.type === ComponentTypes.HublTheme);
|
|
81
|
+
const projectComponents = await (0, structure_1.findProjectComponents)(projectDir);
|
|
82
|
+
const themeComponents = projectComponents.filter(c => c.type === Projects_1.ComponentTypes.HublTheme);
|
|
78
83
|
if (themeComponents.length === 0) {
|
|
79
|
-
logger.error(i18n(`${i18nKey}.errors.noThemeComponents`));
|
|
80
|
-
process.exit(EXIT_CODES.ERROR);
|
|
84
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.noThemeComponents`));
|
|
85
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
81
86
|
}
|
|
82
|
-
const answer = await previewProjectPrompt(themeComponents);
|
|
87
|
+
const answer = await (0, previewPrompt_1.previewProjectPrompt)(themeComponents);
|
|
83
88
|
themeJsonPath = `${answer.themeComponentPath}/theme.json`;
|
|
84
89
|
}
|
|
85
|
-
const { dir: themeDir } =
|
|
90
|
+
const { dir: themeDir } = path_1.default.parse(themeJsonPath);
|
|
86
91
|
absoluteSrc = themeDir;
|
|
87
|
-
const { base: themeName } =
|
|
92
|
+
const { base: themeName } = path_1.default.parse(themeDir);
|
|
88
93
|
dest = `@projects/${projectConfig.name}/${themeName}`;
|
|
89
94
|
}
|
|
90
95
|
return { absoluteSrc, dest };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { derivedAccountId, notify, noSsl, resetSession, port, generateFieldsTypes, } =
|
|
94
|
-
const { absoluteSrc, dest } = await determineSrcAndDest(
|
|
95
|
-
const filePaths = await getUploadableFileList(absoluteSrc, false);
|
|
96
|
-
|
|
97
|
-
const initialUploadProgressBar = new
|
|
96
|
+
}
|
|
97
|
+
async function handler(args) {
|
|
98
|
+
const { derivedAccountId, notify, noSsl, resetSession, port, generateFieldsTypes, } = args;
|
|
99
|
+
const { absoluteSrc, dest } = await determineSrcAndDest(args);
|
|
100
|
+
const filePaths = await (0, upload_1.getUploadableFileList)(absoluteSrc, false);
|
|
101
|
+
function startProgressBar(numFiles) {
|
|
102
|
+
const initialUploadProgressBar = new cli_progress_1.default.SingleBar({
|
|
98
103
|
gracefulExit: true,
|
|
99
104
|
format: '[{bar}] {percentage}% | {value}/{total} | {label}',
|
|
100
105
|
hideCursor: true,
|
|
101
|
-
},
|
|
106
|
+
}, cli_progress_1.default.Presets.rect);
|
|
102
107
|
initialUploadProgressBar.start(numFiles, 0, {
|
|
103
|
-
label: i18n(`${i18nKey}.initialUploadProgressBar.start`),
|
|
108
|
+
label: (0, lang_1.i18n)(`${i18nKey}.initialUploadProgressBar.start`),
|
|
104
109
|
});
|
|
105
110
|
let uploadsHaveStarted = false;
|
|
106
111
|
const uploadOptions = {
|
|
@@ -112,7 +117,7 @@ exports.handler = async (options) => {
|
|
|
112
117
|
if (!uploadsHaveStarted) {
|
|
113
118
|
uploadsHaveStarted = true;
|
|
114
119
|
initialUploadProgressBar.update(0, {
|
|
115
|
-
label: i18n(`${i18nKey}.initialUploadProgressBar.uploading`),
|
|
120
|
+
label: (0, lang_1.i18n)(`${i18nKey}.initialUploadProgressBar.uploading`),
|
|
116
121
|
});
|
|
117
122
|
}
|
|
118
123
|
},
|
|
@@ -123,15 +128,15 @@ exports.handler = async (options) => {
|
|
|
123
128
|
/* Intentionally blank */
|
|
124
129
|
},
|
|
125
130
|
onFinalErrorCallback: () => initialUploadProgressBar.increment(),
|
|
126
|
-
onFinishCallback: results => {
|
|
131
|
+
onFinishCallback: (results) => {
|
|
127
132
|
initialUploadProgressBar.update(numFiles, {
|
|
128
|
-
label: i18n(`${i18nKey}.initialUploadProgressBar.finish`),
|
|
133
|
+
label: (0, lang_1.i18n)(`${i18nKey}.initialUploadProgressBar.finish`),
|
|
129
134
|
});
|
|
130
135
|
initialUploadProgressBar.stop();
|
|
131
136
|
results.forEach(result => {
|
|
132
|
-
if (result.resultType == FILE_UPLOAD_RESULT_TYPES.FAILURE) {
|
|
133
|
-
logger.error('Uploading file "%s" to "%s" failed', result.file, dest);
|
|
134
|
-
logError(result.error, new ApiErrorContext({
|
|
137
|
+
if (result.resultType == files_1.FILE_UPLOAD_RESULT_TYPES.FAILURE) {
|
|
138
|
+
logger_1.logger.error('Uploading file "%s" to "%s" failed', result.file, dest);
|
|
139
|
+
(0, index_1.logError)(result.error, new index_1.ApiErrorContext({
|
|
135
140
|
accountId: derivedAccountId,
|
|
136
141
|
request: dest,
|
|
137
142
|
payload: result.file,
|
|
@@ -141,76 +146,78 @@ exports.handler = async (options) => {
|
|
|
141
146
|
},
|
|
142
147
|
};
|
|
143
148
|
return uploadOptions;
|
|
144
|
-
}
|
|
145
|
-
trackCommandUsage('preview', derivedAccountId);
|
|
149
|
+
}
|
|
150
|
+
(0, usageTracking_1.trackCommandUsage)('preview', {}, derivedAccountId);
|
|
146
151
|
let createUnifiedDevServer;
|
|
147
152
|
try {
|
|
153
|
+
// @ts-ignore TODO: Remove when we deprecate Node 18
|
|
148
154
|
require.resolve('@hubspot/cms-dev-server');
|
|
155
|
+
// @ts-ignore TODO: Remove when we deprecate Node 18
|
|
149
156
|
const { createDevServer } = await import('@hubspot/cms-dev-server');
|
|
150
157
|
createUnifiedDevServer = createDevServer;
|
|
151
158
|
}
|
|
152
159
|
catch (e) {
|
|
153
|
-
logger.warn('Unified dev server requires node 20 to run. Defaulting to legacy preview.');
|
|
160
|
+
logger_1.logger.warn('Unified dev server requires node 20 to run. Defaulting to legacy preview.');
|
|
154
161
|
}
|
|
155
|
-
const isUngatedForUnified = await hasFeature(derivedAccountId, 'cms:react:unifiedThemePreview');
|
|
162
|
+
const isUngatedForUnified = await (0, hasFeature_1.hasFeature)(derivedAccountId, 'cms:react:unifiedThemePreview');
|
|
156
163
|
if (isUngatedForUnified && createUnifiedDevServer) {
|
|
157
164
|
if (port) {
|
|
158
|
-
process.env['PORT'] = port;
|
|
165
|
+
process.env['PORT'] = port.toString();
|
|
159
166
|
}
|
|
160
|
-
createUnifiedDevServer(absoluteSrc, false,
|
|
167
|
+
createUnifiedDevServer(absoluteSrc, false, '', '', !noSsl, generateFieldsTypes, {
|
|
161
168
|
filePaths,
|
|
162
|
-
resetSession,
|
|
169
|
+
resetSession: resetSession || false,
|
|
163
170
|
startProgressBar,
|
|
164
|
-
handleUserInput,
|
|
165
171
|
dest,
|
|
166
172
|
});
|
|
167
173
|
}
|
|
168
174
|
else {
|
|
169
|
-
preview(derivedAccountId, absoluteSrc, dest, {
|
|
175
|
+
(0, theme_preview_dev_server_1.preview)(derivedAccountId, absoluteSrc, dest, {
|
|
170
176
|
notify,
|
|
171
177
|
filePaths,
|
|
172
178
|
noSsl,
|
|
173
179
|
port,
|
|
174
|
-
resetSession,
|
|
180
|
+
resetSession: resetSession || false,
|
|
175
181
|
startProgressBar,
|
|
176
182
|
handleUserInput,
|
|
177
183
|
});
|
|
178
184
|
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
addConfigOptions(yargs);
|
|
182
|
-
addAccountOptions(yargs);
|
|
183
|
-
yargs
|
|
184
|
-
|
|
185
|
+
}
|
|
186
|
+
function builder(yargs) {
|
|
187
|
+
(0, commonOpts_1.addConfigOptions)(yargs);
|
|
188
|
+
(0, commonOpts_1.addAccountOptions)(yargs);
|
|
189
|
+
yargs
|
|
190
|
+
.option('src', {
|
|
191
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.src.describe`),
|
|
185
192
|
type: 'string',
|
|
186
193
|
requiresArg: true,
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
describe: i18n(`${i18nKey}.options.dest.describe`),
|
|
194
|
+
})
|
|
195
|
+
.option('dest', {
|
|
196
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.dest.describe`),
|
|
190
197
|
type: 'string',
|
|
191
198
|
requiresArg: true,
|
|
192
|
-
})
|
|
193
|
-
|
|
199
|
+
})
|
|
200
|
+
.option('notify', {
|
|
194
201
|
alias: 'n',
|
|
195
|
-
describe: i18n(`${i18nKey}.options.notify.describe`),
|
|
202
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.notify.describe`),
|
|
196
203
|
type: 'string',
|
|
197
204
|
requiresArg: true,
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
describe: i18n(`${i18nKey}.options.noSsl.describe`),
|
|
205
|
+
})
|
|
206
|
+
.option('no-ssl', {
|
|
207
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.noSsl.describe`),
|
|
201
208
|
type: 'boolean',
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
describe: i18n(`${i18nKey}.options.port.describe`),
|
|
209
|
+
})
|
|
210
|
+
.option('port', {
|
|
211
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.port.describe`),
|
|
205
212
|
type: 'number',
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
|
|
213
|
+
})
|
|
214
|
+
.option('resetSession', {
|
|
215
|
+
hidden: true,
|
|
209
216
|
type: 'boolean',
|
|
210
|
-
})
|
|
211
|
-
|
|
212
|
-
|
|
217
|
+
})
|
|
218
|
+
.option('generateFieldsTypes', {
|
|
219
|
+
hidden: true,
|
|
213
220
|
type: 'boolean',
|
|
214
221
|
});
|
|
215
222
|
return yargs;
|
|
216
|
-
}
|
|
223
|
+
}
|
package/commands/theme.d.ts
CHANGED