@blocklet/pages-kit-block-studio 0.1.27 → 0.1.28

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.
@@ -59,6 +59,8 @@ const helper_1 = require("../utils/helper");
59
59
  const DID = 'z2qa7rr3eUyVnWp2PCxEVARuUfLFh6cE5V2xV';
60
60
  const RESOURCE_TYPE = 'page';
61
61
  const allTag = '@ALL_COMPONENTS';
62
+ // use for tracking build process
63
+ let currentBuildProcess = null;
62
64
  function copyFile(src, dest) {
63
65
  return new Promise((resolve, reject) => {
64
66
  const readStream = fs_1.default.createReadStream(src);
@@ -136,12 +138,19 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
136
138
  // ignore all tag
137
139
  const componentIds = resources.filter((resource) => resource.id !== allTag);
138
140
  try {
141
+ // if current build process exists, kill it
142
+ if (currentBuildProcess) {
143
+ currentBuildProcess.kill();
144
+ currentBuildProcess = null;
145
+ }
139
146
  // Execute build command with filtered components
140
147
  const buildProcess = (0, child_process_1.spawn)('pnpm', ['run', 'build-lib'], {
141
148
  stdio: 'inherit',
142
149
  shell: true,
143
150
  env: Object.assign(Object.assign({}, process.env), { FORCE_COLOR: '1', BLOCK_FILTER: componentIds.join(','), NODE_OPTIONS: '--max_old_space_size=16384' }),
144
151
  });
152
+ // save current build process
153
+ currentBuildProcess = buildProcess;
145
154
  yield new Promise((resolve, reject) => {
146
155
  buildProcess.on('close', (code) => {
147
156
  if (code === 0)
@@ -159,12 +168,15 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
159
168
  fs_1.default.mkdirSync(dir, { recursive: true });
160
169
  const rootDir = process.cwd();
161
170
  const distDir = (0, path_1.join)(rootDir, helper_1.libDir);
171
+ const codeDir = (0, path_1.join)(distDir, 'es');
162
172
  const tmpPackage = (0, path_1.join)(distDir, 'resource-blocklet');
163
173
  fs_1.default.mkdirSync(tmpPackage, { recursive: true });
164
174
  const pagesDir = (0, path_1.join)(tmpPackage, 'pages');
165
175
  fs_1.default.mkdirSync(pagesDir, { recursive: true });
166
176
  const componentsDir = (0, path_1.join)(tmpPackage, 'components');
167
177
  fs_1.default.mkdirSync(componentsDir, { recursive: true });
178
+ const chunksDir = (0, path_1.join)(tmpPackage, 'chunks');
179
+ fs_1.default.mkdirSync(chunksDir, { recursive: true });
168
180
  // get @metadata.json by glob
169
181
  const canUseComponents = (0, helper_1.findComponentFiles)({ cwd: rootDir, filter: componentIds });
170
182
  // Filter and process metadata files
@@ -172,7 +184,7 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
172
184
  // get metadata
173
185
  const metadata = _metadata;
174
186
  // get code to metadata
175
- const code = fs_1.default.readFileSync((0, path_1.join)(distDir, 'es', `${blockName}.js`), 'utf8');
187
+ const code = fs_1.default.readFileSync((0, path_1.join)(codeDir, `${blockName}.js`), 'utf8');
176
188
  if (code) {
177
189
  (0, set_1.default)(metadata, 'renderer.script', code);
178
190
  (0, set_1.default)(metadata, 'renderer.type', 'react-component');
@@ -190,10 +202,13 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
190
202
  }
191
203
  return metadata;
192
204
  });
205
+ // cp _chunks dir
206
+ yield copyRecursive((0, path_1.join)(codeDir, '_chunks'), chunksDir);
193
207
  // write pages.config.yml
194
208
  const pagesConfigPath = path_1.default.join(tmpPackage, '.blocklet/pages/pages.config.yml');
195
209
  fs_1.default.mkdirSync(path_1.default.dirname(pagesConfigPath), { recursive: true });
196
210
  const pagesConfig = {
211
+ version: 2,
197
212
  pages: [],
198
213
  components: metadataList.map((metadata) => ({
199
214
  id: metadata.id,