@huangjunsen/encode-fe-lint 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/init.d.ts +3 -3
- package/lib/actions/init.js +151 -223
- package/lib/actions/scan.d.ts +3 -3
- package/lib/actions/scan.js +60 -137
- package/lib/actions/update.d.ts +2 -2
- package/lib/actions/update.js +51 -112
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +145 -230
- package/lib/config/_editorconfig.ejs +13 -13
- package/lib/config/_eslintignore.ejs +9 -9
- package/lib/config/_eslintrc.js.ejs +21 -3
- package/lib/config/_markdownlint.json.ejs +1 -1
- package/lib/config/_markdownlintignore.ejs +5 -5
- package/lib/config/_prettierrc.js.ejs +3 -8
- package/lib/config/_stylelintignore.ejs +5 -5
- package/lib/config/_stylelintrc.js.ejs +5 -5
- package/lib/config/_vscode/extensions.json.ejs +7 -7
- package/lib/config/_vscode/settings.json.ejs +55 -54
- package/lib/config/commitlint.config.js.ejs +3 -3
- package/lib/config/encode-fe-lint.config.js.ejs +6 -6
- package/lib/config/eslint.config.mjs.ejs +5 -0
- package/lib/index.d.ts +5 -5
- package/lib/index.js +36 -93
- package/lib/lints/eslint/doEslint.d.ts +6 -6
- package/lib/lints/eslint/doEslint.js +44 -80
- package/lib/lints/eslint/formatESLintResults.d.ts +3 -3
- package/lib/lints/eslint/formatESLintResults.js +28 -39
- package/lib/lints/eslint/getESLintConfig.d.ts +3 -3
- package/lib/lints/eslint/getESLintConfig.js +43 -67
- package/lib/lints/eslint/getESLintConfigType.d.ts +2 -2
- package/lib/lints/eslint/getESLintConfigType.js +23 -26
- package/lib/lints/eslint/index.d.ts +3 -3
- package/lib/lints/eslint/index.js +19 -19
- package/lib/lints/index.d.ts +4 -4
- package/lib/lints/index.js +20 -20
- package/lib/lints/markdownlint/doMarkdownlint.d.ts +6 -6
- package/lib/lints/markdownlint/doMarkdownlint.js +52 -119
- package/lib/lints/markdownlint/formatMarkdownlintResults.d.ts +3 -3
- package/lib/lints/markdownlint/formatMarkdownlintResults.js +35 -39
- package/lib/lints/markdownlint/getMarkdownlintConfig.d.ts +7 -7
- package/lib/lints/markdownlint/getMarkdownlintConfig.js +31 -31
- package/lib/lints/markdownlint/index.d.ts +3 -3
- package/lib/lints/markdownlint/index.js +19 -19
- package/lib/lints/prettier/doPrettier.d.ts +4 -4
- package/lib/lints/prettier/doPrettier.js +32 -106
- package/lib/lints/prettier/index.d.ts +1 -1
- package/lib/lints/prettier/index.js +17 -17
- package/lib/lints/stylelint/doStylelint.d.ts +5 -5
- package/lib/lints/stylelint/doStylelint.js +31 -86
- package/lib/lints/stylelint/formatStylelintResults.d.ts +3 -3
- package/lib/lints/stylelint/formatStylelintResults.js +38 -39
- package/lib/lints/stylelint/getStylelintConfig.d.ts +3 -3
- package/lib/lints/stylelint/getStylelintConfig.js +36 -36
- package/lib/lints/stylelint/getStylelintDocUrl.d.ts +1 -1
- package/lib/lints/stylelint/getStylelintDocUrl.js +13 -13
- package/lib/lints/stylelint/index.d.ts +3 -3
- package/lib/lints/stylelint/index.js +19 -19
- package/lib/types/index.d.ts +73 -73
- package/lib/types/index.js +2 -2
- package/lib/utils/conflict-resolve.d.ts +3 -3
- package/lib/utils/conflict-resolve.js +95 -175
- package/lib/utils/constants.d.ts +18 -18
- package/lib/utils/constants.js +104 -133
- package/lib/utils/generate-template.d.ts +2 -2
- package/lib/utils/generate-template.js +53 -99
- package/lib/utils/git.d.ts +3 -3
- package/lib/utils/git.js +44 -105
- package/lib/utils/log.d.ts +8 -8
- package/lib/utils/log.js +25 -25
- package/lib/utils/npm-type.d.ts +2 -2
- package/lib/utils/npm-type.js +10 -10
- package/lib/utils/print-report.d.ts +3 -3
- package/lib/utils/print-report.js +86 -109
- package/package.json +13 -8
- package/lib/utils/update.d.ts +0 -2
- package/lib/utils/update.js +0 -112
package/lib/types/index.d.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { ESLint } from 'eslint';
|
|
2
|
-
import stylelint from 'stylelint';
|
|
3
|
-
import markdownlint from 'markdownlint';
|
|
4
|
-
export interface PKG {
|
|
5
|
-
eslintConfig?: any;
|
|
6
|
-
eslintIgnore?: string[];
|
|
7
|
-
stylelint?: any;
|
|
8
|
-
peerDependencies?: Record<string, string>;
|
|
9
|
-
devDependencies?: Record<string, string>;
|
|
10
|
-
dependencies?: Record<string, string>;
|
|
11
|
-
[key: string]: any;
|
|
12
|
-
}
|
|
13
|
-
export interface Config {
|
|
14
|
-
enableESLint?: boolean;
|
|
15
|
-
enableStylelint?: boolean;
|
|
16
|
-
enableMarkdownlint?: boolean;
|
|
17
|
-
enablePrettier?: boolean;
|
|
18
|
-
eslintOptions?: ESLint.Options;
|
|
19
|
-
stylelintOptions?: stylelint.LinterOptions;
|
|
20
|
-
markdownlintOptions?: markdownlint.Options;
|
|
21
|
-
}
|
|
22
|
-
export interface ScanOptions {
|
|
23
|
-
cwd: string;
|
|
24
|
-
include: string;
|
|
25
|
-
files?: string[];
|
|
26
|
-
quiet?: boolean;
|
|
27
|
-
ignore?: boolean;
|
|
28
|
-
fix?: boolean;
|
|
29
|
-
outputReport?: boolean;
|
|
30
|
-
config?: Config;
|
|
31
|
-
}
|
|
32
|
-
export interface ScanResult {
|
|
33
|
-
filePath: string;
|
|
34
|
-
errorCount: number;
|
|
35
|
-
warningCount: number;
|
|
36
|
-
fixableErrorCount: number;
|
|
37
|
-
fixableWarningCount: number;
|
|
38
|
-
messages: Array<{
|
|
39
|
-
line: number;
|
|
40
|
-
column: number;
|
|
41
|
-
rule: string;
|
|
42
|
-
url: string;
|
|
43
|
-
message: string;
|
|
44
|
-
errored: boolean;
|
|
45
|
-
}>;
|
|
46
|
-
}
|
|
47
|
-
export interface ScanReport {
|
|
48
|
-
results: ScanResult[];
|
|
49
|
-
errorCount: number;
|
|
50
|
-
warningCount: number;
|
|
51
|
-
runErrors: Error[];
|
|
52
|
-
}
|
|
53
|
-
export interface InitOptions {
|
|
54
|
-
cwd: string;
|
|
55
|
-
checkVersionUpdate: boolean;
|
|
56
|
-
rewriteConfig?: boolean;
|
|
57
|
-
eslintType?: string;
|
|
58
|
-
enableESLint?: boolean;
|
|
59
|
-
enableStylelint?: boolean;
|
|
60
|
-
enableMarkdownlint?: boolean;
|
|
61
|
-
enablePrettier?: boolean;
|
|
62
|
-
disableNpmInstall?: boolean;
|
|
63
|
-
}
|
|
64
|
-
export interface IGetLintConfig {
|
|
65
|
-
(options: ScanOptions, pkg: PKG, config: Config): ESLint.Options;
|
|
66
|
-
(options: ScanOptions, pkg: PKG, config: Config): stylelint.LinterOptions;
|
|
67
|
-
(options: ScanOptions, pkg: PKG, config: Config): markdownlint.Options;
|
|
68
|
-
}
|
|
69
|
-
export interface IFormatResults {
|
|
70
|
-
(results: ESLint.LintResult[], quiet: boolean): ScanResult[];
|
|
71
|
-
(results: stylelint.LintResult[], quiet: boolean): ScanResult[];
|
|
72
|
-
(results: markdownlint.LintResults, quiet: boolean): ScanResult[];
|
|
73
|
-
}
|
|
1
|
+
import { ESLint } from 'eslint';
|
|
2
|
+
import stylelint from 'stylelint';
|
|
3
|
+
import markdownlint from 'markdownlint';
|
|
4
|
+
export interface PKG {
|
|
5
|
+
eslintConfig?: any;
|
|
6
|
+
eslintIgnore?: string[];
|
|
7
|
+
stylelint?: any;
|
|
8
|
+
peerDependencies?: Record<string, string>;
|
|
9
|
+
devDependencies?: Record<string, string>;
|
|
10
|
+
dependencies?: Record<string, string>;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
export interface Config {
|
|
14
|
+
enableESLint?: boolean;
|
|
15
|
+
enableStylelint?: boolean;
|
|
16
|
+
enableMarkdownlint?: boolean;
|
|
17
|
+
enablePrettier?: boolean;
|
|
18
|
+
eslintOptions?: ESLint.Options;
|
|
19
|
+
stylelintOptions?: stylelint.LinterOptions;
|
|
20
|
+
markdownlintOptions?: markdownlint.Options;
|
|
21
|
+
}
|
|
22
|
+
export interface ScanOptions {
|
|
23
|
+
cwd: string;
|
|
24
|
+
include: string;
|
|
25
|
+
files?: string[];
|
|
26
|
+
quiet?: boolean;
|
|
27
|
+
ignore?: boolean;
|
|
28
|
+
fix?: boolean;
|
|
29
|
+
outputReport?: boolean;
|
|
30
|
+
config?: Config;
|
|
31
|
+
}
|
|
32
|
+
export interface ScanResult {
|
|
33
|
+
filePath: string;
|
|
34
|
+
errorCount: number;
|
|
35
|
+
warningCount: number;
|
|
36
|
+
fixableErrorCount: number;
|
|
37
|
+
fixableWarningCount: number;
|
|
38
|
+
messages: Array<{
|
|
39
|
+
line: number;
|
|
40
|
+
column: number;
|
|
41
|
+
rule: string;
|
|
42
|
+
url: string;
|
|
43
|
+
message: string;
|
|
44
|
+
errored: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export interface ScanReport {
|
|
48
|
+
results: ScanResult[];
|
|
49
|
+
errorCount: number;
|
|
50
|
+
warningCount: number;
|
|
51
|
+
runErrors: Error[];
|
|
52
|
+
}
|
|
53
|
+
export interface InitOptions {
|
|
54
|
+
cwd: string;
|
|
55
|
+
checkVersionUpdate: boolean;
|
|
56
|
+
rewriteConfig?: boolean;
|
|
57
|
+
eslintType?: string;
|
|
58
|
+
enableESLint?: boolean;
|
|
59
|
+
enableStylelint?: boolean;
|
|
60
|
+
enableMarkdownlint?: boolean;
|
|
61
|
+
enablePrettier?: boolean;
|
|
62
|
+
disableNpmInstall?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface IGetLintConfig {
|
|
65
|
+
(options: ScanOptions, pkg: PKG, config: Config): ESLint.Options;
|
|
66
|
+
(options: ScanOptions, pkg: PKG, config: Config): stylelint.LinterOptions;
|
|
67
|
+
(options: ScanOptions, pkg: PKG, config: Config): markdownlint.Options;
|
|
68
|
+
}
|
|
69
|
+
export interface IFormatResults {
|
|
70
|
+
(results: ESLint.LintResult[], quiet: boolean): ScanResult[];
|
|
71
|
+
(results: stylelint.LintResult[], quiet: boolean): ScanResult[];
|
|
72
|
+
(results: markdownlint.LintResults, quiet: boolean): ScanResult[];
|
|
73
|
+
}
|
package/lib/types/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { PKG } from '../types';
|
|
2
|
-
declare const _default: (cwd: string, rewriteConfig?: boolean) => Promise<PKG>;
|
|
3
|
-
export default _default;
|
|
1
|
+
import type { PKG } from '../types';
|
|
2
|
+
declare const _default: (cwd: string, rewriteConfig?: boolean) => Promise<PKG>;
|
|
3
|
+
export default _default;
|
|
@@ -1,175 +1,95 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var e_1, _a, e_2, _b;
|
|
97
|
-
return __generator(this, function (_c) {
|
|
98
|
-
switch (_c.label) {
|
|
99
|
-
case 0:
|
|
100
|
-
pkgPath = path_1.default.resolve(cwd, 'package.json');
|
|
101
|
-
pkg = fs_extra_1.default.readJSONSync(pkgPath);
|
|
102
|
-
dependencies = [].concat(Object.keys(pkg.dependencies || {}), Object.keys(pkg.devDependencies || []));
|
|
103
|
-
willRemovePackage = dependencies.filter(function (name) {
|
|
104
|
-
return packageNamesToRemove.includes(name) ||
|
|
105
|
-
packagePrefixesToRemove.some(function (prefix) { return name.startsWith(prefix); });
|
|
106
|
-
});
|
|
107
|
-
uselessConfig = checkUselessConfig(cwd);
|
|
108
|
-
reWriteConfig = checkReWriteConfig(cwd);
|
|
109
|
-
willChangeCount = willRemovePackage.length + uselessConfig.length + reWriteConfig.length;
|
|
110
|
-
if (!(willChangeCount > 0)) return [3, 3];
|
|
111
|
-
log_1.default.warn("\u68C0\u6D4B\u5230\u9879\u76EE\u4E2D\u5B58\u5728\u53EF\u80FD\u4E0E ".concat(constants_1.PKG_NAME, " \u51B2\u7A81\u7684\u4F9D\u8D56\u548C\u914D\u7F6E\uFF0C\u4E3A\u4FDD\u8BC1\u6B63\u5E38\u8FD0\u884C\u5C06"));
|
|
112
|
-
if (willRemovePackage.length > 0) {
|
|
113
|
-
log_1.default.warn('删除以下依赖:');
|
|
114
|
-
log_1.default.warn(JSON.stringify(willRemovePackage, null, 2));
|
|
115
|
-
}
|
|
116
|
-
if (uselessConfig.length > 0) {
|
|
117
|
-
log_1.default.warn('删除以下配置文件:');
|
|
118
|
-
log_1.default.warn(JSON.stringify(uselessConfig, null, 2));
|
|
119
|
-
}
|
|
120
|
-
if (reWriteConfig.length > 0) {
|
|
121
|
-
log_1.default.warn('覆盖以下配置文件:');
|
|
122
|
-
log_1.default.warn(JSON.stringify(reWriteConfig, null, 2));
|
|
123
|
-
}
|
|
124
|
-
if (!(typeof rewriteConfig === 'undefined')) return [3, 2];
|
|
125
|
-
return [4, inquirer_1.default.prompt({
|
|
126
|
-
type: 'confirm',
|
|
127
|
-
name: 'isOverWrite',
|
|
128
|
-
message: '请确认是否继续:',
|
|
129
|
-
})];
|
|
130
|
-
case 1:
|
|
131
|
-
isOverWrite = (_c.sent()).isOverWrite;
|
|
132
|
-
if (!isOverWrite)
|
|
133
|
-
process.exit(0);
|
|
134
|
-
return [3, 3];
|
|
135
|
-
case 2:
|
|
136
|
-
if (!reWriteConfig) {
|
|
137
|
-
process.exit(0);
|
|
138
|
-
}
|
|
139
|
-
_c.label = 3;
|
|
140
|
-
case 3:
|
|
141
|
-
try {
|
|
142
|
-
for (uselessConfig_1 = __values(uselessConfig), uselessConfig_1_1 = uselessConfig_1.next(); !uselessConfig_1_1.done; uselessConfig_1_1 = uselessConfig_1.next()) {
|
|
143
|
-
name_1 = uselessConfig_1_1.value;
|
|
144
|
-
fs_extra_1.default.removeSync(path_1.default.resolve(cwd, name_1));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
148
|
-
finally {
|
|
149
|
-
try {
|
|
150
|
-
if (uselessConfig_1_1 && !uselessConfig_1_1.done && (_a = uselessConfig_1.return)) _a.call(uselessConfig_1);
|
|
151
|
-
}
|
|
152
|
-
finally { if (e_1) throw e_1.error; }
|
|
153
|
-
}
|
|
154
|
-
delete pkg.eslintConfig;
|
|
155
|
-
delete pkg.eslintIgnore;
|
|
156
|
-
delete pkg.stylelint;
|
|
157
|
-
try {
|
|
158
|
-
for (willRemovePackage_1 = __values(willRemovePackage), willRemovePackage_1_1 = willRemovePackage_1.next(); !willRemovePackage_1_1.done; willRemovePackage_1_1 = willRemovePackage_1.next()) {
|
|
159
|
-
name_2 = willRemovePackage_1_1.value;
|
|
160
|
-
delete (pkg.dependencies || {})[name_2];
|
|
161
|
-
delete (pkg.devDependencies || {})[name_2];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
165
|
-
finally {
|
|
166
|
-
try {
|
|
167
|
-
if (willRemovePackage_1_1 && !willRemovePackage_1_1.done && (_b = willRemovePackage_1.return)) _b.call(willRemovePackage_1);
|
|
168
|
-
}
|
|
169
|
-
finally { if (e_2) throw e_2.error; }
|
|
170
|
-
}
|
|
171
|
-
fs_extra_1.default.writeFileSync(path_1.default.resolve(cwd, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
|
|
172
|
-
return [2, pkg];
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}); });
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
|
+
const glob_1 = __importDefault(require("glob"));
|
|
9
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
+
const log_1 = __importDefault(require("./log"));
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const packageNamesToRemove = [
|
|
13
|
+
'@babel/eslint-parser',
|
|
14
|
+
'@commitlint/cli',
|
|
15
|
+
'@iceworks/spec',
|
|
16
|
+
'babel-eslint',
|
|
17
|
+
'eslint',
|
|
18
|
+
'husky',
|
|
19
|
+
'markdownlint',
|
|
20
|
+
'prettier',
|
|
21
|
+
'stylelint',
|
|
22
|
+
'tslint',
|
|
23
|
+
];
|
|
24
|
+
const packagePrefixesToRemove = [
|
|
25
|
+
'@commitlint/',
|
|
26
|
+
'@typescript-eslint/',
|
|
27
|
+
'eslint-',
|
|
28
|
+
'stylelint-',
|
|
29
|
+
'markdownlint-',
|
|
30
|
+
'commitlint-',
|
|
31
|
+
];
|
|
32
|
+
const checkUselessConfig = (cwd) => {
|
|
33
|
+
return []
|
|
34
|
+
.concat(glob_1.default.sync('.eslintrc?(.@(yaml|yml|json))', { cwd }))
|
|
35
|
+
.concat(glob_1.default.sync('.stylelintrc?(.@(yaml|yml|json))', { cwd }))
|
|
36
|
+
.concat(glob_1.default.sync('.markdownlint@(rc|.@(yaml|yml|jsonc))', { cwd }))
|
|
37
|
+
.concat(glob_1.default.sync('.prettierrc?(.@(cjs|config.js|config.cjs|yaml|yml|json|json5|toml))', { cwd }))
|
|
38
|
+
.concat(glob_1.default.sync('tslint.@(yaml|yml|json)', { cwd }))
|
|
39
|
+
.concat(glob_1.default.sync('.kylerc?(.@(yaml|yml|json))', { cwd }));
|
|
40
|
+
};
|
|
41
|
+
const checkReWriteConfig = (cwd) => {
|
|
42
|
+
return glob_1.default
|
|
43
|
+
.sync('**/*.ejs', { cwd: path_1.default.resolve(__dirname, '../config') })
|
|
44
|
+
.map((name) => name.replace(/^_/, '.').replace(/\.ejs$/, ''))
|
|
45
|
+
.filter((filename) => fs_extra_1.default.existsSync(path_1.default.resolve(cwd, filename)));
|
|
46
|
+
};
|
|
47
|
+
exports.default = async (cwd, rewriteConfig) => {
|
|
48
|
+
const pkgPath = path_1.default.resolve(cwd, 'package.json');
|
|
49
|
+
const pkg = fs_extra_1.default.readJSONSync(pkgPath);
|
|
50
|
+
const dependencies = [].concat(Object.keys(pkg.dependencies || {}), Object.keys(pkg.devDependencies || []));
|
|
51
|
+
const willRemovePackage = dependencies.filter((name) => packageNamesToRemove.includes(name) ||
|
|
52
|
+
packagePrefixesToRemove.some((prefix) => name.startsWith(prefix)));
|
|
53
|
+
const uselessConfig = checkUselessConfig(cwd);
|
|
54
|
+
const reWriteConfig = checkReWriteConfig(cwd);
|
|
55
|
+
const willChangeCount = willRemovePackage.length + uselessConfig.length + reWriteConfig.length;
|
|
56
|
+
if (willChangeCount > 0) {
|
|
57
|
+
log_1.default.warn(`检测到项目中存在可能与 ${constants_1.PKG_NAME} 冲突的依赖和配置,为保证正常运行将`);
|
|
58
|
+
if (willRemovePackage.length > 0) {
|
|
59
|
+
log_1.default.warn('删除以下依赖:');
|
|
60
|
+
log_1.default.warn(JSON.stringify(willRemovePackage, null, 2));
|
|
61
|
+
}
|
|
62
|
+
if (uselessConfig.length > 0) {
|
|
63
|
+
log_1.default.warn('删除以下配置文件:');
|
|
64
|
+
log_1.default.warn(JSON.stringify(uselessConfig, null, 2));
|
|
65
|
+
}
|
|
66
|
+
if (reWriteConfig.length > 0) {
|
|
67
|
+
log_1.default.warn('覆盖以下配置文件:');
|
|
68
|
+
log_1.default.warn(JSON.stringify(reWriteConfig, null, 2));
|
|
69
|
+
}
|
|
70
|
+
if (typeof rewriteConfig === 'undefined') {
|
|
71
|
+
const { isOverWrite } = await inquirer_1.default.prompt({
|
|
72
|
+
type: 'confirm',
|
|
73
|
+
name: 'isOverWrite',
|
|
74
|
+
message: '请确认是否继续:',
|
|
75
|
+
});
|
|
76
|
+
if (!isOverWrite)
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
else if (!reWriteConfig) {
|
|
80
|
+
process.exit(0);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const name of uselessConfig) {
|
|
84
|
+
fs_extra_1.default.removeSync(path_1.default.resolve(cwd, name));
|
|
85
|
+
}
|
|
86
|
+
delete pkg.eslintConfig;
|
|
87
|
+
delete pkg.eslintIgnore;
|
|
88
|
+
delete pkg.stylelint;
|
|
89
|
+
for (const name of willRemovePackage) {
|
|
90
|
+
delete (pkg.dependencies || {})[name];
|
|
91
|
+
delete (pkg.devDependencies || {})[name];
|
|
92
|
+
}
|
|
93
|
+
fs_extra_1.default.writeFileSync(path_1.default.resolve(cwd, 'package.json'), JSON.stringify(pkg, null, 2), 'utf8');
|
|
94
|
+
return pkg;
|
|
95
|
+
};
|
package/lib/utils/constants.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export declare enum UNICODE {
|
|
2
|
-
success = "\u2714",
|
|
3
|
-
failure = "\u2716"
|
|
4
|
-
}
|
|
5
|
-
export declare const PKG_NAME: string;
|
|
6
|
-
export declare const PKG_VERSION: string;
|
|
7
|
-
export declare const PROJECT_TYPES: Array<{
|
|
8
|
-
name: string;
|
|
9
|
-
value: string;
|
|
10
|
-
}>;
|
|
11
|
-
export declare const ESLINT_FILE_EXT: string[];
|
|
12
|
-
export declare const ESLINT_IGNORE_PATTERN: string[];
|
|
13
|
-
export declare const STYLELINT_FILE_EXT: string[];
|
|
14
|
-
export declare const STYLELINT_IGNORE_PATTERN: string[];
|
|
15
|
-
export declare const MARKDOWN_LINT_FILE_EXT: string[];
|
|
16
|
-
export declare const MARKDOWN_LINT_IGNORE_PATTERN: string[];
|
|
17
|
-
export declare const PRETTIER_FILE_EXT: string[];
|
|
18
|
-
export declare const PRETTIER_IGNORE_PATTERN: string[];
|
|
1
|
+
export declare enum UNICODE {
|
|
2
|
+
success = "\u2714",
|
|
3
|
+
failure = "\u2716"
|
|
4
|
+
}
|
|
5
|
+
export declare const PKG_NAME: string;
|
|
6
|
+
export declare const PKG_VERSION: string;
|
|
7
|
+
export declare const PROJECT_TYPES: Array<{
|
|
8
|
+
name: string;
|
|
9
|
+
value: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const ESLINT_FILE_EXT: string[];
|
|
12
|
+
export declare const ESLINT_IGNORE_PATTERN: string[];
|
|
13
|
+
export declare const STYLELINT_FILE_EXT: string[];
|
|
14
|
+
export declare const STYLELINT_IGNORE_PATTERN: string[];
|
|
15
|
+
export declare const MARKDOWN_LINT_FILE_EXT: string[];
|
|
16
|
+
export declare const MARKDOWN_LINT_IGNORE_PATTERN: string[];
|
|
17
|
+
export declare const PRETTIER_FILE_EXT: string[];
|
|
18
|
+
export declare const PRETTIER_IGNORE_PATTERN: string[];
|