@blocklet/pages-kit-block-studio 0.4.32 → 0.4.33
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/components/create-resource.js +2 -2
- package/lib/cjs/constants/new-block-template/index.js +2 -14
- package/lib/cjs/middlewares/init-block-studio-router.js +15 -21
- package/lib/cjs/middlewares/init-resource-router.js +34 -42
- package/lib/cjs/plugins/vite-plugin-block-studio.js +107 -86
- package/lib/cjs/plugins/vite-plugin-html-transform.js +13 -24
- package/lib/cjs/plugins/vite-plugin-remote-script-localizer.js +87 -103
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/build-lib.js +62 -74
- package/lib/cjs/utils/generate-wrapper-code.js +366 -120
- package/lib/cjs/utils/helper.js +9 -19
- package/lib/esm/components/create-resource.js +2 -2
- package/lib/esm/constants/new-block-template/index.js +2 -14
- package/lib/esm/middlewares/init-block-studio-router.js +15 -21
- package/lib/esm/middlewares/init-resource-router.js +34 -42
- package/lib/esm/plugins/vite-plugin-block-studio.js +107 -86
- package/lib/esm/plugins/vite-plugin-html-transform.js +13 -24
- package/lib/esm/plugins/vite-plugin-remote-script-localizer.js +87 -103
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/build-lib.js +62 -74
- package/lib/esm/utils/generate-wrapper-code.js +366 -120
- package/lib/esm/utils/helper.js +9 -19
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -22,11 +22,11 @@ function CreateResource({ open, onClose, blockletDid, mode, }) {
|
|
|
22
22
|
},
|
|
23
23
|
}
|
|
24
24
|
: {};
|
|
25
|
-
return ((0, jsx_runtime_1.jsx)(material_1.Box,
|
|
25
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { ...boxProps, children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { children: (0, jsx_runtime_1.jsx)(ui_react_1.BlockletStudio, { mode: mode, tenantScope: tenantScope, title: "Pages Kit Blocks", description: "", note: "", introduction: "", logo: "", componentDid: blockletDid,
|
|
26
26
|
// 透传到 get blocklet resource 的参数
|
|
27
27
|
resourcesParams: {}, dependentComponentsMode: "readonly", open: true, setOpen: () => onClose(), onConnected: () => { }, onUploaded: () => { }, onReleased: () => { },
|
|
28
28
|
// onOpened={() => onOpened?.()}
|
|
29
29
|
// 默认选中的资源
|
|
30
|
-
resources: {} }) }) }))
|
|
30
|
+
resources: {} }) }) }));
|
|
31
31
|
}
|
|
32
32
|
exports.default = CreateResource;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.EditComponent = void 0;
|
|
15
4
|
exports.default = HelloWorld;
|
|
@@ -34,8 +23,7 @@ function HelloWorld({ title = 'Hello World', logo, description, copyright }) {
|
|
|
34
23
|
}, children: copyright }))] }));
|
|
35
24
|
}
|
|
36
25
|
// export edit component
|
|
37
|
-
const EditComponent = (
|
|
38
|
-
var { onChange } = _a, props = __rest(_a, ["onChange"]);
|
|
26
|
+
const EditComponent = ({ onChange, ...props }) => {
|
|
39
27
|
return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', gap: '16px' }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
|
|
40
28
|
fontSize: '14px',
|
|
41
29
|
fontWeight: 500,
|
|
@@ -50,6 +38,6 @@ const EditComponent = (_a) => {
|
|
|
50
38
|
fontSize: '14px',
|
|
51
39
|
transition: 'border-color 0.3s',
|
|
52
40
|
outline: 'none',
|
|
53
|
-
}, value: props.copyright || '', onChange: (e) => onChange
|
|
41
|
+
}, value: props.copyright || '', onChange: (e) => onChange?.({ copyright: e.target.value }), placeholder: "Please Input Copyright" })] }));
|
|
54
42
|
};
|
|
55
43
|
exports.EditComponent = EditComponent;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -21,7 +12,7 @@ const constants_1 = require("../constants");
|
|
|
21
12
|
const helper_1 = require("../utils/helper");
|
|
22
13
|
exports.initBlockStudioRouter = (0, express_1.Router)();
|
|
23
14
|
const BINARY_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.webp', '.ico', '.svg'];
|
|
24
|
-
exports.initBlockStudioRouter.get('/', (req, res) =>
|
|
15
|
+
exports.initBlockStudioRouter.get('/', async (req, res) => {
|
|
25
16
|
if (!helper_1.isDev) {
|
|
26
17
|
return res.status(403).json({ error: 'Only available in development mode' });
|
|
27
18
|
}
|
|
@@ -49,8 +40,8 @@ exports.initBlockStudioRouter.get('/', (req, res) => __awaiter(void 0, void 0, v
|
|
|
49
40
|
catch (error) {
|
|
50
41
|
return res.status(500).json({ error: 'Failed to read file' });
|
|
51
42
|
}
|
|
52
|
-
})
|
|
53
|
-
exports.initBlockStudioRouter.post('/', (req, res) =>
|
|
43
|
+
});
|
|
44
|
+
exports.initBlockStudioRouter.post('/', async (req, res) => {
|
|
54
45
|
if (!helper_1.isDev) {
|
|
55
46
|
return res.status(403).json({ error: 'Only available in development mode' });
|
|
56
47
|
}
|
|
@@ -67,7 +58,7 @@ exports.initBlockStudioRouter.post('/', (req, res) => __awaiter(void 0, void 0,
|
|
|
67
58
|
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
68
59
|
}
|
|
69
60
|
const currentMetadata = (0, helper_1.initializeMetadata)(filePath);
|
|
70
|
-
const mergedContent =
|
|
61
|
+
const mergedContent = { ...currentMetadata, ...content };
|
|
71
62
|
if ((0, lodash_1.isEqual)(currentMetadata, mergedContent)) {
|
|
72
63
|
return res.json({ success: true, content: mergedContent, message: 'No changes' });
|
|
73
64
|
}
|
|
@@ -76,7 +67,7 @@ exports.initBlockStudioRouter.post('/', (req, res) => __awaiter(void 0, void 0,
|
|
|
76
67
|
if ((0, helper_1.isMetadataFile)(filePath) && content.previewImage && currentMetadata.previewImage !== content.previewImage) {
|
|
77
68
|
const previewImagePath = path_1.default.join(dir, (0, helper_1.getPreviewImageRelativePath)(content.previewImage));
|
|
78
69
|
if (!fs_1.default.existsSync(previewImagePath)) {
|
|
79
|
-
|
|
70
|
+
await (0, helper_1.downloadAsset)({
|
|
80
71
|
asset: content.previewImage,
|
|
81
72
|
savePath: previewImagePath,
|
|
82
73
|
componentDid: process.env.BLOCKLET_COMPONENT_DID || '',
|
|
@@ -89,8 +80,8 @@ exports.initBlockStudioRouter.post('/', (req, res) => __awaiter(void 0, void 0,
|
|
|
89
80
|
catch (error) {
|
|
90
81
|
return res.status(500).json({ error: 'Failed to write file' });
|
|
91
82
|
}
|
|
92
|
-
})
|
|
93
|
-
exports.initBlockStudioRouter.post('/create', (req, res) =>
|
|
83
|
+
});
|
|
84
|
+
exports.initBlockStudioRouter.post('/create', async (req, res) => {
|
|
94
85
|
if (!helper_1.isDev) {
|
|
95
86
|
return res.status(403).json({ error: 'Only available in development mode' });
|
|
96
87
|
}
|
|
@@ -118,7 +109,10 @@ exports.initBlockStudioRouter.post('/create', (req, res) => __awaiter(void 0, vo
|
|
|
118
109
|
metadata.updatedAt = new Date().toISOString();
|
|
119
110
|
// get template metadata from @metadata.json
|
|
120
111
|
const metadataContent = fs_1.default.readFileSync(constants_1.NEW_BLOCK_TEMPLATE_METADATA_PATH, 'utf-8');
|
|
121
|
-
metadata =
|
|
112
|
+
metadata = {
|
|
113
|
+
...metadata,
|
|
114
|
+
...(0, helper_1.safeParse)(metadataContent),
|
|
115
|
+
};
|
|
122
116
|
// Write metadata file
|
|
123
117
|
fs_1.default.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
|
|
124
118
|
// Copy template file to index.tsx
|
|
@@ -130,10 +124,10 @@ exports.initBlockStudioRouter.post('/create', (req, res) => __awaiter(void 0, vo
|
|
|
130
124
|
console.error('Failed to create block:', error);
|
|
131
125
|
return res.status(500).json({ error: 'Failed to create block' });
|
|
132
126
|
}
|
|
133
|
-
})
|
|
134
|
-
exports.initBlockStudioRouter.get('/all', (req, res) =>
|
|
127
|
+
});
|
|
128
|
+
exports.initBlockStudioRouter.get('/all', async (req, res) => {
|
|
135
129
|
const { withBlockletData = true } = req.query;
|
|
136
|
-
const allBlocks =
|
|
130
|
+
const allBlocks = await (0, helper_1.findComponentFiles)();
|
|
137
131
|
// get code to metadata
|
|
138
132
|
const allBlocksWithCode = allBlocks.map((block) => {
|
|
139
133
|
const code = (0, helper_1.getBlockCode)(block.fullPath);
|
|
@@ -159,5 +153,5 @@ exports.initBlockStudioRouter.get('/all', (req, res) => __awaiter(void 0, void 0
|
|
|
159
153
|
return res.json((0, lodash_1.keyBy)(allBlocksWithBlockletData, 'data.id'));
|
|
160
154
|
}
|
|
161
155
|
return res.json((0, lodash_1.keyBy)(allBlocksWithCode, 'id'));
|
|
162
|
-
})
|
|
156
|
+
});
|
|
163
157
|
exports.default = exports.initBlockStudioRouter;
|
|
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
37
|
};
|
|
@@ -71,34 +62,30 @@ function copyFile(src, dest) {
|
|
|
71
62
|
readStream.pipe(writeStream);
|
|
72
63
|
});
|
|
73
64
|
}
|
|
74
|
-
function copyDirectory(src, dest) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
yield copyDirectory(srcPath, destPath);
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
// eslint-disable-next-line no-await-in-loop
|
|
87
|
-
yield copyFile(srcPath, destPath);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function copyRecursive(src, dest) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const srcStats = yield fs_1.default.promises.stat(src);
|
|
95
|
-
if (srcStats.isDirectory()) {
|
|
96
|
-
yield copyDirectory(src, dest);
|
|
65
|
+
async function copyDirectory(src, dest) {
|
|
66
|
+
await fs_1.default.promises.mkdir(dest, { recursive: true });
|
|
67
|
+
const entries = await fs_1.default.promises.readdir(src, { withFileTypes: true });
|
|
68
|
+
for (const entry of entries) {
|
|
69
|
+
const srcPath = path_1.default.join(src, entry.name);
|
|
70
|
+
const destPath = path_1.default.join(dest, entry.name);
|
|
71
|
+
if (entry.isDirectory()) {
|
|
72
|
+
// eslint-disable-next-line no-await-in-loop
|
|
73
|
+
await copyDirectory(srcPath, destPath);
|
|
97
74
|
}
|
|
98
75
|
else {
|
|
99
|
-
|
|
76
|
+
// eslint-disable-next-line no-await-in-loop
|
|
77
|
+
await copyFile(srcPath, destPath);
|
|
100
78
|
}
|
|
101
|
-
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function copyRecursive(src, dest) {
|
|
82
|
+
const srcStats = await fs_1.default.promises.stat(src);
|
|
83
|
+
if (srcStats.isDirectory()) {
|
|
84
|
+
await copyDirectory(src, dest);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
await copyFile(src, dest);
|
|
88
|
+
}
|
|
102
89
|
}
|
|
103
90
|
const getExportDir = (projectId, releaseId) => {
|
|
104
91
|
const exportDir = (0, component_1.getResourceExportDir)({ projectId, releaseId });
|
|
@@ -106,7 +93,7 @@ const getExportDir = (projectId, releaseId) => {
|
|
|
106
93
|
return dir;
|
|
107
94
|
};
|
|
108
95
|
exports.initResourceRouter = (0, express_1.Router)();
|
|
109
|
-
exports.initResourceRouter.get('/', (_req, res) =>
|
|
96
|
+
exports.initResourceRouter.get('/', async (_req, res) => {
|
|
110
97
|
const resources = [];
|
|
111
98
|
const rootDir = process.cwd();
|
|
112
99
|
const files = (0, helper_1.findComponentFiles)({ cwd: rootDir });
|
|
@@ -134,8 +121,8 @@ exports.initResourceRouter.get('/', (_req, res) => __awaiter(void 0, void 0, voi
|
|
|
134
121
|
},
|
|
135
122
|
],
|
|
136
123
|
});
|
|
137
|
-
})
|
|
138
|
-
exports.initResourceRouter.post('/', (req, res) =>
|
|
124
|
+
});
|
|
125
|
+
exports.initResourceRouter.post('/', async (req, res) => {
|
|
139
126
|
const { resources, projectId, releaseId } = req.body;
|
|
140
127
|
// ignore all tag
|
|
141
128
|
const componentIds = resources.filter((resource) => resource.id !== allTag);
|
|
@@ -149,11 +136,16 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
|
|
|
149
136
|
const buildProcess = (0, child_process_1.spawn)('pnpm', ['run', 'build-lib'], {
|
|
150
137
|
stdio: 'inherit',
|
|
151
138
|
shell: true,
|
|
152
|
-
env:
|
|
139
|
+
env: {
|
|
140
|
+
...process.env,
|
|
141
|
+
FORCE_COLOR: '1',
|
|
142
|
+
BLOCK_FILTER: componentIds.join(','),
|
|
143
|
+
NODE_OPTIONS: '--max_old_space_size=16384',
|
|
144
|
+
},
|
|
153
145
|
});
|
|
154
146
|
// save current build process
|
|
155
147
|
currentBuildProcess = buildProcess;
|
|
156
|
-
|
|
148
|
+
await new Promise((resolve, reject) => {
|
|
157
149
|
buildProcess.on('close', (code) => {
|
|
158
150
|
if (code === 0)
|
|
159
151
|
resolve(null);
|
|
@@ -205,7 +197,7 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
|
|
|
205
197
|
return metadata;
|
|
206
198
|
});
|
|
207
199
|
// cp _chunks dir
|
|
208
|
-
|
|
200
|
+
await copyRecursive((0, path_1.join)(codeDir, '_chunks'), chunksDir);
|
|
209
201
|
// write pages.config.yml
|
|
210
202
|
const pagesConfigPath = path_1.default.join(tmpPackage, '.blocklet/pages/pages.config.yml');
|
|
211
203
|
fs_1.default.mkdirSync(path_1.default.dirname(pagesConfigPath), { recursive: true });
|
|
@@ -221,7 +213,7 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
|
|
|
221
213
|
};
|
|
222
214
|
fs_1.default.writeFileSync(pagesConfigPath, (0, helper_1.generateYaml)(pagesConfig));
|
|
223
215
|
helper_1.logger.info('generate resource blocklet block count:', metadataList.length);
|
|
224
|
-
|
|
216
|
+
await copyRecursive(tmpPackage, dir);
|
|
225
217
|
// remove tmpPackage
|
|
226
218
|
// fs.rmSync(tmpPackage, { recursive: true, force: true });
|
|
227
219
|
res.json({ success: true });
|
|
@@ -230,5 +222,5 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
|
|
|
230
222
|
console.error('Build failed:', error);
|
|
231
223
|
res.status(500).json({ error: 'Build failed' });
|
|
232
224
|
}
|
|
233
|
-
})
|
|
225
|
+
});
|
|
234
226
|
exports.default = exports.initResourceRouter;
|
|
@@ -32,15 +32,6 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
37
|
};
|
|
@@ -96,17 +87,16 @@ const defaultBlockExternals = {
|
|
|
96
87
|
'@blocklet/pages-kit': '@blocklet/pages-kit',
|
|
97
88
|
};
|
|
98
89
|
function initBlockStudioPlugins(options) {
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const transpileBuiltinModule = (_a = options === null || options === void 0 ? void 0 : options.transpileBuiltinModule) !== null && _a !== void 0 ? _a : true;
|
|
90
|
+
const workingDir = options?.cwd || process.cwd();
|
|
91
|
+
const entryFilesPattern = options?.entryFilesPattern || (0, helper_1.getBlockEntryFilesPattern)();
|
|
92
|
+
const transpileBuiltinModule = options?.transpileBuiltinModule ?? true;
|
|
103
93
|
// 处理 blockExternals 参数
|
|
104
94
|
let externalMappings = defaultBlockExternals;
|
|
105
|
-
if (typeof
|
|
95
|
+
if (typeof options?.blockExternals === 'function') {
|
|
106
96
|
// 如果是函数,则调用它并传入默认值
|
|
107
97
|
externalMappings = options.blockExternals(defaultBlockExternals);
|
|
108
98
|
}
|
|
109
|
-
else if (options
|
|
99
|
+
else if (options?.blockExternals) {
|
|
110
100
|
// 如果是对象,直接使用
|
|
111
101
|
externalMappings = options.blockExternals;
|
|
112
102
|
}
|
|
@@ -125,7 +115,7 @@ function initBlockStudioPlugins(options) {
|
|
|
125
115
|
const externalGlobalMappings = Object.fromEntries(Object.entries(externalMappings).filter(([, value]) => value.startsWith('window.') && value.length > 0));
|
|
126
116
|
const globalsMappings = Object.fromEntries(Object.entries(externalMappings)
|
|
127
117
|
.map(([key, value]) => {
|
|
128
|
-
if (!
|
|
118
|
+
if (!value?.length) {
|
|
129
119
|
return [];
|
|
130
120
|
}
|
|
131
121
|
// 移除 "window." 前缀并转换为首字母大写的驼峰式
|
|
@@ -135,7 +125,7 @@ function initBlockStudioPlugins(options) {
|
|
|
135
125
|
})
|
|
136
126
|
.filter((item) => item.length > 0));
|
|
137
127
|
const filterModules = process.argv.includes('--filter')
|
|
138
|
-
?
|
|
128
|
+
? process.argv[process.argv.indexOf('--filter') + 1]?.split(',')
|
|
139
129
|
: null;
|
|
140
130
|
const entryList = (0, helper_1.findComponentFiles)({ cwd: workingDir })
|
|
141
131
|
.map((entry) => {
|
|
@@ -151,7 +141,7 @@ function initBlockStudioPlugins(options) {
|
|
|
151
141
|
.filter(([blockName]) => !filterModules || filterModules.includes(blockName || ''));
|
|
152
142
|
// @ts-ignore
|
|
153
143
|
const multiMode = entryList.length > 1;
|
|
154
|
-
const formats =
|
|
144
|
+
const formats = options?.formats || ['es', multiMode ? 'cjs' : 'umd'];
|
|
155
145
|
// @ts-ignore
|
|
156
146
|
return [
|
|
157
147
|
// {
|
|
@@ -176,89 +166,120 @@ function initBlockStudioPlugins(options) {
|
|
|
176
166
|
apply: 'build',
|
|
177
167
|
enforce: 'pre',
|
|
178
168
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
179
|
-
config(_config) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
169
|
+
async config(_config) {
|
|
170
|
+
const name = await Promise.resolve(`${`${workingDir}/package.json`}`).then(s => __importStar(require(s))).then((res) => res.name).catch(() => 'MyLib');
|
|
171
|
+
return {
|
|
172
|
+
resolve: {
|
|
173
|
+
alias: {
|
|
174
|
+
// crypto: 'crypto-browserify',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
optimizeDeps: {
|
|
178
|
+
// include: ['crypto-browserify'],
|
|
179
|
+
},
|
|
180
|
+
build: {
|
|
181
|
+
..._config?.build,
|
|
182
|
+
// sourcemap: true,
|
|
183
|
+
cssCodeSplit: true,
|
|
184
|
+
lib: {
|
|
185
|
+
name,
|
|
186
|
+
entry: {
|
|
187
|
+
...Object.fromEntries(entryList),
|
|
187
188
|
},
|
|
189
|
+
formats,
|
|
190
|
+
fileName: (format, entryName) => `${format}/${entryName}.js`,
|
|
188
191
|
},
|
|
189
|
-
|
|
190
|
-
|
|
192
|
+
terserOptions: {
|
|
193
|
+
// 保留导出名
|
|
194
|
+
keep_fnames: true,
|
|
195
|
+
keep_classnames: true,
|
|
191
196
|
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
197
|
+
rollupOptions: {
|
|
198
|
+
..._config?.build?.rollupOptions,
|
|
199
|
+
external: _config?.build?.rollupOptions?.external ||
|
|
200
|
+
((id) => {
|
|
201
|
+
// 是否匹配后缀
|
|
202
|
+
const isMatchAfterSlash = false;
|
|
203
|
+
const skipList = [...Object.keys(externalMappings)];
|
|
204
|
+
if (skipList.some((item) => (isMatchAfterSlash && id.startsWith(`${item}/`)) || id === item)) {
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
return false;
|
|
208
|
+
}),
|
|
209
|
+
treeshake: true,
|
|
210
|
+
output: {
|
|
211
|
+
..._config?.build?.rollupOptions?.output,
|
|
212
|
+
chunkFileNames: () => {
|
|
213
|
+
return '[format]/_chunks/[name]-[hash].js';
|
|
214
|
+
},
|
|
215
|
+
// 使用没有 window. 前缀的映射用于 globals 配置
|
|
216
|
+
globals: globalsMappings,
|
|
217
|
+
// 确保正确处理命名导出和默认导出
|
|
218
|
+
interop: 'auto',
|
|
219
|
+
paths: pathMappings,
|
|
220
|
+
esModule: true,
|
|
221
|
+
// inlineDynamicImports: true,
|
|
222
|
+
// manualChunks: (id) => {
|
|
223
|
+
// // 如果是 EditComponent 或其他关键组件,不要放入 chunks
|
|
224
|
+
// if (ignoreChunksKeys.some((item) => id.includes(item))) {
|
|
225
|
+
// return id; // 返回 null 表示不创建单独的 chunk
|
|
226
|
+
// }
|
|
227
|
+
// return null;
|
|
228
|
+
// },
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
};
|
|
221
233
|
},
|
|
222
234
|
configResolved(config) {
|
|
223
235
|
helper_1.logger.info('config.build', config.build);
|
|
224
236
|
},
|
|
225
237
|
},
|
|
226
238
|
transpileBuiltinModule
|
|
227
|
-
?
|
|
239
|
+
? {
|
|
240
|
+
...(0, rollup_plugin_external_globals_1.default)(externalGlobalMappings),
|
|
241
|
+
apply: 'build',
|
|
242
|
+
enforce: 'pre',
|
|
243
|
+
}
|
|
244
|
+
: undefined,
|
|
228
245
|
// @ts-ignore
|
|
229
246
|
(0, vite_plugin_react_pages_1.default)({
|
|
230
247
|
pagesDir,
|
|
231
248
|
pageStrategy: new vite_plugin_react_pages_1.DefaultPageStrategy({
|
|
232
|
-
extraFindPages: (_pagesDir, helpers) =>
|
|
233
|
-
helpers.watchFiles(workingDir, (0, helper_1.getBlockEntryFilesPattern)(), function fileHandler(file, api) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
249
|
+
extraFindPages: async (_pagesDir, helpers) => {
|
|
250
|
+
helpers.watchFiles(workingDir, (0, helper_1.getBlockEntryFilesPattern)(), async function fileHandler(file, api) {
|
|
251
|
+
const { relative, path: filePath } = file;
|
|
252
|
+
const isHtml = relative.endsWith('.html');
|
|
253
|
+
const blockName = (0, helper_1.getBlockName)(relative);
|
|
254
|
+
const pageId = `/${blockName}`;
|
|
255
|
+
const dirPath = path.dirname(filePath);
|
|
256
|
+
const metadataPath = path.join(dirPath, '@metadata.json');
|
|
257
|
+
const dataPath = isHtml ? `${vite_plugin_html_transform_1.VIRTUAL_MODULE_ID}?dir=${dirPath}` : filePath;
|
|
258
|
+
api.addPageData({
|
|
259
|
+
pageId,
|
|
260
|
+
dataPath,
|
|
261
|
+
staticData: isHtml
|
|
262
|
+
? {
|
|
263
|
+
isHtml: true,
|
|
264
|
+
dataPath,
|
|
265
|
+
code: (0, vite_plugin_html_transform_1.generateComponent)((0, vite_plugin_html_transform_1.readHtmlFiles)(dirPath)),
|
|
266
|
+
blockName,
|
|
267
|
+
dirPath,
|
|
268
|
+
importPath: (0, ufo_1.joinURL)('@id', dataPath),
|
|
269
|
+
metadataPath,
|
|
270
|
+
}
|
|
271
|
+
: {
|
|
272
|
+
...(await helpers.extractStaticData(file)),
|
|
273
|
+
code: (0, fs_1.readFileSync)(file.path, 'utf-8'),
|
|
274
|
+
dataPath,
|
|
275
|
+
blockName,
|
|
276
|
+
dirPath,
|
|
277
|
+
importPath: (0, ufo_1.joinURL)('@fs', dataPath),
|
|
278
|
+
metadataPath,
|
|
279
|
+
},
|
|
259
280
|
});
|
|
260
281
|
});
|
|
261
|
-
}
|
|
282
|
+
},
|
|
262
283
|
}),
|
|
263
284
|
}),
|
|
264
285
|
(0, vite_plugin_html_transform_1.initHtmlPreviewTransformPlugin)(),
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.RESOLVED_VIRTUAL_MODULE_ID = exports.VIRTUAL_MODULE_ID = void 0;
|
|
13
4
|
exports.readHtmlFiles = readHtmlFiles;
|
|
@@ -258,23 +249,21 @@ function initHtmlPreviewTransformPlugin() {
|
|
|
258
249
|
}
|
|
259
250
|
return null;
|
|
260
251
|
},
|
|
261
|
-
load(id) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
htmlCache.set(dirPath, content);
|
|
272
|
-
}
|
|
252
|
+
async load(id) {
|
|
253
|
+
const useCache = false;
|
|
254
|
+
if (id.startsWith(exports.RESOLVED_VIRTUAL_MODULE_ID)) {
|
|
255
|
+
const dirPath = id.split('?dir=')[1] || '';
|
|
256
|
+
// 使用缓存避免重复读取
|
|
257
|
+
let content = useCache ? htmlCache.get(dirPath) : null;
|
|
258
|
+
if (!content) {
|
|
259
|
+
content = readHtmlFiles(dirPath);
|
|
260
|
+
if (useCache) {
|
|
261
|
+
htmlCache.set(dirPath, content);
|
|
273
262
|
}
|
|
274
|
-
return generateComponent(content, !isBuild);
|
|
275
263
|
}
|
|
276
|
-
return
|
|
277
|
-
}
|
|
264
|
+
return generateComponent(content, !isBuild);
|
|
265
|
+
}
|
|
266
|
+
return null;
|
|
278
267
|
},
|
|
279
268
|
// 清理缓存
|
|
280
269
|
buildEnd() {
|