mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-23 07:42:07 +08:00
feat(cli): 添加onInit/onPrepare配置
This commit is contained in:
parent
4e4cae4a77
commit
87f1bfbdd6
@ -2,7 +2,7 @@ import path from 'path';
|
||||
|
||||
import fs from 'fs-extra';
|
||||
|
||||
import { UserConfig } from './types';
|
||||
import { ModuleMainFilePath, UserConfig } from './types';
|
||||
import { prepareEntryFile, resolveAppPackages } from './utils';
|
||||
|
||||
export default class Core {
|
||||
@ -10,7 +10,7 @@ export default class Core {
|
||||
|
||||
public options: UserConfig;
|
||||
|
||||
public moduleMainFilePath = {
|
||||
public moduleMainFilePath: ModuleMainFilePath = {
|
||||
componentMap: {},
|
||||
pluginMap: {},
|
||||
configMap: {},
|
||||
@ -32,9 +32,16 @@ export default class Core {
|
||||
|
||||
public async init() {
|
||||
this.moduleMainFilePath = resolveAppPackages(this);
|
||||
if (typeof this.options.onInit === 'function') {
|
||||
this.moduleMainFilePath = await this.options.onInit(this);
|
||||
}
|
||||
}
|
||||
|
||||
public async prepare() {
|
||||
await prepareEntryFile(this);
|
||||
|
||||
if (typeof this.options.onPrepare === 'function') {
|
||||
this.options.onPrepare(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import type Core from './Core';
|
||||
|
||||
export enum EntryType {
|
||||
CONFIG = 'config',
|
||||
VALUE = 'value',
|
||||
@ -36,6 +38,14 @@ export interface NpmConfig {
|
||||
client?: 'npm' | 'yarn' | 'pnpm';
|
||||
}
|
||||
|
||||
export interface ModuleMainFilePath {
|
||||
componentMap: Record<string, string>;
|
||||
pluginMap: Record<string, string>;
|
||||
configMap: Record<string, string>;
|
||||
valueMap: Record<string, string>;
|
||||
eventMap: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface UserConfig {
|
||||
source: string;
|
||||
temp: string;
|
||||
@ -43,4 +53,6 @@ export interface UserConfig {
|
||||
componentFileAffix: string;
|
||||
cleanTemp: boolean;
|
||||
npmConfig?: NpmConfig;
|
||||
onInit?: (app: Core) => ModuleMainFilePath | Promise<ModuleMainFilePath>;
|
||||
onPrepare?: (app: Core) => void;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import fs from 'fs-extra';
|
||||
import * as recast from 'recast';
|
||||
|
||||
import type App from '../Core';
|
||||
import { Entry, EntryType, NpmConfig, PackageType } from '../types';
|
||||
import { Entry, EntryType, ModuleMainFilePath, NpmConfig, PackageType } from '../types';
|
||||
|
||||
interface TypeAssertion {
|
||||
type: string;
|
||||
@ -20,7 +20,7 @@ interface ParseEntryOption {
|
||||
indexPath: string;
|
||||
}
|
||||
|
||||
export const resolveAppPackages = (app: App) => {
|
||||
export const resolveAppPackages = (app: App): ModuleMainFilePath => {
|
||||
const componentMap: Record<string, string> = {};
|
||||
const configMap: Record<string, string> = {};
|
||||
const eventMap: Record<string, string> = {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user