@huangjunsen/encode-fe-lint 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 +21 -0
  2. package/README.md +0 -0
  3. package/lib/actions/init.d.ts +3 -0
  4. package/lib/actions/init.js +223 -0
  5. package/lib/actions/scan.d.ts +3 -0
  6. package/lib/actions/scan.js +137 -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 +230 -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 +93 -0
  25. package/lib/lints/eslint/doEslint.d.ts +6 -0
  26. package/lib/lints/eslint/doEslint.js +80 -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 +26 -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 +119 -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 +106 -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 +86 -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/index.d.ts +73 -0
  60. package/lib/types/index.js +2 -0
  61. package/lib/utils/conflict-resolve.d.ts +3 -0
  62. package/lib/utils/conflict-resolve.js +175 -0
  63. package/lib/utils/constants.d.ts +18 -0
  64. package/lib/utils/constants.js +133 -0
  65. package/lib/utils/generate-template.d.ts +2 -0
  66. package/lib/utils/generate-template.js +99 -0
  67. package/lib/utils/git.d.ts +3 -0
  68. package/lib/utils/git.js +105 -0
  69. package/lib/utils/init.d.ts +3 -0
  70. package/lib/utils/init.js +223 -0
  71. package/lib/utils/log.d.ts +8 -0
  72. package/lib/utils/log.js +25 -0
  73. package/lib/utils/npm-type.d.ts +2 -0
  74. package/lib/utils/npm-type.js +10 -0
  75. package/lib/utils/print-report.d.ts +3 -0
  76. package/lib/utils/print-report.js +109 -0
  77. package/lib/utils/update.d.ts +2 -0
  78. package/lib/utils/update.js +112 -0
  79. package/package.json +97 -0
