@blocklet/pages-kit-block-studio 0.4.66 → 0.4.68

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.
@@ -47,6 +47,7 @@ const constants_1 = require("../constants");
47
47
  // 导入Zod相关工具
48
48
  const block_props_utils_1 = require("../utils/block-props-utils");
49
49
  const helper_1 = require("../utils/helper");
50
+ const ts_morph_utils_1 = require("../utils/ts-morph-utils");
50
51
  const zod_utils_1 = require("../utils/zod-utils");
51
52
  exports.initBlockStudioRouter = (0, express_1.Router)();
52
53
  const BINARY_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico', '.svg'];
@@ -121,7 +122,7 @@ exports.initBlockStudioRouter.post('/', async (req, res) => {
121
122
  try {
122
123
  const dir = path_1.default.dirname(filePath);
123
124
  if (!fs_1.default.existsSync(dir)) {
124
- fs_1.default.mkdirSync(dir, { recursive: true });
125
+ throw new Error('Directory not found');
125
126
  }
126
127
  const currentMetadata = (0, helper_1.initializeMetadata)(filePath);
127
128
  const mergedContent = { ...currentMetadata, ...content };
@@ -191,7 +192,7 @@ exports.initBlockStudioRouter.post('/create', async (req, res) => {
191
192
  return res.status(500).json({ error: 'Failed to create block' });
192
193
  }
193
194
  });
194
- exports.initBlockStudioRouter.get('/all', async (req, res) => {
195
+ exports.initBlockStudioRouter.get('/resources', async (req, res) => {
195
196
  const { withBlockletData = true } = req.query;
196
197
  const allBlocks = await (0, helper_1.findComponentFiles)();
197
198
  // get code to metadata
@@ -220,6 +221,10 @@ exports.initBlockStudioRouter.get('/all', async (req, res) => {
220
221
  }
221
222
  return res.json((0, lodash_1.keyBy)(allBlocksWithCode, 'id'));
222
223
  });
224
+ exports.initBlockStudioRouter.get('/components', async (_req, res) => {
225
+ const allBlocks = await (0, helper_1.findComponentFiles)();
226
+ return res.json(allBlocks);
227
+ });
223
228
  // 统一的属性到接口转换端点 - 可以预览或生成
224
229
  exports.initBlockStudioRouter.post('/properties-to-interface', async (req, res) => {
225
230
  const write = req.body.write === true;
@@ -308,7 +313,13 @@ exports.initBlockStudioRouter.post('/interface-to-properties', async (req, res)
308
313
  return res.status(404).json({ success: false, error: 'BlockProps interface not found or could not be parsed' });
309
314
  }
310
315
  try {
311
- const newProperties = await (0, zod_utils_1.tsFileInterfaceToProperties)(componentPath, 'BlockProps', currentMetadata.properties || {});
316
+ const zodSchema = await (0, ts_morph_utils_1.tsFileToZodSchema)(componentPath, 'BlockProps');
317
+ const jsonSchema = (0, zod_utils_1.zodSchemaToJsonSchema)(zodSchema);
318
+ const newProperties = (0, zod_utils_1.jsonSchemaToProperties)(jsonSchema, {
319
+ existingProperties: currentMetadata.properties || {},
320
+ key: '',
321
+ isRoot: true,
322
+ });
312
323
  // 如果请求要求写入文件
313
324
  if (write) {
314
325
  // 更新元数据