@baic/yolk-cli 2.1.0-alpha.4 → 2.1.0-alpha.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/es/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #! /usr/bin/env node
2
- export {};
2
+ import './yolk';
package/es/index.js CHANGED
@@ -1,498 +1,2 @@
1
1
  #! /usr/bin/env node
2
- import e from "@babel/runtime/helpers/toArray";
3
-
4
- import t from "@babel/runtime/helpers/defineProperty";
5
-
6
- import s from "lodash/isString";
7
-
8
- import o from "lodash/pick";
9
-
10
- import r from "lodash/floor";
11
-
12
- import i from "lodash/chunk";
13
-
14
- function n(e, t) {
15
- var s = Object.keys(e);
16
- if (Object.getOwnPropertySymbols) {
17
- var o = Object.getOwnPropertySymbols(e);
18
- t && (o = o.filter((function(t) {
19
- return Object.getOwnPropertyDescriptor(e, t).enumerable;
20
- }))), s.push.apply(s, o);
21
- }
22
- return s;
23
- }
24
-
25
- function c(e) {
26
- for (var s = 1; s < arguments.length; s++) {
27
- var o = null != arguments[s] ? arguments[s] : {};
28
- s % 2 ? n(Object(o), !0).forEach((function(s) {
29
- t(e, s, o[s]);
30
- })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(o)) : n(Object(o)).forEach((function(t) {
31
- Object.defineProperty(e, t, Object.getOwnPropertyDescriptor(o, t));
32
- }));
33
- }
34
- return e;
35
- }
36
-
37
- import a from "fs";
38
-
39
- import m from "path";
40
-
41
- import p from "os";
42
-
43
- import l from "commander";
44
-
45
- import d from "inquirer";
46
-
47
- import { spawn as y, execSync as f } from "child_process";
48
-
49
- import u from "ora";
50
-
51
- import g from "glob";
52
-
53
- import h from "minimatch";
54
-
55
- import b from "mustache";
56
-
57
- import j from "mkdirp";
58
-
59
- import S from "rimraf";
60
-
61
- import { format as k } from "prettier";
62
-
63
- import * as x from "miniprogram-ci";
64
-
65
- import v from "../package.json";
66
-
67
- const w = require("staged-git-files"), $ = process.cwd(), P = "##### CREATED BY YOLK #####", O = {
68
- ts: "typescript",
69
- tsx: "typescript",
70
- less: "less",
71
- sass: "scss",
72
- scss: "scss",
73
- css: "css"
74
- }, E = "utf-8", F = 60, B = [ "**/node_modules/**", "**/.umi/**", "**/.umi-production/**", "**/build/**", "**/dist/**", "**/lib/**", "**/es/**", "**/public/**", "**/assets/**", "**/h5+app/**", "**/mock/**", "**/yolk/**", "**/yolk-web/**", "**/yolk-web-ui/**", "**/yolk-mobile/**", "**/yolk-mobile-ui/**", "**/yolk-miniprogram/**", "**/yolk-miniprogram-ui/**" ], D = u(), q = e => e && D.warn(Buffer.from(e, E).toString()), I = e => e && D.fail(Buffer.from(e, E).toString()), Q = e => e && D.succeed(Buffer.from(e, E).toString()), R = e => e && D.info(Buffer.from(e, E).toString()), T = e => "win32" === process.platform ? `${e}.cmd` : e, L = () => {
75
- Q("yolk complete!"), process.exit(0);
76
- }, N = () => {
77
- q("yolk break!"), process.exit(0);
78
- }, _ = ({command: e, args: t, complete: s, close: o, exit: r = !0}) => {
79
- const i = y(T(e), t || [], {
80
- stdio: "inherit"
81
- }).on("close", (e => {
82
- e ? (o && o(), I("yolk close!"), process.exit(e)) : (s && s(), r && L());
83
- }));
84
- process.on("SIGINT", (() => {
85
- l.runningCommand && l.runningCommand.kill("SIGKILL"), i.kill(), N();
86
- }));
87
- }, A = (e, t, s) => {
88
- d.prompt([ {
89
- type: "list",
90
- name: "type",
91
- message: "\u9009\u62e9\u6a21\u7248",
92
- default: "web",
93
- choices: [ {
94
- name: "web template(umi framework)",
95
- value: "umi-web"
96
- }, {
97
- name: "mobile template(umi framework)",
98
- value: "umi-mobile"
99
- }, {
100
- name: "web template(ice framework)",
101
- value: "ice-web"
102
- }, {
103
- name: "mobile template(ice framework)",
104
- value: "ice-mobile"
105
- }, {
106
- name: "miniprogram template",
107
- value: "miniprogram"
108
- } ]
109
- }, {
110
- type: "input",
111
- name: "projectName",
112
- message: "\u9879\u76ee\u540d\u79f0",
113
- default: m.basename(m.basename(process.cwd()))
114
- }, {
115
- type: "list",
116
- name: "dependenciesInstallType",
117
- message: "\u9009\u62e9\u4f9d\u8d56\u5b89\u88c5\u65b9\u5f0f",
118
- default: !1,
119
- choices: [ {
120
- name: "yarn install",
121
- value: "yarn"
122
- }, {
123
- name: "npm install",
124
- value: "npm"
125
- }, {
126
- name: "\u4e0d\u521d\u59cb\u5316",
127
- value: !1
128
- } ]
129
- } ]).then((o => {
130
- const r = {
131
- projectName: o.projectName,
132
- mobile: "umi-mobile" === o.type,
133
- dependenciesInstallType: o.dependenciesInstallType,
134
- yolkVersion: v.version
135
- };
136
- t || (t = m.join(__dirname, `../templates/${o.type}`)), Q(`\u590d\u5236\u6a21\u7248 ${m.basename(t)}`);
137
- const i = g.sync("**/*", {
138
- cwd: t,
139
- dot: !0,
140
- ignore: [ "**/node_modules/**", "**/.git/**", "**/.DS_Store", "**/.idea/**" ]
141
- });
142
- if (i.forEach((s => {
143
- if (!t) return;
144
- const o = m.join(t, s);
145
- if (!a.statSync(o).isDirectory()) if (s.endsWith(".tpl")) {
146
- const t = a.readFileSync(o, E), i = m.join(e, s.replace(/\.tpl$/u, "")), n = b.render(t, r);
147
- j.sync(m.dirname(i)), Q(`\u521b\u5efa ${m.relative(e, i)}`), a.writeFileSync(i, n, E);
148
- } else {
149
- Q(`\u521b\u5efa ${s}`);
150
- const t = m.join(e, s);
151
- j.sync(m.dirname(t)), a.copyFileSync(o, t);
152
- }
153
- })), Q("\u590d\u5236\u6a21\u7248 success!"), s && a.existsSync(t) && S(t, (() => {
154
- Q(`\u7f13\u5b58\u5220\u9664 success! ${m.basename(t || "")}`);
155
- })), o.dependenciesInstallType) switch (Q("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),
156
- o.dependenciesInstallType) {
157
- case "npm":
158
- _({
159
- command: "npm",
160
- args: [ "install" ]
161
- });
162
- break;
163
-
164
- case "yarn":
165
- default:
166
- _({
167
- command: "yarn",
168
- args: [ "install" ]
169
- });
170
- break;
171
- }
172
- Q("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863");
173
- }));
174
- }, K = (e, t) => A(e, t, !0), C = () => {
175
- const e = g.sync("*.yolkrc*", {
176
- cwd: $,
177
- dot: !0
178
- });
179
- if (!e.length) return {};
180
- const t = m.join($, e[0]);
181
- if (!a.existsSync(t)) return {};
182
- try {
183
- return JSON.parse(a.readFileSync(t, E)) || {};
184
- } catch (s) {
185
- return I(s.message || ".yolkrc\u8f6c\u6362\u9519\u8bef"), {};
186
- }
187
- }, J = () => {
188
- const e = m.join($, ".prettierrc");
189
- if (!a.existsSync(e)) {
190
- if (a.existsSync(require.resolve("@umijs/fabric/dist/prettier"))) {
191
- const e = require("@umijs/fabric/dist/prettier");
192
- return e;
193
- }
194
- return {};
195
- }
196
- try {
197
- return JSON.parse(a.readFileSync(e, E)) || {};
198
- } catch (t) {
199
- return I(t.message || ".prettierrc\u8f6c\u6362\u9519\u8bef"), {};
200
- }
201
- }, M = () => {
202
- const e = m.join($, "project.config.json");
203
- if (!a.existsSync(e)) return {};
204
- try {
205
- return JSON.parse(a.readFileSync(e, E)) || {};
206
- } catch (t) {
207
- return I(t.message || "project.config.json\u8f6c\u6362\u9519\u8bef"), {};
208
- }
209
- }, U = () => {
210
- const e = m.join($, "package.json");
211
- if (!a.existsSync(e)) return {};
212
- try {
213
- return JSON.parse(a.readFileSync(e, E)) || {};
214
- } catch (t) {
215
- return I(t.message || "package.json\u8f6c\u6362\u9519\u8bef"), {};
216
- }
217
- }, V = () => a.existsSync(m.join($, "project.config.json")), G = () => a.existsSync(m.join($, ".icerc.ts")) || a.existsSync(m.join($, ".icerc.js")) || a.existsSync(m.join($, ".ice.ts")) || a.existsSync(m.join($, ".ice.js")), H = () => a.existsSync(m.join($, ".icerc.ts")) ? ".icerc.ts" : a.existsSync(m.join($, ".icerc.js")) ? ".icerc.js" : a.existsSync(m.join($, ".ice.ts")) ? ".ice.ts" : ".ice.js", Y = () => {
218
- const e = m.join($, "project.config.json");
219
- if (a.existsSync(e)) {
220
- const t = require(e);
221
- return t.appid;
222
- }
223
- return "";
224
- }, W = () => a.existsSync(m.join($, "project.tt.json")) && 0 === Y().indexOf("tt"), z = () => 0 === Y().indexOf("20"), X = () => {
225
- const e = C(), t = V() ? require.resolve("@baic/eslint-config-yolk-miniprogram") : require.resolve("@baic/eslint-config-yolk"), s = g.sync("*.eslintrc*", {
226
- cwd: $,
227
- dot: !0
228
- }), o = s[0];
229
- return !1 === e.strict && o && a.existsSync(o) ? o : t;
230
- }, Z = () => {
231
- const e = g.sync("*.stylelintrc*", {
232
- cwd: $,
233
- dot: !0
234
- }), t = e[0];
235
- return t;
236
- }, ee = () => {
237
- const e = m.join($, ".git/"), t = m.join($, ".git/hooks"), s = m.join(t, "pre-commit"), o = a.existsSync(e), r = a.existsSync(s), i = r && a.readFileSync(s, "utf8").includes(P);
238
- if (o && (!r || !i)) {
239
- j.sync(t), a.writeFileSync(s, [ "#!/usr/bin/env bash", "npx yolk pre-commit", "RESULT=$?", "[ $RESULT -ne 0 ] && exit 1", "exit 0", P ].join(p.EOL), "utf8");
240
- try {
241
- a.chmodSync(s, "777");
242
- } catch (n) {
243
- I(`chmod ${s} failed: ${n.message}`);
244
- }
245
- Q("Create pre-commit hook");
246
- }
247
- }, te = () => {
248
- const e = C(), t = !1 !== e.strict, s = e.eslintIgnore, o = e.stylelintIgnore;
249
- w().then((e => {
250
- const r = new Promise(((s, r) => {
251
- const n = Z();
252
- if (n) {
253
- const p = e.map((e => e.filename)).filter((e => /^(src|tests)/iu.test(e))).filter((e => /\.(le|sa|sc|c)s{2}$/iu.test(e))).filter((e => B.every((t => !h(e, t, {
254
- matchBase: !0
255
- }))))).filter((e => "string" === typeof o ? !h(e, o, {
256
- matchBase: !0
257
- }) : o instanceof RegExp ? !o.test(e) : !Array.isArray(o) || o.every((t => "string" === typeof t ? !h(e, t, {
258
- matchBase: !0
259
- }) : !(t instanceof RegExp) || !t.test(e))))).map((e => {
260
- const t = m.join($, e);
261
- return a.existsSync(t) ? t : null;
262
- })).filter((e => !!e));
263
- if (p.forEach((e => {
264
- if (e && a.existsSync(e)) {
265
- const t = m.extname(e).replace(/^\./u, ""), s = a.readFileSync(e, "utf8"), o = k(s, c({
266
- parser: O[t]
267
- }, J()));
268
- a.writeFileSync(e, o, "utf8");
269
- }
270
- })), Q("style prettier success!"), p.length >= F) {
271
- const e = [];
272
- i(p, 20).forEach((s => {
273
- e.push(new Promise(((e, o) => {
274
- _({
275
- command: "stylelint",
276
- args: [ t ? "--ignore-disables" : "", "--allow-empty-input", "--config", n, ...s ],
277
- complete: e,
278
- close: o,
279
- exit: !1
280
- });
281
- })));
282
- }));
283
- const o = process.getMaxListeners(), c = i(e, o ? o / 2 : 2);
284
- let a = 0;
285
- const m = () => {
286
- a < c.length ? Promise.all(c[a]).then((() => {
287
- a++, m();
288
- })).catch(r) : s();
289
- };
290
- m();
291
- } else p.length && _({
292
- command: "stylelint",
293
- args: [ t ? "--ignore-disables" : "", "--allow-empty-input", "--config", n, ...p ],
294
- complete: s,
295
- close: r,
296
- exit: !1
297
- });
298
- } else s();
299
- })), n = () => {
300
- const o = e.map((e => e.filename)).filter((e => /^(src|tests)/iu.test(e))).filter((e => /\.([t|j]sx?)$/iu.test(e))).map((e => {
301
- const t = m.join($, e);
302
- return a.existsSync(t) ? t : null;
303
- })).filter((e => !!e));
304
- if (o.length) {
305
- o.forEach((e => {
306
- if (e && a.existsSync(e)) {
307
- const t = m.extname(e).replace(/^\./u, ""), s = a.readFileSync(e, "utf8"), o = k(s, c({
308
- parser: O[t]
309
- }, J()));
310
- a.writeFileSync(e, o, "utf8");
311
- }
312
- })), Q("script prettier success!");
313
- const e = X();
314
- if (e) {
315
- const r = o.filter((e => B.every((t => !h(e, t, {
316
- matchBase: !0
317
- }))))).filter((e => "string" === typeof s ? !h(e, s, {
318
- matchBase: !0
319
- }) : s instanceof RegExp ? !s.test(e) : !Array.isArray(s) || s.every((t => "string" === typeof t ? !h(e, t, {
320
- matchBase: !0
321
- }) : !(t instanceof RegExp) || !t.test(e)))));
322
- if (t && (q("git commit\u7981\u6b62eslint\u7684ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u3002"),
323
- s && q(`\u901a\u8fc7yolkrc\u914d\u7f6eeslintIgnore\uff1a${s}\u3002`)), r.length >= F) {
324
- const s = [];
325
- i(r, 20).forEach((o => {
326
- s.push(new Promise((s => {
327
- _({
328
- command: "eslint",
329
- args: [ t ? "--no-inline-config --no-ignore" : "", "--no-error-on-unmatched-pattern", "--config", e, ...o ],
330
- complete: s,
331
- exit: !1
332
- });
333
- })));
334
- }));
335
- const o = process.getMaxListeners(), n = i(s, o ? o / 2 : 2);
336
- let c = 0;
337
- const a = () => {
338
- c < n.length ? Promise.all(n[c]).then((() => {
339
- c++, a();
340
- })) : L();
341
- };
342
- a();
343
- } else r.length && _({
344
- command: "eslint",
345
- args: [ t ? "--no-inline-config --no-ignore" : "", "--no-error-on-unmatched-pattern", "--config", e, ...r ]
346
- });
347
- } else q("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6");
348
- } else L();
349
- };
350
- q("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),
351
- r.then(n);
352
- }));
353
- }, se = ({mProject: e, mPrivateKeyPath: t, mVersion: s, mDesc: o, mRobot: r, mQrcodeFormat: i, mQrcodeOutputDest: n, mPagePath: c, mSearchQuery: p}) => {
354
- const l = a.existsSync(m.join($, ".git")) ? f("git log -1 --pretty=format:%H").toString() : "", d = M(), y = d.appid, u = e || m.join($, "dist"), g = t || m.join($, `private.${y}.key`);
355
- if (a.existsSync(u)) {
356
- if (a.existsSync(g)) {
357
- const e = U(), t = s || e.version || d.version || "1.0.0", a = o || e.description || d.description, m = `version: ${t};${l ? ` commit: ${l};` : ""}${a ? ` description: ${a};` : ""}`;
358
- l && R(`commit: ${l}`), R(`dist: ${u}`), R(`key: ${g}`), R(`appid: ${y}`), R(`version: ${t}`),
359
- R(`desc: ${m}`);
360
- const f = new x.Project({
361
- appid: y,
362
- type: "miniProgram",
363
- projectPath: u,
364
- privateKeyPath: g,
365
- ignores: [ "node_modules/**/*", "**/*.txt", "**/*.key", "**/*.less", "**/*.sass", "**/*.scss", "**/*.css", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/*.md" ]
366
- });
367
- return {
368
- appid: y,
369
- options: {
370
- project: f,
371
- version: t,
372
- desc: m,
373
- setting: d.setting,
374
- robot: r,
375
- qrcodeFormat: i,
376
- qrcodeOutputDest: n,
377
- pagePath: c,
378
- searchQuery: p
379
- }
380
- };
381
- }
382
- throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${g})`);
383
- }
384
- throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${u})`);
385
- }, oe = () => {
386
- ee(), process.argv.length > 2 ? l.version(v.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(((t, i) => {
387
- const n = e(i), l = n[0], d = n.slice(1), y = t.clone, f = t.template, u = t.docs;
388
- if (l) switch (R(`yolk version: ${v.version}`), R(`node version: ${process.version}`),
389
- R(`platform: ${p.platform()}`), R(`memory: ${r(p.freemem() / 1024 / 1024)} MB(${r(p.totalmem() / 1024 / 1024)} MB)`),
390
- l) {
391
- case "init":
392
- if (Q(`yolk ${l} \u5f00\u59cb`), y) if (f) {
393
- const e = ".yolk", t = m.join($, e);
394
- a.existsSync(t) && S(t, (() => {
395
- Q(`\u7f13\u5b58\u5220\u9664 success! ${t}`);
396
- })), _({
397
- command: "git",
398
- args: [ "clone", "-b", "master", "--depth", "1", f, e ].concat(d)
399
- }), K($, t);
400
- } else I("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template"); else A($);
401
- break;
402
-
403
- case "start":
404
- V() ? W() ? _({
405
- command: "taro",
406
- args: [ "build", "--type", "tt", "--watch" ].concat(d)
407
- }) : z() ? _({
408
- command: "taro",
409
- args: [ "build", "--type", "alipay", "--watch" ].concat(d)
410
- }) : _({
411
- command: "taro",
412
- args: [ "build", "--type", "weapp", "--watch" ].concat(d)
413
- }) : u ? _({
414
- command: "dumi",
415
- args: [ "dev" ].concat(d)
416
- }) : G() ? _({
417
- command: "icejs",
418
- args: [ "start", "--config", H() ].concat(d)
419
- }) : _({
420
- command: "max",
421
- args: [ "dev" ].concat(d)
422
- });
423
- break;
424
-
425
- case "build":
426
- V() ? W() ? _({
427
- command: "taro",
428
- args: [ "build", "--type", "tt" ].concat(d)
429
- }) : z() ? _({
430
- command: "taro",
431
- args: [ "build", "--type", "alipay" ].concat(d)
432
- }) : _({
433
- command: "taro",
434
- args: [ "build", "--type", "weapp" ].concat(d)
435
- }) : u ? _({
436
- command: "dumi",
437
- args: [ "build" ].concat(d)
438
- }) : G() ? _({
439
- command: "icejs",
440
- args: [ "build", "--config", H() ].concat(d)
441
- }) : _({
442
- command: "max",
443
- args: [ "build" ].concat(d)
444
- });
445
- break;
446
-
447
- case "pre-commit":
448
- te();
449
- break;
450
-
451
- case "test":
452
- _({
453
- command: "umi-test",
454
- args: [ "--no-cache", "--update-snapshot", "--runInBand", "--detectOpenHandles" ].concat(d)
455
- });
456
- break;
457
-
458
- case "miniapp-upload":
459
- case "miniprogram-upload":
460
- if (V()) if (W()) ; else if (z()) ; else {
461
- const e = se(t), r = e.appid, i = e.options;
462
- R(`${r}\u4e0a\u4f20\u5f00\u59cb`), x.upload(c(c({}, o(i, [ "project", "version", "desc", "setting", "robot" ])), {}, {
463
- onProgressUpdate: e => {
464
- if (s(e)) R(`task: ${e}`); else {
465
- const t = e.status, s = e.message;
466
- R(`task(${t}): ${s}`);
467
- }
468
- }
469
- })).then((() => {
470
- Q(`${r}\u4e0a\u4f20\u5b8c\u6210`);
471
- }));
472
- }
473
- break;
474
-
475
- case "miniapp-preview":
476
- case "miniprogram-preview":
477
- if (V()) if (W()) ; else if (z()) ; else {
478
- const e = se(t), r = e.appid, i = e.options;
479
- R(`${r}\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`), x.preview(c(c({}, o(i, [ "project", "version", "desc", "setting", "robot", "qrcodeFormat", "qrcodeOutputDest", "pagePath", "searchQuery" ])), {}, {
480
- onProgressUpdate: e => {
481
- if (s(e)) R(`task: ${e}`); else {
482
- const t = e.status, s = e.message;
483
- R(`task(${t}): ${s}`);
484
- }
485
- }
486
- })).then((() => {
487
- Q(`${r}\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`);
488
- }));
489
- }
490
- break;
491
-
492
- default:
493
- N();
494
- }
495
- })).parse(process.argv) : N();
496
- };
497
-
498
- oe();
2
+ import"./yolk";
package/es/yolk.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ export {};
package/es/yolk.js ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ import e from"@babel/runtime/helpers/toArray";import t from"@babel/runtime/helpers/defineProperty";import o from"lodash/isString";import s from"lodash/pick";import r from"lodash/floor";import i from"lodash/chunk";function n(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,s)}return o}function c(e){for(var o=1;o<arguments.length;o++){var s=null!=arguments[o]?arguments[o]:{};o%2?n(Object(s),!0).forEach((function(o){t(e,o,s[o])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(s)):n(Object(s)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(s,t))}))}return e}import{execSync as a,spawn as m}from"child_process";import p from"commander";import l from"fs";import d from"glob";import u from"inquirer";import y from"minimatch";import*as f from"miniprogram-ci";import g from"mkdirp";import h from"mustache";import b from"ora";import j from"os";import S from"path";import{format as k}from"prettier";import x from"rimraf";import v from"../package.json";const w=require("staged-git-files"),$=process.cwd(),P="##### CREATED BY YOLK #####",O={ts:"typescript",tsx:"typescript",less:"less",sass:"scss",scss:"scss",css:"css"},E="utf-8",F=60,B=["**/node_modules/**","**/.umi/**","**/.umi-production/**","**/build/**","**/dist/**","**/lib/**","**/es/**","**/public/**","**/assets/**","**/h5+app/**","**/mock/**","**/yolk/**","**/yolk-web/**","**/yolk-web-ui/**","**/yolk-mobile/**","**/yolk-mobile-ui/**","**/yolk-miniprogram/**","**/yolk-miniprogram-ui/**"],D=b(),I=e=>e&&D.warn(Buffer.from(e,E).toString()),q=e=>e&&D.fail(Buffer.from(e,E).toString()),Q=e=>e&&D.succeed(Buffer.from(e,E).toString()),R=e=>e&&D.info(Buffer.from(e,E).toString()),T=e=>"win32"===process.platform?`${e}.cmd`:e,L=()=>{Q("yolk complete!"),process.exit(0)},N=()=>{I("yolk break!"),process.exit(0)},_=({command:e,args:t,complete:o,close:s,exit:r=!0})=>{const i=m(T(e),t||[],{stdio:"inherit"}).on("close",(e=>{e?(s&&s(),q("yolk close!"),process.exit(e)):(o&&o(),r&&L())}));process.on("SIGINT",(()=>{p.runningCommand&&p.runningCommand.kill("SIGKILL"),i.kill(),N()}))},A=(e,t,o)=>{u.prompt([{type:"list",name:"type",message:"\u9009\u62e9\u6a21\u7248",default:"web",choices:[{name:"web template(umi framework)",value:"umi-web"},{name:"mobile template(umi framework)",value:"umi-mobile"},{name:"web template(ice framework)",value:"ice-web"},{name:"mobile template(ice framework)",value:"ice-mobile"},{name:"miniprogram template",value:"miniprogram"}]},{type:"input",name:"projectName",message:"\u9879\u76ee\u540d\u79f0",default:S.basename(S.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((s=>{const r={projectName:s.projectName,mobile:"umi-mobile"===s.type,dependenciesInstallType:s.dependenciesInstallType,yolkVersion:v.version};t||(t=S.join(__dirname,`../templates/${s.type}`)),Q(`\u590d\u5236\u6a21\u7248 ${S.basename(t)}`);const i=d.sync("**/*",{cwd:t,dot:!0,ignore:["**/node_modules/**","**/.git/**","**/.DS_Store","**/.idea/**"]});if(i.forEach((o=>{if(!t)return;const s=S.join(t,o);if(!l.statSync(s).isDirectory())if(o.endsWith(".tpl")){const t=l.readFileSync(s,E),i=S.join(e,o.replace(/\.tpl$/u,"")),n=h.render(t,r);g.sync(S.dirname(i)),Q(`\u521b\u5efa ${S.relative(e,i)}`),l.writeFileSync(i,n,E)}else{Q(`\u521b\u5efa ${o}`);const t=S.join(e,o);g.sync(S.dirname(t)),l.copyFileSync(s,t)}})),Q("\u590d\u5236\u6a21\u7248 success!"),o&&l.existsSync(t)&&x(t,(()=>{Q(`\u7f13\u5b58\u5220\u9664 success! ${S.basename(t||"")}`)})),s.dependenciesInstallType)switch(Q("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),s.dependenciesInstallType){case"npm":_({command:"npm",args:["install"]});break;case"yarn":default:_({command:"yarn",args:["install"]});break}Q("\u53ef\u67e5\u9605<<https://303394539.github.io/yolk-docs/>>\u4e86\u89e3\u76f8\u5173\u6587\u6863")}))},K=(e,t)=>A(e,t,!0),C=()=>{const e=d.sync("*.yolkrc*",{cwd:$,dot:!0});if(!e.length)return{};const t=S.join($,e[0]);if(!l.existsSync(t))return{};try{return JSON.parse(l.readFileSync(t,E))||{}}catch(o){return q(o.message||".yolkrc\u8f6c\u6362\u9519\u8bef"),{}}},J=()=>{const e=S.join($,".prettierrc");if(l.existsSync(e))try{return JSON.parse(l.readFileSync(e,E))||{}}catch(t){return q(t.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}return{singleQuote:!0,trailingComma:"all",printWidth:80,overrides:[{files:".prettierrc",options:{parser:"json"}}]}},M=()=>{const e=S.join($,"project.config.json");if(!l.existsSync(e))return{};try{return JSON.parse(l.readFileSync(e,E))||{}}catch(t){return q(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},U=()=>{const e=S.join($,"package.json");if(!l.existsSync(e))return{};try{return JSON.parse(l.readFileSync(e,E))||{}}catch(t){return q(t.message||"package.json\u8f6c\u6362\u9519\u8bef"),{}}},V=()=>l.existsSync(S.join($,"project.config.json")),G=()=>l.existsSync(S.join($,".icerc.ts"))||l.existsSync(S.join($,".icerc.js"))||l.existsSync(S.join($,".ice.ts"))||l.existsSync(S.join($,".ice.js")),H=()=>l.existsSync(require.resolve("@umijs/max")),W=()=>l.existsSync(S.join($,".icerc.ts"))?".icerc.ts":l.existsSync(S.join($,".icerc.js"))?".icerc.js":l.existsSync(S.join($,".ice.ts"))?".ice.ts":".ice.js",Y=()=>{const e=S.join($,"project.config.json");if(l.existsSync(e)){const t=require(e);return t.appid}return""},z=()=>l.existsSync(S.join($,"project.tt.json"))&&0===Y().indexOf("tt"),X=()=>0===Y().indexOf("20"),Z=()=>{const e=C(),t=V()?require.resolve("@baic/eslint-config-yolk-miniprogram"):require.resolve("@baic/eslint-config-yolk"),o=d.sync("*.eslintrc*",{cwd:$,dot:!0}),s=o[0];return!1===e.strict&&s&&l.existsSync(s)?s:t},ee=()=>{const e=d.sync("*.stylelintrc*",{cwd:$,dot:!0}),t=e[0];return t},te=()=>{const e=S.join($,".git/"),t=S.join($,".git/hooks"),o=S.join(t,"pre-commit"),s=l.existsSync(e),r=l.existsSync(o),i=r&&l.readFileSync(o,"utf8").includes(P);if(s&&(!r||!i)){g.sync(t),l.writeFileSync(o,["#!/usr/bin/env bash","npx yolk pre-commit","RESULT=$?","[ $RESULT -ne 0 ] && exit 1","exit 0",P].join(j.EOL),"utf8");try{l.chmodSync(o,"777")}catch(n){q(`chmod ${o} failed: ${n.message}`)}Q("Create pre-commit hook")}},oe=()=>{const e=C(),t=!1!==e.strict,o=e.eslintIgnore,s=e.stylelintIgnore;w().then((e=>{const r=new Promise(((o,r)=>{const n=ee();if(n){const a=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>/\.(le|sa|sc|c)s{2}$/iu.test(e))).filter((e=>B.every((t=>!y(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof s?!y(e,s,{matchBase:!0}):s instanceof RegExp?!s.test(e):!Array.isArray(s)||s.every((t=>"string"===typeof t?!y(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e))))).map((e=>{const t=S.join($,e);return l.existsSync(t)?t:null})).filter((e=>!!e));if(a.forEach((e=>{if(e&&l.existsSync(e)){const t=S.extname(e).replace(/^\./u,""),o=l.readFileSync(e,"utf8"),s=k(o,c({parser:O[t]},J()));l.writeFileSync(e,s,"utf8")}})),Q("style prettier success!"),a.length>=F){const e=[];i(a,20).forEach((o=>{e.push(new Promise(((e,s)=>{_({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",n,...o],complete:e,close:s,exit:!1})})))}));const s=process.getMaxListeners(),c=i(e,s?s/2:2);let m=0;const p=()=>{m<c.length?Promise.all(c[m]).then((()=>{m++,p()})).catch(r):o()};p()}else a.length&&_({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",n,...a],complete:o,close:r,exit:!1})}else o()})),n=()=>{const s=e.map((e=>e.filename)).filter((e=>/^(src|tests)/iu.test(e))).filter((e=>/\.([t|j]sx?)$/iu.test(e))).map((e=>{const t=S.join($,e);return l.existsSync(t)?t:null})).filter((e=>!!e));if(s.length){s.forEach((e=>{if(e&&l.existsSync(e)){const t=S.extname(e).replace(/^\./u,""),o=l.readFileSync(e,"utf8"),s=k(o,c({parser:O[t]},J()));l.writeFileSync(e,s,"utf8")}})),Q("script prettier success!");const e=Z();if(e){const r=s.filter((e=>B.every((t=>!y(e,t,{matchBase:!0}))))).filter((e=>"string"===typeof o?!y(e,o,{matchBase:!0}):o instanceof RegExp?!o.test(e):!Array.isArray(o)||o.every((t=>"string"===typeof t?!y(e,t,{matchBase:!0}):!(t instanceof RegExp)||!t.test(e)))));if(t&&(I("git commit\u7981\u6b62eslint\u7684ignore\u65b9\u5f0f(eslint-disable\u3001.eslintrc*\u3001ignore\u7b49)\u3002"),o&&I(`\u901a\u8fc7yolkrc\u914d\u7f6eeslintIgnore\uff1a${o}\u3002`)),r.length>=F){const o=[];i(r,20).forEach((s=>{o.push(new Promise((o=>{_({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",e,...s],complete:o,exit:!1})})))}));const s=process.getMaxListeners(),n=i(o,s?s/2:2);let c=0;const a=()=>{c<n.length?Promise.all(n[c]).then((()=>{c++,a()})):L()};a()}else r.length&&_({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",e,...r]})}else I("\u6ca1\u6709eslint\u914d\u7f6e\u6587\u4ef6")}else L()};I("\u8981\u6c42\u7edf\u4e00\u4ee3\u7801\u89c4\u8303\uff0c\u8fdb\u884c\u4e25\u683c\u7684\u8bed\u6cd5\u68c0\u67e5\u3002"),r.then(n)}))},se=({mProject:e,mPrivateKeyPath:t,mVersion:o,mDesc:s,mRobot:r,mQrcodeFormat:i,mQrcodeOutputDest:n,mPagePath:c,mSearchQuery:m})=>{const p=l.existsSync(S.join($,".git"))?a("git log -1 --pretty=format:%H").toString():"",d=M(),u=d.appid,y=e||S.join($,"dist"),g=t||S.join($,`private.${u}.key`);if(l.existsSync(y)){if(l.existsSync(g)){const e=U(),t=o||e.version||d.version||"1.0.0",a=s||e.description||d.description,l=`version: ${t};${p?` commit: ${p};`:""}${a?` description: ${a};`:""}`;p&&R(`commit: ${p}`),R(`dist: ${y}`),R(`key: ${g}`),R(`appid: ${u}`),R(`version: ${t}`),R(`desc: ${l}`);const h=new f.Project({appid:u,type:"miniProgram",projectPath:y,privateKeyPath:g,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{appid:u,options:{project:h,version:t,desc:l,setting:d.setting,robot:r,qrcodeFormat:i,qrcodeOutputDest:n,pagePath:c,searchQuery:m}}}throw Error(`\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(${g})`)}throw Error(`\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(${y})`)},re=()=>{te(),process.argv.length>2?p.version(v.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(((t,i)=>{const n=e(i),a=n[0],m=n.slice(1),p=t.clone,d=t.template,u=t.docs;if(a)switch(R(`yolk version: ${v.version}`),R(`node version: ${process.version}`),R(`platform: ${j.platform()}`),R(`memory: ${r(j.freemem()/1024/1024)} MB(${r(j.totalmem()/1024/1024)} MB)`),a){case"init":if(Q(`yolk ${a} \u5f00\u59cb`),p)if(d){const e=".yolk",t=S.join($,e);l.existsSync(t)&&x(t,(()=>{Q(`\u7f13\u5b58\u5220\u9664 success! ${t}`)})),_({command:"git",args:["clone","-b","master","--depth","1",d,e].concat(m)}),K($,t)}else q("--clone \u6a21\u5f0f\u5fc5\u987b\u6709--template");else A($);break;case"start":V()?z()?_({command:"taro",args:["build","--type","tt","--watch"].concat(m)}):X()?_({command:"taro",args:["build","--type","alipay","--watch"].concat(m)}):_({command:"taro",args:["build","--type","weapp","--watch"].concat(m)}):u?_({command:"dumi",args:["dev"].concat(m)}):G()?_({command:"icejs",args:["start","--config",W()].concat(m)}):H()?_({command:"max",args:["dev"].concat(m)}):_({command:"umi",args:["dev"].concat(m)});break;case"build":V()?z()?_({command:"taro",args:["build","--type","tt"].concat(m)}):X()?_({command:"taro",args:["build","--type","alipay"].concat(m)}):_({command:"taro",args:["build","--type","weapp"].concat(m)}):u?_({command:"dumi",args:["build"].concat(m)}):G()?_({command:"icejs",args:["build","--config",W()].concat(m)}):H()?_({command:"max",args:["build"].concat(m)}):_({command:"umi",args:["build"].concat(m)});break;case"pre-commit":oe();break;case"test":_({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(m)});break;case"miniapp-upload":case"miniprogram-upload":if(V())if(z());else if(X());else{const e=se(t),r=e.appid,i=e.options;R(`${r}\u4e0a\u4f20\u5f00\u59cb`),f.upload(c(c({},s(i,["project","version","desc","setting","robot"])),{},{onProgressUpdate:e=>{if(o(e))R(`task: ${e}`);else{const t=e.status,o=e.message;R(`task(${t}): ${o}`)}}})).then((()=>{Q(`${r}\u4e0a\u4f20\u5b8c\u6210`)}))}break;case"miniapp-preview":case"miniprogram-preview":if(V())if(z());else if(X());else{const e=se(t),r=e.appid,i=e.options;R(`${r}\u4e0a\u4f20\u9884\u89c8\u5f00\u59cb`),f.preview(c(c({},s(i,["project","version","desc","setting","robot","qrcodeFormat","qrcodeOutputDest","pagePath","searchQuery"])),{},{onProgressUpdate:e=>{if(o(e))R(`task: ${e}`);else{const t=e.status,o=e.message;R(`task(${t}): ${o}`)}}})).then((()=>{Q(`${r}\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210`)}))}break;default:N()}})).parse(process.argv):N()};re();
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #! /usr/bin/env node
2
- export {};
2
+ import './yolk';