fenge 0.1.6 → 0.1.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # fenge
2
2
 
3
+ ## 0.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - d58f9dd: feat(fenge): add `--config` option to sub-command `lint` and `format`
8
+ - 3fd7084: feat(fenge): support `--default` option to forcibly use built-in default config
9
+
3
10
  ## 0.1.6
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fenge",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "A CLI tool for code quality",
5
5
  "keywords": [
6
6
  "cli",
@@ -49,8 +49,8 @@
49
49
  "ora": "8.1.1",
50
50
  "prettier": "3.3.3",
51
51
  "@fenge/eslint-config": "0.2.1",
52
- "@fenge/prettier-config": "0.1.1",
53
52
  "@fenge/tsconfig": "0.1.0",
53
+ "@fenge/prettier-config": "0.1.1",
54
54
  "@fenge/types": "0.1.0",
55
55
  "prettier-ignore": "0.1.3"
56
56
  },
package/src/bin/cli.js CHANGED
@@ -27,6 +27,10 @@ program
27
27
  )
28
28
  .option("-u, --update", "automatically format code and fix linting problems")
29
29
  .option("-c, --config <path>", "path to configuration file")
30
+ .option(
31
+ "--default",
32
+ "force to use built-in default config, ignore specified config and local config",
33
+ )
30
34
  .option(
31
35
  "-d, --dry-run",
32
36
  "print what command will be executed under the hood instead of executing",
@@ -45,6 +49,11 @@ program
45
49
  .description("lint code")
46
50
  .option("-f, --fix", "automatically fix linting problems")
47
51
  .option("-u, --update", "alias for '--fix' option")
52
+ .option("-c, --config <path>", "path to configuration file")
53
+ .option(
54
+ "--default",
55
+ "force to use built-in default config, ignore specified config and local config",
56
+ )
48
57
  .option(
49
58
  "-d, --dry-run",
50
59
  "print what command will be executed under the hood instead of executing",
@@ -57,6 +66,11 @@ program
57
66
  .description("format code")
58
67
  .option("-w, --write", "automatically format code")
59
68
  .option("-u, --update", "alias for '--write' option")
69
+ .option("-c, --config <path>", "path to configuration file")
70
+ .option(
71
+ "--default",
72
+ "force to use built-in default config, ignore specified config and local config",
73
+ )
60
74
  .option(
61
75
  "-d, --dry-run",
62
76
  "print what command will be executed under the hood instead of executing",
@@ -6,14 +6,18 @@ import { dir, execAsync, getBinPath } from "../utils.js";
6
6
 
7
7
  /**
8
8
  * @param {Array<string>} paths
9
- * @param {{update?: boolean, write?: boolean, dryRun?: boolean, config?: string}} options
9
+ * @param {{update?: boolean, write?: boolean, dryRun?: boolean, config?: string, default?: boolean}} options
10
10
  */
11
11
  export async function format(paths = [], options = {}) {
12
12
  const { update = false, write = false, dryRun = false, config } = options;
13
+ const useDefaultConfig = options["default"] ?? false;
13
14
 
14
15
  if (config) {
15
16
  process.env["FENGE_CONFIG"] = config;
16
17
  }
18
+ if (useDefaultConfig) {
19
+ process.env["FENGE_USE_DEFAULT_CONFIG"] = "true";
20
+ }
17
21
  const ignores = [".gitignore", ".prettierignore", prettierignore]
18
22
  .map((p) => path.resolve(p))
19
23
  .flatMap((p) => ["--ignore-path", p]);
@@ -5,14 +5,18 @@ import { dir, execAsync, getBinPath } from "../utils.js";
5
5
 
6
6
  /**
7
7
  * @param {Array<string>} paths
8
- * @param {{update?: boolean, fix?: boolean, dryRun?: boolean, config?: string}} options
8
+ * @param {{update?: boolean, fix?: boolean, dryRun?: boolean, config?: string, default?: boolean}} options
9
9
  */
10
10
  export async function lint(paths = [], options = {}) {
11
11
  const { update = false, fix = false, dryRun = false, config } = options;
12
+ const useDefaultConfig = options["default"] ?? false;
12
13
 
13
14
  if (config) {
14
15
  process.env["FENGE_CONFIG"] = config;
15
16
  }
17
+ if (useDefaultConfig) {
18
+ process.env["FENGE_USE_DEFAULT_CONFIG"] = "true";
19
+ }
16
20
  process.env["ESLINT_USE_FLAT_CONFIG"] = "true"; // TODO remove it once upgrade to eslint 9
17
21
  return execAsync(
18
22
  [
@@ -2,12 +2,24 @@
2
2
  import process from "node:process";
3
3
  import { resolveConfig } from "../utils.js";
4
4
 
5
- async function getLintConfig() {
5
+ async function getConfig() {
6
+ // 1.
7
+ if (process.env["FENGE_USE_DEFAULT_CONFIG"]) {
8
+ return (await import("../re-export/eslint.config.js")).default;
9
+ }
10
+
11
+ // 2.
6
12
  const lint = (await resolveConfig("fenge", process.env["FENGE_CONFIG"]))
7
13
  ?.config?.lint;
8
- return typeof lint === "function" ? await lint() : lint;
14
+ const lintConfig = typeof lint === "function" ? await lint() : lint;
15
+ if (lintConfig) return lintConfig;
16
+
17
+ // 3.
18
+ const eslintConfig = (await resolveConfig("eslint"))?.config;
19
+ if (eslintConfig) return eslintConfig;
20
+
21
+ // 4.
22
+ return (await import("../re-export/eslint.config.js")).default;
9
23
  }
10
24
 
11
- export default (await getLintConfig()) ??
12
- (await resolveConfig("eslint"))?.config ??
13
- (await import("../re-export/eslint.config.js")).default;
25
+ export default await getConfig();
@@ -2,12 +2,24 @@
2
2
  import process from "node:process";
3
3
  import { resolveConfig } from "../utils.js";
4
4
 
5
- async function getFormatConfig() {
5
+ async function getConfig() {
6
+ // 1.
7
+ if (process.env["FENGE_USE_DEFAULT_CONFIG"]) {
8
+ return (await import("../re-export/prettier.config.js")).default;
9
+ }
10
+
11
+ // 2.
6
12
  const format = (await resolveConfig("fenge", process.env["FENGE_CONFIG"]))
7
13
  ?.config?.format;
8
- return typeof format === "function" ? await format() : format;
14
+ const formatConfig = typeof format === "function" ? await format() : format;
15
+ if (formatConfig) return formatConfig;
16
+
17
+ // 3.
18
+ const prettierConfig = (await resolveConfig("prettier"))?.config;
19
+ if (prettierConfig) return prettierConfig;
20
+
21
+ // 4.
22
+ return (await import("../re-export/prettier.config.js")).default;
9
23
  }
10
24
 
11
- export default (await getFormatConfig()) ??
12
- (await resolveConfig("prettier"))?.config ??
13
- (await import("../re-export/prettier.config.js")).default;
25
+ export default await getConfig();