@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.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/lib/actions/init.d.ts +3 -0
- package/lib/actions/init.js +223 -0
- package/lib/actions/scan.d.ts +3 -0
- package/lib/actions/scan.js +137 -0
- package/lib/actions/update.d.ts +2 -0
- package/lib/actions/update.js +112 -0
- package/lib/cli.d.ts +2 -0
- package/lib/cli.js +230 -0
- package/lib/config/_editorconfig.ejs +13 -0
- package/lib/config/_eslintignore.ejs +9 -0
- package/lib/config/_eslintrc.js.ejs +3 -0
- package/lib/config/_markdownlint.json.ejs +1 -0
- package/lib/config/_markdownlintignore.ejs +5 -0
- package/lib/config/_prettierrc.js.ejs +8 -0
- package/lib/config/_stylelintignore.ejs +5 -0
- package/lib/config/_stylelintrc.js.ejs +5 -0
- package/lib/config/_vscode/extensions.json.ejs +7 -0
- package/lib/config/_vscode/settings.json.ejs +54 -0
- package/lib/config/commitlint.config.js.ejs +3 -0
- package/lib/config/encode-fe-lint.config.js.ejs +6 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +93 -0
- package/lib/lints/eslint/doEslint.d.ts +6 -0
- package/lib/lints/eslint/doEslint.js +80 -0
- package/lib/lints/eslint/formatESLintResults.d.ts +3 -0
- package/lib/lints/eslint/formatESLintResults.js +39 -0
- package/lib/lints/eslint/getESLintConfig.d.ts +3 -0
- package/lib/lints/eslint/getESLintConfig.js +67 -0
- package/lib/lints/eslint/getESLintConfigType.d.ts +2 -0
- package/lib/lints/eslint/getESLintConfigType.js +26 -0
- package/lib/lints/eslint/index.d.ts +3 -0
- package/lib/lints/eslint/index.js +19 -0
- package/lib/lints/index.d.ts +4 -0
- package/lib/lints/index.js +20 -0
- package/lib/lints/markdownlint/doMarkdownlint.d.ts +6 -0
- package/lib/lints/markdownlint/doMarkdownlint.js +119 -0
- package/lib/lints/markdownlint/formatMarkdownlintResults.d.ts +3 -0
- package/lib/lints/markdownlint/formatMarkdownlintResults.js +39 -0
- package/lib/lints/markdownlint/getMarkdownlintConfig.d.ts +7 -0
- package/lib/lints/markdownlint/getMarkdownlintConfig.js +31 -0
- package/lib/lints/markdownlint/index.d.ts +3 -0
- package/lib/lints/markdownlint/index.js +19 -0
- package/lib/lints/prettier/doPrettier.d.ts +4 -0
- package/lib/lints/prettier/doPrettier.js +106 -0
- package/lib/lints/prettier/index.d.ts +1 -0
- package/lib/lints/prettier/index.js +17 -0
- package/lib/lints/stylelint/doStylelint.d.ts +5 -0
- package/lib/lints/stylelint/doStylelint.js +86 -0
- package/lib/lints/stylelint/formatStylelintResults.d.ts +3 -0
- package/lib/lints/stylelint/formatStylelintResults.js +39 -0
- package/lib/lints/stylelint/getStylelintConfig.d.ts +3 -0
- package/lib/lints/stylelint/getStylelintConfig.js +36 -0
- package/lib/lints/stylelint/getStylelintDocUrl.d.ts +1 -0
- package/lib/lints/stylelint/getStylelintDocUrl.js +13 -0
- package/lib/lints/stylelint/index.d.ts +3 -0
- package/lib/lints/stylelint/index.js +19 -0
- package/lib/types/index.d.ts +73 -0
- package/lib/types/index.js +2 -0
- package/lib/utils/conflict-resolve.d.ts +3 -0
- package/lib/utils/conflict-resolve.js +175 -0
- package/lib/utils/constants.d.ts +18 -0
- package/lib/utils/constants.js +133 -0
- package/lib/utils/generate-template.d.ts +2 -0
- package/lib/utils/generate-template.js +99 -0
- package/lib/utils/git.d.ts +3 -0
- package/lib/utils/git.js +105 -0
- package/lib/utils/init.d.ts +3 -0
- package/lib/utils/init.js +223 -0
- package/lib/utils/log.d.ts +8 -0
- package/lib/utils/log.js +25 -0
- package/lib/utils/npm-type.d.ts +2 -0
- package/lib/utils/npm-type.js +10 -0
- package/lib/utils/print-report.d.ts +3 -0
- package/lib/utils/print-report.js +109 -0
- package/lib/utils/update.d.ts +2 -0
- package/lib/utils/update.js +112 -0
- package/package.json +97 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 黄俊森
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
|
@@ -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,137 @@
|
|
|
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
|
+
}); });
|
|
@@ -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