@qiangzaifan/encode-fe-lint 0.0.0-stage → 1.0.0

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 (79) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +190 -2
  3. package/lib/actions/init.d.ts +3 -0
  4. package/lib/actions/init.js +250 -0
  5. package/lib/actions/scan.d.ts +3 -0
  6. package/lib/actions/scan.js +146 -0
  7. package/lib/actions/update.d.ts +2 -0
  8. package/lib/actions/update.js +112 -0
  9. package/lib/cli.d.ts +2 -0
  10. package/lib/cli.js +276 -0
  11. package/lib/config/_editorconfig.ejs +13 -0
  12. package/lib/config/_eslintignore.ejs +9 -0
  13. package/lib/config/_eslintrc.js.ejs +3 -0
  14. package/lib/config/_markdownlint.json.ejs +1 -0
  15. package/lib/config/_markdownlintignore.ejs +5 -0
  16. package/lib/config/_prettierrc.js.ejs +8 -0
  17. package/lib/config/_stylelintignore.ejs +5 -0
  18. package/lib/config/_stylelintrc.js.ejs +5 -0
  19. package/lib/config/_vscode/extensions.json.ejs +7 -0
  20. package/lib/config/_vscode/settings.json.ejs +54 -0
  21. package/lib/config/commitlint.config.js.ejs +3 -0
  22. package/lib/config/encode-fe-lint.config.js.ejs +6 -0
  23. package/lib/index.d.ts +5 -0
  24. package/lib/index.js +94 -0
  25. package/lib/lints/eslint/doESLint.d.ts +6 -0
  26. package/lib/lints/eslint/doESLint.js +72 -0
  27. package/lib/lints/eslint/formatESLintResults.d.ts +3 -0
  28. package/lib/lints/eslint/formatESLintResults.js +39 -0
  29. package/lib/lints/eslint/getESLintConfig.d.ts +3 -0
  30. package/lib/lints/eslint/getESLintConfig.js +67 -0
  31. package/lib/lints/eslint/getESLintConfigType.d.ts +2 -0
  32. package/lib/lints/eslint/getESLintConfigType.js +23 -0
  33. package/lib/lints/eslint/index.d.ts +3 -0
  34. package/lib/lints/eslint/index.js +19 -0
  35. package/lib/lints/index.d.ts +4 -0
  36. package/lib/lints/index.js +20 -0
  37. package/lib/lints/markdownlint/doMarkdownlint.d.ts +6 -0
  38. package/lib/lints/markdownlint/doMarkdownlint.js +120 -0
  39. package/lib/lints/markdownlint/formatMarkdownlintResults.d.ts +3 -0
  40. package/lib/lints/markdownlint/formatMarkdownlintResults.js +39 -0
  41. package/lib/lints/markdownlint/getMarkdownlintConfig.d.ts +7 -0
  42. package/lib/lints/markdownlint/getMarkdownlintConfig.js +31 -0
  43. package/lib/lints/markdownlint/index.d.ts +3 -0
  44. package/lib/lints/markdownlint/index.js +19 -0
  45. package/lib/lints/prettier/doPrettier.d.ts +4 -0
  46. package/lib/lints/prettier/doPrettier.js +94 -0
  47. package/lib/lints/prettier/index.d.ts +1 -0
  48. package/lib/lints/prettier/index.js +17 -0
  49. package/lib/lints/stylelint/doStylelint.d.ts +5 -0
  50. package/lib/lints/stylelint/doStylelint.js +77 -0
  51. package/lib/lints/stylelint/formatStylelintResults.d.ts +3 -0
  52. package/lib/lints/stylelint/formatStylelintResults.js +39 -0
  53. package/lib/lints/stylelint/getStylelintConfig.d.ts +3 -0
  54. package/lib/lints/stylelint/getStylelintConfig.js +36 -0
  55. package/lib/lints/stylelint/getStylelintDocUrl.d.ts +1 -0
  56. package/lib/lints/stylelint/getStylelintDocUrl.js +13 -0
  57. package/lib/lints/stylelint/index.d.ts +3 -0
  58. package/lib/lints/stylelint/index.js +19 -0
  59. package/lib/types.d.ts +73 -0
  60. package/lib/types.js +2 -0
  61. package/lib/utils/configure-hooks.d.ts +3 -0
  62. package/lib/utils/configure-hooks.js +81 -0
  63. package/lib/utils/conflict-resolve.d.ts +3 -0
  64. package/lib/utils/conflict-resolve.js +174 -0
  65. package/lib/utils/constants.d.ts +19 -0
  66. package/lib/utils/constants.js +122 -0
  67. package/lib/utils/generate-template.d.ts +2 -0
  68. package/lib/utils/generate-template.js +99 -0
  69. package/lib/utils/get-files.d.ts +3 -0
  70. package/lib/utils/get-files.js +58 -0
  71. package/lib/utils/git.d.ts +3 -0
  72. package/lib/utils/git.js +106 -0
  73. package/lib/utils/log.d.ts +8 -0
  74. package/lib/utils/log.js +25 -0
  75. package/lib/utils/npm-type.d.ts +2 -0
  76. package/lib/utils/npm-type.js +9 -0
  77. package/lib/utils/print-report.d.ts +3 -0
  78. package/lib/utils/print-report.js +109 -0
  79. package/package.json +97 -3
