@blocklet/pages-kit-block-studio 0.1.4 → 0.1.5
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/lib/cjs/constants/index.js +12 -1
- package/lib/cjs/constants/new-block-template/@metadata.json +59 -0
- package/lib/cjs/constants/new-block-template/index.tsx +89 -0
- package/lib/cjs/middlewares/init-block-studio-router.js +42 -0
- package/lib/cjs/plugins/vite-plugin-html-transform.js +24 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/generate-wrapper-code.js +21 -25
- package/lib/cjs/utils/helper.js +20 -12
- package/lib/esm/constants/index.js +8 -0
- package/lib/esm/constants/new-block-template/@metadata.json +59 -0
- package/lib/esm/constants/new-block-template/index.tsx +89 -0
- package/lib/esm/middlewares/init-block-studio-router.js +43 -1
- package/lib/esm/plugins/vite-plugin-html-transform.js +24 -2
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/generate-wrapper-code.js +21 -25
- package/lib/esm/utils/helper.js +10 -6
- package/lib/types/constants/index.d.ts +7 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/helper.d.ts +2 -4
- package/package.json +9 -6
- package/tsconfig.json +3 -1
|
@@ -239,12 +239,10 @@ function getCustomComponentPropertyType(type) {
|
|
|
239
239
|
}
|
|
240
240
|
const ALLOWED_PROPERTY_TYPES = ['string', 'multiline', 'url', 'json', 'yaml'];
|
|
241
241
|
function generatePageDataTypes(state) {
|
|
242
|
-
const
|
|
242
|
+
const pageTypeDefinitions = Object.values(state.pages)
|
|
243
243
|
.map((page) => {
|
|
244
|
-
// check if the page is a template page
|
|
245
244
|
if (!page.isTemplate)
|
|
246
245
|
return null;
|
|
247
|
-
// 将 slug 转换为有效的 TypeScript 类型名
|
|
248
246
|
const typeName = `Page${page.slug
|
|
249
247
|
.replace(/^\//, '')
|
|
250
248
|
.split('/')
|
|
@@ -295,8 +293,7 @@ ${properties}
|
|
|
295
293
|
})
|
|
296
294
|
.filter(Boolean)
|
|
297
295
|
.join('\n');
|
|
298
|
-
|
|
299
|
-
export interface ${typeName} {
|
|
296
|
+
const typeDefinition = `interface ${typeName} {
|
|
300
297
|
title?: string;
|
|
301
298
|
image?: string;
|
|
302
299
|
description?: string;
|
|
@@ -304,29 +301,28 @@ export interface ${typeName} {
|
|
|
304
301
|
${sectionTypes}
|
|
305
302
|
};
|
|
306
303
|
}`;
|
|
304
|
+
return {
|
|
305
|
+
typeName,
|
|
306
|
+
typeDefinition,
|
|
307
|
+
};
|
|
307
308
|
})
|
|
308
|
-
.filter(Boolean)
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
.split('/')
|
|
318
|
-
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
|
|
319
|
-
.join('')
|
|
320
|
-
.replace(/[^a-zA-Z0-9]/g, '')}Data`;
|
|
321
|
-
return typeName;
|
|
322
|
-
})
|
|
323
|
-
.filter(Boolean)
|
|
324
|
-
.join(' | ');
|
|
309
|
+
.filter(Boolean);
|
|
310
|
+
// Generate type definitions string
|
|
311
|
+
const typeDefinitions = pageTypeDefinitions.map((def) => `export ${def === null || def === void 0 ? void 0 : def.typeDefinition}`).join('\n\n');
|
|
312
|
+
// Generate string literals for each type
|
|
313
|
+
const typeStrings = pageTypeDefinitions
|
|
314
|
+
.map((def) => `export const ${def === null || def === void 0 ? void 0 : def.typeName}String = \`${def === null || def === void 0 ? void 0 : def.typeDefinition}\`;`)
|
|
315
|
+
.join('\n\n');
|
|
316
|
+
// Generate union type
|
|
317
|
+
const pageUnionTypes = pageTypeDefinitions.map((def) => def === null || def === void 0 ? void 0 : def.typeName).join(' | ');
|
|
325
318
|
return `
|
|
326
|
-
//
|
|
327
|
-
${
|
|
319
|
+
// Page data type definitions
|
|
320
|
+
${typeDefinitions}
|
|
321
|
+
|
|
322
|
+
// String versions of type definitions
|
|
323
|
+
${typeStrings}
|
|
328
324
|
|
|
329
|
-
//
|
|
325
|
+
// Union type of all page data types
|
|
330
326
|
export type PageDataUnion = ${pageUnionTypes || 'never'};`;
|
|
331
327
|
}
|
|
332
328
|
export default generateWrapperCode;
|
package/lib/esm/utils/helper.js
CHANGED
|
@@ -17,13 +17,9 @@ import path, { basename, dirname } from 'path';
|
|
|
17
17
|
import { pipeline } from 'stream/promises';
|
|
18
18
|
import { joinURL } from 'ufo';
|
|
19
19
|
import * as yaml from 'yaml';
|
|
20
|
-
import { PAGES_KIT_BLOCK_STUDIO_DID } from '../constants';
|
|
20
|
+
import { PAGES_KIT_BLOCK_STUDIO_DID, METADATA_FILE_NAME, PREVIEW_IMAGE_DIR, NANOID_LENGTH, DEFAULT_BLOCK_ENTRY_FILES_PATTERN, } from '../constants';
|
|
21
|
+
export * from '../constants';
|
|
21
22
|
export const logger = console;
|
|
22
|
-
export const libDir = 'lib';
|
|
23
|
-
export const METADATA_FILE_NAME = '@metadata.json';
|
|
24
|
-
export const PREVIEW_IMAGE_DIR = '@preview-images';
|
|
25
|
-
export const NANOID_LENGTH = 16;
|
|
26
|
-
const DEFAULT_BLOCK_ENTRY_FILES_PATTERN = 'src/**/index.{ts,tsx,html}';
|
|
27
23
|
if (!process.env.BLOCK_ENTRY_FILES_PATTERN) {
|
|
28
24
|
process.env.BLOCK_ENTRY_FILES_PATTERN = DEFAULT_BLOCK_ENTRY_FILES_PATTERN;
|
|
29
25
|
}
|
|
@@ -176,3 +172,11 @@ export const getBlockCode = (filePath) => {
|
|
|
176
172
|
}
|
|
177
173
|
return fs.readFileSync(codeFile, 'utf8');
|
|
178
174
|
};
|
|
175
|
+
export const safeParse = (text) => {
|
|
176
|
+
try {
|
|
177
|
+
return JSON.parse(text);
|
|
178
|
+
}
|
|
179
|
+
catch (_a) {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
@@ -4,3 +4,10 @@ export declare const PAGES_KIT_BLOCK_STUDIO_DID = "z2qa7rr3eUyVnWp2PCxEVARuUfLFh
|
|
|
4
4
|
export declare const PAGES_KIT_BLOCK_STUDIO_RESOURCE_TYPE = "page";
|
|
5
5
|
export declare const MEDIA_KIT_DID = "z8ia1mAXo8ZE7ytGF36L5uBf9kD2kenhqFGp9";
|
|
6
6
|
export declare const MEDIA_KIT_RESOURCE_TYPE = "imgpack";
|
|
7
|
+
export declare const NEW_BLOCK_TEMPLATE_PATH: string;
|
|
8
|
+
export declare const NEW_BLOCK_TEMPLATE_METADATA_PATH: string;
|
|
9
|
+
export declare const libDir = "lib";
|
|
10
|
+
export declare const METADATA_FILE_NAME = "@metadata.json";
|
|
11
|
+
export declare const PREVIEW_IMAGE_DIR = "@preview-images";
|
|
12
|
+
export declare const NANOID_LENGTH = 16;
|
|
13
|
+
export declare const DEFAULT_BLOCK_ENTRY_FILES_PATTERN = "src/**/index.{ts,tsx,html}";
|