@@ -0,0 +1,105 @@
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.getAmendFiles = exports.getCommitFiles = void 0;
54
+ var execa_1 = __importDefault(require("execa"));
55
+ var getCommitFiles = function (options) {
56
+ if (options === void 0) { options = {}; }
57
+ return __awaiter(void 0, void 0, void 0, function () {
58
+ var stdout, e_1;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ _a.trys.push([0, 2, , 3]);
63
+ return [4, (0, execa_1.default)('git', [
64
+ 'diff',
65
+ '--staged',
66
+ '--diff-filter=ACMR',
67
+ '--name-only',
68
+ '--ignore-submodules',
69
+ ], __assign(__assign({}, options), { all: true, cwd: options.cwd || process.cwd() }))];
70
+ case 1:
71
+ stdout = (_a.sent()).stdout;
72
+ return [2, stdout ? stdout.split(/\s/).filter(Boolean) : []];
73
+ case 2:
74
+ e_1 = _a.sent();
75
+ return [2, []];
76
+ case 3: return [2];
77
+ }
78
+ });
79
+ });
80
+ };
81
+ exports.getCommitFiles = getCommitFiles;
82
+ var getAmendFiles = function (options) {
83
+ if (options === void 0) { options = {}; }
84
+ return __awaiter(void 0, void 0, void 0, function () {
85
+ var stdout, e_2;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ _a.trys.push([0, 2, , 3]);
90
+ return [4, (0, execa_1.default)('git', [
91
+ 'diff',
92
+ '--name-only',
93
+ ], __assign(__assign({}, options), { all: true, cwd: options.cwd || process.cwd() }))];
94
+ case 1:
95
+ stdout = (_a.sent()).stdout;
96
+ return [2, stdout];
97
+ case 2:
98
+ e_2 = _a.sent();
99
+ return [2, ''];
100
+ case 3: return [2];
101
+ }
102
+ });
103
+ });
104
+ };
105
+ exports.getAmendFiles = getAmendFiles;
@@ -0,0 +1,3 @@
1
+ import type { InitOptions } from '../types';
2
+ declare const _default: (options: InitOptions) => Promise<void>;
3
+ export default _default;
@@ -0,0 +1,223 @@
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, "-scan")]) {
201
+ pkg.scripts["".concat(constants_1.PKG_NAME, "-scan")] = "".concat(constants_1.PKG_NAME, " scan");
202
+ }
203
+ if (!pkg.scripts["".concat(constants_1.PKG_NAME, "-fix")]) {
204
+ pkg.scripts["".concat(constants_1.PKG_NAME, "-fix")] = "".concat(constants_1.PKG_NAME, " 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, " commit-file-scan");
212
+ pkg.husky.hooks['commit-msg'] = "".concat(constants_1.PKG_NAME, " 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
+ }); });
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ success(text: string): void;
3
+ info(text: string): void;
4
+ warn(text: string): void;
5
+ error(text: string): void;
6
+ result(text: string, pass: boolean): void;
7
+ };
8
+ export default _default;
@@ -0,0 +1,25 @@
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
+ var chalk_1 = __importDefault(require("chalk"));
7
+ var constants_1 = require("./constants");
8
+ var green = chalk_1.default.green, blue = chalk_1.default.blue, yellow = chalk_1.default.yellow, red = chalk_1.default.red;
9
+ exports.default = {
10
+ success: function (text) {
11
+ console.log(green(text));
12
+ },
13
+ info: function (text) {
14
+ console.info(blue(text));
15
+ },
16
+ warn: function (text) {
17
+ console.info(yellow(text));
18
+ },
19
+ error: function (text) {
20
+ console.error(red(text));
21
+ },
22
+ result: function (text, pass) {
23
+ console.info(blue("[".concat(constants_1.PKG_NAME, "] ").concat(text)), pass ? green(constants_1.UNICODE.success) : red(constants_1.UNICODE.failure));
24
+ },
25
+ };
@@ -0,0 +1,2 @@
1
+ declare const promise: Promise<'npm' | 'pnpm'>;
2
+ export default promise;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var command_exists_1 = require("command-exists");
4
+ var promise = new Promise(function (resolve, reject) {
5
+ if (!(0, command_exists_1.sync)('pnpm')) {
6
+ resolve('npm');
7
+ }
8
+ resolve('pnpm');
9
+ });
10
+ exports.default = promise;
@@ -0,0 +1,3 @@
1
+ import type { ScanResult } from '../types';
2
+ declare const _default: (results: ScanResult[], fix: boolean) => void;
3
+ export default _default;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ var chalk_1 = __importDefault(require("chalk"));
18
+ var text_table_1 = __importDefault(require("text-table"));
19
+ var terminal_link_1 = __importDefault(require("terminal-link"));
20
+ var is_docker_1 = __importDefault(require("is-docker"));
21
+ var strip_ansi_1 = __importDefault(require("strip-ansi"));
22
+ var constants_1 = require("./constants");
23
+ exports.default = (function (results, fix) {
24
+ var e_1, _a;
25
+ var output = '\n';
26
+ var errorCount = 0;
27
+ var warningCount = 0;
28
+ var fixableErrorCount = 0;
29
+ var fixableWarningCount = 0;
30
+ var summaryColor = 'yellow';
31
+ var transformMessage = function (_a) {
32
+ var line = _a.line, column = _a.column, rule = _a.rule, url = _a.url, message = _a.message, errored = _a.errored;
33
+ if (errored)
34
+ summaryColor = 'red';
35
+ var text = '';
36
+ if (rule && url) {
37
+ text = (0, terminal_link_1.default)(chalk_1.default.blue(rule), chalk_1.default.dim(" ".concat(url, " ")), { fallback: !(0, is_docker_1.default)() });
38
+ }
39
+ else if (rule) {
40
+ text = chalk_1.default.blue(rule);
41
+ }
42
+ return [
43
+ '',
44
+ chalk_1.default.dim("".concat(line, ":").concat(column)),
45
+ errored ? chalk_1.default.red('error') : chalk_1.default.yellow('warning'),
46
+ message,
47
+ text,
48
+ ];
49
+ };
50
+ try {
51
+ for (var results_1 = __values(results), results_1_1 = results_1.next(); !results_1_1.done; results_1_1 = results_1.next()) {
52
+ var result = results_1_1.value;
53
+ if (result.messages.length === 0)
54
+ continue;
55
+ var messages = result.messages;
56
+ errorCount += result.errorCount;
57
+ warningCount += result.warningCount;
58
+ fixableErrorCount += result.fixableErrorCount;
59
+ fixableWarningCount += result.fixableWarningCount;
60
+ output += "".concat(chalk_1.default.underline(result.filePath), "\n");
61
+ output += "".concat((0, text_table_1.default)(messages.map(transformMessage), {
62
+ align: ['.', 'r', 'l'],
63
+ stringLength: function (str) { return (0, strip_ansi_1.default)(str).length; },
64
+ }), "\n\n");
65
+ }
66
+ }
67
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
68
+ finally {
69
+ try {
70
+ if (results_1_1 && !results_1_1.done && (_a = results_1.return)) _a.call(results_1);
71
+ }
72
+ finally { if (e_1) throw e_1.error; }
73
+ }
74
+ var total = errorCount + warningCount;
75
+ var pluralize = function (word, count) { return (count === 1 ? word : "".concat(word, "s")); };
76
+ if (fix)
77
+ output += chalk_1.default.green('代码规范问题自动修复完成,请通过 git diff 确认修复效果 :D\n');
78
+ if (fix && total > 0) {
79
+ output += chalk_1.default.green('ps. 以上显示的是无法被自动修复的问题,需要手动进行修复\n');
80
+ }
81
+ if (!fix && total > 0) {
82
+ output += chalk_1.default[summaryColor].bold([
83
+ "".concat(constants_1.UNICODE.failure, " "),
84
+ total,
85
+ pluralize(' problem', total),
86
+ ' (',
87
+ errorCount,
88
+ pluralize(' error', errorCount),
89
+ ', ',
90
+ warningCount,
91
+ pluralize(' warning', warningCount),
92
+ ')\n',
93
+ ].join(''));
94
+ if (fixableErrorCount > 0 || fixableWarningCount > 0) {
95
+ output += chalk_1.default[summaryColor].bold([
96
+ ' ',
97
+ fixableErrorCount,
98
+ pluralize(' error', fixableErrorCount),
99
+ ' and ',
100
+ fixableWarningCount,
101
+ pluralize(' warning', fixableWarningCount),
102
+ " potentially fixable with the `".concat(constants_1.PKG_NAME, " fix`"),
103
+ ].join(''));
104
+ }
105
+ }
106
+ if (!fix && total === 0)
107
+ output = chalk_1.default.green.bold("".concat(constants_1.UNICODE.success, " no problems"));
108
+ console.log(chalk_1.default.reset(output));
109
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: (install?: boolean) => Promise<void>;
2
+ export default _default;
@@ -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
+ });