@blocklet/pages-kit-block-studio 0.4.142 → 0.4.143
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/middlewares/init-block-studio-router.js +6 -2
- package/lib/cjs/middlewares/init-resource-router.js +2 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/helper.js +4 -4
- package/lib/esm/middlewares/init-block-studio-router.js +6 -2
- package/lib/esm/middlewares/init-resource-router.js +2 -2
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/helper.js +4 -4
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/helper.d.ts +2 -2
- package/package.json +6 -6
package/lib/cjs/utils/helper.js
CHANGED
|
@@ -86,14 +86,14 @@ function getWatchFilesDir() {
|
|
|
86
86
|
return process.env.WATCH_FILES_DIR;
|
|
87
87
|
}
|
|
88
88
|
function findComponentFiles(options = {}) {
|
|
89
|
-
const { cwd = process.cwd(), filter,
|
|
89
|
+
const { cwd = process.cwd(), filter, strictExistMetadata = false } = options;
|
|
90
90
|
const files = (0, glob_1.globSync)(getBlockEntryFilesPattern(), { cwd });
|
|
91
91
|
return files
|
|
92
92
|
.map((file) => {
|
|
93
93
|
const blockName = getBlockName(file);
|
|
94
94
|
const fullPath = path_1.default.resolve(cwd, file);
|
|
95
95
|
const isHtml = file.endsWith('.html');
|
|
96
|
-
const metadata = initializeMetadata(fullPath,
|
|
96
|
+
const metadata = initializeMetadata(fullPath, strictExistMetadata);
|
|
97
97
|
return {
|
|
98
98
|
file,
|
|
99
99
|
blockName,
|
|
@@ -163,7 +163,7 @@ const getPreviewImageRelativePath = (name) => {
|
|
|
163
163
|
return path_1.default.join(constants_1.PREVIEW_IMAGE_DIR, name);
|
|
164
164
|
};
|
|
165
165
|
exports.getPreviewImageRelativePath = getPreviewImageRelativePath;
|
|
166
|
-
function initializeMetadata(tempFilePath,
|
|
166
|
+
function initializeMetadata(tempFilePath, strictExistMetadata = false) {
|
|
167
167
|
let content = '';
|
|
168
168
|
if (!tempFilePath) {
|
|
169
169
|
throw new Error('File path is required');
|
|
@@ -176,7 +176,7 @@ function initializeMetadata(tempFilePath, strictExist = false) {
|
|
|
176
176
|
if (fs_1.default.existsSync(filePath)) {
|
|
177
177
|
content = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
178
178
|
}
|
|
179
|
-
else if (
|
|
179
|
+
else if (strictExistMetadata) {
|
|
180
180
|
return null;
|
|
181
181
|
}
|
|
182
182
|
let metadata = {};
|
|
@@ -180,7 +180,9 @@ initBlockStudioRouter.post('/create', async (req, res) => {
|
|
|
180
180
|
});
|
|
181
181
|
initBlockStudioRouter.get('/resources', async (req, res) => {
|
|
182
182
|
const { withBlockletData = true } = req.query;
|
|
183
|
-
const allBlocks = await findComponentFiles(
|
|
183
|
+
const allBlocks = await findComponentFiles({
|
|
184
|
+
strictExistMetadata: true,
|
|
185
|
+
});
|
|
184
186
|
// get code to metadata
|
|
185
187
|
const allBlocksWithCode = allBlocks.map((block) => {
|
|
186
188
|
const code = getBlockCode(block.fullPath);
|
|
@@ -208,7 +210,9 @@ initBlockStudioRouter.get('/resources', async (req, res) => {
|
|
|
208
210
|
return res.json(keyBy(allBlocksWithCode, 'id'));
|
|
209
211
|
});
|
|
210
212
|
initBlockStudioRouter.get('/components', async (_req, res) => {
|
|
211
|
-
const allBlocks = await findComponentFiles(
|
|
213
|
+
const allBlocks = await findComponentFiles({
|
|
214
|
+
strictExistMetadata: true,
|
|
215
|
+
});
|
|
212
216
|
return res.json(allBlocks);
|
|
213
217
|
});
|
|
214
218
|
// 统一的属性到接口转换端点 - 可以预览或生成
|
|
@@ -55,7 +55,7 @@ export const initResourceRouter = Router();
|
|
|
55
55
|
initResourceRouter.get('/', async (_req, res) => {
|
|
56
56
|
const resources = [];
|
|
57
57
|
const rootDir = process.cwd();
|
|
58
|
-
const files = findComponentFiles({ cwd: rootDir });
|
|
58
|
+
const files = findComponentFiles({ cwd: rootDir, strictExistMetadata: true });
|
|
59
59
|
for (const file of files) {
|
|
60
60
|
// const filePath = path.join(rootDir, file);
|
|
61
61
|
// const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
@@ -134,7 +134,7 @@ initResourceRouter.post('/', async (req, res) => {
|
|
|
134
134
|
const chunksMapPath = join(codeDir, 'chunks-map.json');
|
|
135
135
|
const chunksMap = JSON.parse(fs.readFileSync(chunksMapPath, 'utf8'));
|
|
136
136
|
// get @metadata.json by glob
|
|
137
|
-
const canUseComponents = findComponentFiles({ cwd: rootDir, filter: componentIds });
|
|
137
|
+
const canUseComponents = findComponentFiles({ cwd: rootDir, filter: componentIds, strictExistMetadata: true });
|
|
138
138
|
// Filter and process metadata files
|
|
139
139
|
const metadataList = canUseComponents.map(({ fullPath, blockName, metadata: _metadata }) => {
|
|
140
140
|
// get metadata
|