Skip to content

Commit 576d91e

Browse files
committed
🎉 feat(app): 更新
1 parent 61c1dd3 commit 576d91e

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

src/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface ImpSortOptions {
2+
files: Array<string>;
3+
}
4+
5+
export const impSortGlob = ["./src"];

src/index.ts

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,16 @@ import path from "node:path";
22
import { performance } from "node:perf_hooks";
33

44
import type { CAC } from "cac";
5-
import {
6-
ACTIVATION,
7-
CodeGeniusOptions,
8-
impSortGlob,
9-
ImpSortOptions,
10-
loggerInfo,
11-
printError,
12-
printInfo,
13-
} from "code-genius";
5+
import { ACTIVATION, loggerInfo, printError, printInfo } from "code-genius";
146
import enquirer from "enquirer";
157
import { ESLint } from "eslint";
168
import fs from "fs-extra";
179

18-
const mergeConfig = async (config: CodeGeniusOptions) => {
19-
const commands = config && config?.commands;
20-
if (commands && commands.impsort) {
21-
const { paths } = commands.impsort;
22-
return {
23-
paths: paths && paths.length > 0 ? paths : impSortGlob,
24-
};
25-
}
26-
return {
27-
paths: impSortGlob,
28-
};
29-
};
10+
import { impSortGlob, ImpSortOptions } from "./common";
3011

3112
const generateEnquirer = async (
32-
config: CodeGeniusOptions,
33-
): Promise<ImpSortOptions> => {
13+
paths: Array<string>,
14+
): Promise<Array<string>> => {
3415
const files = fs
3516
.readdirSync(path.join(process.cwd(), "."))
3617
.filter((v) => !v.startsWith("."))
@@ -41,7 +22,6 @@ const generateEnquirer = async (
4122
};
4223
});
4324
files.sort((v1, v2) => v1.sort - v2.sort);
44-
const { paths } = await mergeConfig(config);
4525
const fileMultiChoices = files.map((v) => {
4626
return {
4727
name: `./${v.file}`,
@@ -57,9 +37,7 @@ const generateEnquirer = async (
5737
choices: fileMultiChoices,
5838
},
5939
]);
60-
return {
61-
files: result.files,
62-
};
40+
return result.files;
6341
};
6442

6543
const impSort = async (paths: string[]) => {
@@ -89,7 +67,8 @@ const impSort = async (paths: string[]) => {
8967
}
9068
};
9169

92-
const impSortInstaller = (config: CodeGeniusOptions) => {
70+
const impSortInstaller = (config: ImpSortOptions) => {
71+
const { files } = config;
9372
return {
9473
name: "impSortInstaller",
9574
setup: (cli: CAC) => {
@@ -99,11 +78,10 @@ const impSortInstaller = (config: CodeGeniusOptions) => {
9978
.option("-a, --ask", "启用询问模式")
10079
.action(async (options) => {
10180
const { pattern, ask } = options;
102-
let paths = [];
81+
let paths = files || impSortGlob;
10382
if (ask) {
104-
const result = await generateEnquirer(config);
105-
paths = result.files;
106-
} else {
83+
paths = await generateEnquirer(paths);
84+
} else if (pattern) {
10785
paths = typeof pattern === "string" ? [pattern] : pattern;
10886
}
10987
const start = performance.now();

0 commit comments

Comments
 (0)