@hubspot/cli 7.3.0 → 7.4.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/api/migrate.d.ts +61 -0
- package/api/migrate.js +44 -0
- package/bin/cli.js +10 -183
- package/commands/account/auth.d.ts +10 -0
- package/commands/account/auth.js +168 -0
- package/commands/account/clean.js +38 -5
- package/commands/account/createOverride.d.ts +10 -0
- package/commands/account/createOverride.js +104 -0
- package/commands/account/info.js +38 -4
- package/commands/account/list.js +23 -5
- package/commands/account/remove.js +36 -2
- package/commands/account/removeOverride.d.ts +10 -0
- package/commands/account/removeOverride.js +76 -0
- package/commands/account/use.js +25 -3
- package/commands/account.js +7 -2
- package/commands/app/migrate.d.ts +7 -0
- package/commands/app/migrate.js +95 -0
- package/commands/app.d.ts +6 -0
- package/commands/app.js +23 -0
- package/commands/auth.js +6 -2
- package/commands/cms/lighthouseScore.js +6 -2
- package/commands/config/migrate.d.ts +10 -0
- package/commands/config/migrate.js +84 -0
- package/commands/config/set.d.ts +10 -0
- package/commands/config/set.js +34 -29
- package/commands/config.d.ts +4 -1
- package/commands/config.js +45 -11
- package/commands/create/api-sample.js +3 -1
- package/commands/customObject/schema/delete.js +4 -1
- package/commands/customObject/schema/fetch-all.js +2 -1
- package/commands/customObject/schema/fetch.js +2 -1
- package/commands/init.js +9 -10
- package/commands/project/cloneApp.d.ts +9 -1
- package/commands/project/cloneApp.js +91 -76
- package/commands/project/migrateApp.d.ts +9 -1
- package/commands/project/migrateApp.js +43 -170
- package/commands/project/watch.js +12 -0
- package/lang/en.js +5 -2
- package/lang/en.lyaml +121 -10
- package/lib/app/migrate.d.ts +5 -0
- package/lib/app/migrate.js +242 -0
- package/lib/app/migrate_legacy.d.ts +4 -0
- package/lib/app/migrate_legacy.js +129 -0
- package/lib/configMigrate.d.ts +2 -0
- package/lib/configMigrate.js +104 -0
- package/lib/doctor/Diagnosis.d.ts +1 -2
- package/lib/doctor/Diagnosis.js +10 -6
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +1 -0
- package/lib/doctor/DiagnosticInfoBuilder.js +1 -0
- package/lib/doctor/Doctor.d.ts +1 -0
- package/lib/doctor/Doctor.js +18 -0
- package/lib/middleware/__test__/configMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/configMiddleware.test.js +194 -0
- package/lib/middleware/__test__/gitMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/gitMiddleware.test.js +76 -0
- package/lib/middleware/__test__/notificationsMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/notificationsMiddleware.test.js +10 -0
- package/lib/middleware/__test__/requestMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/requestMiddleware.test.js +20 -0
- package/lib/middleware/__test__/utils.test.d.ts +1 -0
- package/lib/middleware/__test__/utils.test.js +53 -0
- package/lib/middleware/__test__/yargsChecksMiddleware.test.d.ts +1 -0
- package/lib/middleware/__test__/yargsChecksMiddleware.test.js +81 -0
- package/lib/middleware/configMiddleware.d.ts +13 -0
- package/lib/middleware/configMiddleware.js +109 -0
- package/lib/middleware/fireAlarmMiddleware.d.ts +4 -0
- package/lib/middleware/fireAlarmMiddleware.js +137 -0
- package/lib/middleware/gitMiddleware.d.ts +2 -0
- package/lib/middleware/gitMiddleware.js +14 -0
- package/lib/middleware/notificationsMiddleware.d.ts +1 -0
- package/lib/middleware/notificationsMiddleware.js +38 -0
- package/lib/middleware/requestMiddleware.d.ts +1 -0
- package/lib/middleware/requestMiddleware.js +11 -0
- package/lib/middleware/utils.d.ts +8 -0
- package/lib/middleware/utils.js +17 -0
- package/lib/middleware/yargsChecksMiddleware.d.ts +4 -0
- package/lib/middleware/yargsChecksMiddleware.js +24 -0
- package/lib/polling.d.ts +4 -0
- package/lib/polling.js +3 -3
- package/lib/prompts/promptUtils.d.ts +6 -4
- package/lib/prompts/promptUtils.js +3 -1
- package/lib/ui/SpinniesManager.d.ts +1 -1
- package/lib/ui/index.d.ts +3 -2
- package/lib/ui/index.js +11 -5
- package/lib/ui/spinniesUtils.d.ts +5 -5
- package/package.json +7 -6
- package/types/Prompts.d.ts +2 -2
- package/types/Yargs.d.ts +10 -0
|
@@ -0,0 +1,194 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
37
|
+
const cliConfig = __importStar(require("@hubspot/local-dev-lib/config"));
|
|
38
|
+
const validation = __importStar(require("../../validation"));
|
|
39
|
+
const exitCodes_1 = require("../../enums/exitCodes");
|
|
40
|
+
const configMiddleware_1 = require("../configMiddleware");
|
|
41
|
+
jest.mock('@hubspot/local-dev-lib/logger', () => ({
|
|
42
|
+
logger: {
|
|
43
|
+
error: jest.fn(),
|
|
44
|
+
log: jest.fn(),
|
|
45
|
+
},
|
|
46
|
+
}));
|
|
47
|
+
jest.mock('@hubspot/local-dev-lib/config');
|
|
48
|
+
jest.mock('../../validation');
|
|
49
|
+
const validateAccountSpy = jest.spyOn(validation, 'validateAccount');
|
|
50
|
+
const loadConfigSpy = jest.spyOn(cliConfig, 'loadConfig');
|
|
51
|
+
const getAccountIdSpy = jest.spyOn(cliConfig, 'getAccountId');
|
|
52
|
+
const configFileExistsSpy = jest.spyOn(cliConfig, 'configFileExists');
|
|
53
|
+
const getConfigPathSpy = jest.spyOn(cliConfig, 'getConfigPath');
|
|
54
|
+
const validateConfigSpy = jest.spyOn(cliConfig, 'validateConfig');
|
|
55
|
+
const processExitSpy = jest.spyOn(process, 'exit');
|
|
56
|
+
describe('lib/middleware/configMiddleware', () => {
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
processExitSpy.mockImplementation(code => {
|
|
59
|
+
throw new Error(`Process.exit called with code ${code}`);
|
|
60
|
+
});
|
|
61
|
+
getConfigPathSpy.mockReturnValue('/path/to/config');
|
|
62
|
+
});
|
|
63
|
+
describe('handleDeprecatedEnvVariables()', () => {
|
|
64
|
+
it('should handle deprecated HUBSPOT_PORTAL_ID environment variable', () => {
|
|
65
|
+
const originalEnv = process.env;
|
|
66
|
+
process.env = {
|
|
67
|
+
...originalEnv,
|
|
68
|
+
HUBSPOT_PORTAL_ID: '123',
|
|
69
|
+
HUBSPOT_ACCOUNT_ID: undefined,
|
|
70
|
+
};
|
|
71
|
+
const argv = {
|
|
72
|
+
_: ['some-command'],
|
|
73
|
+
useEnv: true,
|
|
74
|
+
$0: 'hs',
|
|
75
|
+
};
|
|
76
|
+
(0, configMiddleware_1.handleDeprecatedEnvVariables)(argv);
|
|
77
|
+
expect(logger_1.logger.log).toHaveBeenCalledWith(expect.stringContaining('The HUBSPOT_PORTAL_ID environment variable is deprecated. Please use HUBSPOT_ACCOUNT_ID instead.'));
|
|
78
|
+
expect(process.env.HUBSPOT_ACCOUNT_ID).toBe('123');
|
|
79
|
+
process.env = originalEnv;
|
|
80
|
+
});
|
|
81
|
+
it('should not handle HUBSPOT_PORTAL_ID if HUBSPOT_ACCOUNT_ID is set', () => {
|
|
82
|
+
const originalEnv = process.env;
|
|
83
|
+
process.env = {
|
|
84
|
+
...originalEnv,
|
|
85
|
+
HUBSPOT_PORTAL_ID: '123',
|
|
86
|
+
HUBSPOT_ACCOUNT_ID: '456',
|
|
87
|
+
};
|
|
88
|
+
const argv = {
|
|
89
|
+
_: ['some-command'],
|
|
90
|
+
useEnv: true,
|
|
91
|
+
$0: 'hs',
|
|
92
|
+
};
|
|
93
|
+
(0, configMiddleware_1.handleDeprecatedEnvVariables)(argv);
|
|
94
|
+
expect(logger_1.logger.log).not.toHaveBeenCalled();
|
|
95
|
+
expect(process.env.HUBSPOT_ACCOUNT_ID).toBe('456');
|
|
96
|
+
process.env = originalEnv;
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('injectAccountIdMiddleware()', () => {
|
|
100
|
+
it('should use HUBSPOT_ACCOUNT_ID from environment when useEnv is true', async () => {
|
|
101
|
+
const originalEnv = process.env;
|
|
102
|
+
process.env = {
|
|
103
|
+
...originalEnv,
|
|
104
|
+
HUBSPOT_ACCOUNT_ID: '123',
|
|
105
|
+
};
|
|
106
|
+
const argv = {
|
|
107
|
+
_: ['some-command'],
|
|
108
|
+
useEnv: true,
|
|
109
|
+
$0: 'hs',
|
|
110
|
+
};
|
|
111
|
+
await (0, configMiddleware_1.injectAccountIdMiddleware)(argv);
|
|
112
|
+
expect(argv.providedAccountId).toBeUndefined();
|
|
113
|
+
expect(argv.derivedAccountId).toBe(123);
|
|
114
|
+
expect(getAccountIdSpy).not.toHaveBeenCalled();
|
|
115
|
+
process.env = originalEnv;
|
|
116
|
+
});
|
|
117
|
+
it('should use getAccountId when useEnv is false', async () => {
|
|
118
|
+
getAccountIdSpy.mockReturnValue(456);
|
|
119
|
+
const argv = {
|
|
120
|
+
_: ['some-command'],
|
|
121
|
+
account: 'test-account',
|
|
122
|
+
useEnv: false,
|
|
123
|
+
$0: 'hs',
|
|
124
|
+
};
|
|
125
|
+
await (0, configMiddleware_1.injectAccountIdMiddleware)(argv);
|
|
126
|
+
expect(argv.providedAccountId).toBe('test-account');
|
|
127
|
+
expect(argv.derivedAccountId).toBe(456);
|
|
128
|
+
expect(getAccountIdSpy).toHaveBeenCalledWith('test-account');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
describe('loadConfigMiddleware()', () => {
|
|
132
|
+
it('should exit with error when config file exists and --config flag is used', async () => {
|
|
133
|
+
configFileExistsSpy.mockReturnValue(true);
|
|
134
|
+
const argv = {
|
|
135
|
+
_: ['some-command'],
|
|
136
|
+
config: 'custom-config.json',
|
|
137
|
+
$0: 'hs',
|
|
138
|
+
};
|
|
139
|
+
await expect((0, configMiddleware_1.loadConfigMiddleware)(argv)).rejects.toThrow();
|
|
140
|
+
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
141
|
+
expect(logger_1.logger.error).toHaveBeenCalledWith('A configuration file already exists at /path/to/config. To specify a new configuration file, delete the existing one and try again.');
|
|
142
|
+
});
|
|
143
|
+
it('should load config and validate for non-init commands', async () => {
|
|
144
|
+
configFileExistsSpy.mockReturnValue(false);
|
|
145
|
+
loadConfigSpy.mockReturnValue({});
|
|
146
|
+
validateConfigSpy.mockReturnValue(true);
|
|
147
|
+
const argv = {
|
|
148
|
+
_: ['some-command'],
|
|
149
|
+
$0: 'hs',
|
|
150
|
+
};
|
|
151
|
+
await (0, configMiddleware_1.loadConfigMiddleware)(argv);
|
|
152
|
+
expect(loadConfigSpy).toHaveBeenCalled();
|
|
153
|
+
expect(validateConfigSpy).toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
it('should skip validation for init command', async () => {
|
|
156
|
+
configFileExistsSpy.mockReturnValue(false);
|
|
157
|
+
const argv = {
|
|
158
|
+
_: ['init'],
|
|
159
|
+
$0: 'hs',
|
|
160
|
+
};
|
|
161
|
+
await (0, configMiddleware_1.loadConfigMiddleware)(argv);
|
|
162
|
+
expect(loadConfigSpy).not.toHaveBeenCalled();
|
|
163
|
+
expect(validateConfigSpy).not.toHaveBeenCalled();
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
describe('validateAccountOptions()', () => {
|
|
167
|
+
it('should validate account for non-skipped commands', async () => {
|
|
168
|
+
validateAccountSpy.mockResolvedValue(true);
|
|
169
|
+
const argv = {
|
|
170
|
+
_: ['some-command'],
|
|
171
|
+
$0: 'hs',
|
|
172
|
+
};
|
|
173
|
+
await (0, configMiddleware_1.validateAccountOptions)(argv);
|
|
174
|
+
expect(validateAccountSpy).toHaveBeenCalledWith(argv);
|
|
175
|
+
});
|
|
176
|
+
it('should skip validation for init command', async () => {
|
|
177
|
+
const argv = {
|
|
178
|
+
_: ['init'],
|
|
179
|
+
$0: 'hs',
|
|
180
|
+
};
|
|
181
|
+
await (0, configMiddleware_1.validateAccountOptions)(argv);
|
|
182
|
+
expect(validateAccountSpy).not.toHaveBeenCalled();
|
|
183
|
+
});
|
|
184
|
+
it('should exit with error when account validation fails', async () => {
|
|
185
|
+
validateAccountSpy.mockResolvedValue(false);
|
|
186
|
+
const argv = {
|
|
187
|
+
_: ['some-command'],
|
|
188
|
+
$0: 'hs',
|
|
189
|
+
};
|
|
190
|
+
await expect((0, configMiddleware_1.validateAccountOptions)(argv)).rejects.toThrow();
|
|
191
|
+
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const config = __importStar(require("@hubspot/local-dev-lib/config"));
|
|
37
|
+
const gitUI = __importStar(require("../../ui/git"));
|
|
38
|
+
const gitMiddleware_1 = require("../gitMiddleware");
|
|
39
|
+
jest.mock('@hubspot/local-dev-lib/config');
|
|
40
|
+
jest.mock('../../ui/git');
|
|
41
|
+
const getConfigPathSpy = jest.spyOn(config, 'getConfigPath');
|
|
42
|
+
const checkAndWarnGitInclusionSpy = jest.spyOn(gitUI, 'checkAndWarnGitInclusion');
|
|
43
|
+
describe('lib/middleware/gitMiddleware', () => {
|
|
44
|
+
describe('checkAndWarnGitInclusionMiddleware()', () => {
|
|
45
|
+
it('should call checkAndWarnGitInclusion when command is provided and config path exists', () => {
|
|
46
|
+
const mockConfigPath = '/path/to/config';
|
|
47
|
+
getConfigPathSpy.mockReturnValue(mockConfigPath);
|
|
48
|
+
const argv = {
|
|
49
|
+
_: ['some-command'],
|
|
50
|
+
$0: 'hs',
|
|
51
|
+
};
|
|
52
|
+
(0, gitMiddleware_1.checkAndWarnGitInclusionMiddleware)(argv);
|
|
53
|
+
expect(getConfigPathSpy).toHaveBeenCalledTimes(1);
|
|
54
|
+
expect(checkAndWarnGitInclusionSpy).toHaveBeenCalledWith(mockConfigPath);
|
|
55
|
+
});
|
|
56
|
+
it('should not call checkAndWarnGitInclusion when no command is provided', () => {
|
|
57
|
+
const argv = {
|
|
58
|
+
_: [],
|
|
59
|
+
$0: 'hs',
|
|
60
|
+
};
|
|
61
|
+
(0, gitMiddleware_1.checkAndWarnGitInclusionMiddleware)(argv);
|
|
62
|
+
expect(getConfigPathSpy).not.toHaveBeenCalled();
|
|
63
|
+
expect(checkAndWarnGitInclusionSpy).not.toHaveBeenCalled();
|
|
64
|
+
});
|
|
65
|
+
it('should not call checkAndWarnGitInclusion when config path is null', () => {
|
|
66
|
+
getConfigPathSpy.mockReturnValue(null);
|
|
67
|
+
const argv = {
|
|
68
|
+
_: ['some-command'],
|
|
69
|
+
$0: 'hs',
|
|
70
|
+
};
|
|
71
|
+
(0, gitMiddleware_1.checkAndWarnGitInclusionMiddleware)(argv);
|
|
72
|
+
expect(getConfigPathSpy).toHaveBeenCalledTimes(1);
|
|
73
|
+
expect(checkAndWarnGitInclusionSpy).not.toHaveBeenCalled();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { notifyAboutUpdates } = require('../notificationsMiddleware');
|
|
4
|
+
describe('lib/middleware/notificationsMiddleware', () => {
|
|
5
|
+
describe('notifyAboutUpdates()', () => {
|
|
6
|
+
it('should safely execute without throwing an error', () => {
|
|
7
|
+
expect(() => notifyAboutUpdates()).not.toThrow();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const http_1 = require("@hubspot/local-dev-lib/http");
|
|
7
|
+
const requestMiddleware_1 = require("../requestMiddleware");
|
|
8
|
+
const package_json_1 = __importDefault(require("../../../package.json"));
|
|
9
|
+
jest.mock('@hubspot/local-dev-lib/http', () => ({
|
|
10
|
+
addUserAgentHeader: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
describe('lib/middleware/requestMiddleware', () => {
|
|
13
|
+
describe('setRequestHeaders()', () => {
|
|
14
|
+
it('should call addUserAgentHeader with correct parameters', () => {
|
|
15
|
+
(0, requestMiddleware_1.setRequestHeaders)();
|
|
16
|
+
expect(http_1.addUserAgentHeader).toHaveBeenCalledTimes(1);
|
|
17
|
+
expect(http_1.addUserAgentHeader).toHaveBeenCalledWith('HubSpot CLI', package_json_1.default.version);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("../utils");
|
|
4
|
+
const targetCommandMap = {
|
|
5
|
+
init: { target: true },
|
|
6
|
+
account: {
|
|
7
|
+
target: true,
|
|
8
|
+
subCommands: {
|
|
9
|
+
use: { target: true },
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
project: {
|
|
13
|
+
subCommands: {
|
|
14
|
+
deploy: { target: true },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
describe('lib/middleware/utils', () => {
|
|
19
|
+
describe('isTargetedCommand()', () => {
|
|
20
|
+
it('should return true for a direct target command', () => {
|
|
21
|
+
const result = (0, utils_1.isTargetedCommand)(['init'], targetCommandMap);
|
|
22
|
+
expect(result).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
it('should return true for a command with a subcommand', () => {
|
|
25
|
+
const result = (0, utils_1.isTargetedCommand)(['account'], targetCommandMap);
|
|
26
|
+
expect(result).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('should return true for a nested target command', () => {
|
|
29
|
+
const result = (0, utils_1.isTargetedCommand)(['project', 'deploy'], targetCommandMap);
|
|
30
|
+
expect(result).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
it('should return false for a non-existent command', () => {
|
|
33
|
+
const result = (0, utils_1.isTargetedCommand)(['nonexistent'], targetCommandMap);
|
|
34
|
+
expect(result).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
it('should return false for a non-targeted command', () => {
|
|
37
|
+
const result = (0, utils_1.isTargetedCommand)(['auth'], targetCommandMap);
|
|
38
|
+
expect(result).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
it('should return false for a command with a targeted subcommand', () => {
|
|
41
|
+
const result = (0, utils_1.isTargetedCommand)(['project'], targetCommandMap);
|
|
42
|
+
expect(result).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('should return false for a non-existent subcommand', () => {
|
|
45
|
+
const result = (0, utils_1.isTargetedCommand)(['auth', 'nonexistent'], targetCommandMap);
|
|
46
|
+
expect(result).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
it('should return false for an empty command array', () => {
|
|
49
|
+
const result = (0, utils_1.isTargetedCommand)([], targetCommandMap);
|
|
50
|
+
expect(result).toBe(false);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
37
|
+
const exitCodes_1 = require("../../enums/exitCodes");
|
|
38
|
+
const projects = __importStar(require("../../projects"));
|
|
39
|
+
const yargsChecksMiddleware_1 = require("../yargsChecksMiddleware");
|
|
40
|
+
jest.mock('@hubspot/local-dev-lib/logger', () => ({
|
|
41
|
+
logger: {
|
|
42
|
+
error: jest.fn(),
|
|
43
|
+
},
|
|
44
|
+
}));
|
|
45
|
+
jest.mock('../../projects');
|
|
46
|
+
jest.mock('../../lang', () => ({
|
|
47
|
+
i18n: jest.fn(key => key),
|
|
48
|
+
}));
|
|
49
|
+
const getIsInProjectSpy = jest.spyOn(projects, 'getIsInProject');
|
|
50
|
+
const processExitSpy = jest.spyOn(process, 'exit');
|
|
51
|
+
describe('lib/middleware/yargsChecksMiddleware', () => {
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
processExitSpy.mockImplementation(code => {
|
|
54
|
+
throw new Error(`Process.exit called with code ${code}`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('performChecks()', () => {
|
|
58
|
+
it('should exit with error when running upload/watch inside a project', () => {
|
|
59
|
+
const argv = {
|
|
60
|
+
_: ['upload'],
|
|
61
|
+
src: './project',
|
|
62
|
+
$0: 'hs',
|
|
63
|
+
};
|
|
64
|
+
getIsInProjectSpy.mockReturnValue(true);
|
|
65
|
+
expect(() => (0, yargsChecksMiddleware_1.performChecks)(argv)).toThrow();
|
|
66
|
+
expect(processExitSpy).toHaveBeenCalledWith(exitCodes_1.EXIT_CODES.ERROR);
|
|
67
|
+
expect(logger_1.logger.error).toHaveBeenCalledWith('commands.generalErrors.srcIsProject');
|
|
68
|
+
});
|
|
69
|
+
it('should return true when no checks fail', () => {
|
|
70
|
+
const argv = {
|
|
71
|
+
_: ['upload'],
|
|
72
|
+
src: './not-a-project',
|
|
73
|
+
$0: 'hs',
|
|
74
|
+
};
|
|
75
|
+
getIsInProjectSpy.mockReturnValue(false);
|
|
76
|
+
expect((0, yargsChecksMiddleware_1.performChecks)(argv)).toBe(true);
|
|
77
|
+
expect(processExitSpy).not.toHaveBeenCalled();
|
|
78
|
+
expect(logger_1.logger.error).not.toHaveBeenCalled();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Arguments } from 'yargs';
|
|
2
|
+
import { CLIOptions } from '@hubspot/local-dev-lib/types/CLIOptions';
|
|
3
|
+
export declare function handleDeprecatedEnvVariables(argv: Arguments<{
|
|
4
|
+
useEnv?: boolean;
|
|
5
|
+
}>): void;
|
|
6
|
+
/**
|
|
7
|
+
* Auto-injects the derivedAccountId flag into all commands
|
|
8
|
+
*/
|
|
9
|
+
export declare function injectAccountIdMiddleware(argv: Arguments<{
|
|
10
|
+
account?: string;
|
|
11
|
+
}>): Promise<void>;
|
|
12
|
+
export declare function loadConfigMiddleware(argv: Arguments<CLIOptions>): Promise<void>;
|
|
13
|
+
export declare function validateAccountOptions(argv: Arguments): Promise<void>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handleDeprecatedEnvVariables = handleDeprecatedEnvVariables;
|
|
4
|
+
exports.injectAccountIdMiddleware = injectAccountIdMiddleware;
|
|
5
|
+
exports.loadConfigMiddleware = loadConfigMiddleware;
|
|
6
|
+
exports.validateAccountOptions = validateAccountOptions;
|
|
7
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
8
|
+
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
9
|
+
const validation_1 = require("../validation");
|
|
10
|
+
const exitCodes_1 = require("../enums/exitCodes");
|
|
11
|
+
const lang_1 = require("../lang");
|
|
12
|
+
const ui_1 = require("../ui");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
function handleDeprecatedEnvVariables(argv) {
|
|
15
|
+
// HUBSPOT_PORTAL_ID is deprecated, but we'll still support it for now
|
|
16
|
+
// The HubSpot GH Deploy Action still uses HUBSPOT_PORTAL_ID
|
|
17
|
+
if (argv.useEnv &&
|
|
18
|
+
process.env.HUBSPOT_PORTAL_ID &&
|
|
19
|
+
!process.env.HUBSPOT_ACCOUNT_ID) {
|
|
20
|
+
(0, ui_1.uiDeprecatedTag)((0, lang_1.i18n)(`commands.generalErrors.handleDeprecatedEnvVariables.portalEnvVarDeprecated`, {
|
|
21
|
+
configPath: (0, config_1.getConfigPath)(),
|
|
22
|
+
}));
|
|
23
|
+
process.env.HUBSPOT_ACCOUNT_ID = process.env.HUBSPOT_PORTAL_ID;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Auto-injects the derivedAccountId flag into all commands
|
|
28
|
+
*/
|
|
29
|
+
async function injectAccountIdMiddleware(argv) {
|
|
30
|
+
const { account } = argv;
|
|
31
|
+
// Preserves the original --account flag for certain commands.
|
|
32
|
+
argv.providedAccountId = account;
|
|
33
|
+
if (argv.useEnv && process.env.HUBSPOT_ACCOUNT_ID) {
|
|
34
|
+
argv.derivedAccountId = parseInt(process.env.HUBSPOT_ACCOUNT_ID, 10);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
argv.derivedAccountId = (0, config_1.getAccountId)(account);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const SKIP_CONFIG_VALIDATION = {
|
|
41
|
+
init: { target: true },
|
|
42
|
+
auth: { target: true },
|
|
43
|
+
};
|
|
44
|
+
async function loadConfigMiddleware(argv) {
|
|
45
|
+
// Skip this when no command is provided
|
|
46
|
+
if (!argv._.length) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const maybeValidateConfig = () => {
|
|
50
|
+
if (!(0, utils_1.isTargetedCommand)(argv._, SKIP_CONFIG_VALIDATION) &&
|
|
51
|
+
!(0, config_1.validateConfig)()) {
|
|
52
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
if ((0, config_1.configFileExists)(true) &&
|
|
56
|
+
argv.config &&
|
|
57
|
+
!(0, utils_1.isTargetedCommand)(argv._, {
|
|
58
|
+
config: { target: false, subCommands: { migrate: { target: true } } },
|
|
59
|
+
})) {
|
|
60
|
+
logger_1.logger.error((0, lang_1.i18n)(`commands.generalErrors.loadConfigMiddleware.configFileExists`, {
|
|
61
|
+
configPath: (0, config_1.getConfigPath)(),
|
|
62
|
+
}));
|
|
63
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
64
|
+
}
|
|
65
|
+
else if (!(0, utils_1.isTargetedCommand)(argv._, { init: { target: true } })) {
|
|
66
|
+
const config = (0, config_1.loadConfig)(argv.config, argv);
|
|
67
|
+
// We don't run validateConfig() for auth because users should be able to run it when
|
|
68
|
+
// no accounts are configured, but we still want to exit if the config file is not found
|
|
69
|
+
if ((0, utils_1.isTargetedCommand)(argv._, { auth: { target: true } }) && !config) {
|
|
70
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
maybeValidateConfig();
|
|
74
|
+
}
|
|
75
|
+
const accountsSubCommands = {
|
|
76
|
+
target: false,
|
|
77
|
+
subCommands: {
|
|
78
|
+
clean: { target: true },
|
|
79
|
+
list: { target: true },
|
|
80
|
+
ls: { target: true },
|
|
81
|
+
remove: { target: true },
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
const sandboxesSubCommands = {
|
|
85
|
+
target: false,
|
|
86
|
+
subCommands: {
|
|
87
|
+
delete: { target: true },
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const SKIP_ACCOUNT_VALIDATION = {
|
|
91
|
+
init: { target: true },
|
|
92
|
+
auth: { target: true },
|
|
93
|
+
account: accountsSubCommands,
|
|
94
|
+
accounts: accountsSubCommands,
|
|
95
|
+
sandbox: sandboxesSubCommands,
|
|
96
|
+
sandboxes: sandboxesSubCommands,
|
|
97
|
+
};
|
|
98
|
+
async function validateAccountOptions(argv) {
|
|
99
|
+
// Skip this when no command is provided
|
|
100
|
+
if (argv._.length) {
|
|
101
|
+
let validAccount = true;
|
|
102
|
+
if (!(0, utils_1.isTargetedCommand)(argv._, SKIP_ACCOUNT_VALIDATION)) {
|
|
103
|
+
validAccount = await (0, validation_1.validateAccount)(argv);
|
|
104
|
+
}
|
|
105
|
+
if (!validAccount) {
|
|
106
|
+
process.exit(exitCodes_1.EXIT_CODES.ERROR);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|