@hubspot/cli 4.2.1-beta.2 → 4.2.1-beta.3
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/commands/accounts/clean.js +139 -0
- package/commands/accounts.js +2 -0
- package/commands/project/dev.js +68 -105
- package/commands/project/download.js +10 -19
- package/commands/sandbox/delete.js +2 -2
- package/commands/sandbox.js +3 -2
- package/lang/en.lyaml +33 -56
- package/lib/DevServerManager.js +18 -67
- package/lib/LocalDevManager.js +240 -569
- package/lib/SpinniesManager.js +2 -82
- package/lib/projectStructure.js +1 -0
- package/lib/projects.js +38 -19
- package/lib/prompts/downloadProjectPrompt.js +1 -4
- package/lib/prompts/projectDevTargetAccountPrompt.js +15 -0
- package/lib/ui.js +9 -2
- package/package.json +5 -8
- package/lib/LocalDevManagerV2.js +0 -239
package/lib/SpinniesManager.js
CHANGED
|
@@ -60,30 +60,6 @@ class SpinniesManager {
|
|
|
60
60
|
this.stream = process.stderr;
|
|
61
61
|
this.lineCount = 0;
|
|
62
62
|
this.currentFrameIndex = 0;
|
|
63
|
-
|
|
64
|
-
// Custom fields
|
|
65
|
-
this.parentSpinnerName = null;
|
|
66
|
-
this.categories = {};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
addSpinnerToCategory(name, category) {
|
|
70
|
-
if (!this.categories[category]) {
|
|
71
|
-
this.categories[category] = {};
|
|
72
|
-
}
|
|
73
|
-
this.categories[category][name] = true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getSpinnerCategory(name) {
|
|
77
|
-
return Object.keys(this.categories).find(
|
|
78
|
-
category => !!this.categories[category][name]
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
removeSpinnerFromCategory(name) {
|
|
83
|
-
const category = this.getSpinnerCategory(name);
|
|
84
|
-
if (category) {
|
|
85
|
-
delete this.categories[category][name];
|
|
86
|
-
}
|
|
87
63
|
}
|
|
88
64
|
|
|
89
65
|
pick(name) {
|
|
@@ -91,40 +67,24 @@ class SpinniesManager {
|
|
|
91
67
|
}
|
|
92
68
|
|
|
93
69
|
add(name, options = {}) {
|
|
94
|
-
const { category, isParent, noIndent, ...spinnerOptions } = options;
|
|
95
|
-
|
|
96
70
|
// Support adding generic spinnies lines without specifying a name
|
|
97
71
|
const resolvedName = name || `${Date.now()}-${Math.random()}`;
|
|
98
72
|
|
|
99
|
-
if (category) {
|
|
100
|
-
this.addSpinnerToCategory(resolvedName, category);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
73
|
if (!options.text) {
|
|
104
|
-
|
|
74
|
+
options.text = resolvedName;
|
|
105
75
|
}
|
|
106
76
|
|
|
107
|
-
const originalIndent = spinnerOptions.indent || 0;
|
|
108
|
-
|
|
109
77
|
const spinnerProperties = {
|
|
110
78
|
...colorOptions(this.options),
|
|
111
79
|
succeedPrefix: this.options.succeedPrefix,
|
|
112
80
|
failPrefix: this.options.failPrefix,
|
|
113
81
|
status: 'spinning',
|
|
114
|
-
...purgeSpinnerOptions(
|
|
115
|
-
indent:
|
|
116
|
-
this.parentSpinnerName && !noIndent
|
|
117
|
-
? originalIndent + 1
|
|
118
|
-
: originalIndent,
|
|
82
|
+
...purgeSpinnerOptions(options),
|
|
119
83
|
};
|
|
120
84
|
|
|
121
85
|
this.spinners[resolvedName] = spinnerProperties;
|
|
122
86
|
this.updateSpinnerState();
|
|
123
87
|
|
|
124
|
-
if (isParent) {
|
|
125
|
-
this.parentSpinnerName = resolvedName;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
88
|
return { name: resolvedName, ...spinnerProperties };
|
|
129
89
|
}
|
|
130
90
|
|
|
@@ -136,20 +96,6 @@ class SpinniesManager {
|
|
|
136
96
|
return this.spinners[name];
|
|
137
97
|
}
|
|
138
98
|
|
|
139
|
-
// TODO there is an issue here with the usage of "non-spinnable"
|
|
140
|
-
// The spinnies lib automatically removes any non-active spinners
|
|
141
|
-
// after adding a new spinner (add -> updateSpinnerState -> checkIfActiveSpinners)
|
|
142
|
-
// so "pick" is telling us that these newly-added spinners don't exist.
|
|
143
|
-
addOrUpdate(name, options = {}) {
|
|
144
|
-
const spinner = this.pick(name);
|
|
145
|
-
|
|
146
|
-
if (spinner) {
|
|
147
|
-
this.update(name, options);
|
|
148
|
-
} else {
|
|
149
|
-
this.add(name, options);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
99
|
succeed(name, options = {}) {
|
|
154
100
|
this.setSpinnerProperties(name, options, 'succeed');
|
|
155
101
|
this.updateSpinnerState();
|
|
@@ -169,37 +115,11 @@ class SpinniesManager {
|
|
|
169
115
|
throw Error('A spinner reference name must be specified');
|
|
170
116
|
}
|
|
171
117
|
|
|
172
|
-
if (name === this.parentSpinnerName) {
|
|
173
|
-
this.parentSpinnerName = null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
this.removeSpinnerFromCategory(name);
|
|
177
|
-
|
|
178
118
|
const spinner = this.spinners[name];
|
|
179
119
|
delete this.spinners[name];
|
|
180
120
|
return spinner;
|
|
181
121
|
}
|
|
182
122
|
|
|
183
|
-
/**
|
|
184
|
-
* Removes all spinnies instances
|
|
185
|
-
* @param {string} targetCategory - remove all spinnies with a matching category
|
|
186
|
-
* @param {string} preserveCategory - do not remove spinnies with a matching category
|
|
187
|
-
*/
|
|
188
|
-
removeAll({ preserveCategory = null, targetCategory = null } = {}) {
|
|
189
|
-
Object.keys(this.spinners).forEach(name => {
|
|
190
|
-
if (targetCategory) {
|
|
191
|
-
if (this.getSpinnerCategory(name) === targetCategory) {
|
|
192
|
-
this.remove(name);
|
|
193
|
-
}
|
|
194
|
-
} else if (
|
|
195
|
-
!preserveCategory ||
|
|
196
|
-
this.getSpinnerCategory(name) !== preserveCategory
|
|
197
|
-
) {
|
|
198
|
-
this.remove(name);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
123
|
stopAll(newStatus = 'stopped') {
|
|
204
124
|
Object.keys(this.spinners).forEach(name => {
|
|
205
125
|
const { status: currentStatus } = this.spinners[name];
|
package/lib/projectStructure.js
CHANGED
package/lib/projects.js
CHANGED
|
@@ -43,6 +43,7 @@ const { i18n } = require('./lang');
|
|
|
43
43
|
const SpinniesManager = require('./SpinniesManager');
|
|
44
44
|
const {
|
|
45
45
|
isSpecifiedError,
|
|
46
|
+
isSpecifiedHubSpotAuthError,
|
|
46
47
|
} = require('@hubspot/cli-lib/errorHandlers/apiErrors');
|
|
47
48
|
|
|
48
49
|
const i18nKey = 'cli.lib.projects';
|
|
@@ -184,7 +185,9 @@ const pollFetchProject = async (accountId, projectName) => {
|
|
|
184
185
|
let pollCount = 0;
|
|
185
186
|
SpinniesManager.init();
|
|
186
187
|
SpinniesManager.add('pollFetchProject', {
|
|
187
|
-
text:
|
|
188
|
+
text: i18n(`${i18nKey}.pollFetchProject.checkingProject`, {
|
|
189
|
+
accountIdentifier: uiAccountDescription(accountId),
|
|
190
|
+
}),
|
|
188
191
|
});
|
|
189
192
|
const pollInterval = setInterval(async () => {
|
|
190
193
|
try {
|
|
@@ -200,14 +203,10 @@ const pollFetchProject = async (accountId, projectName) => {
|
|
|
200
203
|
statusCode: 403,
|
|
201
204
|
category: 'GATED',
|
|
202
205
|
subCategory: 'BuildPipelineErrorType.PORTAL_GATED',
|
|
203
|
-
})
|
|
206
|
+
}) &&
|
|
207
|
+
pollCount < 15
|
|
204
208
|
) {
|
|
205
209
|
pollCount += 1;
|
|
206
|
-
} else if (pollCount >= 15) {
|
|
207
|
-
// Poll up to max 30s
|
|
208
|
-
SpinniesManager.remove('pollFetchProject');
|
|
209
|
-
clearInterval(pollInterval);
|
|
210
|
-
reject(err);
|
|
211
210
|
} else {
|
|
212
211
|
SpinniesManager.remove('pollFetchProject');
|
|
213
212
|
clearInterval(pollInterval);
|
|
@@ -280,6 +279,14 @@ const ensureProjectExists = async (
|
|
|
280
279
|
return false;
|
|
281
280
|
}
|
|
282
281
|
}
|
|
282
|
+
if (
|
|
283
|
+
isSpecifiedHubSpotAuthError(err, {
|
|
284
|
+
statusCode: 401,
|
|
285
|
+
})
|
|
286
|
+
) {
|
|
287
|
+
logger.error(err.message);
|
|
288
|
+
process.exit(EXIT_CODES.ERROR);
|
|
289
|
+
}
|
|
283
290
|
logApiErrorInstance(err, new ApiErrorContext({ accountId, projectName }));
|
|
284
291
|
process.exit(EXIT_CODES.ERROR);
|
|
285
292
|
}
|
|
@@ -566,7 +573,6 @@ const makePollTaskStatusFunc = ({
|
|
|
566
573
|
succeedColor: 'white',
|
|
567
574
|
failColor: 'white',
|
|
568
575
|
failPrefix: chalk.bold('!'),
|
|
569
|
-
category: 'projectPollStatus',
|
|
570
576
|
});
|
|
571
577
|
|
|
572
578
|
const [
|
|
@@ -608,7 +614,10 @@ const makePollTaskStatusFunc = ({
|
|
|
608
614
|
) + '\n';
|
|
609
615
|
|
|
610
616
|
SpinniesManager.update(overallTaskSpinniesKey, {
|
|
611
|
-
text: `${statusStrings.INITIALIZE(
|
|
617
|
+
text: `${statusStrings.INITIALIZE(
|
|
618
|
+
taskName,
|
|
619
|
+
displayId
|
|
620
|
+
)}\n${componentCountText}`,
|
|
612
621
|
});
|
|
613
622
|
|
|
614
623
|
if (!silenceLogs) {
|
|
@@ -627,7 +636,6 @@ const makePollTaskStatusFunc = ({
|
|
|
627
636
|
indent,
|
|
628
637
|
succeedColor: 'white',
|
|
629
638
|
failColor: 'white',
|
|
630
|
-
category: 'projectPollStatus',
|
|
631
639
|
});
|
|
632
640
|
};
|
|
633
641
|
|
|
@@ -688,11 +696,11 @@ const makePollTaskStatusFunc = ({
|
|
|
688
696
|
if (isTaskComplete(taskStatus)) {
|
|
689
697
|
if (status === statusText.STATES.SUCCESS) {
|
|
690
698
|
SpinniesManager.succeed(overallTaskSpinniesKey, {
|
|
691
|
-
text: statusStrings.SUCCESS(taskName),
|
|
699
|
+
text: statusStrings.SUCCESS(taskName, displayId),
|
|
692
700
|
});
|
|
693
701
|
} else if (status === statusText.STATES.FAILURE) {
|
|
694
702
|
SpinniesManager.fail(overallTaskSpinniesKey, {
|
|
695
|
-
text: statusStrings.FAIL(taskName),
|
|
703
|
+
text: statusStrings.FAIL(taskName, displayId),
|
|
696
704
|
});
|
|
697
705
|
|
|
698
706
|
if (!silenceLogs) {
|
|
@@ -712,7 +720,13 @@ const makePollTaskStatusFunc = ({
|
|
|
712
720
|
logger.log('See below for a summary of errors.');
|
|
713
721
|
uiLine();
|
|
714
722
|
|
|
715
|
-
failedSubtasks.
|
|
723
|
+
const displayErrors = failedSubtasks.filter(
|
|
724
|
+
subtask =>
|
|
725
|
+
subtask.standardError.subCategory !==
|
|
726
|
+
'BuildPipelineErrorType.DEPENDENT_SUBBUILD_FAILED'
|
|
727
|
+
);
|
|
728
|
+
|
|
729
|
+
displayErrors.forEach(subTask => {
|
|
716
730
|
logger.log(
|
|
717
731
|
`\n--- ${chalk.bold(
|
|
718
732
|
subTask[statusText.SUBTASK_NAME_KEY]
|
|
@@ -749,9 +763,9 @@ const pollBuildStatus = makePollTaskStatusFunc({
|
|
|
749
763
|
structureFn: getBuildStructure,
|
|
750
764
|
statusText: PROJECT_BUILD_TEXT,
|
|
751
765
|
statusStrings: {
|
|
752
|
-
INITIALIZE: name => `Building ${chalk.bold(name)}`,
|
|
753
|
-
SUCCESS: name => `Built ${chalk.bold(name)}`,
|
|
754
|
-
FAIL: name => `Failed to build ${chalk.bold(name)}`,
|
|
766
|
+
INITIALIZE: (name, buildId) => `Building ${chalk.bold(name)} #${buildId}`,
|
|
767
|
+
SUCCESS: (name, buildId) => `Built ${chalk.bold(name)} #${buildId}`,
|
|
768
|
+
FAIL: (name, buildId) => `Failed to build ${chalk.bold(name)} #${buildId}`,
|
|
755
769
|
SUBTASK_FAIL: (buildId, name) =>
|
|
756
770
|
`Build #${buildId} failed because there was a problem\nbuilding ${chalk.bold(
|
|
757
771
|
name
|
|
@@ -769,9 +783,12 @@ const pollDeployStatus = makePollTaskStatusFunc({
|
|
|
769
783
|
structureFn: getDeployStructure,
|
|
770
784
|
statusText: PROJECT_DEPLOY_TEXT,
|
|
771
785
|
statusStrings: {
|
|
772
|
-
INITIALIZE: name =>
|
|
773
|
-
|
|
774
|
-
|
|
786
|
+
INITIALIZE: (name, buildId) =>
|
|
787
|
+
`Deploying build #${buildId} in ${chalk.bold(name)}`,
|
|
788
|
+
SUCCESS: (name, buildId) =>
|
|
789
|
+
`Deployed build #${buildId} in ${chalk.bold(name)}`,
|
|
790
|
+
FAIL: (name, buildId) =>
|
|
791
|
+
`Failed to deploy build #${buildId} in ${chalk.bold(name)}`,
|
|
775
792
|
SUBTASK_FAIL: (deployedBuildId, name) =>
|
|
776
793
|
`Deploy for build #${deployedBuildId} failed because there was a\nproblem deploying ${chalk.bold(
|
|
777
794
|
name
|
|
@@ -825,11 +842,13 @@ const showPlatformVersionWarning = async (accountId, projectConfig) => {
|
|
|
825
842
|
defaultVersion,
|
|
826
843
|
})
|
|
827
844
|
);
|
|
845
|
+
logger.log('');
|
|
828
846
|
} catch (e) {
|
|
829
847
|
logger.log('');
|
|
830
848
|
logger.warn(
|
|
831
849
|
i18n(`${i18nKey}.showPlatformVersionWarning.noPlatformVersionAlt`)
|
|
832
850
|
);
|
|
851
|
+
logger.log('');
|
|
833
852
|
logger.debug(e.error);
|
|
834
853
|
}
|
|
835
854
|
}
|
|
@@ -5,7 +5,6 @@ const {
|
|
|
5
5
|
logApiErrorInstance,
|
|
6
6
|
ApiErrorContext,
|
|
7
7
|
} = require('@hubspot/cli-lib/errorHandlers');
|
|
8
|
-
const { getProjectConfig } = require('../projects');
|
|
9
8
|
const { EXIT_CODES } = require('../enums/exitCodes');
|
|
10
9
|
const { i18n } = require('../lang');
|
|
11
10
|
|
|
@@ -13,14 +12,12 @@ const i18nKey = 'cli.lib.prompts.downloadProjectPrompt';
|
|
|
13
12
|
|
|
14
13
|
const createProjectsList = async () => {
|
|
15
14
|
const accountId = getAccountId();
|
|
16
|
-
const { projectConfig } = await getProjectConfig();
|
|
17
|
-
const projectName = projectConfig.name;
|
|
18
15
|
|
|
19
16
|
try {
|
|
20
17
|
const projects = await fetchProjects(accountId);
|
|
21
18
|
return projects.results;
|
|
22
19
|
} catch (e) {
|
|
23
|
-
logApiErrorInstance(e, new ApiErrorContext({ accountId
|
|
20
|
+
logApiErrorInstance(e, new ApiErrorContext({ accountId }));
|
|
24
21
|
process.exit(EXIT_CODES.ERROR);
|
|
25
22
|
}
|
|
26
23
|
};
|
|
@@ -74,6 +74,21 @@ const selectTargetAccountPrompt = async (accounts, defaultAccountConfig) => {
|
|
|
74
74
|
return targetAccountInfo;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
const confirmDefaultSandboxAccountPrompt = async (accountName, accountType) => {
|
|
78
|
+
const { useDefaultAccount } = await promptUser([
|
|
79
|
+
{
|
|
80
|
+
name: 'useDefaultAccount',
|
|
81
|
+
type: 'confirm',
|
|
82
|
+
message: i18n(`${i18nKey}.confirmDefaultSandboxAccount`, {
|
|
83
|
+
accountName,
|
|
84
|
+
accountType,
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
return useDefaultAccount;
|
|
89
|
+
};
|
|
90
|
+
|
|
77
91
|
module.exports = {
|
|
78
92
|
selectTargetAccountPrompt,
|
|
93
|
+
confirmDefaultSandboxAccountPrompt,
|
|
79
94
|
};
|
package/lib/ui.js
CHANGED
|
@@ -7,7 +7,9 @@ const { i18n } = require('./lang');
|
|
|
7
7
|
const { logger } = require('@hubspot/cli-lib/logger');
|
|
8
8
|
|
|
9
9
|
const UI_COLORS = {
|
|
10
|
-
|
|
10
|
+
SORBET: '#FF8F59',
|
|
11
|
+
MARIGOLD: '#f5c26b',
|
|
12
|
+
MARIGOLD_DARK: '#dbae60',
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -92,6 +94,10 @@ const uiInfoSection = (title, logContent) => {
|
|
|
92
94
|
uiLine();
|
|
93
95
|
};
|
|
94
96
|
|
|
97
|
+
const uiCommandReference = command => {
|
|
98
|
+
return chalk.bold(chalk.hex(UI_COLORS.MARIGOLD_DARK)(`\`${command}\``));
|
|
99
|
+
};
|
|
100
|
+
|
|
95
101
|
const uiFeatureHighlight = (commands, title) => {
|
|
96
102
|
const i18nKey = 'cli.lib.ui.featureHighlight';
|
|
97
103
|
|
|
@@ -112,7 +118,7 @@ const uiFeatureHighlight = (commands, title) => {
|
|
|
112
118
|
const uiBetaMessage = message => {
|
|
113
119
|
const i18nKey = 'cli.lib.ui';
|
|
114
120
|
|
|
115
|
-
logger.log(chalk.hex(UI_COLORS.
|
|
121
|
+
logger.log(chalk.hex(UI_COLORS.SORBET)(i18n(`${i18nKey}.betaTag`)), message);
|
|
116
122
|
};
|
|
117
123
|
|
|
118
124
|
const uiBetaWarning = logMessage => {
|
|
@@ -126,6 +132,7 @@ const uiBetaWarning = logMessage => {
|
|
|
126
132
|
module.exports = {
|
|
127
133
|
UI_COLORS,
|
|
128
134
|
uiAccountDescription,
|
|
135
|
+
uiCommandReference,
|
|
129
136
|
uiBetaMessage,
|
|
130
137
|
uiBetaWarning,
|
|
131
138
|
uiFeatureHighlight,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cli",
|
|
3
|
-
"version": "4.2.1-beta.
|
|
3
|
+
"version": "4.2.1-beta.3",
|
|
4
4
|
"description": "CLI for working with HubSpot",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -8,16 +8,14 @@
|
|
|
8
8
|
"url": "https://github.com/HubSpot/hubspot-cms-tools"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@hubspot/cli-lib": "^4.2.
|
|
12
|
-
"@hubspot/serverless-dev-runtime": "4.2.1-beta.
|
|
13
|
-
"@hubspot/ui-extensions-dev-server": "^0.
|
|
11
|
+
"@hubspot/cli-lib": "^4.2.2",
|
|
12
|
+
"@hubspot/serverless-dev-runtime": "4.2.1-beta.3",
|
|
13
|
+
"@hubspot/ui-extensions-dev-server": "^0.7.0",
|
|
14
14
|
"archiver": "^5.3.0",
|
|
15
|
-
"body-parser": "^1.19.0",
|
|
16
15
|
"chalk": "^4.1.2",
|
|
17
16
|
"chokidar": "^3.0.1",
|
|
18
17
|
"cli-cursor": "^3.1.0",
|
|
19
18
|
"cli-progress": "^3.11.2",
|
|
20
|
-
"cors": "^2.8.5",
|
|
21
19
|
"express": "^4.17.1",
|
|
22
20
|
"findup-sync": "^4.0.0",
|
|
23
21
|
"fs-extra": "^8.1.0",
|
|
@@ -26,7 +24,6 @@
|
|
|
26
24
|
"moment": "^2.29.1",
|
|
27
25
|
"open": "^7.0.3",
|
|
28
26
|
"ora": "^4.0.3",
|
|
29
|
-
"p-queue": "^6.0.2",
|
|
30
27
|
"strip-ansi": "^5.2.0",
|
|
31
28
|
"tmp": "^0.2.1",
|
|
32
29
|
"update-notifier": "^5.1.0",
|
|
@@ -45,5 +42,5 @@
|
|
|
45
42
|
"publishConfig": {
|
|
46
43
|
"access": "public"
|
|
47
44
|
},
|
|
48
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "e3e46fab20a9efb8c4c98f88b2aed1d13e6d0b1d"
|
|
49
46
|
}
|
package/lib/LocalDevManagerV2.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
const { i18n } = require('./lang');
|
|
4
|
-
const { logger } = require('@hubspot/cli-lib/logger');
|
|
5
|
-
const { handleKeypress } = require('@hubspot/cli-lib/lib/process');
|
|
6
|
-
const {
|
|
7
|
-
getAccountId,
|
|
8
|
-
getConfigDefaultAccount,
|
|
9
|
-
} = require('@hubspot/cli-lib/lib/config');
|
|
10
|
-
const SpinniesManager = require('./SpinniesManager');
|
|
11
|
-
const DevServerManager = require('./DevServerManager');
|
|
12
|
-
const { EXIT_CODES } = require('./enums/exitCodes');
|
|
13
|
-
const { getProjectDetailUrl } = require('./projects');
|
|
14
|
-
const {
|
|
15
|
-
COMPONENT_TYPES,
|
|
16
|
-
findProjectComponents,
|
|
17
|
-
getAppCardConfigs,
|
|
18
|
-
} = require('./projectStructure');
|
|
19
|
-
const {
|
|
20
|
-
UI_COLORS,
|
|
21
|
-
uiAccountDescription,
|
|
22
|
-
uiBetaMessage,
|
|
23
|
-
uiLink,
|
|
24
|
-
uiLine,
|
|
25
|
-
} = require('./ui');
|
|
26
|
-
|
|
27
|
-
const i18nKey = 'cli.lib.LocalDevManagerV2';
|
|
28
|
-
|
|
29
|
-
class LocalDevManagerV2 {
|
|
30
|
-
constructor(options) {
|
|
31
|
-
this.targetAccountId = options.targetAccountId;
|
|
32
|
-
this.projectConfig = options.projectConfig;
|
|
33
|
-
this.projectDir = options.projectDir;
|
|
34
|
-
this.debug = options.debug || false;
|
|
35
|
-
this.alpha = options.alpha;
|
|
36
|
-
this.deployedBuild = options.deployedBuild;
|
|
37
|
-
|
|
38
|
-
this.projectSourceDir = path.join(
|
|
39
|
-
this.projectDir,
|
|
40
|
-
this.projectConfig.srcDir
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
if (!this.targetAccountId || !this.projectConfig || !this.projectDir) {
|
|
44
|
-
logger.log(i18n(`${i18nKey}.failedToInitialize`));
|
|
45
|
-
process.exit(EXIT_CODES.ERROR);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async start() {
|
|
50
|
-
SpinniesManager.removeAll();
|
|
51
|
-
SpinniesManager.init();
|
|
52
|
-
|
|
53
|
-
const components = await findProjectComponents(this.projectSourceDir);
|
|
54
|
-
|
|
55
|
-
if (!components.length) {
|
|
56
|
-
logger.log();
|
|
57
|
-
logger.error(i18n(`${i18nKey}.noComponents`));
|
|
58
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const runnableComponents = components.filter(
|
|
62
|
-
component => component.runnable
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
if (!runnableComponents.length) {
|
|
66
|
-
logger.log();
|
|
67
|
-
logger.error(i18n(`${i18nKey}.noRunnableComponents`));
|
|
68
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
logger.log();
|
|
72
|
-
const setupSucceeded = await this.devServerSetup(runnableComponents);
|
|
73
|
-
|
|
74
|
-
if (setupSucceeded || !this.debug) {
|
|
75
|
-
console.clear();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
uiBetaMessage(i18n(`${i18nKey}.betaMessage`));
|
|
79
|
-
logger.log();
|
|
80
|
-
logger.log(
|
|
81
|
-
chalk.hex(UI_COLORS.orange)(
|
|
82
|
-
i18n(`${i18nKey}.running`, {
|
|
83
|
-
accountIdentifier: uiAccountDescription(this.targetAccountId),
|
|
84
|
-
projectName: this.projectConfig.name,
|
|
85
|
-
})
|
|
86
|
-
)
|
|
87
|
-
);
|
|
88
|
-
logger.log(
|
|
89
|
-
uiLink(
|
|
90
|
-
i18n(`${i18nKey}.viewInHubSpotLink`),
|
|
91
|
-
getProjectDetailUrl(this.projectConfig.name, this.targetAccountId)
|
|
92
|
-
)
|
|
93
|
-
);
|
|
94
|
-
logger.log();
|
|
95
|
-
logger.log(i18n(`${i18nKey}.quitHelper`));
|
|
96
|
-
uiLine();
|
|
97
|
-
logger.log();
|
|
98
|
-
|
|
99
|
-
await this.devServerStart();
|
|
100
|
-
|
|
101
|
-
this.updateKeypressListeners();
|
|
102
|
-
|
|
103
|
-
this.compareLocalProjectToDeployed(runnableComponents);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async stop() {
|
|
107
|
-
SpinniesManager.add('cleanupMessage', {
|
|
108
|
-
text: i18n(`${i18nKey}.exitingStart`),
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const cleanupSucceeded = await this.devServerCleanup();
|
|
112
|
-
|
|
113
|
-
if (!cleanupSucceeded) {
|
|
114
|
-
SpinniesManager.fail('cleanupMessage', {
|
|
115
|
-
text: i18n(`${i18nKey}.exitingFail`),
|
|
116
|
-
});
|
|
117
|
-
process.exit(EXIT_CODES.ERROR);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
SpinniesManager.succeed('cleanupMessage', {
|
|
121
|
-
text: i18n(`${i18nKey}.exitingSucceed`),
|
|
122
|
-
});
|
|
123
|
-
process.exit(EXIT_CODES.SUCCESS);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
updateKeypressListeners() {
|
|
127
|
-
handleKeypress(async key => {
|
|
128
|
-
if ((key.ctrl && key.name === 'c') || key.name === 'q') {
|
|
129
|
-
this.stop();
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
logUploadWarning(reason) {
|
|
135
|
-
const currentDefaultAccount = getConfigDefaultAccount();
|
|
136
|
-
const defaultAccountId = getAccountId(currentDefaultAccount);
|
|
137
|
-
|
|
138
|
-
logger.log();
|
|
139
|
-
logger.warn(i18n(`${i18nKey}.uploadWarning.header`, { reason }));
|
|
140
|
-
logger.log(i18n(`${i18nKey}.uploadWarning.stopDev`));
|
|
141
|
-
if (this.targetAccountId !== defaultAccountId) {
|
|
142
|
-
logger.log(
|
|
143
|
-
i18n(`${i18nKey}.uploadWarning.runUploadWithAccount`, {
|
|
144
|
-
accountId: this.targetAccountId,
|
|
145
|
-
})
|
|
146
|
-
);
|
|
147
|
-
} else {
|
|
148
|
-
logger.log(i18n(`${i18nKey}.uploadWarning.runUpload`));
|
|
149
|
-
}
|
|
150
|
-
logger.log(i18n(`${i18nKey}.uploadWarning.restartDev`));
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
compareLocalProjectToDeployed(runnableComponents) {
|
|
154
|
-
const deployedComponentNames = this.deployedBuild.subbuildStatuses.map(
|
|
155
|
-
subbuildStatus => subbuildStatus.buildName
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
let missingComponents = [];
|
|
159
|
-
|
|
160
|
-
runnableComponents.forEach(({ type, config, path }) => {
|
|
161
|
-
if (type === COMPONENT_TYPES.app) {
|
|
162
|
-
const cardConfigs = getAppCardConfigs(config, path);
|
|
163
|
-
|
|
164
|
-
cardConfigs.forEach(cardConfig => {
|
|
165
|
-
if (
|
|
166
|
-
cardConfig.data &&
|
|
167
|
-
cardConfig.data.title &&
|
|
168
|
-
!deployedComponentNames.includes(cardConfig.data.title)
|
|
169
|
-
) {
|
|
170
|
-
missingComponents.push(cardConfig.data.title);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
if (missingComponents.length) {
|
|
177
|
-
this.logUploadWarning(
|
|
178
|
-
i18n(`${i18nKey}.uploadWarning.missingComponents`, {
|
|
179
|
-
missingComponents: missingComponents.join(','),
|
|
180
|
-
})
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
async devServerSetup(components) {
|
|
186
|
-
try {
|
|
187
|
-
await DevServerManager.setup({
|
|
188
|
-
alpha: this.alpha,
|
|
189
|
-
components,
|
|
190
|
-
debug: this.debug,
|
|
191
|
-
onUploadRequired: this.logUploadWarning.bind(this),
|
|
192
|
-
});
|
|
193
|
-
return true;
|
|
194
|
-
} catch (e) {
|
|
195
|
-
if (this.debug) {
|
|
196
|
-
logger.error(e);
|
|
197
|
-
}
|
|
198
|
-
logger.error(
|
|
199
|
-
i18n(`${i18nKey}.devServer.setupError`, { message: e.message })
|
|
200
|
-
);
|
|
201
|
-
return false;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
async devServerStart() {
|
|
206
|
-
try {
|
|
207
|
-
await DevServerManager.start({
|
|
208
|
-
alpha: this.alpha,
|
|
209
|
-
accountId: this.targetAccountId,
|
|
210
|
-
projectConfig: this.projectConfig,
|
|
211
|
-
});
|
|
212
|
-
} catch (e) {
|
|
213
|
-
if (this.debug) {
|
|
214
|
-
logger.error(e);
|
|
215
|
-
}
|
|
216
|
-
logger.error(
|
|
217
|
-
i18n(`${i18nKey}.devServer.startError`, { message: e.message })
|
|
218
|
-
);
|
|
219
|
-
process.exit(EXIT_CODES.ERROR);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async devServerCleanup() {
|
|
224
|
-
try {
|
|
225
|
-
await DevServerManager.cleanup();
|
|
226
|
-
return true;
|
|
227
|
-
} catch (e) {
|
|
228
|
-
if (this.debug) {
|
|
229
|
-
logger.error(e);
|
|
230
|
-
}
|
|
231
|
-
logger.error(
|
|
232
|
-
i18n(`${i18nKey}.devServer.cleanupError`, { message: e.message })
|
|
233
|
-
);
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
module.exports = LocalDevManagerV2;
|