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

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 +3 -3
  2. package/lib/cjs/{block-studio/plugins → plugins}/vite-plugin-block-studio.js +22 -22
  3. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  4. package/lib/cjs/{block-studio → utils}/build-lib.js +2 -3
  5. package/lib/cjs/{block-studio → utils}/generate-wrapper-code.js +21 -5
  6. package/lib/cjs/{block-studio/utils.js → utils/helper.js} +2 -0
  7. package/lib/esm/{block-studio → middlewares}/init-resource-router.js +2 -2
  8. package/lib/esm/{block-studio/plugins → plugins}/vite-plugin-block-studio.js +16 -16
  9. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  10. package/lib/esm/{block-studio → utils}/build-lib.js +1 -2
  11. package/lib/esm/{block-studio → utils}/generate-wrapper-code.js +21 -5
  12. package/lib/esm/{block-studio/utils.js → utils/helper.js} +1 -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} +1 -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
@@ -17,13 +17,13 @@ exports.buildLib = buildLib;
17
17
  /* eslint-disable no-console */
18
18
  const chalk_1 = __importDefault(require("chalk"));
19
19
  const child_process_1 = require("child_process");
20
- const utils_1 = require("./utils");
20
+ const helper_1 = require("./helper");
21
21
  function buildLib(options) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  var _a, _b;
24
24
  const workingDir = (options === null || options === void 0 ? void 0 : options.cwd) || process.cwd();
25
25
  // Scan for all index files
