@hubspot/cli 6.2.2-experimental.1 → 6.2.2-experimental.2
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 +2 -0
- package/commands/auth.js +0 -2
- package/commands/create/api-sample.js +2 -2
- package/commands/create.js +0 -2
- package/commands/doctor.d.ts +8 -0
- package/commands/doctor.js +60 -0
- package/commands/feedback.js +19 -4
- package/commands/functions/list.js +1 -1
- package/commands/init.js +20 -9
- package/commands/lint.d.ts +4 -1
- package/commands/lint.js +39 -3
- package/commands/module/marketplace-validate.js +1 -1
- package/commands/project/deploy.js +10 -3
- package/commands/project/installDeps.js +5 -5
- package/commands/project/logs.js +2 -2
- package/commands/sandbox/delete.js +5 -3
- package/commands/theme/generate-selectors.js +1 -1
- package/commands/theme/marketplace-validate.js +1 -1
- package/lang/en.lyaml +75 -13
- package/lib/DevServerManager.js +2 -5
- package/lib/LocalDevManager.js +2 -2
- package/lib/commonOpts.d.ts +27 -1
- package/lib/commonOpts.js +74 -57
- package/lib/constants.d.ts +0 -8
- package/lib/constants.js +1 -9
- package/lib/dependencyManagement.d.ts +3 -1
- package/lib/dependencyManagement.js +19 -0
- package/lib/doctor/Diagnosis.d.ts +27 -0
- package/lib/doctor/Diagnosis.js +119 -0
- package/lib/doctor/DiagnosticInfoBuilder.d.ts +61 -0
- package/lib/doctor/DiagnosticInfoBuilder.js +158 -0
- package/lib/doctor/Doctor.d.ts +21 -0
- package/lib/doctor/Doctor.js +328 -0
- package/lib/interpolation.d.ts +7 -0
- package/lib/interpolation.js +41 -48
- package/lib/lang.d.ts +8 -0
- package/lib/lang.js +37 -32
- package/lib/process.d.ts +11 -0
- package/lib/process.js +16 -16
- package/lib/projects.d.ts +4 -1
- package/lib/projects.js +5 -3
- package/lib/prompts/accountNamePrompt.js +1 -2
- package/lib/prompts/accountsPrompt.js +0 -17
- package/lib/prompts/createFunctionPrompt.js +3 -4
- package/lib/prompts/promptUtils.d.ts +12 -1
- package/lib/prompts/promptUtils.js +24 -13
- package/lib/ui/SpinniesManager.d.ts +39 -1
- package/lib/ui/SpinniesManager.js +66 -35
- package/lib/ui/git.d.ts +1 -1
- package/lib/ui/git.js +17 -17
- package/lib/ui/index.d.ts +16 -1
- package/lib/ui/index.js +87 -114
- package/lib/ui/serverlessFunctionLogs.js +25 -20
- package/lib/ui/spinniesUtils.d.ts +31 -0
- package/lib/ui/spinniesUtils.js +45 -31
- package/lib/ui/supportHyperlinks.d.ts +6 -0
- package/lib/ui/supportHyperlinks.js +10 -10
- package/lib/ui/supportsColor.d.ts +16 -0
- package/lib/ui/supportsColor.js +19 -17
- package/lib/ui/table.d.ts +3 -1
- package/lib/ui/table.js +17 -11
- package/lib/usageTracking.d.ts +2 -1
- package/lib/usageTracking.js +12 -1
- package/lib/validation.js +0 -2
- package/package.json +7 -3
- package/lib/debugInfo.js +0 -20
- package/lib/environment.d.ts +0 -1
- package/lib/environment.js +0 -13
- package/lib/hublValidate.d.ts +0 -2
- package/lib/hublValidate.js +0 -32
- package/lib/interpolationHelpers.d.ts +0 -10
- package/lib/interpolationHelpers.js +0 -34
- package/lib/projectLogsManager.d.ts +0 -1
- package/lib/prompts/activeInstallConfirmationPrompt.d.ts +0 -1
- package/lib/prompts/activeInstallConfirmationPrompt.js +0 -20
- package/lib/prompts/deployBuildIdPrompt.d.ts +0 -1
- package/lib/prompts/deployBuildIdPrompt.js +0 -22
- package/lib/prompts/feedbackPrompt.d.ts +0 -1
- package/lib/prompts/feedbackPrompt.js +0 -39
- package/lib/prompts/folderOverwritePrompt.d.ts +0 -1
- package/lib/prompts/folderOverwritePrompt.js +0 -17
- package/lib/regex.d.ts +0 -1
- package/lib/regex.js +0 -4
- /package/lib/{debugInfo.d.ts → ProjectLogsManager.d.ts} +0 -0
- /package/lib/{projectLogsManager.js → ProjectLogsManager.js} +0 -0
- /package/lib/{generate-selectors.d.ts → generateSelectors.d.ts} +0 -0
- /package/lib/{generate-selectors.js → generateSelectors.js} +0 -0
- /package/lib/{marketplace-validate.d.ts → marketplaceValidate.d.ts} +0 -0
- /package/lib/{marketplace-validate.js → marketplaceValidate.js} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DiagnosticInfoBuilder, DiagnosticInfo } from './DiagnosticInfoBuilder';
|
|
2
|
+
export declare class Doctor {
|
|
3
|
+
accountId: number | null;
|
|
4
|
+
private diagnosis?;
|
|
5
|
+
private projectConfig?;
|
|
6
|
+
private diagnosticInfo?;
|
|
7
|
+
readonly diagnosticInfoBuilder: DiagnosticInfoBuilder;
|
|
8
|
+
constructor(diagnosticInfoBuilder?: DiagnosticInfoBuilder);
|
|
9
|
+
diagnose(): Promise<DiagnosticInfo>;
|
|
10
|
+
private performCliChecks;
|
|
11
|
+
private performProjectChecks;
|
|
12
|
+
private performCliConfigChecks;
|
|
13
|
+
private checkIfAccessTokenValid;
|
|
14
|
+
private checkIfNodeIsInstalled;
|
|
15
|
+
private checkIfNpmIsInstalled;
|
|
16
|
+
private checkCLIVersion;
|
|
17
|
+
private checkIfNpmInstallRequired;
|
|
18
|
+
private isValidJsonFile;
|
|
19
|
+
private checkProjectConfigJsonFiles;
|
|
20
|
+
private checkIfPortsAreAvailable;
|
|
21
|
+
}
|
|
@@ -0,0 +1,328 @@
|
|
|
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
|
+
exports.Doctor = void 0;
|
|
7
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
8
|
+
const config_1 = require("@hubspot/local-dev-lib/config");
|
|
9
|
+
const SpinniesManager_1 = __importDefault(require("../ui/SpinniesManager"));
|
|
10
|
+
const dependencyManagement_1 = require("../dependencyManagement");
|
|
11
|
+
const util_1 = __importDefault(require("util"));
|
|
12
|
+
const fs_1 = __importDefault(require("fs"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const Diagnosis_1 = require("./Diagnosis");
|
|
15
|
+
const DiagnosticInfoBuilder_1 = require("./DiagnosticInfoBuilder");
|
|
16
|
+
const portManager_1 = require("@hubspot/local-dev-lib/portManager");
|
|
17
|
+
const ports_1 = require("@hubspot/local-dev-lib/constants/ports");
|
|
18
|
+
const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
|
|
19
|
+
const index_1 = require("@hubspot/local-dev-lib/errors/index");
|
|
20
|
+
const urls_1 = require("@hubspot/local-dev-lib/urls");
|
|
21
|
+
const ui_1 = require("../ui");
|
|
22
|
+
const package_json_1 = __importDefault(require("../../package.json"));
|
|
23
|
+
const { i18n } = require('../lang');
|
|
24
|
+
const { uiLink } = require('../ui');
|
|
25
|
+
const minMajorNodeVersion = 18;
|
|
26
|
+
const i18nKey = `lib.doctor`;
|
|
27
|
+
class Doctor {
|
|
28
|
+
accountId;
|
|
29
|
+
diagnosis;
|
|
30
|
+
projectConfig;
|
|
31
|
+
diagnosticInfo;
|
|
32
|
+
diagnosticInfoBuilder;
|
|
33
|
+
constructor(diagnosticInfoBuilder = new DiagnosticInfoBuilder_1.DiagnosticInfoBuilder(process)) {
|
|
34
|
+
SpinniesManager_1.default.init();
|
|
35
|
+
this.accountId = (0, config_1.getAccountId)();
|
|
36
|
+
this.diagnosticInfoBuilder = diagnosticInfoBuilder;
|
|
37
|
+
}
|
|
38
|
+
async diagnose() {
|
|
39
|
+
SpinniesManager_1.default.add('runningDiagnostics', {
|
|
40
|
+
text: i18n(`${i18nKey}.runningDiagnostics`),
|
|
41
|
+
});
|
|
42
|
+
this.diagnosticInfo = await this.diagnosticInfoBuilder.generateDiagnosticInfo();
|
|
43
|
+
this.projectConfig = this.diagnosticInfo?.project.config;
|
|
44
|
+
this.diagnosis = new Diagnosis_1.Diagnosis({
|
|
45
|
+
diagnosticInfo: this.diagnosticInfo,
|
|
46
|
+
accountId: this.accountId,
|
|
47
|
+
});
|
|
48
|
+
await Promise.all([
|
|
49
|
+
...this.performCliChecks(),
|
|
50
|
+
...this.performCliConfigChecks(),
|
|
51
|
+
...(this.projectConfig?.projectConfig ? this.performProjectChecks() : []),
|
|
52
|
+
]);
|
|
53
|
+
SpinniesManager_1.default.succeed('runningDiagnostics', {
|
|
54
|
+
text: i18n(`${i18nKey}.diagnosticsComplete`),
|
|
55
|
+
succeedColor: 'white',
|
|
56
|
+
});
|
|
57
|
+
this.diagnosticInfo.diagnosis = this.diagnosis.toString();
|
|
58
|
+
this.diagnosticInfo.errorCount = this.diagnosis.getErrorCount();
|
|
59
|
+
this.diagnosticInfo.warningCount = this.diagnosis.getWarningCount();
|
|
60
|
+
return this.diagnosticInfo;
|
|
61
|
+
}
|
|
62
|
+
performCliChecks() {
|
|
63
|
+
return [
|
|
64
|
+
this.checkIfNodeIsInstalled(),
|
|
65
|
+
this.checkIfNpmIsInstalled(),
|
|
66
|
+
this.checkCLIVersion(),
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
performProjectChecks() {
|
|
70
|
+
return [
|
|
71
|
+
this.checkIfNpmInstallRequired(),
|
|
72
|
+
this.checkProjectConfigJsonFiles(),
|
|
73
|
+
this.checkIfPortsAreAvailable(),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
performCliConfigChecks() {
|
|
77
|
+
if (!this.diagnosticInfo?.config) {
|
|
78
|
+
this.diagnosis?.addCLIConfigSection({
|
|
79
|
+
type: 'error',
|
|
80
|
+
message: i18n(`${i18nKey}.diagnosis.cliConfig.noConfigFile`),
|
|
81
|
+
secondaryMessaging: i18n(`${i18nKey}.diagnosis.cliConfig.noConfigFileSecondary`, {
|
|
82
|
+
command: (0, ui_1.uiCommandReference)('hs init'),
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
return [this.checkIfAccessTokenValid()];
|
|
88
|
+
}
|
|
89
|
+
async checkIfAccessTokenValid() {
|
|
90
|
+
const localI18nKey = `${i18nKey}.accountChecks`;
|
|
91
|
+
try {
|
|
92
|
+
await (0, personalAccessKey_1.accessTokenForPersonalAccessKey)(this.accountId, true);
|
|
93
|
+
this.diagnosis?.addCLIConfigSection({
|
|
94
|
+
type: 'success',
|
|
95
|
+
message: i18n(`${localI18nKey}.active`),
|
|
96
|
+
});
|
|
97
|
+
this.diagnosis?.addCLIConfigSection({
|
|
98
|
+
type: 'success',
|
|
99
|
+
message: i18n(`${localI18nKey}.pak.valid`, {
|
|
100
|
+
link: uiLink(i18n(`${localI18nKey}.pak.viewScopes`), `${(0, urls_1.getHubSpotWebsiteOrigin)(this.diagnosticInfoBuilder?.env || 'PROD')}/personal-access-key/${this.diagnosticInfo?.account.accountId}`),
|
|
101
|
+
}),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const portalNotActive = (0, index_1.isSpecifiedError)(error, {
|
|
106
|
+
statusCode: 401,
|
|
107
|
+
category: 'INVALID_AUTHENTICATION',
|
|
108
|
+
subCategory: 'LocalDevAuthErrorType.PORTAL_NOT_ACTIVE',
|
|
109
|
+
}) ||
|
|
110
|
+
(0, index_1.isSpecifiedError)(error, {
|
|
111
|
+
statusCode: 404,
|
|
112
|
+
category: 'INVALID_AUTHENTICATION',
|
|
113
|
+
subCategory: 'LocalDevAuthErrorType.INVALID_PORTAL_ID',
|
|
114
|
+
});
|
|
115
|
+
if (portalNotActive) {
|
|
116
|
+
this.diagnosis?.addCLIConfigSection({
|
|
117
|
+
type: 'error',
|
|
118
|
+
message: i18n(`${localI18nKey}.inactive`),
|
|
119
|
+
secondaryMessaging: i18n(`${localI18nKey}.inactiveSecondary`, {
|
|
120
|
+
command: (0, ui_1.uiCommandReference)(`hs accounts clean`),
|
|
121
|
+
}),
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
else if ((0, index_1.isSpecifiedError)(error, {
|
|
125
|
+
statusCode: 401,
|
|
126
|
+
category: 'INVALID_AUTHENTICATION',
|
|
127
|
+
subCategory: 'LocalDevAuthErrorType.FAILED_TO_SIGN_REFRESH_TOKEN_DECODE',
|
|
128
|
+
})) {
|
|
129
|
+
this.diagnosis?.addCLIConfigSection({
|
|
130
|
+
type: 'success',
|
|
131
|
+
message: i18n(`${localI18nKey}.active`),
|
|
132
|
+
});
|
|
133
|
+
this.diagnosis?.addCLIConfigSection({
|
|
134
|
+
type: 'error',
|
|
135
|
+
message: i18n(`${localI18nKey}.pak.invalid`),
|
|
136
|
+
secondaryMessaging: i18n(`${localI18nKey}.pak.invalidSecondary`, {
|
|
137
|
+
command: (0, ui_1.uiCommandReference)(`hs auth`),
|
|
138
|
+
}),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.diagnosis?.addCLIConfigSection({
|
|
143
|
+
type: 'error',
|
|
144
|
+
message: i18n(`${localI18nKey}.unableToDetermine`),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async checkIfNodeIsInstalled() {
|
|
150
|
+
const localI18nKey = `${i18nKey}.nodeChecks`;
|
|
151
|
+
if (!this.diagnosticInfo?.versions.node) {
|
|
152
|
+
return this.diagnosis?.addCliSection({
|
|
153
|
+
type: 'error',
|
|
154
|
+
message: i18n(`${localI18nKey}.unableToDetermine`),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
const nodeVersion = this.diagnosticInfo?.versions.node?.split('.');
|
|
158
|
+
const currentNodeMajor = nodeVersion?.[0];
|
|
159
|
+
if (!currentNodeMajor || parseInt(currentNodeMajor) < minMajorNodeVersion) {
|
|
160
|
+
return this.diagnosis?.addCliSection({
|
|
161
|
+
type: 'warning',
|
|
162
|
+
message: i18n(`${localI18nKey}.minimumNotMet`, {
|
|
163
|
+
nodeVersion: this.diagnosticInfo?.versions.node,
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
this.diagnosis?.addCliSection({
|
|
168
|
+
type: 'success',
|
|
169
|
+
message: i18n(`${localI18nKey}.success`, {
|
|
170
|
+
nodeVersion: this.diagnosticInfo?.versions.node,
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
async checkIfNpmIsInstalled() {
|
|
175
|
+
const localI18nKey = `${i18nKey}.npmChecks`;
|
|
176
|
+
const npmVersion = this.diagnosticInfo?.versions?.npm;
|
|
177
|
+
if (!npmVersion) {
|
|
178
|
+
return this.diagnosis?.addCliSection({
|
|
179
|
+
type: 'error',
|
|
180
|
+
message: i18n(`${localI18nKey}.notInstalled`),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
this.diagnosis?.addCliSection({
|
|
184
|
+
type: 'success',
|
|
185
|
+
message: i18n(`${localI18nKey}.installed`, {
|
|
186
|
+
npmVersion,
|
|
187
|
+
}),
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
async checkCLIVersion() {
|
|
191
|
+
let latestCLIVersion;
|
|
192
|
+
try {
|
|
193
|
+
latestCLIVersion = await (0, dependencyManagement_1.getLatestCliVersion)();
|
|
194
|
+
}
|
|
195
|
+
catch (e) {
|
|
196
|
+
return this.diagnosis?.addCliSection({
|
|
197
|
+
type: 'error',
|
|
198
|
+
message: i18n(`${i18nKey}.hsChecks.unableToDetermine`),
|
|
199
|
+
secondaryMessaging: i18n(`${i18nKey}.hsChecks.unableToDetermineSecondary`, {
|
|
200
|
+
command: (0, ui_1.uiCommandReference)(`hs --version`),
|
|
201
|
+
link: uiLink(i18n(`${i18nKey}.hsChecks.unableToDetermineSecondaryLink`), `https://www.npmjs.com/package/${package_json_1.default.name}?activeTab=versions`),
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (latestCLIVersion !== package_json_1.default.version) {
|
|
206
|
+
this.diagnosis?.addCliSection({
|
|
207
|
+
type: 'warning',
|
|
208
|
+
message: i18n(`${i18nKey}.hsChecks.notLatest`, {
|
|
209
|
+
hsVersion: package_json_1.default.version,
|
|
210
|
+
}),
|
|
211
|
+
secondaryMessaging: i18n(`${i18nKey}.hsChecks.notLatestSecondary`, {
|
|
212
|
+
hsVersion: package_json_1.default.version,
|
|
213
|
+
command: (0, ui_1.uiCommandReference)(`npm install -g ${package_json_1.default.name}`),
|
|
214
|
+
}),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
this.diagnosis?.addCliSection({
|
|
219
|
+
type: 'success',
|
|
220
|
+
message: i18n(`${i18nKey}.hsChecks.latest`, {
|
|
221
|
+
hsVersion: latestCLIVersion,
|
|
222
|
+
}),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async checkIfNpmInstallRequired() {
|
|
227
|
+
let foundError = false;
|
|
228
|
+
const localI18nKey = `${i18nKey}.projectDependenciesChecks`;
|
|
229
|
+
for (const packageFile of this.diagnosticInfo?.packageFiles || []) {
|
|
230
|
+
const packageDirName = path_1.default.dirname(packageFile);
|
|
231
|
+
try {
|
|
232
|
+
const needsInstall = await (0, dependencyManagement_1.hasMissingPackages)(path_1.default.join(this.projectConfig?.projectDir, packageDirName));
|
|
233
|
+
if (needsInstall) {
|
|
234
|
+
foundError = true;
|
|
235
|
+
this.diagnosis?.addProjectSection({
|
|
236
|
+
type: 'warning',
|
|
237
|
+
message: i18n(`${localI18nKey}.missingDependencies`, {
|
|
238
|
+
dir: packageDirName,
|
|
239
|
+
}),
|
|
240
|
+
secondaryMessaging: i18n(`${localI18nKey}.missingDependenciesSecondary`, {
|
|
241
|
+
command: (0, ui_1.uiCommandReference)('hs project install-deps'),
|
|
242
|
+
}),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
catch (e) {
|
|
247
|
+
foundError = true;
|
|
248
|
+
if (!(await this.isValidJsonFile(packageFile))) {
|
|
249
|
+
this.diagnosis?.addProjectSection({
|
|
250
|
+
type: 'error',
|
|
251
|
+
message: i18n(`${i18nKey}.files.invalidJson`, {
|
|
252
|
+
filename: packageFile,
|
|
253
|
+
}),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
this.diagnosis?.addProjectSection({
|
|
258
|
+
type: 'error',
|
|
259
|
+
message: i18n(`${localI18nKey}.unableToDetermine`, {
|
|
260
|
+
dir: packageDirName,
|
|
261
|
+
}),
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
logger_1.logger.debug(e);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (!foundError) {
|
|
268
|
+
this.diagnosis?.addProjectSection({
|
|
269
|
+
type: 'success',
|
|
270
|
+
message: i18n(`${localI18nKey}.success`),
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async isValidJsonFile(filename) {
|
|
275
|
+
try {
|
|
276
|
+
const readFile = util_1.default.promisify(fs_1.default.readFile);
|
|
277
|
+
const fileContents = await readFile(filename);
|
|
278
|
+
JSON.parse(fileContents.toString());
|
|
279
|
+
}
|
|
280
|
+
catch (e) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
async checkProjectConfigJsonFiles() {
|
|
286
|
+
let foundError = false;
|
|
287
|
+
for (const jsonFile of this.diagnosticInfo?.jsonFiles || []) {
|
|
288
|
+
const fileToCheck = path_1.default.join(this.projectConfig?.projectDir, jsonFile);
|
|
289
|
+
if (!(await this.isValidJsonFile(fileToCheck))) {
|
|
290
|
+
foundError = true;
|
|
291
|
+
this.diagnosis?.addProjectSection({
|
|
292
|
+
type: 'error',
|
|
293
|
+
message: i18n(`${i18nKey}.files.invalidJson`, {
|
|
294
|
+
filename: jsonFile,
|
|
295
|
+
}),
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (!foundError) {
|
|
300
|
+
this.diagnosis?.addProjectSection({
|
|
301
|
+
type: 'success',
|
|
302
|
+
message: i18n(`${i18nKey}.files.validJson`),
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
async checkIfPortsAreAvailable() {
|
|
307
|
+
const localI18nKey = `${i18nKey}.port`;
|
|
308
|
+
if (await (0, portManager_1.isPortManagerPortAvailable)()) {
|
|
309
|
+
this.diagnosis?.addProjectSection({
|
|
310
|
+
type: 'success',
|
|
311
|
+
message: i18n(`${localI18nKey}.available`, {
|
|
312
|
+
port: ports_1.PORT_MANAGER_SERVER_PORT,
|
|
313
|
+
}),
|
|
314
|
+
});
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
this.diagnosis?.addProjectSection({
|
|
318
|
+
type: 'warning',
|
|
319
|
+
message: i18n(`${localI18nKey}.inUse`, {
|
|
320
|
+
port: ports_1.PORT_MANAGER_SERVER_PORT,
|
|
321
|
+
}),
|
|
322
|
+
secondaryMessaging: i18n(`${localI18nKey}.inUseSecondary`, {
|
|
323
|
+
command: (0, ui_1.uiCommandReference)('hs project dev'),
|
|
324
|
+
}),
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
exports.Doctor = Doctor;
|
package/lib/interpolation.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
export declare const helpers: {
|
|
2
|
+
[key: string]: (stringValue: string) => string;
|
|
3
|
+
};
|
|
4
|
+
type InterpolationData = {
|
|
5
|
+
[identifier: string]: string | number;
|
|
6
|
+
};
|
|
7
|
+
export declare function interpolate(stringValue: string, interpolationData: InterpolationData): string;
|
|
1
8
|
export {};
|
package/lib/interpolation.js
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
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
|
-
|
|
6
|
+
exports.helpers = void 0;
|
|
7
|
+
exports.interpolate = interpolate;
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
exports.helpers = {
|
|
10
|
+
bold: function (stringValue) {
|
|
11
|
+
return chalk_1.default.bold(stringValue);
|
|
12
|
+
},
|
|
13
|
+
yellow: function (stringValue) {
|
|
14
|
+
return chalk_1.default.reset.yellow(stringValue);
|
|
15
|
+
},
|
|
16
|
+
green: function (stringValue) {
|
|
17
|
+
return chalk_1.default.reset.green(stringValue);
|
|
18
|
+
},
|
|
19
|
+
red: function (stringValue) {
|
|
20
|
+
return chalk_1.default.reset.red(stringValue);
|
|
21
|
+
},
|
|
22
|
+
cyan: function (stringValue) {
|
|
23
|
+
return chalk_1.default.cyan(stringValue);
|
|
24
|
+
},
|
|
25
|
+
orange: function (stringValue) {
|
|
26
|
+
return chalk_1.default.hex('#FC9900')(stringValue);
|
|
27
|
+
},
|
|
28
|
+
};
|
|
5
29
|
const delimiters = {
|
|
6
30
|
interpolation: {
|
|
7
31
|
start: '{{',
|
|
@@ -12,25 +36,16 @@ const delimiters = {
|
|
|
12
36
|
end: '/',
|
|
13
37
|
},
|
|
14
38
|
};
|
|
15
|
-
|
|
39
|
+
function isHelperIdentifier(identifier) {
|
|
16
40
|
return (identifier.startsWith(delimiters.helpers.start) ||
|
|
17
41
|
identifier.startsWith(delimiters.helpers.end));
|
|
18
|
-
}
|
|
19
|
-
|
|
42
|
+
}
|
|
43
|
+
function generateReplaceFn(matchedText, startIndex, replacementString) {
|
|
20
44
|
return currentStringValue => `${currentStringValue.slice(0, startIndex)}${replacementString !== null && replacementString !== undefined
|
|
21
45
|
? replacementString
|
|
22
46
|
: ''}${currentStringValue.slice(startIndex + matchedText.length)}`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
* Interpolate a string with data
|
|
26
|
-
* @param {string} stringValue - The string to interpolate
|
|
27
|
-
* @param {object} interpolationData - The data to interpolate with
|
|
28
|
-
* @returns {string} - The interpolated string
|
|
29
|
-
* @example
|
|
30
|
-
* interpolation('Hello {{name}}', { name: 'World' })
|
|
31
|
-
* // 'Hello World'
|
|
32
|
-
*/
|
|
33
|
-
const interpolation = (stringValue, interpolationData) => {
|
|
47
|
+
}
|
|
48
|
+
function interpolation(stringValue, interpolationData) {
|
|
34
49
|
const interpolationIdentifierRegEx = new RegExp(`${delimiters.interpolation.start}(.*?)${delimiters.interpolation.end}`, 'g');
|
|
35
50
|
const replaceQueue = [];
|
|
36
51
|
let match;
|
|
@@ -40,23 +55,13 @@ const interpolation = (stringValue, interpolationData) => {
|
|
|
40
55
|
const { 0: matchedText, 1: rawIdentifier, index } = match;
|
|
41
56
|
const identifier = rawIdentifier.trim();
|
|
42
57
|
if (identifier && !isHelperIdentifier(identifier)) {
|
|
43
|
-
replaceQueue.unshift(generateReplaceFn(matchedText, index, interpolationData[identifier]));
|
|
58
|
+
replaceQueue.unshift(generateReplaceFn(matchedText, index, String(interpolationData[identifier])));
|
|
44
59
|
}
|
|
45
60
|
}
|
|
46
61
|
const compiledString = replaceQueue.reduce((currentValue, replaceFn) => replaceFn(currentValue), stringValue);
|
|
47
62
|
return compiledString;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
* Compile a string using a specified helper function
|
|
51
|
-
* @param {string} stringValue - The string to modify
|
|
52
|
-
* @param {object} helperIdentifier - Helper name
|
|
53
|
-
* @param {function} helperFn - Helper function to call on string
|
|
54
|
-
* @returns {string} - The modified string
|
|
55
|
-
* @example
|
|
56
|
-
* compileHelper('White {{#yellow}}yellow{{/yellow}}', 'yellow', (string) => { chalk.reset.yellow(string) }))))
|
|
57
|
-
* // 'White yellow' (with 'yellow' colored yellow)
|
|
58
|
-
*/
|
|
59
|
-
const compileHelper = (stringValue, helperIdentifier, helperFn) => {
|
|
63
|
+
}
|
|
64
|
+
function compileHelper(stringValue, helperIdentifier, helperFn) {
|
|
60
65
|
const helperIdentifierRegEx = new RegExp(`${delimiters.interpolation.start}(${delimiters.helpers.start}${helperIdentifier})${delimiters.interpolation.end}(.*?)${delimiters.interpolation.start}(${delimiters.helpers.end}${helperIdentifier})${delimiters.interpolation.end}`, 'g');
|
|
61
66
|
const replaceQueue = [];
|
|
62
67
|
let match;
|
|
@@ -73,26 +78,14 @@ const compileHelper = (stringValue, helperIdentifier, helperFn) => {
|
|
|
73
78
|
}
|
|
74
79
|
const compiledString = replaceQueue.reduce((currentValue, replaceFn) => replaceFn(currentValue), stringValue);
|
|
75
80
|
return compiledString;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return Object.keys(helpers).reduce((currentStringValue, helperIdentifier) => {
|
|
79
|
-
return compileHelper(currentStringValue, helperIdentifier, helpers[helperIdentifier]);
|
|
81
|
+
}
|
|
82
|
+
function compileHelpers(stringValue) {
|
|
83
|
+
return Object.keys(exports.helpers).reduce((currentStringValue, helperIdentifier) => {
|
|
84
|
+
return compileHelper(currentStringValue, helperIdentifier, exports.helpers[helperIdentifier]);
|
|
80
85
|
}, stringValue);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
* Interpolate a string with data and compile helpers on the string
|
|
84
|
-
* @param {string} stringValue - The string to interpolate
|
|
85
|
-
* @param {object} interpolationData - The data to interpolate with
|
|
86
|
-
* @returns {string} - The interpolated and helper-compiled string
|
|
87
|
-
* @example
|
|
88
|
-
* interpolateAndCompile('Some {{#bold}}{{text}}{{/bold}} text', { text: 'awesomely bold' })
|
|
89
|
-
* // 'Some awsomely bold text' (with the words 'awesomely bold' in bold)
|
|
90
|
-
*/
|
|
91
|
-
const interpolate = (stringValue, interpolationData) => {
|
|
86
|
+
}
|
|
87
|
+
function interpolate(stringValue, interpolationData) {
|
|
92
88
|
const interpolatedString = interpolation(stringValue, interpolationData);
|
|
93
89
|
const helperCompiledString = compileHelpers(interpolatedString);
|
|
94
90
|
return helperCompiledString;
|
|
95
|
-
}
|
|
96
|
-
module.exports = {
|
|
97
|
-
interpolate,
|
|
98
|
-
};
|
|
91
|
+
}
|
package/lib/lang.d.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
+
export declare const MISSING_LANGUAGE_DATA_PREFIX = "[Missing language data]";
|
|
2
|
+
type LanguageObject = {
|
|
3
|
+
[key: string]: string | LanguageObject;
|
|
4
|
+
};
|
|
5
|
+
export declare function i18n(lookupDotNotation: string, options?: {
|
|
6
|
+
[identifier: string]: string | number;
|
|
7
|
+
}): string;
|
|
8
|
+
export declare function setLangData(newLocale: string, newLangObj: LanguageObject): void;
|
|
1
9
|
export {};
|
package/lib/lang.js
CHANGED
|
@@ -1,55 +1,65 @@
|
|
|
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
|
|
6
|
+
exports.MISSING_LANGUAGE_DATA_PREFIX = void 0;
|
|
7
|
+
exports.i18n = i18n;
|
|
8
|
+
exports.setLangData = setLangData;
|
|
9
|
+
const util_1 = __importDefault(require("util"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
12
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
13
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
14
|
+
const interpolation_1 = require("./interpolation");
|
|
15
|
+
exports.MISSING_LANGUAGE_DATA_PREFIX = '[Missing language data]';
|
|
11
16
|
let locale;
|
|
12
17
|
let languageObj;
|
|
13
|
-
|
|
18
|
+
function loadLanguageFromYaml() {
|
|
14
19
|
if (languageObj)
|
|
15
20
|
return;
|
|
16
21
|
try {
|
|
17
22
|
const nodeLocale = Intl.DateTimeFormat()
|
|
18
23
|
.resolvedOptions()
|
|
19
24
|
.locale.split('-')[0];
|
|
20
|
-
const languageFilePath =
|
|
21
|
-
const languageFileExists =
|
|
25
|
+
const languageFilePath = path_1.default.join(__dirname, `../lang/${nodeLocale}.lyaml`);
|
|
26
|
+
const languageFileExists = fs_extra_1.default.existsSync(languageFilePath);
|
|
22
27
|
// Fall back to using the default language file
|
|
23
28
|
locale = languageFileExists ? nodeLocale : 'en';
|
|
24
|
-
languageObj =
|
|
25
|
-
logger.debug('Loaded language data: ',
|
|
29
|
+
languageObj = js_yaml_1.default.load(fs_extra_1.default.readFileSync(path_1.default.join(__dirname, `../lang/${locale}.lyaml`), 'utf8'));
|
|
30
|
+
logger_1.logger.debug('Loaded language data: ', util_1.default.inspect(languageObj, true, 999, true));
|
|
26
31
|
}
|
|
27
32
|
catch (e) {
|
|
28
|
-
logger.error('Error loading language data: ', e);
|
|
33
|
+
logger_1.logger.error('Error loading language data: ', e);
|
|
29
34
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
35
|
+
}
|
|
36
|
+
function getTextValue(lookupDotNotation) {
|
|
32
37
|
const lookupProps = [locale, ...lookupDotNotation.split('.')];
|
|
33
|
-
const missingTextData = `${MISSING_LANGUAGE_DATA_PREFIX}: ${lookupProps.join('.')}`;
|
|
38
|
+
const missingTextData = `${exports.MISSING_LANGUAGE_DATA_PREFIX}: ${lookupProps.join('.')}`;
|
|
34
39
|
let textValue = languageObj;
|
|
35
40
|
let previouslyCheckedProp = lookupProps[0];
|
|
36
41
|
try {
|
|
37
42
|
lookupProps.forEach(prop => {
|
|
38
|
-
textValue
|
|
43
|
+
if (textValue && typeof textValue === 'object') {
|
|
44
|
+
textValue = textValue[prop];
|
|
45
|
+
}
|
|
39
46
|
previouslyCheckedProp = prop;
|
|
40
47
|
});
|
|
41
48
|
}
|
|
42
49
|
catch (e) {
|
|
43
|
-
logger.debug(`Unable to access language property: ${lookupProps.join('.')}. Failed to access prop "${previouslyCheckedProp}".`);
|
|
44
|
-
logger.error('Unable to access language property.');
|
|
50
|
+
logger_1.logger.debug(`Unable to access language property: ${lookupProps.join('.')}. Failed to access prop "${previouslyCheckedProp}".`);
|
|
51
|
+
logger_1.logger.error('Unable to access language property.');
|
|
45
52
|
return missingTextData;
|
|
46
53
|
}
|
|
47
54
|
if (!textValue) {
|
|
48
55
|
return missingTextData;
|
|
49
56
|
}
|
|
57
|
+
if (typeof textValue !== 'string') {
|
|
58
|
+
return missingTextData;
|
|
59
|
+
}
|
|
50
60
|
return textValue;
|
|
51
|
-
}
|
|
52
|
-
|
|
61
|
+
}
|
|
62
|
+
function i18n(lookupDotNotation, options = {}) {
|
|
53
63
|
if (!languageObj) {
|
|
54
64
|
loadLanguageFromYaml();
|
|
55
65
|
}
|
|
@@ -57,15 +67,10 @@ const i18n = (lookupDotNotation, options = {}) => {
|
|
|
57
67
|
throw new Error(`i18n must be passed a string value for lookupDotNotation, received ${typeof lookupDotNotation}`);
|
|
58
68
|
}
|
|
59
69
|
const textValue = getTextValue(lookupDotNotation);
|
|
60
|
-
const shouldInterpolate = !textValue.startsWith(MISSING_LANGUAGE_DATA_PREFIX);
|
|
61
|
-
return shouldInterpolate ? interpolate(textValue, options) : textValue;
|
|
62
|
-
}
|
|
63
|
-
|
|
70
|
+
const shouldInterpolate = !textValue.startsWith(exports.MISSING_LANGUAGE_DATA_PREFIX);
|
|
71
|
+
return shouldInterpolate ? (0, interpolation_1.interpolate)(textValue, options) : textValue;
|
|
72
|
+
}
|
|
73
|
+
function setLangData(newLocale, newLangObj) {
|
|
64
74
|
locale = newLocale;
|
|
65
75
|
languageObj = newLangObj;
|
|
66
|
-
}
|
|
67
|
-
module.exports = {
|
|
68
|
-
i18n,
|
|
69
|
-
setLangData,
|
|
70
|
-
MISSING_LANGUAGE_DATA_PREFIX,
|
|
71
|
-
};
|
|
76
|
+
}
|
package/lib/process.d.ts
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
+
interface KeyPress {
|
|
2
|
+
ctrl?: boolean;
|
|
3
|
+
shift?: boolean;
|
|
4
|
+
alt?: boolean;
|
|
5
|
+
meta?: boolean;
|
|
6
|
+
name?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function handleExit(callback: (onTerminate: {
|
|
9
|
+
isSIGHUP: boolean;
|
|
10
|
+
}) => void): void;
|
|
11
|
+
export declare function handleKeypress(callback: (onKeyPress: KeyPress) => void): void;
|
|
1
12
|
export {};
|
package/lib/process.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
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
|
|
6
|
+
exports.handleExit = handleExit;
|
|
7
|
+
exports.handleKeypress = handleKeypress;
|
|
8
|
+
const readline_1 = __importDefault(require("readline"));
|
|
9
|
+
const logger_1 = require("@hubspot/local-dev-lib/logger");
|
|
10
|
+
const lang_1 = require("./lang");
|
|
7
11
|
const i18nKey = 'lib.process';
|
|
8
|
-
|
|
12
|
+
function handleExit(callback) {
|
|
9
13
|
const terminationSignals = [
|
|
10
14
|
'beforeExit',
|
|
11
15
|
'SIGINT', // Terminal trying to interrupt (Ctrl + C)
|
|
@@ -25,17 +29,17 @@ const handleExit = callback => {
|
|
|
25
29
|
const isSIGHUP = signal === 'SIGHUP';
|
|
26
30
|
// Prevent logs when terminal closes
|
|
27
31
|
if (isSIGHUP) {
|
|
28
|
-
setLogLevel(LOG_LEVEL.NONE);
|
|
32
|
+
(0, logger_1.setLogLevel)(logger_1.LOG_LEVEL.NONE);
|
|
29
33
|
}
|
|
30
|
-
logger.debug(i18n(`${i18nKey}.exitDebug`, { signal }));
|
|
34
|
+
logger_1.logger.debug((0, lang_1.i18n)(`${i18nKey}.exitDebug`, { signal }));
|
|
31
35
|
await callback({ isSIGHUP });
|
|
32
36
|
}
|
|
33
37
|
});
|
|
34
38
|
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
}
|
|
40
|
+
function handleKeypress(callback) {
|
|
41
|
+
readline_1.default.createInterface(process.stdin, process.stdout);
|
|
42
|
+
readline_1.default.emitKeypressEvents(process.stdin);
|
|
39
43
|
if (process.stdin.isTTY) {
|
|
40
44
|
process.stdin.setRawMode(true);
|
|
41
45
|
}
|
|
@@ -45,8 +49,4 @@ const handleKeypress = callback => {
|
|
|
45
49
|
callback(key);
|
|
46
50
|
}
|
|
47
51
|
});
|
|
48
|
-
}
|
|
49
|
-
module.exports = {
|
|
50
|
-
handleExit,
|
|
51
|
-
handleKeypress,
|
|
52
|
-
};
|
|
52
|
+
}
|