@blocklet/pages-kit-block-studio 0.6.7 → 0.6.9
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-resource-router.js +19 -1
- package/lib/cjs/plugins/vite-plugin-code-splitter.js +2 -10
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/helper.js +5 -1
- package/lib/esm/middlewares/init-resource-router.js +20 -2
- package/lib/esm/plugins/vite-plugin-code-splitter.js +3 -11
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/helper.js +3 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/helper.d.ts +2 -0
- package/package.json +3 -3
package/lib/cjs/utils/helper.js
CHANGED
|
@@ -39,7 +39,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.getGetServerSidePropsBlockName = exports.GET_SERVER_SIDE_PROPS_NAME = exports.getAigneOutputValueSchemaBlockName = exports.AIGNE_OUTPUT_VALUE_SCHEMA_NAME = exports.getPropertiesSchemaBlockName = exports.PROPERTIES_SCHEMA_NAME = exports.getEditComponentBlockName = exports.EDIT_COMPONENT_NAME = exports.safeParse = exports.getBlockCode = exports.getPreviewImageRelativePath = exports.downloadAsset = exports.isMetadataFile = exports.isDev = exports.isPathSafe = exports.logger = void 0;
|
|
42
|
+
exports.getGetServerSidePropsBlockName = exports.GET_SERVER_SIDE_PROPS_NAME = exports.getAigneOutputValueSchemaBlockName = exports.AIGNE_OUTPUT_VALUE_SCHEMA_NAME = exports.getPropertiesSchemaBlockName = exports.PROPERTIES_SCHEMA_NAME = exports.getEditComponentBlockName = exports.EDIT_COMPONENT_NAME = exports.getComponentScriptName = exports.safeParse = exports.getBlockCode = exports.getPreviewImageRelativePath = exports.downloadAsset = exports.isMetadataFile = exports.isDev = exports.isPathSafe = exports.logger = void 0;
|
|
43
43
|
exports.setBlockEntryFilesPattern = setBlockEntryFilesPattern;
|
|
44
44
|
exports.getBlockEntryFilesPattern = getBlockEntryFilesPattern;
|
|
45
45
|
exports.getWatchFilesDir = getWatchFilesDir;
|
|
@@ -239,6 +239,10 @@ const safeParse = (text) => {
|
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
exports.safeParse = safeParse;
|
|
242
|
+
const getComponentScriptName = (blockName, format) => {
|
|
243
|
+
return `${blockName}(${format})`;
|
|
244
|
+
};
|
|
245
|
+
exports.getComponentScriptName = getComponentScriptName;
|
|
242
246
|
exports.EDIT_COMPONENT_NAME = 'EditComponent';
|
|
243
247
|
const getEditComponentBlockName = (blockName) => {
|
|
244
248
|
return `${blockName}(${exports.EDIT_COMPONENT_NAME})`;
|
|
@@ -6,7 +6,8 @@ import fs from 'fs';
|
|
|
6
6
|
import get from 'lodash/get';
|
|
7
7
|
import set from 'lodash/set';
|
|
8
8
|
import path, { join, basename } from 'path';
|
|
9
|
-
import
|
|
9
|
+
import ts from 'typescript';
|
|
10
|
+
import { findComponentFiles, libDir, getPreviewImageRelativePath, generateYaml, logger, getComponentScriptName, getEditComponentBlockName, getAigneOutputValueSchemaBlockName, getPropertiesSchemaBlockName, getGetServerSidePropsBlockName, } from '../utils/helper';
|
|
10
11
|
const DID = 'z2qa7BQdkEb3TwYyEYC1psK6uvmGnHSUHt5RM';
|
|
11
12
|
const RESOURCE_TYPE = 'page';
|
|
12
13
|
const allTag = '@ALL_COMPONENTS';
|
|
@@ -147,12 +148,29 @@ initResourceRouter.post('/', async (req, res) => {
|
|
|
147
148
|
// set version to 2
|
|
148
149
|
set(metadata, 'version', 2);
|
|
149
150
|
// get code to metadata
|
|
150
|
-
const code = fs.readFileSync(join(codeDir,
|
|
151
|
+
const code = fs.readFileSync(join(codeDir, `${getComponentScriptName(blockName, 'esm')}.js`), 'utf8');
|
|
151
152
|
if (code) {
|
|
152
153
|
set(metadata, 'renderer.script', code);
|
|
153
154
|
set(metadata, 'renderer.type', 'react-component');
|
|
154
155
|
set(metadata, 'renderer.chunks', chunksMap[jsName] || []);
|
|
155
156
|
}
|
|
157
|
+
// get cjs by code with transpileModule
|
|
158
|
+
try {
|
|
159
|
+
const cjsCode = ts.transpileModule(code, {
|
|
160
|
+
compilerOptions: {
|
|
161
|
+
jsx: ts.JsxEmit.React,
|
|
162
|
+
target: ts.ScriptTarget.ES2016,
|
|
163
|
+
module: ts.ModuleKind.CommonJS,
|
|
164
|
+
moduleResolution: ts.ModuleResolutionKind.Node16,
|
|
165
|
+
},
|
|
166
|
+
}).outputText;
|
|
167
|
+
if (cjsCode) {
|
|
168
|
+
set(metadata, 'renderer.cjsScript', cjsCode);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
// ignore error
|
|
173
|
+
}
|
|
156
174
|
// get edit component code
|
|
157
175
|
try {
|
|
158
176
|
const editComponentJsName = `${getEditComponentBlockName(blockName)}.js`;
|
|
@@ -50,7 +50,7 @@ import pLimit from 'p-limit';
|
|
|
50
50
|
import path, { basename } from 'path';
|
|
51
51
|
import ts from 'typescript';
|
|
52
52
|
import { EDIT_COMPONENT_FILE_NAME_REGEX } from '../constants';
|
|
53
|
-
import { EDIT_COMPONENT_NAME,
|
|
53
|
+
import { EDIT_COMPONENT_NAME, logger, PROPERTIES_SCHEMA_NAME, AIGNE_OUTPUT_VALUE_SCHEMA_NAME, GET_SERVER_SIDE_PROPS_NAME, getEditComponentBlockName, getComponentScriptName, getPropertiesSchemaBlockName, getAigneOutputValueSchemaBlockName, getGetServerSidePropsBlockName, } from '../utils/helper';
|
|
54
54
|
const minify = true;
|
|
55
55
|
/**
|
|
56
56
|
* 导出配置
|
|
@@ -58,20 +58,12 @@ const minify = true;
|
|
|
58
58
|
const EXPORT_CONFIGS = [
|
|
59
59
|
{
|
|
60
60
|
exportName: 'default',
|
|
61
|
-
getBlockName: (key) =>
|
|
61
|
+
getBlockName: (key) => getComponentScriptName(key, 'esm'),
|
|
62
62
|
description: 'Default',
|
|
63
63
|
supportSeparateFile: false,
|
|
64
64
|
target: 'browser',
|
|
65
65
|
external: [],
|
|
66
66
|
},
|
|
67
|
-
// {
|
|
68
|
-
// exportName: 'default',
|
|
69
|
-
// getBlockName: (key) => `${key}(default)`,
|
|
70
|
-
// description: 'Default CJS',
|
|
71
|
-
// supportSeparateFile: false,
|
|
72
|
-
// target: 'node',
|
|
73
|
-
// external: [],
|
|
74
|
-
// },
|
|
75
67
|
{
|
|
76
68
|
exportName: EDIT_COMPONENT_NAME,
|
|
77
69
|
getBlockName: getEditComponentBlockName,
|
|
@@ -475,7 +467,7 @@ export function vitePluginCodeSplitter(options) {
|
|
|
475
467
|
return null; // Regular component file, defaults to browser
|
|
476
468
|
}
|
|
477
469
|
const exportName = match[1];
|
|
478
|
-
return EXPORT_CONFIGS.find((config) => config.
|
|
470
|
+
return EXPORT_CONFIGS.find((config) => config.getBlockName('').includes(exportName));
|
|
479
471
|
};
|
|
480
472
|
/**
|
|
481
473
|
* 🎯 FILE TYPE CLASSIFIER
|