@hubspot/cms-dev-server 0.3.4 → 0.4.1
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/createDevServer.js +60 -11
- package/dist/createViteDevServer.js +25 -4
- package/dist/fsevents-72LCIACT.node +0 -0
- package/dist/index.js +99 -1
- package/dist/internalSsr.js +390 -0
- package/dist/lib/cli.js +3 -1
- package/dist/lib/errors.js +22 -0
- package/dist/lib/httpsRedirectingServer.js +48 -0
- package/dist/lib/renderHelpers.js +3 -3
- package/dist/lib/templates.js +2 -4
- package/dist/proxyPage/fetchContentMetadata.js +2 -0
- package/dist/proxyPage/fetchDomains.js +29 -0
- package/dist/proxyPage/proxyPage.js +5 -2
- package/dist/routes/createDevServerRoutes.js +2 -0
- package/dist/routes/module.js +12 -1
- package/dist/routes/proxyPageRouteHandler.js +2 -2
- package/dist/routes/proxyPathPageRouteHandler.js +1 -1
- package/dist/run.js +1955 -5
- package/dist/shadowDevServer/createShadowDevServerRoutes.js +5 -0
- package/dist/shadowDevServer/startShadowDevServer.js +5 -6
- package/dist/storybook/index.js +62 -4
- package/dist/storybook/moduleStory.js +46 -1
- package/package.json +14 -10
- package/types/createViteDevServer.d.ts +1 -1
- package/types/storybook/moduleStory.d.ts +3 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* hs-eslint ignored failing-rules */
|
|
2
|
+
/* eslint-disable require-await */
|
|
1
3
|
import { Router } from 'express';
|
|
2
4
|
import { getAccountId } from '@hubspot/cli-lib/lib/config.js';
|
|
3
5
|
import cors from 'cors';
|
|
@@ -16,6 +18,9 @@ function getShadowDevServerCheckHandler(devServerPort) {
|
|
|
16
18
|
let localProxyUrl;
|
|
17
19
|
try {
|
|
18
20
|
accountId = getAccountId(portalId);
|
|
21
|
+
if (accountId === null) {
|
|
22
|
+
throw new Error();
|
|
23
|
+
}
|
|
19
24
|
}
|
|
20
25
|
catch (e) {
|
|
21
26
|
response
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import net from 'net';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import createShadowDevServerRoutes from './createShadowDevServerRoutes.js';
|
|
4
|
-
const SHADOW_PORT = 1442;
|
|
5
4
|
const testNetServer = net.createServer();
|
|
6
|
-
export default async function startShadowDevServer(devServerPort) {
|
|
5
|
+
export default async function startShadowDevServer(devServerPort, shadowPort) {
|
|
7
6
|
const portIsTaken = await new Promise((res, rej) => {
|
|
8
|
-
console.log(`Starting proxy link server on port ${
|
|
7
|
+
console.log(`Starting proxy link server on port ${shadowPort}`);
|
|
9
8
|
testNetServer.once('error', err => {
|
|
10
9
|
if (err['code'] === 'EADDRINUSE') {
|
|
11
|
-
console.error(`Port ${
|
|
10
|
+
console.error(`Port ${shadowPort} is in use. HubSpot is unable to automatically create proxy links in the Sprocket Menu`);
|
|
12
11
|
res(true);
|
|
13
12
|
}
|
|
14
13
|
else {
|
|
@@ -21,12 +20,12 @@ export default async function startShadowDevServer(devServerPort) {
|
|
|
21
20
|
testNetServer.once('close', () => {
|
|
22
21
|
res(false);
|
|
23
22
|
});
|
|
24
|
-
testNetServer.listen(
|
|
23
|
+
testNetServer.listen(shadowPort);
|
|
25
24
|
});
|
|
26
25
|
if (portIsTaken) {
|
|
27
26
|
return;
|
|
28
27
|
}
|
|
29
28
|
const shadowDevServer = express();
|
|
30
|
-
shadowDevServer.listen(
|
|
29
|
+
shadowDevServer.listen(shadowPort);
|
|
31
30
|
shadowDevServer.use('/', await createShadowDevServerRoutes(devServerPort));
|
|
32
31
|
}
|
package/dist/storybook/index.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
// src/storybook/moduleStory.tsx
|
|
2
|
+
import React, { useEffect } from "react";
|
|
3
|
+
import { renderToStaticMarkup as renderToStaticMarkup2 } from "react-dom/server";
|
|
4
|
+
|
|
1
5
|
// ../cms-js-internal/dist/index.js
|
|
6
|
+
import path from "path";
|
|
7
|
+
import stream from "stream";
|
|
2
8
|
import { renderToPipeableStream } from "react-dom/server";
|
|
3
9
|
import {
|
|
4
10
|
ServerRenderContext,
|
|
5
11
|
createServerRenderContext
|
|
6
12
|
} from "@hubspot/cms-components";
|
|
7
13
|
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
import path2 from "path";
|
|
15
|
+
import { existsSync, readdirSync, lstatSync } from "fs";
|
|
16
|
+
import { join as joinPosix } from "path/posix";
|
|
17
|
+
import { basename } from "path";
|
|
8
18
|
import { cloneElement } from "react";
|
|
9
19
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
10
20
|
function renderFieldsToJson(fields) {
|
|
@@ -97,14 +107,60 @@ function getNestedFieldObjectForArgs(_args) {
|
|
|
97
107
|
|
|
98
108
|
// src/storybook/moduleStory.tsx
|
|
99
109
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
110
|
+
function moduleFieldsToJson(fields) {
|
|
111
|
+
let moduleJson;
|
|
112
|
+
const outputCallback = (callbackJson) => {
|
|
113
|
+
moduleJson = callbackJson;
|
|
114
|
+
};
|
|
115
|
+
renderToStaticMarkup2(
|
|
116
|
+
React.cloneElement(fields, {
|
|
117
|
+
outputCallback
|
|
118
|
+
})
|
|
119
|
+
);
|
|
120
|
+
if (!moduleJson) {
|
|
121
|
+
throw new Error("couldn't render module fields definition to fields.json");
|
|
122
|
+
}
|
|
123
|
+
return moduleJson;
|
|
124
|
+
}
|
|
100
125
|
function moduleStory(ModuleComponent, fields) {
|
|
101
126
|
const moduleJson = renderFieldsToJson(fields);
|
|
102
127
|
const argTypes = getFieldsArgTypes(moduleJson);
|
|
128
|
+
const story = (_args) => /* @__PURE__ */ jsx2(ModuleComponent, { ..._args });
|
|
129
|
+
const storyWithArgs = story.bind({});
|
|
130
|
+
storyWithArgs.argTypes = argTypes;
|
|
131
|
+
storyWithArgs.args = {};
|
|
132
|
+
return storyWithArgs;
|
|
133
|
+
}
|
|
134
|
+
function moduleStoryWithIsland(moduleName, fields) {
|
|
135
|
+
const moduleJson = moduleFieldsToJson(fields);
|
|
136
|
+
const argTypes = getFieldsArgTypes(moduleJson);
|
|
103
137
|
const story = (_args) => {
|
|
104
138
|
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
139
|
+
const fieldValuesString = JSON.stringify(fieldValues);
|
|
140
|
+
const domain = `${window.location.protocol}//${window.location.hostname.replace("storybook.", "")}:3000`;
|
|
141
|
+
const fieldValuesJson = encodeURIComponent(fieldValuesString);
|
|
142
|
+
const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
const existingElement = document.querySelector("#hs-module-iframe");
|
|
145
|
+
if (existingElement) {
|
|
146
|
+
existingElement.setAttribute("src", iframeSrc);
|
|
147
|
+
return () => {
|
|
148
|
+
existingElement.remove();
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const iframeElement = document.createElement("iframe");
|
|
152
|
+
iframeElement.setAttribute("src", iframeSrc);
|
|
153
|
+
iframeElement.setAttribute("id", "hs-module-iframe");
|
|
154
|
+
iframeElement.setAttribute(
|
|
155
|
+
"style",
|
|
156
|
+
`border: none;width: 100%;height: 100%;overflow: auto;`
|
|
157
|
+
);
|
|
158
|
+
document.body.appendChild(iframeElement);
|
|
159
|
+
return () => {
|
|
160
|
+
iframeElement.remove();
|
|
161
|
+
};
|
|
162
|
+
}, [iframeSrc]);
|
|
163
|
+
return /* @__PURE__ */ jsx2("div", {});
|
|
108
164
|
};
|
|
109
165
|
const storyWithArgs = story.bind({});
|
|
110
166
|
storyWithArgs.argTypes = argTypes;
|
|
@@ -112,5 +168,7 @@ function moduleStory(ModuleComponent, fields) {
|
|
|
112
168
|
return storyWithArgs;
|
|
113
169
|
}
|
|
114
170
|
export {
|
|
115
|
-
|
|
171
|
+
moduleFieldsToJson,
|
|
172
|
+
moduleStory,
|
|
173
|
+
moduleStoryWithIsland
|
|
116
174
|
};
|
|
@@ -1,13 +1,58 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
2
4
|
import { renderFieldsToJson } from '@hubspot/cms-js-internal';
|
|
3
5
|
import getFieldsArgTypes from './getFieldsArgTypes.js';
|
|
4
6
|
import getNestedFieldObjectForArgs from './getNestedFieldObjectForArgs.js';
|
|
7
|
+
export function moduleFieldsToJson(fields) {
|
|
8
|
+
let moduleJson;
|
|
9
|
+
const outputCallback = (callbackJson) => {
|
|
10
|
+
moduleJson = callbackJson;
|
|
11
|
+
};
|
|
12
|
+
renderToStaticMarkup(React.cloneElement(fields, {
|
|
13
|
+
outputCallback,
|
|
14
|
+
}));
|
|
15
|
+
if (!moduleJson) {
|
|
16
|
+
throw new Error("couldn't render module fields definition to fields.json");
|
|
17
|
+
}
|
|
18
|
+
return moduleJson;
|
|
19
|
+
}
|
|
5
20
|
export function moduleStory(ModuleComponent, fields) {
|
|
6
21
|
const moduleJson = renderFieldsToJson(fields);
|
|
7
22
|
const argTypes = getFieldsArgTypes(moduleJson);
|
|
23
|
+
const story = (_args) => _jsx(ModuleComponent, { ..._args });
|
|
24
|
+
const storyWithArgs = story.bind({});
|
|
25
|
+
storyWithArgs.argTypes = argTypes;
|
|
26
|
+
storyWithArgs.args = {};
|
|
27
|
+
return storyWithArgs;
|
|
28
|
+
}
|
|
29
|
+
export function moduleStoryWithIsland(moduleName, fields) {
|
|
30
|
+
const moduleJson = moduleFieldsToJson(fields);
|
|
31
|
+
const argTypes = getFieldsArgTypes(moduleJson);
|
|
8
32
|
const story = (_args) => {
|
|
9
33
|
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
10
|
-
|
|
34
|
+
const fieldValuesString = JSON.stringify(fieldValues);
|
|
35
|
+
const domain = `${window.location.protocol}//${window.location.hostname.replace('storybook.', '')}:3000`;
|
|
36
|
+
const fieldValuesJson = encodeURIComponent(fieldValuesString);
|
|
37
|
+
const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const existingElement = document.querySelector('#hs-module-iframe');
|
|
40
|
+
if (existingElement) {
|
|
41
|
+
existingElement.setAttribute('src', iframeSrc);
|
|
42
|
+
return () => {
|
|
43
|
+
existingElement.remove();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const iframeElement = document.createElement('iframe');
|
|
47
|
+
iframeElement.setAttribute('src', iframeSrc);
|
|
48
|
+
iframeElement.setAttribute('id', 'hs-module-iframe');
|
|
49
|
+
iframeElement.setAttribute('style', `border: none;width: 100%;height: 100%;overflow: auto;`);
|
|
50
|
+
document.body.appendChild(iframeElement);
|
|
51
|
+
return () => {
|
|
52
|
+
iframeElement.remove();
|
|
53
|
+
};
|
|
54
|
+
}, [iframeSrc]);
|
|
55
|
+
return _jsx("div", {});
|
|
11
56
|
};
|
|
12
57
|
const storyWithArgs = story.bind({});
|
|
13
58
|
storyWithArgs.argTypes = argTypes;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=16.x"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsc
|
|
10
|
+
"build": "tsc -noEmit && yarn run copy-html && yarn build-types && node scripts/build.mjs",
|
|
11
11
|
"build:watch": "nodemon --exec 'yarn build'",
|
|
12
12
|
"copy-html": "copyfiles -u 1 'src/html/**' 'dist'",
|
|
13
13
|
"build-types": "tsc --project tsconfig.types.json",
|
|
@@ -24,8 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@hubspot/cli-lib": "^3.0.12",
|
|
27
|
-
"@hubspot/cms-components": "^0.
|
|
28
|
-
"@hubspot/cms-js-internal": "^0.3.4",
|
|
27
|
+
"@hubspot/cms-components": "^0.4.1",
|
|
29
28
|
"@storybook/addon-actions": "^7.0.0-beta.19",
|
|
30
29
|
"@storybook/addon-essentials": "^7.0.0-beta.19",
|
|
31
30
|
"@storybook/addon-interactions": "^7.0.0-beta.19",
|
|
@@ -45,9 +44,11 @@
|
|
|
45
44
|
"request": "^2.88.2",
|
|
46
45
|
"typescript": "~4.7.0",
|
|
47
46
|
"vite": "^4.0.0",
|
|
48
|
-
"vite-plugin-inspect": "^0.4.3"
|
|
47
|
+
"vite-plugin-inspect": "^0.4.3",
|
|
48
|
+
"vite-plugin-mkcert": "^1.10.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
+
"@hubspot/cms-js-internal": "^0.4.0",
|
|
51
52
|
"@testing-library/dom": "^8.20.0",
|
|
52
53
|
"@types/express": "^4.17.13",
|
|
53
54
|
"@types/react": "^18.0.0",
|
|
@@ -58,9 +59,9 @@
|
|
|
58
59
|
"ts-node": "^10.7.0",
|
|
59
60
|
"vitest": "0.25.8"
|
|
60
61
|
},
|
|
61
|
-
"main": "./dist/
|
|
62
|
+
"main": "./dist/index.js",
|
|
62
63
|
"exports": {
|
|
63
|
-
".": "./dist/
|
|
64
|
+
".": "./dist/index.js",
|
|
64
65
|
"./storybook": {
|
|
65
66
|
"types": "./types/storybook/index.d.ts",
|
|
66
67
|
"default": "./dist/storybook/index.js"
|
|
@@ -76,20 +77,23 @@
|
|
|
76
77
|
"types"
|
|
77
78
|
],
|
|
78
79
|
"nodemonConfig": {
|
|
80
|
+
"delay": "2000ms",
|
|
79
81
|
"ext": "js,json,ts,tsx,jsx,html",
|
|
80
82
|
"ignore": [
|
|
81
83
|
"testApp/*",
|
|
82
|
-
"dist/*"
|
|
84
|
+
"./dist/*"
|
|
83
85
|
],
|
|
84
86
|
"watch": [
|
|
85
87
|
"src",
|
|
86
88
|
"package.json",
|
|
87
89
|
"yarn.lock",
|
|
88
|
-
"tsconfig.json"
|
|
90
|
+
"tsconfig.json",
|
|
91
|
+
"../cms-components/dist",
|
|
92
|
+
"../cms-js-internal/dist"
|
|
89
93
|
]
|
|
90
94
|
},
|
|
91
95
|
"publishConfig": {
|
|
92
96
|
"access": "public"
|
|
93
97
|
},
|
|
94
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "d2e7b02c414f07b8bc24b4d97b81bf7e9ba48dc0"
|
|
95
99
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare function createViteDevServer(webRoot: string): Promise<import("vite").ViteDevServer>;
|
|
1
|
+
declare function createViteDevServer(webRoot: string, port: any, sslEnabled: boolean, domainsToProxy?: any[]): Promise<import("vite").ViteDevServer>;
|
|
2
2
|
export default createViteDevServer;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { Field } from '@hubspot/cms-components/fields';
|
|
3
|
+
export declare function moduleFieldsToJson(fields: JSX.Element): Field[];
|
|
2
4
|
export declare function moduleStory(ModuleComponent: React.ComponentType, fields: JSX.Element): any;
|
|
5
|
+
export declare function moduleStoryWithIsland(moduleName: string, fields: JSX.Element): any;
|