@blocklet/pages-kit-block-studio 0.0.10 → 0.0.12

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.
Files changed (35) hide show
  1. package/lib/cjs/{block-studio → middlewares}/init-resource-router.js +4 -4
  2. package/lib/cjs/{block-studio/plugins → plugins}/vite-plugin-block-studio.js +30 -24
  3. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  4. package/lib/cjs/{block-studio → utils}/build-lib.js +5 -7
  5. package/lib/cjs/{block-studio → utils}/generate-wrapper-code.js +21 -5
  6. package/lib/cjs/{block-studio/utils.js → utils/helper.js} +4 -1
  7. package/lib/esm/{block-studio → middlewares}/init-resource-router.js +3 -3
  8. package/lib/esm/{block-studio/plugins → plugins}/vite-plugin-block-studio.js +24 -18
  9. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  10. package/lib/esm/{block-studio → utils}/build-lib.js +1 -3
  11. package/lib/esm/{block-studio → utils}/generate-wrapper-code.js +21 -5
  12. package/lib/esm/{block-studio/utils.js → utils/helper.js} +2 -0
  13. package/lib/types/tsconfig.tsbuildinfo +1 -1
  14. package/lib/types/utils/generate-wrapper-code.d.ts +5 -0
  15. package/lib/types/{block-studio/utils.d.ts → utils/helper.d.ts} +2 -0
  16. package/package.json +28 -25
  17. package/lib/cjs/utils/index.js +0 -1
  18. package/lib/esm/utils/index.js +0 -1
  19. package/lib/types/block-studio/generate-wrapper-code.d.ts +0 -5
  20. package/lib/types/utils/index.d.ts +0 -0
  21. /package/lib/cjs/{block-studio/plugins → plugins}/_theme.js +0 -0
  22. /package/lib/cjs/{block-studio/plugins → plugins}/index.js +0 -0
  23. /package/lib/cjs/{block-studio/plugins → plugins}/vite-plugin-html-transform.js +0 -0
  24. /package/lib/cjs/{block-studio/plugins → plugins}/vite-plugin-remote-script-localizer.js +0 -0
  25. /package/lib/esm/{block-studio/plugins → plugins}/_theme.js +0 -0
  26. /package/lib/esm/{block-studio/plugins → plugins}/index.js +0 -0
  27. /package/lib/esm/{block-studio/plugins → plugins}/vite-plugin-html-transform.js +0 -0
  28. /package/lib/esm/{block-studio/plugins → plugins}/vite-plugin-remote-script-localizer.js +0 -0
  29. /package/lib/types/{block-studio → middlewares}/init-resource-router.d.ts +0 -0
  30. /package/lib/types/{block-studio/plugins → plugins}/_theme.d.ts +0 -0
  31. /package/lib/types/{block-studio/plugins → plugins}/index.d.ts +0 -0
  32. /package/lib/types/{block-studio/plugins → plugins}/vite-plugin-block-studio.d.ts +0 -0
  33. /package/lib/types/{block-studio/plugins → plugins}/vite-plugin-html-transform.d.ts +0 -0
  34. /package/lib/types/{block-studio/plugins → plugins}/vite-plugin-remote-script-localizer.d.ts +0 -0
  35. /package/lib/types/{block-studio → utils}/build-lib.d.ts +0 -0
@@ -54,9 +54,9 @@ const child_process_1 = require("child_process");
54
54
  const express_1 = require("express");
55
55
  const fs_1 = __importDefault(require("fs"));
56
56
  const path_1 = __importStar(require("path"));
57
- const utils_1 = require("./utils");
57
+ const helper_1 = require("../utils/helper");
58
58
  const DID = 'z2qa7rr3eUyVnWp2PCxEVARuUfLFh6cE5V2xV';
59
- const RESOURCE_TYPE = 'block';
59
+ const RESOURCE_TYPE = 'page';
60
60
  const allTag = '@ALL_COMPONENTS';
