@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
|
@@ -190,18 +190,27 @@ function getServerIncludePrebundleDepPatterns(config) {
|
|
|
190
190
|
var _a, _b;
|
|
191
191
|
return ((_b = (_a = config.buildConfig) == null ? void 0 : _a.serverPrebundling) == null ? void 0 : _b.include) ?? [];
|
|
192
192
|
}
|
|
193
|
+
function getBuildInfo(buildDir) {
|
|
194
|
+
try {
|
|
195
|
+
const buildInfo = JSON.parse(
|
|
196
|
+
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
197
|
+
);
|
|
198
|
+
return buildInfo;
|
|
199
|
+
} catch (e) {
|
|
200
|
+
throw new Error(`Error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function getBaseAssetUrlFromBuild(buildDir) {
|
|
204
|
+
return getBuildInfo(buildDir).baseAssetUrl;
|
|
205
|
+
}
|
|
193
206
|
function isUngatedFor(gates, gate) {
|
|
194
207
|
return gates.includes(gate);
|
|
195
208
|
}
|
|
196
209
|
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
197
210
|
try {
|
|
198
|
-
|
|
199
|
-
const buildInfo = JSON.parse(
|
|
200
|
-
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
201
|
-
);
|
|
211
|
+
const buildInfo = getBuildInfo(buildDir);
|
|
202
212
|
return isUngatedFor(buildInfo.gates, gate);
|
|
203
213
|
} catch (e) {
|
|
204
|
-
console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
205
214
|
return false;
|
|
206
215
|
}
|
|
207
216
|
}
|
|
@@ -279,7 +288,7 @@ function setIn(object, nestedKeysArray, value) {
|
|
|
279
288
|
function isStylesheetAsset(staticAsset) {
|
|
280
289
|
return staticAsset.type === "stylesheet";
|
|
281
290
|
}
|
|
282
|
-
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, removeIndexFromPath, removeIndexOrTrailingJsFromPath, HEALTHCHECKS_ENABLED_DEFAULT, HEALTHCHECKS_STRICT_DEFAULT, GATES, ENABLED_FEATURES_GATE_MAP,
|
|
291
|
+
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, badInlineJsChars, inlineJsEscapeChars, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, removeIndexFromPath, removeIndexOrTrailingJsFromPath, HEALTHCHECKS_ENABLED_DEFAULT, HEALTHCHECKS_STRICT_DEFAULT, BUILD_INFO_PATH, GATES, ENABLED_FEATURES_GATE_MAP, findAllComponentsIn;
|
|
283
292
|
var init_basicUtils = __esm({
|
|
284
293
|
"../cms-js-internal/dist/basicUtils.js"() {
|
|
285
294
|
COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
@@ -395,6 +404,7 @@ ${groupEnd}</script>
|
|
|
395
404
|
};
|
|
396
405
|
HEALTHCHECKS_ENABLED_DEFAULT = true;
|
|
397
406
|
HEALTHCHECKS_STRICT_DEFAULT = false;
|
|
407
|
+
BUILD_INFO_PATH = "/build-info.json";
|
|
398
408
|
GATES = [
|
|
399
409
|
"CMS:JSRenderer:GetServerSideProps",
|
|
400
410
|
"CMS:JSRenderer:ModuleHubl",
|
|
@@ -405,7 +415,6 @@ ${groupEnd}</script>
|
|
|
405
415
|
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
406
416
|
"cms:jsr:RemoveCjsPlugin": "CMS:JSRenderer:RemoveCjsPlugin"
|
|
407
417
|
};
|
|
408
|
-
BUILD_INFO_PATH = "/build-info.json";
|
|
409
418
|
findAllComponentsIn = (webRoot2, componentsFolder) => {
|
|
410
419
|
const fullComponentsFolderPath = join(webRoot2, componentsFolder);
|
|
411
420
|
const componentsByName = {};
|
|
@@ -445,6 +454,7 @@ ${groupEnd}</script>
|
|
|
445
454
|
// ../cms-js-internal/dist/index.js
|
|
446
455
|
var dist_exports = {};
|
|
447
456
|
__export(dist_exports, {
|
|
457
|
+
AUTO_GEN_COMMENT: () => AUTO_GEN_COMMENT,
|
|
448
458
|
COMPONENT_EXTENSIONS: () => COMPONENT_EXTENSIONS,
|
|
449
459
|
CSS_LANGS_RE: () => CSS_LANGS_RE,
|
|
450
460
|
ENABLED_FEATURES_GATE_MAP: () => ENABLED_FEATURES_GATE_MAP,
|
|
@@ -454,21 +464,26 @@ __export(dist_exports, {
|
|
|
454
464
|
VIRTUAL_CONFIG_SETUP: () => VIRTUAL_CONFIG_SETUP,
|
|
455
465
|
VIRTUAL_ISLAND_RUNTIME: () => VIRTUAL_ISLAND_RUNTIME,
|
|
456
466
|
areBuildHealthChecksEnabled: () => areBuildHealthChecksEnabled,
|
|
467
|
+
buildTypeFromField: () => buildTypeFromField,
|
|
457
468
|
clientIslandEntryPlugin: () => clientIslandEntryPlugin,
|
|
458
469
|
collectCssInDev: () => collectCssInDev,
|
|
459
470
|
collectCssModules: () => collectCssModules,
|
|
471
|
+
constructFinalType: () => constructFinalType,
|
|
460
472
|
createIslandsGlobalJsForClientInDev: () => createIslandsGlobalJsForClientInDev,
|
|
461
473
|
doHealthChecksFailTheBuild: () => doHealthChecksFailTheBuild,
|
|
462
474
|
escapeForInlineJS: () => escapeForInlineJS,
|
|
463
475
|
findAllComponentsIn: () => findAllComponentsIn,
|
|
464
476
|
findAllModulesInRoot: () => findAllModulesInRoot,
|
|
465
477
|
findAllPartialsInRoot: () => findAllPartialsInRoot,
|
|
478
|
+
getBaseAssetUrlFromBuild: () => getBaseAssetUrlFromBuild,
|
|
479
|
+
getBuildInfo: () => getBuildInfo,
|
|
466
480
|
getCMSAssetConfig: () => getCMSAssetConfig,
|
|
467
481
|
getCMSAssetConfigIfExists: () => getCMSAssetConfigIfExists,
|
|
468
482
|
getCombinedReactUrl: () => getCombinedReactUrl,
|
|
469
483
|
getComponentExtension: () => getComponentExtension,
|
|
470
484
|
getEntryPointHash: () => getEntryPointHash,
|
|
471
485
|
getEntryPointHashWithIndexSuffix: () => getEntryPointHashWithIndexSuffix,
|
|
486
|
+
getFieldTypes: () => getFieldTypes,
|
|
472
487
|
getIslandRuntimeConfigUrl: () => getIslandRuntimeConfigUrl,
|
|
473
488
|
getIslandUrls: () => getIslandUrls,
|
|
474
489
|
getServerGlobalsToInject: () => getServerGlobalsToInject,
|
|
@@ -495,7 +510,8 @@ __export(dist_exports, {
|
|
|
495
510
|
serializeIslandDataForInlineScript: () => serializeIslandDataForInlineScript,
|
|
496
511
|
setIn: () => setIn,
|
|
497
512
|
ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
|
|
498
|
-
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
513
|
+
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId,
|
|
514
|
+
writeFieldsType: () => writeFieldsType
|
|
499
515
|
});
|
|
500
516
|
import * as dotProp from "dot-prop";
|
|
501
517
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -503,7 +519,9 @@ import stream from "stream";
|
|
|
503
519
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
504
520
|
import * as cmsComponents from "@hubspot/cms-components";
|
|
505
521
|
import { ServerRenderContext } from "@hubspot/cms-components";
|
|
506
|
-
import {
|
|
522
|
+
import { writeFileSync } from "fs";
|
|
523
|
+
import ts from "typescript";
|
|
524
|
+
import React, { isValidElement, cloneElement } from "react";
|
|
507
525
|
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
508
526
|
if (!supplementalFieldValues) {
|
|
509
527
|
return supplementalFieldValues;
|
|
@@ -629,6 +647,171 @@ async function renderOnServer(elements, renderContext = bootStrapRenderContext()
|
|
|
629
647
|
}
|
|
630
648
|
return { html, renderContext };
|
|
631
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
|
+
}
|
|
632
815
|
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath, prettyPrint, criticalDevErrors, includeNonces) {
|
|
633
816
|
if (prettyPrint === void 0 && hsServerPageUrl && cmsComponents.isDebugUrlString) {
|
|
634
817
|
prettyPrint = cmsComponents.isDebugUrlString(hsServerPageUrl);
|
|
@@ -704,7 +887,7 @@ function renderFieldsToJson(fields, moduleName) {
|
|
|
704
887
|
throw e;
|
|
705
888
|
}
|
|
706
889
|
}
|
|
707
|
-
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;
|
|
708
891
|
var init_dist = __esm({
|
|
709
892
|
"../cms-js-internal/dist/index.js"() {
|
|
710
893
|
init_basicUtils();
|
|
@@ -855,6 +1038,100 @@ ${indentString}`);
|
|
|
855
1038
|
}) : createServerRenderContext2("", null);
|
|
856
1039
|
return renderContext;
|
|
857
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
|
+
};
|
|
858
1135
|
}
|
|
859
1136
|
});
|
|
860
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
|
}
|