@huangjunsen/encode-fe-lint 1.0.6 → 1.0.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/lib/actions/init.d.ts +3 -3
- package/lib/actions/init.js +151 -223
- package/lib/actions/scan.d.ts +3 -3
- package/lib/actions/scan.js +60 -137
- package/lib/actions/update.d.ts +2 -2
- package/lib/actions/update.js +51 -112
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +145 -230
- package/lib/config/_editorconfig.ejs +13 -13
- package/lib/config/_eslintignore.ejs +9 -9
- package/lib/config/_eslintrc.js.ejs +21 -3
- package/lib/config/_markdownlint.json.ejs +1 -1
- package/lib/config/_markdownlintignore.ejs +5 -5
- package/lib/config/_prettierrc.js.ejs +3 -8
- package/lib/config/_stylelintignore.ejs +5 -5
- package/lib/config/_stylelintrc.js.ejs +5 -5
- package/lib/config/_vscode/extensions.json.ejs +7 -7
- package/lib/config/_vscode/settings.json.ejs +55 -54
- package/lib/config/commitlint.config.js.ejs +3 -3
- package/lib/config/encode-fe-lint.config.js.ejs +6 -6
- package/lib/config/eslint.config.mjs.ejs +5 -0
- package/lib/index.d.ts +5 -5
- package/lib/index.js +36 -93
- package/lib/lints/eslint/doEslint.d.ts +6 -6
- package/lib/lints/eslint/doEslint.js +44 -80
- package/lib/lints/eslint/formatESLintResults.d.ts +3 -3
- package/lib/lints/eslint/formatESLintResults.js +28 -39
- package/lib/lints/eslint/getESLintConfig.d.ts +3 -3
- package/lib/lints/eslint/getESLintConfig.js +43 -67
- package/lib/lints/eslint/getESLintConfigType.d.ts +2 -2
- package/lib/lints/eslint/getESLintConfigType.js +23 -26
- package/lib/lints/eslint/index.d.ts +3 -3
- package/lib/lints/eslint/index.js +19 -19
- package/lib/lints/index.d.ts +4 -4
- package/lib/lints/index.js +20 -20
- package/lib/lints/markdownlint/doMarkdownlint.d.ts +6 -6
- package/lib/lints/markdownlint/doMarkdownlint.js +52 -119
- package/lib/lints/markdownlint/formatMarkdownlintResults.d.ts +3 -3
- package/lib/lints/markdownlint/formatMarkdownlintResults.js +35 -39
- package/lib/lints/markdownlint/getMarkdownlintConfig.d.ts +7 -7
- package/lib/lints/markdownlint/getMarkdownlintConfig.js +31 -31
- package/lib/lints/markdownlint/index.d.ts +3 -3
- package/lib/lints/markdownlint/index.js +19 -19
- package/lib/lints/prettier/doPrettier.d.ts +4 -4
- package/lib/lints/prettier/doPrettier.js +32 -106
- package/lib/lints/prettier/index.d.ts +1 -1
- package/lib/lints/prettier/index.js +17 -17
- package/lib/lints/stylelint/doStylelint.d.ts +5 -5
- package/lib/lints/stylelint/doStylelint.js +31 -86
- package/lib/lints/stylelint/formatStylelintResults.d.ts +3 -3
- package/lib/lints/stylelint/formatStylelintResults.js +38 -39
- package/lib/lints/stylelint/getStylelintConfig.d.ts +3 -3
- package/lib/lints/stylelint/getStylelintConfig.js +36 -36
- package/lib/lints/stylelint/getStylelintDocUrl.d.ts +1 -1
- package/lib/lints/stylelint/getStylelintDocUrl.js +13 -13
- package/lib/lints/stylelint/index.d.ts +3 -3
- package/lib/lints/stylelint/index.js +19 -19
- package/lib/types/index.d.ts +73 -73
- package/lib/types/index.js +2 -2
- package/lib/utils/conflict-resolve.d.ts +3 -3
- package/lib/utils/conflict-resolve.js +95 -175
- package/lib/utils/constants.d.ts +18 -18
- package/lib/utils/constants.js +104 -133
- package/lib/utils/generate-template.d.ts +2 -2
- package/lib/utils/generate-template.js +53 -99
- package/lib/utils/git.d.ts +3 -3
- package/lib/utils/git.js +44 -105
- package/lib/utils/log.d.ts +8 -8
- package/lib/utils/log.js +25 -25
- package/lib/utils/npm-type.d.ts +2 -2
- package/lib/utils/npm-type.js +10 -10
- package/lib/utils/print-report.d.ts +3 -3
- package/lib/utils/print-report.js +86 -109
- package/package.json +13 -8
- package/lib/utils/update.d.ts +0 -2
- package/lib/utils/update.js +0 -112
package/lib/actions/update.js
CHANGED
|
@@ -1,112 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
case 1:
|
|
53
|
-
npm = _a.sent();
|
|
54
|
-
latestVersion = (0, child_process_1.execSync)("".concat(npm, " view ").concat(constants_1.PKG_NAME, " version")).toString('utf-8').trim();
|
|
55
|
-
if (constants_1.PKG_VERSION === latestVersion)
|
|
56
|
-
return [2, null];
|
|
57
|
-
compareArr = constants_1.PKG_VERSION.split('.').map(Number);
|
|
58
|
-
beComparedArr = latestVersion.split('.').map(Number);
|
|
59
|
-
for (i = 0; i < compareArr.length; i++) {
|
|
60
|
-
if (compareArr[i] > beComparedArr[i]) {
|
|
61
|
-
return [2, null];
|
|
62
|
-
}
|
|
63
|
-
else if (compareArr[i] < beComparedArr[i]) {
|
|
64
|
-
return [2, latestVersion];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return [2];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}); };
|
|
71
|
-
exports.default = (function (install) {
|
|
72
|
-
if (install === void 0) { install = true; }
|
|
73
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
74
|
-
var checking, npm, latestVersion, update, e_1;
|
|
75
|
-
return __generator(this, function (_a) {
|
|
76
|
-
switch (_a.label) {
|
|
77
|
-
case 0:
|
|
78
|
-
checking = (0, ora_1.default)("[".concat(constants_1.PKG_NAME, "] \u6B63\u5728\u68C0\u67E5\u6700\u65B0\u7248\u672C..."));
|
|
79
|
-
checking.start();
|
|
80
|
-
_a.label = 1;
|
|
81
|
-
case 1:
|
|
82
|
-
_a.trys.push([1, 4, , 5]);
|
|
83
|
-
return [4, npm_type_1.default];
|
|
84
|
-
case 2:
|
|
85
|
-
npm = _a.sent();
|
|
86
|
-
return [4, checkLatestVersion()];
|
|
87
|
-
case 3:
|
|
88
|
-
latestVersion = _a.sent();
|
|
89
|
-
checking.stop();
|
|
90
|
-
if (latestVersion && install) {
|
|
91
|
-
update = (0, ora_1.default)("[".concat(constants_1.PKG_NAME, "] \u5B58\u5728\u65B0\u7248\u672C\uFF0C\u5C06\u5347\u7EA7\u81F3 ").concat(latestVersion));
|
|
92
|
-
update.start();
|
|
93
|
-
(0, child_process_1.execSync)("".concat(npm, " i -g ").concat(constants_1.PKG_NAME));
|
|
94
|
-
update.stop();
|
|
95
|
-
}
|
|
96
|
-
else if (latestVersion) {
|
|
97
|
-
log_1.default.warn("\u6700\u65B0\u7248\u672C\u4E3A ".concat(latestVersion, "\uFF0C\u672C\u5730\u7248\u672C\u4E3A ").concat(constants_1.PKG_VERSION, "\uFF0C\u8BF7\u5C3D\u5FEB\u5347\u7EA7\u5230\u6700\u65B0\u7248\u672C\u3002\n\u4F60\u53EF\u4EE5\u6267\u884C ").concat(npm, " install -g ").concat(constants_1.PKG_NAME, "@latest \u6765\u5B89\u88C5\u6B64\u7248\u672C\n"));
|
|
98
|
-
}
|
|
99
|
-
else if (install) {
|
|
100
|
-
log_1.default.info("\u5F53\u524D\u6CA1\u6709\u53EF\u7528\u7684\u66F4\u65B0");
|
|
101
|
-
}
|
|
102
|
-
return [3, 5];
|
|
103
|
-
case 4:
|
|
104
|
-
e_1 = _a.sent();
|
|
105
|
-
checking.stop();
|
|
106
|
-
log_1.default.error(e_1);
|
|
107
|
-
return [3, 5];
|
|
108
|
-
case 5: return [2];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
});
|
|
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
|
+
const child_process_1 = require("child_process");
|
|
7
|
+
const ora_1 = __importDefault(require("ora"));
|
|
8
|
+
const log_1 = __importDefault(require("../utils/log"));
|
|
9
|
+
const npm_type_1 = __importDefault(require("../utils/npm-type"));
|
|
10
|
+
const constants_1 = require("../utils/constants");
|
|
11
|
+
const checkLatestVersion = async () => {
|
|
12
|
+
const npm = await npm_type_1.default;
|
|
13
|
+
const latestVersion = (0, child_process_1.execSync)(`${npm} view ${constants_1.PKG_NAME} version`).toString('utf-8').trim();
|
|
14
|
+
if (constants_1.PKG_VERSION === latestVersion)
|
|
15
|
+
return null;
|
|
16
|
+
const compareArr = constants_1.PKG_VERSION.split('.').map(Number);
|
|
17
|
+
const beComparedArr = latestVersion.split('.').map(Number);
|
|
18
|
+
for (let i = 0; i < compareArr.length; i++) {
|
|
19
|
+
if (compareArr[i] > beComparedArr[i]) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
else if (compareArr[i] < beComparedArr[i]) {
|
|
23
|
+
return latestVersion;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.default = async (install = true) => {
|
|
28
|
+
const checking = (0, ora_1.default)(`[${constants_1.PKG_NAME}] 正在检查最新版本...`);
|
|
29
|
+
checking.start();
|
|
30
|
+
try {
|
|
31
|
+
const npm = await npm_type_1.default;
|
|
32
|
+
const latestVersion = await checkLatestVersion();
|
|
33
|
+
checking.stop();
|
|
34
|
+
if (latestVersion && install) {
|
|
35
|
+
const update = (0, ora_1.default)(`[${constants_1.PKG_NAME}] 存在新版本,将升级至 ${latestVersion}`);
|
|
36
|
+
update.start();
|
|
37
|
+
(0, child_process_1.execSync)(`${npm} i -g ${constants_1.PKG_NAME}`);
|
|
38
|
+
update.stop();
|
|
39
|
+
}
|
|
40
|
+
else if (latestVersion) {
|
|
41
|
+
log_1.default.warn(`最新版本为 ${latestVersion},本地版本为 ${constants_1.PKG_VERSION},请尽快升级到最新版本。\n你可以执行 ${npm} install -g ${constants_1.PKG_NAME}@latest 来安装此版本\n`);
|
|
42
|
+
}
|
|
43
|
+
else if (install) {
|
|
44
|
+
log_1.default.info(`当前没有可用的更新`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
checking.stop();
|
|
49
|
+
log_1.default.error(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
package/lib/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
export {};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export {};
|
package/lib/cli.js
CHANGED
|
@@ -1,230 +1,145 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.
|
|
84
|
-
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
.
|
|
107
|
-
.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
commander_1.program
|
|
147
|
-
.command('commit-msg-scan')
|
|
148
|
-
.description('commit message 检查: git commit 时对 commit message 进行检查')
|
|
149
|
-
.action(function () {
|
|
150
|
-
var result = cross_spawn_1.default.sync('commitlint', ['-E', 'HUSKY_GIT_PARAMS'], { stdio: 'inherit' });
|
|
151
|
-
if (result.status !== 0) {
|
|
152
|
-
process.exit(result.status);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
commander_1.program
|
|
156
|
-
.command('commit-file-scan')
|
|
157
|
-
.description('代码提交检查: git commit 时对提交代码进行规范问题扫描')
|
|
158
|
-
.option('-s, --strict', '严格模式,对 warn 和 error 问题都卡口,默认仅对 error 问题卡口')
|
|
159
|
-
.action(function (cmd) { return __awaiter(void 0, void 0, void 0, function () {
|
|
160
|
-
var files, checking, _a, results, errorCount, warningCount, _b;
|
|
161
|
-
var _c;
|
|
162
|
-
return __generator(this, function (_d) {
|
|
163
|
-
switch (_d.label) {
|
|
164
|
-
case 0: return [4, installDepsIfThereNo()];
|
|
165
|
-
case 1:
|
|
166
|
-
_d.sent();
|
|
167
|
-
return [4, (0, git_1.getAmendFiles)()];
|
|
168
|
-
case 2:
|
|
169
|
-
files = _d.sent();
|
|
170
|
-
if (files)
|
|
171
|
-
log_1.default.warn("[".concat(constants_1.PKG_NAME, "] changes not staged for commit: \n").concat(files, "\n"));
|
|
172
|
-
checking = (0, ora_1.default)();
|
|
173
|
-
checking.start("\u6267\u884C ".concat(constants_1.PKG_NAME, " \u4EE3\u7801\u63D0\u4EA4\u68C0\u67E5"));
|
|
174
|
-
_b = scan_1.default;
|
|
175
|
-
_c = {
|
|
176
|
-
cwd: cwd,
|
|
177
|
-
include: cwd,
|
|
178
|
-
quiet: !cmd.strict
|
|
179
|
-
};
|
|
180
|
-
return [4, (0, git_1.getCommitFiles)()];
|
|
181
|
-
case 3: return [4, _b.apply(void 0, [(_c.files = _d.sent(),
|
|
182
|
-
_c)])];
|
|
183
|
-
case 4:
|
|
184
|
-
_a = _d.sent(), results = _a.results, errorCount = _a.errorCount, warningCount = _a.warningCount;
|
|
185
|
-
if (errorCount > 0 || (cmd.strict && warningCount > 0)) {
|
|
186
|
-
checking.fail();
|
|
187
|
-
(0, print_report_1.default)(results, false);
|
|
188
|
-
process.exitCode = 1;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
checking.succeed();
|
|
192
|
-
}
|
|
193
|
-
return [2];
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}); });
|
|
197
|
-
commander_1.program
|
|
198
|
-
.command('fix')
|
|
199
|
-
.description('一键修复:自动修复项目的代码规范扫描问题')
|
|
200
|
-
.option('-i, --include <dirpath>', '指定要进行修复扫描的目录')
|
|
201
|
-
.option('--no-ignore', '忽略 eslint 的 ignore 配置文件和 ignore 规则')
|
|
202
|
-
.action(function (cmd) { return __awaiter(void 0, void 0, void 0, function () {
|
|
203
|
-
var checking, results;
|
|
204
|
-
return __generator(this, function (_a) {
|
|
205
|
-
switch (_a.label) {
|
|
206
|
-
case 0: return [4, installDepsIfThereNo()];
|
|
207
|
-
case 1:
|
|
208
|
-
_a.sent();
|
|
209
|
-
checking = (0, ora_1.default)();
|
|
210
|
-
checking.start("\u6267\u884C ".concat(constants_1.PKG_NAME, " \u4EE3\u7801\u4FEE\u590D"));
|
|
211
|
-
return [4, (0, scan_1.default)({
|
|
212
|
-
cwd: cwd,
|
|
213
|
-
fix: true,
|
|
214
|
-
include: cmd.include || cwd,
|
|
215
|
-
ignore: cmd.ignore,
|
|
216
|
-
})];
|
|
217
|
-
case 2:
|
|
218
|
-
results = (_a.sent()).results;
|
|
219
|
-
checking.succeed();
|
|
220
|
-
if (results.length > 0)
|
|
221
|
-
(0, print_report_1.default)(results, true);
|
|
222
|
-
return [2];
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}); });
|
|
226
|
-
commander_1.program
|
|
227
|
-
.command('update')
|
|
228
|
-
.description("\u66F4\u65B0 ".concat(constants_1.PKG_NAME, " \u81F3\u6700\u65B0\u7248\u672C"))
|
|
229
|
-
.action(function () { return (0, update_1.default)(true); });
|
|
230
|
-
commander_1.program.parse(process.argv);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const ora_1 = __importDefault(require("ora"));
|
|
10
|
+
const glob_1 = __importDefault(require("glob"));
|
|
11
|
+
const commander_1 = require("commander");
|
|
12
|
+
const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
13
|
+
const child_process_1 = require("child_process");
|
|
14
|
+
const init_1 = __importDefault(require("./actions/init"));
|
|
15
|
+
const scan_1 = __importDefault(require("./actions/scan"));
|
|
16
|
+
const update_1 = __importDefault(require("./actions/update"));
|
|
17
|
+
const log_1 = __importDefault(require("./utils/log"));
|
|
18
|
+
const print_report_1 = __importDefault(require("./utils/print-report"));
|
|
19
|
+
const npm_type_1 = __importDefault(require("./utils/npm-type"));
|
|
20
|
+
const git_1 = require("./utils/git");
|
|
21
|
+
const generate_template_1 = __importDefault(require("./utils/generate-template"));
|
|
22
|
+
const constants_1 = require("./utils/constants");
|
|
23
|
+
const cwd = process.cwd();
|
|
24
|
+
const installDepsIfThereNo = async () => {
|
|
25
|
+
const lintConfigFiles = [
|
|
26
|
+
...glob_1.default.sync('.eslintrc?(.@(js|yaml|yml|json))', { cwd }),
|
|
27
|
+
...glob_1.default.sync('.stylelintrc?(.@(js|yaml|yml|json))', { cwd }),
|
|
28
|
+
...glob_1.default.sync('.markdownlint(.@(yaml|yml|json))', { cwd }),
|
|
29
|
+
];
|
|
30
|
+
const nodeModulesPath = path_1.default.resolve(cwd, 'node_modules');
|
|
31
|
+
if (!fs_extra_1.default.existsSync(nodeModulesPath) && lintConfigFiles.length > 0) {
|
|
32
|
+
const npm = await npm_type_1.default;
|
|
33
|
+
log_1.default.info(`使用项目 Lint 配置,检测到项目未安装依赖,将进行安装(执行 ${npm} install)`);
|
|
34
|
+
(0, child_process_1.execSync)(`cd ${cwd} && ${npm} i`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
commander_1.program
|
|
38
|
+
.version(constants_1.PKG_VERSION)
|
|
39
|
+
.description(`${constants_1.PKG_NAME} 是 Lint 工具,提供简单的 CLI 和 Node.js API,让项目能够一键接入、一键扫描、一键修复、一键升级,并为项目配置 git commit 卡点,降低项目实施规范的成本`);
|
|
40
|
+
commander_1.program
|
|
41
|
+
.command('init')
|
|
42
|
+
.description('一键接入:为项目初始化规范工具和配置,可以根据项目类型和需求进行定制')
|
|
43
|
+
.option('--vscode', '写入.vscode/setting.json配置')
|
|
44
|
+
.action(async (cmd) => {
|
|
45
|
+
if (cmd.vscode) {
|
|
46
|
+
const configPath = path_1.default.resolve(cwd, `${constants_1.PKG_NAME}.config.js`);
|
|
47
|
+
(0, generate_template_1.default)(cwd, require(configPath), true);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
await (0, init_1.default)({
|
|
51
|
+
cwd,
|
|
52
|
+
checkVersionUpdate: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
commander_1.program
|
|
57
|
+
.command('scan')
|
|
58
|
+
.description('一键扫描:对项目进行代码规范问题扫描')
|
|
59
|
+
.option('-q, --quiet', '仅报告错误信息 - 默认: false')
|
|
60
|
+
.option('-o, --output-report', '输出扫描出的规范问题日志')
|
|
61
|
+
.option('-i, --include <dirpath>', '指定要进行规范扫描的目录')
|
|
62
|
+
.option('--no-ignore', '忽略 eslint 的 ignore 配置文件和 ignore 规则')
|
|
63
|
+
.action(async (cmd) => {
|
|
64
|
+
await installDepsIfThereNo();
|
|
65
|
+
const checking = (0, ora_1.default)();
|
|
66
|
+
checking.start(`执行 ${constants_1.PKG_NAME} 代码检查`);
|
|
67
|
+
const { results, errorCount, warningCount, runErrors } = await (0, scan_1.default)({
|
|
68
|
+
cwd,
|
|
69
|
+
fix: false,
|
|
70
|
+
include: cmd.include || cwd,
|
|
71
|
+
quiet: Boolean(cmd.quiet),
|
|
72
|
+
outputReport: Boolean(cmd.outputReport),
|
|
73
|
+
ignore: cmd.ignore,
|
|
74
|
+
});
|
|
75
|
+
let type = 'succeed';
|
|
76
|
+
if (runErrors.length > 0 || errorCount > 0) {
|
|
77
|
+
type = 'fail';
|
|
78
|
+
}
|
|
79
|
+
else if (warningCount > 0) {
|
|
80
|
+
type = 'warn';
|
|
81
|
+
}
|
|
82
|
+
checking[type]();
|
|
83
|
+
if (results.length > 0)
|
|
84
|
+
(0, print_report_1.default)(results, false);
|
|
85
|
+
runErrors.forEach((e) => console.log(e));
|
|
86
|
+
});
|
|
87
|
+
commander_1.program
|
|
88
|
+
.command('commit-msg-scan')
|
|
89
|
+
.description('commit message 检查: git commit 时对 commit message 进行检查')
|
|
90
|
+
.action(() => {
|
|
91
|
+
const result = cross_spawn_1.default.sync('commitlint', ['-E', 'HUSKY_GIT_PARAMS'], { stdio: 'inherit' });
|
|
92
|
+
if (result.status !== 0) {
|
|
93
|
+
process.exit(result.status);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
commander_1.program
|
|
97
|
+
.command('commit-file-scan')
|
|
98
|
+
.description('代码提交检查: git commit 时对提交代码进行规范问题扫描')
|
|
99
|
+
.option('-s, --strict', '严格模式,对 warn 和 error 问题都卡口,默认仅对 error 问题卡口')
|
|
100
|
+
.action(async (cmd) => {
|
|
101
|
+
await installDepsIfThereNo();
|
|
102
|
+
const files = await (0, git_1.getAmendFiles)();
|
|
103
|
+
if (files)
|
|
104
|
+
log_1.default.warn(`[${constants_1.PKG_NAME}] changes not staged for commit: \n${files}\n`);
|
|
105
|
+
const checking = (0, ora_1.default)();
|
|
106
|
+
checking.start(`执行 ${constants_1.PKG_NAME} 代码提交检查`);
|
|
107
|
+
const { results, errorCount, warningCount } = await (0, scan_1.default)({
|
|
108
|
+
cwd,
|
|
109
|
+
include: cwd,
|
|
110
|
+
quiet: !cmd.strict,
|
|
111
|
+
files: await (0, git_1.getCommitFiles)(),
|
|
112
|
+
});
|
|
113
|
+
if (errorCount > 0 || (cmd.strict && warningCount > 0)) {
|
|
114
|
+
checking.fail();
|
|
115
|
+
(0, print_report_1.default)(results, false);
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
checking.succeed();
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
commander_1.program
|
|
123
|
+
.command('fix')
|
|
124
|
+
.description('一键修复:自动修复项目的代码规范扫描问题')
|
|
125
|
+
.option('-i, --include <dirpath>', '指定要进行修复扫描的目录')
|
|
126
|
+
.option('--no-ignore', '忽略 eslint 的 ignore 配置文件和 ignore 规则')
|
|
127
|
+
.action(async (cmd) => {
|
|
128
|
+
await installDepsIfThereNo();
|
|
129
|
+
const checking = (0, ora_1.default)();
|
|
130
|
+
checking.start(`执行 ${constants_1.PKG_NAME} 代码修复`);
|
|
131
|
+
const { results } = await (0, scan_1.default)({
|
|
132
|
+
cwd,
|
|
133
|
+
fix: true,
|
|
134
|
+
include: cmd.include || cwd,
|
|
135
|
+
ignore: cmd.ignore,
|
|
136
|
+
});
|
|
137
|
+
checking.succeed();
|
|
138
|
+
if (results.length > 0)
|
|
139
|
+
(0, print_report_1.default)(results, true);
|
|
140
|
+
});
|
|
141
|
+
commander_1.program
|
|
142
|
+
.command('update')
|
|
143
|
+
.description(`更新 ${constants_1.PKG_NAME} 至最新版本`)
|
|
144
|
+
.action(() => (0, update_1.default)(true));
|
|
145
|
+
commander_1.program.parse(process.argv);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
indent_style = space
|
|
5
|
-
indent_size = 2
|
|
6
|
-
end_of_line = lf
|
|
7
|
-
charset = utf-8
|
|
8
|
-
trim_trailing_whitespace = true
|
|
9
|
-
insert_final_newline = true
|
|
10
|
-
quote_type = single
|
|
11
|
-
|
|
12
|
-
[*.md]
|
|
13
|
-
trim_trailing_whitespace = false
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
indent_style = space
|
|
5
|
+
indent_size = 2
|
|
6
|
+
end_of_line = lf
|
|
7
|
+
charset = utf-8
|
|
8
|
+
trim_trailing_whitespace = true
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
quote_type = single
|
|
11
|
+
|
|
12
|
+
[*.md]
|
|
13
|
+
trim_trailing_whitespace = false
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
build/
|
|
2
|
-
coverage/
|
|
3
|
-
dist/
|
|
4
|
-
es/
|
|
5
|
-
lib/
|
|
6
|
-
node_modules/
|
|
7
|
-
**/*.min.js
|
|
8
|
-
**/*-min.js
|
|
9
|
-
**/*.bundle.js
|
|
1
|
+
build/
|
|
2
|
+
coverage/
|
|
3
|
+
dist/
|
|
4
|
+
es/
|
|
5
|
+
lib/
|
|
6
|
+
node_modules/
|
|
7
|
+
**/*.min.js
|
|
8
|
+
**/*-min.js
|
|
9
|
+
**/*.bundle.js
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
<%_ if (eslintType && eslintType.startsWith('custom:')) {
|
|
2
|
+
const customPkg = eslintType.replace('custom:', '');
|
|
3
|
+
_%>
|
|
4
|
+
module.exports = {
|
|
5
|
+
extends: [
|
|
6
|
+
'<%= customPkg %>',
|
|
7
|
+
<%_ if (enablePrettier) { _%>
|
|
8
|
+
'prettier',
|
|
9
|
+
<%_ } _%>
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
<%_ } else if (eslintType) { _%>
|
|
13
|
+
module.exports = {
|
|
14
|
+
extends: [
|
|
15
|
+
'<%= eslintType === 'index' ? '@huangjunsen/eslint-config' : `@huangjunsen/eslint-config/${eslintType}` %>',
|
|
16
|
+
<%_ if (enablePrettier) { _%>
|
|
17
|
+
'prettier',
|
|
18
|
+
<%_ } _%>
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
<%_ } _%>
|