@blocklet/pages-kit-block-studio 0.4.133 → 0.4.135
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 +27 -5
- package/lib/cjs/middlewares/init-uploader-router.js +12 -1
- package/lib/cjs/plugins/_theme.js +1 -8
- package/lib/cjs/plugins/vite-plugin-block-studio.js +15 -6
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/helper.js +15 -6
- package/lib/esm/middlewares/init-block-studio-router.js +27 -5
- package/lib/esm/middlewares/init-uploader-router.js +13 -2
- package/lib/esm/plugins/_theme.js +2 -9
- package/lib/esm/plugins/vite-plugin-block-studio.js +16 -7
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/helper.js +14 -6
- package/lib/types/plugins/vite-plugin-block-studio.d.ts +1 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/helper.d.ts +3 -1
- package/package.json +8 -7
package/lib/esm/utils/helper.js
CHANGED
|
@@ -32,15 +32,18 @@ export function setBlockEntryFilesPattern(pattern) {
|
|
|
32
32
|
export function getBlockEntryFilesPattern() {
|
|
33
33
|
return process.env.BLOCK_ENTRY_FILES_PATTERN || DEFAULT_BLOCK_ENTRY_FILES_PATTERN;
|
|
34
34
|
}
|
|
35
|
+
export function getWatchFilesDir() {
|
|
36
|
+
return process.env.WATCH_FILES_DIR;
|
|
37
|
+
}
|
|
35
38
|
export function findComponentFiles(options = {}) {
|
|
36
|
-
const { cwd = process.cwd(), filter } = options;
|
|
39
|
+
const { cwd = process.cwd(), filter, strictExist = true } = options;
|
|
37
40
|
const files = globSync(getBlockEntryFilesPattern(), { cwd });
|
|
38
41
|
return files
|
|
39
42
|
.map((file) => {
|
|
40
43
|
const blockName = getBlockName(file);
|
|
41
44
|
const fullPath = path.resolve(cwd, file);
|
|
42
45
|
const isHtml = file.endsWith('.html');
|
|
43
|
-
const metadata = initializeMetadata(fullPath);
|
|
46
|
+
const metadata = initializeMetadata(fullPath, strictExist);
|
|
44
47
|
return {
|
|
45
48
|
file,
|
|
46
49
|
blockName,
|
|
@@ -49,7 +52,7 @@ export function findComponentFiles(options = {}) {
|
|
|
49
52
|
metadata,
|
|
50
53
|
};
|
|
51
54
|
})
|
|
52
|
-
.filter(({ blockName }) => !filter?.length || filter.includes(blockName || ''));
|
|
55
|
+
.filter(({ blockName, metadata }) => metadata?.id && (!filter?.length || filter.includes(blockName || '')));
|
|
53
56
|
}
|
|
54
57
|
export function getBlockName(entry) {
|
|
55
58
|
// First try to match index.{ts,tsx,html} pattern
|
|
@@ -68,8 +71,10 @@ export function getBlockName(entry) {
|
|
|
68
71
|
}
|
|
69
72
|
export const isPathSafe = (filePath) => {
|
|
70
73
|
const normalizedPath = path.normalize(filePath);
|
|
71
|
-
const
|
|
72
|
-
return (!normalizedPath.includes('../') &&
|
|
74
|
+
const watchFilesDir = getWatchFilesDir() || process.cwd();
|
|
75
|
+
return (!normalizedPath.includes('../') &&
|
|
76
|
+
!normalizedPath.includes('..\\') &&
|
|
77
|
+
path.resolve(normalizedPath).startsWith(watchFilesDir));
|
|
73
78
|
};
|
|
74
79
|
export const isDev = process.env.BLOCKLET_MODE === 'development';
|
|
75
80
|
export const isMetadataFile = (filePath) => {
|
|
@@ -104,7 +109,7 @@ export const downloadAsset = async ({ asset, savePath, componentDid, }) => {
|
|
|
104
109
|
export const getPreviewImageRelativePath = (name) => {
|
|
105
110
|
return path.join(PREVIEW_IMAGE_DIR, name);
|
|
106
111
|
};
|
|
107
|
-
export function initializeMetadata(tempFilePath) {
|
|
112
|
+
export function initializeMetadata(tempFilePath, strictExist = false) {
|
|
108
113
|
let content = '';
|
|
109
114
|
if (!tempFilePath) {
|
|
110
115
|
throw new Error('File path is required');
|
|
@@ -117,6 +122,9 @@ export function initializeMetadata(tempFilePath) {
|
|
|
117
122
|
if (fs.existsSync(filePath)) {
|
|
118
123
|
content = fs.readFileSync(filePath, 'utf-8');
|
|
119
124
|
}
|
|
125
|
+
else if (strictExist) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
120
128
|
let metadata = {};
|
|
121
129
|
if (content) {
|
|
122
130
|
try {
|