feat(cli): cli返回app

This commit is contained in:
roymondchen 2023-02-22 15:38:13 +08:00
parent 62038c8c60
commit c41af9d01d
2 changed files with 5 additions and 6 deletions

View File

@ -3,12 +3,13 @@ import { cac } from 'cac';
import { allowTs } from './utils/allowTs';
import { error } from './utils/logger';
import { scripts } from './commands';
import App from './Core';
import { UserConfig } from './types';
/**
* 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) =>
cmd(...args).catch((err) => {
error(err.stack);

View File

@ -7,7 +7,7 @@ import { UserConfig } from '../types';
import { loadUserConfig } from '../utils/loadUserConfig';
export const scripts = (defaultAppConfig: UserConfig) => {
const entry = async (): Promise<void> => {
const entry = async (): Promise<App> => {
if (process.env.NODE_ENV === undefined) {
process.env.NODE_ENV = 'development';
}
@ -34,10 +34,6 @@ export const scripts = (defaultAppConfig: UserConfig) => {
},
};
if (appConfig === null) {
return;
}
// create vuepress app
const app = new App(appConfig);
@ -49,6 +45,8 @@ export const scripts = (defaultAppConfig: UserConfig) => {
// initialize and prepare
await app.init();
await app.prepare();
return app;
};
return entry;