Skip to content

Commit b8952b6

Browse files
committed
chore: Refactor CLI commands
1 parent 21debad commit b8952b6

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

src/cli/commands/build.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as exvite from '../..';
2+
import { getInternalConfig } from '../../utils/getInternalConfig';
23
import { defineCommand } from '../utils/defineCommand';
34

4-
export const build = defineCommand(async (root: any, { mode, config }: any) => {
5-
await exvite.build({
6-
mode,
7-
root,
8-
configFile: config,
9-
});
10-
});
5+
export const build = defineCommand(
6+
async (root: any, { mode, config: configFile }: any) => {
7+
const cliConfig: exvite.InlineConfig = { root, mode, configFile };
8+
const config = await getInternalConfig(cliConfig, mode);
9+
10+
await exvite.build(config);
11+
},
12+
);

src/cli/commands/dev.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import * as exvite from '../..';
22
import { defineCommand } from '../utils/defineCommand';
33

4-
export const dev = defineCommand(async (root: any, { mode, config }: any) => {
5-
await exvite.createServer({
6-
mode,
7-
root,
8-
configFile: config,
9-
});
10-
});
4+
export const dev = defineCommand(
5+
async (root: any, { mode, config: configFile }: any) => {
6+
const cliConfig: exvite.InlineConfig = {
7+
mode,
8+
root,
9+
configFile,
10+
};
11+
await exvite.createServer(cliConfig);
12+
},
13+
);

src/cli/commands/prepare.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import { getInternalConfig } from '../../utils/getInternalConfig';
22
import { findEntrypoints } from '../../utils/findEntrypoints';
33
import { generateTypesDir } from '../../utils/generateTypesDir';
44
import { defineCommand } from '../utils/defineCommand';
5+
import * as exvite from '../..';
56

67
export const prepare = defineCommand(
7-
async (root: any, { mode, config }: any) => {
8-
const internalConfig = await getInternalConfig(
9-
{ root, mode, configFile: config },
10-
'build',
11-
);
12-
internalConfig.logger.info('Generating types...');
8+
async (root: any, { mode, config: configFile }: any) => {
9+
const cliConfig: exvite.InlineConfig = { root, mode, configFile };
10+
const config = await getInternalConfig(cliConfig, 'build');
1311

14-
const entrypoints = await findEntrypoints(internalConfig);
15-
await generateTypesDir(entrypoints, internalConfig);
12+
config.logger.info('Generating types...');
13+
14+
const entrypoints = await findEntrypoints(config);
15+
await generateTypesDir(entrypoints, config);
1616
},
1717
);

src/cli/commands/publish.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { consola } from 'consola';
22
import { defineCommand } from '../utils/defineCommand';
33

4-
export const publish = defineCommand(async (root: any, { config }: any) => {
5-
consola.warn('exvite publish: Not implemented');
6-
});
4+
export const publish = defineCommand(
5+
async (root: any, { config: configFile }: any) => {
6+
consola.warn('exvite publish: Not implemented');
7+
},
8+
);

0 commit comments

Comments
 (0)