@baic/yolk-cli 2.0.0-beta.1 → 2.0.1-alpha.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/README.md CHANGED
@@ -1,4 +1,10 @@
1
- #### Yolk 脚手架
1
+ # @baic/yolk-cli
2
+
3
+ ## 安装脚手架
4
+
5
+ ```shell
6
+ $ npm install -g @baic/yolk-cli
7
+ ```
2
8
 
3
9
  ## 初始化项目
4
10
 
@@ -32,4 +38,6 @@ $ yolk build
32
38
 
33
39
  | 参数 | 说明 | 类型 | 默认值 |
34
40
  | :------: | :----------: | :----: | :----: |
35
- | eslintIgnore | 忽略commit时eslint代码检查 | string \| RegExp \| array | - |
41
+ | eslintIgnore | 忽略commit时eslint代码检查,符合glob语法 | string \| RegExp \| array | - |
42
+ | stylelintIgnore | 忽略commit时stylelint代码检查,符合glob语法 | string \| RegExp \| array | - |
43
+ | strict | 严格模式,关闭以后使用项目定义的eslint规则进行提交检查 | boolean | - |
File without changes
package/bin/index.js ADDED
@@ -0,0 +1,665 @@
1
+ #! /usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ function _typeof(e) {
6
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
7
+ return typeof e
8
+ } : function (e) {
9
+ return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
10
+ }, _typeof(e)
11
+ }
12
+ var _isString2 = _interopRequireDefault(require("lodash/isString")),
13
+ _pick2 = _interopRequireDefault(require("lodash/pick")),
14
+ _chunk2 = _interopRequireDefault(require("lodash/chunk")),
15
+ _fs = _interopRequireDefault(require("fs")),
16
+ _path = _interopRequireDefault(require("path")),
17
+ _os = _interopRequireDefault(require("os")),
18
+ _commander = _interopRequireDefault(require("commander")),
19
+ _inquirer = _interopRequireDefault(require("inquirer")),
20
+ _child_process = require("child_process"),
21
+ _ora = _interopRequireDefault(require("ora")),
22
+ _glob = _interopRequireDefault(require("glob")),
23
+ _minimatch = _interopRequireDefault(require("minimatch")),
24
+ _mustache = _interopRequireDefault(require("mustache")),
25
+ _mkdirp = _interopRequireDefault(require("mkdirp")),
26
+ _rimraf = _interopRequireDefault(require("rimraf")),
27
+ _prettier = require("prettier"),
28
+ miniProgramCi = _interopRequireWildcard(require("miniprogram-ci")),
29
+ _package = _interopRequireDefault(require("../package.json"));
30
+
31
+ function _getRequireWildcardCache(e) {
32
+ if ("function" !== typeof WeakMap) return null;
33
+ var t = new WeakMap,
34
+ r = new WeakMap;
35
+ return (_getRequireWildcardCache = function (e) {
36
+ return e ? r : t
37
+ })(e)
38
+ }
39
+
40
+ function _interopRequireWildcard(e, t) {
41
+ if (!t && e && e.__esModule) return e;
42
+ if (null === e || "object" !== _typeof(e) && "function" !== typeof e) return {
43
+ default: e
44
+ };
45
+ var r = _getRequireWildcardCache(t);
46
+ if (r && r.has(e)) return r.get(e);
47
+ var n = {},
48
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
49
+ for (var i in e)
50
+ if ("default" !== i && Object.prototype.hasOwnProperty.call(e, i)) {
51
+ var o = a ? Object.getOwnPropertyDescriptor(e, i) : null;
52
+ o && (o.get || o.set) ? Object.defineProperty(n, i, o) : n[i] = e[i]
53
+ } return n["default"] = e, r && r.set(e, n), n
54
+ }
55
+
56
+ function _interopRequireDefault(e) {
57
+ return e && e.__esModule ? e : {
58
+ default: e
59
+ }
60
+ }
61
+
62
+ function _toArray(e) {
63
+ return _arrayWithHoles(e) || _iterableToArray(e) || _unsupportedIterableToArray(e) || _nonIterableRest()
64
+ }
65
+
66
+ function _nonIterableRest() {
67
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
68
+ }
69
+
70
+ function _arrayWithHoles(e) {
71
+ if (Array.isArray(e)) return e
72
+ }
73
+
74
+ function ownKeys(e, t) {
75
+ var r = Object.keys(e);
76
+ if (Object.getOwnPropertySymbols) {
77
+ var n = Object.getOwnPropertySymbols(e);
78
+ t && (n = n.filter((function (t) {
79
+ return Object.getOwnPropertyDescriptor(e, t).enumerable
80
+ }))), r.push.apply(r, n)
81
+ }
82
+ return r
83
+ }
84
+
85
+ function _objectSpread(e) {
86
+ for (var t = 1; t < arguments.length; t++) {
87
+ var r = null != arguments[t] ? arguments[t] : {};
88
+ t % 2 ? ownKeys(Object(r), !0).forEach((function (t) {
89
+ _defineProperty(e, t, r[t])
90
+ })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ownKeys(Object(r)).forEach((function (t) {
91
+ Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(r, t))
92
+ }))
93
+ }
94
+ return e
95
+ }
96
+
97
+ function _defineProperty(e, t, r) {
98
+ return t in e ? Object.defineProperty(e, t, {
99
+ value: r,
100
+ enumerable: !0,
101
+ configurable: !0,
102
+ writable: !0
103
+ }) : e[t] = r, e
104
+ }
105
+
106
+ function _toConsumableArray(e) {
107
+ return _arrayWithoutHoles(e) || _iterableToArray(e) || _unsupportedIterableToArray(e) || _nonIterableSpread()
108
+ }
109
+
110
+ function _nonIterableSpread() {
111
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")
112
+ }
113
+
114
+ function _unsupportedIterableToArray(e, t) {
115
+ if (e) {
116
+ if ("string" === typeof e) return _arrayLikeToArray(e, t);
117
+ var r = Object.prototype.toString.call(e).slice(8, -1);
118
+ return "Object" === r && e.constructor && (r = e.constructor.name), "Map" === r || "Set" === r ? Array.from(e) : "Arguments" === r || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? _arrayLikeToArray(e, t) : void 0
119
+ }
120
+ }
121
+
122
+ function _iterableToArray(e) {
123
+ if ("undefined" !== typeof Symbol && null != e[Symbol.iterator] || null != e["@@iterator"]) return Array.from(e)
124
+ }
125
+
126
+ function _arrayWithoutHoles(e) {
127
+ if (Array.isArray(e)) return _arrayLikeToArray(e)
128
+ }
129
+
130
+ function _arrayLikeToArray(e, t) {
131
+ (null == t || t > e.length) && (t = e.length);
132
+ for (var r = 0, n = new Array(t); r < t; r++) n[r] = e[r];
133
+ return n
134
+ }
135
+ var sgf = require("staged-git-files"),
136
+ cwd = process.cwd(),
137
+ HOOK_MARK = "##### CREATED BY YOLK #####",
138
+ PRETTIER_PARSER = {
139
+ ts: "typescript",
140
+ tsx: "typescript"
141
+ },
142
+ ENCODING = "utf-8",
143
+ MAX_FILE_COUNT = 60,
144
+ spinner = (0, _ora["default"])(),
145
+ warn = function (e) {
146
+ return e && spinner.warn(Buffer.from(e, ENCODING).toString())
147
+ },
148
+ fail = function (e) {
149
+ return e && spinner.fail(Buffer.from(e, ENCODING).toString())
150
+ },
151
+ succeed = function (e) {
152
+ return e && spinner.succeed(Buffer.from(e, ENCODING).toString())
153
+ },
154
+ info = function (e) {
155
+ return e && spinner.info(Buffer.from(e, ENCODING).toString())
156
+ },
157
+ getCommand = function (e) {
158
+ return "win32" === process.platform ? "".concat(e, ".cmd") : e
159
+ },
160
+ completeExit = function () {
161
+ succeed("yolk complete!"), process.exit(0)
162
+ },
163
+ breakExit = function () {
164
+ warn("yolk break!"), process.exit(0)
165
+ },
166
+ execCommand = function (e) {
167
+ var t = e.command,
168
+ r = e.args,
169
+ n = e.complete,
170
+ a = e.close,
171
+ i = e.exit,
172
+ o = void 0 === i || i,
173
+ c = (0, _child_process.spawn)(getCommand(t), r || [], {
174
+ stdio: "inherit"
175
+ }).on("close", (function (e) {
176
+ e ? (a && a(), fail("yolk close!"), process.exit(e)) : (n && n(), o && completeExit())
177
+ }));
178
+ process.on("SIGINT", (function () {
179
+ _commander["default"].runningCommand && _commander["default"].runningCommand.kill("SIGKILL"), c.kill(), breakExit()
180
+ }))
181
+ },
182
+ createTemplate = function (e, t, r) {
183
+ _inquirer["default"].prompt([{
184
+ type: "list",
185
+ name: "type",
186
+ message: "\u9009\u62e9\u5e73\u53f0",
187
+ default: "web",
188
+ choices: [{
189
+ name: "web",
190
+ value: "web"
191
+ }, {
192
+ name: "mobile",
193
+ value: "mobile"
194
+ }, {
195
+ name: "\u5c0f\u7a0b\u5e8f",
196
+ value: "miniapp"
197
+ }]
198
+ }, {
199
+ type: "input",
200
+ name: "projectName",
201
+ message: "\u9879\u76ee\u540d\u79f0",
202
+ default: _path["default"].basename(_path["default"].basename(process.cwd()))
203
+ }, {
204
+ type: "list",
205
+ name: "dependenciesInstallType",
206
+ message: "\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",
207
+ default: !1,
208
+ choices: [{
209
+ name: "yarn install",
210
+ value: "yarn"
211
+ }, {
212
+ name: "npm install",
213
+ value: "npm"
214
+ }, {
215
+ name: "\u4e0d\u521d\u59cb\u5316",
216
+ value: !1
217
+ }]
218
+ }]).then((function (n) {
219
+ var a = {
220
+ projectName: n.projectName,
221
+ mobile: "mobile" === n.type,
222
+ dependenciesInstallType: n.dependenciesInstallType
223
+ };
224
+ t || (t = _path["default"].join(__dirname, "../templates/".concat(n.type, "/").concat(t || "base"))), succeed("\u590d\u5236\u6a21\u7248 ".concat(_path["default"].basename(t)));
225
+ var i = _glob["default"].sync("**/*", {
226
+ cwd: t,
227
+ dot: !0,
228
+ ignore: ["**/node_modules/**", "**/.git/**", "**/.DS_Store", "**/.idea/**"]
229
+ });
230
+ if (i.forEach((function (r) {
231
+ if (t) {
232
+ var n = _path["default"].join(t, r);
233
+ if (!_fs["default"].statSync(n).isDirectory())
234
+ if (r.endsWith(".tpl")) {
235
+ var i = _fs["default"].readFileSync(n, ENCODING),
236
+ o = _path["default"].join(e, r.replace(/\.tpl$/, "")),
237
+ c = _mustache["default"].render(i, a);
238
+ _mkdirp["default"].sync(_path["default"].dirname(o)), succeed("\u521b\u5efa ".concat(_path["default"].relative(e, o))), _fs["default"].writeFileSync(o, c, ENCODING)
239
+ } else {
240
+ succeed("\u521b\u5efa ".concat(r));
241
+ var s = _path["default"].join(e, r);
242
+ _mkdirp["default"].sync(_path["default"].dirname(s)), _fs["default"].copyFileSync(n, s)
243
+ }
244
+ }
245
+ })), succeed("\u590d\u5236\u6a21\u7248 success!"), r && _fs["default"].existsSync(t) && (0, _rimraf["default"])(t, (function () {
246
+ succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(_path["default"].basename(t || "")))
247
+ })), n.dependenciesInstallType) switch (succeed("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"), n.dependenciesInstallType) {
248
+ case "npm":
249
+ execCommand({
250
+ command: "npm",
251
+ args: ["install"]
252
+ });
253
+ break;
254
+ case "yarn":
255
+ default:
256
+ execCommand({
257
+ command: "yarn",
258
+ args: ["install"]
259
+ });
260
+ break
261
+ }
262
+ succeed("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")
263
+ }))
264
+ },
265
+ createGitTemplate = function (e, t) {
266
+ return createTemplate(e, t, !0)
267
+ },
268
+ getYolkConfig = function () {
269
+ var e = _glob["default"].sync("*.yolkrc*", {
270
+ cwd: cwd,
271
+ dot: !0
272
+ });
273
+ if (!e.length) return {};
274
+ var t = _path["default"].join(cwd, e[0]);
275
+ if (!_fs["default"].existsSync(t)) return {};
276
+ try {
277
+ return JSON.parse(_fs["default"].readFileSync(t, ENCODING)) || {}
278
+ } catch (r) {
279
+ return fail(r.message || ".yolkrc\u8f6c\u6362\u9519\u8bef"), {}
280
+ }
281
+ },
282
+ getPrettierConfig = function () {
283
+ var e = _path["default"].join(cwd, ".prettierrc");
284
+ if (!_fs["default"].existsSync(e)) {
285
+ if (_fs["default"].existsSync(require.resolve("@umijs/fabric/dist/prettier"))) {
286
+ var t = require("@umijs/fabric/dist/prettier");
287
+ return t
288
+ }
289
+ return {}
290
+ }
291
+ try {
292
+ return JSON.parse(_fs["default"].readFileSync(e, ENCODING)) || {}
293
+ } catch (r) {
294
+ return fail(r.message || ".prettierrc\u8f6c\u6362\u9519\u8bef"), {}
295
+ }
296
+ },
297
+ getProjectConfigJSON = function () {
298
+ var e = _path["default"].join(cwd, "project.config.json");
299
+ if (!_fs["default"].existsSync(e)) return {};
300
+ try {
301
+ return JSON.parse(_fs["default"].readFileSync(e, ENCODING)) || {}
302
+ } catch (t) {
303
+ return fail(t.message || "project.config.json\u8f6c\u6362\u9519\u8bef"), {}
304
+ }
305
+ },
306
+ getPackageJSON = function () {
307
+ var e = _path["default"].join(cwd, "package.json");
308
+ if (!_fs["default"].existsSync(e)) return {};
309
+ try {
310
+ return JSON.parse(_fs["default"].readFileSync(e, ENCODING)) || {}
311
+ } catch (t) {
312
+ return fail(t.message || "package.json\u8f6c\u6362\u9519\u8bef"), {}
313
+ }
314
+ },
315
+ isMiniapp = function () {
316
+ return _fs["default"].existsSync(_path["default"].join(cwd, "project.config.json"))
317
+ },
318
+ getAppid = function () {
319
+ var e = _path["default"].join(cwd, "project.config.json");
320
+ if (_fs["default"].existsSync(e)) {
321
+ var t = require(e);
322
+ return t.appid
323
+ }
324
+ return ""
325
+ },
326
+ isWX = function () {
327
+ return 0 === getAppid().indexOf("wx")
328
+ },
329
+ isTT = function () {
330
+ return _fs["default"].existsSync(_path["default"].join(cwd, "project.tt.json")) && 0 === getAppid().indexOf("tt")
331
+ },
332
+ isAlipay = function () {
333
+ return 0 === getAppid().indexOf("20")
334
+ },
335
+ getEsLintConfigPath = function () {
336
+ var e = getYolkConfig(),
337
+ t = isMiniapp() ? require.resolve("@baic/eslint-config-yolk-miniapp") : require.resolve("@baic/eslint-config-yolk"),
338
+ r = _glob["default"].sync("*.eslintrc*", {
339
+ cwd: cwd,
340
+ dot: !0
341
+ }),
342
+ n = r[0];
343
+ return !1 === e.strict && n && _fs["default"].existsSync(n) ? n : t
344
+ },
345
+ getStyleLintConfigPath = function () {
346
+ var e = _glob["default"].sync("*.stylelintrc*", {
347
+ cwd: cwd,
348
+ dot: !0
349
+ }),
350
+ t = e[0];
351
+ return t
352
+ },
353
+ initPreCommit = function () {
354
+ var e = _path["default"].join(cwd, ".git/"),
355
+ t = _path["default"].join(cwd, ".git/hooks"),
356
+ r = _path["default"].join(t, "pre-commit"),
357
+ n = _fs["default"].existsSync(e),
358
+ a = _fs["default"].existsSync(r),
359
+ i = a && _fs["default"].readFileSync(r, "utf8").includes(HOOK_MARK);
360
+ if (n && (!a || !i)) {
361
+ _mkdirp["default"].sync(t), _fs["default"].writeFileSync(r, ["#!/usr/bin/env bash", "npx yolk pre-commit", "RESULT=$?", "[ $RESULT -ne 0 ] && exit 1", "exit 0", HOOK_MARK].join(_os["default"].EOL), "utf8");
362
+ try {
363
+ _fs["default"].chmodSync(r, "777")
364
+ } catch (o) {
365
+ fail("chmod ".concat(r, " failed: ").concat(o.message))
366
+ }
367
+ succeed("Create pre-commit hook")
368
+ }
369
+ },
370
+ preCommit = function () {
371
+ var e = getYolkConfig(),
372
+ t = !1 !== e.strict,
373
+ r = e.eslintIgnore,
374
+ n = e.stylelintIgnore;
375
+ sgf().then((function (e) {
376
+ var a = new Promise((function (r, a) {
377
+ var i = getStyleLintConfigPath();
378
+ if (i) {
379
+ var o = e.map((function (e) {
380
+ return e.filename
381
+ })).filter((function (e) {
382
+ return /^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)
383
+ })).filter((function (e) {
384
+ return /\.(le|[s\u017F]a|[s\u017F]c|c)[s\u017F]{2}$/i.test(e)
385
+ })).filter((function (e) {
386
+ return "string" === typeof n ? !(0, _minimatch["default"])(e, n, {
387
+ matchBase: !0
388
+ }) : n instanceof RegExp ? !n.test(e) : !Array.isArray(n) || n.every((function (t) {
389
+ return "string" === typeof t ? !(0, _minimatch["default"])(e, t, {
390
+ matchBase: !0
391
+ }) : t instanceof RegExp && !t.test(e)
392
+ }))
393
+ })).map((function (e) {
394
+ var t = _path["default"].join(cwd, e);
395
+ return _fs["default"].existsSync(t) ? t : null
396
+ })).filter((function (e) {
397
+ return !!e
398
+ }));
399
+ if (o.length >= MAX_FILE_COUNT) {
400
+ var c = [];
401
+ (0, _chunk2["default"])(o, 20).forEach((function (e) {
402
+ c.push(new Promise((function (r, n) {
403
+ execCommand({
404
+ command: "stylelint",
405
+ args: [t ? "--ignore-disables" : "", "--allow-empty-input", "--config", i].concat(_toConsumableArray(e)),
406
+ complete: r,
407
+ close: n,
408
+ exit: !1
409
+ })
410
+ })))
411
+ }));
412
+ var s = process.getMaxListeners(),
413
+ u = (0, _chunk2["default"])(c, s ? s / 2 : 2),
414
+ l = 0,
415
+ f = function e() {
416
+ l < u.length ? Promise.all(u[l]).then((function () {
417
+ l++, e()
418
+ }))["catch"](a) : r()
419
+ };
420
+ f()
421
+ } else o.length && execCommand({
422
+ command: "stylelint",
423
+ args: [t ? "--ignore-disables" : "", "--allow-empty-input", "--config", i].concat(_toConsumableArray(o)),
424
+ complete: r,
425
+ close: a,
426
+ exit: !1
427
+ })
428
+ } else r()
429
+ })),
430
+ i = function () {
431
+ var n = e.map((function (e) {
432
+ return e.filename
433
+ })).filter((function (e) {
434
+ return /^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)
435
+ })).filter((function (e) {
436
+ return /\.([jt\|][s\u017F]x?)$/i.test(e)
437
+ })).map((function (e) {
438
+ var t = _path["default"].join(cwd, e);
439
+ return _fs["default"].existsSync(t) ? t : null
440
+ })).filter((function (e) {
441
+ return !!e
442
+ }));
443
+ if (n.length) {
444
+ n.forEach((function (e) {
445
+ if (e && _fs["default"].existsSync(e)) {
446
+ var t = _path["default"].extname(e).replace(/^\./, ""),
447
+ r = _fs["default"].readFileSync(e, "utf8"),
448
+ n = (0, _prettier.format)(r, _objectSpread({
449
+ parser: PRETTIER_PARSER[t]
450
+ }, getPrettierConfig()));
451
+ _fs["default"].writeFileSync(e, n, "utf8")
452
+ }
453
+ })), succeed("\u683c\u5f0f\u5316 success!");
454
+ var a = getEsLintConfigPath();
455
+ if (a) {
456
+ var i = n.filter((function (e) {
457
+ return "string" === typeof r ? !(0, _minimatch["default"])(e, r, {
458
+ matchBase: !0
459
+ }) : r instanceof RegExp ? !r.test(e) : !Array.isArray(r) || r.every((function (t) {
460
+ return "string" === typeof t ? !(0, _minimatch["default"])(e, t, {
461
+ matchBase: !0
462
+ }) : t instanceof RegExp && !t.test(e)
463
+ }))
464
+ }));
465
+ if (t && (warn("git commit\u7981\u6b62eslint\u7684ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u3002"), r && warn("\u901a\u8fc7yolkrc\u914d\u7f6eeslintIgnore\uff1a".concat(r, "\u3002"))), i.length >= MAX_FILE_COUNT) {
466
+ var o = [];
467
+ (0, _chunk2["default"])(i, 20).forEach((function (e) {
468
+ o.push(new Promise((function (r) {
469
+ execCommand({
470
+ command: "eslint",
471
+ args: [t ? "--no-inline-config --no-ignore" : "", "--no-error-on-unmatched-pattern", "--config", a].concat(_toConsumableArray(e)),
472
+ complete: r,
473
+ exit: !1
474
+ })
475
+ })))
476
+ }));
477
+ var c = process.getMaxListeners(),
478
+ s = (0, _chunk2["default"])(o, c ? c / 2 : 2),
479
+ u = 0,
480
+ l = function e() {
481
+ u < s.length ? Promise.all(s[u]).then((function () {
482
+ u++, e()
483
+ })) : completeExit()
484
+ };
485
+ l()
486
+ } else i.length && execCommand({
487
+ command: "eslint",
488
+ args: [t ? "--no-inline-config --no-ignore" : "", "--no-error-on-unmatched-pattern", "--config", a].concat(_toConsumableArray(i))
489
+ })
490
+ } else warn("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6")
491
+ } else completeExit()
492
+ };
493
+ warn("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"), a.then(i)
494
+ }))
495
+ },
496
+ getMiniProgramCi = function (e) {
497
+ var t = e.mProject,
498
+ r = e.mPrivateKeyPath,
499
+ n = e.mVersion,
500
+ a = e.mDesc,
501
+ i = e.mRobot,
502
+ o = e.mQrcodeFormat,
503
+ c = e.mQrcodeOutputDest,
504
+ s = e.mPagePath,
505
+ u = e.mSearchQuery,
506
+ l = _fs["default"].existsSync(_path["default"].join(cwd, ".git")) ? (0, _child_process.execSync)("git log -1 --pretty=format:%H").toString() : "",
507
+ f = getProjectConfigJSON(),
508
+ p = f.appid,
509
+ d = t || _path["default"].join(cwd, "dist"),
510
+ m = r || _path["default"].join(cwd, "private.".concat(p, ".key"));
511
+ if (_fs["default"].existsSync(d)) {
512
+ if (_fs["default"].existsSync(m)) {
513
+ var y = getPackageJSON(),
514
+ _ = n || y.version || f.version || "1.0.0",
515
+ g = a || y.description || f.description,
516
+ h = "version: ".concat(_, ";").concat(l ? " commit: ".concat(l, ";") : "").concat(g ? " description: ".concat(g, ";") : "");
517
+ l && info("commit: ".concat(l)), info("dist: ".concat(d)), info("key: ".concat(m)), info("appid: ".concat(p)), info("version: ".concat(_)), info("desc: ".concat(h));
518
+ var b = new miniProgramCi.Project({
519
+ appid: p,
520
+ type: "miniProgram",
521
+ projectPath: d,
522
+ privateKeyPath: m,
523
+ ignores: ["node_modules/**/*", "**/*.txt", "**/*.key", "**/*.less", "**/*.sass", "**/*.scss", "**/*.css", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/*.md"]
524
+ });
525
+ return {
526
+ miniProgramCi: miniProgramCi,
527
+ appid: p,
528
+ options: {
529
+ project: b,
530
+ version: _,
531
+ desc: h,
532
+ setting: f.setting,
533
+ robot: i,
534
+ qrcodeFormat: o,
535
+ qrcodeOutputDest: c,
536
+ pagePath: s,
537
+ searchQuery: u
538
+ }
539
+ }
540
+ }
541
+ throw Error("\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(".concat(m, ")"))
542
+ }
543
+ throw Error("\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(".concat(d, ")"))
544
+ },
545
+ install = function () {
546
+ info("node version: ".concat(process.version)), initPreCommit(), process.argv.length > 2 ? _commander["default"].version(_package["default"].version).usage("[command] [options]").option("--clone", "\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248").option("--template <template>", "\u6a21\u7248\u540d\u79f0\u6216\u8005clone\u6a21\u5f0f\u7684git\u5730\u5740").option("--docs", "\u542f\u52a8\u6587\u6863\u6a21\u5f0f").option("--mProject <project>", "\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u5de5\u7a0b\u76ee\u5f55").option("--mPrivateKeyPath <privateKeyPath>", "\u5c0f\u7a0b\u5e8f\u4e0a\u4f20key\u6587\u4ef6").option("--mVersion <version>", "\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u7248\u672c\u53f7").option("--mDesc <desc>", "\u5c0f\u7a0b\u5e8f\u4e0a\u4f20\u63cf\u8ff0").option("--mRobot <robot>", "\u5c0f\u7a0b\u5e8f\u4e0a\u4f20ci\u673a\u5668\u4eba1~30").option("--mQrcodeFormat <qrcodeFormat>", '\u5c0f\u7a0b\u5e8f\u9884\u89c8\u8fd4\u56de\u4e8c\u7ef4\u7801\u6587\u4ef6\u7684\u683c\u5f0f "image" \u6216 "base64"\uff0c \u9ed8\u8ba4\u503c "terminal" \u4f9b\u8c03\u8bd5\u7528').option("--mQrcodeOutputDest <qrcodeOutputDest>", "\u5c0f\u7a0b\u5e8f\u9884\u89c8\u4e8c\u7ef4\u7801\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84").option("--mPagePath <pagePath>", "\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84").option("--mSearchQuery <searchQuery>", "\u5c0f\u7a0b\u5e8f\u9884\u89c8\u9884\u89c8\u9875\u9762\u8def\u5f84\u542f\u52a8\u53c2\u6570").action((function (e, t) {
547
+ console.log(e, t);
548
+ var r = _toArray(t),
549
+ n = r[0],
550
+ a = r.slice(1),
551
+ i = e.clone,
552
+ o = e.template,
553
+ c = e.docs;
554
+ if (n) switch (n) {
555
+ case "init":
556
+ if (succeed("yolk ".concat(n, " \u5f00\u59cb")), i)
557
+ if (o) {
558
+ var s = ".yolk",
559
+ u = _path["default"].join(cwd, s);
560
+ _fs["default"].existsSync(u) && (0, _rimraf["default"])(u, (function () {
561
+ succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(u))
562
+ })), execCommand({
563
+ command: "git",
564
+ args: ["clone", "-b", "master", "--depth", "1", o, s].concat(a)
565
+ }), createGitTemplate(cwd, u)
566
+ } else fail("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");
567
+ else createTemplate(cwd);
568
+ break;
569
+ case "start":
570
+ isMiniapp() ? isTT() ? execCommand({
571
+ command: "taro",
572
+ args: ["build", "--type", "tt", "--watch"].concat(a)
573
+ }) : isAlipay() ? execCommand({
574
+ command: "taro",
575
+ args: ["build", "--type", "alipay", "--watch"].concat(a)
576
+ }) : execCommand({
577
+ command: "taro",
578
+ args: ["build", "--type", "weapp", "--watch"].concat(a)
579
+ }) : execCommand(c ? {
580
+ command: "dumi",
581
+ args: ["dev"].concat(a)
582
+ } : {
583
+ command: "umi",
584
+ args: ["dev"].concat(a)
585
+ });
586
+ break;
587
+ case "build":
588
+ isMiniapp() ? isTT() ? execCommand({
589
+ command: "taro",
590
+ args: ["build", "--type", "tt"].concat(a)
591
+ }) : isAlipay() ? execCommand({
592
+ command: "taro",
593
+ args: ["build", "--type", "alipay"].concat(a)
594
+ }) : execCommand({
595
+ command: "taro",
596
+ args: ["build", "--type", "weapp"].concat(a)
597
+ }) : execCommand(c ? {
598
+ command: "dumi",
599
+ args: ["build"].concat(a)
600
+ } : {
601
+ command: "umi",
602
+ args: ["build"].concat(a)
603
+ });
604
+ break;
605
+ case "pre-commit":
606
+ preCommit();
607
+ break;
608
+ case "test":
609
+ execCommand({
610
+ command: "umi-test",
611
+ args: ["--no-cache", "--update-snapshot", "--runInBand", "--detectOpenHandles"].concat(a)
612
+ });
613
+ break;
614
+ case "miniapp-upload":
615
+ if (isMiniapp())
616
+ if (isTT());
617
+ else if (isAlipay());
618
+ else {
619
+ var l = getMiniProgramCi(e),
620
+ f = l.miniProgramCi,
621
+ p = l.appid,
622
+ d = l.options;
623
+ info("".concat(p, "\u4e0a\u4f20\u5f00\u59cb")), f.upload(_objectSpread(_objectSpread({}, (0, _pick2["default"])(d, ["project", "version", "desc", "setting", "robot"])), {}, {
624
+ onProgressUpdate: function (e) {
625
+ if ((0, _isString2["default"])(e)) info("task: ".concat(e));
626
+ else {
627
+ var t = e.status,
628
+ r = e.message;
629
+ info("task(".concat(t, "): ").concat(r))
630
+ }
631
+ }
632
+ })).then((function () {
633
+ succeed("".concat(p, "\u4e0a\u4f20\u5b8c\u6210"))
634
+ }))
635
+ }
636
+ break;
637
+ case "miniapp-preview":
638
+ if (isMiniapp())
639
+ if (isTT());
640
+ else if (isAlipay());
641
+ else {
642
+ var m = getMiniProgramCi(e),
643
+ y = m.miniProgramCi,
644
+ _ = m.appid,
645
+ g = m.options;
646
+ info("".concat(_, "\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb")), y.preview(_objectSpread(_objectSpread({}, (0, _pick2["default"])(g, ["project", "version", "desc", "setting", "robot", "qrcodeFormat", "qrcodeOutputDest", "pagePath", "searchQuery"])), {}, {
647
+ onProgressUpdate: function (e) {
648
+ if ((0, _isString2["default"])(e)) info("task: ".concat(e));
649
+ else {
650
+ var t = e.status,
651
+ r = e.message;
652
+ info("task(".concat(t, "): ").concat(r))
653
+ }
654
+ }
655
+ })).then((function () {
656
+ succeed("".concat(_, "\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210"))
657
+ }))
658
+ }
659
+ break;
660
+ default:
661
+ breakExit()
662
+ }
663
+ })).parse(process.argv) : breakExit()
664
+ };
665
+ install();
package/package.json CHANGED
@@ -1,73 +1,41 @@
1
1
  {
2
2
  "name": "@baic/yolk-cli",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.1-alpha.0",
4
+ "description": "",
4
5
  "scripts": {
5
- "start": "dumi dev",
6
- "docs:build": "dumi build",
7
- "docs:deploy": "gh-pages -d docs-dist",
8
- "build": "father-build && gulp",
9
- "deploy": "npm run docs:build && npm run docs:deploy",
10
- "release": "npm run build && npm publish",
11
- "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
12
- "test": "umi-test",
13
- "test:coverage": "umi-test --coverage"
6
+ "pub": "npm publish",
7
+ "start": "node ./bin start"
14
8
  },
15
9
  "bin": {
16
- "yolk": "lib/index.js"
10
+ "yolk": "bin/index.js"
17
11
  },
18
12
  "files": [
19
- "lib",
20
- "es",
13
+ "bin",
21
14
  "templates"
22
15
  ],
23
- "main": "lib/index.js",
24
- "module": "es/index.js",
25
- "typings": "lib/index.d.ts",
26
- "gitHooks": {
27
- "pre-commit": "lint-staged"
28
- },
29
- "lint-staged": {
30
- "*.{js,jsx,less,md,json}": [
31
- "prettier --write"
32
- ],
33
- "*.ts?(x)": [
34
- "prettier --parser=typescript --write"
35
- ]
36
- },
37
16
  "author": "Baic",
38
17
  "repository": {
39
18
  "type": "git",
40
19
  "url": "https://github.com/303394539/yolk"
41
20
  },
21
+ "license": "MIT",
42
22
  "dependencies": {
43
- "@babel/runtime": "~7.15.3",
44
- "@types/glob": "~7.1.4",
45
- "@types/inquirer": "~7.3.3",
46
- "@types/lodash": "~4.14.172",
23
+ "@types/glob": "~7.2.0",
24
+ "@types/inquirer": "~8.1.3",
25
+ "@types/lodash": "~4.14.178",
47
26
  "@types/mkdirp": "~1.0.2",
48
27
  "@types/mustache": "~4.1.2",
49
28
  "@types/rimraf": "~3.0.2",
50
- "commander": "~6.2.1",
51
- "glob": "~7.1.7",
52
- "inquirer": "~8.1.2",
29
+ "commander": "6.x",
30
+ "glob": "~7.2.0",
31
+ "inquirer": "~8.2.0",
53
32
  "lodash": "~4.17.21",
33
+ "miniprogram-ci": "~1.6.10",
54
34
  "mkdirp": "~1.0.4",
55
35
  "mustache": "~4.2.0",
56
- "ora": "~5.4.1",
57
- "prettier": "~2.3.2",
36
+ "ora": "5.x",
37
+ "prettier": "~2.5.1",
58
38
  "rimraf": "~3.0.2",
59
39
  "staged-git-files": "~1.2.0"
60
- },
61
- "devDependencies": {
62
- "@umijs/test": "~3.5.17",
63
- "dumi": "~1.1.25",
64
- "father-build": "~1.19.8",
65
- "gh-pages": "~3.2.3",
66
- "gulp": "~4.0.2",
67
- "gulp-load-plugins": "~2.0.7",
68
- "gulp-terser": "~2.0.1",
69
- "lint-staged": "~11.1.2",
70
- "prettier": "~2.3.2",
71
- "yorkie": "~2.0.0"
72
40
  }
73
41
  }
@@ -18,6 +18,6 @@
18
18
  "dependencies": {
19
19
  "@baic/preset-yolk-miniapp": "1.x",
20
20
  "babel-preset-taro": "3.x",
21
- "eslint": "~7.29.0"
21
+ "eslint": "8.x"
22
22
  }
23
23
  }
package/es/index.js DELETED
@@ -1,2 +0,0 @@
1
- #! /usr/bin/env node
2
- import _toArray from"@babel/runtime/helpers/esm/toArray";import _objectSpread from"@babel/runtime/helpers/esm/objectSpread2";import _toConsumableArray from"@babel/runtime/helpers/esm/toConsumableArray";import fs from"fs";import path from"path";import os from"os";import commander from"commander";import inquirer from"inquirer";import{spawn}from"child_process";import ora from"ora";import glob from"glob";import Mustache from"mustache";import mkdirp from"mkdirp";import rimraf from"rimraf";import{format}from"prettier";import _ from"lodash";import Package from"../package.json";var sgf=require("staged-git-files"),cwd=process.cwd(),HOOK_MARK="##### CREATED BY YOLK #####",PRETTIER_PARSER={ts:"typescript",tsx:"typescript"},ENCODING="utf-8",MAX_FILE_COUNT=60,spinner=ora(),warn=function(e){return e&&spinner.warn(Buffer.from(e,ENCODING).toString())},fail=function(e){return e&&spinner.fail(Buffer.from(e,ENCODING).toString())},succeed=function(e){return e&&spinner.succeed(Buffer.from(e,ENCODING).toString())},info=function(e){return e&&spinner.info(Buffer.from(e,ENCODING).toString())},getCommand=function(e){return"win32"===process.platform?"".concat(e,".cmd"):e},completeExit=function(){succeed("yolk complete!"),process.exit(0)},breakExit=function(){warn("yolk break!"),process.exit(0)},execCommand=function(e){var n=e.command,t=e.args,i=e.complete,r=e.close,o=e.exit,a=void 0===o||o,c=spawn(getCommand(n),t||[],{stdio:"inherit"}).on("close",(function(e){e?(r&&r(),fail("yolk close!"),process.exit(e)):(i&&i(),a&&completeExit())}));process.on("SIGINT",(function(){commander.runningCommand&&commander.runningCommand.kill("SIGKILL"),c.kill(),breakExit()}))},createTemplate=function(e,n,t){inquirer.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u5e73\u53f0",default:"web",choices:[{name:"web",value:"web"},{name:"mobile",value:"mobile"},{name:"\u5c0f\u7a0b\u5e8f",value:"miniapp"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:path.basename(path.basename(process.cwd()))},{type:"list",name:"dependenciesInstallType",message:"\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",default:!1,choices:[{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"},{name:"\u4e0d\u521d\u59cb\u5316",value:!1}]}]).then((function(i){var r={projectName:i.projectName,mobile:"mobile"===i.type,dependenciesInstallType:i.dependenciesInstallType};n||(n=path.join(__dirname,"../templates/".concat(i.type,"/").concat(n||"base"))),succeed("\u590d\u5236\u6a21\u7248 ".concat(path.basename(n)));var o=glob.sync("**/*",{cwd:n,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(o.forEach((function(t){if(n){var i=path.join(n,t);if(!fs.statSync(i).isDirectory())if(t.endsWith(".tpl")){var o=fs.readFileSync(i,ENCODING),a=path.join(e,t.replace(/\.tpl$/,"")),c=Mustache.render(o,r);mkdirp.sync(path.dirname(a)),succeed("\u521b\u5efa ".concat(path.relative(e,a))),fs.writeFileSync(a,c,ENCODING)}else{succeed("\u521b\u5efa ".concat(t));var s=path.join(e,t);mkdirp.sync(path.dirname(s)),fs.copyFileSync(i,s)}}})),succeed("\u590d\u5236\u6a21\u7248 success!"),t&&fs.existsSync(n)&&rimraf(n,(function(){succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(path.basename(n||"")))})),i.dependenciesInstallType)switch(succeed("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),i.dependenciesInstallType){case"npm":execCommand({command:"npm",args:["install"]});break;case"yarn":default:execCommand({command:"yarn",args:["install"]});break}succeed("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},createGitTemplate=function(e,n){return createTemplate(e,n,!0)},getYolkConfig=function(){var e=glob.sync("*.yolkrc*",{cwd:cwd,dot:!0}),n=e[0];if(!fs.existsSync(n))return{};try{return JSON.parse(fs.readFileSync(n,ENCODING))||{}}catch(t){return fail(t.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},getPrettierConfig=function(){var e=path.join(cwd,".prettierrc");if(!fs.existsSync(e)){if(fs.existsSync(require.resolve("@umijs/fabric/dist/prettier"))){var n=require("@umijs/fabric/dist/prettier");return n}return{}}try{return JSON.parse(fs.readFileSync(e,ENCODING))||{}}catch(t){return fail(t.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}},isMiniapp=function(){return fs.existsSync(path.join(cwd,"project.config.json"))},getAppid=function(){var e=path.join(cwd,"project.config.json");if(fs.existsSync(e)){var n=require(e);return n.appid}return""},isWX=function(){return 0===getAppid().indexOf("wx")},isTT=function(){return fs.existsSync(path.join(cwd,"project.tt.json"))&&0===getAppid().indexOf("tt")},isAlipay=function(){return 0===getAppid().indexOf("20")},getEsLintConfigPath=function(){var e=getYolkConfig(),n=isMiniapp()?require.resolve("@baic/eslint-config-yolk-miniapp"):require.resolve("@baic/eslint-config-yolk"),t=glob.sync("*.eslintrc*",{cwd:cwd,dot:!0}),i=t[0];return!1===e.strict&&i&&fs.existsSync(i)?i:n},getStyleLintConfigPath=function(){var e=glob.sync("*.stylelintrc*",{cwd:cwd,dot:!0}),n=e[0];return n},initPreCommit=function(){var e=path.join(cwd,".git/"),n=path.join(cwd,".git/hooks"),t=path.join(n,"pre-commit"),i=fs.existsSync(e),r=fs.existsSync(t),o=r&&fs.readFileSync(t,"utf8").includes(HOOK_MARK);if(i&&(!r||!o)){mkdirp.sync(n),fs.writeFileSync(t,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",HOOK_MARK].join(os.EOL),"utf8");try{fs.chmodSync(t,"777")}catch(a){fail("chmod ".concat(t," failed: ").concat(a.message))}succeed("Create pre-commit hook")}},preCommit=function(){var e=getYolkConfig(),n=!1!==e.strict,t=e.eslintIgnore,i=e.styleIgnore;sgf().then((function(e){var r=new Promise((function(t,r){var o=getStyleLintConfigPath();if(o){var a=e.map((function(e){return e.filename})).filter((function(e){return/^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)})).filter((function(e){return/\.(le|[s\u017F]a|[s\u017F]c|c)[s\u017F]{2}$/i.test(e)})).filter((function(e){return"string"===typeof i?e.indexOf(i)<0:i instanceof RegExp?!i.test(e):!Array.isArray(i)||i.every((function(n){return"string"===typeof n?e.indexOf(n)<0:n instanceof RegExp&&!n.test(e)}))})).map((function(e){var n=path.join(cwd,e);return fs.existsSync(n)?n:null})).filter((function(e){return!!e}));if(a.length>=MAX_FILE_COUNT){var c=[];_.chunk(a,20).forEach((function(e){c.push(new Promise((function(t,i){execCommand({command:"stylelint",args:[n?"--ignore-disables":"","--allow-empty-input","--config",o].concat(_toConsumableArray(e)),complete:t,close:i,exit:!1})})))}));var s=process.getMaxListeners(),m=_.chunk(c,s?s/2:2),l=0,p=function e(){l<m.length?Promise.all(m[l]).then((function(){l++,e()})).catch(r):t()};p()}else a.length&&execCommand({command:"stylelint",args:[n?"--ignore-disables":"","--allow-empty-input","--config",o].concat(_toConsumableArray(a)),complete:t,close:r,exit:!1})}else t()})),o=function(){var i=e.map((function(e){return e.filename})).filter((function(e){return/^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)})).filter((function(e){return/\.([jt\|][s\u017F]x?)$/i.test(e)})).filter((function(e){return"string"===typeof t?e.indexOf(t)<0:t instanceof RegExp?!t.test(e):!Array.isArray(t)||t.every((function(n){return"string"===typeof n?e.indexOf(n)<0:n instanceof RegExp&&!n.test(e)}))})).map((function(e){var n=path.join(cwd,e);return fs.existsSync(n)?n:null})).filter((function(e){return!!e}));if(i.length){i.forEach((function(e){if(e&&fs.existsSync(e)){var n=path.extname(e).replace(/^\./,""),t=fs.readFileSync(e,"utf8"),i=format(t,_objectSpread({parser:PRETTIER_PARSER[n]},getPrettierConfig()));fs.writeFileSync(e,i,"utf8")}})),succeed("\u683c\u5f0f\u5316 success!");var r=getEsLintConfigPath();if(r)if(n&&warn("\u7981\u6b62\u4f7f\u7528ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u8eb2\u907f\u4ee3\u7801\u68c0\u67e5\uff01\uff01\uff01"),i.length>=MAX_FILE_COUNT){var o=[];_.chunk(i,20).forEach((function(e){o.push(new Promise((function(t){execCommand({command:"eslint",args:[n?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",r].concat(_toConsumableArray(e)),complete:t,exit:!1})})))}));var a=process.getMaxListeners(),c=_.chunk(o,a?a/2:2),s=0,m=function e(){s<c.length?Promise.all(c[s]).then((function(){s++,e()})):completeExit()};m()}else i.length&&execCommand({command:"eslint",args:[n?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",r].concat(_toConsumableArray(i))});else warn("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6")}else completeExit()};warn("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),r.then(o)}))},install=function(){info("node version: ".concat(process.version)),initPreCommit(),process.argv.length>2?commander.version(Package.version).usage("[command] [options]").option("--clone","\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248").option("--template <name>","\u6a21\u7248\u540d\u79f0\u6216\u8005clone\u6a21\u5f0f\u7684git\u5730\u5740").option("--docs","\u542f\u52a8\u6587\u6863\u6a21\u5f0f").action((function(e,n){var t=_toArray(n),i=t[0],r=t.slice(1),o=e.clone,a=e.template,c=e.docs;if(i)switch(i){case"init":if(succeed("yolk ".concat(i," \u5f00\u59cb")),o)if(a){var s=".yolk",m=path.join(cwd,s);fs.existsSync(m)&&rimraf(m,(function(){succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(m))})),execCommand({command:"git",args:["clone","-b","master","--depth","1",a,s].concat(r)}),createGitTemplate(cwd,m)}else fail("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else createTemplate(cwd);break;case"start":isMiniapp()?isTT()?execCommand({command:"taro",args:["build","--type","tt","--watch"].concat(r)}):isAlipay()?execCommand({command:"taro",args:["build","--type","alipay","--watch"].concat(r)}):execCommand({command:"taro",args:["build","--type","weapp","--watch"].concat(r)}):execCommand(c?{command:"dumi",args:["dev"].concat(r)}:{command:"umi",args:["dev"].concat(r)});break;case"build":isMiniapp()?isTT()?execCommand({command:"taro",args:["build","--type","tt"].concat(r)}):isAlipay()?execCommand({command:"taro",args:["build","--type","alipay"].concat(r)}):execCommand({command:"taro",args:["build","--type","weapp"].concat(r)}):execCommand(c?{command:"dumi",args:["build"].concat(r)}:{command:"umi",args:["build"].concat(r)});break;case"pre-commit":preCommit();break;case"test":execCommand({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(r)});break;default:breakExit()}})).parse(process.argv):breakExit()};install();
package/lib/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #! /usr/bin/env node
2
- export {};
package/lib/index.js DELETED
@@ -1,2 +0,0 @@
1
- #! /usr/bin/env node
2
- "use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault"),_toArray2=_interopRequireDefault(require("@babel/runtime/helpers/toArray")),_objectSpread2=_interopRequireDefault(require("@babel/runtime/helpers/objectSpread2")),_toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")),_fs=_interopRequireDefault(require("fs")),_path=_interopRequireDefault(require("path")),_os=_interopRequireDefault(require("os")),_commander=_interopRequireDefault(require("commander")),_inquirer=_interopRequireDefault(require("inquirer")),_child_process=require("child_process"),_ora=_interopRequireDefault(require("ora")),_glob=_interopRequireDefault(require("glob")),_mustache=_interopRequireDefault(require("mustache")),_mkdirp=_interopRequireDefault(require("mkdirp")),_rimraf=_interopRequireDefault(require("rimraf")),_prettier=require("prettier"),_lodash=_interopRequireDefault(require("lodash")),_package=_interopRequireDefault(require("../package.json")),sgf=require("staged-git-files"),cwd=process.cwd(),HOOK_MARK="##### CREATED BY YOLK #####",PRETTIER_PARSER={ts:"typescript",tsx:"typescript"},ENCODING="utf-8",MAX_FILE_COUNT=60,spinner=(0,_ora.default)(),warn=function(e){return e&&spinner.warn(Buffer.from(e,ENCODING).toString())},fail=function(e){return e&&spinner.fail(Buffer.from(e,ENCODING).toString())},succeed=function(e){return e&&spinner.succeed(Buffer.from(e,ENCODING).toString())},info=function(e){return e&&spinner.info(Buffer.from(e,ENCODING).toString())},getCommand=function(e){return"win32"===process.platform?"".concat(e,".cmd"):e},completeExit=function(){succeed("yolk complete!"),process.exit(0)},breakExit=function(){warn("yolk break!"),process.exit(0)},execCommand=function(e){var t=e.command,n=e.args,a=e.complete,r=e.close,i=e.exit,c=void 0===i||i,o=(0,_child_process.spawn)(getCommand(t),n||[],{stdio:"inherit"}).on("close",(function(e){e?(r&&r(),fail("yolk close!"),process.exit(e)):(a&&a(),c&&completeExit())}));process.on("SIGINT",(function(){_commander.default.runningCommand&&_commander.default.runningCommand.kill("SIGKILL"),o.kill(),breakExit()}))},createTemplate=function(e,t,n){_inquirer.default.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u5e73\u53f0",default:"web",choices:[{name:"web",value:"web"},{name:"mobile",value:"mobile"},{name:"\u5c0f\u7a0b\u5e8f",value:"miniapp"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:_path.default.basename(_path.default.basename(process.cwd()))},{type:"list",name:"dependenciesInstallType",message:"\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",default:!1,choices:[{name:"yarn install",value:"yarn"},{name:"npm install",value:"npm"},{name:"\u4e0d\u521d\u59cb\u5316",value:!1}]}]).then((function(a){var r={projectName:a.projectName,mobile:"mobile"===a.type,dependenciesInstallType:a.dependenciesInstallType};t||(t=_path.default.join(__dirname,"../templates/".concat(a.type,"/").concat(t||"base"))),succeed("\u590d\u5236\u6a21\u7248 ".concat(_path.default.basename(t)));var i=_glob.default.sync("**/*",{cwd:t,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((function(n){if(t){var a=_path.default.join(t,n);if(!_fs.default.statSync(a).isDirectory())if(n.endsWith(".tpl")){var i=_fs.default.readFileSync(a,ENCODING),c=_path.default.join(e,n.replace(/\.tpl$/,"")),o=_mustache.default.render(i,r);_mkdirp.default.sync(_path.default.dirname(c)),succeed("\u521b\u5efa ".concat(_path.default.relative(e,c))),_fs.default.writeFileSync(c,o,ENCODING)}else{succeed("\u521b\u5efa ".concat(n));var s=_path.default.join(e,n);_mkdirp.default.sync(_path.default.dirname(s)),_fs.default.copyFileSync(a,s)}}})),succeed("\u590d\u5236\u6a21\u7248 success!"),n&&_fs.default.existsSync(t)&&(0,_rimraf.default)(t,(function(){succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(_path.default.basename(t||"")))})),a.dependenciesInstallType)switch(succeed("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),a.dependenciesInstallType){case"npm":execCommand({command:"npm",args:["install"]});break;case"yarn":default:execCommand({command:"yarn",args:["install"]});break}succeed("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},createGitTemplate=function(e,t){return createTemplate(e,t,!0)},getYolkConfig=function(){var e=_glob.default.sync("*.yolkrc*",{cwd:cwd,dot:!0}),t=e[0];if(!_fs.default.existsSync(t))return{};try{return JSON.parse(_fs.default.readFileSync(t,ENCODING))||{}}catch(n){return fail(n.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},getPrettierConfig=function(){var e=_path.default.join(cwd,".prettierrc");if(!_fs.default.existsSync(e)){if(_fs.default.existsSync(require.resolve("@umijs/fabric/dist/prettier"))){var t=require("@umijs/fabric/dist/prettier");return t}return{}}try{return JSON.parse(_fs.default.readFileSync(e,ENCODING))||{}}catch(n){return fail(n.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}},isMiniapp=function(){return _fs.default.existsSync(_path.default.join(cwd,"project.config.json"))},getAppid=function(){var e=_path.default.join(cwd,"project.config.json");if(_fs.default.existsSync(e)){var t=require(e);return t.appid}return""},isWX=function(){return 0===getAppid().indexOf("wx")},isTT=function(){return _fs.default.existsSync(_path.default.join(cwd,"project.tt.json"))&&0===getAppid().indexOf("tt")},isAlipay=function(){return 0===getAppid().indexOf("20")},getEsLintConfigPath=function(){var e=getYolkConfig(),t=isMiniapp()?require.resolve("@baic/eslint-config-yolk-miniapp"):require.resolve("@baic/eslint-config-yolk"),n=_glob.default.sync("*.eslintrc*",{cwd:cwd,dot:!0}),a=n[0];return!1===e.strict&&a&&_fs.default.existsSync(a)?a:t},getStyleLintConfigPath=function(){var e=_glob.default.sync("*.stylelintrc*",{cwd:cwd,dot:!0}),t=e[0];return t},initPreCommit=function(){var e=_path.default.join(cwd,".git/"),t=_path.default.join(cwd,".git/hooks"),n=_path.default.join(t,"pre-commit"),a=_fs.default.existsSync(e),r=_fs.default.existsSync(n),i=r&&_fs.default.readFileSync(n,"utf8").includes(HOOK_MARK);if(a&&(!r||!i)){_mkdirp.default.sync(t),_fs.default.writeFileSync(n,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",HOOK_MARK].join(_os.default.EOL),"utf8");try{_fs.default.chmodSync(n,"777")}catch(c){fail("chmod ".concat(n," failed: ").concat(c.message))}succeed("Create pre-commit hook")}},preCommit=function(){var e=getYolkConfig(),t=!1!==e.strict,n=e.eslintIgnore,a=e.styleIgnore;sgf().then((function(e){var r=new Promise((function(n,r){var i=getStyleLintConfigPath();if(i){var c=e.map((function(e){return e.filename})).filter((function(e){return/^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)})).filter((function(e){return/\.(le|[s\u017F]a|[s\u017F]c|c)[s\u017F]{2}$/i.test(e)})).filter((function(e){return"string"===typeof a?e.indexOf(a)<0:a instanceof RegExp?!a.test(e):!Array.isArray(a)||a.every((function(t){return"string"===typeof t?e.indexOf(t)<0:t instanceof RegExp&&!t.test(e)}))})).map((function(e){var t=_path.default.join(cwd,e);return _fs.default.existsSync(t)?t:null})).filter((function(e){return!!e}));if(c.length>=MAX_FILE_COUNT){var o=[];_lodash.default.chunk(c,20).forEach((function(e){o.push(new Promise((function(n,a){execCommand({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",i].concat((0,_toConsumableArray2.default)(e)),complete:n,close:a,exit:!1})})))}));var s=process.getMaxListeners(),u=_lodash.default.chunk(o,s?s/2:2),l=0,f=function e(){l<u.length?Promise.all(u[l]).then((function(){l++,e()})).catch(r):n()};f()}else c.length&&execCommand({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",i].concat((0,_toConsumableArray2.default)(c)),complete:n,close:r,exit:!1})}else n()})),i=function(){var a=e.map((function(e){return e.filename})).filter((function(e){return/^([s\u017F]rc|te[s\u017F]t[s\u017F])/i.test(e)})).filter((function(e){return/\.([jt\|][s\u017F]x?)$/i.test(e)})).filter((function(e){return"string"===typeof n?e.indexOf(n)<0:n instanceof RegExp?!n.test(e):!Array.isArray(n)||n.every((function(t){return"string"===typeof t?e.indexOf(t)<0:t instanceof RegExp&&!t.test(e)}))})).map((function(e){var t=_path.default.join(cwd,e);return _fs.default.existsSync(t)?t:null})).filter((function(e){return!!e}));if(a.length){a.forEach((function(e){if(e&&_fs.default.existsSync(e)){var t=_path.default.extname(e).replace(/^\./,""),n=_fs.default.readFileSync(e,"utf8"),a=(0,_prettier.format)(n,(0,_objectSpread2.default)({parser:PRETTIER_PARSER[t]},getPrettierConfig()));_fs.default.writeFileSync(e,a,"utf8")}})),succeed("\u683c\u5f0f\u5316 success!");var r=getEsLintConfigPath();if(r)if(t&&warn("\u7981\u6b62\u4f7f\u7528ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u8eb2\u907f\u4ee3\u7801\u68c0\u67e5\uff01\uff01\uff01"),a.length>=MAX_FILE_COUNT){var i=[];_lodash.default.chunk(a,20).forEach((function(e){i.push(new Promise((function(n){execCommand({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",r].concat((0,_toConsumableArray2.default)(e)),complete:n,exit:!1})})))}));var c=process.getMaxListeners(),o=_lodash.default.chunk(i,c?c/2:2),s=0,u=function e(){s<o.length?Promise.all(o[s]).then((function(){s++,e()})):completeExit()};u()}else a.length&&execCommand({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",r].concat((0,_toConsumableArray2.default)(a))});else warn("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6")}else completeExit()};warn("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),r.then(i)}))},install=function(){info("node version: ".concat(process.version)),initPreCommit(),process.argv.length>2?_commander.default.version(_package.default.version).usage("[command] [options]").option("--clone","\u901a\u8fc7git clone\u62c9\u53d6\u6a21\u7248").option("--template <name>","\u6a21\u7248\u540d\u79f0\u6216\u8005clone\u6a21\u5f0f\u7684git\u5730\u5740").option("--docs","\u542f\u52a8\u6587\u6863\u6a21\u5f0f").action((function(e,t){var n=(0,_toArray2.default)(t),a=n[0],r=n.slice(1),i=e.clone,c=e.template,o=e.docs;if(a)switch(a){case"init":if(succeed("yolk ".concat(a," \u5f00\u59cb")),i)if(c){var s=".yolk",u=_path.default.join(cwd,s);_fs.default.existsSync(u)&&(0,_rimraf.default)(u,(function(){succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(u))})),execCommand({command:"git",args:["clone","-b","master","--depth","1",c,s].concat(r)}),createGitTemplate(cwd,u)}else fail("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else createTemplate(cwd);break;case"start":isMiniapp()?isTT()?execCommand({command:"taro",args:["build","--type","tt","--watch"].concat(r)}):isAlipay()?execCommand({command:"taro",args:["build","--type","alipay","--watch"].concat(r)}):execCommand({command:"taro",args:["build","--type","weapp","--watch"].concat(r)}):execCommand(o?{command:"dumi",args:["dev"].concat(r)}:{command:"umi",args:["dev"].concat(r)});break;case"build":isMiniapp()?isTT()?execCommand({command:"taro",args:["build","--type","tt"].concat(r)}):isAlipay()?execCommand({command:"taro",args:["build","--type","alipay"].concat(r)}):execCommand({command:"taro",args:["build","--type","weapp"].concat(r)}):execCommand(o?{command:"dumi",args:["build"].concat(r)}:{command:"umi",args:["build"].concat(r)});break;case"pre-commit":preCommit();break;case"test":execCommand({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(r)});break;default:breakExit()}})).parse(process.argv):breakExit()};install();