@hubspot/cms-dev-server 0.18.28 → 1.0.0
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/app/assets/index-BDlX5eip.js +154 -0
- package/dist/app/assets/index-C0KdU9bk.css +1 -0
- package/dist/app/index.html +2 -2
- package/dist/app/server/serverEntry.js +189 -119
- package/dist/index.js +160 -98
- package/dist/run.js +270 -212
- package/package.json +3 -3
- package/types/api/designmanager.d.ts +1 -0
- package/types/api/project.d.ts +5 -0
- package/types/constants/errors.d.ts +5 -0
- package/types/createAppViteConfig.d.ts +2 -0
- package/types/createDevServer.d.ts +1 -1
- package/types/lib/cli.d.ts +22 -0
- package/types/lib/cliUtils.d.ts +14 -0
- package/types/lib/constants.d.ts +1 -0
- package/types/lib/getDevServerUIData.d.ts +11 -0
- package/types/routes/api.d.ts +2 -0
- package/types/routes/appServerRoutes.d.ts +5 -0
- package/types/storybook-main/preview.d.ts +9 -0
- package/dist/app/assets/index-BivIDhYl.css +0 -1
- package/dist/app/assets/index-C5FZod7r.js +0 -154
- package/types/lib/renderModuleJson.d.ts +0 -4
package/dist/run.js
CHANGED
|
@@ -675,7 +675,6 @@ function getDevServerCommandLineOptions(argv) {
|
|
|
675
675
|
const storybook2 = args.findIndex((arg) => arg === "--storybook") > 0;
|
|
676
676
|
const fieldGenEnabledOption2 = args.includes("--generateFieldsTypes");
|
|
677
677
|
const resetSession2 = args.includes("--resetSession");
|
|
678
|
-
const showUI2 = args.includes("--showUI");
|
|
679
678
|
return {
|
|
680
679
|
hubspotCliConfigPathOption: hubspotCliConfigPathOption2,
|
|
681
680
|
hubspotCliAccountNameOption: hubspotCliAccountNameOption2,
|
|
@@ -683,7 +682,6 @@ function getDevServerCommandLineOptions(argv) {
|
|
|
683
682
|
storybook: storybook2,
|
|
684
683
|
fieldGenEnabledOption: fieldGenEnabledOption2,
|
|
685
684
|
webRoot: webRoot2,
|
|
686
|
-
showUI: showUI2,
|
|
687
685
|
resetSession: resetSession2
|
|
688
686
|
};
|
|
689
687
|
}
|
|
@@ -2097,7 +2095,7 @@ function trackUsage(action) {
|
|
|
2097
2095
|
eventName: EVENT_NAME,
|
|
2098
2096
|
action,
|
|
2099
2097
|
nodeVersion: getNodeVersionData(),
|
|
2100
|
-
version: "0.
|
|
2098
|
+
version: "1.0.0",
|
|
2101
2099
|
os: getPlatform()
|
|
2102
2100
|
};
|
|
2103
2101
|
const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -4177,7 +4175,7 @@ var homeRouteHandler = async (request2, response, next) => {
|
|
|
4177
4175
|
next();
|
|
4178
4176
|
return;
|
|
4179
4177
|
}
|
|
4180
|
-
sendTrackingRequest("view-home-route");
|
|
4178
|
+
sendTrackingRequest("view-legacy-home-route");
|
|
4181
4179
|
const {
|
|
4182
4180
|
authedPortalId,
|
|
4183
4181
|
webRoot: webRoot2,
|
|
@@ -4643,11 +4641,152 @@ function buildTemplateIndex() {
|
|
|
4643
4641
|
}
|
|
4644
4642
|
|
|
4645
4643
|
// src/routes/createDevServerRoutes.ts
|
|
4646
|
-
import
|
|
4644
|
+
import fs5 from "node:fs/promises";
|
|
4647
4645
|
|
|
4648
4646
|
// src/lib/getDevServerUIData.ts
|
|
4649
4647
|
import path12 from "path";
|
|
4650
4648
|
import { normalizePath as normalizePath8 } from "vite";
|
|
4649
|
+
|
|
4650
|
+
// src/api/project.ts
|
|
4651
|
+
import { http as hsCliHttp11 } from "@hubspot/local-dev-lib/http";
|
|
4652
|
+
var DEVELOPER_PROJECTS_API_PATH = "/developer/projects/v1";
|
|
4653
|
+
async function fetchProjectByName(accountId, projectName) {
|
|
4654
|
+
return (await hsCliHttp11.get(accountId, {
|
|
4655
|
+
url: `${DEVELOPER_PROJECTS_API_PATH}/by-name/${projectName}`
|
|
4656
|
+
})).data;
|
|
4657
|
+
}
|
|
4658
|
+
|
|
4659
|
+
// src/createViteDevServer.ts
|
|
4660
|
+
import { createServer as createViteServer } from "vite";
|
|
4661
|
+
import { default as react } from "@vitejs/plugin-react";
|
|
4662
|
+
import { default as mkcert } from "vite-plugin-mkcert";
|
|
4663
|
+
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
|
|
4664
|
+
|
|
4665
|
+
// src/plugins/devSecretsPlugin.ts
|
|
4666
|
+
function devSecretsPlugin(secretNames = []) {
|
|
4667
|
+
return {
|
|
4668
|
+
name: "dev-secrets",
|
|
4669
|
+
config: () => {
|
|
4670
|
+
return {
|
|
4671
|
+
define: {
|
|
4672
|
+
"import.meta.env.secretNames": secretNames
|
|
4673
|
+
}
|
|
4674
|
+
};
|
|
4675
|
+
}
|
|
4676
|
+
};
|
|
4677
|
+
}
|
|
4678
|
+
|
|
4679
|
+
// src/createViteDevServer.ts
|
|
4680
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
4681
|
+
import { join as join4 } from "path";
|
|
4682
|
+
function getPackageJson(packagePath2) {
|
|
4683
|
+
return JSON.parse(readFileSync3(join4(packagePath2, "package.json")).toString());
|
|
4684
|
+
}
|
|
4685
|
+
function getDepsForPackage(packagePath2) {
|
|
4686
|
+
const packageJson = getPackageJson(packagePath2);
|
|
4687
|
+
return packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
|
|
4688
|
+
}
|
|
4689
|
+
function getDepsForPackageIfExists(packagePath2) {
|
|
4690
|
+
try {
|
|
4691
|
+
return getDepsForPackage(packagePath2);
|
|
4692
|
+
} catch (e) {
|
|
4693
|
+
console.log("No package.json at ", packagePath2);
|
|
4694
|
+
return [];
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], jsRenderingGates, secretNames) {
|
|
4698
|
+
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
4699
|
+
`${proxyDomain}.localhost`,
|
|
4700
|
+
`${proxyDomain}.hslocal.net`
|
|
4701
|
+
]).flat();
|
|
4702
|
+
if (process.env.VITE_ORIGIN) {
|
|
4703
|
+
console.log(`
|
|
4704
|
+
Custom origin: ${process.env.VITE_ORIGIN}
|
|
4705
|
+
`);
|
|
4706
|
+
}
|
|
4707
|
+
const origin = process.env.VITE_ORIGIN ?? (sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`);
|
|
4708
|
+
const consumerDeps = getDepsForPackageIfExists(webRoot2);
|
|
4709
|
+
const isProjectWithReact = consumerDeps.includes("@hubspot/cms-components");
|
|
4710
|
+
const ssrAndOptimizeDep = isProjectWithReact ? {
|
|
4711
|
+
ssr: {
|
|
4712
|
+
// TODO: might need more entries here to get things to resolve through
|
|
4713
|
+
// resolveWebRootDepsPlugin
|
|
4714
|
+
noExternal: "@hubspot/cms-components"
|
|
4715
|
+
},
|
|
4716
|
+
resolve: {
|
|
4717
|
+
conditions: ["server"],
|
|
4718
|
+
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
|
|
4719
|
+
},
|
|
4720
|
+
optimizeDeps: {
|
|
4721
|
+
include: ["react", "react-dom", "react-dom/client"]
|
|
4722
|
+
}
|
|
4723
|
+
} : {};
|
|
4724
|
+
const reactAndIslandsPlugins = isProjectWithReact || process.env.VITEST ? [
|
|
4725
|
+
react({
|
|
4726
|
+
babel: {
|
|
4727
|
+
plugins: [
|
|
4728
|
+
"babel-plugin-styled-components",
|
|
4729
|
+
"styled-jsx/babel",
|
|
4730
|
+
"macros"
|
|
4731
|
+
]
|
|
4732
|
+
}
|
|
4733
|
+
}),
|
|
4734
|
+
clientIslandEntryPlugin(),
|
|
4735
|
+
resolveIslandPlugin(),
|
|
4736
|
+
jsRenderingGates.includes("CMS:JSRenderer:RemoveCjsPlugin") ? null : viteCommonjs(),
|
|
4737
|
+
devSecretsPlugin(secretNames),
|
|
4738
|
+
noncePlaceholderPlugin()
|
|
4739
|
+
] : [];
|
|
4740
|
+
const viteConfig = {
|
|
4741
|
+
appType: "custom",
|
|
4742
|
+
server: {
|
|
4743
|
+
middlewareMode: true,
|
|
4744
|
+
host: "hslocal.net",
|
|
4745
|
+
origin,
|
|
4746
|
+
hmr: {
|
|
4747
|
+
protocol: sslEnabled ? "wss" : void 0
|
|
4748
|
+
}
|
|
4749
|
+
},
|
|
4750
|
+
root: webRoot2,
|
|
4751
|
+
...ssrAndOptimizeDep,
|
|
4752
|
+
plugins: [
|
|
4753
|
+
jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
|
|
4754
|
+
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
4755
|
+
...reactAndIslandsPlugins
|
|
4756
|
+
],
|
|
4757
|
+
css: {
|
|
4758
|
+
postcss: webRoot2
|
|
4759
|
+
},
|
|
4760
|
+
envDir: webRoot2,
|
|
4761
|
+
envPrefix: "HS_"
|
|
4762
|
+
};
|
|
4763
|
+
return createViteServer(viteConfig);
|
|
4764
|
+
}
|
|
4765
|
+
var createViteDevServer_default = createViteDevServer;
|
|
4766
|
+
|
|
4767
|
+
// src/lib/getDevServerUIData.ts
|
|
4768
|
+
import fs4 from "node:fs";
|
|
4769
|
+
var templateTypeMap = {
|
|
4770
|
+
// Standard templates
|
|
4771
|
+
4: "Landing Page",
|
|
4772
|
+
2: "Email",
|
|
4773
|
+
42: "Blog Listing",
|
|
4774
|
+
41: "Blog Post",
|
|
4775
|
+
6: "Blog (Deprecated)",
|
|
4776
|
+
// Global partials
|
|
4777
|
+
38: "Global Partial",
|
|
4778
|
+
18: "Global Group",
|
|
4779
|
+
// System templates
|
|
4780
|
+
11: "Error Page",
|
|
4781
|
+
19: "Password Prompt",
|
|
4782
|
+
29: "Membership Login",
|
|
4783
|
+
30: "Membership Register",
|
|
4784
|
+
31: "Membership Reset",
|
|
4785
|
+
32: "Membership Reset Request",
|
|
4786
|
+
12: "Subscription Preferences",
|
|
4787
|
+
14: "Backup Unsubscribe",
|
|
4788
|
+
27: "Search Results"
|
|
4789
|
+
};
|
|
4651
4790
|
function mapReactModules(modules, themeWebRoot, viteServer) {
|
|
4652
4791
|
return Promise.all(
|
|
4653
4792
|
modules.moduleNames.map(async (name, index) => {
|
|
@@ -4682,11 +4821,28 @@ function normalizePartialsData(partialData) {
|
|
|
4682
4821
|
}));
|
|
4683
4822
|
}
|
|
4684
4823
|
function normalizeTemplatesData(templates) {
|
|
4685
|
-
return templates.map((template) => ({
|
|
4824
|
+
return templates.filter((template) => template.templateType in templateTypeMap).map((template) => ({
|
|
4686
4825
|
name: template.displayName || template.label,
|
|
4687
|
-
subPath:
|
|
4826
|
+
subPath: extractSubPath(template.path),
|
|
4827
|
+
templateTypeLabel: templateTypeMap[template.templateType]
|
|
4688
4828
|
}));
|
|
4689
4829
|
}
|
|
4830
|
+
function extractSubPath(componentPath) {
|
|
4831
|
+
var _a;
|
|
4832
|
+
const projectPrefix = "@projects/";
|
|
4833
|
+
if (!componentPath) {
|
|
4834
|
+
return projectPrefix;
|
|
4835
|
+
}
|
|
4836
|
+
const projectPath = (_a = componentPath.split(projectPrefix)) == null ? void 0 : _a[1];
|
|
4837
|
+
return `${projectPrefix}${projectPath || componentPath}`;
|
|
4838
|
+
}
|
|
4839
|
+
function detectPackageManager(projectRoot) {
|
|
4840
|
+
if (fs4.existsSync(path12.join(projectRoot, "yarn.lock")))
|
|
4841
|
+
return "yarn";
|
|
4842
|
+
if (fs4.existsSync(path12.join(projectRoot, "pnpm-lock.yaml")))
|
|
4843
|
+
return "pnpm";
|
|
4844
|
+
return "npm";
|
|
4845
|
+
}
|
|
4690
4846
|
async function getDevServerUIData(reqLocals, viteServer) {
|
|
4691
4847
|
const {
|
|
4692
4848
|
themeWebRoot,
|
|
@@ -4694,8 +4850,19 @@ async function getDevServerUIData(reqLocals, viteServer) {
|
|
|
4694
4850
|
authedPortalId,
|
|
4695
4851
|
projectName,
|
|
4696
4852
|
localPreviewToken,
|
|
4697
|
-
webRootProjectComponentFolder
|
|
4853
|
+
webRootProjectComponentFolder,
|
|
4854
|
+
sslEnabled
|
|
4698
4855
|
} = reqLocals;
|
|
4856
|
+
const packageJson = getPackageJson(themeWebRoot);
|
|
4857
|
+
const packageManager = detectPackageManager(themeWebRoot);
|
|
4858
|
+
const runCommand = packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
4859
|
+
const cliCommands = Object.entries((packageJson == null ? void 0 : packageJson.scripts) || {}).map(
|
|
4860
|
+
([scriptName, description]) => ({
|
|
4861
|
+
scriptName,
|
|
4862
|
+
description,
|
|
4863
|
+
runCommand: `${runCommand} ${scriptName}`
|
|
4864
|
+
})
|
|
4865
|
+
);
|
|
4699
4866
|
const modulesData = findAllModulesInRoot(themeWebRoot);
|
|
4700
4867
|
const partialsData = findAllPartialsInRoot(themeWebRoot);
|
|
4701
4868
|
const reactModules = await mapReactModules(
|
|
@@ -4705,15 +4872,16 @@ async function getDevServerUIData(reqLocals, viteServer) {
|
|
|
4705
4872
|
);
|
|
4706
4873
|
let hubLModuleData = { objects: [] };
|
|
4707
4874
|
let hubLTemplateData = { objects: [] };
|
|
4875
|
+
let projectData = null;
|
|
4708
4876
|
if (authedPortalId) {
|
|
4709
|
-
[hubLModuleData, hubLTemplateData] = await Promise.all([
|
|
4877
|
+
[hubLModuleData, hubLTemplateData, projectData] = await Promise.all([
|
|
4710
4878
|
fetchHubLModules(authedPortalId, localPreviewToken),
|
|
4711
|
-
fetchPreviewTemplates(authedPortalId, localPreviewToken)
|
|
4879
|
+
fetchPreviewTemplates(authedPortalId, localPreviewToken),
|
|
4880
|
+
fetchProjectByName(authedPortalId, projectName).catch(() => {
|
|
4881
|
+
return null;
|
|
4882
|
+
})
|
|
4712
4883
|
]);
|
|
4713
4884
|
}
|
|
4714
|
-
const hubLTemplates = (hubLTemplateData == null ? void 0 : hubLTemplateData.objects.filter(
|
|
4715
|
-
(template) => isCodedFile(template.filename)
|
|
4716
|
-
)) || [];
|
|
4717
4885
|
const mappedHubLModules = normalizeHubLModules((hubLModuleData == null ? void 0 : hubLModuleData.objects) || []);
|
|
4718
4886
|
return {
|
|
4719
4887
|
authedPortalId,
|
|
@@ -4722,9 +4890,12 @@ async function getDevServerUIData(reqLocals, viteServer) {
|
|
|
4722
4890
|
modulesData: reactModules,
|
|
4723
4891
|
partialsData: normalizePartialsData(partialsData),
|
|
4724
4892
|
hubLModules: mappedHubLModules || [],
|
|
4725
|
-
hubLTemplates: normalizeTemplatesData(
|
|
4893
|
+
hubLTemplates: normalizeTemplatesData((hubLTemplateData == null ? void 0 : hubLTemplateData.objects) || []),
|
|
4726
4894
|
themeWebRoot,
|
|
4727
|
-
webRootProjectComponentFolder
|
|
4895
|
+
webRootProjectComponentFolder,
|
|
4896
|
+
cliCommands,
|
|
4897
|
+
sslEnabled,
|
|
4898
|
+
projectData
|
|
4728
4899
|
};
|
|
4729
4900
|
}
|
|
4730
4901
|
var getDevServerUIData_default = getDevServerUIData;
|
|
@@ -4748,6 +4919,7 @@ async function handleGetModulePages(req, res, next) {
|
|
|
4748
4919
|
return res.status(400).json({ error: "Missing required parameters" });
|
|
4749
4920
|
}
|
|
4750
4921
|
try {
|
|
4922
|
+
sendTrackingRequest("handle-module-dependencies");
|
|
4751
4923
|
const data = await fetchModulePageDependencies(
|
|
4752
4924
|
Number(portalId),
|
|
4753
4925
|
path17
|
|
@@ -4763,6 +4935,7 @@ function handleOpenFile(req, res, next) {
|
|
|
4763
4935
|
return res.status(400).json({ error: "Missing required parameters" });
|
|
4764
4936
|
}
|
|
4765
4937
|
try {
|
|
4938
|
+
sendTrackingRequest("handle-open-file");
|
|
4766
4939
|
const command = getOpenCommand();
|
|
4767
4940
|
spawn(command, [path17], { detached: true }).unref();
|
|
4768
4941
|
res.sendStatus(200);
|
|
@@ -4807,50 +4980,46 @@ var createDevServerRoutes = async (viteServer, storybookPort, appServerConfig) =
|
|
|
4807
4980
|
);
|
|
4808
4981
|
}
|
|
4809
4982
|
devServerApp.use(urlencoded());
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
devServerApp.use("/assets", expressStatic(distAssetsPath));
|
|
4815
|
-
} else {
|
|
4816
|
-
devServerApp.use(appServer.middlewares);
|
|
4817
|
-
}
|
|
4818
|
-
devServerApp.use(viteServer.middlewares);
|
|
4819
|
-
devServerApp.use("/api", createAppServerRoutes_default());
|
|
4820
|
-
devServerApp.get("/", async (req, res) => {
|
|
4821
|
-
try {
|
|
4822
|
-
const initialProps = await getDevServerUIData_default(reqLocals, viteServer);
|
|
4823
|
-
const url3 = req.originalUrl.replace("/", "");
|
|
4824
|
-
const templatePath = path13.join(appWebRoot, "index.html");
|
|
4825
|
-
const serverEntryPath = isProd ? path13.join(appWebRoot, "server/serverEntry.js") : path13.join(appWebRoot, "serverEntry.tsx");
|
|
4826
|
-
let render;
|
|
4827
|
-
let template = await fs4.readFile(path13.join(templatePath), "utf-8");
|
|
4828
|
-
if (isProd) {
|
|
4829
|
-
const { render: ssrRender } = await import(serverEntryPath);
|
|
4830
|
-
render = ssrRender;
|
|
4831
|
-
} else {
|
|
4832
|
-
template = await appServer.transformIndexHtml(url3, template);
|
|
4833
|
-
render = (await appServer.ssrLoadModule(serverEntryPath)).render;
|
|
4834
|
-
}
|
|
4835
|
-
const rendered = await render(initialProps);
|
|
4836
|
-
const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "").replace(
|
|
4837
|
-
`<!--app-script-->`,
|
|
4838
|
-
`<script>window.__hsInitialProps = ${JSON.stringify(
|
|
4839
|
-
initialProps
|
|
4840
|
-
)};</script>` ?? ""
|
|
4841
|
-
);
|
|
4842
|
-
res.status(200).set({ "Content-Type": "text/html" }).send(html);
|
|
4843
|
-
} catch (e) {
|
|
4844
|
-
appServer == null ? void 0 : appServer.ssrFixStacktrace(e);
|
|
4845
|
-
console.log(e.stack);
|
|
4846
|
-
res.status(500).end(e.stack);
|
|
4847
|
-
}
|
|
4848
|
-
});
|
|
4849
|
-
devServerApp.get("/legacy", homeRouteHandler_default);
|
|
4983
|
+
const appWebRoot = isProd ? path13.join(__dirname, "app") : appServerConfig == null ? void 0 : appServerConfig.appWebRoot;
|
|
4984
|
+
if (isProd) {
|
|
4985
|
+
const distAssetsPath = path13.join(appWebRoot, "assets");
|
|
4986
|
+
devServerApp.use("/assets", expressStatic(distAssetsPath));
|
|
4850
4987
|
} else {
|
|
4851
|
-
devServerApp.use(
|
|
4852
|
-
devServerApp.get("/", homeRouteHandler_default);
|
|
4988
|
+
devServerApp.use(appServer.middlewares);
|
|
4853
4989
|
}
|
|
4990
|
+
devServerApp.use(viteServer.middlewares);
|
|
4991
|
+
devServerApp.use("/api", createAppServerRoutes_default());
|
|
4992
|
+
devServerApp.get("/", async (req, res) => {
|
|
4993
|
+
try {
|
|
4994
|
+
sendTrackingRequest("view-index-route");
|
|
4995
|
+
const initialProps = await getDevServerUIData_default(reqLocals, viteServer);
|
|
4996
|
+
const url3 = req.originalUrl.replace("/", "");
|
|
4997
|
+
const templatePath = path13.join(appWebRoot, "index.html");
|
|
4998
|
+
const serverEntryPath = isProd ? path13.join(appWebRoot, "server/serverEntry.js") : path13.join(appWebRoot, "serverEntry.tsx");
|
|
4999
|
+
let render;
|
|
5000
|
+
let template = await fs5.readFile(path13.join(templatePath), "utf-8");
|
|
5001
|
+
if (isProd) {
|
|
5002
|
+
const { render: ssrRender } = await import(serverEntryPath);
|
|
5003
|
+
render = ssrRender;
|
|
5004
|
+
} else {
|
|
5005
|
+
template = await appServer.transformIndexHtml(url3, template);
|
|
5006
|
+
render = (await appServer.ssrLoadModule(serverEntryPath)).render;
|
|
5007
|
+
}
|
|
5008
|
+
const rendered = await render(initialProps);
|
|
5009
|
+
const html = template.replace(`<!--app-head-->`, rendered.head ?? "").replace(`<!--app-html-->`, rendered.html ?? "").replace(
|
|
5010
|
+
`<!--app-script-->`,
|
|
5011
|
+
`<script>window.__hsInitialProps = ${JSON.stringify(
|
|
5012
|
+
initialProps
|
|
5013
|
+
)};</script>` ?? ""
|
|
5014
|
+
);
|
|
5015
|
+
res.status(200).set({ "Content-Type": "text/html" }).send(html);
|
|
5016
|
+
} catch (e) {
|
|
5017
|
+
appServer == null ? void 0 : appServer.ssrFixStacktrace(e);
|
|
5018
|
+
console.log(e.stack);
|
|
5019
|
+
res.status(500).end(e.stack);
|
|
5020
|
+
}
|
|
5021
|
+
});
|
|
5022
|
+
devServerApp.get("/legacy", homeRouteHandler_default);
|
|
4854
5023
|
devServerApp.get("/proxy", proxyPathPageRouteHandler);
|
|
4855
5024
|
devServerApp.get("/partials/", linksToAllPartialsRouteHandler_default);
|
|
4856
5025
|
devServerApp.get("/partial/:partial", partial_default);
|
|
@@ -4987,119 +5156,12 @@ async function startShadowDevServer(devServerPort, shadowPort, themePath) {
|
|
|
4987
5156
|
);
|
|
4988
5157
|
}
|
|
4989
5158
|
|
|
4990
|
-
// src/createViteDevServer.ts
|
|
4991
|
-
import { createServer as createViteServer } from "vite";
|
|
4992
|
-
import { default as react } from "@vitejs/plugin-react";
|
|
4993
|
-
import { default as mkcert } from "vite-plugin-mkcert";
|
|
4994
|
-
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
|
|
4995
|
-
|
|
4996
|
-
// src/plugins/devSecretsPlugin.ts
|
|
4997
|
-
function devSecretsPlugin(secretNames = []) {
|
|
4998
|
-
return {
|
|
4999
|
-
name: "dev-secrets",
|
|
5000
|
-
config: () => {
|
|
5001
|
-
return {
|
|
5002
|
-
define: {
|
|
5003
|
-
"import.meta.env.secretNames": secretNames
|
|
5004
|
-
}
|
|
5005
|
-
};
|
|
5006
|
-
}
|
|
5007
|
-
};
|
|
5008
|
-
}
|
|
5009
|
-
|
|
5010
|
-
// src/createViteDevServer.ts
|
|
5011
|
-
import { readFileSync as readFileSync3 } from "fs";
|
|
5012
|
-
import { join as join4 } from "path";
|
|
5013
|
-
function getPackageJson(packagePath2) {
|
|
5014
|
-
return JSON.parse(readFileSync3(join4(packagePath2, "package.json")).toString());
|
|
5015
|
-
}
|
|
5016
|
-
function getDepsForPackage(packagePath2) {
|
|
5017
|
-
const packageJson = getPackageJson(packagePath2);
|
|
5018
|
-
return packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
|
|
5019
|
-
}
|
|
5020
|
-
function getDepsForPackageIfExists(packagePath2) {
|
|
5021
|
-
try {
|
|
5022
|
-
return getDepsForPackage(packagePath2);
|
|
5023
|
-
} catch (e) {
|
|
5024
|
-
console.log("No package.json at ", packagePath2);
|
|
5025
|
-
return [];
|
|
5026
|
-
}
|
|
5027
|
-
}
|
|
5028
|
-
async function createViteDevServer(webRoot2, port, sslEnabled, domainsToProxy = [], jsRenderingGates, secretNames) {
|
|
5029
|
-
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
5030
|
-
`${proxyDomain}.localhost`,
|
|
5031
|
-
`${proxyDomain}.hslocal.net`
|
|
5032
|
-
]).flat();
|
|
5033
|
-
if (process.env.VITE_ORIGIN) {
|
|
5034
|
-
console.log(`
|
|
5035
|
-
Custom origin: ${process.env.VITE_ORIGIN}
|
|
5036
|
-
`);
|
|
5037
|
-
}
|
|
5038
|
-
const origin = process.env.VITE_ORIGIN ?? (sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`);
|
|
5039
|
-
const consumerDeps = getDepsForPackageIfExists(webRoot2);
|
|
5040
|
-
const isProjectWithReact = consumerDeps.includes("@hubspot/cms-components");
|
|
5041
|
-
const ssrAndOptimizeDep = isProjectWithReact ? {
|
|
5042
|
-
ssr: {
|
|
5043
|
-
// TODO: might need more entries here to get things to resolve through
|
|
5044
|
-
// resolveWebRootDepsPlugin
|
|
5045
|
-
noExternal: "@hubspot/cms-components"
|
|
5046
|
-
},
|
|
5047
|
-
resolve: {
|
|
5048
|
-
conditions: ["server"],
|
|
5049
|
-
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
|
|
5050
|
-
},
|
|
5051
|
-
optimizeDeps: {
|
|
5052
|
-
include: ["react", "react-dom", "react-dom/client"]
|
|
5053
|
-
}
|
|
5054
|
-
} : {};
|
|
5055
|
-
const reactAndIslandsPlugins = isProjectWithReact || process.env.VITEST ? [
|
|
5056
|
-
react({
|
|
5057
|
-
babel: {
|
|
5058
|
-
plugins: [
|
|
5059
|
-
"babel-plugin-styled-components",
|
|
5060
|
-
"styled-jsx/babel",
|
|
5061
|
-
"macros"
|
|
5062
|
-
]
|
|
5063
|
-
}
|
|
5064
|
-
}),
|
|
5065
|
-
clientIslandEntryPlugin(),
|
|
5066
|
-
resolveIslandPlugin(),
|
|
5067
|
-
jsRenderingGates.includes("CMS:JSRenderer:RemoveCjsPlugin") ? null : viteCommonjs(),
|
|
5068
|
-
devSecretsPlugin(secretNames),
|
|
5069
|
-
noncePlaceholderPlugin()
|
|
5070
|
-
] : [];
|
|
5071
|
-
const viteConfig = {
|
|
5072
|
-
appType: "custom",
|
|
5073
|
-
server: {
|
|
5074
|
-
middlewareMode: true,
|
|
5075
|
-
host: "hslocal.net",
|
|
5076
|
-
origin,
|
|
5077
|
-
hmr: {
|
|
5078
|
-
protocol: sslEnabled ? "wss" : void 0
|
|
5079
|
-
}
|
|
5080
|
-
},
|
|
5081
|
-
root: webRoot2,
|
|
5082
|
-
...ssrAndOptimizeDep,
|
|
5083
|
-
plugins: [
|
|
5084
|
-
jsRenderingGates.includes("CMS:JSRenderer:AnalyzeCmsModules") ? findCmsModules() : null,
|
|
5085
|
-
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
5086
|
-
...reactAndIslandsPlugins
|
|
5087
|
-
],
|
|
5088
|
-
css: {
|
|
5089
|
-
postcss: webRoot2
|
|
5090
|
-
},
|
|
5091
|
-
envDir: webRoot2,
|
|
5092
|
-
envPrefix: "HS_"
|
|
5093
|
-
};
|
|
5094
|
-
return createViteServer(viteConfig);
|
|
5095
|
-
}
|
|
5096
|
-
var createViteDevServer_default = createViteDevServer;
|
|
5097
|
-
|
|
5098
5159
|
// src/createAppServer.ts
|
|
5099
5160
|
import {
|
|
5100
5161
|
createServer as createViteServer2
|
|
5101
5162
|
} from "vite";
|
|
5102
5163
|
import { default as react2 } from "@vitejs/plugin-react";
|
|
5164
|
+
import { default as mkcert2 } from "vite-plugin-mkcert";
|
|
5103
5165
|
async function createAppServer(appWebRoot, port, sslEnabled) {
|
|
5104
5166
|
const origin = process.env.VITE_ORIGIN ?? (sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`);
|
|
5105
5167
|
const viteConfig = {
|
|
@@ -5108,7 +5170,8 @@ async function createAppServer(appWebRoot, port, sslEnabled) {
|
|
|
5108
5170
|
host: "hslocal.net",
|
|
5109
5171
|
origin,
|
|
5110
5172
|
hmr: {
|
|
5111
|
-
protocol: sslEnabled ? "wss" :
|
|
5173
|
+
protocol: sslEnabled ? "wss" : "ws",
|
|
5174
|
+
port: port + 1
|
|
5112
5175
|
}
|
|
5113
5176
|
},
|
|
5114
5177
|
appType: "custom",
|
|
@@ -5137,7 +5200,8 @@ async function createAppServer(appWebRoot, port, sslEnabled) {
|
|
|
5137
5200
|
}
|
|
5138
5201
|
}),
|
|
5139
5202
|
clientIslandEntryPlugin(),
|
|
5140
|
-
resolveIslandPlugin()
|
|
5203
|
+
resolveIslandPlugin(),
|
|
5204
|
+
sslEnabled ? mkcert2() : null
|
|
5141
5205
|
],
|
|
5142
5206
|
css: {
|
|
5143
5207
|
postcss: appWebRoot
|
|
@@ -5227,7 +5291,7 @@ import {
|
|
|
5227
5291
|
import { fetchSecrets } from "@hubspot/local-dev-lib/api/secrets";
|
|
5228
5292
|
|
|
5229
5293
|
// src/proxyPage/fetchDomains.ts
|
|
5230
|
-
import { http as
|
|
5294
|
+
import { http as hsCliHttp12 } from "@hubspot/local-dev-lib/http";
|
|
5231
5295
|
|
|
5232
5296
|
// src/lib/errors.ts
|
|
5233
5297
|
var MISSING_SCOPE_ERROR_PREFIX = `Your personal access key is missing required scopes fetch domains.
|
|
@@ -5285,7 +5349,7 @@ function handleSecretsError(error) {
|
|
|
5285
5349
|
// src/proxyPage/fetchDomains.ts
|
|
5286
5350
|
async function fetchDomains(portalId) {
|
|
5287
5351
|
try {
|
|
5288
|
-
const result = (await
|
|
5352
|
+
const result = (await hsCliHttp12.get(portalId, {
|
|
5289
5353
|
url: `/cms/v3/domains`,
|
|
5290
5354
|
params: { portalId },
|
|
5291
5355
|
responseType: "json"
|
|
@@ -5309,12 +5373,12 @@ async function fetchWebsiteDomainNames(portalId) {
|
|
|
5309
5373
|
|
|
5310
5374
|
// src/lib/validateHSPlatform.ts
|
|
5311
5375
|
import path14 from "path";
|
|
5312
|
-
import
|
|
5376
|
+
import fs6 from "fs";
|
|
5313
5377
|
import select from "@inquirer/select";
|
|
5314
|
-
import { http as
|
|
5378
|
+
import { http as hsCliHttp13 } from "@hubspot/local-dev-lib/http";
|
|
5315
5379
|
var HSPROJECT_JSON = "hsproject.json";
|
|
5316
5380
|
function checkFileExists(filePath) {
|
|
5317
|
-
return
|
|
5381
|
+
return fs6.existsSync(filePath) && fs6.statSync(filePath).isFile();
|
|
5318
5382
|
}
|
|
5319
5383
|
function findHSProjectJson(startPath) {
|
|
5320
5384
|
let currentDir = startPath;
|
|
@@ -5340,12 +5404,12 @@ async function validateHSPlatform(projectConfigPath, portalId) {
|
|
|
5340
5404
|
);
|
|
5341
5405
|
return false;
|
|
5342
5406
|
}
|
|
5343
|
-
const hsProjectJSONContents =
|
|
5407
|
+
const hsProjectJSONContents = fs6.readFileSync(projectConfigPath, "utf8");
|
|
5344
5408
|
const hsProjectJSONData = JSON.parse(hsProjectJSONContents);
|
|
5345
5409
|
const { platformVersion } = hsProjectJSONData;
|
|
5346
5410
|
let platformVersionResult;
|
|
5347
5411
|
try {
|
|
5348
|
-
platformVersionResult = (await
|
|
5412
|
+
platformVersionResult = (await hsCliHttp13.get(portalId, {
|
|
5349
5413
|
url: `developer/projects/v1/platformVersion`,
|
|
5350
5414
|
responseType: "json"
|
|
5351
5415
|
})).data;
|
|
@@ -5368,7 +5432,7 @@ async function validateHSPlatform(projectConfigPath, portalId) {
|
|
|
5368
5432
|
});
|
|
5369
5433
|
hsProjectJSONData.platformVersion = answer;
|
|
5370
5434
|
try {
|
|
5371
|
-
|
|
5435
|
+
fs6.writeFileSync(
|
|
5372
5436
|
projectConfigPath,
|
|
5373
5437
|
JSON.stringify(hsProjectJSONData, void 0, 2),
|
|
5374
5438
|
"utf8"
|
|
@@ -5385,7 +5449,7 @@ async function validateHSPlatform(projectConfigPath, portalId) {
|
|
|
5385
5449
|
}
|
|
5386
5450
|
|
|
5387
5451
|
// src/createDevServer.ts
|
|
5388
|
-
import { http as
|
|
5452
|
+
import { http as hsCliHttp14 } from "@hubspot/local-dev-lib/http";
|
|
5389
5453
|
|
|
5390
5454
|
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
5391
5455
|
import { writeFileSync } from "fs";
|
|
@@ -5630,7 +5694,7 @@ function writeFieldsType(fields, fileName, typeName) {
|
|
|
5630
5694
|
}
|
|
5631
5695
|
|
|
5632
5696
|
// src/lib/watchFieldsUpdates.ts
|
|
5633
|
-
import
|
|
5697
|
+
import fs7 from "fs";
|
|
5634
5698
|
import path15 from "path";
|
|
5635
5699
|
import readline from "readline";
|
|
5636
5700
|
var lastSerializedFieldsCache = {};
|
|
@@ -5652,9 +5716,9 @@ var isInModulesFolder = (filePath, projectRoot) => {
|
|
|
5652
5716
|
};
|
|
5653
5717
|
};
|
|
5654
5718
|
var fileContainsAutoGenComment = async (filePath) => {
|
|
5655
|
-
if (!
|
|
5719
|
+
if (!fs7.existsSync(filePath))
|
|
5656
5720
|
return true;
|
|
5657
|
-
const stream2 =
|
|
5721
|
+
const stream2 = fs7.createReadStream(filePath);
|
|
5658
5722
|
const reader = readline.createInterface({ input: stream2 });
|
|
5659
5723
|
const firstLine = await new Promise(
|
|
5660
5724
|
(resolve3) => reader.once("line", (line) => resolve3(line.trim()))
|
|
@@ -5673,7 +5737,7 @@ var getIndexFile = (filePath, projectRoot) => {
|
|
|
5673
5737
|
if (isRootModuleFile)
|
|
5674
5738
|
return { indexFilePath: filePath, isRootModuleFile };
|
|
5675
5739
|
const dir = path15.dirname(filePath);
|
|
5676
|
-
const files =
|
|
5740
|
+
const files = fs7.readdirSync(dir);
|
|
5677
5741
|
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
5678
5742
|
return indexFileName ? { indexFilePath: path15.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
5679
5743
|
};
|
|
@@ -5758,7 +5822,7 @@ var BASE_PATH = "/";
|
|
|
5758
5822
|
var PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3e3;
|
|
5759
5823
|
var SHADOW_PORT = 1442;
|
|
5760
5824
|
var STORYBOOK_PORT = process.env.STORYBOOK_PORT ? parseInt(process.env.STORYBOOK_PORT, 10) : 3123;
|
|
5761
|
-
async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2, hubspotCliAccountNameOption2, sslEnabledOption2, fieldGenEnabledOption2, themePreviewOptions2
|
|
5825
|
+
async function createDevServer(webRoot2, storybook2, hubspotCliConfigPathOption2, hubspotCliAccountNameOption2, sslEnabledOption2, fieldGenEnabledOption2, themePreviewOptions2) {
|
|
5762
5826
|
let authedPortalId = null;
|
|
5763
5827
|
let authedEnv = null;
|
|
5764
5828
|
let jsRenderingGates = [];
|
|
@@ -5865,7 +5929,7 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5865
5929
|
}
|
|
5866
5930
|
let authedHublet;
|
|
5867
5931
|
try {
|
|
5868
|
-
const accountInformation = (await
|
|
5932
|
+
const accountInformation = (await hsCliHttp14.get(authedPortalId, {
|
|
5869
5933
|
url: "/account-info/v3/details"
|
|
5870
5934
|
})).data;
|
|
5871
5935
|
authedHublet = accountInformation.dataHostingLocation;
|
|
@@ -5924,32 +5988,28 @@ Local proxy functionality and module preview routes will not work without settin
|
|
|
5924
5988
|
expressServer.locals.domainsToProxy = domainsToProxy;
|
|
5925
5989
|
expressServer.locals.localPreviewToken = _localPreviewToken;
|
|
5926
5990
|
expressServer.use(bodyParser.json());
|
|
5927
|
-
|
|
5928
|
-
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
5940
|
-
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
reqLocals,
|
|
5950
|
-
appWebRoot
|
|
5951
|
-
};
|
|
5952
|
-
}
|
|
5991
|
+
const __dirname2 = path16.dirname(url2.fileURLToPath(import.meta.url));
|
|
5992
|
+
const appWebRoot = normalizePath9(path16.resolve(__dirname2, "../app"));
|
|
5993
|
+
const reqLocals = {
|
|
5994
|
+
themeWebRoot: absoluteWebRoot,
|
|
5995
|
+
authedPortalId,
|
|
5996
|
+
authedEnv,
|
|
5997
|
+
authedHublet,
|
|
5998
|
+
projectName,
|
|
5999
|
+
webRootProjectComponentFolder,
|
|
6000
|
+
localPreviewToken: _localPreviewToken,
|
|
6001
|
+
sslEnabled: sslEnabledOption2
|
|
6002
|
+
};
|
|
6003
|
+
const appServer = await createAppServer_default(
|
|
6004
|
+
appWebRoot,
|
|
6005
|
+
PORT,
|
|
6006
|
+
sslEnabledOption2
|
|
6007
|
+
);
|
|
6008
|
+
const appServerConfig = {
|
|
6009
|
+
appServer,
|
|
6010
|
+
reqLocals,
|
|
6011
|
+
appWebRoot
|
|
6012
|
+
};
|
|
5953
6013
|
expressServer.use(
|
|
5954
6014
|
BASE_PATH,
|
|
5955
6015
|
await createDevServerRoutes_default(
|
|
@@ -6067,8 +6127,7 @@ var {
|
|
|
6067
6127
|
sslEnabledOption,
|
|
6068
6128
|
storybook,
|
|
6069
6129
|
fieldGenEnabledOption,
|
|
6070
|
-
resetSession
|
|
6071
|
-
showUI
|
|
6130
|
+
resetSession
|
|
6072
6131
|
} = getDevServerCommandLineOptions(process.argv);
|
|
6073
6132
|
if (!webRoot) {
|
|
6074
6133
|
throw new Error(`No web root path argument specified`);
|
|
@@ -6088,6 +6147,5 @@ createDevServer_default(
|
|
|
6088
6147
|
hubspotCliAccountNameOption,
|
|
6089
6148
|
sslEnabledOption,
|
|
6090
6149
|
fieldGenEnabledOption,
|
|
6091
|
-
themePreviewOptions
|
|
6092
|
-
showUI
|
|
6150
|
+
themePreviewOptions
|
|
6093
6151
|
);
|