@hubspot/cms-dev-server 1.2.80 → 1.2.83
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/generateFieldsCli.js +438 -0
- package/dist/generateJsonFromJsx.js +1 -1
- package/dist/index.js +1114 -922
- package/dist/internalSsr.js +3 -5
- package/dist/island-runtime.js +22 -6
- package/dist/run.js +990 -798
- package/dist/storybook/index.js +1 -1
- package/dist/storybook-main/main.js +7 -9
- package/dist/validateFieldsCli.js +56 -58
- package/package.json +3 -2
- package/types/lib/renderModulePreview.d.ts +2 -3
- package/types/routes/moduleValidateFields.d.ts +3 -0
- package/types/validateFields.d.ts +39 -0
- package/types/lib/debugAuth.d.ts +0 -8
- package/types/lib/localComponentsLoader.d.ts +0 -2
- package/types/lib/viteAssetHandler.d.ts +0 -18
- package/types/plugins/hubspotStaticAssetPlugin.d.ts +0 -2
- package/types/plugins/remoteAssetsPlugin.d.ts +0 -10
- package/types/plugins/requestSigningPlugin.d.ts +0 -6
- package/types/routes/createAppServerRoutes.d.ts +0 -13
- package/types/routes/homeRouteHandler.d.ts +0 -7
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/validateFields.ts
|
|
4
|
+
import path3 from "path";
|
|
5
|
+
import fs2 from "fs/promises";
|
|
6
|
+
import {
|
|
7
|
+
createServer as createViteServer,
|
|
8
|
+
normalizePath as normalizePath2
|
|
9
|
+
} from "vite";
|
|
10
|
+
import { createRequire } from "module";
|
|
11
|
+
import { default as react } from "@vitejs/plugin-react";
|
|
12
|
+
|
|
13
|
+
// ../cms-js-internal/dist/types-C8bPIEz4.js
|
|
14
|
+
import path from "path";
|
|
15
|
+
import fs, { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
16
|
+
import { join } from "path/posix";
|
|
17
|
+
var COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
18
|
+
var viteRoot;
|
|
19
|
+
var viteCommand;
|
|
20
|
+
function resolveIslandPlugin(islandsSet) {
|
|
21
|
+
return {
|
|
22
|
+
enforce: "pre",
|
|
23
|
+
name: "resolve-islands",
|
|
24
|
+
configResolved(config) {
|
|
25
|
+
viteRoot = config.root;
|
|
26
|
+
viteCommand = config.command;
|
|
27
|
+
},
|
|
28
|
+
load(id) {
|
|
29
|
+
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
30
|
+
const [idWithNoParam] = id.split("?");
|
|
31
|
+
const islandModuleImportPath = `${idWithNoParam}?client-entry`;
|
|
32
|
+
const componentExtension = path.extname(idWithNoParam);
|
|
33
|
+
const componentFilenameWithNoExtension = path.basename(
|
|
34
|
+
idWithNoParam,
|
|
35
|
+
componentExtension
|
|
36
|
+
);
|
|
37
|
+
const modulePath = path.relative(viteRoot, idWithNoParam);
|
|
38
|
+
const moduleId = (viteCommand === "serve" ? idWithNoParam : modulePath).concat("?client-entry");
|
|
39
|
+
if (islandsSet) {
|
|
40
|
+
islandsSet.add(moduleId);
|
|
41
|
+
}
|
|
42
|
+
return `
|
|
43
|
+
const moduleId = '${moduleId}';
|
|
44
|
+
|
|
45
|
+
const lazyComponent = () => import('${islandModuleImportPath}');
|
|
46
|
+
lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
|
|
47
|
+
lazyComponent.moduleId = moduleId;
|
|
48
|
+
|
|
49
|
+
export default lazyComponent;
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || ((id) => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
57
|
+
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
58
|
+
function clientIslandEntryPlugin() {
|
|
59
|
+
return {
|
|
60
|
+
enforce: "pre",
|
|
61
|
+
name: "client-island-entry-plugin",
|
|
62
|
+
resolveId(id) {
|
|
63
|
+
if (id === virtualClientRenderIslandModuleId) {
|
|
64
|
+
return virtualClientRenderIslandModuleId;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
},
|
|
68
|
+
load(id) {
|
|
69
|
+
if (id.endsWith("?client-entry")) {
|
|
70
|
+
const [idWithNoParam] = id.split("?");
|
|
71
|
+
return `
|
|
72
|
+
import { clientRenderIsland } from '${virtualClientRenderIslandModuleId}';
|
|
73
|
+
import Component from '${idWithNoParam}';
|
|
74
|
+
|
|
75
|
+
export function render(island) {
|
|
76
|
+
return clientRenderIsland(island, Component)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default Component;
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
if (id === virtualClientRenderIslandModuleId) {
|
|
83
|
+
return clientRenderIsland;
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
var getComponentExtension = (componentPath) => {
|
|
90
|
+
const filteredExtensions = COMPONENT_EXTENSIONS.filter(
|
|
91
|
+
(ext) => componentPath.endsWith(ext)
|
|
92
|
+
);
|
|
93
|
+
if (filteredExtensions.length === 1) {
|
|
94
|
+
return filteredExtensions[0];
|
|
95
|
+
}
|
|
96
|
+
return void 0;
|
|
97
|
+
};
|
|
98
|
+
var hasComponentExtension = (componentPath) => {
|
|
99
|
+
return !!getComponentExtension(componentPath);
|
|
100
|
+
};
|
|
101
|
+
var isStorybookStory = (componentPath) => {
|
|
102
|
+
return !!path.basename(componentPath, path.extname(componentPath)).endsWith(".stories");
|
|
103
|
+
};
|
|
104
|
+
var removeComponentExtension = (componentPath) => {
|
|
105
|
+
const ext = getComponentExtension(componentPath);
|
|
106
|
+
if (ext == null) {
|
|
107
|
+
return componentPath;
|
|
108
|
+
}
|
|
109
|
+
return componentPath.slice(0, -1 * ext.length);
|
|
110
|
+
};
|
|
111
|
+
var findAllComponentsIn = (webRoot, componentsFolder) => {
|
|
112
|
+
const fullComponentsFolderPath = join(webRoot, componentsFolder);
|
|
113
|
+
const componentsByName = {};
|
|
114
|
+
if (!existsSync(fullComponentsFolderPath)) {
|
|
115
|
+
return componentsByName;
|
|
116
|
+
}
|
|
117
|
+
readdirSync(fullComponentsFolderPath).forEach((fileOrFolderName) => {
|
|
118
|
+
const fullPath = join(fullComponentsFolderPath, fileOrFolderName);
|
|
119
|
+
const subdirPath = join(componentsFolder, fileOrFolderName);
|
|
120
|
+
const isDirectory = lstatSync(fullPath).isDirectory();
|
|
121
|
+
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
122
|
+
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
123
|
+
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
124
|
+
} else if (isDirectory) {
|
|
125
|
+
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
126
|
+
const potentialIndexModule = join(
|
|
127
|
+
subdirPath,
|
|
128
|
+
`index${potentialExtension}`
|
|
129
|
+
);
|
|
130
|
+
const fullPotentialPath = join(
|
|
131
|
+
fullPath,
|
|
132
|
+
`index${potentialExtension}`
|
|
133
|
+
);
|
|
134
|
+
if (existsSync(fullPotentialPath)) {
|
|
135
|
+
const moduleIndexPathNoExtension = removeComponentExtension(potentialIndexModule);
|
|
136
|
+
componentsByName[moduleIndexPathNoExtension] = potentialIndexModule;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return componentsByName;
|
|
143
|
+
};
|
|
144
|
+
function findAllModulesInRoot(webRoot) {
|
|
145
|
+
const allModuleComponents = findAllComponentsIn(
|
|
146
|
+
webRoot,
|
|
147
|
+
"./components/modules"
|
|
148
|
+
);
|
|
149
|
+
const moduleNames = Object.keys(allModuleComponents).map(
|
|
150
|
+
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
151
|
+
);
|
|
152
|
+
const moduleSubpaths = Object.keys(allModuleComponents);
|
|
153
|
+
const moduleExtensions = Object.values(allModuleComponents).map((path22) => {
|
|
154
|
+
if (!path22)
|
|
155
|
+
return "";
|
|
156
|
+
const extension = path22.split(".").pop() || "";
|
|
157
|
+
return extension;
|
|
158
|
+
});
|
|
159
|
+
const moduleNamesWithExtension = Object.values(allModuleComponents).map(
|
|
160
|
+
(path22) => {
|
|
161
|
+
if (!path22)
|
|
162
|
+
return "";
|
|
163
|
+
const file = path22.replace("components/modules/", "");
|
|
164
|
+
return file.includes("/index.") ? file.split("/index.")[0] : file;
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
return {
|
|
168
|
+
moduleNames,
|
|
169
|
+
moduleSubpaths,
|
|
170
|
+
moduleNamesWithExtension,
|
|
171
|
+
moduleExtensions
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ../cms-js-internal/dist/index.js
|
|
176
|
+
import * as dotProp from "dot-prop";
|
|
177
|
+
import _traverse from "@babel/traverse";
|
|
178
|
+
import * as cmsComponents from "@hubspot/cms-components";
|
|
179
|
+
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
180
|
+
function noncePlaceholderPlugin() {
|
|
181
|
+
const HS_DEPLOYED = process.env.AWS_EXECUTION_ENV != null || process.env.HS_DEPLOYED === "true";
|
|
182
|
+
return {
|
|
183
|
+
name: "hs-nonce-placeholder",
|
|
184
|
+
enforce: "post",
|
|
185
|
+
apply() {
|
|
186
|
+
return HS_DEPLOYED;
|
|
187
|
+
},
|
|
188
|
+
transformIndexHtml(html) {
|
|
189
|
+
const regex = /<(style|script|link) (.*)>/gi;
|
|
190
|
+
const replacer = (_, p1, p2) => {
|
|
191
|
+
if (p1 === "style" || p1 === "script" || // if link, only nonce for stylesheet
|
|
192
|
+
p1 === "link" && p2.includes('rel="stylesheet"')) {
|
|
193
|
+
const noncePlaceholderValue = p1 === "script" ? "hs-random-nonce" : "hs-random-style-nonce";
|
|
194
|
+
p2 = `nonce="${noncePlaceholderValue}" ${p2}`;
|
|
195
|
+
}
|
|
196
|
+
return `<${p1} ${p2}>`;
|
|
197
|
+
};
|
|
198
|
+
return html.replace(regex, replacer);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
var traverse = _traverse.default;
|
|
203
|
+
var {
|
|
204
|
+
createServerRenderContextV2: createServerRenderContextV22,
|
|
205
|
+
createServerRenderContext: createServerRenderContext2,
|
|
206
|
+
renderServerSidePropsWithAsyncLocalStoreContext
|
|
207
|
+
} = cmsComponents;
|
|
208
|
+
|
|
209
|
+
// src/validateFields.ts
|
|
210
|
+
import { viteCommonjs } from "@originjs/vite-plugin-commonjs";
|
|
211
|
+
|
|
212
|
+
// src/lib/renderModuleFieldsJson.ts
|
|
213
|
+
import { join as joinPosix } from "path/posix";
|
|
214
|
+
|
|
215
|
+
// src/lib/packagePath.ts
|
|
216
|
+
import path2 from "path";
|
|
217
|
+
import url from "url";
|
|
218
|
+
import { normalizePath } from "vite";
|
|
219
|
+
function packagePath(metaUrl, projectPath) {
|
|
220
|
+
if (true) {
|
|
221
|
+
return normalizePath(
|
|
222
|
+
path2.resolve(path2.dirname(url.fileURLToPath(metaUrl)), projectPath)
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
const parentDirPath = normalizePath(path2.dirname(url.fileURLToPath(metaUrl)));
|
|
226
|
+
const subPath = parentDirPath.replace(/^.+cms-dev-server\/src\//, "");
|
|
227
|
+
const subPathParentDirs = subPath.split("/").map(() => "..");
|
|
228
|
+
return path2.resolve(
|
|
229
|
+
path2.dirname(url.fileURLToPath(metaUrl)),
|
|
230
|
+
path2.join(...subPathParentDirs, projectPath)
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/lib/renderModuleFieldsJson.ts
|
|
235
|
+
var lookForModuleInFolder = async (modulePath, viteServer) => {
|
|
236
|
+
let componentModule;
|
|
237
|
+
const insideFolderPath = joinPosix(modulePath, "index");
|
|
238
|
+
try {
|
|
239
|
+
componentModule = await viteServer.ssrLoadModule(insideFolderPath);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
if (!e.message.includes("Failed to load url")) {
|
|
242
|
+
throw e;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return [componentModule, insideFolderPath];
|
|
246
|
+
};
|
|
247
|
+
async function renderModuleFieldsJson(viteServer, requestedModulePath) {
|
|
248
|
+
let componentModule;
|
|
249
|
+
try {
|
|
250
|
+
if (!hasComponentExtension(requestedModulePath)) {
|
|
251
|
+
[componentModule] = await lookForModuleInFolder(
|
|
252
|
+
requestedModulePath,
|
|
253
|
+
viteServer
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
if (!componentModule) {
|
|
257
|
+
componentModule = await viteServer.ssrLoadModule(requestedModulePath);
|
|
258
|
+
}
|
|
259
|
+
} catch (error) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
`Failed to load module ${requestedModulePath}: ${error.message}`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (!componentModule) {
|
|
265
|
+
throw new Error(`Couldn't find module: ${requestedModulePath}`);
|
|
266
|
+
}
|
|
267
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
268
|
+
const { renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
269
|
+
const fieldsJson = renderFieldsToJson(
|
|
270
|
+
componentModule.fields,
|
|
271
|
+
requestedModulePath
|
|
272
|
+
);
|
|
273
|
+
return fieldsJson;
|
|
274
|
+
}
|
|
275
|
+
var renderModuleFieldsJson_default = renderModuleFieldsJson;
|
|
276
|
+
|
|
277
|
+
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
278
|
+
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
279
|
+
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
280
|
+
|
|
281
|
+
// src/lib/renderModule.ts
|
|
282
|
+
import * as cmsComponents2 from "@hubspot/cms-components";
|
|
283
|
+
var { filterToModuleDataDepsIncludedIn, getModuleDataDependecyTypeFrom } = cmsComponents2;
|
|
284
|
+
|
|
285
|
+
// src/validateFields.ts
|
|
286
|
+
async function generateAndWriteFieldsJson(absoluteModulePath, modulePath, viteServer) {
|
|
287
|
+
let fieldsJson;
|
|
288
|
+
try {
|
|
289
|
+
fieldsJson = await renderModuleFieldsJson_default(viteServer, absoluteModulePath);
|
|
290
|
+
} catch {
|
|
291
|
+
return {
|
|
292
|
+
severity: "FATAL",
|
|
293
|
+
errorType: "MODULE_BUILD_ERROR",
|
|
294
|
+
message: `Failed to SSR-load module at ${modulePath}`
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
if (!Array.isArray(fieldsJson)) {
|
|
298
|
+
return {
|
|
299
|
+
severity: "FATAL",
|
|
300
|
+
errorType: "INVALID_FIELDS",
|
|
301
|
+
message: `renderModuleFieldsJson returned non-array for ${modulePath}`
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
const fieldsJsonPath = path3.join(absoluteModulePath, "fields.json");
|
|
305
|
+
await fs2.writeFile(fieldsJsonPath, JSON.stringify(fieldsJson, null, 2));
|
|
306
|
+
return { fieldsJson, fieldsJsonPath };
|
|
307
|
+
}
|
|
308
|
+
async function generateSingleModule(modulePath, absoluteRoot, viteServer) {
|
|
309
|
+
const absoluteModulePath = path3.resolve(absoluteRoot, modulePath);
|
|
310
|
+
let files;
|
|
311
|
+
try {
|
|
312
|
+
files = await fs2.readdir(absoluteModulePath);
|
|
313
|
+
} catch {
|
|
314
|
+
return {
|
|
315
|
+
fieldsJsonPath: "",
|
|
316
|
+
fieldErrors: [
|
|
317
|
+
{
|
|
318
|
+
severity: "FATAL",
|
|
319
|
+
errorType: "MODULE_NOT_FOUND",
|
|
320
|
+
message: `Module directory does not exist: ${modulePath}`
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const indexFile = files.find((f) => f.startsWith("index."));
|
|
326
|
+
if (!indexFile) {
|
|
327
|
+
return {
|
|
328
|
+
fieldsJsonPath: "",
|
|
329
|
+
fieldErrors: [
|
|
330
|
+
{
|
|
331
|
+
severity: "FATAL",
|
|
332
|
+
errorType: "NO_INDEX_FILE",
|
|
333
|
+
message: `No index file found in ${modulePath}`
|
|
334
|
+
}
|
|
335
|
+
]
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
const jsonResult = await generateAndWriteFieldsJson(
|
|
339
|
+
absoluteModulePath,
|
|
340
|
+
modulePath,
|
|
341
|
+
viteServer
|
|
342
|
+
);
|
|
343
|
+
if ("severity" in jsonResult) {
|
|
344
|
+
return { fieldsJsonPath: "", fieldErrors: [jsonResult] };
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
fieldsJsonPath: jsonResult.fieldsJsonPath,
|
|
348
|
+
fieldErrors: [],
|
|
349
|
+
fieldsJson: jsonResult.fieldsJson,
|
|
350
|
+
indexFile
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
async function forEachModule(projectRoot, moduleName, run) {
|
|
354
|
+
const absoluteRoot = normalizePath2(path3.resolve(process.cwd(), projectRoot));
|
|
355
|
+
const moduleNames = moduleName ? [moduleName] : findAllModulesInRoot(absoluteRoot).moduleNames;
|
|
356
|
+
if (moduleNames.length === 0) {
|
|
357
|
+
throw new Error(
|
|
358
|
+
`No modules found in ${path3.join(absoluteRoot, "components/modules")}`
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
const require2 = createRequire(import.meta.url);
|
|
362
|
+
const viteServer = await createViteServer({
|
|
363
|
+
configFile: false,
|
|
364
|
+
logLevel: "silent",
|
|
365
|
+
appType: "custom",
|
|
366
|
+
root: absoluteRoot,
|
|
367
|
+
cacheDir: path3.join(absoluteRoot, "node_modules/.vite-validate-fields"),
|
|
368
|
+
server: { middlewareMode: true, hmr: false },
|
|
369
|
+
optimizeDeps: { noDiscovery: true, include: [] },
|
|
370
|
+
ssr: { noExternal: "@hubspot/cms-components" },
|
|
371
|
+
resolve: {
|
|
372
|
+
conditions: ["server"],
|
|
373
|
+
dedupe: ["react", "react-dom", "@hubspot/cms-components", "styled-jsx"]
|
|
374
|
+
},
|
|
375
|
+
plugins: [
|
|
376
|
+
react({
|
|
377
|
+
babel: {
|
|
378
|
+
plugins: [
|
|
379
|
+
require2.resolve("babel-plugin-styled-components"),
|
|
380
|
+
require2.resolve("styled-jsx/babel"),
|
|
381
|
+
require2.resolve("babel-plugin-macros")
|
|
382
|
+
]
|
|
383
|
+
}
|
|
384
|
+
}),
|
|
385
|
+
clientIslandEntryPlugin(),
|
|
386
|
+
resolveIslandPlugin(),
|
|
387
|
+
viteCommonjs(),
|
|
388
|
+
noncePlaceholderPlugin()
|
|
389
|
+
]
|
|
390
|
+
});
|
|
391
|
+
try {
|
|
392
|
+
return await Promise.all(
|
|
393
|
+
moduleNames.map(
|
|
394
|
+
(name) => run(`components/modules/${name}`, absoluteRoot, viteServer)
|
|
395
|
+
)
|
|
396
|
+
);
|
|
397
|
+
} finally {
|
|
398
|
+
await viteServer.close();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
async function generateModuleFields(projectRoot, moduleName) {
|
|
402
|
+
const generated = await forEachModule(
|
|
403
|
+
projectRoot,
|
|
404
|
+
moduleName,
|
|
405
|
+
generateSingleModule
|
|
406
|
+
);
|
|
407
|
+
return generated.map(({ fieldsJsonPath, fieldsJson, fieldErrors }) => ({
|
|
408
|
+
fieldsJsonPath,
|
|
409
|
+
fieldsJson: fieldsJson ?? null,
|
|
410
|
+
fieldErrors
|
|
411
|
+
}));
|
|
412
|
+
}
|
|
413
|
+
async function runModuleFieldsCli(commandName, command) {
|
|
414
|
+
const projectPath = process.argv[2];
|
|
415
|
+
const moduleIdx = process.argv.indexOf("--module");
|
|
416
|
+
const moduleName = moduleIdx !== -1 ? process.argv[moduleIdx + 1] : void 0;
|
|
417
|
+
if (!projectPath) {
|
|
418
|
+
console.error(`Usage: ${commandName} <path> [--module <name>]`);
|
|
419
|
+
process.exitCode = 1;
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
const results = await command(projectPath, moduleName);
|
|
424
|
+
console.log(JSON.stringify(results, null, 2));
|
|
425
|
+
const hasErrors = results.some(
|
|
426
|
+
(r) => r.fieldErrors.length > 0 || (r.metaErrors ?? []).length > 0
|
|
427
|
+
);
|
|
428
|
+
process.exitCode = hasErrors ? 1 : 0;
|
|
429
|
+
} catch (error) {
|
|
430
|
+
console.error("An error occurred:", error);
|
|
431
|
+
process.exitCode = 1;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// src/generateFieldsCli.ts
|
|
436
|
+
runModuleFieldsCli("generate-fields", generateModuleFields).catch((error) => {
|
|
437
|
+
throw error;
|
|
438
|
+
});
|
|
@@ -10,7 +10,7 @@ import { createServer as createViteServer } from "vite";
|
|
|
10
10
|
import { createRequire } from "module";
|
|
11
11
|
import { default as react } from "@vitejs/plugin-react";
|
|
12
12
|
|
|
13
|
-
// ../cms-js-internal/dist/types-
|
|
13
|
+
// ../cms-js-internal/dist/types-C8bPIEz4.js
|
|
14
14
|
import path from "path";
|
|
15
15
|
var viteRoot;
|
|
16
16
|
var viteCommand;
|