@hubspot/cli 6.2.2-experimental.1 → 6.3.0-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.
Files changed (143) hide show
  1. package/bin/cli.js +23 -2
  2. package/commands/accounts/clean.js +8 -5
  3. package/commands/accounts/info.js +6 -6
  4. package/commands/accounts/list.js +14 -10
  5. package/commands/accounts/remove.js +1 -1
  6. package/commands/accounts/rename.js +3 -4
  7. package/commands/auth.js +11 -9
  8. package/commands/cms/lighthouseScore.js +19 -19
  9. package/commands/config/set.js +4 -5
  10. package/commands/create/api-sample.js +2 -2
  11. package/commands/create.js +3 -4
  12. package/commands/customObject/create.js +4 -6
  13. package/commands/customObject/schema/create.js +8 -9
  14. package/commands/customObject/schema/delete.js +3 -5
  15. package/commands/customObject/schema/fetch-all.js +3 -4
  16. package/commands/customObject/schema/fetch.js +4 -6
  17. package/commands/customObject/schema/list.js +3 -4
  18. package/commands/customObject/schema/update.js +8 -9
  19. package/commands/doctor.d.ts +8 -0
  20. package/commands/doctor.js +60 -0
  21. package/commands/feedback.js +19 -4
  22. package/commands/fetch.js +4 -4
  23. package/commands/filemanager/fetch.js +4 -5
  24. package/commands/filemanager/upload.js +9 -10
  25. package/commands/functions/deploy.js +12 -10
  26. package/commands/functions/list.js +6 -6
  27. package/commands/functions/server.js +4 -5
  28. package/commands/hubdb/clear.js +5 -6
  29. package/commands/hubdb/create.js +5 -6
  30. package/commands/hubdb/delete.js +5 -6
  31. package/commands/hubdb/fetch.js +4 -5
  32. package/commands/init.js +44 -15
  33. package/commands/lint.d.ts +4 -1
  34. package/commands/lint.js +44 -8
  35. package/commands/list.js +4 -5
  36. package/commands/logs.js +4 -5
  37. package/commands/module/marketplace-validate.js +7 -8
  38. package/commands/mv.js +7 -8
  39. package/commands/open.js +7 -8
  40. package/commands/project/add.js +2 -3
  41. package/commands/project/cloneApp.js +14 -14
  42. package/commands/project/create.js +3 -3
  43. package/commands/project/deploy.js +24 -14
  44. package/commands/project/dev.js +13 -13
  45. package/commands/project/download.js +11 -9
  46. package/commands/project/installDeps.js +5 -5
  47. package/commands/project/listBuilds.js +10 -8
  48. package/commands/project/logs.js +6 -6
  49. package/commands/project/migrateApp.js +18 -18
  50. package/commands/project/open.js +6 -7
  51. package/commands/project/upload.js +12 -10
  52. package/commands/project/watch.js +9 -10
  53. package/commands/remove.js +10 -8
  54. package/commands/sandbox/create.js +8 -9
  55. package/commands/sandbox/delete.js +16 -12
  56. package/commands/secrets/addSecret.js +6 -7
  57. package/commands/secrets/deleteSecret.js +6 -7
  58. package/commands/secrets/listSecrets.js +6 -6
  59. package/commands/secrets/updateSecret.js +6 -7
  60. package/commands/theme/generate-selectors.js +1 -1
  61. package/commands/theme/marketplace-validate.js +7 -8
  62. package/commands/theme/preview.js +5 -6
  63. package/commands/upload.js +18 -15
  64. package/commands/watch.js +9 -10
  65. package/lang/en.lyaml +78 -13
  66. package/lib/DevServerManager.js +2 -5
  67. package/lib/LocalDevManager.js +2 -2
  68. package/lib/buildAccount.js +3 -1
  69. package/lib/commonOpts.d.ts +35 -1
  70. package/lib/commonOpts.js +86 -67
  71. package/lib/constants.d.ts +0 -8
  72. package/lib/constants.js +1 -9
  73. package/lib/dependencyManagement.d.ts +3 -1
  74. package/lib/dependencyManagement.js +19 -0
  75. package/lib/developerTestAccounts.js +8 -5
  76. package/lib/doctor/Diagnosis.d.ts +27 -0
  77. package/lib/doctor/Diagnosis.js +119 -0
  78. package/lib/doctor/DiagnosticInfoBuilder.d.ts +61 -0
  79. package/lib/doctor/DiagnosticInfoBuilder.js +158 -0
  80. package/lib/doctor/Doctor.d.ts +21 -0
  81. package/lib/doctor/Doctor.js +328 -0
  82. package/lib/interpolation.d.ts +7 -0
  83. package/lib/interpolation.js +41 -48
  84. package/lib/lang.d.ts +8 -0
  85. package/lib/lang.js +37 -32
  86. package/lib/oauth.js +3 -1
  87. package/lib/process.d.ts +11 -0
  88. package/lib/process.js +16 -16
  89. package/lib/projects.d.ts +4 -1
  90. package/lib/projects.js +5 -3
  91. package/lib/prompts/accountNamePrompt.js +1 -2
  92. package/lib/prompts/accountsPrompt.js +8 -21
  93. package/lib/prompts/createFunctionPrompt.js +3 -4
  94. package/lib/prompts/projectDevTargetAccountPrompt.js +3 -2
  95. package/lib/prompts/promptUtils.d.ts +12 -1
  96. package/lib/prompts/promptUtils.js +24 -13
  97. package/lib/prompts/sandboxesPrompt.js +10 -7
  98. package/lib/prompts/setAsDefaultAccountPrompt.js +4 -2
  99. package/lib/sandboxSync.js +5 -2
  100. package/lib/sandboxes.js +12 -7
  101. package/lib/ui/SpinniesManager.d.ts +39 -1
  102. package/lib/ui/SpinniesManager.js +66 -35
  103. package/lib/ui/git.d.ts +1 -1
  104. package/lib/ui/git.js +17 -17
  105. package/lib/ui/index.d.ts +16 -1
  106. package/lib/ui/index.js +87 -114
  107. package/lib/ui/serverlessFunctionLogs.js +25 -20
  108. package/lib/ui/spinniesUtils.d.ts +31 -0
  109. package/lib/ui/spinniesUtils.js +45 -31
  110. package/lib/ui/supportHyperlinks.d.ts +6 -0
  111. package/lib/ui/supportHyperlinks.js +10 -10
  112. package/lib/ui/supportsColor.d.ts +16 -0
  113. package/lib/ui/supportsColor.js +19 -17
  114. package/lib/ui/table.d.ts +3 -1
  115. package/lib/ui/table.js +17 -11
  116. package/lib/usageTracking.d.ts +2 -1
  117. package/lib/usageTracking.js +12 -1
  118. package/lib/validation.js +0 -2
  119. package/package.json +7 -3
  120. package/lib/debugInfo.js +0 -20
  121. package/lib/environment.d.ts +0 -1
  122. package/lib/environment.js +0 -13
  123. package/lib/hublValidate.d.ts +0 -2
  124. package/lib/hublValidate.js +0 -32
  125. package/lib/interpolationHelpers.d.ts +0 -10
  126. package/lib/interpolationHelpers.js +0 -34
  127. package/lib/projectLogsManager.d.ts +0 -1
  128. package/lib/prompts/activeInstallConfirmationPrompt.d.ts +0 -1
  129. package/lib/prompts/activeInstallConfirmationPrompt.js +0 -20
  130. package/lib/prompts/deployBuildIdPrompt.d.ts +0 -1
  131. package/lib/prompts/deployBuildIdPrompt.js +0 -22
  132. package/lib/prompts/feedbackPrompt.d.ts +0 -1
  133. package/lib/prompts/feedbackPrompt.js +0 -39
  134. package/lib/prompts/folderOverwritePrompt.d.ts +0 -1
  135. package/lib/prompts/folderOverwritePrompt.js +0 -17
  136. package/lib/regex.d.ts +0 -1
  137. package/lib/regex.js +0 -4
  138. /package/lib/{debugInfo.d.ts → ProjectLogsManager.d.ts} +0 -0
  139. /package/lib/{projectLogsManager.js → ProjectLogsManager.js} +0 -0
  140. /package/lib/{generate-selectors.d.ts → generateSelectors.d.ts} +0 -0
  141. /package/lib/{generate-selectors.js → generateSelectors.js} +0 -0
  142. /package/lib/{marketplace-validate.d.ts → marketplaceValidate.d.ts} +0 -0
  143. /package/lib/{marketplace-validate.js → marketplaceValidate.js} +0 -0
