@huangjunsen/encode-fe-lint 1.0.10 → 1.0.12
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/LICENSE +21 -0
- package/lib/actions/init.js +15 -0
- package/lib/actions/scan.js +9 -1
- package/lib/cli.js +0 -0
- package/lib/config/encode-fe-lint.config.js.ejs +1 -0
- package/lib/config/eslint.config.mjs.ejs +41 -2
- package/lib/lints/eslint/doEslint.d.ts +6 -0
- package/lib/lints/eslint/doEslint.js +27 -14
- package/lib/lints/eslint/getESLintConfig.js +1 -0
- package/lib/lints/markdownlint/doMarkdownlint.js +2 -10
- package/lib/lints/prettier/doPrettier.d.ts +1 -1
- package/lib/lints/prettier/doPrettier.js +18 -12
- package/lib/lints/stylelint/doStylelint.js +2 -6
- package/lib/types/index.d.ts +1 -0
- package/lib/utils/conflict-resolve.js +1 -2
- package/lib/utils/constants.js +14 -14
- package/lib/utils/glob.d.ts +3 -0
- package/lib/utils/glob.js +31 -0
- package/package.json +18 -17
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 黄俊森
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/actions/init.js
CHANGED
|
@@ -60,6 +60,15 @@ const chooseEnablePrettier = async () => {
|
|
|
60
60
|
});
|
|
61
61
|
return enable;
|
|
62
62
|
};
|
|
63
|
+
const chooseEnableFlatConfig = async (defaultValue) => {
|
|
64
|
+
const { enable } = await inquirer_1.default.prompt({
|
|
65
|
+
type: 'confirm',
|
|
66
|
+
name: 'enable',
|
|
67
|
+
message: `Step ${++step}. 是否使用 ESLint Flat Config(eslint.config.mjs,推荐,ESLint 9+ 默认):`,
|
|
68
|
+
default: defaultValue,
|
|
69
|
+
});
|
|
70
|
+
return enable;
|
|
71
|
+
};
|
|
63
72
|
exports.default = async (options) => {
|
|
64
73
|
const cwd = options.cwd || process.cwd();
|
|
65
74
|
const isTest = process.env.NODE_ENV === 'test';
|
|
@@ -101,6 +110,12 @@ exports.default = async (options) => {
|
|
|
101
110
|
else {
|
|
102
111
|
config.enablePrettier = await chooseEnablePrettier();
|
|
103
112
|
}
|
|
113
|
+
if (typeof options.enableFlatConfig === 'boolean') {
|
|
114
|
+
config.enableFlatConfig = options.enableFlatConfig;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
config.enableFlatConfig = await chooseEnableFlatConfig(true);
|
|
118
|
+
}
|
|
104
119
|
if (!isTest) {
|
|
105
120
|
log_1.default.info(`Step ${++step}. 检查并处理项目中可能存在的依赖和配置冲突`);
|
|
106
121
|
pkg = await (0, conflict_resolve_1.default)(cwd, options.rewriteConfig);
|
package/lib/actions/scan.js
CHANGED
|
@@ -21,7 +21,15 @@ exports.default = async (options) => {
|
|
|
21
21
|
const runErrors = [];
|
|
22
22
|
let results = [];
|
|
23
23
|
if (fix && config.enablePrettier !== false) {
|
|
24
|
-
|
|
24
|
+
try {
|
|
25
|
+
const prettierErrors = await (0, lints_1.doPrettier)(options);
|
|
26
|
+
if (prettierErrors.length > 0) {
|
|
27
|
+
runErrors.push(...prettierErrors);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
runErrors.push(e);
|
|
32
|
+
}
|
|
25
33
|
}
|
|
26
34
|
if (config.enableESLint !== false) {
|
|
27
35
|
try {
|
package/lib/cli.js
CHANGED
|
File without changes
|
|
@@ -1,5 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
<%_
|
|
2
|
+
const isCustom = eslintType && eslintType.startsWith('custom:');
|
|
3
|
+
const customPkg = isCustom ? eslintType.replace('custom:', '') : '';
|
|
4
|
+
const useTs = !isCustom && /typescript/.test(eslintType);
|
|
5
|
+
|
|
6
|
+
let mainEntry = '/flat';
|
|
7
|
+
let mainName = 'baseConfig';
|
|
8
|
+
if (!isCustom) {
|
|
9
|
+
if (/vue/.test(eslintType)) {
|
|
10
|
+
mainEntry = '/flat/vue';
|
|
11
|
+
mainName = 'vueConfig';
|
|
12
|
+
} else if (/react/.test(eslintType)) {
|
|
13
|
+
mainEntry = '/flat/react';
|
|
14
|
+
mainName = 'reactConfig';
|
|
15
|
+
} else if (/node/.test(eslintType)) {
|
|
16
|
+
mainEntry = '/flat/node';
|
|
17
|
+
mainName = 'nodeConfig';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
_%>
|
|
21
|
+
<%_ if (isCustom) { _%>
|
|
22
|
+
// eslint.config.mjs
|
|
23
|
+
// 当前使用自定义/社区预设(<%= customPkg %>),请在此处自行组合 Flat Config:
|
|
24
|
+
// import customConfig from '<%= customPkg %>';
|
|
25
|
+
import baseConfig from '@huangjunsen/eslint-config/flat';
|
|
26
|
+
|
|
27
|
+
export default [
|
|
28
|
+
...baseConfig,
|
|
29
|
+
];
|
|
30
|
+
<%_ } else { _%>
|
|
31
|
+
// eslint.config.mjs
|
|
32
|
+
import <%= mainName %> from '@huangjunsen/eslint-config<%= mainEntry %>';
|
|
33
|
+
<%_ if (useTs) { _%>
|
|
34
|
+
import tsConfig from '@huangjunsen/eslint-config/flat/typescript';
|
|
35
|
+
<%_ } _%>
|
|
2
36
|
|
|
3
37
|
export default [
|
|
4
|
-
|
|
38
|
+
...<%= mainName %>,
|
|
39
|
+
<%_ if (useTs) { _%>
|
|
40
|
+
// 放在最后,保证 TypeScript 的规则能覆盖前置预设
|
|
41
|
+
...tsConfig,
|
|
42
|
+
<%_ } _%>
|
|
5
43
|
];
|
|
44
|
+
<%_ } _%>
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { ESLint } from 'eslint';
|
|
1
2
|
import { Config, PKG, ScanOptions } from '../../types';
|
|
2
3
|
export interface DoESLintOptions extends ScanOptions {
|
|
3
4
|
pkg: PKG;
|
|
4
5
|
config?: Config;
|
|
5
6
|
}
|
|
7
|
+
type ESLintConstructor = (new (options?: any) => ESLint) & {
|
|
8
|
+
outputFixes: (results: ESLint.LintResult[]) => Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
export declare function getESLintClass(useFlatConfig: boolean): ESLintConstructor;
|
|
6
11
|
export declare function doESLint(options: DoESLintOptions): Promise<import("../../types").ScanResult[]>;
|
|
12
|
+
export {};
|
|
@@ -3,41 +3,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.doESLint = void 0;
|
|
6
|
+
exports.doESLint = exports.getESLintClass = void 0;
|
|
7
7
|
const eslint_1 = require("eslint");
|
|
8
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
9
|
const path_1 = require("path");
|
|
11
10
|
const constants_1 = require("../../utils/constants");
|
|
11
|
+
const glob_1 = require("../../utils/glob");
|
|
12
12
|
const formatESLintResults_1 = require("./formatESLintResults");
|
|
13
13
|
const getESLintConfig_1 = require("./getESLintConfig");
|
|
14
|
+
const FLAT_CONFIG_FILES = [
|
|
15
|
+
'eslint.config.js',
|
|
16
|
+
'eslint.config.mjs',
|
|
17
|
+
'eslint.config.cjs',
|
|
18
|
+
'eslint.config.ts',
|
|
19
|
+
];
|
|
20
|
+
function getESLintClass(useFlatConfig) {
|
|
21
|
+
if (useFlatConfig) {
|
|
22
|
+
try {
|
|
23
|
+
const risky = require('eslint/use-at-your-own-risk');
|
|
24
|
+
if (risky && typeof risky.FlatESLint === 'function') {
|
|
25
|
+
return risky.FlatESLint;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return eslint_1.ESLint;
|
|
32
|
+
}
|
|
33
|
+
exports.getESLintClass = getESLintClass;
|
|
14
34
|
async function doESLint(options) {
|
|
15
35
|
let files;
|
|
16
36
|
if (options.files) {
|
|
17
37
|
files = options.files.filter((name) => constants_1.ESLINT_FILE_EXT.includes((0, path_1.extname)(name)));
|
|
18
38
|
}
|
|
19
39
|
else {
|
|
20
|
-
files = await (0,
|
|
21
|
-
cwd: options.cwd,
|
|
22
|
-
ignore: constants_1.ESLINT_IGNORE_PATTERN,
|
|
23
|
-
});
|
|
40
|
+
files = await (0, glob_1.globFiles)(options.cwd, options.include, constants_1.ESLINT_FILE_EXT, constants_1.ESLINT_IGNORE_PATTERN);
|
|
24
41
|
}
|
|
25
|
-
const hasFlatConfig =
|
|
26
|
-
|
|
27
|
-
'eslint.config.mjs',
|
|
28
|
-
'eslint.config.cjs',
|
|
29
|
-
'eslint.config.ts',
|
|
30
|
-
].some((file) => fs_extra_1.default.existsSync((0, path_1.join)(options.cwd, file)));
|
|
42
|
+
const hasFlatConfig = FLAT_CONFIG_FILES.some((file) => fs_extra_1.default.existsSync((0, path_1.join)(options.cwd, file)));
|
|
43
|
+
const ESLintClass = getESLintClass(hasFlatConfig);
|
|
31
44
|
const eslintConfig = hasFlatConfig
|
|
32
45
|
? {
|
|
33
46
|
fix: options.fix,
|
|
34
47
|
cwd: options.cwd,
|
|
35
48
|
}
|
|
36
49
|
: (0, getESLintConfig_1.getESLintConfig)(options, options.pkg, options.config);
|
|
37
|
-
const eslint = new
|
|
50
|
+
const eslint = new ESLintClass(eslintConfig);
|
|
38
51
|
const reports = await eslint.lintFiles(files);
|
|
39
52
|
if (options.fix) {
|
|
40
|
-
await
|
|
53
|
+
await ESLintClass.outputFixes(reports);
|
|
41
54
|
}
|
|
42
55
|
return (0, formatESLintResults_1.formatESLintResults)(reports, options.quiet, eslint);
|
|
43
56
|
}
|
|
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.doMarkdownlint = void 0;
|
|
7
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
7
|
const fs_extra_1 = require("fs-extra");
|
|
9
8
|
const markdownlint_1 = __importDefault(require("markdownlint"));
|
|
10
9
|
const markdownlint_rule_helpers_1 = __importDefault(require("markdownlint-rule-helpers"));
|
|
11
10
|
const path_1 = require("path");
|
|
12
11
|
const constants_1 = require("../../utils/constants");
|
|
12
|
+
const glob_1 = require("../../utils/glob");
|
|
13
13
|
const formatMarkdownlintResults_1 = require("./formatMarkdownlintResults");
|
|
14
14
|
const getMarkdownlintConfig_1 = require("./getMarkdownlintConfig");
|
|
15
15
|
async function doMarkdownlint(options) {
|
|
@@ -18,11 +18,7 @@ async function doMarkdownlint(options) {
|
|
|
18
18
|
files = options.files.filter((name) => constants_1.MARKDOWN_LINT_FILE_EXT.includes((0, path_1.extname)(name)));
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
|
|
22
|
-
files = await (0, fast_glob_1.default)(pattern, {
|
|
23
|
-
cwd: options.cwd,
|
|
24
|
-
ignore: constants_1.MARKDOWN_LINT_IGNORE_PATTERN,
|
|
25
|
-
});
|
|
21
|
+
files = await (0, glob_1.globFiles)(options.cwd, options.include, constants_1.MARKDOWN_LINT_FILE_EXT, constants_1.MARKDOWN_LINT_IGNORE_PATTERN);
|
|
26
22
|
}
|
|
27
23
|
const results = await markdownlint_1.default.promises.markdownlint({
|
|
28
24
|
...(0, getMarkdownlintConfig_1.getMarkdownlintConfig)(options, options.pkg, options.config),
|
|
@@ -30,10 +26,6 @@ async function doMarkdownlint(options) {
|
|
|
30
26
|
});
|
|
31
27
|
if (options.fix) {
|
|
32
28
|
await Promise.all(Object.keys(results).map((filename) => formatMarkdownFile(filename, results[filename])));
|
|
33
|
-
for (const file in results) {
|
|
34
|
-
if (!Object.prototype.hasOwnProperty.call(results, file))
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
29
|
}
|
|
38
30
|
return (0, formatMarkdownlintResults_1.formatMarkdownlintResults)(results, options.quiet);
|
|
39
31
|
}
|
|
@@ -4,29 +4,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.doPrettier = void 0;
|
|
7
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
7
|
const fs_extra_1 = require("fs-extra");
|
|
9
8
|
const path_1 = require("path");
|
|
10
9
|
const prettier_1 = __importDefault(require("prettier"));
|
|
11
10
|
const constants_1 = require("../../utils/constants");
|
|
11
|
+
const glob_1 = require("../../utils/glob");
|
|
12
12
|
async function doPrettier(options) {
|
|
13
13
|
let files = [];
|
|
14
14
|
if (options.files) {
|
|
15
15
|
files = options.files.filter((name) => constants_1.PRETTIER_FILE_EXT.includes((0, path_1.extname)(name)));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
|
|
19
|
-
files = await (0, fast_glob_1.default)(pattern, {
|
|
20
|
-
cwd: options.cwd,
|
|
21
|
-
ignore: constants_1.PRETTIER_IGNORE_PATTERN,
|
|
22
|
-
});
|
|
18
|
+
files = await (0, glob_1.globFiles)(options.cwd, options.include, constants_1.PRETTIER_FILE_EXT, constants_1.PRETTIER_IGNORE_PATTERN);
|
|
23
19
|
}
|
|
24
|
-
|
|
20
|
+
const errors = [];
|
|
21
|
+
await Promise.all(files.map((filepath) => formatFile(options.cwd, filepath, errors)));
|
|
22
|
+
return errors;
|
|
25
23
|
}
|
|
26
24
|
exports.doPrettier = doPrettier;
|
|
27
|
-
async function formatFile(filepath) {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
async function formatFile(cwd, filepath, errors) {
|
|
26
|
+
const absolutePath = (0, path_1.isAbsolute)(filepath) ? filepath : (0, path_1.resolve)(cwd, filepath);
|
|
27
|
+
try {
|
|
28
|
+
const text = await (0, fs_extra_1.readFile)(absolutePath, 'utf8');
|
|
29
|
+
const config = (await prettier_1.default.resolveConfig(absolutePath)) || {};
|
|
30
|
+
const formatted = await prettier_1.default.format(text, { ...config, filepath: absolutePath });
|
|
31
|
+
if (formatted !== text) {
|
|
32
|
+
await (0, fs_extra_1.writeFile)(absolutePath, formatted, 'utf8');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
errors.push(e);
|
|
37
|
+
}
|
|
32
38
|
}
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.doStylelint = void 0;
|
|
7
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
7
|
const path_1 = require("path");
|
|
9
8
|
const stylelint_1 = __importDefault(require("stylelint"));
|
|
10
9
|
const constants_1 = require("../../utils/constants");
|
|
10
|
+
const glob_1 = require("../../utils/glob");
|
|
11
11
|
const formatStylelintResults_1 = require("./formatStylelintResults");
|
|
12
12
|
const getStylelintConfig_1 = require("./getStylelintConfig");
|
|
13
13
|
async function doStylelint(options) {
|
|
@@ -16,11 +16,7 @@ async function doStylelint(options) {
|
|
|
16
16
|
files = options.files.filter((name) => constants_1.STYLELINT_FILE_EXT.includes((0, path_1.extname)(name)));
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
|
-
|
|
20
|
-
files = await (0, fast_glob_1.default)(pattern, {
|
|
21
|
-
cwd: options.cwd,
|
|
22
|
-
ignore: constants_1.STYLELINT_IGNORE_PATTERN,
|
|
23
|
-
});
|
|
19
|
+
files = await (0, glob_1.globFiles)(options.cwd, options.include, constants_1.STYLELINT_FILE_EXT, constants_1.STYLELINT_IGNORE_PATTERN);
|
|
24
20
|
}
|
|
25
21
|
const data = await stylelint_1.default.lint({
|
|
26
22
|
...(0, getStylelintConfig_1.getStylelintConfig)(options, options.pkg, options.config),
|
package/lib/types/index.d.ts
CHANGED
|
@@ -31,8 +31,7 @@ const packagePrefixesToRemove = [
|
|
|
31
31
|
];
|
|
32
32
|
const checkUselessConfig = (cwd) => {
|
|
33
33
|
return []
|
|
34
|
-
.concat(glob_1.default.sync('.eslintrc?(.@(yaml|yml|json))', { cwd }))
|
|
35
|
-
.concat(glob_1.default.sync('.stylelintrc?(.@(yaml|yml|json))', { cwd }))
|
|
34
|
+
.concat(glob_1.default.sync('.eslintrc?(.@(yaml|yml|json))', { cwd })).concat(glob_1.default.sync('eslint.config?(.@(js|mjs|cjs|ts))', { cwd })).concat(glob_1.default.sync('.stylelintrc?(.@(yaml|yml|json))', { cwd }))
|
|
36
35
|
.concat(glob_1.default.sync('.markdownlint@(rc|.@(yaml|yml|jsonc))', { cwd }))
|
|
37
36
|
.concat(glob_1.default.sync('.prettierrc?(.@(cjs|config.js|config.cjs|yaml|yml|json|json5|toml))', { cwd }))
|
|
38
37
|
.concat(glob_1.default.sync('tslint.@(yaml|yml|json)', { cwd }))
|
package/lib/utils/constants.js
CHANGED
|
@@ -58,7 +58,7 @@ exports.PROJECT_TYPES = [
|
|
|
58
58
|
];
|
|
59
59
|
exports.ESLINT_FILE_EXT = ['.js', '.jsx', '.ts', '.tsx', '.vue'];
|
|
60
60
|
exports.ESLINT_IGNORE_PATTERN = [
|
|
61
|
-
'node_modules',
|
|
61
|
+
'**/node_modules/**',
|
|
62
62
|
'build',
|
|
63
63
|
'dist',
|
|
64
64
|
'coverage',
|
|
@@ -70,24 +70,24 @@ exports.ESLINT_IGNORE_PATTERN = [
|
|
|
70
70
|
];
|
|
71
71
|
exports.STYLELINT_FILE_EXT = ['.css', '.scss', '.less', '.acss'];
|
|
72
72
|
exports.STYLELINT_IGNORE_PATTERN = [
|
|
73
|
-
'node_modules
|
|
74
|
-
'build
|
|
75
|
-
'dist
|
|
76
|
-
'coverage
|
|
77
|
-
'es
|
|
78
|
-
'lib
|
|
73
|
+
'**/node_modules/**',
|
|
74
|
+
'build/**',
|
|
75
|
+
'dist/**',
|
|
76
|
+
'coverage/**',
|
|
77
|
+
'es/**',
|
|
78
|
+
'lib/**',
|
|
79
79
|
'**/*.min.css',
|
|
80
80
|
'**/*-min.css',
|
|
81
81
|
'**/*.bundle.css',
|
|
82
82
|
];
|
|
83
83
|
exports.MARKDOWN_LINT_FILE_EXT = ['.md'];
|
|
84
84
|
exports.MARKDOWN_LINT_IGNORE_PATTERN = [
|
|
85
|
-
'node_modules
|
|
86
|
-
'build
|
|
87
|
-
'dist
|
|
88
|
-
'coverage
|
|
89
|
-
'es
|
|
90
|
-
'lib
|
|
85
|
+
'**/node_modules/**',
|
|
86
|
+
'build/**',
|
|
87
|
+
'dist/**',
|
|
88
|
+
'coverage/**',
|
|
89
|
+
'es/**',
|
|
90
|
+
'lib/**',
|
|
91
91
|
];
|
|
92
92
|
exports.PRETTIER_FILE_EXT = [
|
|
93
93
|
...exports.STYLELINT_FILE_EXT,
|
|
@@ -95,7 +95,7 @@ exports.PRETTIER_FILE_EXT = [
|
|
|
95
95
|
...exports.MARKDOWN_LINT_FILE_EXT,
|
|
96
96
|
];
|
|
97
97
|
exports.PRETTIER_IGNORE_PATTERN = [
|
|
98
|
-
'node_modules
|
|
98
|
+
'**/node_modules/**',
|
|
99
99
|
'build/**/*',
|
|
100
100
|
'dist/**/*',
|
|
101
101
|
'lib/**/*',
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function normalizeInclude(cwd: string, include?: string): string;
|
|
2
|
+
export declare function getFilePattern(cwd: string, include: string | undefined, ext: string[]): string;
|
|
3
|
+
export declare function globFiles(cwd: string, include: string | undefined, ext: string[], ignore: string[]): Promise<string[]>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.globFiles = exports.getFilePattern = exports.normalizeInclude = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
|
+
function normalizeInclude(cwd, include) {
|
|
10
|
+
const target = include && include.trim() ? include : cwd;
|
|
11
|
+
if (!path_1.default.isAbsolute(target))
|
|
12
|
+
return target;
|
|
13
|
+
const relative = path_1.default.relative(cwd, target);
|
|
14
|
+
return relative || '.';
|
|
15
|
+
}
|
|
16
|
+
exports.normalizeInclude = normalizeInclude;
|
|
17
|
+
function getFilePattern(cwd, include, ext) {
|
|
18
|
+
const prefix = normalizeInclude(cwd, include);
|
|
19
|
+
const extensions = ext.map((item) => item.replace(/^\./, '')).join(',');
|
|
20
|
+
return path_1.default.join(prefix, `**/*.{${extensions}}`);
|
|
21
|
+
}
|
|
22
|
+
exports.getFilePattern = getFilePattern;
|
|
23
|
+
async function globFiles(cwd, include, ext, ignore) {
|
|
24
|
+
return (0, fast_glob_1.default)(getFilePattern(cwd, include, ext), {
|
|
25
|
+
cwd,
|
|
26
|
+
ignore,
|
|
27
|
+
dot: false,
|
|
28
|
+
onlyFiles: true,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.globFiles = globFiles;
|
package/package.json
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huangjunsen/encode-fe-lint",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "前端编码规范工程化标准脚手架",
|
|
5
|
-
"bin": "./lib/cli.js",
|
|
6
5
|
"main": "./lib/index.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"dev": "npm run copyfiles && tsc -w",
|
|
9
|
-
"build": "rm -rf lib && npm run copyfiles && tsc",
|
|
10
|
-
"copyfiles": "copyfiles -a -u 1 \"src/config/**\" lib",
|
|
11
|
-
"test": "npm run build && jest",
|
|
12
|
-
"coverage": "nyc jest --silent --forceExit",
|
|
13
|
-
"prepublishOnly": "npm run test"
|
|
14
|
-
},
|
|
15
6
|
"files": [
|
|
16
7
|
"lib/",
|
|
17
8
|
"README.md"
|
|
@@ -47,11 +38,6 @@
|
|
|
47
38
|
"@babel/eslint-parser": "^7.24.1",
|
|
48
39
|
"@babel/preset-react": "^7.24.1",
|
|
49
40
|
"@commitlint/cli": "^16.3.0",
|
|
50
|
-
"@huangjunsen/commitlint-config": "^1.0.1",
|
|
51
|
-
"@huangjunsen/eslint-config": "^1.0.1",
|
|
52
|
-
"@huangjunsen/markdownlint-config": "^1.0.0",
|
|
53
|
-
"@huangjunsen/prettier-config": "^1.0.1",
|
|
54
|
-
"@huangjunsen/stylelint-config": "^1.0.1",
|
|
55
41
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
56
42
|
"@typescript-eslint/parser": "^5.62.0",
|
|
57
43
|
"chalk": "^4.1.2",
|
|
@@ -86,7 +72,12 @@
|
|
|
86
72
|
"stylelint-scss": "^4.7.0",
|
|
87
73
|
"terminal-link": "^2.1.1",
|
|
88
74
|
"text-table": "^0.2.0",
|
|
89
|
-
"vue-eslint-parser": "^7.11.0"
|
|
75
|
+
"vue-eslint-parser": "^7.11.0",
|
|
76
|
+
"@huangjunsen/eslint-config": "^1.0.3",
|
|
77
|
+
"@huangjunsen/markdownlint-config": "^1.0.0",
|
|
78
|
+
"@huangjunsen/prettier-config": "^1.0.1",
|
|
79
|
+
"@huangjunsen/commitlint-config": "^1.0.1",
|
|
80
|
+
"@huangjunsen/stylelint-config": "^1.0.1"
|
|
90
81
|
},
|
|
91
82
|
"author": "Huangjunsen <951434130@qq.com>",
|
|
92
83
|
"homepage": "https://github.com/Huang-junsen/js-encode-fe-spec#readme",
|
|
@@ -97,5 +88,15 @@
|
|
|
97
88
|
},
|
|
98
89
|
"bugs": {
|
|
99
90
|
"url": "https://github.com/Huang-junsen/js-encode-fe-spec/issues"
|
|
91
|
+
},
|
|
92
|
+
"scripts": {
|
|
93
|
+
"dev": "npm run copyfiles && tsc -w",
|
|
94
|
+
"build": "rm -rf lib && npm run copyfiles && tsc",
|
|
95
|
+
"copyfiles": "copyfiles -a -u 1 \"src/config/**\" lib",
|
|
96
|
+
"test": "npm run build && jest",
|
|
97
|
+
"coverage": "nyc jest --silent --forceExit"
|
|
98
|
+
},
|
|
99
|
+
"bin": {
|
|
100
|
+
"encode-fe-lint": "./lib/cli.js"
|
|
100
101
|
}
|
|
101
|
-
}
|
|
102
|
+
}
|