@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.
Files changed (76) hide show
  1. package/lib/actions/init.d.ts +3 -3
  2. package/lib/actions/init.js +151 -223
  3. package/lib/actions/scan.d.ts +3 -3
  4. package/lib/actions/scan.js +60 -137
  5. package/lib/actions/update.d.ts +2 -2
  6. package/lib/actions/update.js +51 -112
  7. package/lib/cli.d.ts +2 -2
  8. package/lib/cli.js +145 -230
  9. package/lib/config/_editorconfig.ejs +13 -13
  10. package/lib/config/_eslintignore.ejs +9 -9
  11. package/lib/config/_eslintrc.js.ejs +21 -3
  12. package/lib/config/_markdownlint.json.ejs +1 -1
  13. package/lib/config/_markdownlintignore.ejs +5 -5
  14. package/lib/config/_prettierrc.js.ejs +3 -8
  15. package/lib/config/_stylelintignore.ejs +5 -5
  16. package/lib/config/_stylelintrc.js.ejs +5 -5
  17. package/lib/config/_vscode/extensions.json.ejs +7 -7
  18. package/lib/config/_vscode/settings.json.ejs +55 -54
  19. package/lib/config/commitlint.config.js.ejs +3 -3
  20. package/lib/config/encode-fe-lint.config.js.ejs +6 -6
  21. package/lib/config/eslint.config.mjs.ejs +5 -0
  22. package/lib/index.d.ts +5 -5
  23. package/lib/index.js +36 -93
  24. package/lib/lints/eslint/doEslint.d.ts +6 -6
  25. package/lib/lints/eslint/doEslint.js +44 -80
  26. package/lib/lints/eslint/formatESLintResults.d.ts +3 -3
  27. package/lib/lints/eslint/formatESLintResults.js +28 -39
  28. package/lib/lints/eslint/getESLintConfig.d.ts +3 -3
  29. package/lib/lints/eslint/getESLintConfig.js +43 -67
  30. package/lib/lints/eslint/getESLintConfigType.d.ts +2 -2
  31. package/lib/lints/eslint/getESLintConfigType.js +23 -26
  32. package/lib/lints/eslint/index.d.ts +3 -3
  33. package/lib/lints/eslint/index.js +19 -19
  34. package/lib/lints/index.d.ts +4 -4
  35. package/lib/lints/index.js +20 -20
  36. package/lib/lints/markdownlint/doMarkdownlint.d.ts +6 -6
  37. package/lib/lints/markdownlint/doMarkdownlint.js +52 -119
  38. package/lib/lints/markdownlint/formatMarkdownlintResults.d.ts +3 -3
  39. package/lib/lints/markdownlint/formatMarkdownlintResults.js +35 -39
  40. package/lib/lints/markdownlint/getMarkdownlintConfig.d.ts +7 -7
  41. package/lib/lints/markdownlint/getMarkdownlintConfig.js +31 -31
  42. package/lib/lints/markdownlint/index.d.ts +3 -3
  43. package/lib/lints/markdownlint/index.js +19 -19
  44. package/lib/lints/prettier/doPrettier.d.ts +4 -4
  45. package/lib/lints/prettier/doPrettier.js +32 -106
  46. package/lib/lints/prettier/index.d.ts +1 -1
  47. package/lib/lints/prettier/index.js +17 -17
  48. package/lib/lints/stylelint/doStylelint.d.ts +5 -5
  49. package/lib/lints/stylelint/doStylelint.js +31 -86
  50. package/lib/lints/stylelint/formatStylelintResults.d.ts +3 -3
  51. package/lib/lints/stylelint/formatStylelintResults.js +38 -39
  52. package/lib/lints/stylelint/getStylelintConfig.d.ts +3 -3
  53. package/lib/lints/stylelint/getStylelintConfig.js +36 -36
  54. package/lib/lints/stylelint/getStylelintDocUrl.d.ts +1 -1
  55. package/lib/lints/stylelint/getStylelintDocUrl.js +13 -13
  56. package/lib/lints/stylelint/index.d.ts +3 -3
  57. package/lib/lints/stylelint/index.js +19 -19
  58. package/lib/types/index.d.ts +73 -73
  59. package/lib/types/index.js +2 -2
  60. package/lib/utils/conflict-resolve.d.ts +3 -3
  61. package/lib/utils/conflict-resolve.js +95 -175
  62. package/lib/utils/constants.d.ts +18 -18
  63. package/lib/utils/constants.js +104 -133
  64. package/lib/utils/generate-template.d.ts +2 -2
  65. package/lib/utils/generate-template.js +53 -99
  66. package/lib/utils/git.d.ts +3 -3
  67. package/lib/utils/git.js +44 -105
  68. package/lib/utils/log.d.ts +8 -8
  69. package/lib/utils/log.js +25 -25
  70. package/lib/utils/npm-type.d.ts +2 -2
  71. package/lib/utils/npm-type.js +10 -10
  72. package/lib/utils/print-report.d.ts +3 -3
  73. package/lib/utils/print-report.js +86 -109
  74. package/package.json +13 -8
  75. package/lib/utils/update.d.ts +0 -2
  76. package/lib/utils/update.js +0 -112
