@hubspot/cli 4.1.8-beta.3 → 4.1.8-beta.4
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/project/dev.js +6 -6
- package/lang/en.lyaml +3 -0
- package/lib/DevServerManager.js +74 -0
- package/lib/LocalDevManager.js +27 -23
- package/package.json +7 -5
package/commands/project/dev.js
CHANGED
|
@@ -47,7 +47,7 @@ const {
|
|
|
47
47
|
|
|
48
48
|
const i18nKey = 'cli.commands.project.subcommands.dev';
|
|
49
49
|
|
|
50
|
-
exports.command = 'dev [--account] [--
|
|
50
|
+
exports.command = 'dev [--account] [--port]';
|
|
51
51
|
exports.describe = null; //i18n(`${i18nKey}.describe`);
|
|
52
52
|
|
|
53
53
|
exports.handler = async options => {
|
|
@@ -271,11 +271,11 @@ exports.handler = async options => {
|
|
|
271
271
|
|
|
272
272
|
const LocalDev = new LocalDevManager({
|
|
273
273
|
debug: options.debug,
|
|
274
|
-
mockServers: options.mockServers,
|
|
275
274
|
projectConfig,
|
|
276
275
|
projectDir,
|
|
277
276
|
targetAccountId,
|
|
278
277
|
uploadPermission,
|
|
278
|
+
port: options.port,
|
|
279
279
|
});
|
|
280
280
|
|
|
281
281
|
await LocalDev.start();
|
|
@@ -289,11 +289,11 @@ exports.builder = yargs => {
|
|
|
289
289
|
addUseEnvironmentOptions(yargs, true);
|
|
290
290
|
addTestingOptions(yargs, true);
|
|
291
291
|
|
|
292
|
-
yargs.option('
|
|
293
|
-
describe:
|
|
294
|
-
type: '
|
|
295
|
-
default: false,
|
|
292
|
+
yargs.option('port', {
|
|
293
|
+
describe: i18n(`${i18nKey}.options.port.describe`),
|
|
294
|
+
type: 'number',
|
|
296
295
|
});
|
|
296
|
+
|
|
297
297
|
yargs.example([['$0 project dev', i18n(`${i18nKey}.examples.default`)]]);
|
|
298
298
|
|
|
299
299
|
return yargs;
|
package/lang/en.lyaml
CHANGED
|
@@ -465,6 +465,9 @@ en:
|
|
|
465
465
|
prompt:
|
|
466
466
|
createProject: "Create new project {{ projectName}} in {{#bold}}[{{ accountIdentifier }}]{{/bold}}?"
|
|
467
467
|
targetNonSandbox: "Continue testing in a non-sandbox account?"
|
|
468
|
+
options:
|
|
469
|
+
port:
|
|
470
|
+
describe: "The port that the running server will listen on"
|
|
468
471
|
errors:
|
|
469
472
|
noProjectConfig: "No project detected. Please run this command again from a project directory."
|
|
470
473
|
examples:
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
const bodyParser = require('body-parser');
|
|
3
|
+
const cors = require('cors');
|
|
4
|
+
const { getProjectDetailUrl } = require('./projects');
|
|
5
|
+
|
|
6
|
+
const DEFAULT_PORT = 8080;
|
|
7
|
+
|
|
8
|
+
class DevServerManager {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.server = null;
|
|
11
|
+
this.devServers = {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async iterateDevServers(callback) {
|
|
15
|
+
const serverKeys = Object.keys(this.devServers);
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < serverKeys.length; i++) {
|
|
18
|
+
const serverKey = serverKeys[i];
|
|
19
|
+
const serverInterface = this.devServers[serverKey];
|
|
20
|
+
await callback(serverInterface, serverKey);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async start({ projectConfig, accountId, port }) {
|
|
25
|
+
const app = express();
|
|
26
|
+
|
|
27
|
+
// Install Middleware
|
|
28
|
+
app.use(bodyParser.json({ limit: '50mb' }));
|
|
29
|
+
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
30
|
+
app.use(cors());
|
|
31
|
+
|
|
32
|
+
// Configure
|
|
33
|
+
app.set('trust proxy', true);
|
|
34
|
+
|
|
35
|
+
// Initialize a base route
|
|
36
|
+
app.get('/', (req, res) => {
|
|
37
|
+
res.send('HubSpot local dev server');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Initialize URL redirects
|
|
41
|
+
app.get('/hs/project', (req, res) => {
|
|
42
|
+
res.redirect(getProjectDetailUrl(projectConfig.name, accountId));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Initialize component servers
|
|
46
|
+
await this.iterateDevServers(async (serverInterface, serverKey) => {
|
|
47
|
+
if (serverInterface.start) {
|
|
48
|
+
const serverApp = await serverInterface.start(serverKey);
|
|
49
|
+
app.use(`/${serverKey}`, serverApp);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Start server
|
|
54
|
+
this.server = app.listen(port || DEFAULT_PORT);
|
|
55
|
+
|
|
56
|
+
return `http://localhost:${this.server.address().port}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async notify() {
|
|
60
|
+
return { uploadRequired: true };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async execute() {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async cleanup() {
|
|
68
|
+
if (this.server) {
|
|
69
|
+
await this.server.close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = new DevServerManager();
|
package/lib/LocalDevManager.js
CHANGED
|
@@ -22,11 +22,9 @@ const {
|
|
|
22
22
|
queueBuild,
|
|
23
23
|
} = require('@hubspot/cli-lib/api/dfs');
|
|
24
24
|
const SpinniesManager = require('./SpinniesManager');
|
|
25
|
+
const DevServerManager = require('./DevServerManager');
|
|
25
26
|
const { EXIT_CODES } = require('./enums/exitCodes');
|
|
26
|
-
const {
|
|
27
|
-
getProjectDetailUrl,
|
|
28
|
-
pollProjectBuildAndDeploy,
|
|
29
|
-
} = require('./projects');
|
|
27
|
+
const { pollProjectBuildAndDeploy } = require('./projects');
|
|
30
28
|
const { uiAccountDescription, uiLink } = require('./ui');
|
|
31
29
|
|
|
32
30
|
const i18nKey = 'cli.lib.LocalDevManager';
|
|
@@ -45,6 +43,7 @@ const UPLOAD_PERMISSIONS = {
|
|
|
45
43
|
manual: 'manual',
|
|
46
44
|
never: 'never',
|
|
47
45
|
};
|
|
46
|
+
|
|
48
47
|
class LocalDevManager {
|
|
49
48
|
constructor(options) {
|
|
50
49
|
this.targetAccountId = options.targetAccountId;
|
|
@@ -53,7 +52,6 @@ class LocalDevManager {
|
|
|
53
52
|
this.uploadPermission =
|
|
54
53
|
options.uploadPermission || UPLOAD_PERMISSIONS.always;
|
|
55
54
|
this.debug = options.debug || false;
|
|
56
|
-
this.mockServers = options.mockServers || false;
|
|
57
55
|
this.projectSourceDir = path.join(
|
|
58
56
|
this.projectDir,
|
|
59
57
|
this.projectConfig.srcDir
|
|
@@ -64,6 +62,8 @@ class LocalDevManager {
|
|
|
64
62
|
this.standbyChanges = [];
|
|
65
63
|
this.debouncedBuild = null;
|
|
66
64
|
this.currentStagedBuildId = null;
|
|
65
|
+
this.port = options.port;
|
|
66
|
+
this.devServerPath = null;
|
|
67
67
|
|
|
68
68
|
if (!this.targetAccountId || !this.projectConfig || !this.projectDir) {
|
|
69
69
|
process.exit(EXIT_CODES.ERROR);
|
|
@@ -90,8 +90,9 @@ class LocalDevManager {
|
|
|
90
90
|
|
|
91
91
|
this.uploadQueue.start();
|
|
92
92
|
|
|
93
|
-
this.logConsoleHeader();
|
|
94
93
|
await this.startServers();
|
|
94
|
+
|
|
95
|
+
this.logConsoleHeader();
|
|
95
96
|
await this.startWatching();
|
|
96
97
|
this.updateKeypressListeners();
|
|
97
98
|
}
|
|
@@ -159,14 +160,10 @@ class LocalDevManager {
|
|
|
159
160
|
indent: 1,
|
|
160
161
|
category: 'header',
|
|
161
162
|
});
|
|
162
|
-
const projectDetailUrl = getProjectDetailUrl(
|
|
163
|
-
this.projectConfig.name,
|
|
164
|
-
this.targetAccountId
|
|
165
|
-
);
|
|
166
163
|
this.spinnies.add('viewInHubSpotLink', {
|
|
167
164
|
text: uiLink(
|
|
168
165
|
i18n(`${i18nKey}.header.viewInHubSpotLink`),
|
|
169
|
-
|
|
166
|
+
this.generateLocalURL(`/hs/project`),
|
|
170
167
|
{
|
|
171
168
|
inSpinnies: true,
|
|
172
169
|
}
|
|
@@ -230,6 +227,10 @@ class LocalDevManager {
|
|
|
230
227
|
});
|
|
231
228
|
}
|
|
232
229
|
|
|
230
|
+
generateLocalURL(path) {
|
|
231
|
+
return this.devServerPath ? `${this.devServerPath}${path}` : null;
|
|
232
|
+
}
|
|
233
|
+
|
|
233
234
|
updateDevModeStatus(langKey) {
|
|
234
235
|
this.spinnies.update('devModeStatus', {
|
|
235
236
|
text: i18n(`${i18nKey}.header.status.${langKey}`),
|
|
@@ -297,11 +298,13 @@ class LocalDevManager {
|
|
|
297
298
|
remotePath: path.relative(this.projectSourceDir, filePath),
|
|
298
299
|
};
|
|
299
300
|
|
|
300
|
-
const
|
|
301
|
+
const notifyResponse = await this.notifyServers(changeInfo);
|
|
301
302
|
|
|
302
|
-
if (
|
|
303
|
+
if (!notifyResponse.uploadRequired) {
|
|
303
304
|
this.updateDevModeStatus('supportedChange');
|
|
304
305
|
this.addChangeToStandbyQueue({ ...changeInfo, supported: true });
|
|
306
|
+
|
|
307
|
+
await this.executeServers(notifyResponse, changeInfo);
|
|
305
308
|
return;
|
|
306
309
|
}
|
|
307
310
|
|
|
@@ -510,23 +513,24 @@ class LocalDevManager {
|
|
|
510
513
|
}
|
|
511
514
|
|
|
512
515
|
async startServers() {
|
|
513
|
-
|
|
514
|
-
|
|
516
|
+
this.devServerPath = await DevServerManager.start({
|
|
517
|
+
accountId: this.targetAccountId,
|
|
518
|
+
projectConfig: this.projectConfig,
|
|
519
|
+
port: this.port,
|
|
520
|
+
});
|
|
515
521
|
}
|
|
516
522
|
|
|
517
523
|
async notifyServers(changeInfo) {
|
|
518
|
-
const
|
|
524
|
+
const notifyResponse = await DevServerManager.notify(changeInfo);
|
|
525
|
+
return notifyResponse;
|
|
526
|
+
}
|
|
519
527
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
return !remotePath.endsWith('app.json');
|
|
523
|
-
}
|
|
524
|
-
return false;
|
|
528
|
+
async executeServers(notifyResponse, changeInfo) {
|
|
529
|
+
await DevServerManager.execute(notifyResponse, changeInfo);
|
|
525
530
|
}
|
|
526
531
|
|
|
527
532
|
async cleanupServers() {
|
|
528
|
-
|
|
529
|
-
return;
|
|
533
|
+
await DevServerManager.cleanup();
|
|
530
534
|
}
|
|
531
535
|
}
|
|
532
536
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cli",
|
|
3
|
-
"version": "4.1.8-beta.
|
|
3
|
+
"version": "4.1.8-beta.4",
|
|
4
4
|
"description": "CLI for working with HubSpot",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
"url": "https://github.com/HubSpot/hubspot-cms-tools"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@hubspot/cli-lib": "4.1.
|
|
12
|
-
"@hubspot/serverless-dev-runtime": "4.1.8-beta.
|
|
11
|
+
"@hubspot/cli-lib": "^4.1.12",
|
|
12
|
+
"@hubspot/serverless-dev-runtime": "4.1.8-beta.4",
|
|
13
13
|
"archiver": "^5.3.0",
|
|
14
|
+
"body-parser": "^1.19.0",
|
|
14
15
|
"chalk": "^4.1.2",
|
|
15
16
|
"chokidar": "^3.0.1",
|
|
16
17
|
"cli-progress": "^3.11.2",
|
|
18
|
+
"cors": "^2.8.5",
|
|
17
19
|
"express": "^4.17.1",
|
|
18
20
|
"findup-sync": "^4.0.0",
|
|
19
21
|
"fs-extra": "^8.1.0",
|
|
20
|
-
"inquirer": "
|
|
22
|
+
"inquirer": "8.2.0",
|
|
21
23
|
"js-yaml": "^4.1.0",
|
|
22
24
|
"moment": "^2.29.1",
|
|
23
25
|
"open": "^7.0.3",
|
|
@@ -41,5 +43,5 @@
|
|
|
41
43
|
"publishConfig": {
|
|
42
44
|
"access": "public"
|
|
43
45
|
},
|
|
44
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "650d373d034efb5736b357200fc496d5da605e37"
|
|
45
47
|
}
|