@@ -0,0 +1,158 @@
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.DiagnosticInfoBuilder = void 0;
7
+ const projects_1 = require("../projects");
8
+ const projects_2 = require("@hubspot/local-dev-lib/api/projects");
9
+ const path_1 = __importDefault(require("path"));
10
+ const package_json_1 = __importDefault(require("../../package.json"));
11
+ const logger_1 = require("@hubspot/local-dev-lib/logger");
12
+ const config_1 = require("@hubspot/local-dev-lib/config");
13
+ const config_2 = require("@hubspot/local-dev-lib/config");
14
+ const personalAccessKey_1 = require("@hubspot/local-dev-lib/personalAccessKey");
15
+ const fs_1 = require("@hubspot/local-dev-lib/fs");
16
+ const util_1 = __importDefault(require("util"));
17
+ const child_process_1 = require("child_process");
18
+ // This needs to be hardcoded since we are using it in the TS type
19
+ const hubspotCli = '@hubspot/cli';
20
+ const configFiles = [
21
+ 'serverless.json',
22
+ 'hsproject.json',
23
+ 'app.json',
24
+ 'public-app.json',
25
+ 'theme.json',
26
+ 'cms-assets.json',
27
+ ];
28
+ class DiagnosticInfoBuilder {
29
+ accountId;
30
+ env;
31
+ authType;
32
+ accountType;
33
+ personalAccessKey;
34
+ _projectConfig;
35
+ accessToken;
36
+ projectDetails;
37
+ files;
38
+ processInfo;
39
+ constructor(processInfo) {
40
+ this.accountId = (0, config_1.getAccountId)();
41
+ const accountConfig = (0, config_2.getAccountConfig)(this.accountId);
42
+ this.env = accountConfig?.env;
43
+ this.authType = accountConfig?.authType;
44
+ this.accountType = accountConfig?.accountType;
45
+ this.personalAccessKey = accountConfig?.personalAccessKey;
46
+ this.processInfo = processInfo;
47
+ }
48
+ async generateDiagnosticInfo() {
49
+ // @ts-expect-error getProjectConfig not typed yet
50
+ this._projectConfig = await (0, projects_1.getProjectConfig)();
51
+ if (this._projectConfig?.projectConfig) {
52
+ await this.fetchProjectDetails();
53
+ await this.fetchAccessToken();
54
+ await this.fetchProjectFilenames();
55
+ }
56
+ const { platform, arch, versions: { node }, mainModule, } = this.processInfo;
57
+ return {
58
+ platform,
59
+ arch,
60
+ path: mainModule?.path,
61
+ config: (0, config_2.getConfigPath)(),
62
+ versions: {
63
+ [hubspotCli]: package_json_1.default.version,
64
+ node,
65
+ npm: await this.getNpmVersion(),
66
+ },
67
+ account: {
68
+ accountId: this.accountId,
69
+ accountType: this.accountType,
70
+ authType: this.authType,
71
+ name: this.accessToken?.hubName,
72
+ scopeGroups: this.accessToken?.scopeGroups,
73
+ enabledFeatures: this.accessToken?.enabledFeatures,
74
+ },
75
+ project: {
76
+ config: this._projectConfig,
77
+ details: this.projectDetails,
78
+ },
79
+ ...this.generateFilesArrays(),
80
+ files: this.files || [],
81
+ };
82
+ }
83
+ async fetchProjectDetails() {
84
+ try {
85
+ const { data } = await (0, projects_2.fetchProject)(this.accountId, this._projectConfig?.projectConfig?.name);
86
+ this.projectDetails = data;
87
+ }
88
+ catch (e) {
89
+ logger_1.logger.debug(e);
90
+ }
91
+ }
92
+ async fetchAccessToken() {
93
+ try {
94
+ this.accessToken = await (0, personalAccessKey_1.getAccessToken)(this.personalAccessKey, this.env, this.accountId);
95
+ }
96
+ catch (e) {
97
+ logger_1.logger.debug(e);
98
+ }
99
+ return this.accessToken;
100
+ }
101
+ async fetchProjectFilenames() {
102
+ try {
103
+ this.files = (await (0, fs_1.walk)(this._projectConfig?.projectDir))
104
+ .filter(file => !path_1.default.dirname(file).includes('node_modules'))
105
+ .map(filename => path_1.default.relative(this._projectConfig?.projectDir, filename));
106
+ }
107
+ catch (e) {
108
+ logger_1.logger.debug(e);
109
+ }
110
+ }
111
+ async getNpmVersion() {
112
+ const exec = util_1.default.promisify(child_process_1.exec);
113
+ try {
114
+ const { stdout } = await exec('npm --version');
115
+ return stdout.toString().trim();
116
+ }
117
+ catch (e) {
118
+ logger_1.logger.debug(e);
119
+ return null;
120
+ }
121
+ }
122
+ generateFilesArrays() {
123
+ const output = {
124
+ files: this.files || [],
125
+ configFiles: [],
126
+ packageFiles: [],
127
+ packageLockFiles: [],
128
+ envFiles: [],
129
+ jsonFiles: [],
130
+ };
131
+ if (!this.files) {
132
+ return output;
133
+ }
134
+ return this.files.reduce((acc, file) => {
135
+ const { base } = path_1.default.parse(file);
136
+ if (base === 'package.json') {
137
+ acc.packageFiles.push(file);
138
+ }
139
+ else if (configFiles.includes(base)) {
140
+ acc.configFiles.push(file);
141
+ if (file.endsWith('.json')) {
142
+ acc.jsonFiles.push(file);
143
+ }
144
+ }
145
+ else if (base === 'package-lock.json') {
146
+ acc.packageLockFiles.push(file);
147
+ }
148
+ else if (file.endsWith('.env')) {
149
+ acc.envFiles.push(file);
150
+ }
151
+ else if (file.endsWith('.json')) {
152
+ acc.jsonFiles.push(file);
153
+ }
154
+ return acc;
155
+ }, output);
156
+ }
157
+ }
158
+ exports.DiagnosticInfoBuilder = DiagnosticInfoBuilder;
@@ -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;
@@ -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 {};
@@ -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
- // @ts-nocheck
4
- const helpers = require('./interpolationHelpers');
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
- const isHelperIdentifier = identifier => {
39
+ function isHelperIdentifier(identifier) {
16
40
  return (identifier.startsWith(delimiters.helpers.start) ||
17
41
  identifier.startsWith(delimiters.helpers.end));
18
- };
19
- const generateReplaceFn = (matchedText, startIndex, replacementString) => {
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
- const compileHelpers = stringValue => {
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 {};