Skip to content

Commit f056595

Browse files
committed
🔧chore(app): 重构注册部分
1 parent db9b543 commit f056595

File tree

6 files changed

+84
-52
lines changed

6 files changed

+84
-52
lines changed

src/cli.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import cac from "cac";
22

3-
import { handleError } from "@/shared/index";
3+
import { cmdInstaller, handleError } from "@/shared/index";
44

55
import pkg from "../package.json";
6-
import { cmdInstaller } from "./setup";
6+
import config from "@/index";
77

8-
export const setupCli = async () => {
8+
const setupCli = async () => {
99
const cli = cac("codeg");
1010

11-
cmdInstaller(cli);
11+
cmdInstaller(cli, config);
1212

1313
cli.help();
1414
cli.version(pkg.version);

src/command/git-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
printWarring,
99
} from "@/shared/index";
1010
import { ACTIVATION, gitUserOptions } from "@/shared/config";
11-
import { GitUserOptions } from "..";
11+
import { GitUserOptions } from "@/shared/types";
1212

1313
async function printCurrentGitUser() {
1414
const name = await execCommand("git", ["config", "user.name"]);

src/index.ts

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,59 @@
1-
export * from "@/command/clear";
2-
export * from "@/command/git-commit";
3-
export * from "@/command/git-commit-verify";
4-
export * from "@/command/git-init-hooks";
5-
export * from "@/command/npm-run";
6-
export * from "@/command/npm-dep-check";
7-
export * from "@/command/eslint-fix";
8-
export * from "@/command/prettier-format";
1+
import rootInstaller, { root } from "@/command/root";
2+
import createProjectInstaller, {
3+
createProject,
4+
} from "@/command/create-project";
5+
import clearInstaller, { clear } from "@/command/clear";
6+
import gitCommitInstaller, { gitCommit } from "@/command/git-commit";
7+
import gitCommitVerifyInstaller, {
8+
gitCommitVerify,
9+
} from "@/command/git-commit-verify";
10+
import gitInitSimpleHooksInstaller, {
11+
gitInitSimpleHooks,
12+
} from "@/command/git-init-hooks";
13+
import npmDepCheckInstaller, { npmDepCheck } from "@/command/npm-dep-check";
14+
import npmRegistryInstaller, { npmRegistry } from "@/command/npm-registry";
15+
import eslintFixInstaller, { eslintFix } from "@/command/eslint-fix";
16+
import prettierFormatInstaller, {
17+
prettierFormat,
18+
} from "@/command/prettier-format";
19+
import templateInstaller, { template } from "@/command/template";
20+
import lighthouseInstaller, { lighthouse } from "@/command/lighthouse";
21+
import gitUserInstaller, { gitUser } from "@/command/git-user";
22+
import quantityInstaller, { quantity } from "@/command/quantity";
23+
import { defineConfig } from "@/shared/index";
924

10-
export * from "@/shared/index";
11-
export * from "@/shared/config";
12-
export * from "@/shared/types";
25+
export {
26+
root,
27+
createProject,
28+
clear,
29+
gitCommit,
30+
gitCommitVerify,
31+
gitInitSimpleHooks,
32+
npmDepCheck,
33+
npmRegistry,
34+
eslintFix,
35+
prettierFormat,
36+
template,
37+
lighthouse,
38+
gitUser,
39+
quantity,
40+
};
1341

14-
export * from "@/setup";
42+
export default defineConfig({
43+
plugins: [
44+
rootInstaller,
45+
gitCommitInstaller,
46+
gitCommitVerifyInstaller,
47+
gitUserInstaller,
48+
gitInitSimpleHooksInstaller,
49+
npmRegistryInstaller,
50+
clearInstaller,
51+
npmDepCheckInstaller,
52+
eslintFixInstaller,
53+
prettierFormatInstaller,
54+
createProjectInstaller,
55+
templateInstaller,
56+
lighthouseInstaller,
57+
quantityInstaller,
58+
],
59+
});

src/setup.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/shared/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { green, yellow, gray, red } from "kolorist";
99
import boxen from "boxen";
1010

1111
import { ACTIVATION, FRAMEWORKS, TEMPLATES } from "@/shared/config";
12+
import { CAC } from "cac";
13+
import { CodeGeniusOptions } from "./types";
1214

1315
const boxenBorderStyle = {
1416
padding: 1,
@@ -285,3 +287,13 @@ export function generateRandom(length: number) {
285287
}
286288
return result;
287289
}
290+
291+
export const defineConfig = (config: CodeGeniusOptions): CodeGeniusOptions =>
292+
config;
293+
294+
export function cmdInstaller(cli: CAC, config: CodeGeniusOptions) {
295+
const { plugins } = config;
296+
for (const plugin of plugins) {
297+
plugin(cli).setup();
298+
}
299+
}

src/shared/types.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { CAC } from "cac";
22

3+
export type ColorFunc = (str: string | number) => string;
34
export interface CommandSet {
45
[key: string]: (cli: CAC) => void;
56
}
@@ -31,8 +32,6 @@ export interface TemplateOptions {
3132
framework: string;
3233
}
3334

34-
export type ColorFunc = (str: string | number) => string;
35-
3635
export interface FrameworkVariant {
3736
framework: string;
3837
name: string;
@@ -54,3 +53,12 @@ export interface GitUserOptions {
5453
ruleName?: string;
5554
ruleEmail?: string;
5655
}
56+
57+
export interface CodeGeniusOptions {
58+
plugins: Array<
59+
(cli: CAC) => {
60+
name: string;
61+
setup: () => void;
62+
}
63+
>;
64+
}

0 commit comments

Comments
 (0)