@@ -0,0 +1,112 @@
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 child_process_1 = require("child_process");
43
+ var ora_1 = __importDefault(require("ora"));
44
+ var log_1 = __importDefault(require("../utils/log"));
45
+ var npm_type_1 = __importDefault(require("../utils/npm-type"));
46
+ var constants_1 = require("../utils/constants");
47
+ var checkLatestVersion = function () { return __awaiter(void 0, void 0, void 0, function () {
48
+ var npm, latestVersion, compareArr, beComparedArr, i;
49
+ return __generator(this, function (_a) {
50
+ switch (_a.label) {
51
+ case 0: return [4, npm_type_1.default];
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
+ });
package/lib/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/lib/cli.js ADDED
@@ -0,0 +1,276 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __generator = (this && this.__generator) || function (thisArg, body) {
13
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
+ function verb(n) { return function (v) { return step([n, v]); }; }
16
+ function step(op) {
17
+ if (f) throw new TypeError("Generator is already executing.");
18
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
+ 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;
20
+ if (y = 0, t) op = [op[0] & 2, t.value];
21
+ switch (op[0]) {
22
+ case 0: case 1: t = op; break;
23
+ case 4: _.label++; return { value: op[1], done: false };
24
+ case 5: _.label++; y = op[1]; op = [0]; continue;
25
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
+ default:
27
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
+ if (t[2]) _.ops.pop();
32
+ _.trys.pop(); continue;
33
+ }
34
+ op = body.call(thisArg, _);
35
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
+ }
38
+ };
39
+ var __read = (this && this.__read) || function (o, n) {
40
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
41
+ if (!m) return o;
42
+ var i = m.call(o), r, ar = [], e;
43
+ try {
44
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
45
+ }
46
+ catch (error) { e = { error: error }; }
47
+ finally {
48
+ try {
49
+ if (r && !r.done && (m = i["return"])) m.call(i);
50
+ }
51
+ finally { if (e) throw e.error; }
52
+ }
53
+ return ar;
54
+ };
55
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
56
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
57
+ if (ar || !(i in from)) {
58
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
59
+ ar[i] = from[i];
60
+ }
61
+ }
62
+ return to.concat(ar || Array.prototype.slice.call(from));
63
+ };
64
+ var __importDefault = (this && this.__importDefault) || function (mod) {
65
+ return (mod && mod.__esModule) ? mod : { "default": mod };
66
+ };
67
+ Object.defineProperty(exports, "__esModule", { value: true });
68
+ var path_1 = __importDefault(require("path"));
69
+ var fs_extra_1 = __importDefault(require("fs-extra"));
70
+ var ora_1 = __importDefault(require("ora"));
71
+ var glob_1 = __importDefault(require("glob"));
72
+ var commander_1 = require("commander");
73
+ var cross_spawn_1 = __importDefault(require("cross-spawn"));
74
+ var init_1 = __importDefault(require("./actions/init"));
75
+ var scan_1 = __importDefault(require("./actions/scan"));
76
+ var update_1 = __importDefault(require("./actions/update"));
77
+ var log_1 = __importDefault(require("./utils/log"));
78
+ var print_report_1 = __importDefault(require("./utils/print-report"));
79
+ var npm_type_1 = __importDefault(require("./utils/npm-type"));
80
+ var git_1 = require("./utils/git");
81
+ var generate_template_1 = __importDefault(require("./utils/generate-template"));
82
+ var constants_1 = require("./utils/constants");
83
+ var cwd = process.cwd();
84
+ var installDepsIfThereNo = function () { return __awaiter(void 0, void 0, void 0, function () {
85
+ var lintConfigFiles, nodeModulesPath, npm, result;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ lintConfigFiles = [].concat(glob_1.default.sync('.eslintrc?(.@(js|yaml|yml|json))', { cwd: cwd }), glob_1.default.sync('.stylelintrc?(.@(js|yaml|yml|json))', { cwd: cwd }), glob_1.default.sync('.markdownlint(.@(yaml|yml|json))', { cwd: cwd }));
90
+ nodeModulesPath = path_1.default.resolve(cwd, 'node_modules');
91
+ if (!(!fs_extra_1.default.existsSync(nodeModulesPath) && lintConfigFiles.length > 0)) return [3, 2];
92
+ return [4, npm_type_1.default];
93
+ case 1:
94
+ npm = _a.sent();
95
+ log_1.default.info("\u4F7F\u7528\u9879\u76EE Lint \u914D\u7F6E\uFF0C\u68C0\u6D4B\u5230\u9879\u76EE\u672A\u5B89\u88C5\u4F9D\u8D56\uFF0C\u5C06\u8FDB\u884C\u5B89\u88C5\uFF08\u6267\u884C ".concat(npm, " install\uFF09"));
96
+ result = cross_spawn_1.default.sync(npm, ['install'], { cwd: cwd, stdio: 'inherit' });
97
+ if (result.error || result.status !== 0) {
98
+ throw result.error || new Error("".concat(npm, " install \u5931\u8D25\uFF08\u9000\u51FA\u7801 ").concat(result.status, "\uFF09"));
99
+ }
100
+ _a.label = 2;
101
+ case 2: return [2];
102
+ }
103
+ });
104
+ }); };
105
+ commander_1.program
106
+ .version(constants_1.PKG_VERSION)
107
+ .description("".concat(constants_1.PKG_NAME, " \u662F \u5F3A\u4ED4\u524D\u7AEF\u7F16\u7801\u89C4\u8303\u5DE5\u7A0B\u5316 \u7684\u914D\u5957 Lint \u5DE5\u5177\uFF0C\u63D0\u4F9B\u7B80\u5355\u7684 CLI \u548C Node.js API\uFF0C\u8BA9\u9879\u76EE\u80FD\u591F\u4E00\u952E\u63A5\u5165\u3001\u4E00\u952E\u626B\u63CF\u3001\u4E00\u952E\u4FEE\u590D\u3001\u4E00\u952E\u5347\u7EA7\uFF0C\u5E76\u4E3A\u9879\u76EE\u914D\u7F6E git commit \u5361\u70B9\uFF0C\u964D\u4F4E\u9879\u76EE\u5B9E\u65BD\u89C4\u8303\u7684\u6210\u672C"));
108
+ commander_1.program
109
+ .command('init')
110
+ .description('一键接入:为项目初始化规范工具和配置,可以根据项目类型和需求进行定制')
111
+ .option('--vscode', '写入.vscode/setting.json配置')
112
+ .action(function (cmd) { return __awaiter(void 0, void 0, void 0, function () {
113
+ var configPath;
114
+ return __generator(this, function (_a) {
115
+ switch (_a.label) {
116
+ case 0:
117
+ if (!cmd.vscode) return [3, 1];
118
+ configPath = path_1.default.resolve(cwd, "".concat(constants_1.BIN_NAME, ".config.js"));
119
+ (0, generate_template_1.default)(cwd, require(configPath), true);
120
+ return [3, 3];
121
+ case 1: return [4, (0, init_1.default)({
122
+ cwd: cwd,
123
+ checkVersionUpdate: true,
124
+ })];
125
+ case 2:
126
+ _a.sent();
127
+ _a.label = 3;
128
+ case 3: return [2];
129
+ }
130
+ });
131
+ }); });
132
+ commander_1.program
133
+ .command('scan')
134
+ .description('一键扫描:对项目进行代码规范问题扫描')
135
+ .option('-q, --quiet', '仅报告错误信息 - 默认: false')
136
+ .option('-o, --output-report', '输出扫描出的规范问题日志')
137
+ .option('-i, --include <dirpath>', '指定要进行规范扫描的目录')
138
+ .option('--no-ignore', '忽略 eslint 的 ignore 配置文件和 ignore 规则')
139
+ .action(function (cmd) { return __awaiter(void 0, void 0, void 0, function () {
140
+ var checking, _a, results, errorCount, warningCount, runErrors, type;
141
+ return __generator(this, function (_b) {
142
+ switch (_b.label) {
143
+ case 0: return [4, installDepsIfThereNo()];
144
+ case 1:
145
+ _b.sent();
146
+ checking = (0, ora_1.default)();
147
+ checking.start("\u6267\u884C ".concat(constants_1.PKG_NAME, " \u4EE3\u7801\u68C0\u67E5"));
148
+ return [4, (0, scan_1.default)({
149
+ cwd: cwd,
150
+ fix: false,
151
+ include: cmd.include || cwd,
152
+ quiet: Boolean(cmd.quiet),
153
+ outputReport: Boolean(cmd.outputReport),
154
+ ignore: cmd.ignore,
155
+ })];
156
+ case 2:
157
+ _a = _b.sent(), results = _a.results, errorCount = _a.errorCount, warningCount = _a.warningCount, runErrors = _a.runErrors;
158
+ type = 'succeed';
159
+ if (runErrors.length > 0 || errorCount > 0) {
160
+ type = 'fail';
161
+ process.exitCode = 1;
162
+ }
163
+ else if (warningCount > 0) {
164
+ type = 'warn';
165
+ }
166
+ checking[type]();
167
+ if (results.length > 0)
168
+ (0, print_report_1.default)(results, false);
169
+ runErrors.forEach(function (e) { return console.error(e); });
170
+ return [2];
171
+ }
172
+ });
173
+ }); });
174
+ commander_1.program
175
+ .command('commit-msg-scan [file]')
176
+ .description('commit message 检查: git commit 时对 commit message 进行检查')
177
+ .action(function (file) {
178
+ var args = file ? ['--edit', file] : ['-E', 'HUSKY_GIT_PARAMS'];
179
+ var result = cross_spawn_1.default.sync(process.execPath, __spreadArray([require.resolve('@commitlint/cli/cli.js')], __read(args), false), {
180
+ cwd: cwd,
181
+ stdio: 'inherit',
182
+ });
183
+ if (result.error || result.status !== 0) {
184
+ if (result.error)
185
+ console.error(result.error);
186
+ process.exitCode = result.status || 1;
187
+ }
188
+ });
189
+ commander_1.program
190
+ .command('commit-file-scan')
191
+ .description('代码提交检查: git commit 时对提交代码进行规范问题扫描')
192
+ .option('-s, --strict', '严格模式,对 warn 和 error 问题都卡口,默认仅对 error 问题卡口')
193
+ .action(function (cmd) { return __awaiter(void 0, void 0, void 0, function () {
194
+ var files, checking, _a, results, errorCount, warningCount, runErrors, _b;
195
+ var _c;
196
+ return __generator(this, function (_d) {
197
+ switch (_d.label) {
198
+ case 0: return [4, installDepsIfThereNo()];
199
+ case 1:
200
+ _d.sent();
201
+ return [4, (0, git_1.getAmendFiles)()];
202
+ case 2:
203
+ files = _d.sent();
204
+ if (files)
205
+ log_1.default.warn("[".concat(constants_1.PKG_NAME, "] changes not staged for commit: \n").concat(files, "\n"));
206
+ checking = (0, ora_1.default)();
207
+ checking.start("\u6267\u884C ".concat(constants_1.PKG_NAME, " \u4EE3\u7801\u63D0\u4EA4\u68C0\u67E5"));
208
+ _b = scan_1.default;
209
+ _c = {
210
+ cwd: cwd,
211
+ include: cwd,
212
+ quiet: !cmd.strict
213
+ };
214
+ return [4, (0, git_1.getCommitFiles)()];
215
+ case 3: return [4, _b.apply(void 0, [(_c.files = _d.sent(),
216
+ _c)])];
217
+ case 4:
218
+ _a = _d.sent(), results = _a.results, errorCount = _a.errorCount, warningCount = _a.warningCount, runErrors = _a.runErrors;
219
+ if (runErrors.length > 0 || errorCount > 0 || (cmd.strict && warningCount > 0)) {
220
+ checking.fail();
221
+ if (results.length > 0)
222
+ (0, print_report_1.default)(results, false);
223
+ runErrors.forEach(function (error) { return console.error(error); });
224
+ process.exitCode = 1;
225
+ }
226
+ else {
227
+ checking.succeed();
228
+ }
229
+ return [2];
230
+ }
231
+ });
232
+ }); });
233
+ commander_1.program
234
+ .command('fix')
235
+ .description('一键修复:自动修复项目的代码规范扫描问题')
236
+ .option('-i, --include <dirpath>', '指定要进行修复扫描的目录')
237
+ .option('--no-ignore', '忽略 eslint 的 ignore 配置文件和 ignore 规则')
238
+ .action(function (cmd) { return __awaiter(void 0, void 0, void 0, function () {
239
+ var checking, _a, results, errorCount, runErrors;
240
+ return __generator(this, function (_b) {
241
+ switch (_b.label) {
242
+ case 0: return [4, installDepsIfThereNo()];
243
+ case 1:
244
+ _b.sent();
245
+ checking = (0, ora_1.default)();
246
+ checking.start("\u6267\u884C ".concat(constants_1.PKG_NAME, " \u4EE3\u7801\u4FEE\u590D"));
247
+ return [4, (0, scan_1.default)({
248
+ cwd: cwd,
249
+ fix: true,
250
+ include: cmd.include || cwd,
251
+ ignore: cmd.ignore,
252
+ })];
253
+ case 2:
254
+ _a = _b.sent(), results = _a.results, errorCount = _a.errorCount, runErrors = _a.runErrors;
255
+ if (errorCount > 0 || runErrors.length > 0) {
256
+ checking.fail();
257
+ process.exitCode = 1;
258
+ }
259
+ else {
260
+ checking.succeed();
261
+ }
262
+ if (results.length > 0)
263
+ (0, print_report_1.default)(results, true);
264
+ runErrors.forEach(function (error) { return console.error(error); });
265
+ return [2];
266
+ }
267
+ });
268
+ }); });
269
+ commander_1.program
270
+ .command('update')
271
+ .description("\u66F4\u65B0 ".concat(constants_1.PKG_NAME, " \u81F3\u6700\u65B0\u7248\u672C"))
272
+ .action(function () { return (0, update_1.default)(true); });
273
+ commander_1.program.parseAsync(process.argv).catch(function (error) {
274
+ console.error(error);
275
+ process.exitCode = 1;
276
+ });
@@ -0,0 +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
@@ -0,0 +1,9 @@
1
+ build/
2
+ coverage/
3
+ dist/
4
+ es/
5
+ lib/
6
+ node_modules/
7
+ **/*.min.js
8
+ **/*-min.js
9
+ **/*.bundle.js
@@ -0,0 +1,3 @@
1
+ module.exports = { extends: [ '<%= eslintType === 'index' ? '@qiangzaifan/eslint-config-encode' :
2
+ `@qiangzaifan/eslint-config-encode/${eslintType}` %>', <%_ if (enablePrettier) { _%> 'prettier', <%_ } _%> ],
3
+ };
@@ -0,0 +1 @@
1
+ <%_ if (enableMarkdownlint) { _%> { "extends": "@qiangzaifan/markdownlint-config-encode" } <%_ } _%>
@@ -0,0 +1,5 @@
1
+ <%_ if (enableMarkdownlint) { _%>
2
+ <%_ markdownLintIgnores.forEach((txt) => { _%>
3
+ <%= txt %>
4
+ <% }) %>
5
+ <%_ } _%>
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ printWidth: 100,
3
+ tabWidth: 2,
4
+ semi: true,
5
+ singleQuote: true,
6
+ trailingComma: 'all',
7
+ arrowParens: 'always',
8
+ };
@@ -0,0 +1,5 @@
1
+ <%_ if (enableStylelint) { _%>
2
+ <%_ stylelintIgnores.forEach((txt) => { _%>
3
+ <%= txt %>
4
+ <% }) %>
5
+ <%_ } _%>
@@ -0,0 +1,5 @@
1
+ <%_ if (enableStylelint) { _%>
2
+ module.exports = {
3
+ extends: '@qiangzaifan/stylelint-config-encode',
4
+ };
5
+ <%_ } _%>
@@ -0,0 +1,7 @@
1
+ {
2
+ "recommendations": [
3
+ "dbaeumer.vscode-eslint",
4
+ "stylelint.vscode-stylelint",
5
+ "esbenp.prettier-vscode"
6
+ ]
7
+ }
@@ -0,0 +1,54 @@
1
+ {
2
+ <%_ if (enableESLint) { _%>
3
+ "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact", "vue"],
4
+ <%_ } _%>
5
+ <%_ if (enableStylelint) { _%>
6
+ "stylelint.validate": [<%- stylelintExt.map((ext) => `"${ext.replace(/^\./, '')}"`).join(',') %>],
7
+ <%_ } _%>
8
+ "editor.codeActionsOnSave": {
9
+ "source.fixAll.eslint": true<%= enableStylelint || enableMarkdownlint ? ',' : ''%>
10
+ <%_ if (enableStylelint) { _%>
11
+ "source.fixAll.stylelint": true<%= enableMarkdownlint ? ',' : ''%>
12
+ <%_ } _%>
13
+ <%_ if (enableMarkdownlint) { _%>
14
+ "source.fixAll.markdownlint": true
15
+ <%_ } _%>
16
+ },
17
+ <%_ if (enablePrettier) { _%>
18
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
19
+ "[javascript]": {
20
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
21
+ },
22
+ "[javascriptreact]": {
23
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
24
+ },
25
+ "[typescript]": {
26
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
27
+ },
28
+ "[typescriptreact]": {
29
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
30
+ },
31
+ "[vue]": {
32
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
33
+ },
34
+ "[css]": {
35
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
36
+ },
37
+ "[less]": {
38
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
39
+ },
40
+ "[scss]": {
41
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
42
+ },
43
+ "[html]": {
44
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
45
+ },
46
+ "[json]": {
47
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
48
+ },
49
+ "[jsonc]": {
50
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
51
+ },
52
+ <%_ } _%>
53
+ "editor.formatOnSave": <%= enablePrettier ? 'true' : 'false' %>
54
+ }
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ extends: ['@qiangzaifan/commitlint-config-encode'],
3
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ enableESLint: <%= enableESLint %>,
3
+ enableStylelint: <%= enableStylelint %>,
4
+ enableMarkdownlint: <%= enableMarkdownlint %>,
5
+ enablePrettier: <%= enablePrettier %>,
6
+ };
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import type { InitOptions, ScanOptions } from './types';
2
+ type IInitOptions = Omit<InitOptions, 'checkVersionUpdate'>;
3
+ export declare const init: (options: IInitOptions) => Promise<void>;
4
+ export declare const scan: (options: ScanOptions) => Promise<import("./types").ScanReport>;
5
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,94 @@
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
+ exports.scan = exports.init = void 0;
54
+ var ora_1 = __importDefault(require("ora"));
55
+ var scan_1 = __importDefault(require("./actions/scan"));
56
+ var init_1 = __importDefault(require("./actions/init"));
57
+ var constants_1 = require("./utils/constants");
58
+ var print_report_1 = __importDefault(require("./utils/print-report"));
59
+ var init = function (options) { return __awaiter(void 0, void 0, void 0, function () {
60
+ return __generator(this, function (_a) {
61
+ switch (_a.label) {
62
+ case 0: return [4, (0, init_1.default)(__assign(__assign({}, options), { checkVersionUpdate: false }))];
63
+ case 1: return [2, _a.sent()];
64
+ }
65
+ });
66
+ }); };
67
+ exports.init = init;
68
+ var scan = function (options) { return __awaiter(void 0, void 0, void 0, function () {
69
+ var checking, report, results, errorCount, warningCount, runErrors, type;
70
+ return __generator(this, function (_a) {
71
+ switch (_a.label) {
72
+ case 0:
73
+ checking = (0, ora_1.default)();
74
+ checking.start("\u6267\u884C ".concat(constants_1.PKG_NAME, " \u4EE3\u7801\u68C0\u67E5"));
75
+ return [4, (0, scan_1.default)(options)];
76
+ case 1:
77
+ report = _a.sent();
78
+ results = report.results, errorCount = report.errorCount, warningCount = report.warningCount, runErrors = report.runErrors;
79
+ type = 'succeed';
80
+ if (errorCount > 0 || runErrors.length > 0) {
81
+ type = 'fail';
82
+ }
83
+ else if (warningCount > 0) {
84
+ type = 'warn';
85
+ }
86
+ checking[type]();
87
+ if (results.length > 0)
88
+ (0, print_report_1.default)(results, false);
89
+ runErrors.forEach(function (error) { return console.error(error); });
90
+ return [2, report];
91
+ }
92
+ });
93
+ }); };
94
+ exports.scan = scan;
@@ -0,0 +1,6 @@
1
+ import { Config, PKG, ScanOptions } from '../../types';
2
+ export interface DoESLintOptions extends ScanOptions {
3
+ pkg: PKG;
4
+ config?: Config;
5
+ }
6
+ export declare function doESLint(options: DoESLintOptions): Promise<import("../../types").ScanResult[]>;