@huangjunsen/encode-fe-lint 1.0.3 → 1.0.5
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.js +4 -4
- package/lib/cli.js +0 -0
- package/package.json +2 -4
- package/lib/utils/init.d.ts +0 -3
- package/lib/utils/init.js +0 -223
package/lib/actions/init.js
CHANGED
|
@@ -198,18 +198,18 @@ exports.default = (function (options) { return __awaiter(void 0, void 0, void 0,
|
|
|
198
198
|
pkg.scripts = {};
|
|
199
199
|
}
|
|
200
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");
|
|
201
|
+
pkg.scripts["".concat(constants_1.PKG_NAME.split("/").pop(), "-scan")] = "".concat(constants_1.PKG_NAME.split("/").pop(), " scan");
|
|
202
202
|
}
|
|
203
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");
|
|
204
|
+
pkg.scripts["".concat(constants_1.PKG_NAME.split("/").pop(), "-fix")] = "".concat(constants_1.PKG_NAME.split("/").pop(), " fix");
|
|
205
205
|
}
|
|
206
206
|
log_1.default.info("Step ".concat(++step, ". \u914D\u7F6E git commit \u5361\u70B9"));
|
|
207
207
|
if (!pkg.husky)
|
|
208
208
|
pkg.husky = {};
|
|
209
209
|
if (!pkg.husky.hooks)
|
|
210
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");
|
|
211
|
+
pkg.husky.hooks['pre-commit'] = "".concat(constants_1.PKG_NAME.split("/").pop(), " commit-file-scan");
|
|
212
|
+
pkg.husky.hooks['commit-msg'] = "".concat(constants_1.PKG_NAME.split("/").pop(), " commit-msg-scan");
|
|
213
213
|
fs_extra_1.default.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
214
214
|
log_1.default.success("Step ".concat(step, ". \u914D\u7F6E git commit \u5361\u70B9\u6210\u529F :D"));
|
|
215
215
|
log_1.default.info("Step ".concat(++step, ". \u5199\u5165\u914D\u7F6E\u6587\u4EF6"));
|
package/lib/cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huangjunsen/encode-fe-lint",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "前端编码规范工程化标准脚手架",
|
|
5
|
-
"bin":
|
|
6
|
-
"@huangjunsen/encode-fe-lint": "./lib/cli.js"
|
|
7
|
-
},
|
|
5
|
+
"bin": "./lib/cli.js",
|
|
8
6
|
"main": "./lib/index.js",
|
|
9
7
|
"files": [
|
|
10
8
|
"lib/"
|
package/lib/utils/init.d.ts
DELETED
package/lib/utils/init.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
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
|
-
}); });
|