@huangjunsen/encode-fe-lint 1.0.5 → 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/init.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { InitOptions } from '../types';
|
|
2
|
-
declare const _default: (options: InitOptions) => Promise<void>;
|
|
3
|
-
export default _default;
|
|
1
|
+
import type { InitOptions } from '../types';
|
|
2
|
+
declare const _default: (options: InitOptions) => Promise<void>;
|
|
3
|
+
export default _default;
|
package/lib/actions/init.js
CHANGED
|
@@ -1,223 +1,151 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
config.enableStylelint = options.enableStylelint;
|
|
153
|
-
return [3, 8];
|
|
154
|
-
case 6:
|
|
155
|
-
_b = config;
|
|
156
|
-
return [4, chooseEnableStylelint(!/node/.test(config.eslintType))];
|
|
157
|
-
case 7:
|
|
158
|
-
_b.enableStylelint = _e.sent();
|
|
159
|
-
_e.label = 8;
|
|
160
|
-
case 8:
|
|
161
|
-
if (!(typeof options.enableMarkdownlint === 'boolean')) return [3, 9];
|
|
162
|
-
config.enableMarkdownlint = options.enableMarkdownlint;
|
|
163
|
-
return [3, 11];
|
|
164
|
-
case 9:
|
|
165
|
-
_c = config;
|
|
166
|
-
return [4, chooseEnableMarkdownLint()];
|
|
167
|
-
case 10:
|
|
168
|
-
_c.enableMarkdownlint = _e.sent();
|
|
169
|
-
_e.label = 11;
|
|
170
|
-
case 11:
|
|
171
|
-
if (!(typeof options.enablePrettier === 'boolean')) return [3, 12];
|
|
172
|
-
config.enablePrettier = options.enablePrettier;
|
|
173
|
-
return [3, 14];
|
|
174
|
-
case 12:
|
|
175
|
-
_d = config;
|
|
176
|
-
return [4, chooseEnablePrettier()];
|
|
177
|
-
case 13:
|
|
178
|
-
_d.enablePrettier = _e.sent();
|
|
179
|
-
_e.label = 14;
|
|
180
|
-
case 14:
|
|
181
|
-
if (!!isTest) return [3, 17];
|
|
182
|
-
log_1.default.info("Step ".concat(++step, ". \u68C0\u67E5\u5E76\u5904\u7406\u9879\u76EE\u4E2D\u53EF\u80FD\u5B58\u5728\u7684\u4F9D\u8D56\u548C\u914D\u7F6E\u51B2\u7A81"));
|
|
183
|
-
return [4, (0, conflict_resolve_1.default)(cwd, options.rewriteConfig)];
|
|
184
|
-
case 15:
|
|
185
|
-
pkg = _e.sent();
|
|
186
|
-
log_1.default.success("Step ".concat(step, ". \u5DF2\u5B8C\u6210\u9879\u76EE\u4F9D\u8D56\u548C\u914D\u7F6E\u51B2\u7A81\u68C0\u67E5\u5904\u7406 :D"));
|
|
187
|
-
if (!!disableNpmInstall) return [3, 17];
|
|
188
|
-
log_1.default.info("Step ".concat(++step, ". \u5B89\u88C5\u4F9D\u8D56"));
|
|
189
|
-
return [4, npm_type_1.default];
|
|
190
|
-
case 16:
|
|
191
|
-
npm = _e.sent();
|
|
192
|
-
cross_spawn_1.default.sync(npm, ['i', '-D', constants_1.PKG_NAME], { stdio: 'inherit', cwd: cwd });
|
|
193
|
-
log_1.default.success("Step ".concat(step, ". \u5B89\u88C5\u4F9D\u8D56\u6210\u529F :D"));
|
|
194
|
-
_e.label = 17;
|
|
195
|
-
case 17:
|
|
196
|
-
pkg = fs_extra_1.default.readJSONSync(pkgPath);
|
|
197
|
-
if (!pkg.scripts) {
|
|
198
|
-
pkg.scripts = {};
|
|
199
|
-
}
|
|
200
|
-
if (!pkg.scripts["".concat(constants_1.PKG_NAME, "-scan")]) {
|
|
201
|
-
pkg.scripts["".concat(constants_1.PKG_NAME.split("/").pop(), "-scan")] = "".concat(constants_1.PKG_NAME.split("/").pop(), " scan");
|
|
202
|
-
}
|
|
203
|
-
if (!pkg.scripts["".concat(constants_1.PKG_NAME, "-fix")]) {
|
|
204
|
-
pkg.scripts["".concat(constants_1.PKG_NAME.split("/").pop(), "-fix")] = "".concat(constants_1.PKG_NAME.split("/").pop(), " fix");
|
|
205
|
-
}
|
|
206
|
-
log_1.default.info("Step ".concat(++step, ". \u914D\u7F6E git commit \u5361\u70B9"));
|
|
207
|
-
if (!pkg.husky)
|
|
208
|
-
pkg.husky = {};
|
|
209
|
-
if (!pkg.husky.hooks)
|
|
210
|
-
pkg.husky.hooks = {};
|
|
211
|
-
pkg.husky.hooks['pre-commit'] = "".concat(constants_1.PKG_NAME.split("/").pop(), " commit-file-scan");
|
|
212
|
-
pkg.husky.hooks['commit-msg'] = "".concat(constants_1.PKG_NAME.split("/").pop(), " commit-msg-scan");
|
|
213
|
-
fs_extra_1.default.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
214
|
-
log_1.default.success("Step ".concat(step, ". \u914D\u7F6E git commit \u5361\u70B9\u6210\u529F :D"));
|
|
215
|
-
log_1.default.info("Step ".concat(++step, ". \u5199\u5165\u914D\u7F6E\u6587\u4EF6"));
|
|
216
|
-
(0, generate_template_1.default)(cwd, config);
|
|
217
|
-
log_1.default.success("Step ".concat(step, ". \u5199\u5165\u914D\u7F6E\u6587\u4EF6\u6210\u529F :D"));
|
|
218
|
-
logs = ["".concat(constants_1.PKG_NAME, " \u521D\u59CB\u5316\u5B8C\u6210 :D")].join('\r\n');
|
|
219
|
-
log_1.default.success(logs);
|
|
220
|
-
return [2];
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}); });
|
|
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 path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
9
|
+
const cross_spawn_1 = __importDefault(require("cross-spawn"));
|
|
10
|
+
const update_1 = __importDefault(require("./update"));
|
|
11
|
+
const npm_type_1 = __importDefault(require("../utils/npm-type"));
|
|
12
|
+
const log_1 = __importDefault(require("../utils/log"));
|
|
13
|
+
const conflict_resolve_1 = __importDefault(require("../utils/conflict-resolve"));
|
|
14
|
+
const generate_template_1 = __importDefault(require("../utils/generate-template"));
|
|
15
|
+
const constants_1 = require("../utils/constants");
|
|
16
|
+
let step = 0;
|
|
17
|
+
const chooseEslintType = async () => {
|
|
18
|
+
const { type } = await inquirer_1.default.prompt({
|
|
19
|
+
type: 'list',
|
|
20
|
+
name: 'type',
|
|
21
|
+
message: `Step ${++step}. 请选择项目的语言(JS/TS)和框架(React/Vue)类型:`,
|
|
22
|
+
choices: constants_1.PROJECT_TYPES,
|
|
23
|
+
});
|
|
24
|
+
if (type === 'custom') {
|
|
25
|
+
const { customPkg } = await inquirer_1.default.prompt({
|
|
26
|
+
type: 'input',
|
|
27
|
+
name: 'customPkg',
|
|
28
|
+
message: '请输入外部 ESLint 配置包名称(例如 @antfu/eslint-config):',
|
|
29
|
+
default: '@antfu/eslint-config',
|
|
30
|
+
validate: (input) => (input.trim() ? true : '配置包名称不能为空'),
|
|
31
|
+
});
|
|
32
|
+
return `custom:${customPkg.trim()}`;
|
|
33
|
+
}
|
|
34
|
+
return type;
|
|
35
|
+
};
|
|
36
|
+
const chooseEnableStylelint = async (defaultValue) => {
|
|
37
|
+
const { enable } = await inquirer_1.default.prompt({
|
|
38
|
+
type: 'confirm',
|
|
39
|
+
name: 'enable',
|
|
40
|
+
message: `Step ${++step}. 是否需要使用 stylelint(若没有样式文件则不需要):`,
|
|
41
|
+
default: defaultValue,
|
|
42
|
+
});
|
|
43
|
+
return enable;
|
|
44
|
+
};
|
|
45
|
+
const chooseEnableMarkdownLint = async () => {
|
|
46
|
+
const { enable } = await inquirer_1.default.prompt({
|
|
47
|
+
type: 'confirm',
|
|
48
|
+
name: 'enable',
|
|
49
|
+
message: `Step ${++step}. 是否需要使用 markdownlint(若没有 Markdown 文件则不需要):`,
|
|
50
|
+
default: true,
|
|
51
|
+
});
|
|
52
|
+
return enable;
|
|
53
|
+
};
|
|
54
|
+
const chooseEnablePrettier = async () => {
|
|
55
|
+
const { enable } = await inquirer_1.default.prompt({
|
|
56
|
+
type: 'confirm',
|
|
57
|
+
name: 'enable',
|
|
58
|
+
message: `Step ${++step}. 是否需要使用 Prettier 格式化代码:`,
|
|
59
|
+
default: true,
|
|
60
|
+
});
|
|
61
|
+
return enable;
|
|
62
|
+
};
|
|
63
|
+
exports.default = async (options) => {
|
|
64
|
+
const cwd = options.cwd || process.cwd();
|
|
65
|
+
const isTest = process.env.NODE_ENV === 'test';
|
|
66
|
+
const checkVersionUpdate = options.checkVersionUpdate || false;
|
|
67
|
+
const disableNpmInstall = options.disableNpmInstall || false;
|
|
68
|
+
const config = {};
|
|
69
|
+
const pkgPath = path_1.default.resolve(cwd, 'package.json');
|
|
70
|
+
let pkg = fs_extra_1.default.readJSONSync(pkgPath);
|
|
71
|
+
if (!isTest && checkVersionUpdate) {
|
|
72
|
+
await (0, update_1.default)(false);
|
|
73
|
+
}
|
|
74
|
+
if (typeof options.enableESLint === 'boolean') {
|
|
75
|
+
config.enableESLint = options.enableESLint;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
config.enableESLint = true;
|
|
79
|
+
}
|
|
80
|
+
if (options.eslintType && constants_1.PROJECT_TYPES.find((choice) => choice.value === options.eslintType)) {
|
|
81
|
+
config.eslintType = options.eslintType;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
config.eslintType = await chooseEslintType();
|
|
85
|
+
}
|
|
86
|
+
if (typeof options.enableStylelint === 'boolean') {
|
|
87
|
+
config.enableStylelint = options.enableStylelint;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
config.enableStylelint = await chooseEnableStylelint(!/node/.test(config.eslintType));
|
|
91
|
+
}
|
|
92
|
+
if (typeof options.enableMarkdownlint === 'boolean') {
|
|
93
|
+
config.enableMarkdownlint = options.enableMarkdownlint;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
config.enableMarkdownlint = await chooseEnableMarkdownLint();
|
|
97
|
+
}
|
|
98
|
+
if (typeof options.enablePrettier === 'boolean') {
|
|
99
|
+
config.enablePrettier = options.enablePrettier;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
config.enablePrettier = await chooseEnablePrettier();
|
|
103
|
+
}
|
|
104
|
+
if (!isTest) {
|
|
105
|
+
log_1.default.info(`Step ${++step}. 检查并处理项目中可能存在的依赖和配置冲突`);
|
|
106
|
+
pkg = await (0, conflict_resolve_1.default)(cwd, options.rewriteConfig);
|
|
107
|
+
log_1.default.success(`Step ${step}. 已完成项目依赖和配置冲突检查处理 :D`);
|
|
108
|
+
if (!disableNpmInstall) {
|
|
109
|
+
log_1.default.info(`Step ${++step}. 安装依赖`);
|
|
110
|
+
const npm = await npm_type_1.default;
|
|
111
|
+
const depsToInstall = [constants_1.PKG_NAME];
|
|
112
|
+
if (config.eslintType && config.eslintType.startsWith('custom:')) {
|
|
113
|
+
const customPkg = config.eslintType.replace('custom:', '');
|
|
114
|
+
depsToInstall.push(customPkg);
|
|
115
|
+
}
|
|
116
|
+
cross_spawn_1.default.sync(npm, ['i', '-D', ...depsToInstall], { stdio: 'inherit', cwd });
|
|
117
|
+
log_1.default.success(`Step ${step}. 安装依赖成功 :D`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
pkg = fs_extra_1.default.readJSONSync(pkgPath);
|
|
121
|
+
if (!pkg.scripts) {
|
|
122
|
+
pkg.scripts = {};
|
|
123
|
+
}
|
|
124
|
+
if (!pkg.scripts[`${constants_1.PKG_NAME.split("/").pop()}-scan`]) {
|
|
125
|
+
pkg.scripts[`${constants_1.PKG_NAME.split("/").pop()}-scan`] = `${constants_1.PKG_NAME.split("/").pop()} scan`;
|
|
126
|
+
}
|
|
127
|
+
if (!pkg.scripts[`${constants_1.PKG_NAME.split("/").pop()}-fix`]) {
|
|
128
|
+
pkg.scripts[`${constants_1.PKG_NAME.split("/").pop()}-fix`] = `${constants_1.PKG_NAME.split("/").pop()} fix`;
|
|
129
|
+
}
|
|
130
|
+
log_1.default.info(`Step ${++step}. 配置 git commit 卡点`);
|
|
131
|
+
if (!pkg.husky)
|
|
132
|
+
pkg.husky = {};
|
|
133
|
+
if (!pkg.husky.hooks)
|
|
134
|
+
pkg.husky.hooks = {};
|
|
135
|
+
pkg.husky.hooks['pre-commit'] = `${constants_1.PKG_NAME.split("/").pop()} commit-file-scan`;
|
|
136
|
+
pkg.husky.hooks['commit-msg'] = `${constants_1.PKG_NAME.split("/").pop()} commit-msg-scan`;
|
|
137
|
+
if (!pkg.config)
|
|
138
|
+
pkg.config = {};
|
|
139
|
+
if (!pkg.config.commitizen) {
|
|
140
|
+
pkg.config.commitizen = {
|
|
141
|
+
path: 'node_modules/cz-git',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
fs_extra_1.default.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
145
|
+
log_1.default.success(`Step ${step}. 配置 git commit 卡点成功 :D`);
|
|
146
|
+
log_1.default.info(`Step ${++step}. 写入配置文件`);
|
|
147
|
+
(0, generate_template_1.default)(cwd, config);
|
|
148
|
+
log_1.default.success(`Step ${step}. 写入配置文件成功 :D`);
|
|
149
|
+
const logs = [`${constants_1.PKG_NAME} 初始化完成 :D`].join('\r\n');
|
|
150
|
+
log_1.default.success(logs);
|
|
151
|
+
};
|
package/lib/actions/scan.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ScanOptions, ScanReport } from '../types';
|
|
2
|
-
declare const _default: (options: ScanOptions) => Promise<ScanReport>;
|
|
3
|
-
export default _default;
|
|
1
|
+
import type { ScanOptions, ScanReport } from '../types';
|
|
2
|
+
declare const _default: (options: ScanOptions) => Promise<ScanReport>;
|
|
3
|
+
export default _default;
|
package/lib/actions/scan.js
CHANGED
|
@@ -1,137 +1,60 @@
|
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
case 0:
|
|
62
|
-
cwd = options.cwd, fix = options.fix, outputReport = options.outputReport, scanConfig = options.config;
|
|
63
|
-
readConfigFile = function (pth) {
|
|
64
|
-
var localPath = path_1.default.resolve(cwd, pth);
|
|
65
|
-
return fs_extra_1.default.existsSync(localPath) ? require(localPath) : {};
|
|
66
|
-
};
|
|
67
|
-
pkg = readConfigFile('package.json');
|
|
68
|
-
config = scanConfig || readConfigFile("".concat(constants_1.PKG_NAME, ".config.js"));
|
|
69
|
-
runErrors = [];
|
|
70
|
-
results = [];
|
|
71
|
-
if (!(fix && config.enablePrettier !== false)) return [3, 2];
|
|
72
|
-
return [4, (0, lints_1.doPrettier)(options)];
|
|
73
|
-
case 1:
|
|
74
|
-
_a.sent();
|
|
75
|
-
_a.label = 2;
|
|
76
|
-
case 2:
|
|
77
|
-
if (!(config.enableESLint !== false)) return [3, 6];
|
|
78
|
-
_a.label = 3;
|
|
79
|
-
case 3:
|
|
80
|
-
_a.trys.push([3, 5, , 6]);
|
|
81
|
-
return [4, (0, lints_1.doESLint)(__assign(__assign({}, options), { pkg: pkg, config: config }))];
|
|
82
|
-
case 4:
|
|
83
|
-
eslintResults = _a.sent();
|
|
84
|
-
results = results.concat(eslintResults);
|
|
85
|
-
return [3, 6];
|
|
86
|
-
case 5:
|
|
87
|
-
e_1 = _a.sent();
|
|
88
|
-
runErrors.push(e_1);
|
|
89
|
-
return [3, 6];
|
|
90
|
-
case 6:
|
|
91
|
-
if (!(config.enableStylelint !== false)) return [3, 10];
|
|
92
|
-
_a.label = 7;
|
|
93
|
-
case 7:
|
|
94
|
-
_a.trys.push([7, 9, , 10]);
|
|
95
|
-
return [4, (0, lints_1.doStylelint)(__assign(__assign({}, options), { pkg: pkg, config: config }))];
|
|
96
|
-
case 8:
|
|
97
|
-
stylelintResults = _a.sent();
|
|
98
|
-
results = results.concat(stylelintResults);
|
|
99
|
-
return [3, 10];
|
|
100
|
-
case 9:
|
|
101
|
-
e_2 = _a.sent();
|
|
102
|
-
runErrors.push(e_2);
|
|
103
|
-
return [3, 10];
|
|
104
|
-
case 10:
|
|
105
|
-
if (!(config.enableMarkdownlint !== false)) return [3, 14];
|
|
106
|
-
_a.label = 11;
|
|
107
|
-
case 11:
|
|
108
|
-
_a.trys.push([11, 13, , 14]);
|
|
109
|
-
return [4, (0, lints_1.doMarkdownlint)(__assign(__assign({}, options), { pkg: pkg, config: config }))];
|
|
110
|
-
case 12:
|
|
111
|
-
markdownlintResults = _a.sent();
|
|
112
|
-
results = results.concat(markdownlintResults);
|
|
113
|
-
return [3, 14];
|
|
114
|
-
case 13:
|
|
115
|
-
e_3 = _a.sent();
|
|
116
|
-
runErrors.push(e_3);
|
|
117
|
-
return [3, 14];
|
|
118
|
-
case 14:
|
|
119
|
-
if (outputReport) {
|
|
120
|
-
reportPath = path_1.default.resolve(process.cwd(), "./".concat(constants_1.PKG_NAME, "-report.json"));
|
|
121
|
-
fs_extra_1.default.outputFile(reportPath, JSON.stringify(results, null, 2), function () { });
|
|
122
|
-
}
|
|
123
|
-
return [2, {
|
|
124
|
-
results: results,
|
|
125
|
-
errorCount: results.reduce(function (count, _a) {
|
|
126
|
-
var errorCount = _a.errorCount;
|
|
127
|
-
return count + errorCount;
|
|
128
|
-
}, 0),
|
|
129
|
-
warningCount: results.reduce(function (count, _a) {
|
|
130
|
-
var warningCount = _a.warningCount;
|
|
131
|
-
return count + warningCount;
|
|
132
|
-
}, 0),
|
|
133
|
-
runErrors: runErrors,
|
|
134
|
-
}];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}); });
|
|
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 fs_extra_1 = __importDefault(require("fs-extra"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const lints_1 = require("../lints");
|
|
9
|
+
const constants_1 = require("../utils/constants");
|
|
10
|
+
exports.default = async (options) => {
|
|
11
|
+
const { cwd, fix, outputReport, config: scanConfig } = options;
|
|
12
|
+
const readConfigFile = (pth) => {
|
|
13
|
+
const localPath = path_1.default.resolve(cwd, pth);
|
|
14
|
+
return fs_extra_1.default.existsSync(localPath) ? require(localPath) : {};
|
|
15
|
+
};
|
|
16
|
+
const pkg = readConfigFile('package.json');
|
|
17
|
+
const config = scanConfig || readConfigFile(`${constants_1.PKG_NAME}.config.js`);
|
|
18
|
+
const runErrors = [];
|
|
19
|
+
let results = [];
|
|
20
|
+
if (fix && config.enablePrettier !== false) {
|
|
21
|
+
await (0, lints_1.doPrettier)(options);
|
|
22
|
+
}
|
|
23
|
+
if (config.enableESLint !== false) {
|
|
24
|
+
try {
|
|
25
|
+
const eslintResults = await (0, lints_1.doESLint)({ ...options, pkg, config });
|
|
26
|
+
results = results.concat(eslintResults);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
runErrors.push(e);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (config.enableStylelint !== false) {
|
|
33
|
+
try {
|
|
34
|
+
const stylelintResults = await (0, lints_1.doStylelint)({ ...options, pkg, config });
|
|
35
|
+
results = results.concat(stylelintResults);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
runErrors.push(e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (config.enableMarkdownlint !== false) {
|
|
42
|
+
try {
|
|
43
|
+
const markdownlintResults = await (0, lints_1.doMarkdownlint)({ ...options, pkg, config });
|
|
44
|
+
results = results.concat(markdownlintResults);
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
runErrors.push(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (outputReport) {
|
|
51
|
+
const reportPath = path_1.default.resolve(process.cwd(), `./${constants_1.PKG_NAME}-report.json`);
|
|
52
|
+
fs_extra_1.default.outputFile(reportPath, JSON.stringify(results, null, 2), () => { });
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
results,
|
|
56
|
+
errorCount: results.reduce((count, { errorCount }) => count + errorCount, 0),
|
|
57
|
+
warningCount: results.reduce((count, { warningCount }) => count + warningCount, 0),
|
|
58
|
+
runErrors,
|
|
59
|
+
};
|
|
60
|
+
};
|
package/lib/actions/update.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: (install?: boolean) => Promise<void>;
|
|
2
|
-
export default _default;
|
|
1
|
+
declare const _default: (install?: boolean) => Promise<void>;
|
|
2
|
+
export default _default;
|