@hubspot/cli 3.0.13-beta.1 → 3.0.13-beta.4
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 +14 -0
- package/commands/module/marketplace-validate.js +77 -0
- package/commands/module.js +17 -0
- package/commands/project/logs.js +26 -15
- package/commands/theme/marketplace-validate.js +4 -2
- package/commands/upload.js +8 -3
- package/commands/watch.js +8 -2
- package/lib/hasFlag.js +15 -0
- package/lib/projects.js +1 -2
- package/lib/prompts/projectsLogsPrompt.js +54 -3
- package/lib/prompts/uploadPrompt.js +39 -0
- package/lib/serverlessLogs.js +7 -1
- package/lib/supportHyperlinks.js +75 -0
- package/lib/supportsColor.js +129 -0
- package/lib/ui.js +22 -5
- package/lib/validators/__tests__/{BaseValidator.js → AbsoluteValidator.js} +3 -3
- package/lib/validators/__tests__/ModuleDependencyValidator.js +79 -0
- package/lib/validators/__tests__/ModuleValidator.js +22 -55
- package/lib/validators/__tests__/RelativeValidator.js +28 -0
- package/lib/validators/__tests__/TemplateValidator.js +1 -1
- package/lib/validators/__tests__/ThemeConfigValidator.js +1 -1
- package/lib/validators/__tests__/{DependencyValidator.js → ThemeDependencyValidator.js} +14 -12
- package/lib/validators/__tests__/ThemeModuleValidator.js +84 -0
- package/lib/validators/__tests__/validatorTestUtils.js +2 -0
- package/lib/validators/applyValidators.js +20 -4
- package/lib/validators/constants.js +4 -2
- package/lib/validators/index.js +8 -4
- package/lib/validators/marketplaceValidators/{BaseValidator.js → AbsoluteValidator.js} +8 -8
- package/lib/validators/marketplaceValidators/RelativeValidator.js +46 -0
- package/lib/validators/marketplaceValidators/module/ModuleDependencyValidator.js +101 -0
- package/lib/validators/marketplaceValidators/module/ModuleValidator.js +102 -0
- package/lib/validators/marketplaceValidators/theme/SectionValidator.js +2 -2
- package/lib/validators/marketplaceValidators/theme/TemplateValidator.js +2 -2
- package/lib/validators/marketplaceValidators/theme/ThemeConfigValidator.js +3 -3
- package/lib/validators/marketplaceValidators/theme/{DependencyValidator.js → ThemeDependencyValidator.js} +15 -12
- package/lib/validators/marketplaceValidators/theme/{ModuleValidator.js → ThemeModuleValidator.js} +5 -5
- package/package.json +4 -5
package/bin/cli.js
CHANGED
|
@@ -31,6 +31,7 @@ const openCommand = require('../commands/open');
|
|
|
31
31
|
const mvCommand = require('../commands/mv');
|
|
32
32
|
const projectCommands = require('../commands/project');
|
|
33
33
|
const themeCommand = require('../commands/theme');
|
|
34
|
+
const moduleCommand = require('../commands/module');
|
|
34
35
|
const configCommand = require('../commands/config');
|
|
35
36
|
const accountsCommand = require('../commands/accounts');
|
|
36
37
|
const sandboxesCommand = require('../commands/sandbox');
|
|
@@ -81,6 +82,18 @@ const argv = yargs
|
|
|
81
82
|
describe: 'set log level to debug',
|
|
82
83
|
type: 'boolean',
|
|
83
84
|
})
|
|
85
|
+
.option('noHyperlinks', {
|
|
86
|
+
default: false,
|
|
87
|
+
describe: 'prevent hyperlinks from displaying in the ui',
|
|
88
|
+
hidden: true,
|
|
89
|
+
type: 'boolean',
|
|
90
|
+
})
|
|
91
|
+
.option('noColor', {
|
|
92
|
+
default: false,
|
|
93
|
+
describe: 'prevent color from displaying in the ui',
|
|
94
|
+
hidden: true,
|
|
95
|
+
type: 'boolean',
|
|
96
|
+
})
|
|
84
97
|
.check(argv => {
|
|
85
98
|
if (argv._.length === 1 && ['upload', 'watch'].includes(argv._[0])) {
|
|
86
99
|
if (getIsInProject(argv.src)) {
|
|
@@ -120,6 +133,7 @@ const argv = yargs
|
|
|
120
133
|
.command(mvCommand)
|
|
121
134
|
.command(projectCommands)
|
|
122
135
|
.command(themeCommand)
|
|
136
|
+
.command(moduleCommand)
|
|
123
137
|
.command(configCommand)
|
|
124
138
|
.command(accountsCommand)
|
|
125
139
|
.command(sandboxesCommand)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const { logger } = require('@hubspot/cli-lib/logger');
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
addConfigOptions,
|
|
5
|
+
addAccountOptions,
|
|
6
|
+
addUseEnvironmentOptions,
|
|
7
|
+
getAccountId,
|
|
8
|
+
} = require('../../lib/commonOpts');
|
|
9
|
+
const { loadAndValidateOptions } = require('../../lib/validation');
|
|
10
|
+
const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
11
|
+
const {
|
|
12
|
+
logValidatorResults,
|
|
13
|
+
} = require('../../lib/validators/logValidatorResults');
|
|
14
|
+
const {
|
|
15
|
+
applyRelativeValidators,
|
|
16
|
+
} = require('../../lib/validators/applyValidators');
|
|
17
|
+
const MARKETPLACE_VALIDATORS = require('../../lib/validators');
|
|
18
|
+
const { VALIDATION_RESULT } = require('../../lib/validators/constants');
|
|
19
|
+
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
20
|
+
|
|
21
|
+
const i18nKey = 'cli.commands.module.subcommands.marketplaceValidate';
|
|
22
|
+
const { EXIT_CODES } = require('../../lib/enums/exitCodes');
|
|
23
|
+
|
|
24
|
+
exports.command = 'marketplace-validate <src>';
|
|
25
|
+
exports.describe = i18n(`${i18nKey}.describe`);
|
|
26
|
+
|
|
27
|
+
exports.handler = async options => {
|
|
28
|
+
const { src } = options;
|
|
29
|
+
|
|
30
|
+
await loadAndValidateOptions(options);
|
|
31
|
+
|
|
32
|
+
const accountId = getAccountId(options);
|
|
33
|
+
|
|
34
|
+
if (!options.json) {
|
|
35
|
+
logger.log(
|
|
36
|
+
i18n(`${i18nKey}.logs.validatingModule`, {
|
|
37
|
+
path: src,
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
trackCommandUsage('validate', {}, accountId);
|
|
42
|
+
|
|
43
|
+
applyRelativeValidators(
|
|
44
|
+
MARKETPLACE_VALIDATORS.module,
|
|
45
|
+
src,
|
|
46
|
+
src,
|
|
47
|
+
accountId
|
|
48
|
+
).then(groupedResults => {
|
|
49
|
+
logValidatorResults(groupedResults, { logAsJson: options.json });
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
groupedResults
|
|
53
|
+
.flat()
|
|
54
|
+
.some(result => result.result === VALIDATION_RESULT.FATAL)
|
|
55
|
+
) {
|
|
56
|
+
process.exit(EXIT_CODES.WARNING);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
exports.builder = yargs => {
|
|
62
|
+
addConfigOptions(yargs, true);
|
|
63
|
+
addAccountOptions(yargs, true);
|
|
64
|
+
addUseEnvironmentOptions(yargs, true);
|
|
65
|
+
|
|
66
|
+
yargs.options({
|
|
67
|
+
json: {
|
|
68
|
+
describe: i18n(`${i18nKey}.options.json.describe`),
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
yargs.positional('src', {
|
|
73
|
+
describe: i18n(`${i18nKey}.positionals.src.describe`),
|
|
74
|
+
type: 'string',
|
|
75
|
+
});
|
|
76
|
+
return yargs;
|
|
77
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const marketplaceValidate = require('./module/marketplace-validate');
|
|
2
|
+
const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts');
|
|
3
|
+
// const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
4
|
+
|
|
5
|
+
// const i18nKey = 'cli.commands.module';
|
|
6
|
+
|
|
7
|
+
exports.command = 'module';
|
|
8
|
+
exports.describe = false; //i18n(`${i18nKey}.describe`);
|
|
9
|
+
|
|
10
|
+
exports.builder = yargs => {
|
|
11
|
+
addConfigOptions(yargs, true);
|
|
12
|
+
addAccountOptions(yargs, true);
|
|
13
|
+
|
|
14
|
+
yargs.command(marketplaceValidate).demandCommand(1, '');
|
|
15
|
+
|
|
16
|
+
return yargs;
|
|
17
|
+
};
|
package/commands/project/logs.js
CHANGED
|
@@ -120,7 +120,7 @@ const handleFunctionLog = async (accountId, options) => {
|
|
|
120
120
|
return false;
|
|
121
121
|
};
|
|
122
122
|
|
|
123
|
-
exports.command = 'logs [--project] [--app] [--function]';
|
|
123
|
+
exports.command = 'logs [--project] [--app] [--function] [--endpoint]';
|
|
124
124
|
exports.describe = i18n(`${i18nKey}.describe`);
|
|
125
125
|
|
|
126
126
|
exports.handler = async options => {
|
|
@@ -128,21 +128,22 @@ exports.handler = async options => {
|
|
|
128
128
|
|
|
129
129
|
const accountId = getAccountId(options);
|
|
130
130
|
|
|
131
|
-
logger.log(options);
|
|
132
131
|
const {
|
|
133
132
|
projectName: promptProjectName,
|
|
134
133
|
appName: promptAppName,
|
|
135
134
|
functionName: promptFunctionName,
|
|
135
|
+
endpointName: promptEndpointName,
|
|
136
136
|
} = await projectLogsPrompt(accountId, options);
|
|
137
137
|
|
|
138
138
|
const projectName = options.project || promptProjectName;
|
|
139
139
|
const appName = options.app || promptAppName;
|
|
140
140
|
const functionName =
|
|
141
141
|
options.function || promptFunctionName || options.endpoint;
|
|
142
|
+
const endpointName = options.endpoint || promptEndpointName;
|
|
142
143
|
|
|
143
144
|
let relativeAppPath;
|
|
144
145
|
|
|
145
|
-
if (appName && !
|
|
146
|
+
if (appName && !endpointName) {
|
|
146
147
|
await ensureProjectExists(accountId, projectName, {
|
|
147
148
|
allowCreate: false,
|
|
148
149
|
});
|
|
@@ -168,21 +169,31 @@ exports.handler = async options => {
|
|
|
168
169
|
|
|
169
170
|
trackCommandUsage('project-logs', { latest: options.latest }, accountId);
|
|
170
171
|
|
|
171
|
-
const logsInfo = [
|
|
172
|
-
|
|
173
|
-
];
|
|
172
|
+
const logsInfo = [accountId, `"${projectName}"`];
|
|
173
|
+
let tableHeader;
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
if (endpointName) {
|
|
176
|
+
logsInfo.push(`"${endpointName}"`);
|
|
177
|
+
tableHeader = getTableHeader([
|
|
178
|
+
i18n(`${i18nKey}.table.accountHeader`),
|
|
179
|
+
i18n(`${i18nKey}.table.projectHeader`),
|
|
180
|
+
i18n(`${i18nKey}.table.endpointHeader`),
|
|
181
|
+
]);
|
|
182
|
+
} else {
|
|
183
|
+
logsInfo.push(`"${appName}"`);
|
|
184
|
+
logsInfo.push(functionName);
|
|
185
|
+
tableHeader = getTableHeader([
|
|
177
186
|
i18n(`${i18nKey}.table.accountHeader`),
|
|
178
187
|
i18n(`${i18nKey}.table.projectHeader`),
|
|
179
188
|
i18n(`${i18nKey}.table.appHeader`),
|
|
180
189
|
i18n(`${i18nKey}.table.functionHeader`),
|
|
181
|
-
])
|
|
182
|
-
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
183
192
|
|
|
184
193
|
logger.log(i18n(`${i18nKey}.logs.showingLogs`));
|
|
185
|
-
logger.log(
|
|
194
|
+
logger.log(
|
|
195
|
+
getTableContents([tableHeader, logsInfo], { border: { bodyLeft: ' ' } })
|
|
196
|
+
);
|
|
186
197
|
|
|
187
198
|
logger.log(
|
|
188
199
|
uiLink(
|
|
@@ -197,7 +208,7 @@ exports.handler = async options => {
|
|
|
197
208
|
...options,
|
|
198
209
|
projectName,
|
|
199
210
|
appPath: relativeAppPath,
|
|
200
|
-
functionName,
|
|
211
|
+
functionName: functionName || endpointName,
|
|
201
212
|
});
|
|
202
213
|
|
|
203
214
|
if (showFinalMessage) {
|
|
@@ -217,7 +228,6 @@ exports.builder = yargs => {
|
|
|
217
228
|
endpoint: {
|
|
218
229
|
alias: 'endpoint',
|
|
219
230
|
describe: i18n(`${i18nKey}.options.endpoint.describe`),
|
|
220
|
-
hidden: true,
|
|
221
231
|
requiresArg: true,
|
|
222
232
|
type: 'string',
|
|
223
233
|
},
|
|
@@ -253,10 +263,11 @@ exports.builder = yargs => {
|
|
|
253
263
|
})
|
|
254
264
|
.conflicts('follow', 'limit');
|
|
255
265
|
|
|
266
|
+
yargs.example([['$0 project logs', i18n(`${i18nKey}.examples.default`)]]);
|
|
256
267
|
yargs.example([
|
|
257
268
|
[
|
|
258
|
-
'$0 project logs --project=
|
|
259
|
-
i18n(`${i18nKey}.examples.
|
|
269
|
+
'$0 project logs --project=my-project --app=app --function=my-function',
|
|
270
|
+
i18n(`${i18nKey}.examples.withOptions`),
|
|
260
271
|
],
|
|
261
272
|
]);
|
|
262
273
|
|
|
@@ -16,7 +16,9 @@ const { trackCommandUsage } = require('../../lib/usageTracking');
|
|
|
16
16
|
const {
|
|
17
17
|
logValidatorResults,
|
|
18
18
|
} = require('../../lib/validators/logValidatorResults');
|
|
19
|
-
const {
|
|
19
|
+
const {
|
|
20
|
+
applyAbsoluteValidators,
|
|
21
|
+
} = require('../../lib/validators/applyValidators');
|
|
20
22
|
const MARKETPLACE_VALIDATORS = require('../../lib/validators');
|
|
21
23
|
const { VALIDATION_RESULT } = require('../../lib/validators/constants');
|
|
22
24
|
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
@@ -65,7 +67,7 @@ exports.handler = async options => {
|
|
|
65
67
|
|
|
66
68
|
const themeFiles = await walk(absoluteSrcPath);
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
applyAbsoluteValidators(
|
|
69
71
|
MARKETPLACE_VALIDATORS.theme,
|
|
70
72
|
absoluteSrcPath,
|
|
71
73
|
themeFiles,
|
package/commands/upload.js
CHANGED
|
@@ -26,6 +26,7 @@ const {
|
|
|
26
26
|
getAccountId,
|
|
27
27
|
getMode,
|
|
28
28
|
} = require('../lib/commonOpts');
|
|
29
|
+
const { uploadPrompt } = require('../lib/prompts/uploadPrompt');
|
|
29
30
|
const { validateMode, loadAndValidateOptions } = require('../lib/validation');
|
|
30
31
|
const { trackCommandUsage } = require('../lib/usageTracking');
|
|
31
32
|
const { getThemePreviewUrl } = require('@hubspot/cli-lib/lib/files');
|
|
@@ -34,7 +35,7 @@ const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
|
34
35
|
const i18nKey = 'cli.commands.upload';
|
|
35
36
|
const { EXIT_CODES } = require('../lib/enums/exitCodes');
|
|
36
37
|
|
|
37
|
-
exports.command = 'upload
|
|
38
|
+
exports.command = 'upload [--src] [--dest]';
|
|
38
39
|
exports.describe = i18n(`${i18nKey}.describe`);
|
|
39
40
|
|
|
40
41
|
const logThemePreview = (filePath, accountId) => {
|
|
@@ -50,8 +51,6 @@ const logThemePreview = (filePath, accountId) => {
|
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
exports.handler = async options => {
|
|
53
|
-
const { src, dest } = options;
|
|
54
|
-
|
|
55
54
|
await loadAndValidateOptions(options);
|
|
56
55
|
|
|
57
56
|
if (!validateMode(options)) {
|
|
@@ -60,6 +59,12 @@ exports.handler = async options => {
|
|
|
60
59
|
|
|
61
60
|
const accountId = getAccountId(options);
|
|
62
61
|
const mode = getMode(options);
|
|
62
|
+
|
|
63
|
+
const uploadPromptAnswers = await uploadPrompt(options);
|
|
64
|
+
|
|
65
|
+
const src = options.src || uploadPromptAnswers.src;
|
|
66
|
+
const dest = options.dest || uploadPromptAnswers.dest;
|
|
67
|
+
|
|
63
68
|
const absoluteSrcPath = path.resolve(getCwd(), src);
|
|
64
69
|
let stats;
|
|
65
70
|
try {
|
package/commands/watch.js
CHANGED
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
getAccountId,
|
|
14
14
|
getMode,
|
|
15
15
|
} = require('../lib/commonOpts');
|
|
16
|
+
const { uploadPrompt } = require('../lib/prompts/uploadPrompt');
|
|
16
17
|
const { validateMode, loadAndValidateOptions } = require('../lib/validation');
|
|
17
18
|
const { trackCommandUsage } = require('../lib/usageTracking');
|
|
18
19
|
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
@@ -20,11 +21,11 @@ const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
|
20
21
|
const i18nKey = 'cli.commands.watch';
|
|
21
22
|
const { EXIT_CODES } = require('../lib/enums/exitCodes');
|
|
22
23
|
|
|
23
|
-
exports.command = 'watch
|
|
24
|
+
exports.command = 'watch [--src] [--dest]';
|
|
24
25
|
exports.describe = i18n(`${i18nKey}.describe`);
|
|
25
26
|
|
|
26
27
|
exports.handler = async options => {
|
|
27
|
-
const {
|
|
28
|
+
const { remove, initialUpload, disableInitial, notify } = options;
|
|
28
29
|
|
|
29
30
|
await loadAndValidateOptions(options);
|
|
30
31
|
|
|
@@ -35,6 +36,11 @@ exports.handler = async options => {
|
|
|
35
36
|
const accountId = getAccountId(options);
|
|
36
37
|
const mode = getMode(options);
|
|
37
38
|
|
|
39
|
+
const uploadPromptAnswers = await uploadPrompt(options);
|
|
40
|
+
|
|
41
|
+
const src = options.src || uploadPromptAnswers.src;
|
|
42
|
+
const dest = options.dest || uploadPromptAnswers.dest;
|
|
43
|
+
|
|
38
44
|
const absoluteSrcPath = path.resolve(getCwd(), src);
|
|
39
45
|
try {
|
|
40
46
|
const stats = fs.statSync(absoluteSrcPath);
|
package/lib/hasFlag.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const process = require('process');
|
|
2
|
+
|
|
3
|
+
// See https://github.com/sindresorhus/has-flag/blob/main/index.js (License: https://github.com/sindresorhus/has-flag/blob/main/license)
|
|
4
|
+
|
|
5
|
+
function hasFlag(flag, argv = process.argv) {
|
|
6
|
+
const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
|
|
7
|
+
const position = argv.indexOf(prefix + flag);
|
|
8
|
+
const terminatorPosition = argv.indexOf('--');
|
|
9
|
+
return (
|
|
10
|
+
position !== -1 &&
|
|
11
|
+
(terminatorPosition === -1 || position < terminatorPosition)
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = hasFlag;
|
package/lib/projects.js
CHANGED
|
@@ -483,8 +483,7 @@ const pollBuildStatus = makePollTaskStatusFunc({
|
|
|
483
483
|
linkToHubSpot: (projectName, buildId, accountId) =>
|
|
484
484
|
uiLink(
|
|
485
485
|
`View build #${buildId} in HubSpot`,
|
|
486
|
-
getProjectBuildDetailUrl(projectName, buildId, accountId)
|
|
487
|
-
{ useColor: true }
|
|
486
|
+
getProjectBuildDetailUrl(projectName, buildId, accountId)
|
|
488
487
|
),
|
|
489
488
|
statusFn: getBuildStatus,
|
|
490
489
|
statusText: PROJECT_BUILD_TEXT,
|
|
@@ -7,22 +7,55 @@ const { EXIT_CODES } = require('../enums/exitCodes');
|
|
|
7
7
|
|
|
8
8
|
const i18nKey = 'cli.lib.prompts.projectLogsPrompt';
|
|
9
9
|
|
|
10
|
+
const SERVERLESS_FUNCTION_TYPES = {
|
|
11
|
+
APP_FUNCTION: 'app-function',
|
|
12
|
+
PUBLIC_ENDPOINT: 'public-endpoint',
|
|
13
|
+
};
|
|
14
|
+
|
|
10
15
|
const projectLogsPrompt = (accountId, promptOptions = {}) => {
|
|
11
16
|
return promptUser([
|
|
12
17
|
{
|
|
13
18
|
name: 'projectName',
|
|
14
|
-
message: i18n(`${i18nKey}.projectName`),
|
|
19
|
+
message: i18n(`${i18nKey}.projectName.message`),
|
|
15
20
|
when: !promptOptions.project,
|
|
16
21
|
default: async () => {
|
|
17
22
|
const { projectConfig } = await getProjectConfig();
|
|
18
23
|
return projectConfig && projectConfig.name ? projectConfig.name : null;
|
|
19
24
|
},
|
|
25
|
+
validate: name =>
|
|
26
|
+
!name.length ? i18n(`${i18nKey}.projectName.error`) : true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'logType',
|
|
30
|
+
type: 'list',
|
|
31
|
+
message: i18n(`${i18nKey}.logType.message`),
|
|
32
|
+
when:
|
|
33
|
+
!promptOptions.app &&
|
|
34
|
+
!promptOptions.function &&
|
|
35
|
+
!promptOptions.endpoint,
|
|
36
|
+
choices: [
|
|
37
|
+
{
|
|
38
|
+
name: i18n(`${i18nKey}.logType.function`),
|
|
39
|
+
value: SERVERLESS_FUNCTION_TYPES.APP_FUNCTION,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: i18n(`${i18nKey}.logType.endpoint`),
|
|
43
|
+
value: SERVERLESS_FUNCTION_TYPES.PUBLIC_ENDPOINT,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
20
46
|
},
|
|
21
47
|
{
|
|
22
48
|
name: 'appName',
|
|
23
49
|
type: 'list',
|
|
24
50
|
message: i18n(`${i18nKey}.appName`),
|
|
25
|
-
when:
|
|
51
|
+
when: ({ logType }) => {
|
|
52
|
+
return (
|
|
53
|
+
(promptOptions.function ||
|
|
54
|
+
logType === SERVERLESS_FUNCTION_TYPES.APP_FUNCTION) &&
|
|
55
|
+
!promptOptions.app &&
|
|
56
|
+
!promptOptions.endpoint
|
|
57
|
+
);
|
|
58
|
+
},
|
|
26
59
|
choices: async ({ projectName }) => {
|
|
27
60
|
const name = projectName || promptOptions.project;
|
|
28
61
|
|
|
@@ -47,7 +80,25 @@ const projectLogsPrompt = (accountId, promptOptions = {}) => {
|
|
|
47
80
|
{
|
|
48
81
|
name: 'functionName',
|
|
49
82
|
message: i18n(`${i18nKey}.functionName`),
|
|
50
|
-
when:
|
|
83
|
+
when: ({ logType }) => {
|
|
84
|
+
return (
|
|
85
|
+
(promptOptions.app ||
|
|
86
|
+
logType === SERVERLESS_FUNCTION_TYPES.APP_FUNCTION) &&
|
|
87
|
+
!promptOptions.function &&
|
|
88
|
+
!promptOptions.endpoint
|
|
89
|
+
);
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'endpointName',
|
|
94
|
+
message: i18n(`${i18nKey}.endpointName`),
|
|
95
|
+
when: ({ logType }) => {
|
|
96
|
+
return (
|
|
97
|
+
logType === SERVERLESS_FUNCTION_TYPES.PUBLIC_ENDPOINT &&
|
|
98
|
+
!promptOptions.function &&
|
|
99
|
+
!promptOptions.endpoint
|
|
100
|
+
);
|
|
101
|
+
},
|
|
51
102
|
},
|
|
52
103
|
]);
|
|
53
104
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const { getCwd } = require('@hubspot/cli-lib/path');
|
|
3
|
+
const { promptUser } = require('./promptUtils');
|
|
4
|
+
const { i18n } = require('@hubspot/cli-lib/lib/lang');
|
|
5
|
+
|
|
6
|
+
const i18nKey = 'cli.lib.prompts.uploadPrompt';
|
|
7
|
+
|
|
8
|
+
const uploadPrompt = (promptOptions = {}) => {
|
|
9
|
+
return promptUser([
|
|
10
|
+
{
|
|
11
|
+
name: 'src',
|
|
12
|
+
message: i18n(`${i18nKey}.enterSrc`),
|
|
13
|
+
when: !promptOptions.src,
|
|
14
|
+
default: '.',
|
|
15
|
+
validate: input => {
|
|
16
|
+
if (!input) {
|
|
17
|
+
return i18n(`${i18nKey}.errors.srcRequired`);
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'dest',
|
|
24
|
+
message: i18n(`${i18nKey}.enterDest`),
|
|
25
|
+
when: !promptOptions.dest,
|
|
26
|
+
default: path.basename(getCwd()),
|
|
27
|
+
validate: input => {
|
|
28
|
+
if (!input) {
|
|
29
|
+
return i18n(`${i18nKey}.errors.destRequired`);
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
]);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = {
|
|
38
|
+
uploadPrompt,
|
|
39
|
+
};
|
package/lib/serverlessLogs.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const https = require('https');
|
|
2
2
|
const Spinnies = require('spinnies');
|
|
3
|
+
const chalk = require('chalk');
|
|
3
4
|
const { logger } = require('@hubspot/cli-lib/logger');
|
|
4
5
|
const { outputLogs } = require('@hubspot/cli-lib/lib/logs');
|
|
5
6
|
const {
|
|
@@ -17,6 +18,7 @@ const TAIL_DELAY = 5000;
|
|
|
17
18
|
const handleUserInput = spinnies => {
|
|
18
19
|
const onTerminate = async () => {
|
|
19
20
|
spinnies.remove('tailLogs');
|
|
21
|
+
spinnies.remove('stopMessage');
|
|
20
22
|
process.exit(EXIT_CODES.SUCCESS);
|
|
21
23
|
};
|
|
22
24
|
|
|
@@ -83,7 +85,11 @@ const tailLogs = async ({
|
|
|
83
85
|
const spinnies = new Spinnies();
|
|
84
86
|
|
|
85
87
|
spinnies.add('tailLogs', {
|
|
86
|
-
text: `Following logs for ${name}
|
|
88
|
+
text: `Following logs for ${name}`,
|
|
89
|
+
});
|
|
90
|
+
spinnies.add('stopMessage', {
|
|
91
|
+
text: `> Press ${chalk.bold('q')} to stop following`,
|
|
92
|
+
status: 'non-spinnable',
|
|
87
93
|
});
|
|
88
94
|
|
|
89
95
|
handleUserInput(spinnies);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const hasFlag = require('./hasFlag');
|
|
3
|
+
|
|
4
|
+
//See https://github.com/jamestalmage/supports-hyperlinks (License: https://github.com/jamestalmage/supports-hyperlinks/blob/master/license)
|
|
5
|
+
|
|
6
|
+
function parseVersion(versionString) {
|
|
7
|
+
if (/^\d{3,4}$/.test(versionString)) {
|
|
8
|
+
// Env var doesn't always use dots. example: 4601 => 46.1.0
|
|
9
|
+
const m = /(\d{1,2})(\d{2})/.exec(versionString);
|
|
10
|
+
return {
|
|
11
|
+
major: 0,
|
|
12
|
+
minor: parseInt(m[1], 10),
|
|
13
|
+
patch: parseInt(m[2], 10),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const versions = (versionString || '').split('.').map(n => parseInt(n, 10));
|
|
18
|
+
return {
|
|
19
|
+
major: versions[0],
|
|
20
|
+
minor: versions[1],
|
|
21
|
+
patch: versions[2],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function supportsHyperlink(stream) {
|
|
26
|
+
const { env } = process;
|
|
27
|
+
|
|
28
|
+
if (hasFlag('noHyperlinks')) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (stream && !stream.isTTY) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (process.platform === 'win32') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if ('CI' in env) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if ('TERM_PROGRAM' in env) {
|
|
45
|
+
const version = parseVersion(env.TERM_PROGRAM_VERSION);
|
|
46
|
+
|
|
47
|
+
switch (env.TERM_PROGRAM) {
|
|
48
|
+
case 'iTerm.app':
|
|
49
|
+
if (version.major === 3) {
|
|
50
|
+
return version.minor >= 1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return version.major > 3;
|
|
54
|
+
// No default
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if ('VTE_VERSION' in env) {
|
|
59
|
+
// 0.50.0 was supposed to support hyperlinks, but throws a segfault
|
|
60
|
+
if (env.VTE_VERSION === '0.50.0') {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const version = parseVersion(env.VTE_VERSION);
|
|
65
|
+
return version.major > 0 || version.minor >= 50;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
supportsHyperlink,
|
|
73
|
+
stdout: supportsHyperlink(process.stdout),
|
|
74
|
+
stderr: supportsHyperlink(process.stderr),
|
|
75
|
+
};
|