@baic/yolk-cli 1.0.20 → 2.0.1-alpha.1

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/bin/index.js CHANGED
@@ -1,809 +1,2 @@
1
1
  #! /usr/bin/env node
2
- import fs from 'fs';
3
- import path from 'path';
4
- import os from 'os';
5
- import commander from 'commander';
6
- import inquirer from 'inquirer';
7
- import { spawn, execSync } from 'child_process';
8
- import ora from 'ora';
9
- import glob from 'glob';
10
- import minimatch from 'minimatch';
11
- import Mustache from 'mustache';
12
- import mkdirp from 'mkdirp';
13
- import rimraf from 'rimraf';
14
- import { format } from 'prettier';
15
- import _ from 'lodash';
16
- import * as miniProgramCi from 'miniprogram-ci';
17
- import Package from '../package.json';
18
- const sgf = require('staged-git-files');
19
- const cwd = process.cwd();
20
- const HOOK_MARK = '##### CREATED BY YOLK #####';
21
- const PRETTIER_PARSER = {
22
- // js: "babel",
23
- // jsx: "babel",
24
- ts: 'typescript',
25
- tsx: 'typescript',
26
- };
27
- const ENCODING = 'utf-8';
28
- const MAX_FILE_COUNT = 20 * 3;
29
- const spinner = ora();
30
- const warn = (text) => text && spinner.warn(Buffer.from(text, ENCODING).toString());
31
- const fail = (text) => text && spinner.fail(Buffer.from(text, ENCODING).toString());
32
- const succeed = (text) => text && spinner.succeed(Buffer.from(text, ENCODING).toString());
33
- const info = (text) => text && spinner.info(Buffer.from(text, ENCODING).toString());
34
- const getCommand = (command) => process.platform === 'win32' ? `${command}.cmd` : command;
35
- const completeExit = () => {
36
- succeed('yolk complete!');
37
- process.exit(0);
38
- };
39
- const breakExit = () => {
40
- warn('yolk break!');
41
- process.exit(0);
42
- };
43
- const execCommand = ({ command, args, complete, close, exit = true, }) => {
44
- const child = spawn(getCommand(command), args || [], {
45
- stdio: 'inherit',
46
- }).on('close', (code) => {
47
- if (code) {
48
- if (close) {
49
- close();
50
- }
51
- fail('yolk close!');
52
- process.exit(code);
53
- }
54
- else {
55
- if (complete) {
56
- complete();
57
- }
58
- if (exit) {
59
- completeExit();
60
- }
61
- }
62
- });
63
- process.on('SIGINT', () => {
64
- commander.runningCommand && commander.runningCommand.kill('SIGKILL');
65
- child.kill();
66
- breakExit();
67
- });
68
- };
69
- const createTemplate = (processCwd, template, isTmp) => {
70
- inquirer
71
- .prompt([
72
- {
73
- type: 'list',
74
- name: 'type',
75
- message: '选择平台',
76
- default: 'web',
77
- choices: [
78
- { name: 'web', value: 'web' },
79
- { name: 'mobile', value: 'mobile' },
80
- { name: '小程序', value: 'miniapp' },
81
- ],
82
- },
83
- {
84
- type: 'input',
85
- name: 'projectName',
86
- message: '项目名称',
87
- default: path.basename(path.basename(process.cwd())),
88
- },
89
- {
90
- type: 'list',
91
- name: 'dependenciesInstallType',
92
- message: '选择依赖安装方式',
93
- default: false,
94
- choices: [
95
- { name: 'yarn install', value: 'yarn' },
96
- { name: 'npm install', value: 'npm' },
97
- { name: '不初始化', value: false },
98
- ],
99
- },
100
- ])
101
- .then((res) => {
102
- const context = {
103
- projectName: res.projectName,
104
- mobile: res.type === 'mobile',
105
- dependenciesInstallType: res.dependenciesInstallType,
106
- };
107
- if (!template) {
108
- template = path.join(__dirname, `../templates/${res.type}/${template || 'base'}`);
109
- }
110
- succeed(`复制模版 ${path.basename(template)}`);
111
- const files = glob.sync('**/*', {
112
- cwd: template,
113
- dot: true,
114
- ignore: [
115
- '**/node_modules/**',
116
- '**/.git/**',
117
- '**/.DS_Store',
118
- '**/.idea/**',
119
- ],
120
- });
121
- files.forEach((file) => {
122
- if (!template) {
123
- return;
124
- }
125
- const absFile = path.join(template, file);
126
- if (fs.statSync(absFile).isDirectory())
127
- return;
128
- if (file.endsWith('.tpl')) {
129
- const tpl = fs.readFileSync(absFile, ENCODING);
130
- const tplTarget = path.join(processCwd, file.replace(/\.tpl$/, ''));
131
- const content = Mustache.render(tpl, context);
132
- mkdirp.sync(path.dirname(tplTarget));
133
- succeed(`创建 ${path.relative(processCwd, tplTarget)}`);
134
- fs.writeFileSync(tplTarget, content, ENCODING);
135
- }
136
- else {
137
- succeed(`创建 ${file}`);
138
- const absTarget = path.join(processCwd, file);
139
- mkdirp.sync(path.dirname(absTarget));
140
- fs.copyFileSync(absFile, absTarget);
141
- }
142
- });
143
- succeed('复制模版 success!');
144
- if (isTmp && fs.existsSync(template)) {
145
- rimraf(template, () => {
146
- succeed(`缓存删除 success! ${path.basename(template || '')}`);
147
- });
148
- }
149
- if (res.dependenciesInstallType) {
150
- succeed('初始化依赖包');
151
- switch (res.dependenciesInstallType) {
152
- case 'npm':
153
- execCommand({
154
- command: 'npm',
155
- args: ['install'],
156
- });
157
- break;
158
- case 'yarn':
159
- default:
160
- execCommand({
161
- command: 'yarn',
162
- args: ['install'],
163
- });
164
- break;
165
- }
166
- }
167
- succeed('可查阅<<https://303394539.github.io/yolk-docs/>>了解相关文档');
168
- });
169
- };
170
- const createGitTemplate = (processCwd, template) => createTemplate(processCwd, template, true);
171
- const getYolkConfig = () => {
172
- const yolkPaths = glob.sync('*.yolkrc*', {
173
- cwd,
174
- dot: true,
175
- });
176
- if (!yolkPaths.length) {
177
- return {};
178
- }
179
- const yolkPath = path.join(cwd, yolkPaths[0]);
180
- if (fs.existsSync(yolkPath)) {
181
- try {
182
- return JSON.parse(fs.readFileSync(yolkPath, ENCODING)) || {};
183
- }
184
- catch (error) {
185
- fail(error.message || '.yolkrc转换错误');
186
- return {};
187
- }
188
- }
189
- else {
190
- return {};
191
- }
192
- };
193
- const getPrettierConfig = () => {
194
- const prettierrcPath = path.join(cwd, '.prettierrc');
195
- if (fs.existsSync(prettierrcPath)) {
196
- try {
197
- return JSON.parse(fs.readFileSync(prettierrcPath, ENCODING)) || {};
198
- }
199
- catch (error) {
200
- fail(error.message || '.prettierrc转换错误');
201
- return {};
202
- }
203
- }
204
- else {
205
- if (fs.existsSync(require.resolve('@umijs/fabric/dist/prettier'))) {
206
- const templateConfig = require('@umijs/fabric/dist/prettier');
207
- return templateConfig;
208
- }
209
- return {};
210
- }
211
- };
212
- const getProjectConfigJSON = () => {
213
- const projectConfigJSONPath = path.join(cwd, 'project.config.json');
214
- if (fs.existsSync(projectConfigJSONPath)) {
215
- try {
216
- return JSON.parse(fs.readFileSync(projectConfigJSONPath, ENCODING)) || {};
217
- }
218
- catch (error) {
219
- fail(error.message || 'project.config.json转换错误');
220
- return {};
221
- }
222
- }
223
- else {
224
- return {};
225
- }
226
- };
227
- const getPackageJSON = () => {
228
- const packageJSONPath = path.join(cwd, 'package.json');
229
- if (fs.existsSync(packageJSONPath)) {
230
- try {
231
- return JSON.parse(fs.readFileSync(packageJSONPath, ENCODING)) || {};
232
- }
233
- catch (error) {
234
- fail(error.message || 'package.json转换错误');
235
- return {};
236
- }
237
- }
238
- else {
239
- return {};
240
- }
241
- };
242
- const isMiniapp = () => fs.existsSync(path.join(cwd, 'project.config.json'));
243
- const getAppid = () => {
244
- const projectConfigJson = path.join(cwd, 'project.config.json');
245
- if (fs.existsSync(projectConfigJson)) {
246
- const config = require(projectConfigJson);
247
- return config.appid;
248
- }
249
- return '';
250
- };
251
- const isWX = () => getAppid().indexOf('wx') === 0;
252
- const isTT = () => fs.existsSync(path.join(cwd, 'project.tt.json')) &&
253
- getAppid().indexOf('tt') === 0;
254
- const isAlipay = () => getAppid().indexOf('20') === 0;
255
- const getEsLintConfigPath = () => {
256
- /** eslint是强制检查 */
257
- const yolkConfig = getYolkConfig();
258
- const templateLintPath = isMiniapp()
259
- ? require.resolve('@baic/eslint-config-yolk-miniapp')
260
- : require.resolve('@baic/eslint-config-yolk');
261
- const eslintrcPaths = glob.sync('*.eslintrc*', {
262
- cwd,
263
- dot: true,
264
- });
265
- const lintPath = eslintrcPaths[0];
266
- if (yolkConfig.strict === false && lintPath && fs.existsSync(lintPath)) {
267
- return lintPath;
268
- }
269
- else {
270
- return templateLintPath;
271
- }
272
- };
273
- const getStyleLintConfigPath = () => {
274
- /** stylelint是辅助检查 */
275
- // const yolkConfig = getYolkConfig();
276
- // const templateLintPath = require.resolve('@baic/stylelint-config-yolk');
277
- const stylelintrcPaths = glob.sync('*.stylelintrc*', {
278
- cwd,
279
- dot: true,
280
- });
281
- const lintPath = stylelintrcPaths[0];
282
- return lintPath;
283
- };
284
- const initPreCommit = () => {
285
- const gitPath = path.join(cwd, '.git/');
286
- const hookPath = path.join(cwd, '.git/hooks');
287
- const preCommitHooks = path.join(hookPath, 'pre-commit');
288
- const existGit = fs.existsSync(gitPath);
289
- const existHooks = fs.existsSync(preCommitHooks);
290
- const isYolkPreCommit = existHooks && fs.readFileSync(preCommitHooks, 'utf8').includes(HOOK_MARK);
291
- if (existGit) {
292
- if (!existHooks || !isYolkPreCommit) {
293
- // Create hook path
294
- mkdirp.sync(hookPath);
295
- fs.writeFileSync(preCommitHooks, [
296
- '#!/usr/bin/env bash',
297
- 'npx yolk pre-commit',
298
- 'RESULT=$?',
299
- '[ $RESULT -ne 0 ] && exit 1',
300
- 'exit 0',
301
- HOOK_MARK,
302
- ].join(os.EOL), 'utf8');
303
- try {
304
- fs.chmodSync(preCommitHooks, '777');
305
- }
306
- catch (e) {
307
- fail(`chmod ${preCommitHooks} failed: ${e.message}`);
308
- }
309
- succeed('Create pre-commit hook');
310
- }
311
- }
312
- };
313
- const preCommit = () => {
314
- const yolkConfig = getYolkConfig();
315
- const isStrict = yolkConfig.strict !== false;
316
- const eslintIgnore = yolkConfig.eslintIgnore;
317
- const stylelintIgnore = yolkConfig.stylelintIgnore;
318
- sgf().then((files) => {
319
- const stylelint = new Promise((resolve, reject) => {
320
- // stylelint
321
- const styleLintConfigPath = getStyleLintConfigPath();
322
- if (styleLintConfigPath) {
323
- const styleFileList = files
324
- .map((file) => file.filename)
325
- .filter((filename) => /^(src|tests)/iu.test(filename))
326
- .filter((filename) => /\.(le|sa|sc|c)s{2}$/iu.test(filename))
327
- .filter((filename) => {
328
- if (typeof stylelintIgnore === 'string') {
329
- return !minimatch(filename, stylelintIgnore, { matchBase: true });
330
- }
331
- else if (stylelintIgnore instanceof RegExp) {
332
- return !stylelintIgnore.test(filename);
333
- }
334
- else if (Array.isArray(stylelintIgnore)) {
335
- return stylelintIgnore.every((item) => {
336
- if (typeof item === 'string') {
337
- return !minimatch(filename, item, { matchBase: true });
338
- }
339
- else if (item instanceof RegExp) {
340
- return !item.test(filename);
341
- }
342
- return false;
343
- });
344
- }
345
- return true;
346
- })
347
- // Only keep exist files
348
- .map((filename) => {
349
- const filePath = path.join(cwd, filename);
350
- return fs.existsSync(filePath) ? filePath : null;
351
- })
352
- .filter((filePath) => !!filePath);
353
- if (styleFileList.length >= MAX_FILE_COUNT) {
354
- const jobs = [];
355
- _.chunk(styleFileList, 20).forEach((arr) => {
356
- jobs.push(new Promise(($resolve, $reject) => {
357
- execCommand({
358
- command: 'stylelint',
359
- args: [
360
- isStrict ? '--ignore-disables' : '',
361
- '--allow-empty-input',
362
- '--config',
363
- styleLintConfigPath,
364
- ...arr,
365
- ],
366
- complete: $resolve,
367
- close: $reject,
368
- exit: false,
369
- });
370
- }));
371
- });
372
- // 避免内存溢出
373
- const maxListeners = process.getMaxListeners();
374
- const jobsChunks = _.chunk(jobs, maxListeners ? maxListeners / 2 : 2);
375
- let i = 0;
376
- const exec = () => {
377
- if (i < jobsChunks.length) {
378
- Promise.all(jobsChunks[i])
379
- .then(() => {
380
- i++;
381
- exec();
382
- })
383
- .catch(reject);
384
- }
385
- else {
386
- resolve();
387
- }
388
- };
389
- exec();
390
- }
391
- else if (styleFileList.length) {
392
- execCommand({
393
- command: 'stylelint',
394
- args: [
395
- isStrict ? '--ignore-disables' : '',
396
- '--allow-empty-input',
397
- '--config',
398
- styleLintConfigPath,
399
- ...styleFileList,
400
- ],
401
- complete: resolve,
402
- close: reject,
403
- exit: false,
404
- });
405
- }
406
- }
407
- else {
408
- resolve();
409
- }
410
- });
411
- const eslint = () => {
412
- const jsFileList = files
413
- .map((file) => file.filename)
414
- .filter((filename) => /^(src|tests)/iu.test(filename))
415
- .filter((filename) => /\.([t|j]sx?)$/iu.test(filename))
416
- // Only keep exist files
417
- .map((filename) => {
418
- const filePath = path.join(cwd, filename);
419
- return fs.existsSync(filePath) ? filePath : null;
420
- })
421
- .filter((filePath) => !!filePath);
422
- if (!jsFileList.length) {
423
- completeExit();
424
- }
425
- else {
426
- // Prettier
427
- jsFileList.forEach((filePath) => {
428
- if (filePath && fs.existsSync(filePath)) {
429
- const ext = path.extname(filePath).replace(/^\./, '');
430
- const text = fs.readFileSync(filePath, 'utf8');
431
- const formatText = format(text, {
432
- parser: PRETTIER_PARSER[ext],
433
- ...getPrettierConfig(),
434
- });
435
- fs.writeFileSync(filePath, formatText, 'utf8');
436
- }
437
- });
438
- succeed('格式化 success!');
439
- // eslint
440
- const esLintConfigPath = getEsLintConfigPath();
441
- if (esLintConfigPath) {
442
- const eslintFileList = jsFileList.filter((filename) => {
443
- if (typeof eslintIgnore === 'string') {
444
- return !minimatch(filename, eslintIgnore, { matchBase: true });
445
- }
446
- else if (eslintIgnore instanceof RegExp) {
447
- return !eslintIgnore.test(filename);
448
- }
449
- else if (Array.isArray(eslintIgnore)) {
450
- return eslintIgnore.every((item) => {
451
- if (typeof item === 'string') {
452
- return !minimatch(filename, item, { matchBase: true });
453
- }
454
- else if (item instanceof RegExp) {
455
- return !item.test(filename);
456
- }
457
- return false;
458
- });
459
- }
460
- return true;
461
- });
462
- if (isStrict) {
463
- warn('git commit禁止eslint的ignore方式(eslint-disable、.eslintrc*、ignore等)。');
464
- if (eslintIgnore) {
465
- warn(`通过yolkrc配置eslintIgnore:${eslintIgnore}。`);
466
- }
467
- }
468
- if (eslintFileList.length >= MAX_FILE_COUNT) {
469
- const jobs = [];
470
- _.chunk(eslintFileList, 20).forEach((arr) => {
471
- jobs.push(new Promise((resolve) => {
472
- execCommand({
473
- command: 'eslint',
474
- args: [
475
- isStrict ? '--no-inline-config --no-ignore' : '',
476
- '--no-error-on-unmatched-pattern',
477
- '--config',
478
- esLintConfigPath,
479
- ...arr,
480
- ],
481
- complete: resolve,
482
- exit: false,
483
- });
484
- }));
485
- });
486
- // 避免内存溢出
487
- const maxListeners = process.getMaxListeners();
488
- const jobsChunks = _.chunk(jobs, maxListeners ? maxListeners / 2 : 2);
489
- let i = 0;
490
- const exec = () => {
491
- if (i < jobsChunks.length) {
492
- Promise.all(jobsChunks[i]).then(() => {
493
- i++;
494
- exec();
495
- });
496
- }
497
- else {
498
- completeExit();
499
- }
500
- };
501
- exec();
502
- }
503
- else if (eslintFileList.length) {
504
- execCommand({
505
- command: 'eslint',
506
- args: [
507
- isStrict ? '--no-inline-config --no-ignore' : '',
508
- '--no-error-on-unmatched-pattern',
509
- '--config',
510
- esLintConfigPath,
511
- ...eslintFileList,
512
- ],
513
- });
514
- }
515
- }
516
- else {
517
- warn('没有eslint配置文件');
518
- }
519
- }
520
- };
521
- warn('要求统一代码规范,进行严格的语法检查。');
522
- stylelint.then(eslint);
523
- });
524
- };
525
- const getMiniProgramCi = ({ mProject, mPrivateKeyPath, mVersion, mDesc, mRobot, mQrcodeFormat, mQrcodeOutputDest, mPagePath, mSearchQuery, }) => {
526
- const commit = fs.existsSync(path.join(cwd, '.git'))
527
- ? execSync('git log -1 --pretty=format:%H').toString()
528
- : '';
529
- const projectConfigJSON = getProjectConfigJSON();
530
- const appid = projectConfigJSON.appid;
531
- const projectPath = mProject || path.join(cwd, 'dist');
532
- const privateKeyPath = mPrivateKeyPath || path.join(cwd, `private.${appid}.key`);
533
- if (!fs.existsSync(projectPath)) {
534
- throw Error(`没有找到dist目录(${projectPath})`);
535
- }
536
- else if (!fs.existsSync(privateKeyPath)) {
537
- throw Error(`没有找到上传密钥(${privateKeyPath})`);
538
- }
539
- else {
540
- const packageJSON = getPackageJSON();
541
- const version = mVersion || packageJSON.version || projectConfigJSON.version || '1.0.0';
542
- const description = mDesc || packageJSON.description || projectConfigJSON.description;
543
- const desc = `version: ${version};${commit ? ` commit: ${commit};` : ''}${description ? ` description: ${description};` : ''}`;
544
- if (commit) {
545
- info(`commit: ${commit}`);
546
- }
547
- info(`dist: ${projectPath}`);
548
- info(`key: ${privateKeyPath}`);
549
- info(`appid: ${appid}`);
550
- info(`version: ${version}`);
551
- info(`desc: ${desc}`);
552
- const project = new miniProgramCi.Project({
553
- appid,
554
- type: 'miniProgram',
555
- projectPath,
556
- privateKeyPath,
557
- ignores: [
558
- 'node_modules/**/*',
559
- '**/*.txt',
560
- '**/*.key',
561
- '**/*.less',
562
- '**/*.sass',
563
- '**/*.scss',
564
- '**/*.css',
565
- '**/*.jsx',
566
- '**/*.ts',
567
- '**/*.tsx',
568
- '**/*.md',
569
- ],
570
- });
571
- return {
572
- miniProgramCi,
573
- appid,
574
- options: {
575
- project,
576
- version,
577
- desc,
578
- setting: projectConfigJSON.setting,
579
- robot: mRobot,
580
- qrcodeFormat: mQrcodeFormat,
581
- qrcodeOutputDest: mQrcodeOutputDest,
582
- pagePath: mPagePath,
583
- searchQuery: mSearchQuery,
584
- },
585
- };
586
- }
587
- };
588
- const install = () => {
589
- info(`node version: ${process.version}`);
590
- // 初始化pre-commit;
591
- initPreCommit();
592
- if (process.argv.length > 2) {
593
- // 注册命令行
594
- commander
595
- .version(Package.version)
596
- .usage('[command] [options]')
597
- .option('--clone', '通过git clone拉取模版')
598
- .option('--template <template>', '模版名称或者clone模式的git地址')
599
- .option('--docs', '启动文档模式')
600
- .option('--mProject <project>', '小程序上传工程目录')
601
- .option('--mPrivateKeyPath <privateKeyPath>', '小程序上传key文件')
602
- .option('--mVersion <version>', '小程序上传版本号')
603
- .option('--mDesc <desc>', '小程序上传描述')
604
- .option('--mRobot <robot>', '小程序上传ci机器人1~30')
605
- .option('--mQrcodeFormat <qrcodeFormat>', '小程序预览返回二维码文件的格式 "image" 或 "base64", 默认值 "terminal" 供调试用')
606
- .option('--mQrcodeOutputDest <qrcodeOutputDest>', '小程序预览二维码文件保存路径')
607
- .option('--mPagePath <pagePath>', '小程序预览预览页面路径')
608
- .option('--mSearchQuery <searchQuery>', '小程序预览预览页面路径启动参数')
609
- .action((dir, args) => {
610
- const [command, ...moreArgs] = args;
611
- const { clone, template, docs } = dir;
612
- if (command) {
613
- switch (command) {
614
- case 'init':
615
- succeed(`yolk ${command} 开始`);
616
- if (clone) {
617
- if (template) {
618
- const tmpName = '.yolk';
619
- const tmpPath = path.join(cwd, tmpName);
620
- if (fs.existsSync(tmpPath)) {
621
- rimraf(tmpPath, () => {
622
- succeed(`缓存删除 success! ${tmpPath}`);
623
- });
624
- }
625
- execCommand({
626
- command: 'git',
627
- args: [
628
- 'clone',
629
- '-b',
630
- 'master',
631
- '--depth',
632
- '1',
633
- template,
634
- tmpName,
635
- ].concat(moreArgs),
636
- });
637
- createGitTemplate(cwd, tmpPath);
638
- }
639
- else {
640
- fail('--clone 模式必须有--template');
641
- }
642
- }
643
- else {
644
- createTemplate(cwd);
645
- }
646
- break;
647
- case 'start':
648
- if (isMiniapp()) {
649
- if (isTT()) {
650
- execCommand({
651
- command: 'taro',
652
- args: ['build', '--type', 'tt', '--watch'].concat(moreArgs),
653
- });
654
- }
655
- else if (isAlipay()) {
656
- execCommand({
657
- command: 'taro',
658
- args: ['build', '--type', 'alipay', '--watch'].concat(moreArgs),
659
- });
660
- }
661
- else {
662
- execCommand({
663
- command: 'taro',
664
- args: ['build', '--type', 'weapp', '--watch'].concat(moreArgs),
665
- });
666
- }
667
- }
668
- else if (docs) {
669
- execCommand({
670
- command: 'dumi',
671
- args: ['dev'].concat(moreArgs),
672
- });
673
- }
674
- else {
675
- execCommand({ command: 'umi', args: ['dev'].concat(moreArgs) });
676
- }
677
- break;
678
- case 'build':
679
- if (isMiniapp()) {
680
- if (isTT()) {
681
- execCommand({
682
- command: 'taro',
683
- args: ['build', '--type', 'tt'].concat(moreArgs),
684
- });
685
- }
686
- else if (isAlipay()) {
687
- execCommand({
688
- command: 'taro',
689
- args: ['build', '--type', 'alipay'].concat(moreArgs),
690
- });
691
- }
692
- else {
693
- execCommand({
694
- command: 'taro',
695
- args: ['build', '--type', 'weapp'].concat(moreArgs),
696
- });
697
- }
698
- }
699
- else if (docs) {
700
- execCommand({
701
- command: 'dumi',
702
- args: ['build'].concat(moreArgs),
703
- });
704
- }
705
- else {
706
- execCommand({
707
- command: 'umi',
708
- args: ['build'].concat(moreArgs),
709
- });
710
- }
711
- break;
712
- case 'pre-commit':
713
- preCommit();
714
- break;
715
- case 'test':
716
- execCommand({
717
- command: 'umi-test',
718
- args: [
719
- '--no-cache',
720
- '--update-snapshot',
721
- '--runInBand',
722
- '--detectOpenHandles',
723
- ].concat(moreArgs),
724
- });
725
- break;
726
- case 'miniapp-upload':
727
- if (isMiniapp()) {
728
- if (isTT()) {
729
- }
730
- else if (isAlipay()) {
731
- }
732
- else {
733
- const { miniProgramCi, appid, options } = getMiniProgramCi(dir);
734
- info(`${appid}上传开始`);
735
- miniProgramCi
736
- .upload({
737
- ..._.pick(options, [
738
- 'project',
739
- 'version',
740
- 'desc',
741
- 'setting',
742
- 'robot',
743
- ]),
744
- onProgressUpdate: (e) => {
745
- if (_.isString(e)) {
746
- info(`task: ${e}`);
747
- }
748
- else {
749
- const { status, message } = e;
750
- info(`task(${status}): ${message}`);
751
- }
752
- },
753
- })
754
- .then(() => {
755
- succeed(`${appid}上传完成`);
756
- });
757
- }
758
- }
759
- break;
760
- case 'miniapp-preview':
761
- if (isMiniapp()) {
762
- if (isTT()) {
763
- }
764
- else if (isAlipay()) {
765
- }
766
- else {
767
- const { miniProgramCi, appid, options } = getMiniProgramCi(dir);
768
- info(`${appid}上传预览开始`);
769
- miniProgramCi
770
- .preview({
771
- ..._.pick(options, [
772
- 'project',
773
- 'version',
774
- 'desc',
775
- 'setting',
776
- 'robot',
777
- 'qrcodeFormat',
778
- 'qrcodeOutputDest',
779
- 'pagePath',
780
- 'searchQuery',
781
- ]),
782
- onProgressUpdate: (e) => {
783
- if (_.isString(e)) {
784
- info(`task: ${e}`);
785
- }
786
- else {
787
- const { status, message } = e;
788
- info(`task(${status}): ${message}`);
789
- }
790
- },
791
- })
792
- .then(() => {
793
- succeed(`${appid}上传预览完成`);
794
- });
795
- }
796
- }
797
- break;
798
- default:
799
- breakExit();
800
- }
801
- }
802
- })
803
- .parse(process.argv);
804
- }
805
- else {
806
- breakExit();
807
- }
808
- };
809
- install();
2
+ "use strict";function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var _isString2=_interopRequireDefault(require("lodash/isString")),_pick2=_interopRequireDefault(require("lodash/pick")),_chunk2=_interopRequireDefault(require("lodash/chunk")),_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")),_minimatch=_interopRequireDefault(require("minimatch")),_mustache=_interopRequireDefault(require("mustache")),_mkdirp=_interopRequireDefault(require("mkdirp")),_rimraf=_interopRequireDefault(require("rimraf")),_prettier=require("prettier"),miniProgramCi=_interopRequireWildcard(require("miniprogram-ci")),_package=_interopRequireDefault(require("../package.json"));function _getRequireWildcardCache(e){if("function"!==typeof WeakMap)return null;var t=new WeakMap,r=new WeakMap;return(_getRequireWildcardCache=function(e){return e?r:t})(e)}function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;if(null===e||"object"!==_typeof(e)&&"function"!==typeof e)return{default:e};var r=_getRequireWildcardCache(t);if(r&&r.has(e))return r.get(e);var n={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var i in e)if("default"!==i&&Object.prototype.hasOwnProperty.call(e,i)){var o=a?Object.getOwnPropertyDescriptor(e,i):null;o&&(o.get||o.set)?Object.defineProperty(n,i,o):n[i]=e[i]}return n["default"]=e,r&&r.set(e,n),n}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _toArray(e){return _arrayWithHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _arrayWithHoles(e){if(Array.isArray(e))return e}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"===typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);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}}function _iterableToArray(e){if("undefined"!==typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}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=(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,r=e.args,n=e.complete,a=e.close,i=e.exit,o=void 0===i||i,c=(0,_child_process.spawn)(getCommand(t),r||[],{stdio:"inherit"}).on("close",(function(e){e?(a&&a(),fail("yolk close!"),process.exit(e)):(n&&n(),o&&completeExit())}));process.on("SIGINT",(function(){_commander["default"].runningCommand&&_commander["default"].runningCommand.kill("SIGKILL"),c.kill(),breakExit()}))},createTemplate=function(e,t,r){_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(n){var a={projectName:n.projectName,mobile:"mobile"===n.type,dependenciesInstallType:n.dependenciesInstallType};t||(t=_path["default"].join(__dirname,"../templates/".concat(n.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(r){if(t){var n=_path["default"].join(t,r);if(!_fs["default"].statSync(n).isDirectory())if(r.endsWith(".tpl")){var i=_fs["default"].readFileSync(n,ENCODING),o=_path["default"].join(e,r.replace(/\.tpl$/,"")),c=_mustache["default"].render(i,a);_mkdirp["default"].sync(_path["default"].dirname(o)),succeed("\u521b\u5efa ".concat(_path["default"].relative(e,o))),_fs["default"].writeFileSync(o,c,ENCODING)}else{succeed("\u521b\u5efa ".concat(r));var s=_path["default"].join(e,r);_mkdirp["default"].sync(_path["default"].dirname(s)),_fs["default"].copyFileSync(n,s)}}})),succeed("\u590d\u5236\u6a21\u7248 success!"),r&&_fs["default"].existsSync(t)&&(0,_rimraf["default"])(t,(function(){succeed("\u7f13\u5b58\u5220\u9664 success! ".concat(_path["default"].basename(t||"")))})),n.dependenciesInstallType)switch(succeed("\u521d\u59cb\u5316\u4f9d\u8d56\u5305"),n.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});if(!e.length)return{};var t=_path["default"].join(cwd,e[0]);if(!_fs["default"].existsSync(t))return{};try{return JSON.parse(_fs["default"].readFileSync(t,ENCODING))||{}}catch(r){return fail(r.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(r){return fail(r.message||".prettierrc\u8f6c\u6362\u9519\u8bef"),{}}},getProjectConfigJSON=function(){var e=_path["default"].join(cwd,"project.config.json");if(!_fs["default"].existsSync(e))return{};try{return JSON.parse(_fs["default"].readFileSync(e,ENCODING))||{}}catch(t){return fail(t.message||"project.config.json\u8f6c\u6362\u9519\u8bef"),{}}},getPackageJSON=function(){var e=_path["default"].join(cwd,"package.json");if(!_fs["default"].existsSync(e))return{};try{return JSON.parse(_fs["default"].readFileSync(e,ENCODING))||{}}catch(t){return fail(t.message||"package.json\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"),r=_glob["default"].sync("*.eslintrc*",{cwd:cwd,dot:!0}),n=r[0];return!1===e.strict&&n&&_fs["default"].existsSync(n)?n: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"),r=_path["default"].join(t,"pre-commit"),n=_fs["default"].existsSync(e),a=_fs["default"].existsSync(r),i=a&&_fs["default"].readFileSync(r,"utf8").includes(HOOK_MARK);if(n&&(!a||!i)){_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");try{_fs["default"].chmodSync(r,"777")}catch(o){fail("chmod ".concat(r," failed: ").concat(o.message))}succeed("Create pre-commit hook")}},preCommit=function(){var e=getYolkConfig(),t=!1!==e.strict,r=e.eslintIgnore,n=e.stylelintIgnore;sgf().then((function(e){var a=new Promise((function(r,a){var i=getStyleLintConfigPath();if(i){var o=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 n?!(0,_minimatch["default"])(e,n,{matchBase:!0}):n instanceof RegExp?!n.test(e):!Array.isArray(n)||n.every((function(t){return"string"===typeof t?!(0,_minimatch["default"])(e,t,{matchBase:!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(o.length>=MAX_FILE_COUNT){var c=[];(0,_chunk2["default"])(o,20).forEach((function(e){c.push(new Promise((function(r,n){execCommand({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",i].concat(_toConsumableArray(e)),complete:r,close:n,exit:!1})})))}));var s=process.getMaxListeners(),u=(0,_chunk2["default"])(c,s?s/2:2),l=0,f=function e(){l<u.length?Promise.all(u[l]).then((function(){l++,e()}))["catch"](a):r()};f()}else o.length&&execCommand({command:"stylelint",args:[t?"--ignore-disables":"","--allow-empty-input","--config",i].concat(_toConsumableArray(o)),complete:r,close:a,exit:!1})}else r()})),i=function(){var n=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)})).map((function(e){var t=_path["default"].join(cwd,e);return _fs["default"].existsSync(t)?t:null})).filter((function(e){return!!e}));if(n.length){n.forEach((function(e){if(e&&_fs["default"].existsSync(e)){var t=_path["default"].extname(e).replace(/^\./,""),r=_fs["default"].readFileSync(e,"utf8"),n=(0,_prettier.format)(r,_objectSpread({parser:PRETTIER_PARSER[t]},getPrettierConfig()));_fs["default"].writeFileSync(e,n,"utf8")}})),succeed("\u683c\u5f0f\u5316 success!");var a=getEsLintConfigPath();if(a){var i=n.filter((function(e){return"string"===typeof r?!(0,_minimatch["default"])(e,r,{matchBase:!0}):r instanceof RegExp?!r.test(e):!Array.isArray(r)||r.every((function(t){return"string"===typeof t?!(0,_minimatch["default"])(e,t,{matchBase:!0}):t instanceof RegExp&&!t.test(e)}))}));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){var o=[];(0,_chunk2["default"])(i,20).forEach((function(e){o.push(new Promise((function(r){execCommand({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",a].concat(_toConsumableArray(e)),complete:r,exit:!1})})))}));var c=process.getMaxListeners(),s=(0,_chunk2["default"])(o,c?c/2:2),u=0,l=function e(){u<s.length?Promise.all(s[u]).then((function(){u++,e()})):completeExit()};l()}else i.length&&execCommand({command:"eslint",args:[t?"--no-inline-config --no-ignore":"","--no-error-on-unmatched-pattern","--config",a].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"),a.then(i)}))},getMiniProgramCi=function(e){var t=e.mProject,r=e.mPrivateKeyPath,n=e.mVersion,a=e.mDesc,i=e.mRobot,o=e.mQrcodeFormat,c=e.mQrcodeOutputDest,s=e.mPagePath,u=e.mSearchQuery,l=_fs["default"].existsSync(_path["default"].join(cwd,".git"))?(0,_child_process.execSync)("git log -1 --pretty=format:%H").toString():"",f=getProjectConfigJSON(),p=f.appid,d=t||_path["default"].join(cwd,"dist"),m=r||_path["default"].join(cwd,"private.".concat(p,".key"));if(_fs["default"].existsSync(d)){if(_fs["default"].existsSync(m)){var y=getPackageJSON(),_=n||y.version||f.version||"1.0.0",g=a||y.description||f.description,h="version: ".concat(_,";").concat(l?" commit: ".concat(l,";"):"").concat(g?" description: ".concat(g,";"):"");l&&info("commit: ".concat(l)),info("dist: ".concat(d)),info("key: ".concat(m)),info("appid: ".concat(p)),info("version: ".concat(_)),info("desc: ".concat(h));var b=new miniProgramCi.Project({appid:p,type:"miniProgram",projectPath:d,privateKeyPath:m,ignores:["node_modules/**/*","**/*.txt","**/*.key","**/*.less","**/*.sass","**/*.scss","**/*.css","**/*.jsx","**/*.ts","**/*.tsx","**/*.md"]});return{miniProgramCi:miniProgramCi,appid:p,options:{project:b,version:_,desc:h,setting:f.setting,robot:i,qrcodeFormat:o,qrcodeOutputDest:c,pagePath:s,searchQuery:u}}}throw Error("\u6ca1\u6709\u627e\u5230\u4e0a\u4f20\u5bc6\u94a5(".concat(m,")"))}throw Error("\u6ca1\u6709\u627e\u5230dist\u76ee\u5f55(".concat(d,")"))},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 <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){var r=_toArray(t),n=r[0],a=r.slice(1),i=e.clone,o=e.template,c=e.docs;if(n)switch(n){case"init":if(succeed("yolk ".concat(n," \u5f00\u59cb")),i)if(o){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",o,s].concat(a)}),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(a)}):isAlipay()?execCommand({command:"taro",args:["build","--type","alipay","--watch"].concat(a)}):execCommand({command:"taro",args:["build","--type","weapp","--watch"].concat(a)}):execCommand(c?{command:"dumi",args:["dev"].concat(a)}:{command:"umi",args:["dev"].concat(a)});break;case"build":isMiniapp()?isTT()?execCommand({command:"taro",args:["build","--type","tt"].concat(a)}):isAlipay()?execCommand({command:"taro",args:["build","--type","alipay"].concat(a)}):execCommand({command:"taro",args:["build","--type","weapp"].concat(a)}):execCommand(c?{command:"dumi",args:["build"].concat(a)}:{command:"umi",args:["build"].concat(a)});break;case"pre-commit":preCommit();break;case"test":execCommand({command:"umi-test",args:["--no-cache","--update-snapshot","--runInBand","--detectOpenHandles"].concat(a)});break;case"miniapp-upload":if(isMiniapp())if(isTT());else if(isAlipay());else{var l=getMiniProgramCi(e),f=l.miniProgramCi,p=l.appid,d=l.options;info("".concat(p,"\u4e0a\u4f20\u5f00\u59cb")),f.upload(_objectSpread(_objectSpread({},(0,_pick2["default"])(d,["project","version","desc","setting","robot"])),{},{onProgressUpdate:function(e){if((0,_isString2["default"])(e))info("task: ".concat(e));else{var t=e.status,r=e.message;info("task(".concat(t,"): ").concat(r))}}})).then((function(){succeed("".concat(p,"\u4e0a\u4f20\u5b8c\u6210"))}))}break;case"miniapp-preview":if(isMiniapp())if(isTT());else if(isAlipay());else{var m=getMiniProgramCi(e),y=m.miniProgramCi,_=m.appid,g=m.options;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"])),{},{onProgressUpdate:function(e){if((0,_isString2["default"])(e))info("task: ".concat(e));else{var t=e.status,r=e.message;info("task(".concat(t,"): ").concat(r))}}})).then((function(){succeed("".concat(_,"\u4e0a\u4f20\u9884\u89c8\u5b8c\u6210"))}))}break;default:breakExit()}})).parse(process.argv):breakExit()};install();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baic/yolk-cli",
3
- "version": "1.0.20",
3
+ "version": "2.0.1-alpha.1",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "pub": "npm publish",
@@ -26,14 +26,14 @@
26
26
  "@types/mkdirp": "~1.0.2",
27
27
  "@types/mustache": "~4.1.2",
28
28
  "@types/rimraf": "~3.0.2",
29
- "commander": "6.2.1",
29
+ "commander": "6.x",
30
30
  "glob": "~7.2.0",
31
31
  "inquirer": "~8.2.0",
32
32
  "lodash": "~4.17.21",
33
33
  "miniprogram-ci": "~1.6.10",
34
34
  "mkdirp": "~1.0.4",
35
35
  "mustache": "~4.2.0",
36
- "ora": "5.4.1",
36
+ "ora": "5.x",
37
37
  "prettier": "~2.5.1",
38
38
  "rimraf": "~3.0.2",
39
39
  "staged-git-files": "~1.2.0"
@@ -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
  }