fenge 0.1.2 → 0.1.3
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 +9 -0
- package/package.json +3 -3
- package/src/bin/cli.js +1 -0
- package/src/command/format.js +8 -4
- package/src/command/lint.js +8 -4
- package/src/config/eslint.config.js +3 -1
- package/src/config/prettier.config.js +3 -1
- package/src/utils.js +6 -4
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fenge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A CLI tool for code quality",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"lint-staged": "15.2.10",
|
|
49
49
|
"ora": "8.1.1",
|
|
50
50
|
"prettier": "3.3.3",
|
|
51
|
-
"@fenge/eslint-config": "0.1.
|
|
52
|
-
"@fenge/prettier-config": "0.1.
|
|
51
|
+
"@fenge/eslint-config": "0.1.3",
|
|
52
|
+
"@fenge/prettier-config": "0.1.1",
|
|
53
53
|
"@fenge/tsconfig": "0.1.0",
|
|
54
54
|
"@fenge/types": "0.1.0",
|
|
55
55
|
"prettier-ignore": "0.1.3"
|
package/src/bin/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ program
|
|
|
26
26
|
"automatically format code only, will not fix linting problems",
|
|
27
27
|
)
|
|
28
28
|
.option("-u, --update", "automatically format code and fix linting problems")
|
|
29
|
+
.option("-c, --config <path>", "path to configuration file")
|
|
29
30
|
.option(
|
|
30
31
|
"-d, --dry-run",
|
|
31
32
|
"print what command will be executed under the hood instead of executing",
|
package/src/command/format.js
CHANGED
|
@@ -6,12 +6,14 @@ 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}} options
|
|
9
|
+
* @param {{update?: boolean, write?: boolean, dryRun?: boolean, config?: string}} options
|
|
10
10
|
*/
|
|
11
11
|
export async function format(paths = [], options = {}) {
|
|
12
|
-
const { update = false, write = false, dryRun = false } = options;
|
|
12
|
+
const { update = false, write = false, dryRun = false, config } = options;
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
if (config) {
|
|
15
|
+
process.env["FENGE_CONFIG"] = config;
|
|
16
|
+
}
|
|
15
17
|
const ignores = [".gitignore", ".prettierignore", prettierignore]
|
|
16
18
|
.map((p) => path.resolve(p))
|
|
17
19
|
.flatMap((p) => ["--ignore-path", p]);
|
|
@@ -27,7 +29,9 @@ export async function format(paths = [], options = {}) {
|
|
|
27
29
|
"--ignore-unknown",
|
|
28
30
|
"--no-error-on-unmatched-pattern", // Not a good option name. It's for skipping formatting symlinks. https://github.com/prettier/prettier/pull/15533
|
|
29
31
|
...(update || write ? ["--write"] : ["--check"]),
|
|
30
|
-
...(paths.length <= 0 ? ["."] : paths).map((p) =>
|
|
32
|
+
...(paths.length <= 0 ? ["."] : paths).map((p) =>
|
|
33
|
+
path.resolve(process.cwd(), p),
|
|
34
|
+
),
|
|
31
35
|
],
|
|
32
36
|
{ topic: "💃 Checking formatting", dryRun },
|
|
33
37
|
);
|
package/src/command/lint.js
CHANGED
|
@@ -5,12 +5,14 @@ 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}} options
|
|
8
|
+
* @param {{update?: boolean, fix?: boolean, dryRun?: boolean, config?: string}} options
|
|
9
9
|
*/
|
|
10
10
|
export async function lint(paths = [], options = {}) {
|
|
11
|
-
const { update = false, fix = false, dryRun = false } = options;
|
|
11
|
+
const { update = false, fix = false, dryRun = false, config } = options;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
if (config) {
|
|
14
|
+
process.env["FENGE_CONFIG"] = config;
|
|
15
|
+
}
|
|
14
16
|
process.env["ESLINT_USE_FLAT_CONFIG"] = "true"; // TODO remove it once upgrade to eslint 9
|
|
15
17
|
return execAsync(
|
|
16
18
|
[
|
|
@@ -19,7 +21,9 @@ export async function lint(paths = [], options = {}) {
|
|
|
19
21
|
"--config",
|
|
20
22
|
path.join(dir(import.meta.url), "..", "config", "eslint.config.js"),
|
|
21
23
|
...(update || fix ? ["--fix"] : []),
|
|
22
|
-
...(paths.length <= 0 ? ["."] : paths).map((p) =>
|
|
24
|
+
...(paths.length <= 0 ? ["."] : paths).map((p) =>
|
|
25
|
+
path.resolve(process.cwd(), p),
|
|
26
|
+
),
|
|
23
27
|
],
|
|
24
28
|
{ topic: "📏 Checking linting", dryRun },
|
|
25
29
|
);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
import process from "node:process";
|
|
2
3
|
import { resolveConfig } from "../utils.js";
|
|
3
4
|
|
|
4
|
-
export default (await resolveConfig("fenge"))
|
|
5
|
+
export default (await resolveConfig("fenge", process.env["FENGE_CONFIG"]))
|
|
6
|
+
?.config?.lint ??
|
|
5
7
|
(await resolveConfig("eslint"))?.config ??
|
|
6
8
|
(await import("../re-export/eslint.config.js")).default;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
import process from "node:process";
|
|
2
3
|
import { resolveConfig } from "../utils.js";
|
|
3
4
|
|
|
4
|
-
export default (await resolveConfig("fenge"))
|
|
5
|
+
export default (await resolveConfig("fenge", process.env["FENGE_CONFIG"]))
|
|
6
|
+
?.config?.format ??
|
|
5
7
|
(await resolveConfig("prettier"))?.config ??
|
|
6
8
|
(await import("../re-export/prettier.config.js")).default;
|
package/src/utils.js
CHANGED
|
@@ -31,11 +31,13 @@ export function dir(importMetaUrl) {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* @param {string} module
|
|
34
|
+
* @param {string} [loadPath]
|
|
34
35
|
*/
|
|
35
|
-
export async function resolveConfig(module) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
export async function resolveConfig(module, loadPath) {
|
|
37
|
+
const searcher = lilconfig(module, { stopDir: process.cwd() });
|
|
38
|
+
return loadPath
|
|
39
|
+
? await searcher.load(loadPath)
|
|
40
|
+
: await searcher.search(process.cwd());
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/**
|