26
- const allBlocks = (0, utils_1.findComponentFiles)({ cwd: workingDir }).map((entry) => {
26
+ const allBlocks = (0, helper_1.findComponentFiles)({ cwd: workingDir }).map((entry) => {
27
27
  return entry.blockName;
28
28
  });
29
29
  const filterModules = process.argv.includes('--filter')
@@ -60,7 +60,6 @@ function buildLib(options) {
60
60
  libDir,
61
61
  '--emptyOutDir=false',
62
62
  hasConfig ? `--config ${configFile}.*` : '',
63
- multiMode ? '--multi' : '',
64
63
  ], {
65
64
  stdio: ignoreViteLog ? ['inherit', 'ignore', 'ignore'] : 'inherit',
66
65
  shell: true,
@@ -43,9 +43,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.generateWrapperCode = generateWrapperCode;
46
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
47
  function generateWrapperCode(_a) {
47
- return __awaiter(this, arguments, void 0, function* ({ project, version }) {
48
- const projectName = (project.name || project.id).toLowerCase().replaceAll(/[^a-z0-9]/g, '_');
48
+ return __awaiter(this, arguments, void 0, function* ({ project, state, version }) {
49
+ const projectName = (project.name || project.id).toLowerCase().replaceAll(/[^a-z0-9]/g, '-');
49
50
  const packageName = `@pages-kit-project/${projectName}`;
50
51
  const packageJson = JSON.stringify({
51
52
  name: packageName,
@@ -79,14 +80,16 @@ function generateWrapperCode(_a) {
79
80
  },
80
81
  },
81
82
  }, null, 2);
82
- const index = `\
83
+ const client = `\
83
84
  import HomeComponent from '@blocklet/pages-kit-runtime/client';
84
85
 
86
+
87
+
85
88
  export default HomeComponent;
86
89
  `;
87
- const client = index;
90
+ const index = client;
88
91
  const middleware = `
89
- import { initResourceRouter } from '@blocklet/pages-kit-block-studio/block-studio/init-resource-router';
92
+ import { initResourceRouter } from '@blocklet/pages-kit-block-studio/init-resource-router';
90
93
  import { getPreloadComponents } from '@blocklet/pages-kit-inner-components/components';
91
94
  import { initPackResourceStates } from '@blocklet/pages-kit-inner-components/site-state';
92
95
  import express, { Router } from 'express';
@@ -193,10 +196,15 @@ router.use(
193
196
 
194
197
  export default router;
195
198
  `;
199
+ const data = JSON.stringify({
200
+ project,
201
+ state,
202
+ }, null, 2);
196
203
  const tsFiles = [
197
204
  { fileName: 'index.ts', content: index },
198
205
  { fileName: 'client.ts', content: client },
199
206
  { fileName: 'middleware.ts', content: middleware },
207
+ { fileName: 'data.json', content: data },
200
208
  ];
201
209
  const ts = yield Promise.resolve().then(() => __importStar(require('typescript')));
202
210
  const compilerOptions = {
@@ -206,6 +214,14 @@ export default router;
206
214
  declaration: true,
207
215
  };
208
216
  const result = (yield Promise.all(tsFiles.map((_a) => __awaiter(this, [_a], void 0, function* ({ fileName, content }) {
217
+ if (fileName === 'data.json') {
218
+ return [
219
+ {
220
+ fileName: 'data.json',
221
+ content: data,
222
+ },
223
+ ];
224
+ }
209
225
  const cjs = ts.transpileModule(content, {
210
226
  fileName,
211
227
  compilerOptions: Object.assign(Object.assign({}, compilerOptions), { module: ts.ModuleKind.CommonJS }),
@@ -8,6 +8,7 @@ exports.setBlockEntryFilesPattern = setBlockEntryFilesPattern;
8
8
  exports.getBlockEntryFilesPattern = getBlockEntryFilesPattern;
9
9
  exports.findComponentFiles = findComponentFiles;
10
10
  exports.getBlockName = getBlockName;
11
+ exports.generateBlockYml = generateBlockYml;
11
12
  const glob_1 = require("glob");
12
13
  const path_1 = __importDefault(require("path"));
13
14
  const DEFAULT_BLOCK_ENTRY_FILES_PATTERN = 'src/**/index.{ts,tsx,html}';
@@ -51,3 +52,4 @@ function getBlockName(entry) {
51
52
  return path_1.default.basename(entry, path_1.default.extname(entry));
52
53
  }
53
54
  exports.logger = console;
55
+ function generateBlockYml() { }
@@ -12,9 +12,9 @@ import { spawn } from 'child_process';
12
12
  import { Router } from 'express';
13
13
  import fs from 'fs';
14
14
  import path, { join } from 'path';
15
- import { findComponentFiles } from './utils';
15
+ import { findComponentFiles } from '../utils/helper';
16
16
  const DID = 'z2qa7rr3eUyVnWp2PCxEVARuUfLFh6cE5V2xV';
17
- const RESOURCE_TYPE = 'block';
17
+ const RESOURCE_TYPE = 'page';
18
18
  const allTag = '@ALL_COMPONENTS';
19
19
  export function copyFile(src, dest) {
20
20
  return new Promise((resolve, reject) => {
@@ -12,7 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
12
12
  import { readFileSync, existsSync } from 'fs';
13
13
  import * as path from 'path';
14
14
  import pages, { DefaultPageStrategy } from 'vite-plugin-react-pages';
15
- import { findComponentFiles, setBlockEntryFilesPattern, getBlockEntryFilesPattern, getBlockName, logger, } from '../utils';
15
+ import { findComponentFiles, setBlockEntryFilesPattern, getBlockEntryFilesPattern, getBlockName, logger, } from '../utils/helper';
16
16
  import { initHtmlPreviewTransformPlugin, VIRTUAL_MODULE_ID } from './vite-plugin-html-transform';
17
17
  // import initRemoteScriptLocalizerPlugin from './vite-plugin-remote-script-localizer';
18
18
  export function initBlockStudioPlugins(options) {
@@ -51,25 +51,25 @@ export function initBlockStudioPlugins(options) {
51
51
  const filterModules = process.argv.includes('--filter')
52
52
  ? (_a = process.argv[process.argv.indexOf('--filter') + 1]) === null || _a === void 0 ? void 0 : _a.split(',')
53
53
  : null;
54
- const multiMode = !!process.argv.includes('--multi');
55
54
  const name = yield import(`${workingDir}/package.json`).then((res) => res.name).catch(() => 'MyLib');
55
+ const entryList = findComponentFiles({ cwd: workingDir })
56
+ .map((entry) => {
57
+ const { blockName } = entry;
58
+ const { isHtml } = entry;
59
+ const { file } = entry;
60
+ if (isHtml) {
61
+ return [blockName, `${VIRTUAL_MODULE_ID}?dir=${path.dirname(file)}`];
62
+ }
63
+ return [blockName, path.resolve(workingDir, file)];
64
+ })
65
+ .filter(Boolean)
66
+ .filter(([blockName]) => !filterModules || filterModules.includes(blockName || ''));
67
+ const multiMode = entryList.length > 1;
56
68
  return {
57
69
  build: Object.assign({ cssCodeSplit: false, lib: {
58
70
  name,
59
- entry: Object.assign({}, Object.fromEntries(findComponentFiles({ cwd: workingDir })
60
- .map((entry) => {
61
- const { blockName } = entry;
62
- const { isHtml } = entry;
63
- const { file } = entry;
64
- if (isHtml) {
65
- return [blockName, `${VIRTUAL_MODULE_ID}?dir=${path.dirname(file)}`];
66
- }
67
- return [blockName, path.resolve(workingDir, file)];
68
- })
69
- .filter(Boolean)
70
- .filter(([blockName]) => !filterModules || filterModules.includes(blockName || '')))),
71
- // multiMode not support umd
72
- formats: ['es', multiMode ? 'umd' : 'cjs'],
71
+ entry: Object.assign({}, Object.fromEntries(entryList)),
72
+ formats: ['es', !multiMode ? 'umd' : 'cjs'],
73
73
  fileName: (format, entryName) => `${format}/${entryName}.js`,
74
74
  }, rollupOptions: {
75
75
  external: [