@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.
- package/LICENSE +22 -0
- package/README.md +190 -2
- package/lib/actions/init.d.ts +3 -0
- package/lib/actions/init.js +250 -0
- package/lib/actions/scan.d.ts +3 -0
- package/lib/actions/scan.js +146 -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 +276 -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 +94 -0
- package/lib/lints/eslint/doESLint.d.ts +6 -0
- package/lib/lints/eslint/doESLint.js +72 -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 +23 -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 +120 -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 +94 -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 +77 -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.d.ts +73 -0
- package/lib/types.js +2 -0
- package/lib/utils/configure-hooks.d.ts +3 -0
- package/lib/utils/configure-hooks.js +81 -0
- package/lib/utils/conflict-resolve.d.ts +3 -0
- package/lib/utils/conflict-resolve.js +174 -0
- package/lib/utils/constants.d.ts +19 -0
- package/lib/utils/constants.js +122 -0
- package/lib/utils/generate-template.d.ts +2 -0
- package/lib/utils/generate-template.js +99 -0
- package/lib/utils/get-files.d.ts +3 -0
- package/lib/utils/get-files.js +58 -0
- package/lib/utils/git.d.ts +3 -0
- package/lib/utils/git.js +106 -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 +9 -0
- package/lib/utils/print-report.d.ts +3 -0
- package/lib/utils/print-report.js +109 -0
- package/package.json +97 -3
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.PRETTIER_IGNORE_PATTERN = exports.PRETTIER_FILE_EXT = exports.MARKDOWN_LINT_IGNORE_PATTERN = exports.MARKDOWN_LINT_FILE_EXT = exports.STYLELINT_IGNORE_PATTERN = exports.STYLELINT_FILE_EXT = exports.ESLINT_IGNORE_PATTERN = exports.ESLINT_FILE_EXT = exports.PROJECT_TYPES = exports.PKG_VERSION = exports.BIN_NAME = exports.PKG_NAME = exports.UNICODE = void 0;
|
|
32
|
+
var path_1 = __importDefault(require("path"));
|
|
33
|
+
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
34
|
+
var pkg = JSON.parse(fs_extra_1.default.readFileSync(path_1.default.join(__dirname, '../../package.json'), 'utf8'));
|
|
35
|
+
var UNICODE;
|
|
36
|
+
(function (UNICODE) {
|
|
37
|
+
UNICODE["success"] = "\u2714";
|
|
38
|
+
UNICODE["failure"] = "\u2716";
|
|
39
|
+
})(UNICODE = exports.UNICODE || (exports.UNICODE = {}));
|
|
40
|
+
exports.PKG_NAME = pkg.name;
|
|
41
|
+
exports.BIN_NAME = exports.PKG_NAME.split('/').pop();
|
|
42
|
+
exports.PKG_VERSION = pkg.version;
|
|
43
|
+
exports.PROJECT_TYPES = [
|
|
44
|
+
{
|
|
45
|
+
name: '未使用 React、Vue、Node.js 的项目(JavaScript)',
|
|
46
|
+
value: 'index',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: '未使用 React、Vue、Node.js 的项目(TypeScript)',
|
|
50
|
+
value: 'typescript',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'React 项目(JavaScript)',
|
|
54
|
+
value: 'react',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'React 项目(TypeScript)',
|
|
58
|
+
value: 'typescript/react',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'Vue 项目(JavaScript)',
|
|
62
|
+
value: 'vue',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'Vue 项目(TypeScript)',
|
|
66
|
+
value: 'typescript/vue',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'Node.js 项目(JavaScript)',
|
|
70
|
+
value: 'node',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'Node.js 项目(TypeScript)',
|
|
74
|
+
value: 'typescript/node',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: '使用 ES5 及之前版本 JavaScript 的老项目',
|
|
78
|
+
value: 'es5',
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
exports.ESLINT_FILE_EXT = ['.js', '.jsx', '.ts', '.tsx', '.vue'];
|
|
82
|
+
exports.ESLINT_IGNORE_PATTERN = [
|
|
83
|
+
'node_modules',
|
|
84
|
+
'build',
|
|
85
|
+
'dist',
|
|
86
|
+
'coverage',
|
|
87
|
+
'es',
|
|
88
|
+
'lib',
|
|
89
|
+
'**/*.min.js',
|
|
90
|
+
'**/*-min.js',
|
|
91
|
+
'**/*.bundle.js',
|
|
92
|
+
];
|
|
93
|
+
exports.STYLELINT_FILE_EXT = ['.css', '.scss', '.less', '.acss'];
|
|
94
|
+
exports.STYLELINT_IGNORE_PATTERN = [
|
|
95
|
+
'node_modules/',
|
|
96
|
+
'build/',
|
|
97
|
+
'dist/',
|
|
98
|
+
'coverage/',
|
|
99
|
+
'es/',
|
|
100
|
+
'lib/',
|
|
101
|
+
'**/*.min.css',
|
|
102
|
+
'**/*-min.css',
|
|
103
|
+
'**/*.bundle.css',
|
|
104
|
+
];
|
|
105
|
+
exports.MARKDOWN_LINT_FILE_EXT = ['.md'];
|
|
106
|
+
exports.MARKDOWN_LINT_IGNORE_PATTERN = [
|
|
107
|
+
'node_modules/',
|
|
108
|
+
'build/',
|
|
109
|
+
'dist/',
|
|
110
|
+
'coverage/',
|
|
111
|
+
'es/',
|
|
112
|
+
'lib/',
|
|
113
|
+
];
|
|
114
|
+
exports.PRETTIER_FILE_EXT = __spreadArray(__spreadArray(__spreadArray([], __read(exports.STYLELINT_FILE_EXT), false), __read(exports.ESLINT_FILE_EXT), false), __read(exports.MARKDOWN_LINT_FILE_EXT), false);
|
|
115
|
+
exports.PRETTIER_IGNORE_PATTERN = [
|
|
116
|
+
'node_modules/**/*',
|
|
117
|
+
'build/**/*',
|
|
118
|
+
'dist/**/*',
|
|
119
|
+
'lib/**/*',
|
|
120
|
+
'es/**/*',
|
|
121
|
+
'coverage/**/*',
|
|
122
|
+
];
|
|
@@ -0,0 +1,99 @@
|
|
|
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 __read = (this && this.__read) || function (o, n) {
|
|
14
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
+
if (!m) return o;
|
|
16
|
+
var i = m.call(o), r, ar = [], e;
|
|
17
|
+
try {
|
|
18
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
+
}
|
|
20
|
+
catch (error) { e = { error: error }; }
|
|
21
|
+
finally {
|
|
22
|
+
try {
|
|
23
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
+
}
|
|
25
|
+
finally { if (e) throw e.error; }
|
|
26
|
+
}
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
+
if (ar || !(i in from)) {
|
|
32
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
+
ar[i] = from[i];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
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 path_1 = __importDefault(require("path"));
|
|
54
|
+
var fs_extra_1 = __importDefault(require("fs-extra"));
|
|
55
|
+
var lodash_1 = __importDefault(require("lodash"));
|
|
56
|
+
var glob_1 = __importDefault(require("glob"));
|
|
57
|
+
var ejs_1 = __importDefault(require("ejs"));
|
|
58
|
+
var constants_1 = require("./constants");
|
|
59
|
+
var mergeVSCodeConfig = function (filepath, content) {
|
|
60
|
+
if (!fs_extra_1.default.existsSync(filepath))
|
|
61
|
+
return content;
|
|
62
|
+
try {
|
|
63
|
+
var targetData = fs_extra_1.default.readJSONSync(filepath);
|
|
64
|
+
var sourceData = JSON.parse(content);
|
|
65
|
+
return JSON.stringify(lodash_1.default.mergeWith(targetData, sourceData, function (target, source) {
|
|
66
|
+
if (Array.isArray(target) && Array.isArray(source)) {
|
|
67
|
+
return __spreadArray([], __read(new Set(source.concat(target))), false);
|
|
68
|
+
}
|
|
69
|
+
}), null, 2);
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.default = (function (cwd, data, vscode) {
|
|
76
|
+
var e_1, _a;
|
|
77
|
+
var templatePath = path_1.default.resolve(__dirname, '../config');
|
|
78
|
+
var templates = glob_1.default.sync("".concat(vscode ? '_vscode' : '**', "/*.ejs"), { cwd: templatePath });
|
|
79
|
+
try {
|
|
80
|
+
for (var templates_1 = __values(templates), templates_1_1 = templates_1.next(); !templates_1_1.done; templates_1_1 = templates_1.next()) {
|
|
81
|
+
var name_1 = templates_1_1.value;
|
|
82
|
+
var filepath = path_1.default.resolve(cwd, name_1.replace(/\.ejs$/, '').replace(/^_/, '.'));
|
|
83
|
+
var content = ejs_1.default.render(fs_extra_1.default.readFileSync(path_1.default.resolve(templatePath, name_1), 'utf8'), __assign({ eslintIgnores: constants_1.ESLINT_IGNORE_PATTERN, stylelintExt: constants_1.STYLELINT_FILE_EXT, stylelintIgnores: constants_1.STYLELINT_IGNORE_PATTERN, markdownLintIgnores: constants_1.MARKDOWN_LINT_IGNORE_PATTERN }, data));
|
|
84
|
+
if (/^_vscode/.test(name_1)) {
|
|
85
|
+
content = mergeVSCodeConfig(filepath, content);
|
|
86
|
+
}
|
|
87
|
+
if (!content.trim())
|
|
88
|
+
continue;
|
|
89
|
+
fs_extra_1.default.outputFileSync(filepath, content, 'utf8');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
93
|
+
finally {
|
|
94
|
+
try {
|
|
95
|
+
if (templates_1_1 && !templates_1_1.done && (_a = templates_1.return)) _a.call(templates_1);
|
|
96
|
+
}
|
|
97
|
+
finally { if (e_1) throw e_1.error; }
|
|
98
|
+
}
|
|
99
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
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 fast_glob_1 = __importDefault(require("fast-glob"));
|
|
43
|
+
var path_1 = __importDefault(require("path"));
|
|
44
|
+
exports.default = (function (options, extensions, ignore) { return __awaiter(void 0, void 0, void 0, function () {
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
if (options.files) {
|
|
47
|
+
return [2, options.files
|
|
48
|
+
.filter(function (name) { return extensions.includes(path_1.default.extname(name)); })
|
|
49
|
+
.map(function (name) { return path_1.default.resolve(options.cwd, name); })];
|
|
50
|
+
}
|
|
51
|
+
return [2, (0, fast_glob_1.default)(extensions.map(function (ext) { return "**/*".concat(ext); }), {
|
|
52
|
+
cwd: path_1.default.resolve(options.cwd, options.include || '.'),
|
|
53
|
+
ignore: ignore,
|
|
54
|
+
absolute: true,
|
|
55
|
+
onlyFiles: true,
|
|
56
|
+
})];
|
|
57
|
+
});
|
|
58
|
+
}); });
|
package/lib/utils/git.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
'-z',
|
|
69
|
+
'--ignore-submodules',
|
|
70
|
+
], __assign(__assign({}, options), { all: true, cwd: options.cwd || process.cwd() }))];
|
|
71
|
+
case 1:
|
|
72
|
+
stdout = (_a.sent()).stdout;
|
|
73
|
+
return [2, stdout ? stdout.split('\0').filter(Boolean) : []];
|
|
74
|
+
case 2:
|
|
75
|
+
e_1 = _a.sent();
|
|
76
|
+
return [2, []];
|
|
77
|
+
case 3: return [2];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
exports.getCommitFiles = getCommitFiles;
|
|
83
|
+
var getAmendFiles = function (options) {
|
|
84
|
+
if (options === void 0) { options = {}; }
|
|
85
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
+
var stdout, e_2;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
_a.trys.push([0, 2, , 3]);
|
|
91
|
+
return [4, (0, execa_1.default)('git', [
|
|
92
|
+
'diff',
|
|
93
|
+
'--name-only',
|
|
94
|
+
], __assign(__assign({}, options), { all: true, cwd: options.cwd || process.cwd() }))];
|
|
95
|
+
case 1:
|
|
96
|
+
stdout = (_a.sent()).stdout;
|
|
97
|
+
return [2, stdout];
|
|
98
|
+
case 2:
|
|
99
|
+
e_2 = _a.sent();
|
|
100
|
+
return [2, ''];
|
|
101
|
+
case 3: return [2];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
exports.getAmendFiles = getAmendFiles;
|
package/lib/utils/log.js
ADDED
|
@@ -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,9 @@
|
|
|
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) {
|
|
5
|
+
if (!(0, command_exists_1.sync)('pnpm'))
|
|
6
|
+
return resolve('npm');
|
|
7
|
+
resolve('pnpm');
|
|
8
|
+
});
|
|
9
|
+
exports.default = promise;
|
|
@@ -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.BIN_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
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,100 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qiangzaifan/encode-fe-lint",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "强仔教育前端编码规范工程化标准脚手架",
|
|
5
|
+
"bin": "./lib/cli.js",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"encode",
|
|
15
|
+
"lint",
|
|
16
|
+
"cli"
|
|
17
|
+
],
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/command-exists": "^1.2.0",
|
|
20
|
+
"@types/cross-spawn": "^6.0.2",
|
|
21
|
+
"@types/ejs": "^3.1.0",
|
|
22
|
+
"@types/eslint": "^8.4.1",
|
|
23
|
+
"@types/fs-extra": "^9.0.13",
|
|
24
|
+
"@types/glob": "^7.2.0",
|
|
25
|
+
"@types/lodash": "^4.14.180",
|
|
26
|
+
"@types/node": "^14.14.11",
|
|
27
|
+
"@types/prettier": "^2.4.4",
|
|
28
|
+
"@types/stylelint": "^14.0.0",
|
|
29
|
+
"@types/text-table": "^0.2.2",
|
|
30
|
+
"copyfiles": "^2.4.1",
|
|
31
|
+
"jest": "^27.5.1",
|
|
32
|
+
"nyc": "^15.1.0",
|
|
33
|
+
"typescript": "^4.6.2"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@babel/core": "^7.16.0",
|
|
37
|
+
"@babel/eslint-parser": "^7.16.3",
|
|
38
|
+
"@babel/preset-react": "^7.16.0",
|
|
39
|
+
"@commitlint/cli": "^16.0.0",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
|
41
|
+
"@typescript-eslint/parser": "^5.0.0",
|
|
42
|
+
"chalk": "^4.1.0",
|
|
43
|
+
"command-exists": "^1.2.9",
|
|
44
|
+
"commander": "^6.2.1",
|
|
45
|
+
"cross-spawn": "^7.0.3",
|
|
46
|
+
"ejs": "^3.1.5",
|
|
47
|
+
"eslint": "^8.7.0",
|
|
48
|
+
"eslint-config-egg": "^10.0.0",
|
|
49
|
+
"eslint-config-prettier": "^8.3.0",
|
|
50
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
51
|
+
"eslint-plugin-import": "^2.22.1",
|
|
52
|
+
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
53
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
54
|
+
"eslint-plugin-react": "^7.21.5",
|
|
55
|
+
"eslint-plugin-react-hooks": "^4.2.0",
|
|
56
|
+
"eslint-plugin-vue": "^7.3.0",
|
|
57
|
+
"execa": "^5.0.0",
|
|
58
|
+
"fast-glob": "^3.2.11",
|
|
59
|
+
"fs-extra": "^9.0.1",
|
|
60
|
+
"glob": "^7.1.6",
|
|
61
|
+
"inquirer": "^7.3.3",
|
|
62
|
+
"is-docker": "^2.1.1",
|
|
63
|
+
"lodash": "^4.17.20",
|
|
64
|
+
"markdownlint": "^0.25.1",
|
|
65
|
+
"markdownlint-rule-helpers": "^0.13.0",
|
|
66
|
+
"ora": "^5.1.0",
|
|
67
|
+
"prettier": "^2.2.1",
|
|
68
|
+
"strip-ansi": "^6.0.0",
|
|
69
|
+
"stylelint": "^14.3.0",
|
|
70
|
+
"stylelint-scss": "^4.1.0",
|
|
71
|
+
"terminal-link": "^2.1.1",
|
|
72
|
+
"text-table": "^0.2.0",
|
|
73
|
+
"vue-eslint-parser": "^7.3.0",
|
|
74
|
+
"@qiangzaifan/commitlint-config-encode": "^1.0.0",
|
|
75
|
+
"@qiangzaifan/eslint-config-encode": "^1.0.0",
|
|
76
|
+
"@qiangzaifan/markdownlint-config-encode": "^1.0.0",
|
|
77
|
+
"@qiangzaifan/stylelint-config-encode": "^1.0.0"
|
|
78
|
+
},
|
|
79
|
+
"author": "chenghuai",
|
|
80
|
+
"homepage": "https://github.com/qiangzaiFan/fe-spec-project#readme",
|
|
81
|
+
"license": "MIT",
|
|
82
|
+
"repository": {
|
|
83
|
+
"type": "git",
|
|
84
|
+
"url": "git+https://github.com/qiangzaiFan/fe-spec-project.git"
|
|
85
|
+
},
|
|
86
|
+
"bugs": {
|
|
87
|
+
"url": "https://github.com/qiangzaiFan/fe-spec-project/issues"
|
|
88
|
+
},
|
|
89
|
+
"publishConfig": {
|
|
90
|
+
"access": "public",
|
|
91
|
+
"registry": "https://registry.npmjs.org/"
|
|
92
|
+
},
|
|
93
|
+
"scripts": {
|
|
94
|
+
"dev": "npm run copyfiles && tsc -w",
|
|
95
|
+
"build": "rm -rf lib && npm run copyfiles && tsc",
|
|
96
|
+
"copyfiles": "copyfiles -a -u 1 \"src/config/**\" lib",
|
|
97
|
+
"test": "npm run build && jest",
|
|
98
|
+
"coverage": "nyc jest --silent --forceExit"
|
|
99
|
+
}
|
|
6
100
|
}
|