@hubspot/cms-dev-server 0.4.2 → 0.4.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/dist/index.js +36 -6
- package/dist/internalSsr.js +87 -12
- package/dist/run.js +174 -45
- package/package.json +4 -4
- package/types/createViteDevServer.d.ts +1 -1
- package/dist/components/ModulesList.js +0 -14
- package/dist/components/PartialsList.js +0 -13
- package/dist/createDevServer.js +0 -164
- package/dist/createDevServerConfiguration.js +0 -155
- package/dist/createViteDevServer.js +0 -52
- package/dist/lib/cli.js +0 -27
- package/dist/lib/debug.js +0 -2
- package/dist/lib/errors.js +0 -22
- package/dist/lib/fullOriginalUrlFromRequest.js +0 -3
- package/dist/lib/getDevServerConfiguration.js +0 -63
- package/dist/lib/httpsRedirectingServer.js +0 -48
- package/dist/lib/moduleGraph.js +0 -11
- package/dist/lib/proxyHelpers.js +0 -70
- package/dist/lib/proxyHelpers.test.js +0 -136
- package/dist/lib/renderComponentWithCSS.js +0 -26
- package/dist/lib/renderHelpers.js +0 -45
- package/dist/lib/renderModule.js +0 -56
- package/dist/lib/renderPartial.js +0 -15
- package/dist/lib/templates.js +0 -66
- package/dist/proxyPage/constants.js +0 -1
- package/dist/proxyPage/fetchContentMetadata.js +0 -59
- package/dist/proxyPage/fetchDomains.js +0 -29
- package/dist/proxyPage/fetchPreviewInfo.js +0 -37
- package/dist/proxyPage/proxyPage.js +0 -174
- package/dist/proxyPage/renderLocalError.js +0 -27
- package/dist/proxyPage/utils.js +0 -38
- package/dist/routes/createDevServerRoutes.js +0 -43
- package/dist/routes/homeRouteHandler.js +0 -12
- package/dist/routes/linksToAllModulesRouteHandler.js +0 -10
- package/dist/routes/linksToAllPartialsRouteHandler.js +0 -10
- package/dist/routes/module.js +0 -41
- package/dist/routes/partial.js +0 -30
- package/dist/routes/proxyPageResourceRedirect.js +0 -22
- package/dist/routes/proxyPageRouteHandler.js +0 -40
- package/dist/routes/proxyPathPageResourceRedirect.js +0 -36
- package/dist/routes/proxyPathPageRouteHandler.js +0 -43
- package/dist/shadowDevServer/createShadowDevServerRoutes.js +0 -63
- package/dist/shadowDevServer/startShadowDevServer.js +0 -31
- package/dist/storybook/getFieldsArgTypes.js +0 -54
- package/dist/storybook/getFieldsArgTypes.test.js +0 -91
- package/dist/storybook/getNestedFieldObjectForArgs.js +0 -22
- package/dist/storybook/getNestedFieldObjectForArgs.test.js +0 -40
- package/dist/storybook/main.js +0 -31
- package/dist/storybook/moduleStory.js +0 -61
- package/dist/storybook/preview.js +0 -9
- package/dist/storybook/types.js +0 -1
package/dist/createDevServer.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import url from 'url';
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import http from 'http';
|
|
5
|
-
import bodyParser from 'body-parser';
|
|
6
|
-
import { spawn } from 'child_process';
|
|
7
|
-
import { normalizePath } from 'vite';
|
|
8
|
-
import createDevServerRoutes from './routes/createDevServerRoutes.js';
|
|
9
|
-
import startShadowDevServer from './shadowDevServer/startShadowDevServer.js';
|
|
10
|
-
import { getProjectNameFromHSConfig } from './lib/proxyHelpers.js';
|
|
11
|
-
import createViteDevServer from './createViteDevServer.js';
|
|
12
|
-
import { createHttpsRedirectingServer } from './lib/httpsRedirectingServer.js';
|
|
13
|
-
import { debug } from './lib/debug.js';
|
|
14
|
-
import { getEnv, getAccountId, loadConfig, validateConfig, } from '@hubspot/cli-lib/lib/config.js';
|
|
15
|
-
import { fetchWebsiteDomainNames } from './proxyPage/fetchDomains.js';
|
|
16
|
-
import { logMissingScopeWarning, MissingScopeError } from './lib/errors.js';
|
|
17
|
-
const sharedDepsEnabled = Boolean(process.env.SHARED_DEPS_ENABLED);
|
|
18
|
-
const BASE_PATH = '/';
|
|
19
|
-
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
20
|
-
const SHADOW_PORT = 1442;
|
|
21
|
-
const STORYBOOK_PORT = process.env.STORYBOOK_PORT
|
|
22
|
-
? parseInt(process.env.STORYBOOK_PORT, 10)
|
|
23
|
-
: 3123;
|
|
24
|
-
async function createDevServer(webRoot, storybook, hubspotCliConfigPathOption, hubspotCliAccountNameOption, sslEnabledOption) {
|
|
25
|
-
console.log('Warning: this is a prerelease and requires specific HubSpot account configuration to work');
|
|
26
|
-
let authedPortalId = null;
|
|
27
|
-
let authedEnv = null;
|
|
28
|
-
if (hubspotCliConfigPathOption && hubspotCliAccountNameOption) {
|
|
29
|
-
console.log(`Loading HS auth (account = ${hubspotCliAccountNameOption}) configuration at: ${hubspotCliConfigPathOption}`);
|
|
30
|
-
}
|
|
31
|
-
else if (hubspotCliConfigPathOption) {
|
|
32
|
-
console.log(`Loading HS auth configuration at: ${hubspotCliConfigPathOption}`);
|
|
33
|
-
}
|
|
34
|
-
else if (hubspotCliAccountNameOption) {
|
|
35
|
-
console.log(`Loading HS auth (account = ${hubspotCliAccountNameOption}) configuration.`);
|
|
36
|
-
}
|
|
37
|
-
// If a custom hubspot.config.yaml config path was set, make sure to force load that before
|
|
38
|
-
// any hs config values are read
|
|
39
|
-
loadConfig(hubspotCliConfigPathOption || null, { useEnv: false });
|
|
40
|
-
if (validateConfig()) {
|
|
41
|
-
authedPortalId = getAccountId(hubspotCliAccountNameOption);
|
|
42
|
-
authedEnv = getEnv(hubspotCliAccountNameOption);
|
|
43
|
-
if (!authedPortalId && hubspotCliAccountNameOption) {
|
|
44
|
-
console.error(`Couldn't find ${hubspotCliAccountNameOption} in your hubspot.config.yaml`);
|
|
45
|
-
process.exit(1);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
console.warn(`Couldn't find an account to use, make sure there is hubspot.config.yaml in this folder (or a parent).
|
|
50
|
-
If needed you can refer to another config file with --config.
|
|
51
|
-
|
|
52
|
-
Local proxy functionality will not work without setting up authentication.`);
|
|
53
|
-
}
|
|
54
|
-
let domainsToProxy = [];
|
|
55
|
-
if (sslEnabledOption && authedPortalId) {
|
|
56
|
-
try {
|
|
57
|
-
const portalDomains = await fetchWebsiteDomainNames(authedPortalId);
|
|
58
|
-
domainsToProxy = (process.env.DOMAINS_TO_PROXY || '')
|
|
59
|
-
.split(',')
|
|
60
|
-
.filter(d => !!d);
|
|
61
|
-
domainsToProxy = [...domainsToProxy, ...portalDomains];
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
if (e instanceof MissingScopeError) {
|
|
65
|
-
logMissingScopeWarning(e);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
console.warn(`Failed to fetch domains for ${authedPortalId}, HTTPS proxying won't work with them.`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const authedHublet = 'na1';
|
|
73
|
-
const absoluteWebRoot = normalizePath(path.resolve(process.cwd(), webRoot));
|
|
74
|
-
const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, '').split('/').slice(-2);
|
|
75
|
-
const viteServer = await createViteDevServer(absoluteWebRoot, PORT, sslEnabledOption, domainsToProxy, sharedDepsEnabled);
|
|
76
|
-
// Get https key and cert from the vite config set by vite-plugin-mkcert (if it worked )
|
|
77
|
-
const viteHTTPSConfig = viteServer.config.server.https;
|
|
78
|
-
const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
|
|
79
|
-
const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
|
|
80
|
-
const httpServers = [];
|
|
81
|
-
const expressServer = express();
|
|
82
|
-
expressServer.locals.devServerHost = 'hslocal.net';
|
|
83
|
-
expressServer.locals.devServerPort = PORT;
|
|
84
|
-
expressServer.locals.webRoot = webRoot;
|
|
85
|
-
expressServer.locals.viteServer = viteServer;
|
|
86
|
-
expressServer.locals.authedPortalId = authedPortalId;
|
|
87
|
-
expressServer.locals.authedEnv = authedEnv;
|
|
88
|
-
expressServer.locals.authedHublet = authedHublet;
|
|
89
|
-
expressServer.locals.storybookEnabled = storybook;
|
|
90
|
-
expressServer.locals.storybookPort = STORYBOOK_PORT;
|
|
91
|
-
expressServer.locals.sharedDepsEnabled = sharedDepsEnabled;
|
|
92
|
-
expressServer.locals.projectName = getProjectNameFromHSConfig(path.join(webRoot, '../hsproject.json'));
|
|
93
|
-
expressServer.locals.projectComponentPath = webRootProjectComponentFolder;
|
|
94
|
-
expressServer.use(bodyParser.json());
|
|
95
|
-
expressServer.use(BASE_PATH, await createDevServerRoutes(viteServer, storybook ? STORYBOOK_PORT : null));
|
|
96
|
-
if (sslEnabledOption) {
|
|
97
|
-
if (httpsKey && httpsCert) {
|
|
98
|
-
const { server, innerHTTPServer, innerHTTPSServer } = createHttpsRedirectingServer({ key: httpsKey, cert: httpsCert }, expressServer);
|
|
99
|
-
server.listen(PORT);
|
|
100
|
-
httpServers.push(server);
|
|
101
|
-
// Not sure if we need to worry about closing all of these, but🤷
|
|
102
|
-
httpServers.push(innerHTTPServer);
|
|
103
|
-
httpServers.push(innerHTTPSServer);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
console.error('Failed to start a HTTPS server, try --no-ssl');
|
|
107
|
-
process.exit(1);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const httpServer = http.createServer(expressServer);
|
|
112
|
-
httpServer.listen(PORT);
|
|
113
|
-
httpServers.push(httpServer);
|
|
114
|
-
}
|
|
115
|
-
startShadowDevServer(PORT, SHADOW_PORT);
|
|
116
|
-
let extraServerInfo = '';
|
|
117
|
-
const protocol = sslEnabledOption ? 'https' : 'http';
|
|
118
|
-
if (authedPortalId) {
|
|
119
|
-
extraServerInfo += `, hubid=${authedPortalId}`;
|
|
120
|
-
}
|
|
121
|
-
if (authedEnv && authedEnv !== 'prod') {
|
|
122
|
-
extraServerInfo += `, env=${authedEnv}`;
|
|
123
|
-
}
|
|
124
|
-
console.log(`
|
|
125
|
-
HubSpot CMS dev server hosting: ${expressServer.locals.projectName}/${expressServer.locals.projectComponentPath} (at ${protocol}://hslocal.net:${PORT}${extraServerInfo})
|
|
126
|
-
`);
|
|
127
|
-
if (storybook) {
|
|
128
|
-
const packageRoot = path.dirname(url.fileURLToPath(import.meta.url));
|
|
129
|
-
const configPath = path.resolve(packageRoot, './storybook');
|
|
130
|
-
const storybookProcess = spawn('npx', [
|
|
131
|
-
'sb',
|
|
132
|
-
'dev',
|
|
133
|
-
'-p',
|
|
134
|
-
STORYBOOK_PORT.toString(),
|
|
135
|
-
'-c',
|
|
136
|
-
configPath,
|
|
137
|
-
'--quiet',
|
|
138
|
-
'--no-open',
|
|
139
|
-
], {
|
|
140
|
-
cwd: process.cwd(),
|
|
141
|
-
env: {
|
|
142
|
-
...process.env,
|
|
143
|
-
WEB_ROOT: path.join(webRoot, 'components'),
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
console.log(`Starting storybook server on port ${STORYBOOK_PORT}`);
|
|
147
|
-
if (debug.enabled) {
|
|
148
|
-
storybookProcess.stdout.pipe(process.stdout);
|
|
149
|
-
}
|
|
150
|
-
storybookProcess.stderr.pipe(process.stderr);
|
|
151
|
-
}
|
|
152
|
-
// Return hook to shut down server gracefully
|
|
153
|
-
return {
|
|
154
|
-
close: () => {
|
|
155
|
-
const serverClosePromises = httpServers.map(server => new Promise(resolve => {
|
|
156
|
-
server.close(() => {
|
|
157
|
-
resolve(null);
|
|
158
|
-
});
|
|
159
|
-
}));
|
|
160
|
-
return Promise.allSettled([...serverClosePromises, viteServer.close()]);
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
export default createDevServer;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import url from 'url';
|
|
3
|
-
import express from 'express';
|
|
4
|
-
import http from 'http';
|
|
5
|
-
import { spawn } from 'child_process';
|
|
6
|
-
import { normalizePath } from 'vite';
|
|
7
|
-
import createDevServerRoutes from './routes/createDevServerRoutes.js';
|
|
8
|
-
import startShadowDevServer from './shadowDevServer/startShadowDevServer.js';
|
|
9
|
-
import { getProjectNameFromHSConfig } from './lib/proxyHelpers.js';
|
|
10
|
-
import createViteDevServer from './createViteDevServer.js';
|
|
11
|
-
import { createHttpsRedirectingServer } from './lib/httpsRedirectingServer.js';
|
|
12
|
-
import { debug } from './lib/debug.js';
|
|
13
|
-
import { getEnv, getAccountId, loadConfig, validateConfig, } from '@hubspot/cli-lib/lib/config.js';
|
|
14
|
-
import { fetchWebsiteDomainNames } from './proxyPage/fetchDomains.js';
|
|
15
|
-
import { logMissingScopeWarning, MissingScopeError } from './lib/errors.js';
|
|
16
|
-
async function createDevServer(devServerConfiguration) {
|
|
17
|
-
const { basePath, shadowPort, storybookPort, webRoot, storybookEnabled, hubspotCliConfigPathOption, hubspotCliAccountNameOption, sslEnabled, port, } = devServerConfiguration;
|
|
18
|
-
console.log('Warning: this is a prerelease and requires specific HubSpot account configuration to work');
|
|
19
|
-
let authedPortalId = null;
|
|
20
|
-
let authedEnv = null;
|
|
21
|
-
if (hubspotCliConfigPathOption && hubspotCliAccountNameOption) {
|
|
22
|
-
console.log(`Loading HS auth (account = ${hubspotCliAccountNameOption}) configuration at: ${hubspotCliConfigPathOption}`);
|
|
23
|
-
}
|
|
24
|
-
else if (hubspotCliConfigPathOption) {
|
|
25
|
-
console.log(`Loading HS auth configuration at: ${hubspotCliConfigPathOption}`);
|
|
26
|
-
}
|
|
27
|
-
else if (hubspotCliAccountNameOption) {
|
|
28
|
-
console.log(`Loading HS auth (account = ${hubspotCliAccountNameOption}) configuration.`);
|
|
29
|
-
}
|
|
30
|
-
// If a custom hubspot.config.yaml config path was set, make sure to force load that before
|
|
31
|
-
// any hs config values are read
|
|
32
|
-
loadConfig(hubspotCliConfigPathOption || null, { useEnv: false });
|
|
33
|
-
if (validateConfig()) {
|
|
34
|
-
authedPortalId = getAccountId(hubspotCliAccountNameOption);
|
|
35
|
-
authedEnv = getEnv(hubspotCliAccountNameOption);
|
|
36
|
-
if (!authedPortalId && hubspotCliAccountNameOption) {
|
|
37
|
-
console.error(`Couldn't find ${hubspotCliAccountNameOption} in your hubspot.config.yaml`);
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
console.warn(`Couldn't find an account to use, make sure there is hubspot.config.yaml in this folder (or a parent).
|
|
43
|
-
If needed you can refer to another config file with --config.
|
|
44
|
-
|
|
45
|
-
Local proxy functionality will not work without setting up authentication.`);
|
|
46
|
-
}
|
|
47
|
-
let domainsToProxy = [];
|
|
48
|
-
if (sslEnabled && authedPortalId) {
|
|
49
|
-
try {
|
|
50
|
-
const portalDomains = await fetchWebsiteDomainNames(authedPortalId);
|
|
51
|
-
domainsToProxy = (process.env.DOMAINS_TO_PROXY || '')
|
|
52
|
-
.split(',')
|
|
53
|
-
.filter(d => !!d);
|
|
54
|
-
domainsToProxy = [...domainsToProxy, ...portalDomains];
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
if (e instanceof MissingScopeError) {
|
|
58
|
-
logMissingScopeWarning(e);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
console.warn(`Failed to fetch domains for ${authedPortalId}, HTTPS proxying won't work with them.`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const authedHublet = 'na1';
|
|
66
|
-
const absoluteWebRoot = normalizePath(path.resolve(process.cwd(), webRoot));
|
|
67
|
-
const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, '').split('/').slice(-2);
|
|
68
|
-
const viteServer = await createViteDevServer(absoluteWebRoot, port, sslEnabled, domainsToProxy);
|
|
69
|
-
// Get https key and cert from the vite config set by vite-plugin-mkcert (if it worked )
|
|
70
|
-
const viteHTTPSConfig = viteServer.config.server.https;
|
|
71
|
-
const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
|
|
72
|
-
const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
|
|
73
|
-
const httpServers = [];
|
|
74
|
-
const expressServer = express();
|
|
75
|
-
expressServer.locals.devServerHost = 'hslocal.net';
|
|
76
|
-
expressServer.locals.devServerPort = port;
|
|
77
|
-
expressServer.locals.webRoot = webRoot;
|
|
78
|
-
expressServer.locals.viteServer = viteServer;
|
|
79
|
-
expressServer.locals.authedPortalId = authedPortalId;
|
|
80
|
-
expressServer.locals.authedEnv = authedEnv;
|
|
81
|
-
expressServer.locals.authedHublet = authedHublet;
|
|
82
|
-
expressServer.locals.storybookEnabled = storybookEnabled;
|
|
83
|
-
expressServer.locals.storybookPort = storybookPort;
|
|
84
|
-
expressServer.locals.projectName = getProjectNameFromHSConfig(path.join(webRoot, '../hsproject.json'));
|
|
85
|
-
expressServer.locals.projectComponentPath = webRootProjectComponentFolder;
|
|
86
|
-
expressServer.use(basePath, await createDevServerRoutes(viteServer, storybookEnabled ? storybookPort : null));
|
|
87
|
-
if (sslEnabled) {
|
|
88
|
-
if (httpsKey && httpsCert) {
|
|
89
|
-
const { server, innerHTTPServer, innerHTTPSServer } = createHttpsRedirectingServer({ key: httpsKey, cert: httpsCert }, expressServer);
|
|
90
|
-
server.listen(port);
|
|
91
|
-
httpServers.push(server);
|
|
92
|
-
// Not sure if we need to worry about closing all of these, but🤷
|
|
93
|
-
httpServers.push(innerHTTPServer);
|
|
94
|
-
httpServers.push(innerHTTPSServer);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
console.error('Failed to start a HTTPS server, try --no-ssl');
|
|
98
|
-
process.exit(1);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
const httpServer = http.createServer(expressServer);
|
|
103
|
-
httpServer.listen(port);
|
|
104
|
-
httpServers.push(httpServer);
|
|
105
|
-
}
|
|
106
|
-
startShadowDevServer(port, shadowPort);
|
|
107
|
-
let extraServerInfo = '';
|
|
108
|
-
const protocol = sslEnabled ? 'https' : 'http';
|
|
109
|
-
if (authedPortalId) {
|
|
110
|
-
extraServerInfo += `, hubid=${authedPortalId}`;
|
|
111
|
-
}
|
|
112
|
-
if (authedEnv && authedEnv !== 'prod') {
|
|
113
|
-
extraServerInfo += `, env=${authedEnv}`;
|
|
114
|
-
}
|
|
115
|
-
console.log(`
|
|
116
|
-
HubSpot CMS dev server hosting: ${expressServer.locals.projectName}/${expressServer.locals.projectComponentPath} (at ${protocol}://hslocal.net:${port}${extraServerInfo})
|
|
117
|
-
`);
|
|
118
|
-
if (storybookEnabled) {
|
|
119
|
-
const packageRoot = path.dirname(url.fileURLToPath(import.meta.url));
|
|
120
|
-
const configPath = path.resolve(packageRoot, './storybook');
|
|
121
|
-
const storybookProcess = spawn('yarn', [
|
|
122
|
-
'sb',
|
|
123
|
-
'dev',
|
|
124
|
-
'-p',
|
|
125
|
-
storybookPort.toString(),
|
|
126
|
-
'-c',
|
|
127
|
-
configPath,
|
|
128
|
-
'--quiet',
|
|
129
|
-
'--no-open',
|
|
130
|
-
], {
|
|
131
|
-
cwd: process.cwd(),
|
|
132
|
-
env: {
|
|
133
|
-
...process.env,
|
|
134
|
-
WEB_ROOT: path.join(webRoot, 'components'),
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
console.log(`Starting storybook server on port ${storybookPort}`);
|
|
138
|
-
if (debug.enabled) {
|
|
139
|
-
storybookProcess.stdout.pipe(process.stdout);
|
|
140
|
-
}
|
|
141
|
-
storybookProcess.stderr.pipe(process.stderr);
|
|
142
|
-
}
|
|
143
|
-
// Return hook to shut down server gracefully
|
|
144
|
-
return {
|
|
145
|
-
close: () => {
|
|
146
|
-
const serverClosePromises = httpServers.map(server => new Promise(resolve => {
|
|
147
|
-
server.close(() => {
|
|
148
|
-
resolve(null);
|
|
149
|
-
});
|
|
150
|
-
}));
|
|
151
|
-
return Promise.allSettled([...serverClosePromises, viteServer.close()]);
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
export default createDevServer;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/* hs-eslint ignored failing-rules */
|
|
2
|
-
/* eslint-disable require-await */
|
|
3
|
-
import { createServer as createViteServer } from 'vite';
|
|
4
|
-
import { default as react } from '@vitejs/plugin-react';
|
|
5
|
-
import { clientIslandEntryPlugin, resolveIslandPlugin, } from '@hubspot/cms-js-internal';
|
|
6
|
-
import mkcert from 'vite-plugin-mkcert';
|
|
7
|
-
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], sharedDepsEnabled) {
|
|
8
|
-
const additionalMkcertHosts = domainsToProxy
|
|
9
|
-
.map(proxyDomain => [
|
|
10
|
-
`${proxyDomain}.localhost`,
|
|
11
|
-
`${proxyDomain}.hslocal.net`,
|
|
12
|
-
])
|
|
13
|
-
.flat();
|
|
14
|
-
additionalMkcertHosts.push('*.hslocal.net', 'hslocal.net');
|
|
15
|
-
const origin = sslEnabled
|
|
16
|
-
? `https://hslocal.net:${port}`
|
|
17
|
-
: `http://hslocal.net:${port}`;
|
|
18
|
-
const viteConfig = {
|
|
19
|
-
appType: 'custom',
|
|
20
|
-
server: {
|
|
21
|
-
middlewareMode: true,
|
|
22
|
-
host: 'hslocal.net',
|
|
23
|
-
origin,
|
|
24
|
-
https: sslEnabled,
|
|
25
|
-
hmr: {
|
|
26
|
-
protocol: sslEnabled ? 'wss' : undefined,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
ssr: {
|
|
30
|
-
// TODO: might need more entries here to get things to resolve through
|
|
31
|
-
// resolveWebRootDepsPlugin
|
|
32
|
-
noExternal: '@hubspot/cms-components',
|
|
33
|
-
},
|
|
34
|
-
resolve: {
|
|
35
|
-
dedupe: ['react', 'react-dom', '@hubspot/cms-components'],
|
|
36
|
-
},
|
|
37
|
-
optimizeDeps: {
|
|
38
|
-
include: ['react', 'react-dom', 'react-dom/client'],
|
|
39
|
-
},
|
|
40
|
-
plugins: [
|
|
41
|
-
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
42
|
-
react(),
|
|
43
|
-
sharedDepsEnabled && clientIslandEntryPlugin(),
|
|
44
|
-
resolveIslandPlugin({ sharedDepsEnabled }),
|
|
45
|
-
],
|
|
46
|
-
css: {
|
|
47
|
-
postcss: webRoot,
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
return createViteServer(viteConfig);
|
|
51
|
-
}
|
|
52
|
-
export default createViteDevServer;
|
package/dist/lib/cli.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
export function getDevServerCommandLineOptions(argv) {
|
|
3
|
-
const args = [...argv];
|
|
4
|
-
const webRoot = args[2];
|
|
5
|
-
let hubspotCliConfigPathOption;
|
|
6
|
-
let hubspotCliAccountNameOption;
|
|
7
|
-
// Very basic CLI option parsing
|
|
8
|
-
const configOptionIndex = args.findIndex(arg => arg === '-c' || arg === '--config');
|
|
9
|
-
if (configOptionIndex > 0 && args.length > configOptionIndex) {
|
|
10
|
-
hubspotCliConfigPathOption = resolve(args[configOptionIndex + 1]);
|
|
11
|
-
args.splice(configOptionIndex, 2);
|
|
12
|
-
}
|
|
13
|
-
const accountOptionIndex = args.findIndex(arg => arg === '-a' || arg === '--account');
|
|
14
|
-
if (accountOptionIndex > 0 && args.length > accountOptionIndex) {
|
|
15
|
-
hubspotCliAccountNameOption = args[accountOptionIndex + 1];
|
|
16
|
-
args.splice(accountOptionIndex, 2);
|
|
17
|
-
}
|
|
18
|
-
const sslEnabledOption = args.includes('--ssl') && !args.includes('--no-ssl');
|
|
19
|
-
const storybook = args.findIndex(arg => arg === '--storybook') > 0;
|
|
20
|
-
return {
|
|
21
|
-
hubspotCliConfigPathOption,
|
|
22
|
-
hubspotCliAccountNameOption,
|
|
23
|
-
sslEnabledOption,
|
|
24
|
-
storybook,
|
|
25
|
-
webRoot,
|
|
26
|
-
};
|
|
27
|
-
}
|
package/dist/lib/debug.js
DELETED
package/dist/lib/errors.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.\nYou may need to re-generate a new personal access key with the required scopes and re-run \`hs-auth\`, or you may not have this functionality enabled in your account\n`;
|
|
2
|
-
const OAUTH_ERROR_REGEX = /^This oauth-token \([\w]+\) does not have proper permissions!/;
|
|
3
|
-
const NOT_PUBLIC_USE_ERROR = `The scope needed for this API call isn't available for public use`;
|
|
4
|
-
export class MissingScopeError extends Error {
|
|
5
|
-
constructor(error) {
|
|
6
|
-
let messageEnd = '';
|
|
7
|
-
if (error.error.message.match(OAUTH_ERROR_REGEX)) {
|
|
8
|
-
messageEnd = error.error.message;
|
|
9
|
-
}
|
|
10
|
-
super(`${MISSING_SCOPE_ERROR_PREFIX}\n${messageEnd}`);
|
|
11
|
-
// Set the prototype explicitly.
|
|
12
|
-
Object.setPrototypeOf(this, MissingScopeError.prototype);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export function logMissingScopeWarning(error) {
|
|
16
|
-
console.warn(error.message);
|
|
17
|
-
}
|
|
18
|
-
export function isMissingScopeError(error) {
|
|
19
|
-
return (error.statusCode === 403 &&
|
|
20
|
-
(error.error.message.match(OAUTH_ERROR_REGEX) ||
|
|
21
|
-
error.error.message.startsWith(NOT_PUBLIC_USE_ERROR)));
|
|
22
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { resolve } from 'path';
|
|
2
|
-
const BASE_PATH = '/';
|
|
3
|
-
const AUTHED_HUBLET = 'na1';
|
|
4
|
-
/**
|
|
5
|
-
* Command line options
|
|
6
|
-
* --ssl
|
|
7
|
-
* --c (--config)
|
|
8
|
-
* --a (--account)
|
|
9
|
-
*/
|
|
10
|
-
export function getDevServerConfiguration(args) {
|
|
11
|
-
const commandLineOptions = getCommandLineOptions(args);
|
|
12
|
-
const environmentVariables = getEnvironmentVariables();
|
|
13
|
-
return {
|
|
14
|
-
...commandLineOptions,
|
|
15
|
-
...environmentVariables,
|
|
16
|
-
authedHublet: AUTHED_HUBLET,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
function getCommandLineOptions(args) {
|
|
20
|
-
const webRoot = args[2];
|
|
21
|
-
let hubspotCliConfigPathOption;
|
|
22
|
-
let hubspotCliAccountNameOption;
|
|
23
|
-
// Very basic CLI option parsing
|
|
24
|
-
const configOptionIndex = args.findIndex(arg => arg === '-c' || arg === '--config');
|
|
25
|
-
if (configOptionIndex > 0 && args.length > configOptionIndex) {
|
|
26
|
-
hubspotCliConfigPathOption = resolve(args[configOptionIndex + 1]);
|
|
27
|
-
args.splice(configOptionIndex, 2);
|
|
28
|
-
}
|
|
29
|
-
const accountOptionIndex = args.findIndex(arg => arg === '-a' || arg === '--account');
|
|
30
|
-
if (accountOptionIndex > 0 && args.length > accountOptionIndex) {
|
|
31
|
-
hubspotCliAccountNameOption = args[accountOptionIndex + 1];
|
|
32
|
-
args.splice(accountOptionIndex, 2);
|
|
33
|
-
}
|
|
34
|
-
const sslEnabled = args.includes('--ssl') && !args.includes('--no-ssl');
|
|
35
|
-
const storybookEnabled = args.findIndex(arg => arg === '--storybook') > 0;
|
|
36
|
-
return {
|
|
37
|
-
hubspotCliConfigPathOption,
|
|
38
|
-
hubspotCliAccountNameOption,
|
|
39
|
-
sslEnabled,
|
|
40
|
-
storybookEnabled,
|
|
41
|
-
webRoot,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
function getEnvironmentVariables() {
|
|
45
|
-
// Ports
|
|
46
|
-
const port = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
47
|
-
const storybookPort = process.env.STORYBOOK_PORT
|
|
48
|
-
? parseInt(process.env.STORYBOOK_PORT, 10)
|
|
49
|
-
: 3123;
|
|
50
|
-
const shadowPort = process.env.SHADOW_PORT
|
|
51
|
-
? parseInt(process.env.SHADOW_PORT, 10)
|
|
52
|
-
: 1442;
|
|
53
|
-
const domainsToProxy = (process.env.DOMAINS_TO_PROXY || '')
|
|
54
|
-
.split(',')
|
|
55
|
-
.filter(d => !!d);
|
|
56
|
-
return {
|
|
57
|
-
basePath: BASE_PATH,
|
|
58
|
-
port,
|
|
59
|
-
storybookPort,
|
|
60
|
-
shadowPort,
|
|
61
|
-
domainsToProxy,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import net from 'net';
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import https from 'https';
|
|
4
|
-
function requireHTTPS(message, response) {
|
|
5
|
-
const newLocation = `https://${message.headers.host}${message.url}`;
|
|
6
|
-
response
|
|
7
|
-
.writeHead(302, {
|
|
8
|
-
Location: newLocation,
|
|
9
|
-
})
|
|
10
|
-
.end();
|
|
11
|
-
}
|
|
12
|
-
// Running http and https servers on the same port pulled from https://stackoverflow.com/a/42019773
|
|
13
|
-
export function createHttpsRedirectingServer(opts, handler) {
|
|
14
|
-
const innerHTTPServer = http.createServer(requireHTTPS);
|
|
15
|
-
const innerHTTPSServer = https.createServer(opts, handler);
|
|
16
|
-
const server = net.createServer(socket => {
|
|
17
|
-
socket.once('data', buffer => {
|
|
18
|
-
// Pause the socket
|
|
19
|
-
socket.pause();
|
|
20
|
-
// Determine if this is an HTTP(s) request
|
|
21
|
-
const byte = buffer[0];
|
|
22
|
-
let protocol;
|
|
23
|
-
if (byte === 22) {
|
|
24
|
-
protocol = 'https';
|
|
25
|
-
}
|
|
26
|
-
else if (32 < byte && byte < 127) {
|
|
27
|
-
protocol = 'http';
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
throw new Error('Unknown issue with incoming data, unknown if http or https');
|
|
31
|
-
}
|
|
32
|
-
const proxy = protocol === 'http' ? innerHTTPServer : innerHTTPSServer;
|
|
33
|
-
if (proxy) {
|
|
34
|
-
// Push the buffer back onto the front of the data stream
|
|
35
|
-
socket.unshift(buffer);
|
|
36
|
-
// Emit the socket to the HTTP(s) server
|
|
37
|
-
proxy.emit('connection', socket);
|
|
38
|
-
}
|
|
39
|
-
// As of NodeJS 10.x the socket must be
|
|
40
|
-
// resumed asynchronously or the socket
|
|
41
|
-
// connection hangs, potentially crashing
|
|
42
|
-
// the process. Prior to NodeJS 10.x
|
|
43
|
-
// the socket may be resumed synchronously.
|
|
44
|
-
process.nextTick(() => socket.resume());
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
return { server, innerHTTPServer, innerHTTPSServer };
|
|
48
|
-
}
|
package/dist/lib/moduleGraph.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/* hs-eslint ignored failing-rules */
|
|
2
|
-
/* eslint-disable consistent-return */
|
|
3
|
-
import { COMPONENT_EXTENSIONS } from '@hubspot/cms-js-internal';
|
|
4
|
-
export const findFullPathInModuleGraph = (modulePathNoExtension, moduleGraph) => {
|
|
5
|
-
for (const extension of COMPONENT_EXTENSIONS) {
|
|
6
|
-
const pathToTry = `${modulePathNoExtension}${extension}`;
|
|
7
|
-
if (moduleGraph.fileToModulesMap.has(pathToTry)) {
|
|
8
|
-
return pathToTry;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
};
|
package/dist/lib/proxyHelpers.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/* hs-eslint ignored failing-rules */
|
|
2
|
-
/* eslint-disable consistent-return */
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { resolve } from 'path';
|
|
5
|
-
const localJsRenderStartString = '<!-- proxy local render of "';
|
|
6
|
-
// const localJsRenderStartRegex = /<!-- proxy local render of "([^"]+)"/;
|
|
7
|
-
const localJsRenderEndString = 'end proxy local render -->';
|
|
8
|
-
export const findLocalRenderPlaceholders = (body) => {
|
|
9
|
-
let offsetSoFar = 0;
|
|
10
|
-
const result = [];
|
|
11
|
-
while (offsetSoFar < body.length && offsetSoFar !== -1) {
|
|
12
|
-
// Get start of local render block
|
|
13
|
-
const startOffset = body.indexOf(localJsRenderStartString, offsetSoFar);
|
|
14
|
-
offsetSoFar = startOffset;
|
|
15
|
-
if (startOffset >= 0) {
|
|
16
|
-
const nextNewlineOffset = body.indexOf('\n', startOffset + localJsRenderStartString.length);
|
|
17
|
-
const pathEndOffset = body.indexOf('"', startOffset + localJsRenderStartString.length);
|
|
18
|
-
const nearestNewlineOrQuoteAfterBlockOpen = Math.min(nextNewlineOffset, pathEndOffset);
|
|
19
|
-
// Keep on moving our "where we've scanned so far" pointer
|
|
20
|
-
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
21
|
-
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
22
|
-
// Pull the path out of double quotes after the block opening
|
|
23
|
-
const path = body.substring(startOffset + localJsRenderStartString.length, pathEndOffset);
|
|
24
|
-
offsetSoFar = pathEndOffset + 1;
|
|
25
|
-
// console.log(`${startOffset}: path = ${path}`);
|
|
26
|
-
// If we're in a valid bloc so far that exists and has a path...
|
|
27
|
-
if (startOffset >= 0 && path) {
|
|
28
|
-
const nextCommentEndOffset = body.indexOf('-->', pathEndOffset);
|
|
29
|
-
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
30
|
-
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
31
|
-
// Make sure that there is an ending to the block and there is not another
|
|
32
|
-
// HTML end comment string before it
|
|
33
|
-
if (endOffset >= startOffset && endOffset < nextCommentEndOffset) {
|
|
34
|
-
// Then pull out the JSON in the middle and try to parse it
|
|
35
|
-
const jsonString = body
|
|
36
|
-
.substring(pathEndOffset + 1, endOffset)
|
|
37
|
-
.trim();
|
|
38
|
-
// console.log(`${endOffset}: jsonString = ${jsonString}`);
|
|
39
|
-
try {
|
|
40
|
-
const json = JSON.parse(jsonString);
|
|
41
|
-
result.push({
|
|
42
|
-
startOffset,
|
|
43
|
-
endOffset: endOffset + localJsRenderEndString.length,
|
|
44
|
-
path,
|
|
45
|
-
json,
|
|
46
|
-
});
|
|
47
|
-
offsetSoFar = endOffset + localJsRenderEndString.length;
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
console.error(`Invalid JSON inside <!-- proxy local render .. --> string (around offset ${pathEndOffset})`);
|
|
51
|
-
offsetSoFar = endOffset;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return result;
|
|
59
|
-
};
|
|
60
|
-
const getHSProjectConfig = hsProjectConfigPath => {
|
|
61
|
-
try {
|
|
62
|
-
return JSON.parse(fs.readFileSync(hsProjectConfigPath, 'utf8'));
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
console.warn(`Missing hsproject.json file (${resolve(hsProjectConfigPath)}): `, e.message);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
export const getProjectNameFromHSConfig = hsProjectConfigPath => {
|
|
69
|
-
return getHSProjectConfig(hsProjectConfigPath).name;
|
|
70
|
-
};
|