feat: 🎸 容器的模块名统一都用 PascalCase, 并为页面添加特定后缀防止与组件名冲突

This commit is contained in:
牧毅 2020-08-12 00:32:48 +08:00
parent 965ef4a4ed
commit 42f7bdbe42
2 changed files with 8 additions and 4 deletions

View File

@ -2,7 +2,7 @@
* 使
* schema
*/
import changeCase from 'change-case';
import { SUPPORT_SCHEMA_VERSION_LIST } from '../const';
import { handleChildren } from '../utils/nodeToJSX';
@ -90,7 +90,7 @@ class SchemaParser implements ISchemaParser {
const container: IContainerInfo = {
...subRoot,
containerType: subRoot.componentName,
moduleName: subRoot.fileName, // TODO: 驼峰化名称
moduleName: changeCase.pascalCase(subRoot.fileName),
};
return container;
});

View File

@ -1,3 +1,4 @@
import changeCase from 'change-case';
import { COMMON_CHUNK_NAME, CLASS_DEFINE_CHUNK_NAME } from '../../../const/generator';
import { REACT_CHUNK_NAME } from './const';
@ -18,11 +19,14 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const ir = next.ir as IContainerInfo;
// 将模块名转换成 PascalCase 的格式,并添加特定后缀,防止命名冲突
const componentClassName = `${changeCase.pascalCase(ir.moduleName)}$$Page`;
next.chunks.push({
type: ChunkType.STRING,
fileType: FileType.JSX,
name: CLASS_DEFINE_CHUNK_NAME.Start,
content: `class ${ir.moduleName} extends React.Component {`,
content: `class ${componentClassName} extends React.Component {`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,
@ -86,7 +90,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
type: ChunkType.STRING,
fileType: FileType.JSX,
name: COMMON_CHUNK_NAME.FileExport,
content: `export default ${ir.moduleName};`,
content: `export default ${componentClassName};`,
linkAfter: [
COMMON_CHUNK_NAME.ExternalDepsImport,
COMMON_CHUNK_NAME.InternalDepsImport,