Skip to content

Commit dbeec84

Browse files
committed
🎉 feat(app): 抹平差异
1 parent 0ca7649 commit dbeec84

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

src/common.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
1-
import Ajv from "ajv";
2-
31
export interface ClearOptions {
42
files: Array<string>;
53
}
64

75
export const clearGlob = ["./dist"];
8-
9-
export const schema = {
10-
type: "object",
11-
properties: {
12-
paths: { type: "array" },
13-
},
14-
required: ["paths"],
15-
};
16-
17-
export const validateArgs = (schema: object, data: unknown) => {
18-
const ajv = new Ajv();
19-
const validate = ajv.compile(schema);
20-
const valid = validate(data);
21-
if (!valid && validate.errors && validate.errors?.length > 0) {
22-
throw new Error(validate.errors[0].message);
23-
}
24-
};

src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ACTIVATION, execCommand, loggerInfo, printInfo } from "code-genius";
66
import enquirer from "enquirer";
77
import fs from "fs-extra";
88

9-
import { clearGlob, ClearOptions, schema, validateArgs } from "./common";
9+
import { clearGlob, ClearOptions } from "./common";
1010

1111
const generateEnquirer = async (
1212
paths: Array<string>,
@@ -44,9 +44,6 @@ const clear = async (paths: string[]) => {
4444
if (ACTIVATION) {
4545
loggerInfo(`clear 参数信息: \n ${JSON.stringify(paths)}`);
4646
}
47-
48-
validateArgs(schema, paths);
49-
5047
await execCommand("npx", ["rimraf", "--glob", ...paths], {
5148
stdio: "inherit",
5249
});
@@ -64,10 +61,10 @@ const clearInstaller = (config: ClearOptions) => {
6461
.option("-a, --ask", "启用询问模式")
6562
.action(async (options) => {
6663
const { pattern, ask } = options;
67-
let paths = [];
64+
let paths = files || clearGlob;
6865
if (ask) {
69-
paths = await generateEnquirer(files || clearGlob);
70-
} else {
66+
paths = await generateEnquirer(paths);
67+
} else if (pattern) {
7168
paths = typeof pattern === "string" ? [pattern] : pattern;
7269
}
7370
const start = performance.now();

0 commit comments

Comments
 (0)