@hubspot/cms-dev-server 0.15.4 → 0.15.8
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 +2 -0
- package/dist/internalSsr.js +268 -2
- package/dist/run.js +399 -46
- package/dist/storybook/index.js +3 -1
- package/dist/storybook-main/main.js +269 -3
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -107,6 +107,8 @@ var {
|
|
|
107
107
|
createServerRenderContext: createServerRenderContext2,
|
|
108
108
|
renderServerSidePropsWithAsyncLocalStoreContext
|
|
109
109
|
} = cmsComponents;
|
|
110
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
111
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
110
112
|
|
|
111
113
|
// src/createViteDevServer.ts
|
|
112
114
|
import { default as mkcert } from "vite-plugin-mkcert";
|
package/dist/internalSsr.js
CHANGED
|
@@ -445,7 +445,9 @@ import stream from "stream";
|
|
|
445
445
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
446
446
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
447
447
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
448
|
-
import {
|
|
448
|
+
import { writeFileSync } from "fs";
|
|
449
|
+
import ts from "typescript";
|
|
450
|
+
import React, { isValidElement, cloneElement } from "react";
|
|
449
451
|
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
450
452
|
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
451
453
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
@@ -717,6 +719,265 @@ async function renderOnServer(elements, renderContext = bootStrapRenderContext()
|
|
|
717
719
|
}
|
|
718
720
|
return { html, renderContext };
|
|
719
721
|
}
|
|
722
|
+
var fieldTypeNameByType = {
|
|
723
|
+
alignment: "AlignmentFieldType",
|
|
724
|
+
audioplayer: "AudioFieldType",
|
|
725
|
+
backgroundimage: "BackgroundImageFieldType",
|
|
726
|
+
blog: "BlogFieldType",
|
|
727
|
+
boolean: "BooleanFieldType",
|
|
728
|
+
border: "BorderFieldType",
|
|
729
|
+
choice: "ChoiceFieldType",
|
|
730
|
+
color: "ColorFieldType",
|
|
731
|
+
crmobject: "CrmObjectFieldType",
|
|
732
|
+
cta: "CtaFieldType",
|
|
733
|
+
date: "DateFieldType",
|
|
734
|
+
datetime: "DateTimeFieldType",
|
|
735
|
+
email: "EmailFieldType",
|
|
736
|
+
embed: "EmbedFieldType",
|
|
737
|
+
file: "FileFieldType",
|
|
738
|
+
followupemail: "FollowUpEmailFieldType",
|
|
739
|
+
font: "FontFieldType",
|
|
740
|
+
form: "FormFieldType",
|
|
741
|
+
gradient: "GradientFieldType",
|
|
742
|
+
group: "GroupFieldType",
|
|
743
|
+
html: "HtmlFieldType",
|
|
744
|
+
hubdbrow: "HubDbRowFieldType",
|
|
745
|
+
hubdbtable: "HubDbTableFieldType",
|
|
746
|
+
hubl: "HublFieldType",
|
|
747
|
+
icon: "IconFieldType",
|
|
748
|
+
image: "ImageFieldType",
|
|
749
|
+
link: "LinkFieldType",
|
|
750
|
+
logo: "LogoFieldType",
|
|
751
|
+
meeting: "MeetingFieldType",
|
|
752
|
+
menu: "MenuFieldType",
|
|
753
|
+
number: "NumberFieldType",
|
|
754
|
+
page: "PageFieldType",
|
|
755
|
+
payment: "PaymentFieldType",
|
|
756
|
+
podcast: "PodcastFieldType",
|
|
757
|
+
richtext: "RichTextFieldType",
|
|
758
|
+
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
759
|
+
simplemenu: "SimpleMenuFieldType",
|
|
760
|
+
spacing: "SpacingFieldType",
|
|
761
|
+
survey: "SurveyFieldType",
|
|
762
|
+
tag: "TagFieldType",
|
|
763
|
+
textalignment: "TextAlignmentFieldType",
|
|
764
|
+
text: "TextFieldType",
|
|
765
|
+
url: "UrlFieldType",
|
|
766
|
+
video: "VideoFieldType",
|
|
767
|
+
workflow: "WorkflowFieldType"
|
|
768
|
+
};
|
|
769
|
+
var getChildrenAsArray = (element) => React.Children.toArray(element.props.children);
|
|
770
|
+
function getFieldEntries(fields) {
|
|
771
|
+
if (isValidElement(fields)) {
|
|
772
|
+
const fieldsJSX = getChildrenAsArray(fields);
|
|
773
|
+
return getReactFieldEntries(fieldsJSX);
|
|
774
|
+
} else if (Array.isArray(fields)) {
|
|
775
|
+
return getJSONFieldEntries(fields);
|
|
776
|
+
}
|
|
777
|
+
return void 0;
|
|
778
|
+
}
|
|
779
|
+
var getJSXFieldType = (fieldFunctionName) => {
|
|
780
|
+
switch (fieldFunctionName) {
|
|
781
|
+
case "RepeatedFieldGroup":
|
|
782
|
+
case "FieldGroup":
|
|
783
|
+
return "GroupFieldType";
|
|
784
|
+
default:
|
|
785
|
+
return `${fieldFunctionName}Type`;
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
var getElementName = (element) => typeof element.type === "string" ? element.type : element.type.name || null;
|
|
789
|
+
function getReactFieldEntries(fields) {
|
|
790
|
+
const validTypeNames = Object.values(fieldTypeNameByType);
|
|
791
|
+
if (!Array.isArray(fields)) {
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
return fields.filter((field) => field.props && field.props.name).map((field) => {
|
|
795
|
+
const elName = getElementName(field);
|
|
796
|
+
const fieldType = getJSXFieldType(getElementName(field));
|
|
797
|
+
if (!validTypeNames.includes(fieldType)) {
|
|
798
|
+
return void 0;
|
|
799
|
+
}
|
|
800
|
+
const { name, default: hasDefault } = field.props;
|
|
801
|
+
const isRepeater = elName === "RepeatedFieldGroup";
|
|
802
|
+
const entry = {
|
|
803
|
+
type: fieldType,
|
|
804
|
+
name,
|
|
805
|
+
hasDefault: !!hasDefault,
|
|
806
|
+
isRepeater,
|
|
807
|
+
children: []
|
|
808
|
+
};
|
|
809
|
+
if (fieldType === "GroupFieldType") {
|
|
810
|
+
const childrenArray = getChildrenAsArray(field);
|
|
811
|
+
const children = getReactFieldEntries(childrenArray);
|
|
812
|
+
return {
|
|
813
|
+
...entry,
|
|
814
|
+
children
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
return entry;
|
|
818
|
+
}).filter((entry) => entry !== void 0);
|
|
819
|
+
}
|
|
820
|
+
function getJSONFieldEntries(fields) {
|
|
821
|
+
if (!Array.isArray(fields)) {
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
825
|
+
const { name, type } = field;
|
|
826
|
+
const fieldType = fieldTypeNameByType[type];
|
|
827
|
+
if (!fieldType) {
|
|
828
|
+
return void 0;
|
|
829
|
+
}
|
|
830
|
+
const entry = {
|
|
831
|
+
type: fieldType,
|
|
832
|
+
name,
|
|
833
|
+
isRepeater: "occurrence" in field,
|
|
834
|
+
hasDefault: !!field.default,
|
|
835
|
+
children: []
|
|
836
|
+
};
|
|
837
|
+
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
838
|
+
const children = getJSONFieldEntries(field.children);
|
|
839
|
+
return { ...entry, children };
|
|
840
|
+
}
|
|
841
|
+
return entry;
|
|
842
|
+
}).filter((entry) => entry !== void 0);
|
|
843
|
+
}
|
|
844
|
+
var OVERRIDE_TYPE = "Override";
|
|
845
|
+
var REQUIRED_TYPE = "Required";
|
|
846
|
+
var REPEATED_VAR = "_repeater";
|
|
847
|
+
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
848
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
849
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
850
|
+
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
851
|
+
var createPropertySignature = (identifier, type) => ts.factory.createPropertySignature([], identifier, void 0, type);
|
|
852
|
+
var buildTypeFromField = (field, additionalNode) => {
|
|
853
|
+
const imports = [field.type];
|
|
854
|
+
const identifier = ts.factory.createIdentifier(field.name);
|
|
855
|
+
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
856
|
+
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
857
|
+
baseType
|
|
858
|
+
]);
|
|
859
|
+
let finalType = field.hasDefault ? requiredType : baseType;
|
|
860
|
+
if (additionalNode) {
|
|
861
|
+
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
862
|
+
const repeaterName = ts.factory.createLiteralTypeNode(
|
|
863
|
+
ts.factory.createStringLiteral(REPEATED_VAR)
|
|
864
|
+
);
|
|
865
|
+
if (!field.isRepeater) {
|
|
866
|
+
imports.push(OVERRIDE_TYPE);
|
|
867
|
+
}
|
|
868
|
+
finalType = field.isRepeater ? ts.factory.createTypeReferenceNode("Array", [
|
|
869
|
+
ts.factory.createTypeReferenceNode("Record", [
|
|
870
|
+
repeaterName,
|
|
871
|
+
typeLiteral
|
|
872
|
+
])
|
|
873
|
+
]) : ts.factory.createTypeReferenceNode(OVERRIDE_TYPE, [
|
|
874
|
+
finalType,
|
|
875
|
+
typeLiteral
|
|
876
|
+
]);
|
|
877
|
+
}
|
|
878
|
+
return { type: createPropertySignature(identifier, finalType), imports };
|
|
879
|
+
};
|
|
880
|
+
function getImportDeclaration(imports, moduleSpecifier) {
|
|
881
|
+
const importSpecifiers = Array.from(imports).map(
|
|
882
|
+
(importName) => ts.factory.createImportSpecifier(
|
|
883
|
+
true,
|
|
884
|
+
void 0,
|
|
885
|
+
ts.factory.createIdentifier(importName)
|
|
886
|
+
)
|
|
887
|
+
);
|
|
888
|
+
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
889
|
+
return ts.factory.createImportDeclaration(
|
|
890
|
+
[],
|
|
891
|
+
[],
|
|
892
|
+
ts.factory.createImportClause(false, void 0, namedImports),
|
|
893
|
+
ts.factory.createStringLiteral(moduleSpecifier)
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
function getFieldTypes(fields) {
|
|
897
|
+
const imports = ["DefaultValues"];
|
|
898
|
+
const types = fields.map((field) => {
|
|
899
|
+
if (field.children) {
|
|
900
|
+
const childrenResult = getFieldTypes(field.children);
|
|
901
|
+
imports.push(...childrenResult.imports);
|
|
902
|
+
if (childrenResult.types.length) {
|
|
903
|
+
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
904
|
+
const childrenPropertySignature = createPropertySignature(
|
|
905
|
+
"children",
|
|
906
|
+
subType
|
|
907
|
+
);
|
|
908
|
+
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
909
|
+
field,
|
|
910
|
+
field.isRepeater ? subType : childrenPropertySignature
|
|
911
|
+
);
|
|
912
|
+
imports.push(...newImports2);
|
|
913
|
+
return type2;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
const { type, imports: newImports } = buildTypeFromField(field);
|
|
917
|
+
imports.push(...newImports);
|
|
918
|
+
return type;
|
|
919
|
+
});
|
|
920
|
+
return { types, imports: Array.from(new Set(imports)) };
|
|
921
|
+
}
|
|
922
|
+
function constructFinalType(fields, typeName) {
|
|
923
|
+
const { types, imports } = getFieldTypes(fields);
|
|
924
|
+
const importDeclaration = getImportDeclaration(
|
|
925
|
+
imports,
|
|
926
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
927
|
+
);
|
|
928
|
+
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
929
|
+
[],
|
|
930
|
+
[],
|
|
931
|
+
"",
|
|
932
|
+
void 0,
|
|
933
|
+
ts.factory.createTypeLiteralNode(types)
|
|
934
|
+
);
|
|
935
|
+
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
936
|
+
baseType.type
|
|
937
|
+
]);
|
|
938
|
+
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
939
|
+
[],
|
|
940
|
+
[],
|
|
941
|
+
typeName,
|
|
942
|
+
void 0,
|
|
943
|
+
wrappedType
|
|
944
|
+
);
|
|
945
|
+
const defaultExport = ts.factory.createExportDefault(
|
|
946
|
+
ts.factory.createIdentifier(typeName)
|
|
947
|
+
);
|
|
948
|
+
return [importDeclaration, finalType, defaultExport];
|
|
949
|
+
}
|
|
950
|
+
function writeFieldsType(fields, fileName, typeName) {
|
|
951
|
+
const entries = getFieldEntries(fields);
|
|
952
|
+
if (!entries) {
|
|
953
|
+
return false;
|
|
954
|
+
}
|
|
955
|
+
try {
|
|
956
|
+
const file = ts.createSourceFile(
|
|
957
|
+
fileName,
|
|
958
|
+
"",
|
|
959
|
+
ts.ScriptTarget.ESNext,
|
|
960
|
+
false,
|
|
961
|
+
ts.ScriptKind.TS
|
|
962
|
+
);
|
|
963
|
+
const printer = ts.createPrinter();
|
|
964
|
+
const nodes = constructFinalType(entries, typeName);
|
|
965
|
+
const comments = [
|
|
966
|
+
AUTO_GEN_COMMENT,
|
|
967
|
+
"Removing the above comment will disable type generation for this module",
|
|
968
|
+
"This file was created by @hubspot/cms-dev-server, for more information see https://github.hubspot.com/cms-react/reference/js-modules.html#module-fields"
|
|
969
|
+
].map((comment) => `// ${comment}`);
|
|
970
|
+
const typeResult = nodes.map(
|
|
971
|
+
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
972
|
+
);
|
|
973
|
+
const result = [...comments, ...typeResult].join("\n");
|
|
974
|
+
writeFileSync(fileName, result);
|
|
975
|
+
return true;
|
|
976
|
+
} catch (e) {
|
|
977
|
+
console.error(e);
|
|
978
|
+
return false;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
720
981
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
721
982
|
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
722
983
|
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
@@ -793,6 +1054,7 @@ function renderFieldsToJson(fields, moduleName) {
|
|
|
793
1054
|
}
|
|
794
1055
|
}
|
|
795
1056
|
export {
|
|
1057
|
+
AUTO_GEN_COMMENT,
|
|
796
1058
|
COMPONENT_EXTENSIONS,
|
|
797
1059
|
CSS_LANGS_RE,
|
|
798
1060
|
ENABLED_FEATURES_GATE_MAP,
|
|
@@ -802,9 +1064,11 @@ export {
|
|
|
802
1064
|
VIRTUAL_CONFIG_SETUP,
|
|
803
1065
|
VIRTUAL_ISLAND_RUNTIME,
|
|
804
1066
|
areBuildHealthChecksEnabled,
|
|
1067
|
+
buildTypeFromField,
|
|
805
1068
|
clientIslandEntryPlugin,
|
|
806
1069
|
collectCssInDev,
|
|
807
1070
|
collectCssModules,
|
|
1071
|
+
constructFinalType,
|
|
808
1072
|
createIslandsGlobalJsForClientInDev,
|
|
809
1073
|
doHealthChecksFailTheBuild,
|
|
810
1074
|
escapeForInlineJS,
|
|
@@ -819,6 +1083,7 @@ export {
|
|
|
819
1083
|
getComponentExtension,
|
|
820
1084
|
getEntryPointHash,
|
|
821
1085
|
getEntryPointHashWithIndexSuffix,
|
|
1086
|
+
getFieldTypes,
|
|
822
1087
|
getIslandRuntimeConfigUrl,
|
|
823
1088
|
getIslandUrls,
|
|
824
1089
|
getServerGlobalsToInject,
|
|
@@ -845,5 +1110,6 @@ export {
|
|
|
845
1110
|
serializeIslandDataForInlineScript,
|
|
846
1111
|
setIn,
|
|
847
1112
|
ungatedAtBuildTimeFor,
|
|
848
|
-
virtualClientRenderIslandModuleId
|
|
1113
|
+
virtualClientRenderIslandModuleId,
|
|
1114
|
+
writeFieldsType
|
|
849
1115
|
};
|
package/dist/run.js
CHANGED
|
@@ -35,6 +35,7 @@ Options:
|
|
|
35
35
|
-a, --account The account name or id to use for the dev server.
|
|
36
36
|
--ssl Enables SSL for the dev server, serving it over an https:// URL.
|
|
37
37
|
--storybook Launches a Storybook dev server.
|
|
38
|
+
--generateFieldsTypes Generate types for fields.(jsx|json) files in module folders.
|
|
38
39
|
|
|
39
40
|
For more information on HubSpot CMS JS Rendering, visit:
|
|
40
41
|
${wrapMessageInColor(
|
|
@@ -47,7 +48,7 @@ function getDevServerCommandLineOptions(argv) {
|
|
|
47
48
|
const webRoot2 = args[2];
|
|
48
49
|
let hubspotCliConfigPathOption2;
|
|
49
50
|
let hubspotCliAccountNameOption2;
|
|
50
|
-
if (args.length
|
|
51
|
+
if (args.length === 2 || args.includes("help") || args.includes("--help")) {
|
|
51
52
|
printHelpMessage();
|
|
52
53
|
process.exit(0);
|
|
53
54
|
}
|
|
@@ -67,17 +68,19 @@ function getDevServerCommandLineOptions(argv) {
|
|
|
67
68
|
}
|
|
68
69
|
const sslEnabledOption2 = args.includes("--ssl") && !args.includes("--no-ssl");
|
|
69
70
|
const storybook2 = args.findIndex((arg) => arg === "--storybook") > 0;
|
|
71
|
+
const fieldGenEnabledOption2 = args.includes("--generateFieldsTypes");
|
|
70
72
|
return {
|
|
71
73
|
hubspotCliConfigPathOption: hubspotCliConfigPathOption2,
|
|
72
74
|
hubspotCliAccountNameOption: hubspotCliAccountNameOption2,
|
|
73
75
|
sslEnabledOption: sslEnabledOption2,
|
|
74
76
|
storybook: storybook2,
|
|
77
|
+
fieldGenEnabledOption: fieldGenEnabledOption2,
|
|
75
78
|
webRoot: webRoot2
|
|
76
79
|
};
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
// src/createDevServer.ts
|
|
80
|
-
import
|
|
83
|
+
import path9 from "path";
|
|
81
84
|
import url2 from "url";
|
|
82
85
|
import express2 from "express";
|
|
83
86
|
import http3 from "http";
|
|
@@ -409,6 +412,9 @@ import stream from "stream";
|
|
|
409
412
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
410
413
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
411
414
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
415
|
+
import { writeFileSync } from "fs";
|
|
416
|
+
import ts from "typescript";
|
|
417
|
+
import React, { isValidElement, cloneElement } from "react";
|
|
412
418
|
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
413
419
|
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
414
420
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
@@ -652,6 +658,265 @@ async function renderOnServer(elements, renderContext = bootStrapRenderContext()
|
|
|
652
658
|
}
|
|
653
659
|
return { html, renderContext };
|
|
654
660
|
}
|
|
661
|
+
var fieldTypeNameByType = {
|
|
662
|
+
alignment: "AlignmentFieldType",
|
|
663
|
+
audioplayer: "AudioFieldType",
|
|
664
|
+
backgroundimage: "BackgroundImageFieldType",
|
|
665
|
+
blog: "BlogFieldType",
|
|
666
|
+
boolean: "BooleanFieldType",
|
|
667
|
+
border: "BorderFieldType",
|
|
668
|
+
choice: "ChoiceFieldType",
|
|
669
|
+
color: "ColorFieldType",
|
|
670
|
+
crmobject: "CrmObjectFieldType",
|
|
671
|
+
cta: "CtaFieldType",
|
|
672
|
+
date: "DateFieldType",
|
|
673
|
+
datetime: "DateTimeFieldType",
|
|
674
|
+
email: "EmailFieldType",
|
|
675
|
+
embed: "EmbedFieldType",
|
|
676
|
+
file: "FileFieldType",
|
|
677
|
+
followupemail: "FollowUpEmailFieldType",
|
|
678
|
+
font: "FontFieldType",
|
|
679
|
+
form: "FormFieldType",
|
|
680
|
+
gradient: "GradientFieldType",
|
|
681
|
+
group: "GroupFieldType",
|
|
682
|
+
html: "HtmlFieldType",
|
|
683
|
+
hubdbrow: "HubDbRowFieldType",
|
|
684
|
+
hubdbtable: "HubDbTableFieldType",
|
|
685
|
+
hubl: "HublFieldType",
|
|
686
|
+
icon: "IconFieldType",
|
|
687
|
+
image: "ImageFieldType",
|
|
688
|
+
link: "LinkFieldType",
|
|
689
|
+
logo: "LogoFieldType",
|
|
690
|
+
meeting: "MeetingFieldType",
|
|
691
|
+
menu: "MenuFieldType",
|
|
692
|
+
number: "NumberFieldType",
|
|
693
|
+
page: "PageFieldType",
|
|
694
|
+
payment: "PaymentFieldType",
|
|
695
|
+
podcast: "PodcastFieldType",
|
|
696
|
+
richtext: "RichTextFieldType",
|
|
697
|
+
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
698
|
+
simplemenu: "SimpleMenuFieldType",
|
|
699
|
+
spacing: "SpacingFieldType",
|
|
700
|
+
survey: "SurveyFieldType",
|
|
701
|
+
tag: "TagFieldType",
|
|
702
|
+
textalignment: "TextAlignmentFieldType",
|
|
703
|
+
text: "TextFieldType",
|
|
704
|
+
url: "UrlFieldType",
|
|
705
|
+
video: "VideoFieldType",
|
|
706
|
+
workflow: "WorkflowFieldType"
|
|
707
|
+
};
|
|
708
|
+
var getChildrenAsArray = (element) => React.Children.toArray(element.props.children);
|
|
709
|
+
function getFieldEntries(fields) {
|
|
710
|
+
if (isValidElement(fields)) {
|
|
711
|
+
const fieldsJSX = getChildrenAsArray(fields);
|
|
712
|
+
return getReactFieldEntries(fieldsJSX);
|
|
713
|
+
} else if (Array.isArray(fields)) {
|
|
714
|
+
return getJSONFieldEntries(fields);
|
|
715
|
+
}
|
|
716
|
+
return void 0;
|
|
717
|
+
}
|
|
718
|
+
var getJSXFieldType = (fieldFunctionName) => {
|
|
719
|
+
switch (fieldFunctionName) {
|
|
720
|
+
case "RepeatedFieldGroup":
|
|
721
|
+
case "FieldGroup":
|
|
722
|
+
return "GroupFieldType";
|
|
723
|
+
default:
|
|
724
|
+
return `${fieldFunctionName}Type`;
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
var getElementName = (element) => typeof element.type === "string" ? element.type : element.type.name || null;
|
|
728
|
+
function getReactFieldEntries(fields) {
|
|
729
|
+
const validTypeNames = Object.values(fieldTypeNameByType);
|
|
730
|
+
if (!Array.isArray(fields)) {
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
return fields.filter((field) => field.props && field.props.name).map((field) => {
|
|
734
|
+
const elName = getElementName(field);
|
|
735
|
+
const fieldType = getJSXFieldType(getElementName(field));
|
|
736
|
+
if (!validTypeNames.includes(fieldType)) {
|
|
737
|
+
return void 0;
|
|
738
|
+
}
|
|
739
|
+
const { name, default: hasDefault } = field.props;
|
|
740
|
+
const isRepeater = elName === "RepeatedFieldGroup";
|
|
741
|
+
const entry = {
|
|
742
|
+
type: fieldType,
|
|
743
|
+
name,
|
|
744
|
+
hasDefault: !!hasDefault,
|
|
745
|
+
isRepeater,
|
|
746
|
+
children: []
|
|
747
|
+
};
|
|
748
|
+
if (fieldType === "GroupFieldType") {
|
|
749
|
+
const childrenArray = getChildrenAsArray(field);
|
|
750
|
+
const children = getReactFieldEntries(childrenArray);
|
|
751
|
+
return {
|
|
752
|
+
...entry,
|
|
753
|
+
children
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
return entry;
|
|
757
|
+
}).filter((entry) => entry !== void 0);
|
|
758
|
+
}
|
|
759
|
+
function getJSONFieldEntries(fields) {
|
|
760
|
+
if (!Array.isArray(fields)) {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
764
|
+
const { name, type } = field;
|
|
765
|
+
const fieldType = fieldTypeNameByType[type];
|
|
766
|
+
if (!fieldType) {
|
|
767
|
+
return void 0;
|
|
768
|
+
}
|
|
769
|
+
const entry = {
|
|
770
|
+
type: fieldType,
|
|
771
|
+
name,
|
|
772
|
+
isRepeater: "occurrence" in field,
|
|
773
|
+
hasDefault: !!field.default,
|
|
774
|
+
children: []
|
|
775
|
+
};
|
|
776
|
+
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
777
|
+
const children = getJSONFieldEntries(field.children);
|
|
778
|
+
return { ...entry, children };
|
|
779
|
+
}
|
|
780
|
+
return entry;
|
|
781
|
+
}).filter((entry) => entry !== void 0);
|
|
782
|
+
}
|
|
783
|
+
var OVERRIDE_TYPE = "Override";
|
|
784
|
+
var REQUIRED_TYPE = "Required";
|
|
785
|
+
var REPEATED_VAR = "_repeater";
|
|
786
|
+
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
787
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
788
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
789
|
+
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
790
|
+
var createPropertySignature = (identifier, type) => ts.factory.createPropertySignature([], identifier, void 0, type);
|
|
791
|
+
var buildTypeFromField = (field, additionalNode) => {
|
|
792
|
+
const imports = [field.type];
|
|
793
|
+
const identifier = ts.factory.createIdentifier(field.name);
|
|
794
|
+
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
795
|
+
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
796
|
+
baseType
|
|
797
|
+
]);
|
|
798
|
+
let finalType = field.hasDefault ? requiredType : baseType;
|
|
799
|
+
if (additionalNode) {
|
|
800
|
+
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
801
|
+
const repeaterName = ts.factory.createLiteralTypeNode(
|
|
802
|
+
ts.factory.createStringLiteral(REPEATED_VAR)
|
|
803
|
+
);
|
|
804
|
+
if (!field.isRepeater) {
|
|
805
|
+
imports.push(OVERRIDE_TYPE);
|
|
806
|
+
}
|
|
807
|
+
finalType = field.isRepeater ? ts.factory.createTypeReferenceNode("Array", [
|
|
808
|
+
ts.factory.createTypeReferenceNode("Record", [
|
|
809
|
+
repeaterName,
|
|
810
|
+
typeLiteral
|
|
811
|
+
])
|
|
812
|
+
]) : ts.factory.createTypeReferenceNode(OVERRIDE_TYPE, [
|
|
813
|
+
finalType,
|
|
814
|
+
typeLiteral
|
|
815
|
+
]);
|
|
816
|
+
}
|
|
817
|
+
return { type: createPropertySignature(identifier, finalType), imports };
|
|
818
|
+
};
|
|
819
|
+
function getImportDeclaration(imports, moduleSpecifier) {
|
|
820
|
+
const importSpecifiers = Array.from(imports).map(
|
|
821
|
+
(importName) => ts.factory.createImportSpecifier(
|
|
822
|
+
true,
|
|
823
|
+
void 0,
|
|
824
|
+
ts.factory.createIdentifier(importName)
|
|
825
|
+
)
|
|
826
|
+
);
|
|
827
|
+
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
828
|
+
return ts.factory.createImportDeclaration(
|
|
829
|
+
[],
|
|
830
|
+
[],
|
|
831
|
+
ts.factory.createImportClause(false, void 0, namedImports),
|
|
832
|
+
ts.factory.createStringLiteral(moduleSpecifier)
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
function getFieldTypes(fields) {
|
|
836
|
+
const imports = ["DefaultValues"];
|
|
837
|
+
const types = fields.map((field) => {
|
|
838
|
+
if (field.children) {
|
|
839
|
+
const childrenResult = getFieldTypes(field.children);
|
|
840
|
+
imports.push(...childrenResult.imports);
|
|
841
|
+
if (childrenResult.types.length) {
|
|
842
|
+
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
843
|
+
const childrenPropertySignature = createPropertySignature(
|
|
844
|
+
"children",
|
|
845
|
+
subType
|
|
846
|
+
);
|
|
847
|
+
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
848
|
+
field,
|
|
849
|
+
field.isRepeater ? subType : childrenPropertySignature
|
|
850
|
+
);
|
|
851
|
+
imports.push(...newImports2);
|
|
852
|
+
return type2;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
const { type, imports: newImports } = buildTypeFromField(field);
|
|
856
|
+
imports.push(...newImports);
|
|
857
|
+
return type;
|
|
858
|
+
});
|
|
859
|
+
return { types, imports: Array.from(new Set(imports)) };
|
|
860
|
+
}
|
|
861
|
+
function constructFinalType(fields, typeName) {
|
|
862
|
+
const { types, imports } = getFieldTypes(fields);
|
|
863
|
+
const importDeclaration = getImportDeclaration(
|
|
864
|
+
imports,
|
|
865
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
866
|
+
);
|
|
867
|
+
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
868
|
+
[],
|
|
869
|
+
[],
|
|
870
|
+
"",
|
|
871
|
+
void 0,
|
|
872
|
+
ts.factory.createTypeLiteralNode(types)
|
|
873
|
+
);
|
|
874
|
+
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
875
|
+
baseType.type
|
|
876
|
+
]);
|
|
877
|
+
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
878
|
+
[],
|
|
879
|
+
[],
|
|
880
|
+
typeName,
|
|
881
|
+
void 0,
|
|
882
|
+
wrappedType
|
|
883
|
+
);
|
|
884
|
+
const defaultExport = ts.factory.createExportDefault(
|
|
885
|
+
ts.factory.createIdentifier(typeName)
|
|
886
|
+
);
|
|
887
|
+
return [importDeclaration, finalType, defaultExport];
|
|
888
|
+
}
|
|
889
|
+
function writeFieldsType(fields, fileName, typeName) {
|
|
890
|
+
const entries = getFieldEntries(fields);
|
|
891
|
+
if (!entries) {
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
try {
|
|
895
|
+
const file = ts.createSourceFile(
|
|
896
|
+
fileName,
|
|
897
|
+
"",
|
|
898
|
+
ts.ScriptTarget.ESNext,
|
|
899
|
+
false,
|
|
900
|
+
ts.ScriptKind.TS
|
|
901
|
+
);
|
|
902
|
+
const printer = ts.createPrinter();
|
|
903
|
+
const nodes = constructFinalType(entries, typeName);
|
|
904
|
+
const comments = [
|
|
905
|
+
AUTO_GEN_COMMENT,
|
|
906
|
+
"Removing the above comment will disable type generation for this module",
|
|
907
|
+
"This file was created by @hubspot/cms-dev-server, for more information see https://github.hubspot.com/cms-react/reference/js-modules.html#module-fields"
|
|
908
|
+
].map((comment) => `// ${comment}`);
|
|
909
|
+
const typeResult = nodes.map(
|
|
910
|
+
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
911
|
+
);
|
|
912
|
+
const result = [...comments, ...typeResult].join("\n");
|
|
913
|
+
writeFileSync(fileName, result);
|
|
914
|
+
return true;
|
|
915
|
+
} catch (e) {
|
|
916
|
+
console.error(e);
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
655
920
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
656
921
|
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
657
922
|
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
@@ -1044,7 +1309,7 @@ function trackUsage(action) {
|
|
|
1044
1309
|
eventName: EVENT_NAME,
|
|
1045
1310
|
action,
|
|
1046
1311
|
nodeVersion: getNodeVersionData(),
|
|
1047
|
-
version: "0.15.
|
|
1312
|
+
version: "0.15.8",
|
|
1048
1313
|
os: getPlatform()
|
|
1049
1314
|
};
|
|
1050
1315
|
const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -1690,12 +1955,12 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1690
1955
|
);
|
|
1691
1956
|
offsetSoFar = nearestNewlineOrQuoteAfterBlockOpen;
|
|
1692
1957
|
if (pathEndOffset >= 0 && pathEndOffset < nextNewlineOffset) {
|
|
1693
|
-
const
|
|
1958
|
+
const path10 = body.substring(
|
|
1694
1959
|
startOffset + localJsRenderStartString.length,
|
|
1695
1960
|
pathEndOffset
|
|
1696
1961
|
);
|
|
1697
1962
|
offsetSoFar = pathEndOffset + 1;
|
|
1698
|
-
if (startOffset >= 0 &&
|
|
1963
|
+
if (startOffset >= 0 && path10) {
|
|
1699
1964
|
const nextCommentEndOffset = body.indexOf("-->", pathEndOffset);
|
|
1700
1965
|
const endOffset = body.indexOf(localJsRenderEndString, pathEndOffset);
|
|
1701
1966
|
offsetSoFar = Math.min(nextCommentEndOffset, endOffset);
|
|
@@ -1720,7 +1985,7 @@ var findLocalRenderPlaceholders = (body) => {
|
|
|
1720
1985
|
result.push({
|
|
1721
1986
|
startOffset,
|
|
1722
1987
|
endOffset: endOffset + localJsRenderEndString.length,
|
|
1723
|
-
path:
|
|
1988
|
+
path: path10,
|
|
1724
1989
|
json
|
|
1725
1990
|
});
|
|
1726
1991
|
}
|
|
@@ -1834,9 +2099,9 @@ var customColors = [
|
|
|
1834
2099
|
];
|
|
1835
2100
|
var Converter = new AnsiToHtmlConverter({ colors: customColors });
|
|
1836
2101
|
var darkErrorStyles = `background-color: #222; color: #ccc; padding: 0.5em; font-family: ui-monospace, Menlo, Monaco, 'Cascadia Mono', 'Segoe UI Mono', 'Roboto Mono', 'Oxygen Mono', 'Ubuntu Monospace', 'Source Code Pro', 'Fira Mono', 'Droid Sans Mono', 'Courier New', monospace;`;
|
|
1837
|
-
var renderLocalError_default = (
|
|
2102
|
+
var renderLocalError_default = (path10, error) => {
|
|
1838
2103
|
const stackWithColorClasses = Converter.toHtml(error.stack);
|
|
1839
|
-
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${
|
|
2104
|
+
return `<div data-js-rendered="error" style="${darkErrorStyles}">Error rendering ${path10}<br/><br/><code><pre>${stackWithColorClasses}</pre></code></div>`;
|
|
1840
2105
|
};
|
|
1841
2106
|
|
|
1842
2107
|
// src/proxyPage/fetchPreviewInfo.ts
|
|
@@ -1887,34 +2152,6 @@ import {
|
|
|
1887
2152
|
isDebugUrlString as isDebugUrlString3,
|
|
1888
2153
|
mergeServerRequestData_internal
|
|
1889
2154
|
} from "@hubspot/cms-components";
|
|
1890
|
-
|
|
1891
|
-
// src/lib/cleanCookieHeaders.ts
|
|
1892
|
-
var CookieBlockList = [
|
|
1893
|
-
"__cflb",
|
|
1894
|
-
"__cf_bm",
|
|
1895
|
-
"__cfseq",
|
|
1896
|
-
"__cfwaitingroom",
|
|
1897
|
-
"__cfruid",
|
|
1898
|
-
"_cfuvid",
|
|
1899
|
-
"cf_ob_info",
|
|
1900
|
-
"cf_use_ob",
|
|
1901
|
-
"cf_clearance",
|
|
1902
|
-
"cf_chl_XXXX",
|
|
1903
|
-
"cf_chl_rc_i",
|
|
1904
|
-
"cf_chl_rc_ni",
|
|
1905
|
-
"cf_chl_rc_m"
|
|
1906
|
-
];
|
|
1907
|
-
function cleanCookieHeaders(cookieHeader) {
|
|
1908
|
-
if (cookieHeader === void 0)
|
|
1909
|
-
return "";
|
|
1910
|
-
const cookies = cookieHeader.split(";");
|
|
1911
|
-
const cookieRegex = new RegExp(CookieBlockList.join("|"));
|
|
1912
|
-
return cookies.filter((cookie) => {
|
|
1913
|
-
return !cookie.match(cookieRegex);
|
|
1914
|
-
}).join(";");
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
// src/proxyPage/proxyPage.ts
|
|
1918
2155
|
var getEntryPointBasePathFromProxyRequest = (request2) => {
|
|
1919
2156
|
if (!request2) {
|
|
1920
2157
|
return "";
|
|
@@ -1939,7 +2176,6 @@ function resolvePlaceholderPath(placeholderPath, projectName, projectComponent)
|
|
|
1939
2176
|
}
|
|
1940
2177
|
var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, projectName, environmentConfig, __jsRenderingGates, cookieHeader) => {
|
|
1941
2178
|
const url3 = new URL(urlToProxy);
|
|
1942
|
-
const cleanedCookieHeader = cleanCookieHeaders(cookieHeader);
|
|
1943
2179
|
const renderPreviewLocally = url3.searchParams.has("renderPreviewLocally");
|
|
1944
2180
|
let proxiedQueryParams = {};
|
|
1945
2181
|
let baseUrl = url3.origin;
|
|
@@ -1983,7 +2219,8 @@ var makeProxyPreviewRequest = (accountId, urlToProxy, previewKey, contentId, pro
|
|
|
1983
2219
|
json: false,
|
|
1984
2220
|
useQuerystring: true,
|
|
1985
2221
|
headers: {
|
|
1986
|
-
COOKIE:
|
|
2222
|
+
COOKIE: cookieHeader,
|
|
2223
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
1987
2224
|
}
|
|
1988
2225
|
});
|
|
1989
2226
|
return result.catch((error) => {
|
|
@@ -2664,7 +2901,8 @@ async function modulePreviewRouteHandler(request2, response) {
|
|
|
2664
2901
|
["content-type"]: "application/x-www-form-urlencoded",
|
|
2665
2902
|
["Accept"]: "text/html",
|
|
2666
2903
|
referer: `https://app.hubspot${authedEnv === "qa" ? "qa" : ""}.com`,
|
|
2667
|
-
cookie:
|
|
2904
|
+
cookie: request2.get("COOKIE"),
|
|
2905
|
+
"User-Agent": "HubSpot CMS Dev Server"
|
|
2668
2906
|
},
|
|
2669
2907
|
body: `module=${encodeURIComponent(JSON.stringify(localModule))}`
|
|
2670
2908
|
});
|
|
@@ -3213,11 +3451,121 @@ async function validateHSPlatform(projectConfigPath, portalId) {
|
|
|
3213
3451
|
|
|
3214
3452
|
// src/createDevServer.ts
|
|
3215
3453
|
import { get as hsGet6 } from "@hubspot/cli-lib/http.js";
|
|
3454
|
+
|
|
3455
|
+
// src/lib/watchFieldsUpdates.ts
|
|
3456
|
+
import fs4 from "fs";
|
|
3457
|
+
import path8 from "path";
|
|
3458
|
+
import readline from "readline";
|
|
3459
|
+
var lastSerializedFieldsCache = {};
|
|
3460
|
+
var formatAsTypeName = (str) => {
|
|
3461
|
+
const typeName = `${str.replace(/[^a-zA-Z0-9_$]/g, "_")}FieldsType`;
|
|
3462
|
+
const validFirstChar = /^[A-Za-z_$]/.test(str.charAt(0));
|
|
3463
|
+
return validFirstChar ? typeName : `_${typeName}`;
|
|
3464
|
+
};
|
|
3465
|
+
var isInModulesFolder = (filePath, projectRoot) => {
|
|
3466
|
+
const getEntryPathFromId = (id) => {
|
|
3467
|
+
return id.startsWith(projectRoot) ? id.replace(`${projectRoot}/`, "") : "";
|
|
3468
|
+
};
|
|
3469
|
+
const currentModuleId = path8.normalize(filePath);
|
|
3470
|
+
const moduleEntryPath = getEntryPathFromId(currentModuleId);
|
|
3471
|
+
const subFolderTokens = moduleEntryPath.split(path8.sep);
|
|
3472
|
+
return {
|
|
3473
|
+
inModuleFolder: subFolderTokens[0] === "components" && subFolderTokens[1] === "modules",
|
|
3474
|
+
isRootModuleFile: subFolderTokens.length === 3
|
|
3475
|
+
};
|
|
3476
|
+
};
|
|
3477
|
+
var fileContainsAutoGenComment = async (filePath) => {
|
|
3478
|
+
if (!fs4.existsSync(filePath))
|
|
3479
|
+
return true;
|
|
3480
|
+
const stream2 = fs4.createReadStream(filePath);
|
|
3481
|
+
const reader = readline.createInterface({ input: stream2 });
|
|
3482
|
+
const firstLine = await new Promise(
|
|
3483
|
+
(resolve3) => reader.once("line", (line) => resolve3(line.trim()))
|
|
3484
|
+
);
|
|
3485
|
+
reader.close();
|
|
3486
|
+
stream2.close();
|
|
3487
|
+
return firstLine && firstLine === `// ${AUTO_GEN_COMMENT}`;
|
|
3488
|
+
};
|
|
3489
|
+
var getIndexFile = (filePath, projectRoot) => {
|
|
3490
|
+
const { inModuleFolder, isRootModuleFile } = isInModulesFolder(
|
|
3491
|
+
filePath,
|
|
3492
|
+
projectRoot
|
|
3493
|
+
);
|
|
3494
|
+
if (!inModuleFolder)
|
|
3495
|
+
return void 0;
|
|
3496
|
+
if (isRootModuleFile)
|
|
3497
|
+
return { indexFilePath: filePath, isRootModuleFile };
|
|
3498
|
+
const dir = path8.dirname(filePath);
|
|
3499
|
+
const files = fs4.readdirSync(dir);
|
|
3500
|
+
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
3501
|
+
return indexFileName ? { indexFilePath: path8.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
3502
|
+
};
|
|
3503
|
+
var getIndexFileFields = async (indexFilePath, viteServer) => {
|
|
3504
|
+
let indexFile;
|
|
3505
|
+
try {
|
|
3506
|
+
indexFile = await viteServer.ssrLoadModule(indexFilePath);
|
|
3507
|
+
} catch (e) {
|
|
3508
|
+
return void 0;
|
|
3509
|
+
}
|
|
3510
|
+
if (!indexFile.fields)
|
|
3511
|
+
return void 0;
|
|
3512
|
+
const fields = indexFile.fields;
|
|
3513
|
+
const isJsonFields = Array.isArray(fields);
|
|
3514
|
+
const isReactFields = fields.type && fields.type.name === "ModuleFields";
|
|
3515
|
+
if (isJsonFields || isReactFields) {
|
|
3516
|
+
return fields;
|
|
3517
|
+
}
|
|
3518
|
+
return void 0;
|
|
3519
|
+
};
|
|
3520
|
+
var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
3521
|
+
const indexInfo = getIndexFile(filePath, projectRoot);
|
|
3522
|
+
if (!indexInfo)
|
|
3523
|
+
return;
|
|
3524
|
+
const { indexFilePath, isRootModuleFile } = indexInfo;
|
|
3525
|
+
const indexFileName = path8.parse(indexFilePath).name;
|
|
3526
|
+
const isTypeFile = filePath.endsWith(".types.ts");
|
|
3527
|
+
if (isTypeFile)
|
|
3528
|
+
return;
|
|
3529
|
+
const fields = await getIndexFileFields(indexFilePath, viteServer);
|
|
3530
|
+
if (fields) {
|
|
3531
|
+
const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
|
|
3532
|
+
const typeFilePath = path8.join(path8.dirname(filePath), typeFileName);
|
|
3533
|
+
const lastSerializedFields = lastSerializedFieldsCache[typeFilePath];
|
|
3534
|
+
const serializedFields = JSON.stringify(fields);
|
|
3535
|
+
if (lastSerializedFields === serializedFields)
|
|
3536
|
+
return;
|
|
3537
|
+
const hasAutoGenComment = await fileContainsAutoGenComment(typeFilePath);
|
|
3538
|
+
if (!hasAutoGenComment)
|
|
3539
|
+
return;
|
|
3540
|
+
const moduleFolderName = path8.basename(path8.dirname(filePath));
|
|
3541
|
+
const outputTypeName = formatAsTypeName(moduleFolderName);
|
|
3542
|
+
const didSucceed = writeFieldsType(fields, typeFilePath, outputTypeName);
|
|
3543
|
+
if (didSucceed) {
|
|
3544
|
+
lastSerializedFieldsCache[typeFilePath] = serializedFields;
|
|
3545
|
+
}
|
|
3546
|
+
const pathToLog = isRootModuleFile ? `${moduleFolderName}/${indexFileName}` : moduleFolderName;
|
|
3547
|
+
const successMsg = `Successfully generated types for ${pathToLog}`;
|
|
3548
|
+
const errorMsg = `Failed to generate types for ${pathToLog}`;
|
|
3549
|
+
const message = didSucceed ? successMsg : errorMsg;
|
|
3550
|
+
console.log(wrapMessageInColor(didSucceed ? "green" : "red", message));
|
|
3551
|
+
}
|
|
3552
|
+
};
|
|
3553
|
+
var startFieldsTypeGenWatcher = (viteServer, projectRoot) => {
|
|
3554
|
+
const { moduleSubpaths } = findAllModulesInRoot(projectRoot);
|
|
3555
|
+
moduleSubpaths.forEach((modulePath) => {
|
|
3556
|
+
const resolvedPath = path8.resolve(projectRoot, modulePath);
|
|
3557
|
+
maybeUpdateFields(resolvedPath, viteServer, projectRoot);
|
|
3558
|
+
});
|
|
3559
|
+
const watchCallback = (filePath) => maybeUpdateFields(filePath, viteServer, projectRoot);
|
|
3560
|
+
viteServer.watcher.on("add", watchCallback).on("change", watchCallback);
|
|
3561
|
+
};
|
|
3562
|
+
|
|
3563
|
+
// src/createDevServer.ts
|
|
3216
3564
|
var BASE_PATH = "/";
|
|
3217
3565
|
var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
|
|
3218
3566
|
var SHADOW_PORT = 1442;
|
|
3219
3567
|
var STORYBOOK_PORT = process.env.STORYBOOK_PORT ? parseInt(process.env.STORYBOOK_PORT, 10) : 3123;
|
|
3220
|
-
async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2, hubspotCliAccountNameOption2, sslEnabledOption2) {
|
|
3568
|
+
async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2, hubspotCliAccountNameOption2, sslEnabledOption2, fieldGenEnabledOption2) {
|
|
3221
3569
|
let authedPortalId = null;
|
|
3222
3570
|
let authedEnv = null;
|
|
3223
3571
|
let jsRenderingGates = [];
|
|
@@ -3324,7 +3672,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
3324
3672
|
} catch (e) {
|
|
3325
3673
|
authedHublet = "na1";
|
|
3326
3674
|
}
|
|
3327
|
-
const absoluteWebRoot = normalizePath6(
|
|
3675
|
+
const absoluteWebRoot = normalizePath6(path9.resolve(process.cwd(), webRoot2));
|
|
3328
3676
|
const [__webRootProjectFolder, webRootProjectComponentFolder] = absoluteWebRoot.replace(/\/$/, "").split("/").slice(-2);
|
|
3329
3677
|
const projectConfigPath = findHSProjectJson(absoluteWebRoot);
|
|
3330
3678
|
if (authedPortalId) {
|
|
@@ -3338,6 +3686,9 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
3338
3686
|
jsRenderingGates,
|
|
3339
3687
|
secretNames
|
|
3340
3688
|
);
|
|
3689
|
+
if (fieldGenEnabledOption2) {
|
|
3690
|
+
startFieldsTypeGenWatcher(viteServer, absoluteWebRoot);
|
|
3691
|
+
}
|
|
3341
3692
|
const viteHTTPSConfig = viteServer.config.server.https;
|
|
3342
3693
|
const httpsKey = viteHTTPSConfig ? viteHTTPSConfig.key : null;
|
|
3343
3694
|
const httpsCert = viteHTTPSConfig ? viteHTTPSConfig.cert : null;
|
|
@@ -3398,8 +3749,8 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
3398
3749
|
`
|
|
3399
3750
|
);
|
|
3400
3751
|
if (storybook2) {
|
|
3401
|
-
const packageRoot =
|
|
3402
|
-
const configPath =
|
|
3752
|
+
const packageRoot = path9.dirname(url2.fileURLToPath(import.meta.url));
|
|
3753
|
+
const configPath = path9.resolve(packageRoot, "./storybook-main");
|
|
3403
3754
|
sendTrackingRequest("start-storybook");
|
|
3404
3755
|
const storybookProcess = spawn(
|
|
3405
3756
|
"sb",
|
|
@@ -3419,7 +3770,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
3419
3770
|
portalId: authedPortalId.toString(),
|
|
3420
3771
|
hsEnv: authedEnv,
|
|
3421
3772
|
hublet: authedHublet,
|
|
3422
|
-
WEB_ROOT:
|
|
3773
|
+
WEB_ROOT: path9.join(webRoot2, "components")
|
|
3423
3774
|
}
|
|
3424
3775
|
}
|
|
3425
3776
|
);
|
|
@@ -3465,7 +3816,8 @@ var {
|
|
|
3465
3816
|
hubspotCliConfigPathOption,
|
|
3466
3817
|
hubspotCliAccountNameOption,
|
|
3467
3818
|
sslEnabledOption,
|
|
3468
|
-
storybook
|
|
3819
|
+
storybook,
|
|
3820
|
+
fieldGenEnabledOption
|
|
3469
3821
|
} = getDevServerCommandLineOptions(process.argv);
|
|
3470
3822
|
if (!webRoot) {
|
|
3471
3823
|
throw new Error(`No web root path argument specified`);
|
|
@@ -3475,5 +3827,6 @@ createDevServer_default(
|
|
|
3475
3827
|
storybook,
|
|
3476
3828
|
hubspotCliConfigPathOption,
|
|
3477
3829
|
hubspotCliAccountNameOption,
|
|
3478
|
-
sslEnabledOption
|
|
3830
|
+
sslEnabledOption,
|
|
3831
|
+
fieldGenEnabledOption
|
|
3479
3832
|
);
|
package/dist/storybook/index.js
CHANGED
|
@@ -36,13 +36,15 @@ function namespaceModulePropsShape(props) {
|
|
|
36
36
|
import * as dotProp from "dot-prop";
|
|
37
37
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
38
38
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
39
|
-
import { isValidElement, cloneElement } from "react";
|
|
39
|
+
import React, { isValidElement, cloneElement } from "react";
|
|
40
40
|
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
41
41
|
var {
|
|
42
42
|
createServerRenderContextV2: createServerRenderContextV22,
|
|
43
43
|
createServerRenderContext: createServerRenderContext2,
|
|
44
44
|
renderServerSidePropsWithAsyncLocalStoreContext
|
|
45
45
|
} = cmsComponents;
|
|
46
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
47
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
46
48
|
function renderFieldsJSX(fieldsJSX) {
|
|
47
49
|
let moduleJson;
|
|
48
50
|
const outputCallback = (callbackJson) => {
|
|
@@ -454,6 +454,7 @@ ${groupEnd}</script>
|
|
|
454
454
|
// ../cms-js-internal/dist/index.js
|
|
455
455
|
var dist_exports = {};
|
|
456
456
|
__export(dist_exports, {
|
|
457
|
+
AUTO_GEN_COMMENT: () => AUTO_GEN_COMMENT,
|
|
457
458
|
COMPONENT_EXTENSIONS: () => COMPONENT_EXTENSIONS,
|
|
458
459
|
CSS_LANGS_RE: () => CSS_LANGS_RE,
|
|
459
460
|
ENABLED_FEATURES_GATE_MAP: () => ENABLED_FEATURES_GATE_MAP,
|
|
@@ -463,9 +464,11 @@ __export(dist_exports, {
|
|
|
463
464
|
VIRTUAL_CONFIG_SETUP: () => VIRTUAL_CONFIG_SETUP,
|
|
464
465
|
VIRTUAL_ISLAND_RUNTIME: () => VIRTUAL_ISLAND_RUNTIME,
|
|
465
466
|
areBuildHealthChecksEnabled: () => areBuildHealthChecksEnabled,
|
|
467
|
+
buildTypeFromField: () => buildTypeFromField,
|
|
466
468
|
clientIslandEntryPlugin: () => clientIslandEntryPlugin,
|
|
467
469
|
collectCssInDev: () => collectCssInDev,
|
|
468
470
|
collectCssModules: () => collectCssModules,
|
|
471
|
+
constructFinalType: () => constructFinalType,
|
|
469
472
|
createIslandsGlobalJsForClientInDev: () => createIslandsGlobalJsForClientInDev,
|
|
470
473
|
doHealthChecksFailTheBuild: () => doHealthChecksFailTheBuild,
|
|
471
474
|
escapeForInlineJS: () => escapeForInlineJS,
|
|
@@ -480,6 +483,7 @@ __export(dist_exports, {
|
|
|
480
483
|
getComponentExtension: () => getComponentExtension,
|
|
481
484
|
getEntryPointHash: () => getEntryPointHash,
|
|
482
485
|
getEntryPointHashWithIndexSuffix: () => getEntryPointHashWithIndexSuffix,
|
|
486
|
+
getFieldTypes: () => getFieldTypes,
|
|
483
487
|
getIslandRuntimeConfigUrl: () => getIslandRuntimeConfigUrl,
|
|
484
488
|
getIslandUrls: () => getIslandUrls,
|
|
485
489
|
getServerGlobalsToInject: () => getServerGlobalsToInject,
|
|
@@ -506,7 +510,8 @@ __export(dist_exports, {
|
|
|
506
510
|
serializeIslandDataForInlineScript: () => serializeIslandDataForInlineScript,
|
|
507
511
|
setIn: () => setIn,
|
|
508
512
|
ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
|
|
509
|
-
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
513
|
+
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId,
|
|
514
|
+
writeFieldsType: () => writeFieldsType
|
|
510
515
|
});
|
|
511
516
|
import * as dotProp from "dot-prop";
|
|
512
517
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -514,7 +519,9 @@ import stream from "stream";
|
|
|
514
519
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
515
520
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
516
521
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
517
|
-
import {
|
|
522
|
+
import { writeFileSync } from "fs";
|
|
523
|
+
import ts from "typescript";
|
|
524
|
+
import React, { isValidElement, cloneElement } from "react";
|
|
518
525
|
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
519
526
|
if (!supplementalFieldValues) {
|
|
520
527
|
return supplementalFieldValues;
|
|
@@ -640,6 +647,171 @@ async function renderOnServer(elements, renderContext = bootStrapRenderContext()
|
|
|
640
647
|
}
|
|
641
648
|
return { html, renderContext };
|
|
642
649
|
}
|
|
650
|
+
function getFieldEntries(fields) {
|
|
651
|
+
if (isValidElement(fields)) {
|
|
652
|
+
const fieldsJSX = getChildrenAsArray(fields);
|
|
653
|
+
return getReactFieldEntries(fieldsJSX);
|
|
654
|
+
} else if (Array.isArray(fields)) {
|
|
655
|
+
return getJSONFieldEntries(fields);
|
|
656
|
+
}
|
|
657
|
+
return void 0;
|
|
658
|
+
}
|
|
659
|
+
function getReactFieldEntries(fields) {
|
|
660
|
+
const validTypeNames = Object.values(fieldTypeNameByType);
|
|
661
|
+
if (!Array.isArray(fields)) {
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
return fields.filter((field) => field.props && field.props.name).map((field) => {
|
|
665
|
+
const elName = getElementName(field);
|
|
666
|
+
const fieldType = getJSXFieldType(getElementName(field));
|
|
667
|
+
if (!validTypeNames.includes(fieldType)) {
|
|
668
|
+
return void 0;
|
|
669
|
+
}
|
|
670
|
+
const { name, default: hasDefault } = field.props;
|
|
671
|
+
const isRepeater = elName === "RepeatedFieldGroup";
|
|
672
|
+
const entry = {
|
|
673
|
+
type: fieldType,
|
|
674
|
+
name,
|
|
675
|
+
hasDefault: !!hasDefault,
|
|
676
|
+
isRepeater,
|
|
677
|
+
children: []
|
|
678
|
+
};
|
|
679
|
+
if (fieldType === "GroupFieldType") {
|
|
680
|
+
const childrenArray = getChildrenAsArray(field);
|
|
681
|
+
const children = getReactFieldEntries(childrenArray);
|
|
682
|
+
return {
|
|
683
|
+
...entry,
|
|
684
|
+
children
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
return entry;
|
|
688
|
+
}).filter((entry) => entry !== void 0);
|
|
689
|
+
}
|
|
690
|
+
function getJSONFieldEntries(fields) {
|
|
691
|
+
if (!Array.isArray(fields)) {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
695
|
+
const { name, type } = field;
|
|
696
|
+
const fieldType = fieldTypeNameByType[type];
|
|
697
|
+
if (!fieldType) {
|
|
698
|
+
return void 0;
|
|
699
|
+
}
|
|
700
|
+
const entry = {
|
|
701
|
+
type: fieldType,
|
|
702
|
+
name,
|
|
703
|
+
isRepeater: "occurrence" in field,
|
|
704
|
+
hasDefault: !!field.default,
|
|
705
|
+
children: []
|
|
706
|
+
};
|
|
707
|
+
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
708
|
+
const children = getJSONFieldEntries(field.children);
|
|
709
|
+
return { ...entry, children };
|
|
710
|
+
}
|
|
711
|
+
return entry;
|
|
712
|
+
}).filter((entry) => entry !== void 0);
|
|
713
|
+
}
|
|
714
|
+
function getImportDeclaration(imports, moduleSpecifier) {
|
|
715
|
+
const importSpecifiers = Array.from(imports).map(
|
|
716
|
+
(importName) => ts.factory.createImportSpecifier(
|
|
717
|
+
true,
|
|
718
|
+
void 0,
|
|
719
|
+
ts.factory.createIdentifier(importName)
|
|
720
|
+
)
|
|
721
|
+
);
|
|
722
|
+
const namedImports = ts.factory.createNamedImports(importSpecifiers);
|
|
723
|
+
return ts.factory.createImportDeclaration(
|
|
724
|
+
[],
|
|
725
|
+
[],
|
|
726
|
+
ts.factory.createImportClause(false, void 0, namedImports),
|
|
727
|
+
ts.factory.createStringLiteral(moduleSpecifier)
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
function getFieldTypes(fields) {
|
|
731
|
+
const imports = ["DefaultValues"];
|
|
732
|
+
const types = fields.map((field) => {
|
|
733
|
+
if (field.children) {
|
|
734
|
+
const childrenResult = getFieldTypes(field.children);
|
|
735
|
+
imports.push(...childrenResult.imports);
|
|
736
|
+
if (childrenResult.types.length) {
|
|
737
|
+
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
738
|
+
const childrenPropertySignature = createPropertySignature(
|
|
739
|
+
"children",
|
|
740
|
+
subType
|
|
741
|
+
);
|
|
742
|
+
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
743
|
+
field,
|
|
744
|
+
field.isRepeater ? subType : childrenPropertySignature
|
|
745
|
+
);
|
|
746
|
+
imports.push(...newImports2);
|
|
747
|
+
return type2;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
const { type, imports: newImports } = buildTypeFromField(field);
|
|
751
|
+
imports.push(...newImports);
|
|
752
|
+
return type;
|
|
753
|
+
});
|
|
754
|
+
return { types, imports: Array.from(new Set(imports)) };
|
|
755
|
+
}
|
|
756
|
+
function constructFinalType(fields, typeName) {
|
|
757
|
+
const { types, imports } = getFieldTypes(fields);
|
|
758
|
+
const importDeclaration = getImportDeclaration(
|
|
759
|
+
imports,
|
|
760
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
761
|
+
);
|
|
762
|
+
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
763
|
+
[],
|
|
764
|
+
[],
|
|
765
|
+
"",
|
|
766
|
+
void 0,
|
|
767
|
+
ts.factory.createTypeLiteralNode(types)
|
|
768
|
+
);
|
|
769
|
+
const wrappedType = ts.factory.createTypeReferenceNode(DEFAULT_VALUES_TYPE, [
|
|
770
|
+
baseType.type
|
|
771
|
+
]);
|
|
772
|
+
const finalType = ts.factory.createTypeAliasDeclaration(
|
|
773
|
+
[],
|
|
774
|
+
[],
|
|
775
|
+
typeName,
|
|
776
|
+
void 0,
|
|
777
|
+
wrappedType
|
|
778
|
+
);
|
|
779
|
+
const defaultExport = ts.factory.createExportDefault(
|
|
780
|
+
ts.factory.createIdentifier(typeName)
|
|
781
|
+
);
|
|
782
|
+
return [importDeclaration, finalType, defaultExport];
|
|
783
|
+
}
|
|
784
|
+
function writeFieldsType(fields, fileName, typeName) {
|
|
785
|
+
const entries = getFieldEntries(fields);
|
|
786
|
+
if (!entries) {
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
try {
|
|
790
|
+
const file = ts.createSourceFile(
|
|
791
|
+
fileName,
|
|
792
|
+
"",
|
|
793
|
+
ts.ScriptTarget.ESNext,
|
|
794
|
+
false,
|
|
795
|
+
ts.ScriptKind.TS
|
|
796
|
+
);
|
|
797
|
+
const printer = ts.createPrinter();
|
|
798
|
+
const nodes = constructFinalType(entries, typeName);
|
|
799
|
+
const comments = [
|
|
800
|
+
AUTO_GEN_COMMENT,
|
|
801
|
+
"Removing the above comment will disable type generation for this module",
|
|
802
|
+
"This file was created by @hubspot/cms-dev-server, for more information see https://github.hubspot.com/cms-react/reference/js-modules.html#module-fields"
|
|
803
|
+
].map((comment) => `// ${comment}`);
|
|
804
|
+
const typeResult = nodes.map(
|
|
805
|
+
(node) => printer.printNode(ts.EmitHint.Unspecified, node, file)
|
|
806
|
+
);
|
|
807
|
+
const result = [...comments, ...typeResult].join("\n");
|
|
808
|
+
writeFileSync(fileName, result);
|
|
809
|
+
return true;
|
|
810
|
+
} catch (e) {
|
|
811
|
+
console.error(e);
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
}
|
|
643
815
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
644
816
|
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
645
817
|
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
@@ -715,7 +887,7 @@ function renderFieldsToJson(fields, moduleName) {
|
|
|
715
887
|
throw e;
|
|
716
888
|
}
|
|
717
889
|
}
|
|
718
|
-
var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext;
|
|
890
|
+
var setProperty, getProperty, hasProperty, serializeIslandDataForInlineScript, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, promiseForNewWritableStream, renderStreamToPromise, createServerRenderContextV22, createServerRenderContext2, renderServerSidePropsWithAsyncLocalStoreContext, bootStrapRenderContext, fieldTypeNameByType, getChildrenAsArray, getJSXFieldType, getElementName, OVERRIDE_TYPE, REQUIRED_TYPE, REPEATED_VAR, DEFAULT_VALUES_TYPE, CMS_COMPONENTS, CMS_COMPONENTS_FIELD_TYPES, AUTO_GEN_COMMENT, createPropertySignature, buildTypeFromField;
|
|
719
891
|
var init_dist = __esm({
|
|
720
892
|
"../cms-js-internal/dist/index.js"() {
|
|
721
893
|
init_basicUtils();
|
|
@@ -866,6 +1038,100 @@ ${indentString}`);
|
|
|
866
1038
|
}) : createServerRenderContext2("", null);
|
|
867
1039
|
return renderContext;
|
|
868
1040
|
};
|
|
1041
|
+
fieldTypeNameByType = {
|
|
1042
|
+
alignment: "AlignmentFieldType",
|
|
1043
|
+
audioplayer: "AudioFieldType",
|
|
1044
|
+
backgroundimage: "BackgroundImageFieldType",
|
|
1045
|
+
blog: "BlogFieldType",
|
|
1046
|
+
boolean: "BooleanFieldType",
|
|
1047
|
+
border: "BorderFieldType",
|
|
1048
|
+
choice: "ChoiceFieldType",
|
|
1049
|
+
color: "ColorFieldType",
|
|
1050
|
+
crmobject: "CrmObjectFieldType",
|
|
1051
|
+
cta: "CtaFieldType",
|
|
1052
|
+
date: "DateFieldType",
|
|
1053
|
+
datetime: "DateTimeFieldType",
|
|
1054
|
+
email: "EmailFieldType",
|
|
1055
|
+
embed: "EmbedFieldType",
|
|
1056
|
+
file: "FileFieldType",
|
|
1057
|
+
followupemail: "FollowUpEmailFieldType",
|
|
1058
|
+
font: "FontFieldType",
|
|
1059
|
+
form: "FormFieldType",
|
|
1060
|
+
gradient: "GradientFieldType",
|
|
1061
|
+
group: "GroupFieldType",
|
|
1062
|
+
html: "HtmlFieldType",
|
|
1063
|
+
hubdbrow: "HubDbRowFieldType",
|
|
1064
|
+
hubdbtable: "HubDbTableFieldType",
|
|
1065
|
+
hubl: "HublFieldType",
|
|
1066
|
+
icon: "IconFieldType",
|
|
1067
|
+
image: "ImageFieldType",
|
|
1068
|
+
link: "LinkFieldType",
|
|
1069
|
+
logo: "LogoFieldType",
|
|
1070
|
+
meeting: "MeetingFieldType",
|
|
1071
|
+
menu: "MenuFieldType",
|
|
1072
|
+
number: "NumberFieldType",
|
|
1073
|
+
page: "PageFieldType",
|
|
1074
|
+
payment: "PaymentFieldType",
|
|
1075
|
+
podcast: "PodcastFieldType",
|
|
1076
|
+
richtext: "RichTextFieldType",
|
|
1077
|
+
salesforcecampaign: "SfdcCamapaignFieldType",
|
|
1078
|
+
simplemenu: "SimpleMenuFieldType",
|
|
1079
|
+
spacing: "SpacingFieldType",
|
|
1080
|
+
survey: "SurveyFieldType",
|
|
1081
|
+
tag: "TagFieldType",
|
|
1082
|
+
textalignment: "TextAlignmentFieldType",
|
|
1083
|
+
text: "TextFieldType",
|
|
1084
|
+
url: "UrlFieldType",
|
|
1085
|
+
video: "VideoFieldType",
|
|
1086
|
+
workflow: "WorkflowFieldType"
|
|
1087
|
+
};
|
|
1088
|
+
getChildrenAsArray = (element) => React.Children.toArray(element.props.children);
|
|
1089
|
+
getJSXFieldType = (fieldFunctionName) => {
|
|
1090
|
+
switch (fieldFunctionName) {
|
|
1091
|
+
case "RepeatedFieldGroup":
|
|
1092
|
+
case "FieldGroup":
|
|
1093
|
+
return "GroupFieldType";
|
|
1094
|
+
default:
|
|
1095
|
+
return `${fieldFunctionName}Type`;
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
getElementName = (element) => typeof element.type === "string" ? element.type : element.type.name || null;
|
|
1099
|
+
OVERRIDE_TYPE = "Override";
|
|
1100
|
+
REQUIRED_TYPE = "Required";
|
|
1101
|
+
REPEATED_VAR = "_repeater";
|
|
1102
|
+
DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
1103
|
+
CMS_COMPONENTS = "@hubspot/cms-components";
|
|
1104
|
+
CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
1105
|
+
AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
1106
|
+
createPropertySignature = (identifier, type) => ts.factory.createPropertySignature([], identifier, void 0, type);
|
|
1107
|
+
buildTypeFromField = (field, additionalNode) => {
|
|
1108
|
+
const imports = [field.type];
|
|
1109
|
+
const identifier = ts.factory.createIdentifier(field.name);
|
|
1110
|
+
const baseType = ts.factory.createTypeReferenceNode(field.type);
|
|
1111
|
+
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
1112
|
+
baseType
|
|
1113
|
+
]);
|
|
1114
|
+
let finalType = field.hasDefault ? requiredType : baseType;
|
|
1115
|
+
if (additionalNode) {
|
|
1116
|
+
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
1117
|
+
const repeaterName = ts.factory.createLiteralTypeNode(
|
|
1118
|
+
ts.factory.createStringLiteral(REPEATED_VAR)
|
|
1119
|
+
);
|
|
1120
|
+
if (!field.isRepeater) {
|
|
1121
|
+
imports.push(OVERRIDE_TYPE);
|
|
1122
|
+
}
|
|
1123
|
+
finalType = field.isRepeater ? ts.factory.createTypeReferenceNode("Array", [
|
|
1124
|
+
ts.factory.createTypeReferenceNode("Record", [
|
|
1125
|
+
repeaterName,
|
|
1126
|
+
typeLiteral
|
|
1127
|
+
])
|
|
1128
|
+
]) : ts.factory.createTypeReferenceNode(OVERRIDE_TYPE, [
|
|
1129
|
+
finalType,
|
|
1130
|
+
typeLiteral
|
|
1131
|
+
]);
|
|
1132
|
+
}
|
|
1133
|
+
return { type: createPropertySignature(identifier, finalType), imports };
|
|
1134
|
+
};
|
|
869
1135
|
}
|
|
870
1136
|
});
|
|
871
1137
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.8",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@hubspot/cli-lib": "^3.0.12",
|
|
29
|
-
"@hubspot/cms-components": "^0.15.
|
|
29
|
+
"@hubspot/cms-components": "^0.15.8",
|
|
30
30
|
"@inquirer/select": "^2.0.0",
|
|
31
31
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
32
32
|
"@storybook/addon-actions": "7.0.7",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"publishConfig": {
|
|
109
109
|
"access": "public"
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "9a5e9512c41af68242b0be979cffd0420a37fe8f"
|
|
112
112
|
}
|