Skip to content

Commit

Permalink
feat(cli): cli返回app
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Feb 22, 2023
1 parent 62038c8 commit c41af9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions packages/cli/src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -34,10 +34,6 @@ export const scripts = (defaultAppConfig: UserConfig) => {
},
};

if (appConfig === null) {
return;
}

// create vuepress app
const app = new App(appConfig);

Expand All @@ -49,6 +45,8 @@ export const scripts = (defaultAppConfig: UserConfig) => {
// initialize and prepare
await app.init();
await app.prepare();

return app;
};

return entry;
Expand Down

0 comments on commit c41af9d

Please sign in to comment.