61
61
  function copyFile(src, dest) {
62
62
  return new Promise((resolve, reject) => {
@@ -104,7 +104,7 @@ exports.initResourceRouter = (0, express_1.Router)();
104
104
  exports.initResourceRouter.get('/', (_req, res) => __awaiter(void 0, void 0, void 0, function* () {
105
105
  const resources = [];
106
106
  const rootDir = process.cwd();
107
- const files = (0, utils_1.findComponentFiles)({ cwd: rootDir });
107
+ const files = (0, helper_1.findComponentFiles)({ cwd: rootDir });
108
108
  for (const file of files) {
109
109
  // const filePath = path.join(rootDir, file);
110
110
  // const fileContent = fs.readFileSync(filePath, 'utf8');
@@ -153,7 +153,7 @@ exports.initResourceRouter.post('/', (req, res) => __awaiter(void 0, void 0, voi
153
153
  fs_1.default.rmSync(dir, { recursive: true, force: true });
154
154
  fs_1.default.mkdirSync(dir, { recursive: true });
155
155
  const rootDir = process.cwd();
156
- const tmpPackage = (0, path_1.join)(rootDir, 'lib');
156
+ const tmpPackage = (0, path_1.join)(rootDir, helper_1.libDir);
157
157
  yield copyRecursive(tmpPackage, dir);
158
158
  fs_1.default.rmSync(tmpPackage, { recursive: true, force: true });
159
159
  res.json({ success: true });
@@ -48,18 +48,18 @@ exports.initBlockStudioPlugins = initBlockStudioPlugins;
48
48
  const fs_1 = require("fs");
49
49
  const path = __importStar(require("path"));
50
50
  const vite_plugin_react_pages_1 = __importStar(require("vite-plugin-react-pages"));
51
- const utils_1 = require("../utils");
51
+ const helper_1 = require("../utils/helper");
52
52
  const vite_plugin_html_transform_1 = require("./vite-plugin-html-transform");
53
53
  // import initRemoteScriptLocalizerPlugin from './vite-plugin-remote-script-localizer';
54
54
  function initBlockStudioPlugins(options) {
55
55
  const workingDir = (options === null || options === void 0 ? void 0 : options.cwd) || process.cwd();
56
- const entryFilesPattern = (options === null || options === void 0 ? void 0 : options.entryFilesPattern) || (0, utils_1.getBlockEntryFilesPattern)();
57
- (0, utils_1.setBlockEntryFilesPattern)(entryFilesPattern);
56
+ const entryFilesPattern = (options === null || options === void 0 ? void 0 : options.entryFilesPattern) || (0, helper_1.getBlockEntryFilesPattern)();
57
+ (0, helper_1.setBlockEntryFilesPattern)(entryFilesPattern);
58
58
  // fallback to __dirname if _theme.tsx not exists
59
59
  const pagesDir = (0, fs_1.existsSync)(path.join(workingDir, '_theme.tsx')) ? workingDir : __dirname.replace('cjs', 'esm');
60
- utils_1.logger.log('initBlockStudioPlugins options: ', {
60
+ helper_1.logger.log('initBlockStudioPlugins options: ', {
61
61
  cwd: workingDir,
62
- entryFilesPattern: (0, utils_1.getBlockEntryFilesPattern)(),
62
+ entryFilesPattern: (0, helper_1.getBlockEntryFilesPattern)(),
63
63
  pagesDir,
64
64
  });
65
65
  return [
@@ -87,25 +87,25 @@ function initBlockStudioPlugins(options) {
87
87
  const filterModules = process.argv.includes('--filter')
88
88
  ? (_a = process.argv[process.argv.indexOf('--filter') + 1]) === null || _a === void 0 ? void 0 : _a.split(',')
89
89
  : null;
90
- const multiMode = !!process.argv.includes('--multi');
91
90
  const name = yield Promise.resolve(`${`${workingDir}/package.json`}`).then(s => __importStar(require(s))).then((res) => res.name).catch(() => 'MyLib');
91
+ const entryList = (0, helper_1.findComponentFiles)({ cwd: workingDir })
92
+ .map((entry) => {
93
+ const { blockName } = entry;
94
+ const { isHtml } = entry;
95
+ const { file } = entry;
96
+ if (isHtml) {
97
+ return [blockName, `${vite_plugin_html_transform_1.VIRTUAL_MODULE_ID}?dir=${path.dirname(file)}`];
98
+ }
99
+ return [blockName, path.resolve(workingDir, file)];
100
+ })
101
+ .filter(Boolean)
102
+ .filter(([blockName]) => !filterModules || filterModules.includes(blockName || ''));
103
+ const multiMode = entryList.length > 1;
92
104
  return {
93
105
  build: Object.assign({ cssCodeSplit: false, lib: {
94
106
  name,
95
- entry: Object.assign({}, Object.fromEntries((0, utils_1.findComponentFiles)({ cwd: workingDir })
96
- .map((entry) => {
97
- const { blockName } = entry;
98
- const { isHtml } = entry;
99
- const { file } = entry;
100
- if (isHtml) {
101
- return [blockName, `${vite_plugin_html_transform_1.VIRTUAL_MODULE_ID}?dir=${path.dirname(file)}`];
102
- }
103
- return [blockName, path.resolve(workingDir, file)];
104
- })
105
- .filter(Boolean)
106
- .filter(([blockName]) => !filterModules || filterModules.includes(blockName || '')))),
107
- // multiMode not support umd
108
- formats: ['es', multiMode ? 'umd' : 'cjs'],
107
+ entry: Object.assign({}, Object.fromEntries(entryList)),
108
+ formats: ['es', !multiMode ? 'umd' : 'cjs'],
109
109
  fileName: (format, entryName) => `${format}/${entryName}.js`,
110
110
  }, rollupOptions: {
111
111
  external: [
@@ -151,22 +151,28 @@ function initBlockStudioPlugins(options) {
151
151
  pagesDir,
152
152
  pageStrategy: new vite_plugin_react_pages_1.DefaultPageStrategy({
153
153
  extraFindPages: (_pagesDir, helpers) => __awaiter(this, void 0, void 0, function* () {
154
- helpers.watchFiles(workingDir, (0, utils_1.getBlockEntryFilesPattern)(), function fileHandler(file, api) {
154
+ helpers.watchFiles(workingDir, (0, helper_1.getBlockEntryFilesPattern)(), function fileHandler(file, api) {
155
155
  return __awaiter(this, void 0, void 0, function* () {
156
156
  const { relative, path: filePath } = file;
157
157
  const isHtml = relative.endsWith('.html');
158
- const blockName = (0, utils_1.getBlockName)(relative);
158
+ const blockName = (0, helper_1.getBlockName)(relative);
159
159
  const pageId = `/${blockName}`;
160
+ const dirPath = path.dirname(filePath);
161
+ const metadataPath = path.join(dirPath, '@metadata.json');
160
162
  api.addPageData({
161
163
  pageId,
162
- dataPath: isHtml ? `${vite_plugin_html_transform_1.VIRTUAL_MODULE_ID}?dir=${path.dirname(filePath)}` : filePath,
164
+ dataPath: isHtml ? `${vite_plugin_html_transform_1.VIRTUAL_MODULE_ID}?dir=${dirPath}` : filePath,
163
165
  staticData: isHtml
164
166
  ? {
165
167
  isHtmlPreview: true,
166
168
  dataPath: filePath,
167
169
  blockName,
170
+ dirPath,
171
+ metadataPath,
168
172
  }
169
- : Object.assign(Object.assign({}, (yield helpers.extractStaticData(file))), { code: (0, fs_1.readFileSync)(file.path, 'utf-8'), dataPath: filePath, blockName }),
173
+ : Object.assign(Object.assign({}, (yield helpers.extractStaticData(file))), { code: (0, fs_1.readFileSync)(file.path, 'utf-8'), dataPath: filePath, blockName,
174
+ dirPath,
175
+ metadataPath }),
170
176
  });
171
177
  });
172
178
  });