@hubspot/cms-dev-server 0.18.27 → 0.18.29

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 CHANGED
@@ -1465,7 +1465,7 @@ function trackUsage(action) {
1465
1465
  eventName: EVENT_NAME,
1466
1466
  action,
1467
1467
  nodeVersion: getNodeVersionData(),
1468
- version: "0.18.27",
1468
+ version: "0.18.29",
1469
1469
  os: getPlatform()
1470
1470
  };
1471
1471
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -4011,11 +4011,44 @@ function buildTemplateIndex() {
4011
4011
  }
4012
4012
 
4013
4013
  // src/routes/createDevServerRoutes.ts
4014
- import fs3 from "node:fs/promises";
4014
+ import fs4 from "node:fs/promises";
4015
4015
 
4016
4016
  // src/lib/getDevServerUIData.ts
4017
4017
  import path11 from "path";
4018
4018
  import { normalizePath as normalizePath8 } from "vite";
4019
+
4020
+ // src/api/project.ts
4021
+ import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
4022
+ var DEVELOPER_PROJECTS_API_PATH = "/developer/projects/v1";
4023
+ async function fetchProjectByName(accountId, projectName) {
4024
+ return (await hsCliHttp11.get(accountId, {
4025
+ url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${projectName}`
4026
+ })).data;
4027
+ }
4028
+
4029
+ // src/lib/getDevServerUIData.ts
4030
+ import fs3 from "node:fs";
4031
+ var templateTypeMap = {
4032
+ // Standard templates
4033
+ 4: "Landing Page",
4034
+ 2: "Email",
4035
+ 42: "Blog Listing",
4036
+ 41: "Blog Post",
4037
+ 6: "Blog (Deprecated)",
4038
+ // Global partials
4039
+ 38: "Global Partial",
4040
+ 18: "Global Group",
4041
+ // System templates
4042
+ 11: "Error Page",
4043
+ 19: "Password Prompt",
4044
+ 29: "Membership Login",
4045
+ 30: "Membership Register",
4046
+ 31: "Membership Reset",
4047
+ 32: "Membership Reset Request",
4048
+ 12: "Subscription Preferences",
4049
+ 14: "Backup Unsubscribe",
4050
+ 27: "Search Results"
4051
+ };
4019
4052
  function mapReactModules(modules, themeWebRoot, viteServer) {
4020
4053
  return Promise.all(
4021
4054
  modules.moduleNames.map(async (name, index) => {
@@ -4050,11 +4083,28 @@ function normalizePartialsData(partialData) {
4050
4083
  }));
4051
4084
  }
4052
4085
  function normalizeTemplatesData(templates) {
4053
- return templates.map((template) => ({
4086
+ return templates.filter((template) => template.templateType in templateTypeMap).map((template) => ({
4054
4087
  name: template.displayName || template.label,
4055
- subPath: `@projects/${template.path.split("/@projects/")[1] || template.path}`
4088
+ subPath: extractSubPath(template.path),
4089
+ templateTypeLabel: templateTypeMap[template.templateType]
4056
4090
  }));
4057
4091
  }
4092
+ function extractSubPath(componentPath) {
4093
+ var _a;
4094
+ const projectPrefix = "@projects/";
4095
+ if (!componentPath) {
4096
+ return projectPrefix;
4097
+ }
4098
+ const projectPath = (_a = componentPath.split(projectPrefix)) == null ? void 0 : _a[1];
4099
+ return `${projectPrefix}${projectPath || componentPath}`;
4100
+ }
4101
+ function detectPackageManager(projectRoot) {
4102
+ if (fs3.existsSync(path11.join(projectRoot, "yarn.lock")))
4103
+ return "yarn";
4104
+ if (fs3.existsSync(path11.join(projectRoot, "pnpm-lock.yaml")))
4105
+ return "pnpm";
4106
+ return "npm";
4107
+ }
4058
4108
  async function getDevServerUIData(reqLocals, viteServer) {
4059
4109
  const {
4060
4110
  themeWebRoot,
@@ -4062,8 +4112,19 @@ async function getDevServerUIData(reqLocals, viteServer) {
4062
4112
  authedPortalId,
4063
4113
  projectName,
4064
4114
  localPreviewToken,
4065
- webRootProjectComponentFolder
4115
+ webRootProjectComponentFolder,
4116
+ sslEnabled
4066
4117
  } = reqLocals;
4118
+ const packageJson = getPackageJson(themeWebRoot);
4119
+ const packageManager = detectPackageManager(themeWebRoot);
4120
+ const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager} run`;
4121
+ const cliCommands = Object.entries((packageJson == null ? void 0 : packageJson.scripts) || {}).map(
4122
+ ([scriptName, description]) => ({
4123
+ scriptName,
4124
+ description,
4125
+ runCommand: `${runCommand} ${scriptName}`
4126
+ })
4127
+ );
4067
4128
  const modulesData = findAllModulesInRoot(themeWebRoot);
4068
4129
  const partialsData = findAllPartialsInRoot(themeWebRoot);
4069
4130
  const reactModules = await mapReactModules(
@@ -4073,15 +4134,16 @@ async function getDevServerUIData(reqLocals, viteServer) {
4073
4134
  );
4074
4135
  let hubLModuleData = { objects: [] };
4075
4136
  let hubLTemplateData = { objects: [] };
4137
+ let projectData = null;
4076
4138
  if (authedPortalId) {
4077
- [hubLModuleData, hubLTemplateData] = await Promise.all([
4139
+ [hubLModuleData, hubLTemplateData, projectData] = await Promise.all([
4078
4140
  fetchHubLModules(authedPortalId, localPreviewToken),
4079
- fetchPreviewTemplates(authedPortalId, localPreviewToken)
4141
+ fetchPreviewTemplates(authedPortalId, localPreviewToken),
4142
+ fetchProjectByName(authedPortalId, projectName).catch(() => {
4143
+ return null;
4144
+ })
4080
4145
  ]);
4081
4146
  }
4082
- const hubLTemplates = (hubLTemplateData == null ? void 0 : hubLTemplateData.objects.filter(
4083
- (template) => isCodedFile(template.filename)
4084
- )) || [];
4085
4147
  const mappedHubLModules = normalizeHubLModules((hubLModuleData == null ? void 0 : hubLModuleData.objects) || []);
4086
4148
  return {
4087
4149
  authedPortalId,
@@ -4090,9 +4152,12 @@ async function getDevServerUIData(reqLocals, viteServer) {
4090
4152
  modulesData: reactModules,
4091
4153
  partialsData: normalizePartialsData(partialsData),
4092
4154
  hubLModules: mappedHubLModules || [],
4093
- hubLTemplates: normalizeTemplatesData(hubLTemplates),
4155
+ hubLTemplates: normalizeTemplatesData((hubLTemplateData == null ? void 0 : hubLTemplateData.objects) || []),
4094
4156
  themeWebRoot,
4095
- webRootProjectComponentFolder
4157
+ webRootProjectComponentFolder,
4158
+ cliCommands,
4159
+ sslEnabled,
4160
+ projectData
4096
4161
  };
4097
4162
  }
4098
4163
  var getDevServerUIData_default = getDevServerUIData;
@@ -4192,7 +4257,7 @@ var createDevServerRoutes = async (viteServer, storybookPort, appServerConfig) =
4192
4257
  const templatePath = path12.join(appWebRoot, "index.html");
4193
4258
  const serverEntryPath = isProd ? path12.join(appWebRoot, "server/serverEntry.js") : path12.join(appWebRoot, "serverEntry.tsx");
4194
4259
  let render;
4195
- let template = await fs3.readFile(path12.join(templatePath), "utf-8");
4260
+ let template = await fs4.readFile(path12.join(templatePath), "utf-8");
4196
4261
  if (isProd) {
4197
4262
  const { render: ssrRender } = await import(serverEntryPath);
4198
4263
  render = ssrRender;
@@ -4360,6 +4425,7 @@ import {
4360
4425
  createServer as createViteServer2
4361
4426
  } from "vite";
4362
4427
  import { default as react2 } from "@vitejs/plugin-react";
4428
+ import { default as mkcert2 } from "vite-plugin-mkcert";
4363
4429
  async function createAppServer(appWebRoot, port, sslEnabled) {
4364
4430
  const origin = process.env.VITE_ORIGIN ?? (sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`);
4365
4431
  const viteConfig = {
@@ -4368,7 +4434,8 @@ async function createAppServer(appWebRoot, port, sslEnabled) {
4368
4434
  host: "hslocal.net",
4369
4435
  origin,
4370
4436
  hmr: {
4371
- protocol: sslEnabled ? "wss" : void 0
4437
+ protocol: sslEnabled ? "wss" : "ws",
4438
+ port: port + 1
4372
4439
  }
4373
4440
  },
4374
4441
  appType: "custom",
@@ -4397,7 +4464,8 @@ async function createAppServer(appWebRoot, port, sslEnabled) {
4397
4464
  }
4398
4465
  }),
4399
4466
  clientIslandEntryPlugin(),
4400
- resolveIslandPlugin()
4467
+ resolveIslandPlugin(),
4468
+ sslEnabled ? mkcert2() : null
4401
4469
  ],
4402
4470
  css: {
4403
4471
  postcss: appWebRoot
@@ -4487,7 +4555,7 @@ import {
4487
4555
  import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
4488
4556
 
4489
4557
  // src/proxyPage/fetchDomains.ts
4490
- import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
4558
+ import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
4491
4559
 
4492
4560
  // src/lib/errors.ts
4493
4561
  var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
@@ -4545,7 +4613,7 @@ function handleSecretsError(error) {
4545
4613
  // src/proxyPage/fetchDomains.ts
4546
4614
  async function fetchDomains(portalId) {
4547
4615
  try {
4548
- const result = (await hsCliHttp11.get(portalId, {
4616
+ const result = (await hsCliHttp12.get(portalId, {
4549
4617
  url: `/cms/v3/domains`,
4550
4618
  params: { portalId },
4551
4619
  responseType: "json"
@@ -4569,12 +4637,12 @@ async function fetchWebsiteDomainNames(portalId) {
4569
4637
 
4570
4638
  // src/lib/validateHSPlatform.ts
4571
4639
  import path13 from "path";
4572
- import fs4 from "fs";
4640
+ import fs5 from "fs";
4573
4641
  import select from "@inquirer/select";
4574
- import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
4642
+ import { http as hsCliHttp13 } from "@hubspot/local-dev-lib/http";
4575
4643
  var HSPROJECT_JSON = "hsproject.json";
4576
4644
  function checkFileExists(filePath) {
4577
- return fs4.existsSync(filePath) && fs4.statSync(filePath).isFile();
4645
+ return fs5.existsSync(filePath) && fs5.statSync(filePath).isFile();
4578
4646
  }
4579
4647
  function findHSProjectJson(startPath) {
4580
4648
  let currentDir = startPath;
@@ -4600,12 +4668,12 @@ async function validateHSPlatform(projectConfigPath, portalId) {
4600
4668
  );
4601
4669
  return false;
4602
4670
  }
4603
- const hsProjectJSONContents = fs4.readFileSync(projectConfigPath, "utf8");
4671
+ const hsProjectJSONContents = fs5.readFileSync(projectConfigPath, "utf8");
4604
4672
  const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
4605
4673
  const { platformVersion } = hsProjectJSONData;
4606
4674
  let platformVersionResult;
4607
4675
  try {
4608
- platformVersionResult = (await hsCliHttp12.get(portalId, {
4676
+ platformVersionResult = (await hsCliHttp13.get(portalId, {
4609
4677
  url: `developer/projects/v1/platformVersion`,
4610
4678
  responseType: "json"
4611
4679
  })).data;
@@ -4628,7 +4696,7 @@ async function validateHSPlatform(projectConfigPath, portalId) {
4628
4696
  });
4629
4697
  hsProjectJSONData.platformVersion = answer;
4630
4698
  try {
4631
- fs4.writeFileSync(
4699
+ fs5.writeFileSync(
4632
4700
  projectConfigPath,
4633
4701
  JSON.stringify(hsProjectJSONData, void 0, 2),
4634
4702
  "utf8"
@@ -4645,7 +4713,7 @@ async function validateHSPlatform(projectConfigPath, portalId) {
4645
4713
  }
4646
4714
 
4647
4715
  // src/createDevServer.ts
4648
- import { http as hsCliHttp13 } from "@hubspot/local-dev-lib/http";
4716
+ import { http as hsCliHttp14 } from "@hubspot/local-dev-lib/http";
4649
4717
 
4650
4718
  // ../cms-js-internal/dist/buildFieldsTypes.js
4651
4719
  import { writeFileSync } from "fs";
@@ -4890,7 +4958,7 @@ function writeFieldsType(fields, fileName, typeName) {
4890
4958
  }
4891
4959
 
4892
4960
  // src/lib/watchFieldsUpdates.ts
4893
- import fs5 from "fs";
4961
+ import fs6 from "fs";
4894
4962
  import path14 from "path";
4895
4963
  import readline from "readline";
4896
4964
  var lastSerializedFieldsCache = {};
@@ -4912,9 +4980,9 @@ var isInModulesFolder = (filePath, projectRoot) => {
4912
4980
  };
4913
4981
  };
4914
4982
  var fileContainsAutoGenComment = async (filePath) => {
4915
- if (!fs5.existsSync(filePath))
4983
+ if (!fs6.existsSync(filePath))
4916
4984
  return true;
4917
- const stream2 = fs5.createReadStream(filePath);
4985
+ const stream2 = fs6.createReadStream(filePath);
4918
4986
  const reader = readline.createInterface({ input: stream2 });
4919
4987
  const firstLine = await new Promise(
4920
4988
  (resolve2) => reader.once("line", (line) => resolve2(line.trim()))
@@ -4933,7 +5001,7 @@ var getIndexFile = (filePath, projectRoot) => {
4933
5001
  if (isRootModuleFile)
4934
5002
  return { indexFilePath: filePath, isRootModuleFile };
4935
5003
  const dir = path14.dirname(filePath);
4936
- const files = fs5.readdirSync(dir);
5004
+ const files = fs6.readdirSync(dir);
4937
5005
  const indexFileName = files.find((file) => file.startsWith("index."));
4938
5006
  return indexFileName ? { indexFilePath: path14.join(dir, indexFileName), isRootModuleFile } : void 0;
4939
5007
  };
@@ -5125,7 +5193,7 @@ Local proxy functionality and module preview routes will not work without settin
5125
5193
  }
5126
5194
  let authedHublet;
5127
5195
  try {
5128
- const accountInformation = (await hsCliHttp13.get(authedPortalId, {
5196
+ const accountInformation = (await hsCliHttp14.get(authedPortalId, {
5129
5197
  url: "/account-info/v3/details"
5130
5198
  })).data;
5131
5199
  authedHublet = accountInformation.dataHostingLocation;
@@ -5186,10 +5254,8 @@ Local proxy functionality and module preview routes will not work without settin
5186
5254
  expressServer.use(bodyParser.json());
5187
5255
  let appServerConfig = null;
5188
5256
  if (showUI) {
5189
- const appWebRoot = path15.join(
5190
- path15.dirname(url2.fileURLToPath(import.meta.url)),
5191
- "../app"
5192
- );
5257
+ const __dirname2 = path15.dirname(url2.fileURLToPath(import.meta.url));
5258
+ const appWebRoot = normalizePath9(path15.resolve(__dirname2, "../app"));
5193
5259
  const reqLocals = {
5194
5260
  themeWebRoot: absoluteWebRoot,
5195
5261
  authedPortalId,
@@ -5197,7 +5263,8 @@ Local proxy functionality and module preview routes will not work without settin
5197
5263
  authedHublet,
5198
5264
  projectName,
5199
5265
  webRootProjectComponentFolder,
5200
- localPreviewToken: _localPreviewToken
5266
+ localPreviewToken: _localPreviewToken,
5267
+ sslEnabled: sslEnabledOption
5201
5268
  };
5202
5269
  const appServer = await createAppServer_default(
5203
5270
  appWebRoot,