zixulu 1.3.5 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ var import_utils = require("./utils");
6
6
  var program = new import_commander.Command();
7
7
  var pkg = (0, import_utils.readPackageJson)("./");
8
8
  program.name("格数科技").version(pkg.version);
9
+ program.command("eslint").description("删除 ESLint 配置文件").action(import_utils.removeESLint);
9
10
  program.command("prettier").description("添加 prettier 配置文件").option("-t, --tailwind", "是否添加 tailwind 插件").action((options) => {
10
11
  const { tailwind: tailwind2 } = options;
11
12
  (0, import_utils.addPrettierConfig)(tailwind2);
@@ -1,3 +1,7 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Stats } from "fs";
4
+ import { ParsedPath } from "path";
1
5
  import { Config } from "prettier";
2
6
  export declare function resolve(...paths: string[]): string;
3
7
  export declare function getPackageJsonPath(path?: string): string;
@@ -11,8 +15,8 @@ export declare function addDependencies(packageJson: Record<string, any>, packag
11
15
  export declare function addDevDependencies(packageJson: Record<string, any>, packageName: string, version?: string): Promise<void>;
12
16
  /** 写回 package.json */
13
17
  export declare function writePackageJson(packageJson: Record<string, any>, path?: string): void;
14
- export declare function getFilesOrFolders(path: string, isFile: boolean, regExp?: string | RegExp): string[];
15
- /** 去除项目中的 eslint */
18
+ export declare function getFiles(path: string, judge: (path: ParsedPath, stats: Stats) => boolean, depth?: number): string[];
19
+ /** 删除 ESLint 配置文件 */
16
20
  export declare function removeESLint(): void;
17
21
  export declare function vite(): void;
18
22
  /** 添加 tailwind.config.js 配置成功 */
@@ -35,7 +35,7 @@ __export(utils_exports, {
35
35
  addPrettierConfig: () => addPrettierConfig,
36
36
  addTailwindConfig: () => addTailwindConfig,
37
37
  addTailwindToCSS: () => addTailwindToCSS,
38
- getFilesOrFolders: () => getFilesOrFolders,
38
+ getFiles: () => getFiles,
39
39
  getPackageJsonPath: () => getPackageJsonPath,
40
40
  getPackageLatestVersion: () => getPackageLatestVersion,
41
41
  prettierConfig: () => prettierConfig,
@@ -128,28 +128,35 @@ function writePackageJson(packageJson, path) {
128
128
  (0, import_process.exit)();
129
129
  }
130
130
  }
131
- function getFilesOrFolders(path, isFile, regExp) {
132
- function satisfy(name) {
133
- if (typeof regExp === "string" && name !== regExp)
134
- return false;
135
- if (regExp instanceof RegExp && !regExp.test(name))
136
- return false;
137
- const stat = (0, import_fs.statSync)((0, import_path.join)(path, name));
138
- return isFile && stat.isFile() || !isFile && stat.isDirectory();
131
+ function getFiles(path, judge, depth) {
132
+ const result = [];
133
+ const files = (0, import_fs.readdirSync)(path);
134
+ for (const file of files) {
135
+ const filePath = resolve(path, file);
136
+ const parsedPath = (0, import_path.parse)(filePath);
137
+ const stat = (0, import_fs.statSync)(filePath);
138
+ if (judge(parsedPath, stat)) {
139
+ result.push(filePath);
140
+ }
141
+ if (stat.isDirectory() && (depth === void 0 || depth > 0)) {
142
+ result.push(...getFiles(filePath, judge, depth === void 0 ? void 0 : depth - 1));
143
+ }
139
144
  }
140
- const dir = (0, import_fs.readdirSync)(path);
141
- return dir.filter((item) => satisfy);
145
+ return result;
142
146
  }
143
147
  function removeESLint() {
144
148
  try {
145
- const dir = (0, import_fs.readdirSync)((0, import_process.cwd)());
146
- } catch (error) {
147
- }
148
- try {
149
- (0, import_fs.unlinkSync)(resolve(".eslintrc.cjs"));
150
- import_consola.default.success("删除 .eslintrc.cjs 文件成功");
149
+ const files = getFiles((0, import_process.cwd)(), (path, stats) => /\.eslintrc\.[cm]?js/.test(path.base) && stats.isFile(), 1);
150
+ files.forEach((file) => {
151
+ try {
152
+ (0, import_fs.unlinkSync)(file);
153
+ } catch (error) {
154
+ import_consola.default.fail(`删除 ${file} 失败`);
155
+ }
156
+ });
157
+ import_consola.default.success("删除 ESLint 配置文件成功");
151
158
  } catch (error) {
152
- import_consola.default.fail("删除 .eslintrc.cjs 文件失败");
159
+ import_consola.default.fail("获取 ESLint 配置文件列表失败");
153
160
  }
154
161
  try {
155
162
  const pkg = readPackageJson();
@@ -281,7 +288,7 @@ function removeComment(path) {
281
288
  addPrettierConfig,
282
289
  addTailwindConfig,
283
290
  addTailwindToCSS,
284
- getFilesOrFolders,
291
+ getFiles,
285
292
  getPackageJsonPath,
286
293
  getPackageLatestVersion,
287
294
  prettierConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zixulu",
3
- "version": "1.3.5",
3
+ "version": "1.4.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "bin": "dist/index.js",