@hubspot/cms-dev-server 0.18.14 → 0.18.17
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/generateJsonFromJsx.js +9 -5
- package/dist/index.js +106 -35
- package/dist/internalSsr.js +23 -6
- package/dist/run.js +106 -35
- package/dist/storybook/index.js +1 -1
- package/dist/storybook-main/main.js +27 -10
- package/package.json +3 -3
- package/types/api/designmanager.d.ts +4 -0
- package/types/lib/getDevServerUIData.d.ts +14 -5
- package/types/lib/renderModuleJson.d.ts +4 -0
- package/types/routes/createAppServerRoutes.d.ts +5 -0
- package/dist/generateJsonFromJsx.js.map +0 -7
- package/dist/index.js.map +0 -7
- package/dist/internalSsr.js.map +0 -7
- package/dist/island-runtime.js.map +0 -7
- package/dist/run.js.map +0 -7
- package/dist/storybook/index.js.map +0 -7
- package/dist/storybook-main/main.js.map +0 -7
- package/dist/storybook-main/preview.js.map +0 -7
- package/types/island-runtime.d.ts +0 -2
|
@@ -9,7 +9,7 @@ import { normalizePath as normalizePath2 } from "vite";
|
|
|
9
9
|
import { createServer as createViteServer } from "vite";
|
|
10
10
|
import { default as react } from "@vitejs/plugin-react";
|
|
11
11
|
|
|
12
|
-
// ../cms-js-internal/dist/types-
|
|
12
|
+
// ../cms-js-internal/dist/types-CsJ4tzsl.js
|
|
13
13
|
import path from "path";
|
|
14
14
|
var viteRoot;
|
|
15
15
|
var viteCommand;
|
|
@@ -126,7 +126,7 @@ function findCmsModules(buildContentDescriptors = {}) {
|
|
|
126
126
|
},
|
|
127
127
|
transform(code, id) {
|
|
128
128
|
const moduleInfo = this.getModuleInfo(id);
|
|
129
|
-
if (
|
|
129
|
+
if (!shouldAnalyzeModule(config, moduleInfo, code))
|
|
130
130
|
return null;
|
|
131
131
|
const contentDescriptors = analyzeSourceCodeUsages(
|
|
132
132
|
this,
|
|
@@ -141,7 +141,6 @@ function findCmsModules(buildContentDescriptors = {}) {
|
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
return null;
|
|
145
144
|
},
|
|
146
145
|
buildEnd(error) {
|
|
147
146
|
if (error)
|
|
@@ -213,9 +212,14 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
|
|
|
213
212
|
function toRelativePath(config, path4) {
|
|
214
213
|
return path4.replace(`${config.root}/`, "");
|
|
215
214
|
}
|
|
216
|
-
function
|
|
215
|
+
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
216
|
+
const [fileId, __] = moduleInfo.id.split("?");
|
|
217
217
|
const isExternal = config.command !== "serve" && moduleInfo.isExternal;
|
|
218
|
-
return
|
|
218
|
+
return (
|
|
219
|
+
// analyze customer code only
|
|
220
|
+
!isExternal && moduleInfo.id.startsWith(config.root) && // jsx files that contain "Module" / "DndArea"
|
|
221
|
+
(fileId.endsWith(".tsx") || fileId.endsWith(".jsx")) && (code.includes(CMS_MODULE_COMPONENT_NAME) || code.includes(DND_AREA_COMPONENT_NAME))
|
|
222
|
+
);
|
|
219
223
|
}
|
|
220
224
|
function getEntryPoints(ctx, config) {
|
|
221
225
|
return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createServer as createViteServer } from "vite";
|
|
3
3
|
import { default as react } from "@vitejs/plugin-react";
|
|
4
4
|
|
|
5
|
-
// ../cms-js-internal/dist/types-
|
|
5
|
+
// ../cms-js-internal/dist/types-CsJ4tzsl.js
|
|
6
6
|
import path from "path";
|
|
7
7
|
import { createHash } from "crypto";
|
|
8
8
|
import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
@@ -223,13 +223,26 @@ function findAllModulesInRoot(webRoot) {
|
|
|
223
223
|
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
224
224
|
);
|
|
225
225
|
const moduleSubpaths = Object.keys(allModuleComponents);
|
|
226
|
+
const moduleExtensions = Object.values(allModuleComponents).map((path22) => {
|
|
227
|
+
if (!path22)
|
|
228
|
+
return "";
|
|
229
|
+
const extension = path22.split(".").pop() || "";
|
|
230
|
+
return extension;
|
|
231
|
+
});
|
|
226
232
|
const moduleNamesWithExtension = Object.values(allModuleComponents).map(
|
|
227
233
|
(path22) => {
|
|
234
|
+
if (!path22)
|
|
235
|
+
return "";
|
|
228
236
|
const file = path22.replace("components/modules/", "");
|
|
229
237
|
return file.includes("/index.") ? file.split("/index.")[0] : file;
|
|
230
238
|
}
|
|
231
239
|
);
|
|
232
|
-
return {
|
|
240
|
+
return {
|
|
241
|
+
moduleNames,
|
|
242
|
+
moduleSubpaths,
|
|
243
|
+
moduleNamesWithExtension,
|
|
244
|
+
moduleExtensions
|
|
245
|
+
};
|
|
233
246
|
}
|
|
234
247
|
function findAllPartialsInRoot(webRoot) {
|
|
235
248
|
const allPartialComponents = findAllComponentsIn(
|
|
@@ -500,7 +513,7 @@ function findCmsModules(buildContentDescriptors = {}) {
|
|
|
500
513
|
},
|
|
501
514
|
transform(code, id) {
|
|
502
515
|
const moduleInfo = this.getModuleInfo(id);
|
|
503
|
-
if (
|
|
516
|
+
if (!shouldAnalyzeModule(config, moduleInfo, code))
|
|
504
517
|
return null;
|
|
505
518
|
const contentDescriptors = analyzeSourceCodeUsages(
|
|
506
519
|
this,
|
|
@@ -515,7 +528,6 @@ function findCmsModules(buildContentDescriptors = {}) {
|
|
|
515
528
|
}
|
|
516
529
|
};
|
|
517
530
|
}
|
|
518
|
-
return null;
|
|
519
531
|
},
|
|
520
532
|
buildEnd(error) {
|
|
521
533
|
if (error)
|
|
@@ -587,9 +599,14 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
|
|
|
587
599
|
function toRelativePath(config, path15) {
|
|
588
600
|
return path15.replace(`${config.root}/`, "");
|
|
589
601
|
}
|
|
590
|
-
function
|
|
602
|
+
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
603
|
+
const [fileId, __] = moduleInfo.id.split("?");
|
|
591
604
|
const isExternal = config.command !== "serve" && moduleInfo.isExternal;
|
|
592
|
-
return
|
|
605
|
+
return (
|
|
606
|
+
// analyze customer code only
|
|
607
|
+
!isExternal && moduleInfo.id.startsWith(config.root) && // jsx files that contain "Module" / "DndArea"
|
|
608
|
+
(fileId.endsWith(".tsx") || fileId.endsWith(".jsx")) && (code.includes(CMS_MODULE_COMPONENT_NAME) || code.includes(DND_AREA_COMPONENT_NAME))
|
|
609
|
+
);
|
|
593
610
|
}
|
|
594
611
|
function getEntryPoints(ctx, config) {
|
|
595
612
|
return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
|
|
@@ -1034,7 +1051,7 @@ import url2 from "url";
|
|
|
1034
1051
|
import express3 from "express";
|
|
1035
1052
|
import http3 from "http";
|
|
1036
1053
|
import bodyParser from "body-parser";
|
|
1037
|
-
import { spawn } from "child_process";
|
|
1054
|
+
import { spawn as spawn2 } from "child_process";
|
|
1038
1055
|
import { normalizePath as normalizePath9 } from "vite";
|
|
1039
1056
|
import { Transform } from "stream";
|
|
1040
1057
|
|
|
@@ -1455,7 +1472,7 @@ function trackUsage(action) {
|
|
|
1455
1472
|
eventName: EVENT_NAME,
|
|
1456
1473
|
action,
|
|
1457
1474
|
nodeVersion: getNodeVersionData(),
|
|
1458
|
-
version: "0.18.
|
|
1475
|
+
version: "0.18.17",
|
|
1459
1476
|
os: getPlatform()
|
|
1460
1477
|
};
|
|
1461
1478
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -4194,7 +4211,7 @@ import { default as react2 } from "@vitejs/plugin-react";
|
|
|
4194
4211
|
// src/lib/getDevServerUIData.ts
|
|
4195
4212
|
import path11 from "path";
|
|
4196
4213
|
import { normalizePath as normalizePath8 } from "vite";
|
|
4197
|
-
function
|
|
4214
|
+
function mapReactModules(modules, themeWebRoot, viteServer) {
|
|
4198
4215
|
return Promise.all(
|
|
4199
4216
|
modules.moduleNames.map(async (name, index) => {
|
|
4200
4217
|
const modulePath = normalizePath8(
|
|
@@ -4203,22 +4220,40 @@ function mapModulesData(modules, themeWebRoot, viteServer) {
|
|
|
4203
4220
|
const fieldsJson = await renderModuleFieldsJson_default(viteServer, modulePath);
|
|
4204
4221
|
return {
|
|
4205
4222
|
name,
|
|
4223
|
+
type: "react" /* REACT */,
|
|
4206
4224
|
subPath: modules.moduleSubpaths[index],
|
|
4207
4225
|
nameWithExtension: modules.moduleNamesWithExtension[index],
|
|
4226
|
+
extension: modules.moduleExtensions[index],
|
|
4208
4227
|
fieldsJson
|
|
4209
4228
|
};
|
|
4210
4229
|
})
|
|
4211
4230
|
);
|
|
4212
4231
|
}
|
|
4213
|
-
function
|
|
4214
|
-
return modules.
|
|
4232
|
+
function normalizeHubLModules(modules) {
|
|
4233
|
+
return modules.map((module) => ({
|
|
4234
|
+
name: module.name,
|
|
4235
|
+
type: "hubl" /* HUBL */,
|
|
4236
|
+
subPath: `@projects/${module.path.split("/@projects/")[1] || module.path}`,
|
|
4237
|
+
nameWithExtension: module.filename,
|
|
4238
|
+
fieldsJson: module.fields
|
|
4239
|
+
}));
|
|
4240
|
+
}
|
|
4241
|
+
function normalizePartialsData(partialData) {
|
|
4242
|
+
return partialData.partialNames.map((name, index) => ({
|
|
4215
4243
|
name,
|
|
4216
|
-
subPath:
|
|
4244
|
+
subPath: partialData.partialSubpaths[index]
|
|
4245
|
+
}));
|
|
4246
|
+
}
|
|
4247
|
+
function normalizeTemplatesData(templates) {
|
|
4248
|
+
return templates.map((template) => ({
|
|
4249
|
+
name: template.displayName || template.label,
|
|
4250
|
+
subPath: `@projects/${template.path.split("/@projects/")[1] || template.path}`
|
|
4217
4251
|
}));
|
|
4218
4252
|
}
|
|
4219
4253
|
async function getDevServerUIData(reqLocals) {
|
|
4220
4254
|
const {
|
|
4221
4255
|
themeWebRoot,
|
|
4256
|
+
authedEnv,
|
|
4222
4257
|
authedPortalId,
|
|
4223
4258
|
projectName,
|
|
4224
4259
|
localPreviewToken,
|
|
@@ -4227,7 +4262,7 @@ async function getDevServerUIData(reqLocals) {
|
|
|
4227
4262
|
} = reqLocals;
|
|
4228
4263
|
const modulesData = findAllModulesInRoot(themeWebRoot);
|
|
4229
4264
|
const partialsData = findAllPartialsInRoot(themeWebRoot);
|
|
4230
|
-
const
|
|
4265
|
+
const reactModules = await mapReactModules(
|
|
4231
4266
|
modulesData,
|
|
4232
4267
|
themeWebRoot,
|
|
4233
4268
|
viteServer
|
|
@@ -4244,19 +4279,69 @@ async function getDevServerUIData(reqLocals) {
|
|
|
4244
4279
|
const hubLTemplates = (hubLTemplateData == null ? void 0 : hubLTemplateData.objects.filter(
|
|
4245
4280
|
(template) => isCodedFile(template.filename)
|
|
4246
4281
|
)) || [];
|
|
4282
|
+
const mappedHubLModules = normalizeHubLModules((hubLModuleData == null ? void 0 : hubLModuleData.objects) || []);
|
|
4247
4283
|
return {
|
|
4248
4284
|
authedPortalId,
|
|
4285
|
+
authedEnv,
|
|
4249
4286
|
projectName,
|
|
4250
|
-
modulesData:
|
|
4251
|
-
partialsData:
|
|
4252
|
-
hubLModules:
|
|
4253
|
-
hubLTemplates,
|
|
4287
|
+
modulesData: reactModules,
|
|
4288
|
+
partialsData: normalizePartialsData(partialsData),
|
|
4289
|
+
hubLModules: mappedHubLModules || [],
|
|
4290
|
+
hubLTemplates: normalizeTemplatesData(hubLTemplates),
|
|
4254
4291
|
themeWebRoot,
|
|
4255
4292
|
webRootProjectComponentFolder
|
|
4256
4293
|
};
|
|
4257
4294
|
}
|
|
4258
4295
|
var getDevServerUIData_default = getDevServerUIData;
|
|
4259
4296
|
|
|
4297
|
+
// src/routes/createAppServerRoutes.ts
|
|
4298
|
+
import { Router as Router3 } from "express";
|
|
4299
|
+
import { spawn } from "child_process";
|
|
4300
|
+
function getOpenCommand() {
|
|
4301
|
+
switch (process.platform) {
|
|
4302
|
+
case "darwin":
|
|
4303
|
+
return "open";
|
|
4304
|
+
case "win32":
|
|
4305
|
+
return "start";
|
|
4306
|
+
default:
|
|
4307
|
+
return "xdg-open";
|
|
4308
|
+
}
|
|
4309
|
+
}
|
|
4310
|
+
async function handleGetModulePages(req, res, next) {
|
|
4311
|
+
const { path: path15, portalId } = req.query;
|
|
4312
|
+
if (!path15 || !portalId) {
|
|
4313
|
+
return res.status(400).json({ error: "Missing required parameters" });
|
|
4314
|
+
}
|
|
4315
|
+
try {
|
|
4316
|
+
const data = await fetchModulePageDependencies(
|
|
4317
|
+
Number(portalId),
|
|
4318
|
+
path15
|
|
4319
|
+
);
|
|
4320
|
+
res.json(data);
|
|
4321
|
+
} catch (err) {
|
|
4322
|
+
next(err);
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4325
|
+
function handleOpenFile(req, res, next) {
|
|
4326
|
+
const { path: path15 } = req.query;
|
|
4327
|
+
if (!path15) {
|
|
4328
|
+
return res.status(400).json({ error: "Missing required parameters" });
|
|
4329
|
+
}
|
|
4330
|
+
try {
|
|
4331
|
+
const command = getOpenCommand();
|
|
4332
|
+
spawn(command, [path15], { detached: true }).unref();
|
|
4333
|
+
res.sendStatus(200);
|
|
4334
|
+
} catch (err) {
|
|
4335
|
+
next(err);
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
function createAppServerRoutes() {
|
|
4339
|
+
const router = Router3();
|
|
4340
|
+
router.get("/module-pages", handleGetModulePages);
|
|
4341
|
+
router.get("/open-file", handleOpenFile);
|
|
4342
|
+
return router;
|
|
4343
|
+
}
|
|
4344
|
+
|
|
4260
4345
|
// src/createAppServer.ts
|
|
4261
4346
|
async function createAppServer(webRoot, reqLocals, port) {
|
|
4262
4347
|
const app = express2();
|
|
@@ -4306,23 +4391,9 @@ async function createAppServer(webRoot, reqLocals, port) {
|
|
|
4306
4391
|
envPrefix: "HS_"
|
|
4307
4392
|
};
|
|
4308
4393
|
const viteServer = await createViteServer2(viteConfig);
|
|
4394
|
+
app.use("/api", createAppServerRoutes());
|
|
4309
4395
|
app.use(viteServer.middlewares);
|
|
4310
|
-
app.get("
|
|
4311
|
-
const { path: path15, portalId } = req.query;
|
|
4312
|
-
if (!path15 || !portalId) {
|
|
4313
|
-
return res.status(400).json({ error: "Missing required parameters" });
|
|
4314
|
-
}
|
|
4315
|
-
try {
|
|
4316
|
-
const data = await fetchModulePageDependencies(
|
|
4317
|
-
Number(portalId),
|
|
4318
|
-
path15
|
|
4319
|
-
);
|
|
4320
|
-
res.json(data);
|
|
4321
|
-
} catch (err) {
|
|
4322
|
-
next(err);
|
|
4323
|
-
}
|
|
4324
|
-
});
|
|
4325
|
-
app.use("*", async (req, res) => {
|
|
4396
|
+
app.get("/*", async (req, res) => {
|
|
4326
4397
|
try {
|
|
4327
4398
|
const initialProps = await getDevServerUIData_default({
|
|
4328
4399
|
...reqLocals,
|
|
@@ -4348,7 +4419,7 @@ async function createAppServer(webRoot, reqLocals, port) {
|
|
|
4348
4419
|
res.status(500).end(e.stack);
|
|
4349
4420
|
}
|
|
4350
4421
|
});
|
|
4351
|
-
app.use((err, req, res,
|
|
4422
|
+
app.use((err, req, res, __next) => {
|
|
4352
4423
|
console.error("API Error:", err);
|
|
4353
4424
|
res.status(500).json({ error: "Internal server error" });
|
|
4354
4425
|
});
|
|
@@ -5194,7 +5265,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
5194
5265
|
const packageRoot = path14.dirname(url2.fileURLToPath(import.meta.url));
|
|
5195
5266
|
const configPath = path14.resolve(packageRoot, "./storybook-main");
|
|
5196
5267
|
sendTrackingRequest("start-storybook");
|
|
5197
|
-
const storybookProcess =
|
|
5268
|
+
const storybookProcess = spawn2(
|
|
5198
5269
|
"sb",
|
|
5199
5270
|
[
|
|
5200
5271
|
"dev",
|
package/dist/internalSsr.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../cms-js-internal/dist/types-
|
|
1
|
+
// ../cms-js-internal/dist/types-CsJ4tzsl.js
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { createHash } from "crypto";
|
|
4
4
|
import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
@@ -383,13 +383,26 @@ function findAllModulesInRoot(webRoot) {
|
|
|
383
383
|
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
384
384
|
);
|
|
385
385
|
const moduleSubpaths = Object.keys(allModuleComponents);
|
|
386
|
+
const moduleExtensions = Object.values(allModuleComponents).map((path2) => {
|
|
387
|
+
if (!path2)
|
|
388
|
+
return "";
|
|
389
|
+
const extension = path2.split(".").pop() || "";
|
|
390
|
+
return extension;
|
|
391
|
+
});
|
|
386
392
|
const moduleNamesWithExtension = Object.values(allModuleComponents).map(
|
|
387
393
|
(path2) => {
|
|
394
|
+
if (!path2)
|
|
395
|
+
return "";
|
|
388
396
|
const file = path2.replace("components/modules/", "");
|
|
389
397
|
return file.includes("/index.") ? file.split("/index.")[0] : file;
|
|
390
398
|
}
|
|
391
399
|
);
|
|
392
|
-
return {
|
|
400
|
+
return {
|
|
401
|
+
moduleNames,
|
|
402
|
+
moduleSubpaths,
|
|
403
|
+
moduleNamesWithExtension,
|
|
404
|
+
moduleExtensions
|
|
405
|
+
};
|
|
393
406
|
}
|
|
394
407
|
function findAllPartialsInRoot(webRoot) {
|
|
395
408
|
const allPartialComponents = findAllComponentsIn(
|
|
@@ -664,7 +677,7 @@ function findCmsModules(buildContentDescriptors = {}) {
|
|
|
664
677
|
},
|
|
665
678
|
transform(code, id) {
|
|
666
679
|
const moduleInfo = this.getModuleInfo(id);
|
|
667
|
-
if (
|
|
680
|
+
if (!shouldAnalyzeModule(config, moduleInfo, code))
|
|
668
681
|
return null;
|
|
669
682
|
const contentDescriptors = analyzeSourceCodeUsages(
|
|
670
683
|
this,
|
|
@@ -679,7 +692,6 @@ function findCmsModules(buildContentDescriptors = {}) {
|
|
|
679
692
|
}
|
|
680
693
|
};
|
|
681
694
|
}
|
|
682
|
-
return null;
|
|
683
695
|
},
|
|
684
696
|
buildEnd(error) {
|
|
685
697
|
if (error)
|
|
@@ -751,9 +763,14 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
|
|
|
751
763
|
function toRelativePath(config, path2) {
|
|
752
764
|
return path2.replace(`${config.root}/`, "");
|
|
753
765
|
}
|
|
754
|
-
function
|
|
766
|
+
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
767
|
+
const [fileId, __] = moduleInfo.id.split("?");
|
|
755
768
|
const isExternal = config.command !== "serve" && moduleInfo.isExternal;
|
|
756
|
-
return
|
|
769
|
+
return (
|
|
770
|
+
// analyze customer code only
|
|
771
|
+
!isExternal && moduleInfo.id.startsWith(config.root) && // jsx files that contain "Module" / "DndArea"
|
|
772
|
+
(fileId.endsWith(".tsx") || fileId.endsWith(".jsx")) && (code.includes(CMS_MODULE_COMPONENT_NAME) || code.includes(DND_AREA_COMPONENT_NAME))
|
|
773
|
+
);
|
|
757
774
|
}
|
|
758
775
|
function getEntryPoints(ctx, config) {
|
|
759
776
|
return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
|
package/dist/run.js
CHANGED
|
@@ -751,7 +751,7 @@ import url2 from "url";
|
|
|
751
751
|
import express3 from "express";
|
|
752
752
|
import http3 from "http";
|
|
753
753
|
import bodyParser from "body-parser";
|
|
754
|
-
import { spawn } from "child_process";
|
|
754
|
+
import { spawn as spawn2 } from "child_process";
|
|
755
755
|
import { normalizePath as normalizePath9 } from "vite";
|
|
756
756
|
import { Transform } from "stream";
|
|
757
757
|
|
|
@@ -795,7 +795,7 @@ function packagePath(metaUrl, projectPath) {
|
|
|
795
795
|
);
|
|
796
796
|
}
|
|
797
797
|
|
|
798
|
-
// ../cms-js-internal/dist/types-
|
|
798
|
+
// ../cms-js-internal/dist/types-CsJ4tzsl.js
|
|
799
799
|
import path3 from "path";
|
|
800
800
|
import { createHash } from "crypto";
|
|
801
801
|
import fs2, { readFileSync, existsSync as existsSync2, readdirSync, lstatSync } from "fs";
|
|
@@ -1016,13 +1016,26 @@ function findAllModulesInRoot(webRoot2) {
|
|
|
1016
1016
|
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
1017
1017
|
);
|
|
1018
1018
|
const moduleSubpaths = Object.keys(allModuleComponents);
|
|
1019
|
+
const moduleExtensions = Object.values(allModuleComponents).map((path22) => {
|
|
1020
|
+
if (!path22)
|
|
1021
|
+
return "";
|
|
1022
|
+
const extension = path22.split(".").pop() || "";
|
|
1023
|
+
return extension;
|
|
1024
|
+
});
|
|
1019
1025
|
const moduleNamesWithExtension = Object.values(allModuleComponents).map(
|
|
1020
1026
|
(path22) => {
|
|
1027
|
+
if (!path22)
|
|
1028
|
+
return "";
|
|
1021
1029
|
const file = path22.replace("components/modules/", "");
|
|
1022
1030
|
return file.includes("/index.") ? file.split("/index.")[0] : file;
|
|
1023
1031
|
}
|
|
1024
1032
|
);
|
|
1025
|
-
return {
|
|
1033
|
+
return {
|
|
1034
|
+
moduleNames,
|
|
1035
|
+
moduleSubpaths,
|
|
1036
|
+
moduleNamesWithExtension,
|
|
1037
|
+
moduleExtensions
|
|
1038
|
+
};
|
|
1026
1039
|
}
|
|
1027
1040
|
function findAllPartialsInRoot(webRoot2) {
|
|
1028
1041
|
const allPartialComponents = findAllComponentsIn(
|
|
@@ -1293,7 +1306,7 @@ function findCmsModules(buildContentDescriptors = {}) {
|
|
|
1293
1306
|
},
|
|
1294
1307
|
transform(code, id) {
|
|
1295
1308
|
const moduleInfo = this.getModuleInfo(id);
|
|
1296
|
-
if (
|
|
1309
|
+
if (!shouldAnalyzeModule(config, moduleInfo, code))
|
|
1297
1310
|
return null;
|
|
1298
1311
|
const contentDescriptors = analyzeSourceCodeUsages(
|
|
1299
1312
|
this,
|
|
@@ -1308,7 +1321,6 @@ function findCmsModules(buildContentDescriptors = {}) {
|
|
|
1308
1321
|
}
|
|
1309
1322
|
};
|
|
1310
1323
|
}
|
|
1311
|
-
return null;
|
|
1312
1324
|
},
|
|
1313
1325
|
buildEnd(error) {
|
|
1314
1326
|
if (error)
|
|
@@ -1380,9 +1392,14 @@ function convertEntryPointIslandPathsToRelative(config, entryPointsCmsModuleMap)
|
|
|
1380
1392
|
function toRelativePath(config, path16) {
|
|
1381
1393
|
return path16.replace(`${config.root}/`, "");
|
|
1382
1394
|
}
|
|
1383
|
-
function
|
|
1395
|
+
function shouldAnalyzeModule(config, moduleInfo, code) {
|
|
1396
|
+
const [fileId, __] = moduleInfo.id.split("?");
|
|
1384
1397
|
const isExternal = config.command !== "serve" && moduleInfo.isExternal;
|
|
1385
|
-
return
|
|
1398
|
+
return (
|
|
1399
|
+
// analyze customer code only
|
|
1400
|
+
!isExternal && moduleInfo.id.startsWith(config.root) && // jsx files that contain "Module" / "DndArea"
|
|
1401
|
+
(fileId.endsWith(".tsx") || fileId.endsWith(".jsx")) && (code.includes(CMS_MODULE_COMPONENT_NAME) || code.includes(DND_AREA_COMPONENT_NAME))
|
|
1402
|
+
);
|
|
1386
1403
|
}
|
|
1387
1404
|
function getEntryPoints(ctx, config) {
|
|
1388
1405
|
return Array.from(ctx.getModuleIds()).filter((moduleId) => moduleId.startsWith(config.root)).map((moduleId) => ctx.getModuleInfo(moduleId)).filter((moduleInfo) => moduleInfo.isEntry);
|
|
@@ -2064,7 +2081,7 @@ function trackUsage(action) {
|
|
|
2064
2081
|
eventName: EVENT_NAME,
|
|
2065
2082
|
action,
|
|
2066
2083
|
nodeVersion: getNodeVersionData(),
|
|
2067
|
-
version: "0.18.
|
|
2084
|
+
version: "0.18.17",
|
|
2068
2085
|
os: getPlatform()
|
|
2069
2086
|
};
|
|
2070
2087
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -4922,7 +4939,7 @@ import { default as react2 } from "@vitejs/plugin-react";
|
|
|
4922
4939
|
// src/lib/getDevServerUIData.ts
|
|
4923
4940
|
import path12 from "path";
|
|
4924
4941
|
import { normalizePath as normalizePath8 } from "vite";
|
|
4925
|
-
function
|
|
4942
|
+
function mapReactModules(modules, themeWebRoot, viteServer) {
|
|
4926
4943
|
return Promise.all(
|
|
4927
4944
|
modules.moduleNames.map(async (name, index) => {
|
|
4928
4945
|
const modulePath = normalizePath8(
|
|
@@ -4931,22 +4948,40 @@ function mapModulesData(modules, themeWebRoot, viteServer) {
|
|
|
4931
4948
|
const fieldsJson = await renderModuleFieldsJson_default(viteServer, modulePath);
|
|
4932
4949
|
return {
|
|
4933
4950
|
name,
|
|
4951
|
+
type: "react" /* REACT */,
|
|
4934
4952
|
subPath: modules.moduleSubpaths[index],
|
|
4935
4953
|
nameWithExtension: modules.moduleNamesWithExtension[index],
|
|
4954
|
+
extension: modules.moduleExtensions[index],
|
|
4936
4955
|
fieldsJson
|
|
4937
4956
|
};
|
|
4938
4957
|
})
|
|
4939
4958
|
);
|
|
4940
4959
|
}
|
|
4941
|
-
function
|
|
4942
|
-
return modules.
|
|
4960
|
+
function normalizeHubLModules(modules) {
|
|
4961
|
+
return modules.map((module) => ({
|
|
4962
|
+
name: module.name,
|
|
4963
|
+
type: "hubl" /* HUBL */,
|
|
4964
|
+
subPath: `@projects/${module.path.split("/@projects/")[1] || module.path}`,
|
|
4965
|
+
nameWithExtension: module.filename,
|
|
4966
|
+
fieldsJson: module.fields
|
|
4967
|
+
}));
|
|
4968
|
+
}
|
|
4969
|
+
function normalizePartialsData(partialData) {
|
|
4970
|
+
return partialData.partialNames.map((name, index) => ({
|
|
4943
4971
|
name,
|
|
4944
|
-
subPath:
|
|
4972
|
+
subPath: partialData.partialSubpaths[index]
|
|
4973
|
+
}));
|
|
4974
|
+
}
|
|
4975
|
+
function normalizeTemplatesData(templates) {
|
|
4976
|
+
return templates.map((template) => ({
|
|
4977
|
+
name: template.displayName || template.label,
|
|
4978
|
+
subPath: `@projects/${template.path.split("/@projects/")[1] || template.path}`
|
|
4945
4979
|
}));
|
|
4946
4980
|
}
|
|
4947
4981
|
async function getDevServerUIData(reqLocals) {
|
|
4948
4982
|
const {
|
|
4949
4983
|
themeWebRoot,
|
|
4984
|
+
authedEnv,
|
|
4950
4985
|
authedPortalId,
|
|
4951
4986
|
projectName,
|
|
4952
4987
|
localPreviewToken,
|
|
@@ -4955,7 +4990,7 @@ async function getDevServerUIData(reqLocals) {
|
|
|
4955
4990
|
} = reqLocals;
|
|
4956
4991
|
const modulesData = findAllModulesInRoot(themeWebRoot);
|
|
4957
4992
|
const partialsData = findAllPartialsInRoot(themeWebRoot);
|
|
4958
|
-
const
|
|
4993
|
+
const reactModules = await mapReactModules(
|
|
4959
4994
|
modulesData,
|
|
4960
4995
|
themeWebRoot,
|
|
4961
4996
|
viteServer
|
|
@@ -4972,19 +5007,69 @@ async function getDevServerUIData(reqLocals) {
|
|
|
4972
5007
|
const hubLTemplates = (hubLTemplateData == null ? void 0 : hubLTemplateData.objects.filter(
|
|
4973
5008
|
(template) => isCodedFile(template.filename)
|
|
4974
5009
|
)) || [];
|
|
5010
|
+
const mappedHubLModules = normalizeHubLModules((hubLModuleData == null ? void 0 : hubLModuleData.objects) || []);
|
|
4975
5011
|
return {
|
|
4976
5012
|
authedPortalId,
|
|
5013
|
+
authedEnv,
|
|
4977
5014
|
projectName,
|
|
4978
|
-
modulesData:
|
|
4979
|
-
partialsData:
|
|
4980
|
-
hubLModules:
|
|
4981
|
-
hubLTemplates,
|
|
5015
|
+
modulesData: reactModules,
|
|
5016
|
+
partialsData: normalizePartialsData(partialsData),
|
|
5017
|
+
hubLModules: mappedHubLModules || [],
|
|
5018
|
+
hubLTemplates: normalizeTemplatesData(hubLTemplates),
|
|
4982
5019
|
themeWebRoot,
|
|
4983
5020
|
webRootProjectComponentFolder
|
|
4984
5021
|
};
|
|
4985
5022
|
}
|
|
4986
5023
|
var getDevServerUIData_default = getDevServerUIData;
|
|
4987
5024
|
|
|
5025
|
+
// src/routes/createAppServerRoutes.ts
|
|
5026
|
+
import { Router as Router3 } from "express";
|
|
5027
|
+
import { spawn } from "child_process";
|
|
5028
|
+
function getOpenCommand() {
|
|
5029
|
+
switch (process.platform) {
|
|
5030
|
+
case "darwin":
|
|
5031
|
+
return "open";
|
|
5032
|
+
case "win32":
|
|
5033
|
+
return "start";
|
|
5034
|
+
default:
|
|
5035
|
+
return "xdg-open";
|
|
5036
|
+
}
|
|
5037
|
+
}
|
|
5038
|
+
async function handleGetModulePages(req, res, next) {
|
|
5039
|
+
const { path: path16, portalId } = req.query;
|
|
5040
|
+
if (!path16 || !portalId) {
|
|
5041
|
+
return res.status(400).json({ error: "Missing required parameters" });
|
|
5042
|
+
}
|
|
5043
|
+
try {
|
|
5044
|
+
const data = await fetchModulePageDependencies(
|
|
5045
|
+
Number(portalId),
|
|
5046
|
+
path16
|
|
5047
|
+
);
|
|
5048
|
+
res.json(data);
|
|
5049
|
+
} catch (err) {
|
|
5050
|
+
next(err);
|
|
5051
|
+
}
|
|
5052
|
+
}
|
|
5053
|
+
function handleOpenFile(req, res, next) {
|
|
5054
|
+
const { path: path16 } = req.query;
|
|
5055
|
+
if (!path16) {
|
|
5056
|
+
return res.status(400).json({ error: "Missing required parameters" });
|
|
5057
|
+
}
|
|
5058
|
+
try {
|
|
5059
|
+
const command = getOpenCommand();
|
|
5060
|
+
spawn(command, [path16], { detached: true }).unref();
|
|
5061
|
+
res.sendStatus(200);
|
|
5062
|
+
} catch (err) {
|
|
5063
|
+
next(err);
|
|
5064
|
+
}
|
|
5065
|
+
}
|
|
5066
|
+
function createAppServerRoutes() {
|
|
5067
|
+
const router = Router3();
|
|
5068
|
+
router.get("/module-pages", handleGetModulePages);
|
|
5069
|
+
router.get("/open-file", handleOpenFile);
|
|
5070
|
+
return router;
|
|
5071
|
+
}
|
|
5072
|
+
|
|
4988
5073
|
// src/createAppServer.ts
|
|
4989
5074
|
async function createAppServer(webRoot2, reqLocals, port) {
|
|
4990
5075
|
const app = express2();
|
|
@@ -5034,23 +5119,9 @@ async function createAppServer(webRoot2, reqLocals, port) {
|
|
|
5034
5119
|
envPrefix: "HS_"
|
|
5035
5120
|
};
|
|
5036
5121
|
const viteServer = await createViteServer2(viteConfig);
|
|
5122
|
+
app.use("/api", createAppServerRoutes());
|
|
5037
5123
|
app.use(viteServer.middlewares);
|
|
5038
|
-
app.get("
|
|
5039
|
-
const { path: path16, portalId } = req.query;
|
|
5040
|
-
if (!path16 || !portalId) {
|
|
5041
|
-
return res.status(400).json({ error: "Missing required parameters" });
|
|
5042
|
-
}
|
|
5043
|
-
try {
|
|
5044
|
-
const data = await fetchModulePageDependencies(
|
|
5045
|
-
Number(portalId),
|
|
5046
|
-
path16
|
|
5047
|
-
);
|
|
5048
|
-
res.json(data);
|
|
5049
|
-
} catch (err) {
|
|
5050
|
-
next(err);
|
|
5051
|
-
}
|
|
5052
|
-
});
|
|
5053
|
-
app.use("*", async (req, res) => {
|
|
5124
|
+
app.get("/*", async (req, res) => {
|
|
5054
5125
|
try {
|
|
5055
5126
|
const initialProps = await getDevServerUIData_default({
|
|
5056
5127
|
...reqLocals,
|
|
@@ -5076,7 +5147,7 @@ async function createAppServer(webRoot2, reqLocals, port) {
|
|
|
5076
5147
|
res.status(500).end(e.stack);
|
|
5077
5148
|
}
|
|
5078
5149
|
});
|
|
5079
|
-
app.use((err, req, res,
|
|
5150
|
+
app.use((err, req, res, __next) => {
|
|
5080
5151
|
console.error("API Error:", err);
|
|
5081
5152
|
res.status(500).json({ error: "Internal server error" });
|
|
5082
5153
|
});
|
|
@@ -5922,7 +5993,7 @@ HubSpot CMS dev server hosting: ${projectName}/${expressServer.locals.projectCom
|
|
|
5922
5993
|
const packageRoot = path15.dirname(url2.fileURLToPath(import.meta.url));
|
|
5923
5994
|
const configPath = path15.resolve(packageRoot, "./storybook-main");
|
|
5924
5995
|
sendTrackingRequest("start-storybook");
|
|
5925
|
-
const storybookProcess =
|
|
5996
|
+
const storybookProcess = spawn2(
|
|
5926
5997
|
"sb",
|
|
5927
5998
|
[
|
|
5928
5999
|
"dev",
|
package/dist/storybook/index.js
CHANGED