@hubspot/cms-dev-server 0.15.3 → 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 +285 -8
- package/dist/run.js +403 -48
- package/dist/storybook/index.js +3 -1
- package/dist/storybook-main/main.js +287 -10
- 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
|
@@ -295,6 +295,20 @@ function getServerIncludePrebundleDepPatterns(config) {
|
|
|
295
295
|
var _a, _b;
|
|
296
296
|
return ((_b = (_a = config.buildConfig) == null ? void 0 : _a.serverPrebundling) == null ? void 0 : _b.include) ?? [];
|
|
297
297
|
}
|
|
298
|
+
var BUILD_INFO_PATH = "/build-info.json";
|
|
299
|
+
function getBuildInfo(buildDir) {
|
|
300
|
+
try {
|
|
301
|
+
const buildInfo = JSON.parse(
|
|
302
|
+
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
303
|
+
);
|
|
304
|
+
return buildInfo;
|
|
305
|
+
} catch (e) {
|
|
306
|
+
throw new Error(`Error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function getBaseAssetUrlFromBuild(buildDir) {
|
|
310
|
+
return getBuildInfo(buildDir).baseAssetUrl;
|
|
311
|
+
}
|
|
298
312
|
var GATES = [
|
|
299
313
|
"CMS:JSRenderer:GetServerSideProps",
|
|
300
314
|
"CMS:JSRenderer:ModuleHubl",
|
|
@@ -308,16 +322,11 @@ var ENABLED_FEATURES_GATE_MAP = {
|
|
|
308
322
|
function isUngatedFor(gates, gate) {
|
|
309
323
|
return gates.includes(gate);
|
|
310
324
|
}
|
|
311
|
-
var BUILD_INFO_PATH = "/build-info.json";
|
|
312
325
|
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
313
326
|
try {
|
|
314
|
-
|
|
315
|
-
const buildInfo = JSON.parse(
|
|
316
|
-
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
317
|
-
);
|
|
327
|
+
const buildInfo = getBuildInfo(buildDir);
|
|
318
328
|
return isUngatedFor(buildInfo.gates, gate);
|
|
319
329
|
} catch (e) {
|
|
320
|
-
console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
321
330
|
return false;
|
|
322
331
|
}
|
|
323
332
|
}
|
|
@@ -436,7 +445,9 @@ import stream from "stream";
|
|
|
436
445
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
437
446
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
438
447
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
439
|
-
import {
|
|
448
|
+
import { writeFileSync } from "fs";
|
|
449
|
+
import ts from "typescript";
|
|
450
|
+
import React, { isValidElement, cloneElement } from "react";
|
|
440
451
|
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
441
452
|
var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestData, baseIndent = 0, prettyPrint) => {
|
|
442
453
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
@@ -708,6 +719,265 @@ async function renderOnServer(elements, renderContext = bootStrapRenderContext()
|
|
|
708
719
|
}
|
|
709
720
|
return { html, renderContext };
|
|
710
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
|
+
}
|
|
711
981
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
712
982
|
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
713
983
|
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
@@ -784,6 +1054,7 @@ function renderFieldsToJson(fields, moduleName) {
|
|
|
784
1054
|
}
|
|
785
1055
|
}
|
|
786
1056
|
export {
|
|
1057
|
+
AUTO_GEN_COMMENT,
|
|
787
1058
|
COMPONENT_EXTENSIONS,
|
|
788
1059
|
CSS_LANGS_RE,
|
|
789
1060
|
ENABLED_FEATURES_GATE_MAP,
|
|
@@ -793,21 +1064,26 @@ export {
|
|
|
793
1064
|
VIRTUAL_CONFIG_SETUP,
|
|
794
1065
|
VIRTUAL_ISLAND_RUNTIME,
|
|
795
1066
|
areBuildHealthChecksEnabled,
|
|
1067
|
+
buildTypeFromField,
|
|
796
1068
|
clientIslandEntryPlugin,
|
|
797
1069
|
collectCssInDev,
|
|
798
1070
|
collectCssModules,
|
|
1071
|
+
constructFinalType,
|
|
799
1072
|
createIslandsGlobalJsForClientInDev,
|
|
800
1073
|
doHealthChecksFailTheBuild,
|
|
801
1074
|
escapeForInlineJS,
|
|
802
1075
|
findAllComponentsIn,
|
|
803
1076
|
findAllModulesInRoot,
|
|
804
1077
|
findAllPartialsInRoot,
|
|
1078
|
+
getBaseAssetUrlFromBuild,
|
|
1079
|
+
getBuildInfo,
|
|
805
1080
|
getCMSAssetConfig,
|
|
806
1081
|
getCMSAssetConfigIfExists,
|
|
807
1082
|
getCombinedReactUrl,
|
|
808
1083
|
getComponentExtension,
|
|
809
1084
|
getEntryPointHash,
|
|
810
1085
|
getEntryPointHashWithIndexSuffix,
|
|
1086
|
+
getFieldTypes,
|
|
811
1087
|
getIslandRuntimeConfigUrl,
|
|
812
1088
|
getIslandUrls,
|
|
813
1089
|
getServerGlobalsToInject,
|
|
@@ -834,5 +1110,6 @@ export {
|
|
|
834
1110
|
serializeIslandDataForInlineScript,
|
|
835
1111
|
setIn,
|
|
836
1112
|
ungatedAtBuildTimeFor,
|
|
837
|
-
virtualClientRenderIslandModuleId
|
|
1113
|
+
virtualClientRenderIslandModuleId,
|
|
1114
|
+
writeFieldsType
|
|
838
1115
|
};
|