@hubspot/cms-dev-server 0.2.13 → 0.3.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 +35 -2
- package/dist/createViteDevServer.js +3 -2
- package/dist/lib/cli.js +2 -0
- package/dist/lib/debug.js +2 -0
- package/dist/lib/renderModule.js +1 -1
- package/dist/routes/createDevServerRoutes.js +17 -1
- package/dist/routes/homeRouteHandler.js +2 -2
- package/dist/run.js +2 -2
- package/dist/storybook/getFieldsArgTypes.js +42 -0
- package/dist/storybook/getFieldsArgTypes.test.js +67 -0
- package/dist/storybook/getFieldsArgTypes.ts +47 -0
- package/dist/storybook/getNestedFieldObjectForArgs.js +22 -0
- package/dist/storybook/getNestedFieldObjectForArgs.test.js +40 -0
- package/dist/storybook/index.js +13 -1
- package/dist/storybook/main.js +6 -1
- package/dist/storybook/moduleStory.js +13 -1
- package/dist/storybook/types.js +1 -0
- package/package.json +31 -10
- package/types/storybook/getFieldsArgTypes.d.ts +9 -0
- package/types/storybook/getNestedFieldObjectForArgs.d.ts +6 -0
- package/types/storybook/index.d.ts +1 -0
- package/types/storybook/moduleStory.d.ts +12 -0
- package/types/storybook/types.d.ts +3 -0
package/dist/createDevServer.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import url from 'url';
|
|
2
3
|
import express from 'express';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
3
5
|
import { normalizePath } from 'vite';
|
|
4
6
|
import createDevServerRoutes from './routes/createDevServerRoutes.js';
|
|
5
7
|
import { getProjectNameFromHSConfig } from './lib/proxyHelpers.js';
|
|
6
8
|
import createViteDevServer from './createViteDevServer.js';
|
|
9
|
+
import { debug } from './lib/debug.js';
|
|
7
10
|
import { getEnv, getAccountId, loadConfig, validateConfig, } from '@hubspot/cli-lib/lib/config.js';
|
|
8
11
|
const BASE_PATH = '/';
|
|
9
12
|
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
10
|
-
|
|
13
|
+
const STORYBOOK_PORT = process.env.STORYBOOK_PORT
|
|
14
|
+
? parseInt(process.env.STORYBOOK_PORT, 10)
|
|
15
|
+
: 3123;
|
|
16
|
+
async function createDevServer(webRoot, storybook, hubspotCliConfigPathOption, hubspotCliAccountNameOption) {
|
|
11
17
|
console.log('Warning: this is a prerelease and requires specific HubSpot account configuration to work');
|
|
12
18
|
let authedPortalId = null;
|
|
13
19
|
let authedEnv = null;
|
|
@@ -45,9 +51,11 @@ Local proxy functionality will not work without setting up authentication.`);
|
|
|
45
51
|
expressServer.locals.devServerPort = PORT;
|
|
46
52
|
expressServer.locals.webRoot = webRoot;
|
|
47
53
|
expressServer.locals.viteServer = viteServer;
|
|
54
|
+
expressServer.locals.storybookEnabled = storybook;
|
|
55
|
+
expressServer.locals.storybookPort = STORYBOOK_PORT;
|
|
48
56
|
expressServer.locals.projectName = getProjectNameFromHSConfig(path.join(webRoot, '../hsproject.json'));
|
|
49
57
|
expressServer.locals.projectComponentPath = webRootProjectComponentFolder;
|
|
50
|
-
expressServer.use(BASE_PATH, await createDevServerRoutes(viteServer));
|
|
58
|
+
expressServer.use(BASE_PATH, await createDevServerRoutes(viteServer, storybook ? STORYBOOK_PORT : null));
|
|
51
59
|
expressServer.listen(PORT);
|
|
52
60
|
let extraServerInfo = '';
|
|
53
61
|
if (authedPortalId) {
|
|
@@ -59,5 +67,30 @@ Local proxy functionality will not work without setting up authentication.`);
|
|
|
59
67
|
console.log(`
|
|
60
68
|
HubSpot CMS dev server hosting: ${expressServer.locals.projectName}/${expressServer.locals.projectComponentPath} (at http://localhost:${PORT}${extraServerInfo})
|
|
61
69
|
`);
|
|
70
|
+
if (storybook) {
|
|
71
|
+
const packageRoot = path.dirname(url.fileURLToPath(import.meta.url));
|
|
72
|
+
const configPath = path.resolve(packageRoot, './storybook');
|
|
73
|
+
const storybookProcess = spawn('yarn', [
|
|
74
|
+
'sb',
|
|
75
|
+
'dev',
|
|
76
|
+
'-p',
|
|
77
|
+
STORYBOOK_PORT.toString(),
|
|
78
|
+
'-c',
|
|
79
|
+
configPath,
|
|
80
|
+
'--quiet',
|
|
81
|
+
'--no-open',
|
|
82
|
+
], {
|
|
83
|
+
cwd: process.cwd(),
|
|
84
|
+
env: {
|
|
85
|
+
...process.env,
|
|
86
|
+
WEB_ROOT: path.join(webRoot, 'components'),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
console.log(`Starting storybook server on port ${STORYBOOK_PORT}`);
|
|
90
|
+
if (debug.enabled) {
|
|
91
|
+
storybookProcess.stdout.pipe(process.stdout);
|
|
92
|
+
}
|
|
93
|
+
storybookProcess.stderr.pipe(process.stderr);
|
|
94
|
+
}
|
|
62
95
|
}
|
|
63
96
|
export default createDevServer;
|
|
@@ -3,7 +3,7 @@ import { default as react } from '@vitejs/plugin-react';
|
|
|
3
3
|
import { resolveIslandPlugin } from '@hubspot/cms-js-internal';
|
|
4
4
|
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
5
5
|
async function createViteDevServer() {
|
|
6
|
-
|
|
6
|
+
const viteConfig = {
|
|
7
7
|
appType: 'custom',
|
|
8
8
|
server: {
|
|
9
9
|
middlewareMode: true,
|
|
@@ -21,6 +21,7 @@ async function createViteDevServer() {
|
|
|
21
21
|
include: ['react', 'react-dom', 'react-dom/client'],
|
|
22
22
|
},
|
|
23
23
|
plugins: [react(), resolveIslandPlugin()],
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
|
+
return createViteServer(viteConfig);
|
|
25
26
|
}
|
|
26
27
|
export default createViteDevServer;
|
package/dist/lib/cli.js
CHANGED
|
@@ -15,9 +15,11 @@ export function getDevServerCommandLineOptions(argv) {
|
|
|
15
15
|
hubspotCliAccountNameOption = args[accountOptionIndex + 1];
|
|
16
16
|
args.splice(accountOptionIndex, 2);
|
|
17
17
|
}
|
|
18
|
+
const storybook = args.findIndex(arg => arg === '--storybook') > 0;
|
|
18
19
|
return {
|
|
19
20
|
webRoot,
|
|
20
21
|
hubspotCliConfigPathOption,
|
|
21
22
|
hubspotCliAccountNameOption,
|
|
23
|
+
storybook,
|
|
22
24
|
};
|
|
23
25
|
}
|
package/dist/lib/renderModule.js
CHANGED
|
@@ -9,7 +9,7 @@ const lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
|
9
9
|
componentModule = await viteServer.ssrLoadModule(insideFolderPath);
|
|
10
10
|
}
|
|
11
11
|
catch (e) {
|
|
12
|
-
if (!e.message.includes('
|
|
12
|
+
if (!e.message.includes('Failed to load url')) {
|
|
13
13
|
throw e;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
+
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
2
3
|
import partialRouteHandler from './partial.js';
|
|
3
4
|
import linksToAllPartialsRouteHandler from './linksToAllPartialsRouteHandler.js';
|
|
4
5
|
import linksToAllModulesRouteHandler from './linksToAllModulesRouteHandler.js';
|
|
@@ -6,8 +7,23 @@ import moduleRouteHandler from './module.js';
|
|
|
6
7
|
import proxyPageRouteHandler from './proxyPageRouteHandler.js';
|
|
7
8
|
import proxyPageResourceRedirect from './proxyPageResourceRedirect.js';
|
|
8
9
|
import homeRouteHandler from './homeRouteHandler.js';
|
|
9
|
-
|
|
10
|
+
import { debug } from '../lib/debug.js';
|
|
11
|
+
import { VALID_PROXY_DOMAIN_SUFFIXES } from '../proxyPage/constants.js';
|
|
12
|
+
const STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(domain => `storybook.${domain}`);
|
|
13
|
+
const createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
10
14
|
const devServerApp = Router();
|
|
15
|
+
// Debug incoming requests, enable with the DEBUG=cms-dev-server env variable
|
|
16
|
+
devServerApp.use((request, response, next) => {
|
|
17
|
+
const { method, url, hostname } = request;
|
|
18
|
+
debug(`${method}:${hostname}${url}`);
|
|
19
|
+
next();
|
|
20
|
+
});
|
|
21
|
+
if (storybookPort) {
|
|
22
|
+
devServerApp.use(createProxyMiddleware((__pathname, req) => STORYBOOK_DOMAINS.includes(req.hostname), {
|
|
23
|
+
logLevel: 'warn',
|
|
24
|
+
target: `http://localhost:${storybookPort}`,
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
11
27
|
devServerApp.use(viteServer.middlewares);
|
|
12
28
|
devServerApp.get('/partials/', linksToAllPartialsRouteHandler);
|
|
13
29
|
devServerApp.get('/partial/:partial', partialRouteHandler);
|
|
@@ -3,10 +3,10 @@ import { findAllModulesInRoot, findAllPartialsInRoot, renderOnServer, } from '@h
|
|
|
3
3
|
import ModulesList from '../components/ModulesList.js';
|
|
4
4
|
import PartialsList from '../components/PartialsList.js';
|
|
5
5
|
const homeRouteHandler = async (request, response) => {
|
|
6
|
-
const { webRoot } = request.app.locals;
|
|
6
|
+
const { webRoot, storybookEnabled, devServerPort } = request.app.locals;
|
|
7
7
|
const { partialNames } = findAllPartialsInRoot(webRoot);
|
|
8
8
|
const { moduleNames } = findAllModulesInRoot(webRoot);
|
|
9
|
-
const { html: responseHtml } = await renderOnServer(_jsxs(_Fragment, { children: [_jsx("h2", { children: "Partials" }), _jsx(PartialsList, { webRoot: webRoot, partialNames: partialNames }), _jsx("h2", { children: "Modules" }), _jsx(ModulesList, { webRoot: webRoot, moduleNames: moduleNames })] }), null);
|
|
9
|
+
const { html: responseHtml } = await renderOnServer(_jsxs(_Fragment, { children: [storybookEnabled ? (_jsx("h2", { children: _jsx("a", { href: `//storybook.${request.hostname}:${devServerPort}`, children: "Storybook" }) })) : null, _jsx("h2", { children: "Partials" }), _jsx(PartialsList, { webRoot: webRoot, partialNames: partialNames }), _jsx("h2", { children: "Modules" }), _jsx(ModulesList, { webRoot: webRoot, moduleNames: moduleNames })] }), null);
|
|
10
10
|
response.status(200).set({ 'Content-Type': 'text/html' }).end(responseHtml);
|
|
11
11
|
};
|
|
12
12
|
export default homeRouteHandler;
|
package/dist/run.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { getDevServerCommandLineOptions } from './lib/cli.js';
|
|
3
3
|
import createDevServer from './createDevServer.js';
|
|
4
|
-
const { webRoot, hubspotCliConfigPathOption, hubspotCliAccountNameOption } = getDevServerCommandLineOptions(process.argv);
|
|
4
|
+
const { webRoot, hubspotCliConfigPathOption, hubspotCliAccountNameOption, storybook, } = getDevServerCommandLineOptions(process.argv);
|
|
5
5
|
if (!webRoot) {
|
|
6
6
|
throw new Error(`No web root path argument specified`);
|
|
7
7
|
}
|
|
8
|
-
createDevServer(webRoot, hubspotCliConfigPathOption, hubspotCliAccountNameOption);
|
|
8
|
+
createDevServer(webRoot, storybook, hubspotCliConfigPathOption, hubspotCliAccountNameOption);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export default function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
2
|
+
let resultArgTypes = {};
|
|
3
|
+
for (const field of fieldsJson) {
|
|
4
|
+
// storybook doesn't support nested controls, so emulate our nested
|
|
5
|
+
// structure with group1.group2.field structure
|
|
6
|
+
const fullFieldName = [...currentPathSegments, field.name].join('.');
|
|
7
|
+
// should this definition of fieldType => argType live next to fields in cms-components?
|
|
8
|
+
switch (field.type) {
|
|
9
|
+
case 'group': {
|
|
10
|
+
if (!field.children) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const groupResult = getFieldsArgTypes(field.children, [
|
|
14
|
+
...currentPathSegments,
|
|
15
|
+
field.name,
|
|
16
|
+
]);
|
|
17
|
+
resultArgTypes = {
|
|
18
|
+
...resultArgTypes,
|
|
19
|
+
...groupResult,
|
|
20
|
+
};
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'boolean': {
|
|
24
|
+
resultArgTypes[fullFieldName] = {
|
|
25
|
+
control: 'boolean',
|
|
26
|
+
defaultValue: field.default,
|
|
27
|
+
};
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
case 'text': {
|
|
31
|
+
resultArgTypes[fullFieldName] = {
|
|
32
|
+
control: 'text',
|
|
33
|
+
defaultValue: field.default,
|
|
34
|
+
};
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return resultArgTypes;
|
|
42
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { ModuleFields, BooleanField, TextField, FieldGroup, } from '@hubspot/cms-components/fields';
|
|
4
|
+
import { renderFieldsToJson } from '@hubspot/cms-js-internal';
|
|
5
|
+
import getFieldsArgTypes from './getFieldsArgTypes.js';
|
|
6
|
+
describe('getFieldsArgTypes', () => {
|
|
7
|
+
it('creates argType for boolean field', () => {
|
|
8
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false }) }));
|
|
9
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
10
|
+
expect(argTypes).toStrictEqual({
|
|
11
|
+
testBooleanField: {
|
|
12
|
+
control: 'boolean',
|
|
13
|
+
defaultValue: false,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it('creates text argType for text field', () => {
|
|
18
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(TextField, { name: "testStringField", label: "field", default: 'test' }) }));
|
|
19
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
20
|
+
expect(argTypes).toStrictEqual({
|
|
21
|
+
testStringField: {
|
|
22
|
+
control: 'text',
|
|
23
|
+
defaultValue: 'test',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('prefixes fields in a group with . separated group names', () => {
|
|
28
|
+
const fields = (_jsx(ModuleFields, { children: _jsxs(FieldGroup, { name: "mygroup", label: "field group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false })] }) }));
|
|
29
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
30
|
+
expect(argTypes).toStrictEqual({
|
|
31
|
+
'mygroup.testStringField': {
|
|
32
|
+
control: 'text',
|
|
33
|
+
defaultValue: 'test',
|
|
34
|
+
},
|
|
35
|
+
'mygroup.testBooleanField': {
|
|
36
|
+
control: 'boolean',
|
|
37
|
+
defaultValue: false,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('handles multiple nesting alongside top level values', () => {
|
|
42
|
+
const fields = (_jsxs(ModuleFields, { children: [_jsx(TextField, { name: "toplevel", label: "top level text field", default: "defaultvalue" }), _jsxs(FieldGroup, { name: "mygroup", label: "field group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false }), _jsxs(FieldGroup, { name: "nestedgroup", label: "nested group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false })] })] })] }));
|
|
43
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
44
|
+
expect(argTypes).toStrictEqual({
|
|
45
|
+
toplevel: {
|
|
46
|
+
control: 'text',
|
|
47
|
+
defaultValue: 'defaultvalue',
|
|
48
|
+
},
|
|
49
|
+
'mygroup.testStringField': {
|
|
50
|
+
control: 'text',
|
|
51
|
+
defaultValue: 'test',
|
|
52
|
+
},
|
|
53
|
+
'mygroup.testBooleanField': {
|
|
54
|
+
control: 'boolean',
|
|
55
|
+
defaultValue: false,
|
|
56
|
+
},
|
|
57
|
+
'mygroup.nestedgroup.testStringField': {
|
|
58
|
+
control: 'text',
|
|
59
|
+
defaultValue: 'test',
|
|
60
|
+
},
|
|
61
|
+
'mygroup.nestedgroup.testBooleanField': {
|
|
62
|
+
control: 'boolean',
|
|
63
|
+
defaultValue: false,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Field } from '@hubspot/cms-components/fields';
|
|
2
|
+
|
|
3
|
+
export default function getFieldsArgTypes(
|
|
4
|
+
fieldsJson: Field[],
|
|
5
|
+
currentPathSegments = []
|
|
6
|
+
) {
|
|
7
|
+
let resultArgTypes = {};
|
|
8
|
+
for (const field of fieldsJson) {
|
|
9
|
+
// storybook doesn't support nested controls, so emulate our nested
|
|
10
|
+
// structure with group1.group2.field structure
|
|
11
|
+
const fullFieldName = [...currentPathSegments, field.name].join('.');
|
|
12
|
+
// should this definition of fieldType => argType live next to fields in cms-components?
|
|
13
|
+
switch (field.type) {
|
|
14
|
+
case 'group': {
|
|
15
|
+
if (!field.children) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const groupResult = getFieldsArgTypes(field.children, [
|
|
19
|
+
...currentPathSegments,
|
|
20
|
+
field.name,
|
|
21
|
+
]);
|
|
22
|
+
resultArgTypes = {
|
|
23
|
+
...resultArgTypes,
|
|
24
|
+
...groupResult,
|
|
25
|
+
};
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'boolean': {
|
|
29
|
+
resultArgTypes[fullFieldName] = {
|
|
30
|
+
control: 'boolean',
|
|
31
|
+
defaultValue: field.default,
|
|
32
|
+
};
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'text': {
|
|
36
|
+
resultArgTypes[fullFieldName] = {
|
|
37
|
+
control: 'text',
|
|
38
|
+
defaultValue: field.default,
|
|
39
|
+
};
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
default:
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return resultArgTypes;
|
|
47
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// default values come through via `defaultValue` in the story's argTypes, we
|
|
2
|
+
// need to re-nest them to match the field structure
|
|
3
|
+
export default function getNestedFieldObjectForArgs(_args) {
|
|
4
|
+
const result = {};
|
|
5
|
+
for (const argPath in _args) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(_args, argPath)) {
|
|
7
|
+
const argPathSegments = argPath.split('.');
|
|
8
|
+
const nestedSegments = argPathSegments.slice(0, -1);
|
|
9
|
+
const fieldName = argPathSegments[argPathSegments.length - 1];
|
|
10
|
+
const fieldValue = _args[argPath];
|
|
11
|
+
let currentNest = result;
|
|
12
|
+
for (const segment of nestedSegments) {
|
|
13
|
+
if (!Object.prototype.hasOwnProperty.call(currentNest, segment)) {
|
|
14
|
+
currentNest[segment] = {};
|
|
15
|
+
}
|
|
16
|
+
currentNest = currentNest[segment];
|
|
17
|
+
}
|
|
18
|
+
currentNest[fieldName] = fieldValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import getNestedFieldObjectForArgs from './getNestedFieldObjectForArgs.js';
|
|
3
|
+
describe('getNestedFieldObjectForArgs', () => {
|
|
4
|
+
it('leaves top level args as is', () => {
|
|
5
|
+
const argMap = {
|
|
6
|
+
testField: 'testValue',
|
|
7
|
+
testField2: 'testValue',
|
|
8
|
+
};
|
|
9
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
10
|
+
expect(result).toStrictEqual(argMap);
|
|
11
|
+
});
|
|
12
|
+
it('turns a . separated arg name into a nested field', () => {
|
|
13
|
+
const argMap = {
|
|
14
|
+
'group.testField': 'testValue',
|
|
15
|
+
topLevelField: 'testValue',
|
|
16
|
+
};
|
|
17
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
18
|
+
expect(result).toStrictEqual({
|
|
19
|
+
group: {
|
|
20
|
+
testField: 'testValue',
|
|
21
|
+
},
|
|
22
|
+
topLevelField: 'testValue',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it('keeps nested fields with the same group prefix nested in the same object', () => {
|
|
26
|
+
const argMap = {
|
|
27
|
+
'group.testField': 'testValue',
|
|
28
|
+
'group.secondField': 'testValue',
|
|
29
|
+
topLevelField: 'testValue',
|
|
30
|
+
};
|
|
31
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
32
|
+
expect(result).toStrictEqual({
|
|
33
|
+
group: {
|
|
34
|
+
testField: 'testValue',
|
|
35
|
+
secondField: 'testValue',
|
|
36
|
+
},
|
|
37
|
+
topLevelField: 'testValue',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
package/dist/storybook/index.js
CHANGED
|
@@ -35,8 +35,20 @@ function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
|
35
35
|
};
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
case "number": {
|
|
39
|
+
resultArgTypes[fullFieldName] = {
|
|
40
|
+
control: "number",
|
|
41
|
+
defaultValue: field.default
|
|
42
|
+
};
|
|
39
43
|
break;
|
|
44
|
+
}
|
|
45
|
+
default: {
|
|
46
|
+
resultArgTypes[fullFieldName] = {
|
|
47
|
+
control: "object",
|
|
48
|
+
defaultValue: field.default
|
|
49
|
+
};
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
return resultArgTypes;
|
package/dist/storybook/main.js
CHANGED
|
@@ -10,7 +10,12 @@ export default {
|
|
|
10
10
|
const { resolveIslandPlugin } = await import('@hubspot/cms-js-internal');
|
|
11
11
|
const viteConfig = {
|
|
12
12
|
resolve: {
|
|
13
|
-
dedupe: [
|
|
13
|
+
dedupe: [
|
|
14
|
+
'react',
|
|
15
|
+
'react-dom',
|
|
16
|
+
'@hubspot/cms-components',
|
|
17
|
+
'@hubspot/cms-dev-server',
|
|
18
|
+
],
|
|
14
19
|
},
|
|
15
20
|
optimizeDeps: {
|
|
16
21
|
include: ['react', 'react-dom', 'react-dom/client'],
|
|
@@ -37,8 +37,20 @@ function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
|
37
37
|
};
|
|
38
38
|
break;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
case 'number': {
|
|
41
|
+
resultArgTypes[fullFieldName] = {
|
|
42
|
+
control: 'number',
|
|
43
|
+
defaultValue: field.default,
|
|
44
|
+
};
|
|
41
45
|
break;
|
|
46
|
+
}
|
|
47
|
+
default: {
|
|
48
|
+
resultArgTypes[fullFieldName] = {
|
|
49
|
+
control: 'object',
|
|
50
|
+
defaultValue: field.default,
|
|
51
|
+
};
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
56
|
return resultArgTypes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/createViteDevServer.js",
|
|
7
6
|
"engines": {
|
|
8
7
|
"node": ">=16.x"
|
|
9
8
|
},
|
|
10
9
|
"scripts": {
|
|
11
|
-
"build": "tsc --build &&
|
|
10
|
+
"build": "tsc --build && yarn run copy-html && yarn build-types && node scripts/build.mjs",
|
|
12
11
|
"copy-html": "copyfiles -u 1 'src/html/**' 'dist'",
|
|
12
|
+
"build-types": "tsc --project tsconfig.types.json",
|
|
13
13
|
"clean": "tsc --build --clean",
|
|
14
14
|
"dev": "nodemon --exec 'ts-node-esm --transpileOnly runWhenDeveloping.ts'",
|
|
15
15
|
"dev-inspect": "nodemon --exec 'node --loader ts-node/esm --inspect runWhenDeveloping.ts'",
|
|
@@ -21,16 +21,26 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@hubspot/cli-lib": "^3.0.12",
|
|
24
|
-
"@hubspot/cms-components": "^0.
|
|
25
|
-
"@hubspot/cms-js-internal": "^0.
|
|
26
|
-
"@
|
|
24
|
+
"@hubspot/cms-components": "^0.3.1",
|
|
25
|
+
"@hubspot/cms-js-internal": "^0.3.1",
|
|
26
|
+
"@storybook/addon-actions": "^7.0.0-beta.19",
|
|
27
|
+
"@storybook/addon-essentials": "^7.0.0-beta.19",
|
|
28
|
+
"@storybook/addon-interactions": "^7.0.0-beta.19",
|
|
29
|
+
"@storybook/addon-links": "^7.0.0-beta.19",
|
|
30
|
+
"@storybook/cli": "^7.0.0-beta.19",
|
|
31
|
+
"@storybook/react": "^7.0.0-beta.19",
|
|
32
|
+
"@storybook/react-vite": "^7.0.0-beta.19",
|
|
33
|
+
"@storybook/testing-library": "^0.0.13",
|
|
34
|
+
"@vitejs/plugin-react": "^3.0.0",
|
|
27
35
|
"ansi-to-html": "0.7.x",
|
|
36
|
+
"debug": "^4.3.4",
|
|
28
37
|
"express": "^4.17.3",
|
|
38
|
+
"http-proxy-middleware": "^2.0.6",
|
|
29
39
|
"react": "^18.1.0",
|
|
30
40
|
"react-dom": "^18.1.0",
|
|
31
41
|
"request": "^2.88.2",
|
|
32
42
|
"typescript": "~4.7.0",
|
|
33
|
-
"vite": "^
|
|
43
|
+
"vite": "^4.0.0",
|
|
34
44
|
"vite-plugin-inspect": "^0.4.3"
|
|
35
45
|
},
|
|
36
46
|
"devDependencies": {
|
|
@@ -40,13 +50,24 @@
|
|
|
40
50
|
"copyfiles": "^2.4.1",
|
|
41
51
|
"nodemon": "^2.0.15",
|
|
42
52
|
"ts-node": "^10.7.0",
|
|
43
|
-
"vitest": "0.
|
|
53
|
+
"vitest": "0.25.8"
|
|
54
|
+
},
|
|
55
|
+
"main": "./dist/createViteDevServer.js",
|
|
56
|
+
"exports": {
|
|
57
|
+
".": "./dist/createViteDevServer.js",
|
|
58
|
+
"./storybook": {
|
|
59
|
+
"types": "./types/storybook/index.d.ts",
|
|
60
|
+
"default": "./dist/storybook/index.js"
|
|
61
|
+
},
|
|
62
|
+
"./dist/storybook/preview.js": "./dist/storybook/preview.js"
|
|
44
63
|
},
|
|
64
|
+
"types": "types/index.d.ts",
|
|
45
65
|
"bin": {
|
|
46
66
|
"hs-cms-dev-server": "./dist/run.js"
|
|
47
67
|
},
|
|
48
68
|
"files": [
|
|
49
|
-
"dist/**/*"
|
|
69
|
+
"dist/**/*",
|
|
70
|
+
"types"
|
|
50
71
|
],
|
|
51
72
|
"nodemonConfig": {
|
|
52
73
|
"ext": "js,json,ts,tsx,jsx,html",
|
|
@@ -64,5 +85,5 @@
|
|
|
64
85
|
"publishConfig": {
|
|
65
86
|
"access": "public"
|
|
66
87
|
},
|
|
67
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "3eaa36708908e15af14d091ba1995b9bcd6caad7"
|
|
68
89
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Field } from '@hubspot/cms-components/fields';
|
|
2
|
+
declare type ArgTypes = {
|
|
3
|
+
[fieldPath: string]: {
|
|
4
|
+
control: string;
|
|
5
|
+
defaultValue: any;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export default function getFieldsArgTypes(fieldsJson: Field[], currentPathSegments?: string[]): ArgTypes;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './moduleStory.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Field } from '@hubspot/cms-components/fields';
|
|
3
|
+
declare type Args = {
|
|
4
|
+
[fieldPath: string]: any;
|
|
5
|
+
};
|
|
6
|
+
declare type FieldValues = {
|
|
7
|
+
[fieldNameOrGroupName: string]: FieldValues;
|
|
8
|
+
};
|
|
9
|
+
export declare function getNestedFieldObjectForArgs(_args: Args): FieldValues;
|
|
10
|
+
export declare function moduleFieldsToJson(fields: JSX.Element): Field[];
|
|
11
|
+
export declare function moduleStory(ModuleComponent: React.ComponentType, fields: JSX.Element): any;
|
|
12
|
+
export {};
|