@@ -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;
@@ -1,223 +1,151 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- var path_1 = __importDefault(require("path"));
43
- var fs_extra_1 = __importDefault(require("fs-extra"));
44
- var inquirer_1 = __importDefault(require("inquirer"));
45
- var cross_spawn_1 = __importDefault(require("cross-spawn"));
46
- var update_1 = __importDefault(require("./update"));
47
- var npm_type_1 = __importDefault(require("../utils/npm-type"));
48
- var log_1 = __importDefault(require("../utils/log"));
49
- var conflict_resolve_1 = __importDefault(require("../utils/conflict-resolve"));
50
- var generate_template_1 = __importDefault(require("../utils/generate-template"));
51
- var constants_1 = require("../utils/constants");
52
- var step = 0;
53
- var chooseEslintType = function () { return __awaiter(void 0, void 0, void 0, function () {
54
- var type;
55
- return __generator(this, function (_a) {
56
- switch (_a.label) {
57
- case 0: return [4, inquirer_1.default.prompt({
58
- type: 'list',
59
- name: 'type',
60
- message: "Step ".concat(++step, ". \u8BF7\u9009\u62E9\u9879\u76EE\u7684\u8BED\u8A00\uFF08JS/TS\uFF09\u548C\u6846\u67B6\uFF08React/Vue\uFF09\u7C7B\u578B\uFF1A"),
61
- choices: constants_1.PROJECT_TYPES,
62
- })];
63
- case 1:
64
- type = (_a.sent()).type;
65
- return [2, type];
66
- }
67
- });
68
- }); };
69
- var chooseEnableStylelint = function (defaultValue) { return __awaiter(void 0, void 0, void 0, function () {
70
- var enable;
71
- return __generator(this, function (_a) {
72
- switch (_a.label) {
73
- case 0: return [4, inquirer_1.default.prompt({
74
- type: 'confirm',
75
- name: 'enable',
76
- message: "Step ".concat(++step, ". \u662F\u5426\u9700\u8981\u4F7F\u7528 stylelint\uFF08\u82E5\u6CA1\u6709\u6837\u5F0F\u6587\u4EF6\u5219\u4E0D\u9700\u8981\uFF09\uFF1A"),
77
- default: defaultValue,
78
- })];
79
- case 1:
80
- enable = (_a.sent()).enable;
81
- return [2, enable];
82
- }
83
- });
84
- }); };
85
- var chooseEnableMarkdownLint = function () { return __awaiter(void 0, void 0, void 0, function () {
86
- var enable;
87
- return __generator(this, function (_a) {
88
- switch (_a.label) {
89
- case 0: return [4, inquirer_1.default.prompt({
90
- type: 'confirm',
91
- name: 'enable',
92
- message: "Step ".concat(++step, ". \u662F\u5426\u9700\u8981\u4F7F\u7528 markdownlint\uFF08\u82E5\u6CA1\u6709 Markdown \u6587\u4EF6\u5219\u4E0D\u9700\u8981\uFF09\uFF1A"),
93
- default: true,
94
- })];
95
- case 1:
96
- enable = (_a.sent()).enable;
97
- return [2, enable];
98
- }
99
- });
100
- }); };
101
- var chooseEnablePrettier = function () { return __awaiter(void 0, void 0, void 0, function () {
102
- var enable;
103
- return __generator(this, function (_a) {
104
- switch (_a.label) {
105
- case 0: return [4, inquirer_1.default.prompt({
106
- type: 'confirm',
107
- name: 'enable',
108
- message: "Step ".concat(++step, ". \u662F\u5426\u9700\u8981\u4F7F\u7528 Prettier \u683C\u5F0F\u5316\u4EE3\u7801\uFF1A"),
109
- default: true,
110
- })];
111
- case 1:
112
- enable = (_a.sent()).enable;
113
- return [2, enable];
114
- }
115
- });
116
- }); };
117
- exports.default = (function (options) { return __awaiter(void 0, void 0, void 0, function () {
118
- var cwd, isTest, checkVersionUpdate, disableNpmInstall, config, pkgPath, pkg, _a, _b, _c, _d, npm, logs;
119
- return __generator(this, function (_e) {
120
- switch (_e.label) {
121
- case 0:
122
- cwd = options.cwd || process.cwd();
123
- isTest = process.env.NODE_ENV === 'test';
124
- checkVersionUpdate = options.checkVersionUpdate || false;
125
- disableNpmInstall = options.disableNpmInstall || false;
126
- config = {};
127
- pkgPath = path_1.default.resolve(cwd, 'package.json');
128
- pkg = fs_extra_1.default.readJSONSync(pkgPath);
129
- if (!(!isTest && checkVersionUpdate)) return [3, 2];
130
- return [4, (0, update_1.default)(false)];
131
- case 1:
132
- _e.sent();
133
- _e.label = 2;
134
- case 2:
135
- if (typeof options.enableESLint === 'boolean') {
136
- config.enableESLint = options.enableESLint;
137
- }
138
- else {
139
- config.enableESLint = true;
140
- }
141
- if (!(options.eslintType && constants_1.PROJECT_TYPES.find(function (choice) { return choice.value === options.eslintType; }))) return [3, 3];
142
- config.eslintType = options.eslintType;
143
- return [3, 5];
144
- case 3:
145
- _a = config;
146
- return [4, chooseEslintType()];
147
- case 4:
148
- _a.eslintType = _e.sent();
149
- _e.label = 5;
150
- case 5:
151
- if (!(typeof options.enableStylelint === 'boolean')) return [3, 6];
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.split("/").pop(), "-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.split("/").pop(), "-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
+ };
@@ -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;
@@ -1,137 +1,60 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __importDefault = (this && this.__importDefault) || function (mod) {
50
- return (mod && mod.__esModule) ? mod : { "default": mod };
51
- };
52
- Object.defineProperty(exports, "__esModule", { value: true });
53
- var fs_extra_1 = __importDefault(require("fs-extra"));
54
- var path_1 = __importDefault(require("path"));
55
- var lints_1 = require("../lints");
56
- var constants_1 = require("../utils/constants");
57
- exports.default = (function (options) { return __awaiter(void 0, void 0, void 0, function () {
58
- var cwd, fix, outputReport, scanConfig, readConfigFile, pkg, config, runErrors, results, eslintResults, e_1, stylelintResults, e_2, markdownlintResults, e_3, reportPath;
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
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
+ };
@@ -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;