@hubspot/cli 7.2.3-experimental.0 → 7.2.4-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 +0 -2
- package/commands/account/info.d.ts +1 -1
- package/commands/account/info.js +8 -5
- package/commands/auth.d.ts +9 -0
- package/commands/auth.js +89 -83
- package/commands/init.d.ts +11 -0
- package/commands/init.js +114 -100
- package/commands/list.d.ts +9 -0
- package/commands/list.js +63 -57
- package/commands/mv.d.ts +10 -0
- package/commands/mv.js +32 -32
- package/commands/open.d.ts +10 -0
- package/commands/open.js +37 -34
- package/commands/project/cloneApp.d.ts +1 -5
- package/commands/project/cloneApp.js +75 -78
- package/commands/project/create.js +2 -0
- package/commands/project/dev/deprecatedFlow.d.ts +5 -0
- package/commands/project/{dev.js → dev/deprecatedFlow.js} +14 -44
- package/commands/project/{dev.d.ts → dev/index.d.ts} +1 -3
- 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.d.ts +1 -6
- package/commands/project/migrateApp.js +184 -17
- package/commands/project/upload.js +7 -2
- package/commands/remove.d.ts +9 -0
- package/commands/remove.js +25 -23
- package/lang/en.lyaml +19 -36
- package/lib/DevServerManagerV2.d.ts +34 -0
- package/lib/DevServerManagerV2.js +85 -0
- package/lib/LocalDevManager.js +1 -1
- package/lib/LocalDevManagerV2.d.ts +64 -0
- package/lib/LocalDevManagerV2.js +382 -0
- package/lib/commonOpts.d.ts +1 -0
- package/lib/commonOpts.js +30 -0
- package/lib/constants.d.ts +12 -0
- package/lib/constants.js +13 -1
- 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 +1 -1
- package/lib/localDev.js +2 -2
- 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/accountNamePrompt.d.ts +2 -3
- package/lib/prompts/createProjectPrompt.js +14 -12
- package/lib/prompts/personalAccessKeyPrompt.d.ts +4 -4
- package/lib/prompts/promptUtils.d.ts +3 -3
- package/lib/ui/index.d.ts +4 -4
- package/lib/ui/index.js +12 -15
- package/lib/ui/supportHyperlinks.js +2 -2
- package/lib/ui/supportsColor.js +2 -2
- package/lib/usageTracking.d.ts +1 -2
- package/lib/yargsUtils.d.ts +9 -0
- package/lib/yargsUtils.js +40 -0
- package/package.json +4 -4
- package/types/ProjectComponents.d.ts +38 -0
- package/types/ProjectComponents.js +3 -0
- package/types/Prompts.d.ts +2 -2
- package/types/Yargs.d.ts +1 -6
- package/commands/app/migrate.d.ts +0 -6
- package/commands/app/migrate.js +0 -80
- package/commands/app.d.ts +0 -4
- package/commands/app.js +0 -47
- package/lib/app/migrate.d.ts +0 -6
- package/lib/app/migrate.js +0 -277
- package/lib/hasFlag.d.ts +0 -1
- package/lib/hasFlag.js +0 -15
package/bin/cli.js
CHANGED
|
@@ -43,7 +43,6 @@ const cmsCommand = require('../commands/cms');
|
|
|
43
43
|
const feedbackCommand = require('../commands/feedback');
|
|
44
44
|
const doctorCommand = require('../commands/doctor');
|
|
45
45
|
const completionCommand = require('../commands/completion');
|
|
46
|
-
const appCommand = require('../commands/app');
|
|
47
46
|
const notifier = updateNotifier({
|
|
48
47
|
pkg: { ...pkg, name: '@hubspot/cli' },
|
|
49
48
|
distTag: 'latest',
|
|
@@ -296,7 +295,6 @@ const argv = yargs
|
|
|
296
295
|
.command(feedbackCommand)
|
|
297
296
|
.command(doctorCommand)
|
|
298
297
|
.command(completionCommand)
|
|
299
|
-
.command(appCommand)
|
|
300
298
|
.help()
|
|
301
299
|
.alias('h', 'help')
|
|
302
300
|
.recommendCommands()
|
|
@@ -4,5 +4,5 @@ export declare const describe: string;
|
|
|
4
4
|
export declare const command = "info [account]";
|
|
5
5
|
type AccountInfoArgs = CommonArgs & ConfigArgs;
|
|
6
6
|
export declare function handler(args: ArgumentsCamelCase<AccountInfoArgs>): Promise<void>;
|
|
7
|
-
export declare
|
|
7
|
+
export declare const builder: (yargs: Argv) => Promise<Argv<AccountInfoArgs>>;
|
|
8
8
|
export {};
|
package/commands/account/info.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.command = exports.describe = void 0;
|
|
3
|
+
exports.builder = exports.command = exports.describe = void 0;
|
|
4
4
|
exports.handler = handler;
|
|
5
|
-
exports.builder = builder;
|
|
6
5
|
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
7
6
|
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
8
7
|
const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
|
|
9
|
-
const
|
|
8
|
+
const yargsUtils_1 = require("../../lib/yargsUtils");
|
|
10
9
|
const lang_1 = require("../../lib/lang");
|
|
11
10
|
const table_1 = require("../../lib/ui/table");
|
|
12
11
|
const i18nKey = 'commands.account.subcommands.info';
|
|
@@ -30,8 +29,11 @@ async function handler(args) {
|
|
|
30
29
|
logger_1.logger.log((0, lang_1.i18n)(`${i18nKey}.errors.notUsingPersonalAccessKey`));
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
function
|
|
34
|
-
(
|
|
32
|
+
function accountInfoBuilder(yargs) {
|
|
33
|
+
yargs.positional('account', {
|
|
34
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.account.describe`),
|
|
35
|
+
type: 'string',
|
|
36
|
+
});
|
|
35
37
|
yargs.example([
|
|
36
38
|
['$0 accounts info', (0, lang_1.i18n)(`${i18nKey}.examples.default`)],
|
|
37
39
|
['$0 accounts info MyAccount', (0, lang_1.i18n)(`${i18nKey}.examples.nameBased`)],
|
|
@@ -39,3 +41,4 @@ function builder(yargs) {
|
|
|
39
41
|
]);
|
|
40
42
|
return yargs;
|
|
41
43
|
}
|
|
44
|
+
exports.builder = (0, yargsUtils_1.makeYargsBuilder)(accountInfoBuilder, exports.command, exports.describe, { useConfigOptions: true });
|
package/commands/auth.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
+
import { Argv, ArgumentsCamelCase } from 'yargs';
|
|
2
|
+
import { AccountArgs, CommonArgs, ConfigArgs, TestingArgs } from '../types/Yargs';
|
|
3
|
+
export declare const command = "auth";
|
|
4
|
+
export declare const describe: string;
|
|
5
|
+
type AuthArgs = CommonArgs & ConfigArgs & TestingArgs & AccountArgs & {
|
|
6
|
+
authType?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function handler(args: ArgumentsCamelCase<AuthArgs>): Promise<void>;
|
|
9
|
+
export declare const builder: (yargs: Argv) => Promise<Argv<AuthArgs>>;
|
|
1
10
|
export {};
|
package/commands/auth.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
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
|
|
3
|
+
exports.builder = exports.describe = exports.command = void 0;
|
|
4
|
+
exports.handler = handler;
|
|
5
|
+
const git_1 = require("../lib/ui/git");
|
|
6
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
7
|
+
const auth_1 = require("@hubspot/local-dev-lib/constants/auth");
|
|
8
|
+
const environments_1 = require("@hubspot/local-dev-lib/constants/environments");
|
|
9
|
+
const config_1 = require("@hubspot/local-dev-lib/constants/config");
|
|
10
|
+
const lang_1 = require("../lib/lang");
|
|
11
|
+
const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
|
|
12
|
+
const config_2 = require("@hubspot/local-dev-lib/config");
|
|
13
|
+
const text_1 = require("@hubspot/local-dev-lib/text");
|
|
14
|
+
const promptUtils_1 = require("../lib/prompts/promptUtils");
|
|
15
|
+
const personalAccessKeyPrompt_1 = require("../lib/prompts/personalAccessKeyPrompt");
|
|
16
|
+
const accountNamePrompt_1 = require("../lib/prompts/accountNamePrompt");
|
|
17
|
+
const setAsDefaultAccountPrompt_1 = require("../lib/prompts/setAsDefaultAccountPrompt");
|
|
18
|
+
const commonOpts_1 = require("../lib/commonOpts");
|
|
19
|
+
const yargsUtils_1 = require("../lib/yargsUtils");
|
|
20
|
+
const usageTracking_1 = require("../lib/usageTracking");
|
|
21
|
+
const oauth_1 = require("../lib/oauth");
|
|
22
|
+
const exitCodes_1 = require("../lib/enums/exitCodes");
|
|
23
|
+
const ui_1 = require("../lib/ui");
|
|
24
|
+
const index_1 = require("../lib/errorHandlers/index");
|
|
23
25
|
const i18nKey = 'commands.auth';
|
|
24
26
|
const TRACKING_STATUS = {
|
|
25
27
|
STARTED: 'started',
|
|
@@ -27,29 +29,30 @@ const TRACKING_STATUS = {
|
|
|
27
29
|
COMPLETE: 'complete',
|
|
28
30
|
};
|
|
29
31
|
const ALLOWED_AUTH_METHODS = [
|
|
30
|
-
OAUTH_AUTH_METHOD.value,
|
|
31
|
-
PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
32
|
+
auth_1.OAUTH_AUTH_METHOD.value,
|
|
33
|
+
auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
32
34
|
];
|
|
33
|
-
const SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT = commaSeparatedValues(ALLOWED_AUTH_METHODS);
|
|
35
|
+
const SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT = (0, text_1.commaSeparatedValues)(ALLOWED_AUTH_METHODS);
|
|
34
36
|
exports.command = 'auth';
|
|
35
|
-
exports.describe = i18n(`${i18nKey}.describe
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
exports.handler = async (options) => {
|
|
39
|
-
const { authType: authTypeFlagValue, config: configFlagValue, qa, providedAccountId, } = options;
|
|
37
|
+
exports.describe = (0, lang_1.i18n)(`${i18nKey}.describe`);
|
|
38
|
+
async function handler(args) {
|
|
39
|
+
const { authType: authTypeFlagValue, config: configFlagValue, qa, providedAccountId, } = args;
|
|
40
40
|
const authType = (authTypeFlagValue && authTypeFlagValue.toLowerCase()) ||
|
|
41
|
-
PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
|
|
42
|
-
setLogLevel(
|
|
43
|
-
const env = qa ? ENVIRONMENTS.QA : ENVIRONMENTS.PROD;
|
|
41
|
+
auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
|
|
42
|
+
(0, commonOpts_1.setLogLevel)(args);
|
|
43
|
+
const env = qa ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD;
|
|
44
44
|
// Needed to load deprecated config
|
|
45
|
-
loadConfig(configFlagValue);
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
(0, config_2.loadConfig)(configFlagValue);
|
|
46
|
+
const configPath = (0, config_2.getConfigPath)();
|
|
47
|
+
if (configPath) {
|
|
48
|
+
(0, git_1.checkAndWarnGitInclusion)(configPath);
|
|
49
|
+
}
|
|
50
|
+
if (!(0, config_2.getConfigPath)(configFlagValue)) {
|
|
51
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.noConfigFileFound`));
|
|
52
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
50
53
|
}
|
|
51
|
-
trackCommandUsage('auth');
|
|
52
|
-
trackAuthAction('auth', authType, TRACKING_STATUS.STARTED);
|
|
54
|
+
(0, usageTracking_1.trackCommandUsage)('auth');
|
|
55
|
+
(0, usageTracking_1.trackAuthAction)('auth', authType, TRACKING_STATUS.STARTED, providedAccountId);
|
|
53
56
|
let configData;
|
|
54
57
|
let updatedConfig;
|
|
55
58
|
let validName;
|
|
@@ -57,104 +60,107 @@ exports.handler = async (options) => {
|
|
|
57
60
|
let token;
|
|
58
61
|
let defaultName;
|
|
59
62
|
switch (authType) {
|
|
60
|
-
case OAUTH_AUTH_METHOD.value:
|
|
61
|
-
configData = await promptUser(OAUTH_FLOW);
|
|
62
|
-
await authenticateWithOauth({
|
|
63
|
+
case auth_1.OAUTH_AUTH_METHOD.value:
|
|
64
|
+
configData = await (0, promptUtils_1.promptUser)(personalAccessKeyPrompt_1.OAUTH_FLOW);
|
|
65
|
+
await (0, oauth_1.authenticateWithOauth)({
|
|
63
66
|
...configData,
|
|
64
67
|
env,
|
|
65
68
|
});
|
|
66
|
-
successAuthMethod = OAUTH_AUTH_METHOD.name;
|
|
69
|
+
successAuthMethod = auth_1.OAUTH_AUTH_METHOD.name;
|
|
67
70
|
break;
|
|
68
|
-
case PERSONAL_ACCESS_KEY_AUTH_METHOD.value:
|
|
69
|
-
configData = await personalAccessKeyPrompt({
|
|
71
|
+
case auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value:
|
|
72
|
+
configData = await (0, personalAccessKeyPrompt_1.personalAccessKeyPrompt)({
|
|
70
73
|
env,
|
|
71
74
|
account: providedAccountId,
|
|
72
75
|
});
|
|
73
76
|
try {
|
|
74
|
-
token = await getAccessToken(configData.personalAccessKey, env);
|
|
75
|
-
defaultName = toKebabCase(token.hubName);
|
|
76
|
-
updatedConfig = await updateConfigWithAccessToken(token, configData.personalAccessKey, env);
|
|
77
|
+
token = await (0, personalAccessKey_1.getAccessToken)(configData.personalAccessKey, env);
|
|
78
|
+
defaultName = (0, text_1.toKebabCase)(token.hubName);
|
|
79
|
+
updatedConfig = await (0, personalAccessKey_1.updateConfigWithAccessToken)(token, configData.personalAccessKey, env);
|
|
77
80
|
}
|
|
78
81
|
catch (e) {
|
|
79
|
-
logError(e);
|
|
82
|
+
(0, index_1.logError)(e);
|
|
80
83
|
}
|
|
81
84
|
if (!updatedConfig) {
|
|
82
85
|
break;
|
|
83
86
|
}
|
|
84
87
|
validName = updatedConfig.name;
|
|
85
88
|
if (!validName) {
|
|
86
|
-
const { name: namePrompt } = await cliAccountNamePrompt(defaultName);
|
|
89
|
+
const { name: namePrompt } = await (0, accountNamePrompt_1.cliAccountNamePrompt)(defaultName);
|
|
87
90
|
validName = namePrompt;
|
|
88
91
|
}
|
|
89
|
-
updateAccountConfig({
|
|
92
|
+
(0, config_2.updateAccountConfig)({
|
|
90
93
|
...updatedConfig,
|
|
91
|
-
|
|
94
|
+
env: updatedConfig.env,
|
|
92
95
|
tokenInfo: updatedConfig.auth.tokenInfo,
|
|
93
96
|
name: validName,
|
|
94
97
|
});
|
|
95
|
-
writeConfig();
|
|
96
|
-
successAuthMethod = PERSONAL_ACCESS_KEY_AUTH_METHOD.name;
|
|
98
|
+
(0, config_2.writeConfig)();
|
|
99
|
+
successAuthMethod = auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.name;
|
|
97
100
|
break;
|
|
98
101
|
default:
|
|
99
|
-
logger.error(i18n(`${i18nKey}.errors.unsupportedAuthType`, {
|
|
102
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.unsupportedAuthType`, {
|
|
100
103
|
supportedProtocols: SUPPORTED_AUTHENTICATION_PROTOCOLS_TEXT,
|
|
101
|
-
type,
|
|
104
|
+
type: authType,
|
|
102
105
|
}));
|
|
103
106
|
break;
|
|
104
107
|
}
|
|
105
108
|
if (!successAuthMethod) {
|
|
106
|
-
await trackAuthAction('auth', authType, TRACKING_STATUS.ERROR);
|
|
107
|
-
process.exit(EXIT_CODES.ERROR);
|
|
109
|
+
await (0, usageTracking_1.trackAuthAction)('auth', authType, TRACKING_STATUS.ERROR, providedAccountId);
|
|
110
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
108
111
|
}
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
+
const nameFromConfigData = 'name' in configData ? configData.name : undefined;
|
|
113
|
+
const accountName = (updatedConfig && updatedConfig.name) || validName || nameFromConfigData;
|
|
114
|
+
const setAsDefault = await (0, setAsDefaultAccountPrompt_1.setAsDefaultAccountPrompt)(accountName);
|
|
115
|
+
logger_1.logger.log('');
|
|
112
116
|
if (setAsDefault) {
|
|
113
|
-
logger.success(i18n(`lib.prompts.setAsDefaultAccountPrompt.setAsDefaultAccount`, {
|
|
117
|
+
logger_1.logger.success((0, lang_1.i18n)(`lib.prompts.setAsDefaultAccountPrompt.setAsDefaultAccount`, {
|
|
114
118
|
accountName,
|
|
115
119
|
}));
|
|
116
120
|
}
|
|
117
121
|
else {
|
|
118
|
-
logger.info(i18n(`lib.prompts.setAsDefaultAccountPrompt.keepingCurrentDefault`, {
|
|
119
|
-
accountName: getConfigDefaultAccount(),
|
|
122
|
+
logger_1.logger.info((0, lang_1.i18n)(`lib.prompts.setAsDefaultAccountPrompt.keepingCurrentDefault`, {
|
|
123
|
+
accountName: (0, config_2.getConfigDefaultAccount)(),
|
|
120
124
|
}));
|
|
121
125
|
}
|
|
122
|
-
logger.success(i18n(`${i18nKey}.success.configFileUpdated`, {
|
|
123
|
-
configFilename: DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
126
|
+
logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.success.configFileUpdated`, {
|
|
127
|
+
configFilename: config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
124
128
|
authType: successAuthMethod,
|
|
125
129
|
accountName,
|
|
126
130
|
}));
|
|
127
|
-
uiFeatureHighlight([
|
|
131
|
+
(0, ui_1.uiFeatureHighlight)([
|
|
128
132
|
'accountsUseCommand',
|
|
129
133
|
'accountOption',
|
|
130
134
|
'accountsListCommand',
|
|
131
135
|
]);
|
|
132
|
-
const accountId = getAccountId(accountName);
|
|
133
|
-
await trackAuthAction('auth', authType, TRACKING_STATUS.COMPLETE, accountId);
|
|
134
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
135
|
-
}
|
|
136
|
-
|
|
136
|
+
const accountId = (0, config_2.getAccountId)(accountName) || undefined;
|
|
137
|
+
await (0, usageTracking_1.trackAuthAction)('auth', authType, TRACKING_STATUS.COMPLETE, accountId);
|
|
138
|
+
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
139
|
+
}
|
|
140
|
+
function authBuilder(yargs) {
|
|
137
141
|
yargs.options({
|
|
138
142
|
'auth-type': {
|
|
139
|
-
describe: i18n(`${i18nKey}.options.authType.describe`),
|
|
143
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.authType.describe`),
|
|
140
144
|
type: 'string',
|
|
141
145
|
choices: [
|
|
142
|
-
`${PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
|
|
143
|
-
`${OAUTH_AUTH_METHOD.value}`,
|
|
146
|
+
`${auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
|
|
147
|
+
`${auth_1.OAUTH_AUTH_METHOD.value}`,
|
|
144
148
|
],
|
|
145
|
-
default: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
146
|
-
defaultDescription: i18n(`${i18nKey}.options.authType.defaultDescription`, {
|
|
147
|
-
authMethod: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
148
|
-
}),
|
|
149
|
+
default: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
149
150
|
},
|
|
150
151
|
account: {
|
|
151
|
-
describe: i18n(`${i18nKey}.options.account.describe`),
|
|
152
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.account.describe`),
|
|
152
153
|
type: 'string',
|
|
153
154
|
alias: 'a',
|
|
154
155
|
},
|
|
155
156
|
});
|
|
156
|
-
addConfigOptions(yargs);
|
|
157
|
-
addTestingOptions(yargs);
|
|
158
|
-
addGlobalOptions(yargs);
|
|
159
157
|
return yargs;
|
|
160
|
-
}
|
|
158
|
+
}
|
|
159
|
+
exports.builder = (0, yargsUtils_1.makeYargsBuilder)(authBuilder, exports.command, (0, lang_1.i18n)(`${i18nKey}.verboseDescribe`, {
|
|
160
|
+
authMethod: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
161
|
+
configName: config_1.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
162
|
+
}), {
|
|
163
|
+
useGlobalOptions: true,
|
|
164
|
+
useConfigOptions: true,
|
|
165
|
+
useTestingOptions: true,
|
|
166
|
+
});
|
package/commands/init.d.ts
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
+
import { ArgumentsCamelCase, Argv } from 'yargs';
|
|
2
|
+
import { ConfigArgs, CommonArgs, TestingArgs, AccountArgs } from '../types/Yargs';
|
|
3
|
+
export declare const command = "init";
|
|
4
|
+
export declare const describe: string;
|
|
5
|
+
type InitArgs = CommonArgs & ConfigArgs & TestingArgs & AccountArgs & {
|
|
6
|
+
authType?: string;
|
|
7
|
+
'disable-tracking'?: boolean;
|
|
8
|
+
'use-hidden-config'?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function handler(args: ArgumentsCamelCase<InitArgs>): Promise<void>;
|
|
11
|
+
export declare const builder: (yargs: Argv) => Promise<Argv<InitArgs>>;
|
|
1
12
|
export {};
|
package/commands/init.js
CHANGED
|
@@ -1,156 +1,164 @@
|
|
|
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
|
-
const
|
|
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
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
6
|
+
exports.builder = exports.describe = exports.command = void 0;
|
|
7
|
+
exports.handler = handler;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
11
|
+
const auth_1 = require("@hubspot/local-dev-lib/constants/auth");
|
|
12
|
+
const gitignore_1 = require("@hubspot/local-dev-lib/gitignore");
|
|
13
|
+
const config_2 = require("@hubspot/local-dev-lib/constants/config");
|
|
14
|
+
const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
|
|
15
|
+
const path_2 = require("@hubspot/local-dev-lib/path");
|
|
16
|
+
const text_1 = require("@hubspot/local-dev-lib/text");
|
|
17
|
+
const environments_1 = require("@hubspot/local-dev-lib/constants/environments");
|
|
18
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
19
|
+
const getAccountIdentifier_1 = require("@hubspot/local-dev-lib/config/getAccountIdentifier");
|
|
20
|
+
const commonOpts_1 = require("../lib/commonOpts");
|
|
21
|
+
const yargsUtils_1 = require("../lib/yargsUtils");
|
|
22
|
+
const process_1 = require("../lib/process");
|
|
23
|
+
const index_1 = require("../lib/errorHandlers/index");
|
|
24
|
+
const lang_1 = require("../lib/lang");
|
|
25
|
+
const usageTracking_1 = require("../lib/usageTracking");
|
|
26
|
+
const promptUtils_1 = require("../lib/prompts/promptUtils");
|
|
27
|
+
const personalAccessKeyPrompt_1 = require("../lib/prompts/personalAccessKeyPrompt");
|
|
28
|
+
const accountNamePrompt_1 = require("../lib/prompts/accountNamePrompt");
|
|
29
|
+
const oauth_1 = require("../lib/oauth");
|
|
30
|
+
const exitCodes_1 = require("../lib/enums/exitCodes");
|
|
31
|
+
const ui_1 = require("../lib/ui");
|
|
27
32
|
const i18nKey = 'commands.init';
|
|
28
33
|
const TRACKING_STATUS = {
|
|
29
34
|
STARTED: 'started',
|
|
30
35
|
ERROR: 'error',
|
|
31
36
|
COMPLETE: 'complete',
|
|
32
37
|
};
|
|
33
|
-
|
|
34
|
-
const { personalAccessKey } = await personalAccessKeyPrompt({ env, account });
|
|
38
|
+
async function personalAccessKeyConfigCreationFlow(env, account) {
|
|
39
|
+
const { personalAccessKey } = await (0, personalAccessKeyPrompt_1.personalAccessKeyPrompt)({ env, account });
|
|
35
40
|
let updatedConfig;
|
|
36
41
|
try {
|
|
37
|
-
const token = await getAccessToken(personalAccessKey, env);
|
|
38
|
-
const defaultName = token.hubName ? toKebabCase(token.hubName) :
|
|
39
|
-
const { name } = await cliAccountNamePrompt(defaultName);
|
|
40
|
-
updatedConfig = updateConfigWithAccessToken(token, personalAccessKey, env, name, true);
|
|
42
|
+
const token = await (0, personalAccessKey_1.getAccessToken)(personalAccessKey, env);
|
|
43
|
+
const defaultName = token.hubName ? (0, text_1.toKebabCase)(token.hubName) : undefined;
|
|
44
|
+
const { name } = await (0, accountNamePrompt_1.cliAccountNamePrompt)(defaultName);
|
|
45
|
+
updatedConfig = await (0, personalAccessKey_1.updateConfigWithAccessToken)(token, personalAccessKey, env, name, true);
|
|
41
46
|
}
|
|
42
47
|
catch (e) {
|
|
43
|
-
logError(e);
|
|
48
|
+
(0, index_1.logError)(e);
|
|
44
49
|
}
|
|
45
50
|
return updatedConfig;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const configData = await promptUser(OAUTH_FLOW);
|
|
51
|
+
}
|
|
52
|
+
async function oauthConfigCreationFlow(env) {
|
|
53
|
+
const configData = await (0, promptUtils_1.promptUser)(personalAccessKeyPrompt_1.OAUTH_FLOW);
|
|
49
54
|
const accountConfig = {
|
|
50
55
|
...configData,
|
|
51
56
|
env,
|
|
52
57
|
};
|
|
53
|
-
await authenticateWithOauth(accountConfig);
|
|
54
|
-
updateDefaultAccount(accountConfig.name);
|
|
58
|
+
await (0, oauth_1.authenticateWithOauth)(accountConfig);
|
|
59
|
+
(0, config_1.updateDefaultAccount)(accountConfig.name);
|
|
55
60
|
return accountConfig;
|
|
56
|
-
}
|
|
57
|
-
const CONFIG_CREATION_FLOWS = {
|
|
58
|
-
[PERSONAL_ACCESS_KEY_AUTH_METHOD.value]: personalAccessKeyConfigCreationFlow,
|
|
59
|
-
[OAUTH_AUTH_METHOD.value]: oauthConfigCreationFlow,
|
|
60
|
-
};
|
|
61
|
+
}
|
|
61
62
|
const AUTH_TYPE_NAMES = {
|
|
62
|
-
[PERSONAL_ACCESS_KEY_AUTH_METHOD.value]: PERSONAL_ACCESS_KEY_AUTH_METHOD.name,
|
|
63
|
-
[OAUTH_AUTH_METHOD.value]: OAUTH_AUTH_METHOD.name,
|
|
63
|
+
[auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value]: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.name,
|
|
64
|
+
[auth_1.OAUTH_AUTH_METHOD.value]: auth_1.OAUTH_AUTH_METHOD.name,
|
|
64
65
|
};
|
|
65
66
|
exports.command = 'init';
|
|
66
|
-
exports.describe = i18n(`${i18nKey}.describe
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
exports.handler = async (options) => {
|
|
70
|
-
const { authType: authTypeFlagValue, c: configFlagValue, providedAccountId, disableTracking, useHiddenConfig, } = options;
|
|
67
|
+
exports.describe = (0, lang_1.i18n)(`${i18nKey}.describe`);
|
|
68
|
+
async function handler(args) {
|
|
69
|
+
const { authType: authTypeFlagValue, c: configFlagValue, providedAccountId, disableTracking, useHiddenConfig, } = args;
|
|
71
70
|
const authType = (authTypeFlagValue && authTypeFlagValue.toLowerCase()) ||
|
|
72
|
-
PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
|
|
73
|
-
const configPath = (configFlagValue &&
|
|
74
|
-
getConfigPath('', useHiddenConfig);
|
|
75
|
-
setLogLevel(
|
|
71
|
+
auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value;
|
|
72
|
+
const configPath = (configFlagValue && path_1.default.join((0, path_2.getCwd)(), configFlagValue)) ||
|
|
73
|
+
(0, config_1.getConfigPath)('', useHiddenConfig);
|
|
74
|
+
(0, commonOpts_1.setLogLevel)(args);
|
|
76
75
|
if (!disableTracking) {
|
|
77
|
-
trackCommandUsage('init', {
|
|
76
|
+
(0, usageTracking_1.trackCommandUsage)('init', {
|
|
78
77
|
authType,
|
|
79
78
|
});
|
|
80
79
|
}
|
|
81
|
-
const env =
|
|
82
|
-
if (
|
|
83
|
-
logger.error(i18n(`${i18nKey}.errors.configFileExists`, {
|
|
84
|
-
configPath,
|
|
80
|
+
const env = args.qa ? environments_1.ENVIRONMENTS.QA : environments_1.ENVIRONMENTS.PROD;
|
|
81
|
+
if (fs_extra_1.default.existsSync(configPath)) {
|
|
82
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.configFileExists`, {
|
|
83
|
+
configPath: configPath,
|
|
85
84
|
}));
|
|
86
|
-
logger.info(i18n(`${i18nKey}.logs.updateConfig`));
|
|
87
|
-
process.exit(EXIT_CODES.ERROR);
|
|
85
|
+
logger_1.logger.info((0, lang_1.i18n)(`${i18nKey}.logs.updateConfig`));
|
|
86
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
88
87
|
}
|
|
89
88
|
if (!disableTracking) {
|
|
90
|
-
await trackAuthAction('init', authType, TRACKING_STATUS.STARTED);
|
|
89
|
+
await (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.STARTED, providedAccountId);
|
|
91
90
|
}
|
|
92
|
-
const doesOtherConfigFileExist = configFileExists(!useHiddenConfig);
|
|
91
|
+
const doesOtherConfigFileExist = (0, config_1.configFileExists)(!useHiddenConfig);
|
|
93
92
|
if (doesOtherConfigFileExist) {
|
|
94
|
-
const path = getConfigPath('', !useHiddenConfig);
|
|
95
|
-
logger.error(i18n(`${i18nKey}.errors.bothConfigFilesNotAllowed`, { path }));
|
|
96
|
-
process.exit(EXIT_CODES.ERROR);
|
|
93
|
+
const path = (0, config_1.getConfigPath)('', !useHiddenConfig);
|
|
94
|
+
logger_1.logger.error((0, lang_1.i18n)(`${i18nKey}.errors.bothConfigFilesNotAllowed`, { path: path }));
|
|
95
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
97
96
|
}
|
|
98
|
-
trackAuthAction('init', authType, TRACKING_STATUS.STARTED);
|
|
99
|
-
createEmptyConfigFile({ path: configPath }, useHiddenConfig);
|
|
97
|
+
(0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.STARTED, providedAccountId);
|
|
98
|
+
(0, config_1.createEmptyConfigFile)({ path: configPath }, useHiddenConfig);
|
|
100
99
|
//Needed to load deprecated config
|
|
101
|
-
loadConfig(configPath,
|
|
102
|
-
handleExit(deleteEmptyConfigFile);
|
|
100
|
+
(0, config_1.loadConfig)(configPath, args);
|
|
101
|
+
(0, process_1.handleExit)(config_1.deleteEmptyConfigFile);
|
|
103
102
|
try {
|
|
104
|
-
|
|
103
|
+
let accountId;
|
|
104
|
+
let name;
|
|
105
|
+
if (authType === auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value) {
|
|
106
|
+
const personalAccessKeyResult = await personalAccessKeyConfigCreationFlow(env, providedAccountId);
|
|
107
|
+
if (personalAccessKeyResult) {
|
|
108
|
+
accountId = (0, getAccountIdentifier_1.getAccountIdentifier)(personalAccessKeyResult);
|
|
109
|
+
name = personalAccessKeyResult.name;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const oauthResult = await oauthConfigCreationFlow(env);
|
|
114
|
+
accountId = oauthResult.accountId;
|
|
115
|
+
name = oauthResult.name;
|
|
116
|
+
}
|
|
105
117
|
try {
|
|
106
|
-
checkAndAddConfigToGitignore(configPath);
|
|
118
|
+
(0, gitignore_1.checkAndAddConfigToGitignore)(configPath);
|
|
107
119
|
}
|
|
108
120
|
catch (e) {
|
|
109
|
-
debugError(e);
|
|
121
|
+
(0, index_1.debugError)(e);
|
|
110
122
|
}
|
|
111
123
|
let newConfigPath = configPath;
|
|
112
124
|
if (!newConfigPath && !useHiddenConfig) {
|
|
113
|
-
newConfigPath = `${getCwd()}/${DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}`;
|
|
125
|
+
newConfigPath = `${(0, path_2.getCwd)()}/${config_2.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME}`;
|
|
114
126
|
}
|
|
115
|
-
logger.log('');
|
|
116
|
-
logger.success(i18n(`${i18nKey}.success.configFileCreated`, {
|
|
127
|
+
logger_1.logger.log('');
|
|
128
|
+
logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.success.configFileCreated`, {
|
|
117
129
|
configPath: newConfigPath,
|
|
118
130
|
}));
|
|
119
|
-
logger.success(i18n(`${i18nKey}.success.configFileUpdated`, {
|
|
131
|
+
logger_1.logger.success((0, lang_1.i18n)(`${i18nKey}.success.configFileUpdated`, {
|
|
120
132
|
authType: AUTH_TYPE_NAMES[authType],
|
|
121
133
|
account: name || accountId,
|
|
122
134
|
}));
|
|
123
|
-
uiFeatureHighlight(['helpCommand', 'authCommand', 'accountsListCommand']);
|
|
135
|
+
(0, ui_1.uiFeatureHighlight)(['helpCommand', 'authCommand', 'accountsListCommand']);
|
|
124
136
|
if (!disableTracking) {
|
|
125
|
-
await trackAuthAction('init', authType, TRACKING_STATUS.COMPLETE, accountId);
|
|
137
|
+
await (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.COMPLETE, accountId);
|
|
126
138
|
}
|
|
127
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
139
|
+
process.exit(exitCodes_1.EXIT_CODES.SUCCESS);
|
|
128
140
|
}
|
|
129
141
|
catch (err) {
|
|
130
|
-
logError(err);
|
|
142
|
+
(0, index_1.logError)(err);
|
|
131
143
|
if (!disableTracking) {
|
|
132
|
-
await trackAuthAction('init', authType, TRACKING_STATUS.ERROR);
|
|
144
|
+
await (0, usageTracking_1.trackAuthAction)('init', authType, TRACKING_STATUS.ERROR, providedAccountId);
|
|
133
145
|
}
|
|
134
|
-
process.exit(EXIT_CODES.ERROR);
|
|
146
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
135
147
|
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
yargs
|
|
139
|
-
.options({
|
|
148
|
+
}
|
|
149
|
+
function initBuilder(yargs) {
|
|
150
|
+
yargs.options({
|
|
140
151
|
'auth-type': {
|
|
141
|
-
describe: i18n(`${i18nKey}.options.authType.describe`),
|
|
152
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.authType.describe`),
|
|
142
153
|
type: 'string',
|
|
143
154
|
choices: [
|
|
144
|
-
`${PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
|
|
145
|
-
`${OAUTH_AUTH_METHOD.value}`,
|
|
155
|
+
`${auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value}`,
|
|
156
|
+
`${auth_1.OAUTH_AUTH_METHOD.value}`,
|
|
146
157
|
],
|
|
147
|
-
default: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
148
|
-
defaultDescription: i18n(`${i18nKey}.options.authType.defaultDescription`, {
|
|
149
|
-
authMethod: PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
150
|
-
}),
|
|
158
|
+
default: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
151
159
|
},
|
|
152
160
|
account: {
|
|
153
|
-
describe: i18n(`${i18nKey}.options.account.describe`),
|
|
161
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.account.describe`),
|
|
154
162
|
type: 'string',
|
|
155
163
|
alias: 'a',
|
|
156
164
|
},
|
|
@@ -160,14 +168,20 @@ exports.builder = yargs => {
|
|
|
160
168
|
default: false,
|
|
161
169
|
},
|
|
162
170
|
'use-hidden-config': {
|
|
163
|
-
describe: i18n(`${i18nKey}.options.useHiddenConfig.describe`),
|
|
171
|
+
describe: (0, lang_1.i18n)(`${i18nKey}.options.useHiddenConfig.describe`),
|
|
164
172
|
hidden: true,
|
|
165
173
|
type: 'boolean',
|
|
166
174
|
},
|
|
167
|
-
})
|
|
168
|
-
|
|
169
|
-
addConfigOptions(yargs);
|
|
170
|
-
addTestingOptions(yargs);
|
|
171
|
-
addGlobalOptions(yargs);
|
|
175
|
+
});
|
|
176
|
+
yargs.conflicts('use-hidden-config', 'config');
|
|
172
177
|
return yargs;
|
|
173
|
-
}
|
|
178
|
+
}
|
|
179
|
+
exports.builder = (0, yargsUtils_1.makeYargsBuilder)(initBuilder, exports.command, (0, lang_1.i18n)(`${i18nKey}.verboseDescribe`, {
|
|
180
|
+
command: (0, ui_1.uiCommandReference)('hs auth'),
|
|
181
|
+
configName: config_2.DEFAULT_HUBSPOT_CONFIG_YAML_FILE_NAME,
|
|
182
|
+
authMethod: auth_1.PERSONAL_ACCESS_KEY_AUTH_METHOD.value,
|
|
183
|
+
}), {
|
|
184
|
+
useGlobalOptions: true,
|
|
185
|
+
useConfigOptions: true,
|
|
186
|
+
useTestingOptions: true,
|
|
187
|
+
});
|
package/commands/list.d.ts
CHANGED
|
@@ -1 +1,10 @@
|
|
|
1
|
+
import { Argv, ArgumentsCamelCase } from 'yargs';
|
|
2
|
+
import { AccountArgs, CommonArgs, ConfigArgs, EnvironmentArgs } from '../types/Yargs';
|
|
3
|
+
export declare const command = "list [path]";
|
|
4
|
+
export declare const describe: string;
|
|
5
|
+
type ListArgs = CommonArgs & ConfigArgs & EnvironmentArgs & AccountArgs & {
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function handler(args: ArgumentsCamelCase<ListArgs>): Promise<void>;
|
|
9
|
+
export declare function builder(yargs: Argv): Argv<ListArgs>;
|
|
1
10
|
export {};
|