diff --git a/packages/code-generator/package.json b/packages/code-generator/package.json index 4f3b87d88..45cb02d76 100644 --- a/packages/code-generator/package.json +++ b/packages/code-generator/package.json @@ -41,7 +41,7 @@ "ts" ], "require": [ - "ts-node/register" + "ts-node/register/transpile-only" ] }, "publishConfig": { diff --git a/packages/code-generator/src/generator/ProjectBuilder.ts b/packages/code-generator/src/generator/ProjectBuilder.ts index ec1c897b6..0538f4b88 100644 --- a/packages/code-generator/src/generator/ProjectBuilder.ts +++ b/packages/code-generator/src/generator/ProjectBuilder.ts @@ -121,6 +121,19 @@ export class ProjectBuilder implements IProjectBuilder { files, }); } + + // appConfig + if (parseResult.project && builders.appConfig) { + const { files } = await builders.appConfig.generateModule( + parseResult.project, + ); + + buildResult.push({ + path: this.template.slots.appConfig.path, + files, + }); + } + // constants? if ( parseResult.project && @@ -136,6 +149,7 @@ export class ProjectBuilder implements IProjectBuilder { files, }); } + // utils? if ( parseResult.globalUtils && @@ -151,6 +165,7 @@ export class ProjectBuilder implements IProjectBuilder { files, }); } + // i18n? if (parseResult.globalI18n && builders.i18n && this.template.slots.i18n) { const { files } = await builders.i18n.generateModule( @@ -162,6 +177,7 @@ export class ProjectBuilder implements IProjectBuilder { files, }); } + // globalStyle if (parseResult.project && builders.globalStyle) { const { files } = await builders.globalStyle.generateModule( @@ -173,6 +189,7 @@ export class ProjectBuilder implements IProjectBuilder { files, }); } + // htmlEntry if (parseResult.project && builders.htmlEntry) { const { files } = await builders.htmlEntry.generateModule( @@ -184,6 +201,7 @@ export class ProjectBuilder implements IProjectBuilder { files, }); } + // packageJSON if (parseResult.project && builders.packageJSON) { const { files } = await builders.packageJSON.generateModule( diff --git a/packages/code-generator/src/index.ts b/packages/code-generator/src/index.ts index 5d670b5ab..87df670ee 100644 --- a/packages/code-generator/src/index.ts +++ b/packages/code-generator/src/index.ts @@ -6,8 +6,8 @@ import { createProjectBuilder } from './generator/ProjectBuilder'; import { createModuleBuilder } from './generator/ModuleBuilder'; import { createDiskPublisher } from './publisher/disk'; import { createZipPublisher } from './publisher/zip'; -import createIceJsProjectBuilder from './solutions/icejs'; -import createRecoreProjectBuilder from './solutions/recore'; +// import createIceJsProjectBuilder from './solutions/icejs'; +// import createRecoreProjectBuilder from './solutions/recore'; // 引入说明 import { REACT_CHUNK_NAME } from './plugins/component/react/const'; @@ -50,8 +50,8 @@ export default { createProjectBuilder, createModuleBuilder, solutions: { - icejs: createIceJsProjectBuilder, - recore: createRecoreProjectBuilder, + // icejs: createIceJsProjectBuilder, + // recore: createRecoreProjectBuilder, }, solutionParts: { icejs, diff --git a/packages/code-generator/src/plugins/project/framework/rax/index.ts b/packages/code-generator/src/plugins/project/framework/rax/index.ts new file mode 100644 index 000000000..3f9080565 --- /dev/null +++ b/packages/code-generator/src/plugins/project/framework/rax/index.ts @@ -0,0 +1,17 @@ +import template from './template'; +import entry from './plugins/entry'; +import appConfig from './plugins/appConfig'; +import entryDocument from './plugins/entryDocument'; +import globalStyle from './plugins/globalStyle'; +import packageJSON from './plugins/packageJSON'; + +export default { + template, + plugins: { + appConfig, + entry, + entryDocument, + globalStyle, + packageJSON, + }, +}; diff --git a/packages/code-generator/src/plugins/project/framework/rax/plugins/appConfig.ts b/packages/code-generator/src/plugins/project/framework/rax/plugins/appConfig.ts new file mode 100644 index 000000000..7df09a0f1 --- /dev/null +++ b/packages/code-generator/src/plugins/project/framework/rax/plugins/appConfig.ts @@ -0,0 +1,45 @@ +import { COMMON_CHUNK_NAME } from '../../../../../const/generator'; + +import { + BuilderComponentPlugin, + BuilderComponentPluginFactory, + ChunkType, + FileType, + ICodeStruct, + IRouterInfo, +} from '../../../../../types'; + +const pluginFactory: BuilderComponentPluginFactory = () => { + const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { + const next: ICodeStruct = { + ...pre, + }; + + const ir = next.ir as IRouterInfo; + + next.chunks.push({ + type: ChunkType.STRING, + fileType: FileType.JSON, + name: COMMON_CHUNK_NAME.CustomContent, + content: ` +{ + "routes": [ + { + "path": "/", + "source": "pages/Home/index" + } + ], + "window": { + "title": "Rax App Demo" + } +} + `, + linkAfter: [], + }); + + return next; + }; + return plugin; +}; + +export default pluginFactory; diff --git a/packages/code-generator/src/plugins/project/framework/rax/plugins/entry.ts b/packages/code-generator/src/plugins/project/framework/rax/plugins/entry.ts new file mode 100644 index 000000000..09bc07af8 --- /dev/null +++ b/packages/code-generator/src/plugins/project/framework/rax/plugins/entry.ts @@ -0,0 +1,51 @@ +import { COMMON_CHUNK_NAME } from '../../../../../const/generator'; + +import { + BuilderComponentPlugin, + BuilderComponentPluginFactory, + ChunkType, + FileType, + ICodeStruct, + IProjectInfo, +} from '../../../../../types'; + +const pluginFactory: BuilderComponentPluginFactory = () => { + const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { + const next: ICodeStruct = { + ...pre, + }; + + const ir = next.ir as IProjectInfo; + + next.chunks.push({ + type: ChunkType.STRING, + fileType: FileType.JS, + name: COMMON_CHUNK_NAME.ExternalDepsImport, + content: ` +import { runApp } from 'rax-app'; +import appConfig from './app.json'; +`, + linkAfter: [], + }); + + next.chunks.push({ + type: ChunkType.STRING, + fileType: FileType.JS, + name: COMMON_CHUNK_NAME.FileMainContent, + content: ` +runApp(appConfig); +`, + linkAfter: [ + COMMON_CHUNK_NAME.ExternalDepsImport, + COMMON_CHUNK_NAME.InternalDepsImport, + COMMON_CHUNK_NAME.FileVarDefine, + COMMON_CHUNK_NAME.FileUtilDefine, + ], + }); + + return next; + }; + return plugin; +}; + +export default pluginFactory; diff --git a/packages/code-generator/src/plugins/project/framework/rax/plugins/entryDocument.ts b/packages/code-generator/src/plugins/project/framework/rax/plugins/entryDocument.ts new file mode 100644 index 000000000..ba8488c00 --- /dev/null +++ b/packages/code-generator/src/plugins/project/framework/rax/plugins/entryDocument.ts @@ -0,0 +1,59 @@ +import { COMMON_CHUNK_NAME } from '../../../../../const/generator'; + +import { + BuilderComponentPlugin, + BuilderComponentPluginFactory, + ChunkType, + FileType, + ICodeStruct, + IProjectInfo, +} from '../../../../../types'; + +const pluginFactory: BuilderComponentPluginFactory = () => { + const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { + const next: ICodeStruct = { + ...pre, + }; + + const ir = next.ir as IProjectInfo; + + next.chunks.push({ + type: ChunkType.STRING, + fileType: FileType.JSX, + name: COMMON_CHUNK_NAME.CustomContent, + content: ` +import { createElement } from 'rax'; +import { Root, Style, Script } from 'rax-document'; + +function Document() { + return ( + + + + + ${ir.meta.name} +