fix: factory api

This commit is contained in:
春希 2020-04-20 14:27:51 +08:00
parent d6855e2236
commit 237b86656b
24 changed files with 860 additions and 769 deletions

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
CodeGeneratorError, CodeGeneratorError,
DependencyType, DependencyType,
@ -41,7 +42,7 @@ function groupDepsByPack(deps: IDependency[]): Record<string, IDependency[]> {
function buildPackageImport( function buildPackageImport(
pkg: string, pkg: string,
deps: IDependency[], deps: IDependency[],
isJSX: boolean, targetFileType: string,
): ICodeChunk[] { ): ICodeChunk[] {
const chunks: ICodeChunk[] = []; const chunks: ICodeChunk[] = [];
let defaultImport: string = ''; let defaultImport: string = '';
@ -58,7 +59,7 @@ function buildPackageImport(
if (dep.subName) { if (dep.subName) {
chunks.push({ chunks.push({
type: ChunkType.STRING, type: ChunkType.STRING,
fileType: isJSX ? FileType.JSX : FileType.JS, fileType: targetFileType,
name: COMMON_CHUNK_NAME.FileVarDefine, name: COMMON_CHUNK_NAME.FileVarDefine,
content: `const ${targetName} = ${srcName}.${dep.subName};`, content: `const ${targetName} = ${srcName}.${dep.subName};`,
linkAfter: [ linkAfter: [
@ -103,7 +104,7 @@ function buildPackageImport(
statementL.push(`'@/${(deps[0] as IInternalDependency).type}/${pkg}';`); statementL.push(`'@/${(deps[0] as IInternalDependency).type}/${pkg}';`);
chunks.push({ chunks.push({
type: ChunkType.STRING, type: ChunkType.STRING,
fileType: isJSX ? FileType.JSX : FileType.JS, fileType: targetFileType,
name: COMMON_CHUNK_NAME.InternalDepsImport, name: COMMON_CHUNK_NAME.InternalDepsImport,
content: statementL.join(' '), content: statementL.join(' '),
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport], linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
@ -112,7 +113,7 @@ function buildPackageImport(
statementL.push(`'${pkg}';`); statementL.push(`'${pkg}';`);
chunks.push({ chunks.push({
type: ChunkType.STRING, type: ChunkType.STRING,
fileType: isJSX ? FileType.JSX : FileType.JS, fileType: targetFileType,
name: COMMON_CHUNK_NAME.ExternalDepsImport, name: COMMON_CHUNK_NAME.ExternalDepsImport,
content: statementL.join(' '), content: statementL.join(' '),
linkAfter: [], linkAfter: [],
@ -122,20 +123,28 @@ function buildPackageImport(
return chunks; return chunks;
} }
interface PluginConfig {
fileType: string;
}
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?: PluginConfig) => {
const cfg: PluginConfig = {
fileType: FileType.JS,
...config,
};
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
}; };
const isJSX = next.chunks.some(chunk => chunk.fileType === FileType.JSX);
const ir = next.ir as IWithDependency; const ir = next.ir as IWithDependency;
if (ir && ir.deps && ir.deps.length > 0) { if (ir && ir.deps && ir.deps.length > 0) {
const packs = groupDepsByPack(ir.deps); const packs = groupDepsByPack(ir.deps);
Object.keys(packs).forEach(pkg => { Object.keys(packs).forEach(pkg => {
const chunks = buildPackageImport(pkg, packs[pkg], isJSX); const chunks = buildPackageImport(pkg, packs[pkg], cfg.fileType);
next.chunks.push.apply(next.chunks, chunks); next.chunks.push.apply(next.chunks, chunks);
}); });
} }
@ -143,4 +152,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
export default plugin; return plugin;
};
export default pluginFactory;

View File

@ -2,12 +2,14 @@ import { COMMON_CHUNK_NAME } from '../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
} from '../../types'; } from '../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -23,5 +25,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -3,12 +3,14 @@ import { REACT_CHUNK_NAME } from './const';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
IContainerInfo, IContainerInfo,
} from '../../../types'; } from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -97,5 +99,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -4,12 +4,14 @@ import { generateCompositeType } from '../../utils/compositeType';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
IContainerInfo, IContainerInfo,
} from '../../../types'; } from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -35,5 +37,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -4,12 +4,14 @@ import { generateCompositeType } from '../../utils/compositeType';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
IContainerInfo, IContainerInfo,
} from '../../../types'; } from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -35,5 +37,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,11 +2,13 @@ import { REACT_CHUNK_NAME } from './const';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
} from '../../../types'; } from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -22,5 +24,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -7,6 +7,7 @@ import {
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
CodeGeneratorError, CodeGeneratorError,
FileType, FileType,
@ -16,6 +17,7 @@ import {
IJSExpression, IJSExpression,
} from '../../../types'; } from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -77,5 +79,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -4,6 +4,7 @@ import { transformFuncExpr2MethodMember } from '../../utils/jsExpression';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeChunk, ICodeChunk,
@ -12,6 +13,7 @@ import {
IJSExpression, IJSExpression,
} from '../../../types'; } from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -41,5 +43,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -1,5 +1,6 @@
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChildNodeItem, ChildNodeItem,
ChildNodeType, ChildNodeType,
ChunkType, ChunkType,
@ -111,6 +112,7 @@ function generateChildren(children: ChildNodeType): string[] {
}); });
} }
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -145,5 +147,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -9,6 +10,7 @@ import {
} from '../../../types'; } from '../../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -24,5 +26,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,12 +2,14 @@ import { COMMON_CHUNK_NAME } from '../../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
IContainerInfo, IContainerInfo,
} from '../../../types'; } from '../../../types';
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -33,5 +35,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../const/generator';
import { generateCompositeType } from '../../plugins/utils/compositeType'; import { generateCompositeType } from '../../plugins/utils/compositeType';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -9,6 +10,7 @@ import {
} from '../../types'; } from '../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -50,5 +52,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -9,6 +10,7 @@ import {
} from '../../../../../types'; } from '../../../../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -51,5 +53,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -9,6 +10,7 @@ import {
} from '../../../../../types'; } from '../../../../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -39,5 +41,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -9,6 +10,7 @@ import {
} from '../../../../../types'; } from '../../../../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -49,5 +51,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -21,6 +22,7 @@ interface IIceJsPackageJSON extends IPackageJSON {
} }
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -82,5 +84,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../../../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -9,6 +10,7 @@ import {
} from '../../../../../types'; } from '../../../../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -75,5 +77,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../const/generator';
import { generateCompositeType } from '../../plugins/utils/compositeType'; import { generateCompositeType } from '../../plugins/utils/compositeType';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -9,6 +10,7 @@ import {
} from '../../types'; } from '../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -62,5 +64,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -2,6 +2,7 @@ import { COMMON_CHUNK_NAME } from '../../const/generator';
import { import {
BuilderComponentPlugin, BuilderComponentPlugin,
BuilderComponentPluginFactory,
ChunkType, ChunkType,
FileType, FileType,
ICodeStruct, ICodeStruct,
@ -9,6 +10,7 @@ import {
} from '../../types'; } from '../../types';
// TODO: How to merge this logic to common deps // TODO: How to merge this logic to common deps
const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => { const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
const next: ICodeStruct = { const next: ICodeStruct = {
...pre, ...pre,
@ -85,5 +87,7 @@ const plugin: BuilderComponentPlugin = async (pre: ICodeStruct) => {
return next; return next;
}; };
return plugin;
};
export default plugin; export default pluginFactory;

View File

@ -1,12 +1,13 @@
import prettier from 'prettier'; import prettier from 'prettier';
import { PostProcessor } from '../../types'; import { PostProcessor, PostProcessorFactory } from '../../types';
const PARSERS = ['css', 'scss', 'less', 'json', 'html', 'vue']; const PARSERS = ['css', 'scss', 'less', 'json', 'html', 'vue'];
const factory: PostProcessorFactory<unknown> = () => {
const codePrettier: PostProcessor = (content: string, fileType: string) => { const codePrettier: PostProcessor = (content: string, fileType: string) => {
let parser: prettier.BuiltInParserName; let parser: prettier.BuiltInParserName;
if (fileType === 'js' || fileType === 'jsx') { if (fileType === 'js' || fileType === 'jsx' || fileType === 'ts' || fileType === 'tsx') {
parser = 'babel'; parser = 'babel';
} else if (PARSERS.indexOf(fileType) >= 0) { } else if (PARSERS.indexOf(fileType) >= 0) {
parser = fileType as prettier.BuiltInParserName; parser = fileType as prettier.BuiltInParserName;
@ -19,4 +20,7 @@ const codePrettier: PostProcessor = (content: string, fileType: string) => {
}); });
}; };
export default codePrettier; return codePrettier;
};
export default factory;

View File

@ -28,36 +28,40 @@ export default function createIceJsProjectBuilder(): IProjectBuilder {
template, template,
plugins: { plugins: {
components: [ components: [
reactCommonDeps, reactCommonDeps(),
esmodule, esmodule({
containerClass, fileType: 'jsx',
containerInjectUtils, }),
containerInitState, containerClass(),
containerLifeCycle, containerInjectUtils(),
containerMethod, containerInitState(),
jsx, containerLifeCycle(),
css, containerMethod(),
jsx(),
css(),
], ],
pages: [ pages: [
reactCommonDeps, reactCommonDeps(),
esmodule, esmodule({
containerClass, fileType: 'jsx',
containerInjectUtils, }),
containerInitState, containerClass(),
containerLifeCycle, containerInjectUtils(),
containerMethod, containerInitState(),
jsx, containerLifeCycle(),
css, containerMethod(),
jsx(),
css(),
], ],
router: [esmodule, iceJsRouter], router: [esmodule(), iceJsRouter()],
entry: [iceJsEntry], entry: [iceJsEntry()],
constants: [constants], constants: [constants()],
utils: [esmodule, utils], utils: [esmodule(), utils()],
i18n: [i18n], i18n: [i18n()],
globalStyle: [iceJsGlobalStyle], globalStyle: [iceJsGlobalStyle()],
htmlEntry: [iceJsEntryHtml], htmlEntry: [iceJsEntryHtml()],
packageJSON: [iceJsPackageJSON], packageJSON: [iceJsPackageJSON()],
}, },
postProcessors: [prettier], postProcessors: [prettier()],
}); });
} }

