mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-06-17 18:51:33 +08:00
feat(cli): 增加 useTs 配置
This commit is contained in:
parent
bc4b62a4c1
commit
b512e14129
@ -8,5 +8,6 @@ cli({
|
||||
componentFileAffix: '',
|
||||
cleanTemp: true,
|
||||
temp: '.tmagic',
|
||||
useTs: true,
|
||||
dynamicImport: false,
|
||||
});
|
||||
|
@ -60,6 +60,8 @@ export interface UserConfig {
|
||||
npmConfig?: NpmConfig;
|
||||
/** 是否使用import()加载组件 */
|
||||
dynamicImport?: boolean;
|
||||
/** 入口文件是否生成为 ts 格式 */
|
||||
useTs?: boolean;
|
||||
hooks?: {
|
||||
beforeWriteEntry?: (genContentMap: Record<string, string>, app: Core) => Promise<Record<string, string>>;
|
||||
};
|
||||
|
@ -5,27 +5,30 @@ import { EntryType } from '../types';
|
||||
|
||||
export const prepareEntryFile = async (app: App) => {
|
||||
const { componentMap = {}, pluginMap = {}, configMap = {}, valueMap = {}, eventMap = {} } = app.moduleMainFilePath;
|
||||
const { componentFileAffix, dynamicImport, hooks } = app.options;
|
||||
const { componentFileAffix, dynamicImport, hooks, useTs } = app.options;
|
||||
|
||||
let 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),
|
||||
'comp-entry': generateContent(useTs, EntryType.COMPONENT, componentMap, componentFileAffix),
|
||||
'async-comp-entry': generateContent(useTs, EntryType.COMPONENT, componentMap, componentFileAffix, dynamicImport),
|
||||
'plugin-entry': generateContent(useTs, EntryType.PLUGIN, pluginMap),
|
||||
'async-plugin-entry': generateContent(useTs, EntryType.PLUGIN, pluginMap, '', dynamicImport),
|
||||
'config-entry': generateContent(useTs, EntryType.CONFIG, configMap),
|
||||
'value-entry': generateContent(useTs, EntryType.VALUE, valueMap),
|
||||
'event-entry': generateContent(useTs, EntryType.EVENT, eventMap),
|
||||
};
|
||||
|
||||
if (typeof hooks?.beforeWriteEntry === 'function') {
|
||||
contentMap = await hooks.beforeWriteEntry(contentMap, app);
|
||||
}
|
||||
|
||||
Object.keys(contentMap).forEach((fileName: string) => {
|
||||
app.writeTemp(fileName, contentMap[fileName]);
|
||||
Object.keys(contentMap).forEach((file: string) => {
|
||||
const fileName = `${file}.${useTs ? 'ts' : 'js'}`;
|
||||
app.writeTemp(fileName, contentMap[file]);
|
||||
});
|
||||
};
|
||||
|
||||
const generateContent = (
|
||||
useTs = true,
|
||||
type: EntryType,
|
||||
map: Record<string, string>,
|
||||
componentFileAffix = '',
|
||||
@ -51,7 +54,7 @@ const generateContent = (
|
||||
const exportToken = `${type}s`;
|
||||
|
||||
return prettyCode(`${importDeclarations.join(';')}
|
||||
const ${exportToken}: Record<string, any> = {
|
||||
const ${exportToken}${useTs ? ': Record<string, any>' : ''} = {
|
||||
${list.join(',')}
|
||||
}
|
||||
export default ${exportToken};
|
||||
|
Loading…
x
Reference in New Issue
Block a user