@hubspot/cms-dev-server 0.15.10 → 0.15.11
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/run.js +32 -64
- package/package.json +3 -3
package/dist/run.js
CHANGED
|
@@ -1047,7 +1047,7 @@ function trackUsage(action) {
|
|
|
1047
1047
|
eventName: EVENT_NAME,
|
|
1048
1048
|
action,
|
|
1049
1049
|
nodeVersion: getNodeVersionData(),
|
|
1050
|
-
version: "0.15.
|
|
1050
|
+
version: "0.15.11",
|
|
1051
1051
|
os: getPlatform()
|
|
1052
1052
|
};
|
|
1053
1053
|
const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -3193,7 +3193,6 @@ import { get as hsGet6 } from "@hubspot/cli-lib/http.js";
|
|
|
3193
3193
|
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
3194
3194
|
import { writeFileSync } from "fs";
|
|
3195
3195
|
import ts from "typescript";
|
|
3196
|
-
import React, { isValidElement } from "react";
|
|
3197
3196
|
var fieldTypeNameByType = {
|
|
3198
3197
|
alignment: "AlignmentFieldType",
|
|
3199
3198
|
audioplayer: "AudioFieldType",
|
|
@@ -3241,60 +3240,9 @@ var fieldTypeNameByType = {
|
|
|
3241
3240
|
video: "VideoFieldType",
|
|
3242
3241
|
workflow: "WorkflowFieldType"
|
|
3243
3242
|
};
|
|
3244
|
-
var getChildrenAsArray = (element) => React.Children.toArray(element.props.children);
|
|
3245
3243
|
function getFieldEntries(fields) {
|
|
3246
|
-
if (isValidElement(fields)) {
|
|
3247
|
-
const fieldsJSX = getChildrenAsArray(fields);
|
|
3248
|
-
return getReactFieldEntries(fieldsJSX);
|
|
3249
|
-
} else if (Array.isArray(fields)) {
|
|
3250
|
-
return getJSONFieldEntries(fields);
|
|
3251
|
-
}
|
|
3252
|
-
return void 0;
|
|
3253
|
-
}
|
|
3254
|
-
var getJSXFieldType = (fieldFunctionName) => {
|
|
3255
|
-
switch (fieldFunctionName) {
|
|
3256
|
-
case "RepeatedFieldGroup":
|
|
3257
|
-
case "FieldGroup":
|
|
3258
|
-
return "GroupFieldType";
|
|
3259
|
-
default:
|
|
3260
|
-
return `${fieldFunctionName}Type`;
|
|
3261
|
-
}
|
|
3262
|
-
};
|
|
3263
|
-
var getElementName = (element) => typeof element.type === "string" ? element.type : element.type.name || null;
|
|
3264
|
-
function getReactFieldEntries(fields) {
|
|
3265
|
-
const validTypeNames = Object.values(fieldTypeNameByType);
|
|
3266
3244
|
if (!Array.isArray(fields)) {
|
|
3267
|
-
return;
|
|
3268
|
-
}
|
|
3269
|
-
return fields.filter((field) => field.props && field.props.name).map((field) => {
|
|
3270
|
-
const elName = getElementName(field);
|
|
3271
|
-
const fieldType = getJSXFieldType(getElementName(field));
|
|
3272
|
-
if (!validTypeNames.includes(fieldType)) {
|
|
3273
|
-
return void 0;
|
|
3274
|
-
}
|
|
3275
|
-
const { name, default: hasDefault } = field.props;
|
|
3276
|
-
const isRepeater = elName === "RepeatedFieldGroup";
|
|
3277
|
-
const entry = {
|
|
3278
|
-
type: fieldType,
|
|
3279
|
-
name,
|
|
3280
|
-
hasDefault: !!hasDefault,
|
|
3281
|
-
isRepeater,
|
|
3282
|
-
children: []
|
|
3283
|
-
};
|
|
3284
|
-
if (fieldType === "GroupFieldType") {
|
|
3285
|
-
const childrenArray = getChildrenAsArray(field);
|
|
3286
|
-
const children = getReactFieldEntries(childrenArray);
|
|
3287
|
-
return {
|
|
3288
|
-
...entry,
|
|
3289
|
-
children
|
|
3290
|
-
};
|
|
3291
|
-
}
|
|
3292
|
-
return entry;
|
|
3293
|
-
}).filter((entry) => entry !== void 0);
|
|
3294
|
-
}
|
|
3295
|
-
function getJSONFieldEntries(fields) {
|
|
3296
|
-
if (!Array.isArray(fields)) {
|
|
3297
|
-
return;
|
|
3245
|
+
return void 0;
|
|
3298
3246
|
}
|
|
3299
3247
|
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
3300
3248
|
const { name, type } = field;
|
|
@@ -3307,15 +3255,20 @@ function getJSONFieldEntries(fields) {
|
|
|
3307
3255
|
name,
|
|
3308
3256
|
isRepeater: "occurrence" in field,
|
|
3309
3257
|
hasDefault: !!field.default,
|
|
3258
|
+
choices: (
|
|
3259
|
+
// Choices are pair [value, label] but only the value is printed to the page, so flatten it.
|
|
3260
|
+
"choices" in field ? field.choices.map(([value]) => value) : void 0
|
|
3261
|
+
),
|
|
3310
3262
|
children: []
|
|
3311
3263
|
};
|
|
3312
3264
|
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
3313
|
-
const children =
|
|
3265
|
+
const children = getFieldEntries(field.children);
|
|
3314
3266
|
return { ...entry, children };
|
|
3315
3267
|
}
|
|
3316
3268
|
return entry;
|
|
3317
3269
|
}).filter((entry) => entry !== void 0);
|
|
3318
3270
|
}
|
|
3271
|
+
var INVALID_IMPORTS = ["ChoiceFieldType"];
|
|
3319
3272
|
var OVERRIDE_TYPE = "Override";
|
|
3320
3273
|
var REQUIRED_TYPE = "Required";
|
|
3321
3274
|
var REPEATED_VAR = "_repeater";
|
|
@@ -3324,6 +3277,11 @@ var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
|
3324
3277
|
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
3325
3278
|
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
3326
3279
|
var createPropertySignature = (identifier, type) => ts.factory.createPropertySignature([], identifier, void 0, type);
|
|
3280
|
+
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
3281
|
+
values.map(
|
|
3282
|
+
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
3283
|
+
)
|
|
3284
|
+
);
|
|
3327
3285
|
var buildTypeFromField = (field, additionalNode) => {
|
|
3328
3286
|
const imports = [field.type];
|
|
3329
3287
|
const identifier = ts.factory.createIdentifier(field.name);
|
|
@@ -3332,6 +3290,9 @@ var buildTypeFromField = (field, additionalNode) => {
|
|
|
3332
3290
|
baseType
|
|
3333
3291
|
]);
|
|
3334
3292
|
let finalType = field.hasDefault ? requiredType : baseType;
|
|
3293
|
+
if (field.choices) {
|
|
3294
|
+
finalType = createUnionTypeFromArray(field.choices);
|
|
3295
|
+
}
|
|
3335
3296
|
if (additionalNode) {
|
|
3336
3297
|
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
3337
3298
|
const repeaterName = ts.factory.createLiteralTypeNode(
|
|
@@ -3392,7 +3353,10 @@ function getFieldTypes(fields) {
|
|
|
3392
3353
|
imports.push(...newImports);
|
|
3393
3354
|
return type;
|
|
3394
3355
|
});
|
|
3395
|
-
|
|
3356
|
+
const validImports = Array.from(
|
|
3357
|
+
new Set(imports.filter((name) => !INVALID_IMPORTS.includes(name)))
|
|
3358
|
+
);
|
|
3359
|
+
return { types, imports: validImports };
|
|
3396
3360
|
}
|
|
3397
3361
|
function constructFinalType(fields, typeName) {
|
|
3398
3362
|
const { types, imports } = getFieldTypes(fields);
|
|
@@ -3502,22 +3466,22 @@ var getIndexFile = (filePath, projectRoot) => {
|
|
|
3502
3466
|
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
3503
3467
|
return indexFileName ? { indexFilePath: path8.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
3504
3468
|
};
|
|
3505
|
-
var getIndexFileFields = async (indexFilePath, viteServer) => {
|
|
3469
|
+
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
3506
3470
|
let indexFile;
|
|
3471
|
+
let renderFieldsToJson;
|
|
3507
3472
|
try {
|
|
3508
3473
|
indexFile = await viteServer.ssrLoadModule(indexFilePath);
|
|
3474
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
3475
|
+
({ renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath));
|
|
3509
3476
|
} catch (e) {
|
|
3510
3477
|
return void 0;
|
|
3511
3478
|
}
|
|
3512
3479
|
if (!indexFile.fields)
|
|
3513
3480
|
return void 0;
|
|
3514
3481
|
const fields = indexFile.fields;
|
|
3515
|
-
const
|
|
3516
|
-
const
|
|
3517
|
-
|
|
3518
|
-
return fields;
|
|
3519
|
-
}
|
|
3520
|
-
return void 0;
|
|
3482
|
+
const renderedFieldsJson = renderFieldsToJson(fields, indexFileName);
|
|
3483
|
+
const isValidFields = Array.isArray(renderedFieldsJson);
|
|
3484
|
+
return isValidFields ? renderedFieldsJson : void 0;
|
|
3521
3485
|
};
|
|
3522
3486
|
var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
3523
3487
|
const indexInfo = getIndexFile(filePath, projectRoot);
|
|
@@ -3528,7 +3492,11 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
3528
3492
|
const isTypeFile = filePath.endsWith(".types.ts");
|
|
3529
3493
|
if (isTypeFile)
|
|
3530
3494
|
return;
|
|
3531
|
-
const fields = await getIndexFileFields(
|
|
3495
|
+
const fields = await getIndexFileFields(
|
|
3496
|
+
indexFilePath,
|
|
3497
|
+
indexFileName,
|
|
3498
|
+
viteServer
|
|
3499
|
+
);
|
|
3532
3500
|
if (fields) {
|
|
3533
3501
|
const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
|
|
3534
3502
|
const typeFilePath = path8.join(path8.dirname(filePath), typeFileName);
|
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.11",
|
|
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.11",
|
|
30
30
|
"@inquirer/select": "^2.0.0",
|
|
31
31
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
32
32
|
"@storybook/addon-actions": "7.1.1",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"publishConfig": {
|
|
109
109
|
"access": "public"
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "17dca24355a7fcd3f3d851c1f908cab81ee9883b"
|
|
112
112
|
}
|