mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-05-08 19:49:24 +08:00
feat(cli): cli返回app
This commit is contained in:
parent
62038c8c60
commit
c41af9d01d
@ -3,12 +3,13 @@ import { cac } from 'cac';
|
|||||||
import { allowTs } from './utils/allowTs';
|
import { allowTs } from './utils/allowTs';
|
||||||
import { error } from './utils/logger';
|
import { error } from './utils/logger';
|
||||||
import { scripts } from './commands';
|
import { scripts } from './commands';
|
||||||
|
import App from './Core';
|
||||||
import { UserConfig } from './types';
|
import { UserConfig } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap raw command to catch errors and exit process
|
* Wrap raw command to catch errors and exit process
|
||||||
*/
|
*/
|
||||||
const wrapCommand = (cmd: (...args: any[]) => Promise<void>): typeof cmd => {
|
const wrapCommand = (cmd: (...args: any[]) => Promise<App>): typeof cmd => {
|
||||||
const wrappedCommand: typeof cmd = (...args) =>
|
const wrappedCommand: typeof cmd = (...args) =>
|
||||||
cmd(...args).catch((err) => {
|
cmd(...args).catch((err) => {
|
||||||
error(err.stack);
|
error(err.stack);
|
||||||
|
@ -7,7 +7,7 @@ import { UserConfig } from '../types';
|
|||||||
import { loadUserConfig } from '../utils/loadUserConfig';
|
import { loadUserConfig } from '../utils/loadUserConfig';
|
||||||
|
|
||||||
export const scripts = (defaultAppConfig: UserConfig) => {
|
export const scripts = (defaultAppConfig: UserConfig) => {
|
||||||
const entry = async (): Promise<void> => {
|
const entry = async (): Promise<App> => {
|
||||||
if (process.env.NODE_ENV === undefined) {
|
if (process.env.NODE_ENV === undefined) {
|
||||||
process.env.NODE_ENV = 'development';
|
process.env.NODE_ENV = 'development';
|
||||||
}
|
}
|
||||||
@ -34,10 +34,6 @@ export const scripts = (defaultAppConfig: UserConfig) => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (appConfig === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// create vuepress app
|
// create vuepress app
|
||||||
const app = new App(appConfig);
|
const app = new App(appConfig);
|
||||||
|
|
||||||
@ -49,6 +45,8 @@ export const scripts = (defaultAppConfig: UserConfig) => {
|
|||||||
// initialize and prepare
|
// initialize and prepare
|
||||||
await app.init();
|
await app.init();
|
||||||
await app.prepare();
|
await app.prepare();
|
||||||
|
|
||||||
|
return app;
|
||||||
};
|
};
|
||||||
|
|
||||||
return entry;
|
return entry;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user