mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-22 23:20:00 +08:00
feat(cli): 增加 hook.beforeWriteEntry
This commit is contained in:
parent
258ac4d56b
commit
4c94fa0a8f
@ -60,6 +60,9 @@ export interface UserConfig {
|
|||||||
npmConfig?: NpmConfig;
|
npmConfig?: NpmConfig;
|
||||||
/** 是否使用import()加载组件 */
|
/** 是否使用import()加载组件 */
|
||||||
dynamicImport?: boolean;
|
dynamicImport?: boolean;
|
||||||
|
hooks?: {
|
||||||
|
beforeWriteEntry?: (genContentMap: Record<string, string>, app: Core) => void;
|
||||||
|
};
|
||||||
onInit?: (app: Core) => ModuleMainFilePath | Promise<ModuleMainFilePath>;
|
onInit?: (app: Core) => ModuleMainFilePath | Promise<ModuleMainFilePath>;
|
||||||
onPrepare?: (app: Core) => void;
|
onPrepare?: (app: Core) => void;
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,26 @@ import * as recast from 'recast';
|
|||||||
import type App from '../Core';
|
import type App from '../Core';
|
||||||
import { EntryType } from '../types';
|
import { EntryType } from '../types';
|
||||||
|
|
||||||
export const prepareEntryFile = (app: App) => {
|
export const prepareEntryFile = async (app: App) => {
|
||||||
const { componentMap = {}, pluginMap = {}, configMap = {}, valueMap = {}, eventMap = {} } = app.moduleMainFilePath;
|
const { componentMap = {}, pluginMap = {}, configMap = {}, valueMap = {}, eventMap = {} } = app.moduleMainFilePath;
|
||||||
const { componentFileAffix, dynamicImport } = app.options;
|
const { componentFileAffix, dynamicImport, hooks } = app.options;
|
||||||
|
const contentMap: Record<string, string> = {
|
||||||
|
'comp-entry.ts': generateContent(EntryType.COMPONENT, componentMap, componentFileAffix),
|
||||||
|
'async-comp-entry.ts': generateContent(EntryType.COMPONENT, componentMap, componentFileAffix, dynamicImport),
|
||||||
|
'plugin-entry.ts': generateContent(EntryType.PLUGIN, pluginMap),
|
||||||
|
'async-plugin-entry.ts': generateContent(EntryType.PLUGIN, pluginMap, '', dynamicImport),
|
||||||
|
'config-entry.ts': generateContent(EntryType.CONFIG, configMap),
|
||||||
|
'value-entry.ts': generateContent(EntryType.VALUE, valueMap),
|
||||||
|
'event-entry.ts': generateContent(EntryType.EVENT, eventMap),
|
||||||
|
};
|
||||||
|
|
||||||
app.writeTemp('comp-entry.ts', generateContent(EntryType.COMPONENT, componentMap, componentFileAffix));
|
if (typeof hooks?.beforeWriteEntry === 'function') {
|
||||||
app.writeTemp(
|
await hooks.beforeWriteEntry(contentMap, app);
|
||||||
'async-comp-entry.ts',
|
}
|
||||||
generateContent(EntryType.COMPONENT, componentMap, componentFileAffix, dynamicImport),
|
|
||||||
);
|
|
||||||
|
|
||||||
app.writeTemp('plugin-entry.ts', generateContent(EntryType.PLUGIN, pluginMap));
|
Object.keys(contentMap).forEach((fileName: string) => {
|
||||||
app.writeTemp('async-plugin-entry.ts', generateContent(EntryType.PLUGIN, pluginMap, '', dynamicImport));
|
app.writeTemp(fileName, contentMap[fileName]);
|
||||||
app.writeTemp('config-entry.ts', generateContent(EntryType.CONFIG, configMap));
|
});
|
||||||
app.writeTemp('value-entry.ts', generateContent(EntryType.VALUE, valueMap));
|
|
||||||
app.writeTemp('event-entry.ts', generateContent(EntryType.EVENT, eventMap));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateContent = (
|
const generateContent = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user