View File

@ -12,6 +12,8 @@ export enum FileType {
HTML = 'html', HTML = 'html',
JS = 'js', JS = 'js',
JSX = 'jsx', JSX = 'jsx',
TS = 'ts',
TSX = 'tsx',
JSON = 'json', JSON = 'json',
} }
@ -32,7 +34,7 @@ export type CodeGeneratorFunction<T> = (content: T) => string;
export interface ICodeChunk { export interface ICodeChunk {
type: ChunkType; type: ChunkType;
fileType: FileType; fileType: string;
name: string; name: string;
subModule?: string; subModule?: string;
content: ChunkContent; content: ChunkContent;
@ -53,6 +55,8 @@ export type BuilderComponentPlugin = (
initStruct: ICodeStruct, initStruct: ICodeStruct,
) => Promise<ICodeStruct>; ) => Promise<ICodeStruct>;
export type BuilderComponentPluginFactory<T> = (config?: T) => BuilderComponentPlugin;
export interface IChunkBuilder { export interface IChunkBuilder {
run( run(
ir: any, ir: any,
@ -142,6 +146,7 @@ export interface IProjectBuilder {
generateProject(schema: IProjectSchema): Promise<IResultDir>; generateProject(schema: IProjectSchema): Promise<IResultDir>;
} }
export type PostProcessorFactory<T> = (config?: T) => PostProcessor;
export type PostProcessor = (content: string, fileType: string) => string; export type PostProcessor = (content: string, fileType: string) => string;
// TODO: temp interface, need modify // TODO: temp interface, need modify

View File

@ -144,14 +144,7 @@ export interface IContainerNodeItem extends IComponentNodeItem {
* componentWillUnmount() * componentWillUnmount()
* componentDidCatch(error, info) * componentDidCatch(error, info)
*/ */
lifeCycles?: { lifeCycles?: Record<string, IJSExpression>; // 生命周期Hook方法
constructor?: IJSExpression;
render?: IJSExpression;
componentDidMount?: IJSExpression;
componentDidUpdate?: IJSExpression;
componentWillUnmount?: IJSExpression;
componentDidCatch?: IJSExpression;
}; // 生命周期Hook方法
methods?: { methods?: {
[methodName: string]: IJSExpression; [methodName: string]: IJSExpression;
}; // 自定义方法设置 }; // 自定义方法设置

View File

@ -5,6 +5,7 @@
"lib": [ "lib": [
"es6" "es6"
], ],
"module": "commonjs",
"types": ["node"], "types": ["node"],
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */ "baseUrl": ".", /* Base directory to resolve non-absolute module names. */
}, },