@hubspot/cms-dev-server 0.3.1 → 0.3.2

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.
@@ -43,10 +43,10 @@ If needed you can refer to another config file with --config.
43
43
 
44
44
  Local proxy functionality will not work without setting up authentication.`);
45
45
  }
46
- const expressServer = express();
47
- const viteServer = await createViteDevServer();
48
46
  const absoluteWebRoot = normalizePath(path.resolve(process.cwd(), webRoot));
49
47
  const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, '').split('/').slice(-2);
48
+ const expressServer = express();
49
+ const viteServer = await createViteDevServer(absoluteWebRoot);
50
50
  expressServer.locals.devServerHost = 'localhost';
51
51
  expressServer.locals.devServerPort = PORT;
52
52
  expressServer.locals.webRoot = webRoot;
@@ -1,8 +1,8 @@
1
- import { createServer as createViteServer } from 'vite';
1
+ import { createServer as createViteServer, } from 'vite';
2
2
  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
- async function createViteDevServer() {
5
+ async function createViteDevServer(webRoot) {
6
6
  const viteConfig = {
7
7
  appType: 'custom',
8
8
  server: {
@@ -20,6 +20,9 @@ async function createViteDevServer() {
20
20
  optimizeDeps: {
21
21
  include: ['react', 'react-dom', 'react-dom/client'],
22
22
  },
23
+ css: {
24
+ postcss: webRoot,
25
+ },
23
26
  plugins: [react(), resolveIslandPlugin()],
24
27
  };
25
28
  return createViteServer(viteConfig);
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default as createViteDevServer } from './createViteDevServer.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -21,8 +21,8 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@hubspot/cli-lib": "^3.0.12",
24
- "@hubspot/cms-components": "^0.3.1",
25
- "@hubspot/cms-js-internal": "^0.3.1",
24
+ "@hubspot/cms-components": "^0.3.2",
25
+ "@hubspot/cms-js-internal": "^0.3.2",
26
26
  "@storybook/addon-actions": "^7.0.0-beta.19",
27
27
  "@storybook/addon-essentials": "^7.0.0-beta.19",
28
28
  "@storybook/addon-interactions": "^7.0.0-beta.19",
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "3eaa36708908e15af14d091ba1995b9bcd6caad7"
88
+ "gitHead": "7421368e55dab0204aa03c7f937287f8e1f0c8be"
89
89
  }
@@ -0,0 +1,2 @@
1
+ declare function createViteDevServer(webRoot: string): Promise<import("vite").ViteDevServer>;
2
+ export default createViteDevServer;
@@ -0,0 +1 @@
1
+ export { default as createViteDevServer } from './createViteDevServer.js';
@@ -1,42 +0,0 @@
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
- }
@@ -1,67 +0,0 @@
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
- });
@@ -1,47 +0,0 @@
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
- }
@@ -1,22 +0,0 @@
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
- }
@@ -1,40 +0,0 @@
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
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
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 {};
@@ -1,6 +0,0 @@
1
- import { Args } from './types.js';
2
- declare type FieldValues = {
3
- [fieldNameOrGroupName: string]: FieldValues;
4
- };
5
- export default function getNestedFieldObjectForArgs(_args: Args): FieldValues;
6
- export {};
@@ -1,3 +0,0 @@
1
- export declare type Args = {
2
- [fieldPath: string]: any;
3
- };