@hubspot/cms-dev-server 0.2.13 → 0.3.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/createDevServer.js +34 -2
- package/dist/createViteDevServer.js +3 -2
- package/dist/lib/cli.js +4 -0
- package/dist/lib/renderModule.js +1 -1
- package/dist/routes/createDevServerRoutes.js +10 -1
- package/dist/routes/homeRouteHandler.js +2 -2
- package/dist/run.js +2 -2
- package/dist/storybook/main.js +6 -1
- package/package.json +30 -10
- package/types/storybook/index.d.ts +1 -0
- package/types/storybook/moduleStory.d.ts +12 -0
package/dist/createDevServer.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import url from 'url';
|
|
2
3
|
import express from 'express';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
3
5
|
import { normalizePath } from 'vite';
|
|
4
6
|
import createDevServerRoutes from './routes/createDevServerRoutes.js';
|
|
5
7
|
import { getProjectNameFromHSConfig } from './lib/proxyHelpers.js';
|
|
@@ -7,7 +9,10 @@ import createViteDevServer from './createViteDevServer.js';
|
|
|
7
9
|
import { getEnv, getAccountId, loadConfig, validateConfig, } from '@hubspot/cli-lib/lib/config.js';
|
|
8
10
|
const BASE_PATH = '/';
|
|
9
11
|
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
10
|
-
|
|
12
|
+
const STORYBOOK_PORT = process.env.STORYBOOK_PORT
|
|
13
|
+
? parseInt(process.env.STORYBOOK_PORT, 10)
|
|
14
|
+
: 3123;
|
|
15
|
+
async function createDevServer(webRoot, storybook, hubspotCliConfigPathOption, hubspotCliAccountNameOption, debug) {
|
|
11
16
|
console.log('Warning: this is a prerelease and requires specific HubSpot account configuration to work');
|
|
12
17
|
let authedPortalId = null;
|
|
13
18
|
let authedEnv = null;
|
|
@@ -45,9 +50,11 @@ Local proxy functionality will not work without setting up authentication.`);
|
|
|
45
50
|
expressServer.locals.devServerPort = PORT;
|
|
46
51
|
expressServer.locals.webRoot = webRoot;
|
|
47
52
|
expressServer.locals.viteServer = viteServer;
|
|
53
|
+
expressServer.locals.storybookEnabled = storybook;
|
|
54
|
+
expressServer.locals.storybookPort = STORYBOOK_PORT;
|
|
48
55
|
expressServer.locals.projectName = getProjectNameFromHSConfig(path.join(webRoot, '../hsproject.json'));
|
|
49
56
|
expressServer.locals.projectComponentPath = webRootProjectComponentFolder;
|
|
50
|
-
expressServer.use(BASE_PATH, await createDevServerRoutes(viteServer));
|
|
57
|
+
expressServer.use(BASE_PATH, await createDevServerRoutes(viteServer, storybook ? STORYBOOK_PORT : null));
|
|
51
58
|
expressServer.listen(PORT);
|
|
52
59
|
let extraServerInfo = '';
|
|
53
60
|
if (authedPortalId) {
|
|
@@ -59,5 +66,30 @@ Local proxy functionality will not work without setting up authentication.`);
|
|
|
59
66
|
console.log(`
|
|
60
67
|
HubSpot CMS dev server hosting: ${expressServer.locals.projectName}/${expressServer.locals.projectComponentPath} (at http://localhost:${PORT}${extraServerInfo})
|
|
61
68
|
`);
|
|
69
|
+
if (storybook) {
|
|
70
|
+
const packageRoot = path.dirname(url.fileURLToPath(import.meta.url));
|
|
71
|
+
const configPath = path.resolve(packageRoot, './storybook');
|
|
72
|
+
const storybookProcess = spawn('yarn', [
|
|
73
|
+
'sb',
|
|
74
|
+
'dev',
|
|
75
|
+
'-p',
|
|
76
|
+
STORYBOOK_PORT.toString(),
|
|
77
|
+
'-c',
|
|
78
|
+
configPath,
|
|
79
|
+
'--quiet',
|
|
80
|
+
'--no-open',
|
|
81
|
+
], {
|
|
82
|
+
cwd: process.cwd(),
|
|
83
|
+
env: {
|
|
84
|
+
...process.env,
|
|
85
|
+
WEB_ROOT: path.join(webRoot, 'components'),
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
console.log(`Starting storybook server on port ${STORYBOOK_PORT}`);
|
|
89
|
+
if (debug) {
|
|
90
|
+
storybookProcess.stdout.pipe(process.stdout);
|
|
91
|
+
}
|
|
92
|
+
storybookProcess.stderr.pipe(process.stderr);
|
|
93
|
+
}
|
|
62
94
|
}
|
|
63
95
|
export default createDevServer;
|
|
@@ -3,7 +3,7 @@ import { default as react } from '@vitejs/plugin-react';
|
|
|
3
3
|
import { resolveIslandPlugin } from '@hubspot/cms-js-internal';
|
|
4
4
|
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
5
5
|
async function createViteDevServer() {
|
|
6
|
-
|
|
6
|
+
const viteConfig = {
|
|
7
7
|
appType: 'custom',
|
|
8
8
|
server: {
|
|
9
9
|
middlewareMode: true,
|
|
@@ -21,6 +21,7 @@ async function createViteDevServer() {
|
|
|
21
21
|
include: ['react', 'react-dom', 'react-dom/client'],
|
|
22
22
|
},
|
|
23
23
|
plugins: [react(), resolveIslandPlugin()],
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
|
+
return createViteServer(viteConfig);
|
|
25
26
|
}
|
|
26
27
|
export default createViteDevServer;
|
package/dist/lib/cli.js
CHANGED
|
@@ -15,9 +15,13 @@ export function getDevServerCommandLineOptions(argv) {
|
|
|
15
15
|
hubspotCliAccountNameOption = args[accountOptionIndex + 1];
|
|
16
16
|
args.splice(accountOptionIndex, 2);
|
|
17
17
|
}
|
|
18
|
+
const storybook = args.findIndex(arg => arg === '--storybook') > 0;
|
|
19
|
+
const debug = args.findIndex(arg => arg === '--debug') > 0;
|
|
18
20
|
return {
|
|
19
21
|
webRoot,
|
|
20
22
|
hubspotCliConfigPathOption,
|
|
21
23
|
hubspotCliAccountNameOption,
|
|
24
|
+
storybook,
|
|
25
|
+
debug,
|
|
22
26
|
};
|
|
23
27
|
}
|
package/dist/lib/renderModule.js
CHANGED
|
@@ -9,7 +9,7 @@ const lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
|
9
9
|
componentModule = await viteServer.ssrLoadModule(insideFolderPath);
|
|
10
10
|
}
|
|
11
11
|
catch (e) {
|
|
12
|
-
if (!e.message.includes('
|
|
12
|
+
if (!e.message.includes('Failed to load url')) {
|
|
13
13
|
throw e;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Router } from 'express';
|
|
2
|
+
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
2
3
|
import partialRouteHandler from './partial.js';
|
|
3
4
|
import linksToAllPartialsRouteHandler from './linksToAllPartialsRouteHandler.js';
|
|
4
5
|
import linksToAllModulesRouteHandler from './linksToAllModulesRouteHandler.js';
|
|
@@ -6,8 +7,16 @@ import moduleRouteHandler from './module.js';
|
|
|
6
7
|
import proxyPageRouteHandler from './proxyPageRouteHandler.js';
|
|
7
8
|
import proxyPageResourceRedirect from './proxyPageResourceRedirect.js';
|
|
8
9
|
import homeRouteHandler from './homeRouteHandler.js';
|
|
9
|
-
|
|
10
|
+
import { VALID_PROXY_DOMAIN_SUFFIXES } from '../proxyPage/constants.js';
|
|
11
|
+
const STORYBOOK_DOMAINS = VALID_PROXY_DOMAIN_SUFFIXES.map(domain => `storybook.${domain}`);
|
|
12
|
+
const createDevServerRoutes = async (viteServer, storybookPort) => {
|
|
10
13
|
const devServerApp = Router();
|
|
14
|
+
if (storybookPort) {
|
|
15
|
+
devServerApp.use(createProxyMiddleware((__pathname, req) => STORYBOOK_DOMAINS.includes(req.hostname), {
|
|
16
|
+
logLevel: 'warn',
|
|
17
|
+
target: `http://localhost:${storybookPort}`,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
11
20
|
devServerApp.use(viteServer.middlewares);
|
|
12
21
|
devServerApp.get('/partials/', linksToAllPartialsRouteHandler);
|
|
13
22
|
devServerApp.get('/partial/:partial', partialRouteHandler);
|
|
@@ -3,10 +3,10 @@ import { findAllModulesInRoot, findAllPartialsInRoot, renderOnServer, } from '@h
|
|
|
3
3
|
import ModulesList from '../components/ModulesList.js';
|
|
4
4
|
import PartialsList from '../components/PartialsList.js';
|
|
5
5
|
const homeRouteHandler = async (request, response) => {
|
|
6
|
-
const { webRoot } = request.app.locals;
|
|
6
|
+
const { webRoot, storybookEnabled, devServerPort } = request.app.locals;
|
|
7
7
|
const { partialNames } = findAllPartialsInRoot(webRoot);
|
|
8
8
|
const { moduleNames } = findAllModulesInRoot(webRoot);
|
|
9
|
-
const { html: responseHtml } = await renderOnServer(_jsxs(_Fragment, { children: [_jsx("h2", { children: "Partials" }), _jsx(PartialsList, { webRoot: webRoot, partialNames: partialNames }), _jsx("h2", { children: "Modules" }), _jsx(ModulesList, { webRoot: webRoot, moduleNames: moduleNames })] }), null);
|
|
9
|
+
const { html: responseHtml } = await renderOnServer(_jsxs(_Fragment, { children: [storybookEnabled ? (_jsx("h2", { children: _jsx("a", { href: `//storybook.${request.hostname}:${devServerPort}`, children: "Storybook" }) })) : null, _jsx("h2", { children: "Partials" }), _jsx(PartialsList, { webRoot: webRoot, partialNames: partialNames }), _jsx("h2", { children: "Modules" }), _jsx(ModulesList, { webRoot: webRoot, moduleNames: moduleNames })] }), null);
|
|
10
10
|
response.status(200).set({ 'Content-Type': 'text/html' }).end(responseHtml);
|
|
11
11
|
};
|
|
12
12
|
export default homeRouteHandler;
|
package/dist/run.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { getDevServerCommandLineOptions } from './lib/cli.js';
|
|
3
3
|
import createDevServer from './createDevServer.js';
|
|
4
|
-
const { webRoot, hubspotCliConfigPathOption, hubspotCliAccountNameOption } = getDevServerCommandLineOptions(process.argv);
|
|
4
|
+
const { webRoot, hubspotCliConfigPathOption, hubspotCliAccountNameOption, storybook, debug, } = getDevServerCommandLineOptions(process.argv);
|
|
5
5
|
if (!webRoot) {
|
|
6
6
|
throw new Error(`No web root path argument specified`);
|
|
7
7
|
}
|
|
8
|
-
createDevServer(webRoot, hubspotCliConfigPathOption, hubspotCliAccountNameOption);
|
|
8
|
+
createDevServer(webRoot, storybook, hubspotCliConfigPathOption, hubspotCliAccountNameOption, debug);
|
package/dist/storybook/main.js
CHANGED
|
@@ -10,7 +10,12 @@ export default {
|
|
|
10
10
|
const { resolveIslandPlugin } = await import('@hubspot/cms-js-internal');
|
|
11
11
|
const viteConfig = {
|
|
12
12
|
resolve: {
|
|
13
|
-
dedupe: [
|
|
13
|
+
dedupe: [
|
|
14
|
+
'react',
|
|
15
|
+
'react-dom',
|
|
16
|
+
'@hubspot/cms-components',
|
|
17
|
+
'@hubspot/cms-dev-server',
|
|
18
|
+
],
|
|
14
19
|
},
|
|
15
20
|
optimizeDeps: {
|
|
16
21
|
include: ['react', 'react-dom', 'react-dom/client'],
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/createViteDevServer.js",
|
|
7
6
|
"engines": {
|
|
8
7
|
"node": ">=16.x"
|
|
9
8
|
},
|
|
10
9
|
"scripts": {
|
|
11
|
-
"build": "tsc --build &&
|
|
10
|
+
"build": "tsc --build && yarn run copy-html && yarn build-types && node scripts/build.mjs",
|
|
12
11
|
"copy-html": "copyfiles -u 1 'src/html/**' 'dist'",
|
|
12
|
+
"build-types": "tsc --project tsconfig.types.json",
|
|
13
13
|
"clean": "tsc --build --clean",
|
|
14
14
|
"dev": "nodemon --exec 'ts-node-esm --transpileOnly runWhenDeveloping.ts'",
|
|
15
15
|
"dev-inspect": "nodemon --exec 'node --loader ts-node/esm --inspect runWhenDeveloping.ts'",
|
|
@@ -21,16 +21,25 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@hubspot/cli-lib": "^3.0.12",
|
|
24
|
-
"@hubspot/cms-components": "^0.
|
|
25
|
-
"@hubspot/cms-js-internal": "^0.
|
|
26
|
-
"@
|
|
24
|
+
"@hubspot/cms-components": "^0.3.0",
|
|
25
|
+
"@hubspot/cms-js-internal": "^0.3.0",
|
|
26
|
+
"@storybook/addon-actions": "^7.0.0-beta.19",
|
|
27
|
+
"@storybook/addon-essentials": "^7.0.0-beta.19",
|
|
28
|
+
"@storybook/addon-interactions": "^7.0.0-beta.19",
|
|
29
|
+
"@storybook/addon-links": "^7.0.0-beta.19",
|
|
30
|
+
"@storybook/cli": "^7.0.0-beta.19",
|
|
31
|
+
"@storybook/react": "^7.0.0-beta.19",
|
|
32
|
+
"@storybook/react-vite": "^7.0.0-beta.19",
|
|
33
|
+
"@storybook/testing-library": "^0.0.13",
|
|
34
|
+
"@vitejs/plugin-react": "^3.0.0",
|
|
27
35
|
"ansi-to-html": "0.7.x",
|
|
28
36
|
"express": "^4.17.3",
|
|
37
|
+
"http-proxy-middleware": "^2.0.6",
|
|
29
38
|
"react": "^18.1.0",
|
|
30
39
|
"react-dom": "^18.1.0",
|
|
31
40
|
"request": "^2.88.2",
|
|
32
41
|
"typescript": "~4.7.0",
|
|
33
|
-
"vite": "^
|
|
42
|
+
"vite": "^4.0.0",
|
|
34
43
|
"vite-plugin-inspect": "^0.4.3"
|
|
35
44
|
},
|
|
36
45
|
"devDependencies": {
|
|
@@ -40,13 +49,24 @@
|
|
|
40
49
|
"copyfiles": "^2.4.1",
|
|
41
50
|
"nodemon": "^2.0.15",
|
|
42
51
|
"ts-node": "^10.7.0",
|
|
43
|
-
"vitest": "0.
|
|
52
|
+
"vitest": "0.25.8"
|
|
53
|
+
},
|
|
54
|
+
"main": "./dist/createViteDevServer.js",
|
|
55
|
+
"exports": {
|
|
56
|
+
".": "./dist/createViteDevServer.js",
|
|
57
|
+
"./storybook": {
|
|
58
|
+
"types": "./types/storybook/index.d.ts",
|
|
59
|
+
"default": "./dist/storybook/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./dist/storybook/preview.js": "./dist/storybook/preview.js"
|
|
44
62
|
},
|
|
63
|
+
"types": "types/index.d.ts",
|
|
45
64
|
"bin": {
|
|
46
65
|
"hs-cms-dev-server": "./dist/run.js"
|
|
47
66
|
},
|
|
48
67
|
"files": [
|
|
49
|
-
"dist/**/*"
|
|
68
|
+
"dist/**/*",
|
|
69
|
+
"types"
|
|
50
70
|
],
|
|
51
71
|
"nodemonConfig": {
|
|
52
72
|
"ext": "js,json,ts,tsx,jsx,html",
|
|
@@ -64,5 +84,5 @@
|
|
|
64
84
|
"publishConfig": {
|
|
65
85
|
"access": "public"
|
|
66
86
|
},
|
|
67
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "e995b0c502a618dd584a9ae887405aef3bc3f962"
|
|
68
88
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './moduleStory.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Field } from '@hubspot/cms-components/fields';
|
|
3
|
+
declare type Args = {
|
|
4
|
+
[fieldPath: string]: any;
|
|
5
|
+
};
|
|
6
|
+
declare type FieldValues = {
|
|
7
|
+
[fieldNameOrGroupName: string]: FieldValues;
|
|
8
|
+
};
|
|
9
|
+
export declare function getNestedFieldObjectForArgs(_args: Args): FieldValues;
|
|
10
|
+
export declare function moduleFieldsToJson(fields: JSX.Element): Field[];
|
|
11
|
+
export declare function moduleStory(ModuleComponent: React.ComponentType, fields: JSX.Element): any;
|
|
12
|
+
export {};
|