@sevenvip666/rop 0.0.9 → 0.1.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.
@@ -1,19 +1,20 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
- import * as fs from 'node:fs';
4
- import fs__default from 'node:fs';
5
- import { confirm, select, input } from '@inquirer/prompts';
3
+ import fs, { readFileSync, existsSync } from 'fs';
4
+ import fetch$1 from 'node-fetch';
5
+ import FormData from 'form-data';
6
+ import cliProgress from 'cli-progress';
6
7
  import colors from 'ansi-colors';
7
- import path from 'node:path';
8
- import { exec } from 'child_process';
9
- import fs$1, { readFileSync, existsSync } from 'fs';
10
8
  import path$1, { resolve, join, sep, normalize } from 'path';
9
+ import { exec } from 'child_process';
10
+ import path from 'node:path';
11
+ import fs$1 from 'node:fs';
11
12
  import { parse } from '@iarna/toml';
12
13
  import { globbySync } from 'globby';
13
14
  import JSON5 from 'json5';
14
- import fetch from 'node-fetch';
15
- import FormData from 'form-data';
16
- import cliProgress from 'cli-progress';
15
+ import yaml from 'js-yaml';
16
+ import { confirm, select, input, password } from '@inquirer/prompts';
17
+ import * as os from 'node:os';
17
18
 
18
19
  /******************************************************************************
19
20
  Copyright (c) Microsoft Corporation.
@@ -43,6 +44,18 @@ var __assign = function() {
43
44
  return __assign.apply(this, arguments);
44
45
  };
45
46
 
47
+ function __rest(s, e) {
48
+ var t = {};
49
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
50
+ t[p] = s[p];
51
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
52
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
53
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
54
+ t[p[i]] = s[p[i]];
55
+ }
56
+ return t;
57
+ }
58
+
46
59
  function __awaiter(thisArg, _arguments, P, generator) {
47
60
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
48
61
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -86,107 +99,12 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
86
99
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
87
100
  };
88
101
 
89
- var Init = /** @class */ (function () {
90
- function Init() {
91
- }
92
- Init.prototype.initProjectConfigJson = function (framework) {
93
- return __awaiter(this, void 0, void 0, function () {
94
- var jsonConfigPath, jsonConfigData, flag, str;
95
- return __generator(this, function (_a) {
96
- switch (_a.label) {
97
- case 0:
98
- jsonConfigPath = path.join('.', 'rop.json');
99
- if (!fs__default.existsSync(jsonConfigPath)) return [3 /*break*/, 5];
100
- flag = false;
101
- _a.label = 1;
102
- case 1:
103
- _a.trys.push([1, 3, , 4]);
104
- return [4 /*yield*/, confirm({
105
- message: "".concat(colors.cyan('rop.json'), " already exists, does it need to be overwritten?"),
106
- })];
107
- case 2:
108
- flag = _a.sent();
109
- return [3 /*break*/, 4];
110
- case 3:
111
- _a.sent();
112
- console.log('cancel');
113
- return [2 /*return*/, false];
114
- case 4:
115
- if (!flag) {
116
- console.log('cancel');
117
- return [2 /*return*/, false];
118
- }
119
- str = fs__default.readFileSync(jsonConfigPath, 'utf8');
120
- jsonConfigData = JSON.parse(str);
121
- if (!jsonConfigData.framework) {
122
- jsonConfigData.framework = {
123
- name: framework,
124
- };
125
- }
126
- else {
127
- jsonConfigData.framework.name = framework;
128
- }
129
- return [3 /*break*/, 6];
130
- case 5:
131
- jsonConfigData = {
132
- framework: {
133
- name: framework,
134
- },
135
- };
136
- _a.label = 6;
137
- case 6:
138
- fs__default.writeFileSync(jsonConfigPath, JSON.stringify(jsonConfigData, null, 2), 'utf8');
139
- return [2 /*return*/, true];
140
- }
141
- });
142
- });
143
- };
144
- Init.prototype.initRopConfig = function (accessKey) {
145
- return __awaiter(this, void 0, void 0, function () {
146
- var ropConfigDirPath, ropConfigPath, ropConfigData;
147
- return __generator(this, function (_a) {
148
- ropConfigDirPath = path.join('.', '.rop');
149
- if (!fs__default.existsSync(ropConfigDirPath)) {
150
- fs__default.mkdirSync(ropConfigDirPath);
151
- }
152
- ropConfigPath = path.join(ropConfigDirPath, 'config.json');
153
- ropConfigData = {};
154
- if (fs__default.existsSync(ropConfigPath)) {
155
- ropConfigData = JSON.parse(fs__default.readFileSync(ropConfigPath, 'utf8'));
156
- }
157
- ropConfigData.accessKey = accessKey;
158
- fs__default.writeFileSync(ropConfigPath, JSON.stringify(ropConfigData, null, 2), 'utf8');
159
- return [2 /*return*/];
160
- });
161
- });
162
- };
163
- Init.prototype.initGitignore = function () {
164
- return __awaiter(this, void 0, void 0, function () {
165
- var gitignorePath, gitignoreData;
166
- return __generator(this, function (_a) {
167
- gitignorePath = path.join('.', '.gitignore');
168
- if (fs__default.existsSync(gitignorePath)) {
169
- gitignoreData = fs__default.readFileSync(gitignorePath, 'utf8');
170
- if (!gitignoreData.includes('.rop')) {
171
- fs__default.appendFileSync(gitignorePath, "\n.rop", 'utf8');
172
- }
173
- }
174
- else {
175
- fs__default.writeFileSync(gitignorePath, ".rop", 'utf8');
176
- }
177
- return [2 /*return*/];
178
- });
179
- });
180
- };
181
- return Init;
182
- }());
183
-
184
- var frameworkList = ['tauri'];
102
+ var frameworkList = ['tauri', 'ionic', 'flutter'];
185
103
  var Framework;
186
104
  (function (Framework) {
187
- Framework["TAURI"] = "TAURI";
188
- Framework["IONIC"] = "IONIC";
189
- Framework["FLUTTER"] = "FLUTTER";
105
+ Framework["TAURI"] = "tauri";
106
+ Framework["IONIC"] = "ionic";
107
+ Framework["FLUTTER"] = "flutter";
190
108
  })(Framework || (Framework = {}));
191
109
 
192
110
  function getWorkspaceDir(dir) {
@@ -415,36 +333,184 @@ var getTauriEnv = function (projectPath) {
415
333
  };
416
334
 
417
335
  var tauri = {
418
- macos: {
419
- x64: {
420
- target: {
421
- path: "${basePath}/x86_64-apple-darwin/release/bundle/dmg/${appName}_${version}_${arch}.dmg"
422
- },
423
- update: {
424
- path: "${basePath}/x86_64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz",
425
- name: "${appName}_${version}_${arch}.app.tar.gz"
426
- },
427
- sig: {
428
- path: "${basePath}/x86_64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz.sig"
336
+ macos: [
337
+ {
338
+ arch: "x64",
339
+ artifacts: {
340
+ target: {
341
+ path: "${basePath}/x86_64-apple-darwin/release/bundle/dmg/${appName}_${version}_${arch}.dmg"
342
+ },
343
+ update: {
344
+ path: "${basePath}/x86_64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz",
345
+ name: "${appName}_${version}_${arch}.app.tar.gz"
346
+ },
347
+ sig: {
348
+ path: "${basePath}/x86_64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz.sig"
349
+ }
429
350
  }
430
351
  },
431
- arm64: {
432
- target: {
433
- path: "${basePath}/aarch64-apple-darwin/release/bundle/dmg/${appName}_${version}_arrch64.dmg"
434
- },
435
- update: {
436
- path: "${basePath}/aarch64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz",
437
- name: "${appName}_${version}_${arch}.app.tar.gz"
438
- },
439
- sig: {
440
- path: "${basePath}/aarch64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz.sig"
352
+ {
353
+ arch: "arm64",
354
+ artifacts: {
355
+ target: {
356
+ path: "${basePath}/aarch64-apple-darwin/release/bundle/dmg/${appName}_${version}_aarch64.dmg",
357
+ name: "${appName}_${version}_${arch}.dmg"
358
+ },
359
+ update: {
360
+ path: "${basePath}/aarch64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz",
361
+ name: "${appName}_${version}_${arch}.app.tar.gz"
362
+ },
363
+ sig: {
364
+ path: "${basePath}/aarch64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz.sig"
365
+ }
366
+ }
367
+ },
368
+ {
369
+ arch: "universal",
370
+ artifacts: {
371
+ target: {
372
+ path: "${basePath}/universal-apple-darwin/release/bundle/dmg/${appName}_${version}_${arch}.dmg"
373
+ },
374
+ update: {
375
+ path: "${basePath}/universal-apple-darwin/release/bundle/macos/${appName}.app.tar.gz",
376
+ name: "${appName}_${version}_${arch}.app.tar.gz"
377
+ },
378
+ sig: {
379
+ path: "${basePath}/universal-apple-darwin/release/bundle/macos/${appName}.app.tar.gz.sig"
380
+ }
381
+ }
382
+ }
383
+ ],
384
+ windows: [
385
+ {
386
+ arch: "x64",
387
+ installerType: "nsis",
388
+ artifacts: {
389
+ target: {
390
+ path: "${basePath}/release/bundle/nsis/${appName}_${version}_${arch}-setup.exe"
391
+ },
392
+ update: {
393
+ path: "${basePath}/release/bundle/nsis/${appName}_${version}_${arch}-setup.nsis.zip"
394
+ },
395
+ sig: {
396
+ path: "${basePath}/release/bundle/nsis/${appName}_${version}_${arch}-setup.nsis.zip.sig"
397
+ }
398
+ }
399
+ }
400
+ ]
401
+ };
402
+ var flutter = {
403
+ ios: [
404
+ {
405
+ arch: "universal",
406
+ artifacts: {
407
+ target: {
408
+ path: "build/ios/ipa/${appName}.ipa",
409
+ name: "${appName}_${version}.ipa"
410
+ }
411
+ }
412
+ }
413
+ ],
414
+ android: [
415
+ {
416
+ arch: "universal",
417
+ artifacts: {
418
+ target: {
419
+ path: "build/app/outputs/flutter-apk/app-release.apk",
420
+ name: "${appName}_${version}.apk"
421
+ }
441
422
  }
442
423
  }
443
- }
424
+ ],
425
+ macos: [
426
+ {
427
+ arch: "universal",
428
+ artifacts: {
429
+ target: {
430
+ path: "build/${appName}.dmg",
431
+ name: "${appName}_${version}.dmg"
432
+ }
433
+ }
434
+ }
435
+ ]
436
+ };
437
+ var ionic = {
444
438
  };
445
439
  var platformDefaultConfigMap = {
446
- tauri: tauri
440
+ tauri: tauri,
441
+ flutter: flutter,
442
+ ionic: ionic
443
+ };
444
+
445
+ var getFlutterEnv = function (projectPath) {
446
+ var dir = getDir$1(projectPath !== null && projectPath !== void 0 ? projectPath : '.');
447
+ if (dir !== null) {
448
+ if (existsSync(join(dir, 'pubspec.yaml'))) {
449
+ var doc = yaml.load(fs.readFileSync(join(dir, 'pubspec.yaml'), 'utf8'));
450
+ return {
451
+ basePath: dir + '/build',
452
+ appName: doc.name,
453
+ version: doc.version.split('+')[0],
454
+ };
455
+ }
456
+ else {
457
+ throw Error("Couldn't detect Flutter pubspec.yaml");
458
+ }
459
+ }
460
+ else {
461
+ // This should not actually happen.
462
+ throw Error("Couldn't detect Flutter dir");
463
+ }
464
+ };
465
+ function getDir$1(root) {
466
+ var confPaths = globbySync(['**/pubspec.yaml'], {
467
+ gitignore: true,
468
+ cwd: root,
469
+ // Forcefully ignore target and node_modules dirs
470
+ ignore: ['**/build', '**/ios', '**/android', '**/windows', '**/macos', '**/linux'],
471
+ });
472
+ if (confPaths.length === 0) {
473
+ return null;
474
+ }
475
+ return resolve(root, confPaths[0], '..');
476
+ }
477
+
478
+ var getIonicEnv = function (projectPath) {
479
+ var dir = getDir(projectPath !== null && projectPath !== void 0 ? projectPath : '.');
480
+ if (dir !== null) {
481
+ if (existsSync(join(dir, 'package.json'))) {
482
+ var config = readFileSync(join(dir, 'capacitor.config.ts'), 'utf8').toString();
483
+ var json = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8').toString());
484
+ // 使用正则表达式来找到 appName 的值
485
+ var appNameRegex = /appName:\s*['"]([^'"]*)['"]/;
486
+ var match = appNameRegex.exec(config);
487
+ return {
488
+ basePath: dir,
489
+ appName: match === null || match === void 0 ? void 0 : match[1],
490
+ version: json.version,
491
+ };
492
+ }
493
+ else {
494
+ throw Error("Couldn't detect Flutter pubspec.yaml");
495
+ }
496
+ }
497
+ else {
498
+ // This should not actually happen.
499
+ throw Error("Couldn't detect Flutter dir");
500
+ }
447
501
  };
502
+ function getDir(root) {
503
+ var confPaths = globbySync(['**/package.json', '**/capacitor.config.ts'], {
504
+ gitignore: true,
505
+ cwd: root,
506
+ // Forcefully ignore target and node_modules dirs
507
+ ignore: ['**/build', '**/ios', '**/android', '**/windows', '**/macos', '**/linux'],
508
+ });
509
+ if (confPaths.length === 0) {
510
+ return null;
511
+ }
512
+ return resolve(root, confPaths[0], '..');
513
+ }
448
514
 
449
515
  var getBranch = function () { return __awaiter(void 0, void 0, void 0, function () {
450
516
  return __generator(this, function (_a) {
@@ -457,43 +523,45 @@ var getBranch = function () { return __awaiter(void 0, void 0, void 0, function
457
523
  resolve(stdout.trim());
458
524
  return;
459
525
  }
460
- resolve(undefined);
526
+ resolve('none');
461
527
  });
462
528
  })];
463
529
  });
464
530
  }); };
465
- // 读取 YAML 文件并替换模版变量
531
+ // 读取 JSON 文件并替换模版变量
466
532
  function loadJsonWithEnv(_a) {
467
533
  var _b, _c, _d, _e, _f;
468
- var platform = _a.platform, arch = _a.arch, optionAccessKey = _a.optionAccessKey;
534
+ var platform = _a.platform, arch = _a.arch;
469
535
  var configFilePath = path.join('.', 'rop.json');
470
- var configData = fs__default.readFileSync(configFilePath, 'utf8');
536
+ var configData = fs$1.readFileSync(configFilePath, 'utf8');
471
537
  var inputConfig = JSON.parse(configData);
472
- var _arch;
538
+ var _arch = arch !== null && arch !== void 0 ? arch : 'universal';
473
539
  if (arch == 'x86_64') {
474
540
  _arch = 'x64';
475
541
  }
476
- else if (arch) {
477
- _arch = arch;
542
+ else if (arch == 'i386' || arch == 'i686') {
543
+ _arch = 'x86';
478
544
  }
479
- else {
480
- _arch = 'x64';
545
+ else if (arch == 'aarch64') {
546
+ _arch = 'arm64';
481
547
  }
482
548
  var env = {
483
549
  arch: _arch,
484
550
  };
485
551
  var config;
486
- if (!inputConfig.platforms) {
487
- if (((_b = inputConfig.framework) === null || _b === void 0 ? void 0 : _b.name) && frameworkList.includes((_c = inputConfig.framework) === null || _c === void 0 ? void 0 : _c.name)) {
488
- var framework = inputConfig.framework.name;
489
- var defaultPlatformConfig = platformDefaultConfigMap[framework];
490
- config = __assign(__assign({}, inputConfig), { platforms: defaultPlatformConfig });
491
- }
552
+ if (!inputConfig.platforms && ((_b = inputConfig.framework) === null || _b === void 0 ? void 0 : _b.name) && frameworkList.includes((_c = inputConfig.framework) === null || _c === void 0 ? void 0 : _c.name)) {
553
+ var framework = inputConfig.framework.name;
554
+ var defaultPlatformConfig = platformDefaultConfigMap[framework];
555
+ var _config = __assign(__assign({}, inputConfig), { platforms: defaultPlatformConfig });
556
+ config = _config;
492
557
  }
493
558
  else {
494
559
  config = inputConfig;
495
560
  }
496
- var _autoEnv = getAutoEnvByFramework((_d = config.framework) === null || _d === void 0 ? void 0 : _d.name, config.projectPath);
561
+ if (!config.platforms || Object.keys(config.platforms).length == 0) {
562
+ throw new Error('platforms is not null');
563
+ }
564
+ var _autoEnv = getAutoEnvByFramework((_d = config === null || config === void 0 ? void 0 : config.framework) === null || _d === void 0 ? void 0 : _d.name, config.projectPath);
497
565
  env = __assign(__assign(__assign({}, env), (_autoEnv !== null && _autoEnv !== void 0 ? _autoEnv : {})), ((_f = (_e = config.framework) === null || _e === void 0 ? void 0 : _e.env) !== null && _f !== void 0 ? _f : {}));
498
566
  // 确保配置文件中存在 host 属性
499
567
  if (!env.version) {
@@ -513,42 +581,52 @@ function loadJsonWithEnv(_a) {
513
581
  });
514
582
  }
515
583
  replaceEnvInObject(config);
516
- var targetInfo = config.platforms[platform]
517
- ? config.platforms[platform][_arch]
518
- : undefined;
519
- if (!targetInfo) {
520
- throw new Error('not find target file');
521
- }
584
+ var targetInfos = getTargetInfo(config.platforms, platform, _arch);
522
585
  console.log('find target file:');
523
- console.log(targetInfo);
524
- var accessKey = getAccessKey(optionAccessKey);
525
- return { config: config, targetInfo: targetInfo, accessKey: accessKey, version: env.version };
586
+ console.log(targetInfos);
587
+ return { config: config, targetInfos: targetInfos, version: env.version, arch: _arch };
526
588
  }
527
- var getAccessKey = function (accessKey) {
528
- if (accessKey) {
529
- return accessKey;
589
+ var loadConfigJSON = function () {
590
+ var configFilePath = path.join('.rop', 'config.json');
591
+ if (!fs$1.existsSync(configFilePath)) {
592
+ return {
593
+ projectId: undefined,
594
+ };
530
595
  }
531
- var configDataStr = fs__default.readFileSync('.rop/config.json', 'utf8');
596
+ var configDataStr = fs$1.readFileSync(configFilePath, 'utf8');
532
597
  var configData = JSON.parse(configDataStr);
533
- if (configData.accessKey) {
534
- return configData.accessKey;
535
- }
536
- throw new Error('missing access-key');
598
+ return {
599
+ projectId: configData.projectId,
600
+ };
537
601
  };
538
602
  var getAutoEnvByFramework = function (framework, projectPath) {
539
603
  if (!framework) {
540
604
  return undefined;
541
605
  }
542
606
  switch (framework.toLowerCase()) {
543
- case Framework.TAURI.toLowerCase():
607
+ case Framework.TAURI:
544
608
  return getTauriEnv(projectPath);
609
+ case Framework.FLUTTER:
610
+ return getFlutterEnv(projectPath);
611
+ case Framework.IONIC:
612
+ return getIonicEnv(projectPath);
545
613
  default:
546
614
  return undefined;
547
615
  }
548
616
  };
617
+ var getTargetInfo = function (platforms, platform, arch) {
618
+ var list = platforms[platform];
619
+ if (list && list.length > 0) {
620
+ var targetList = list.filter(function (item) { return item.arch == arch; });
621
+ if (targetList.length > 0) {
622
+ return targetList;
623
+ }
624
+ }
625
+ throw new Error('Not find artifacts file');
626
+ };
549
627
 
550
- var RopUpload = /** @class */ (function () {
551
- function RopUpload(_a) {
628
+ var RopUploadApi = /** @class */ (function () {
629
+ function RopUploadApi(_a) {
552
630
  var baseDomain = _a.baseDomain;
553
631
  var _this = this;
554
632
  this.checkParams = function (config) { return __awaiter(_this, void 0, void 0, function () {
@@ -558,7 +636,9 @@ var RopUpload = /** @class */ (function () {
558
636
  switch (_c.label) {
559
637
  case 0:
560
638
  if (!config.accessKey) {
561
- throw new Error('accessKey not null');
639
+ if (!config.token || !config.projectId) {
640
+ throw new Error('accessKey, token, projectId cannot be empty at the same time');
641
+ }
562
642
  }
563
643
  if (!((_b = config.branch) !== null && _b !== void 0)) return [3 /*break*/, 1];
564
644
  _a = _b;
@@ -584,11 +664,13 @@ var RopUpload = /** @class */ (function () {
584
664
  if (!config.targetPath) {
585
665
  throw new Error('target path not null');
586
666
  }
587
- if (!fs$1.existsSync(config.targetPath)) {
667
+ if (!fs.existsSync(config.targetPath)) {
588
668
  throw new Error("target file not found, file path: ".concat(config.targetPath));
589
669
  }
590
- if (config.updatePath && !fs$1.existsSync(config.updatePath)) {
591
- throw new Error("update file not found\uFF0C file path: ".concat(config.updatePath));
670
+ // 如果更新包不存在的情况使用本身的包
671
+ if (config.updatePath && !fs.existsSync(config.updatePath)) {
672
+ config.updatePath = config.targetPath;
673
+ config.updateName = config.targetName;
592
674
  }
593
675
  if (!config.version) {
594
676
  throw new Error('version not null');
@@ -599,7 +681,7 @@ var RopUpload = /** @class */ (function () {
599
681
  }); };
600
682
  this.baseDomain = baseDomain;
601
683
  }
602
- RopUpload.prototype.upload = function (_config) {
684
+ RopUploadApi.prototype.upload = function (_config) {
603
685
  return __awaiter(this, void 0, void 0, function () {
604
686
  var config, formData, fileStream, multibar, bar1, totalUploaded, updateFileStream, bar2_1, totalUpdateUploaded_1, res, body;
605
687
  var _a, _b;
@@ -609,14 +691,14 @@ var RopUpload = /** @class */ (function () {
609
691
  case 1:
610
692
  config = _c.sent();
611
693
  formData = new FormData();
612
- fileStream = fs$1.createReadStream(config.targetPath);
694
+ fileStream = fs.createReadStream(config.targetPath);
613
695
  multibar = new cliProgress.MultiBar({
614
696
  format: 'Upload Progress |' + colors.cyan('{bar}') + '| {percentage}% | {filename}',
615
697
  barCompleteChar: '\u2588',
616
698
  barIncompleteChar: '\u2591',
617
699
  hideCursor: true,
618
700
  });
619
- bar1 = multibar.create(fs$1.statSync(config.targetPath).size, 0);
701
+ bar1 = multibar.create(fs.statSync(config.targetPath).size, 0);
620
702
  totalUploaded = 0;
621
703
  fileStream.on('data', function (chunk) {
622
704
  totalUploaded += chunk.length;
@@ -626,8 +708,8 @@ var RopUpload = /** @class */ (function () {
626
708
  filename: (_a = config.targetName) !== null && _a !== void 0 ? _a : path$1.basename(config.targetPath),
627
709
  });
628
710
  if (config.updatePath) {
629
- bar2_1 = multibar.create(fs$1.statSync(config.updatePath).size, 0);
630
- updateFileStream = fs$1.createReadStream(config.updatePath);
711
+ bar2_1 = multibar.create(fs.statSync(config.updatePath).size, 0);
712
+ updateFileStream = fs.createReadStream(config.updatePath);
631
713
  totalUpdateUploaded_1 = 0;
632
714
  updateFileStream.on('data', function (chunk) {
633
715
  totalUpdateUploaded_1 += chunk.length;
@@ -637,7 +719,15 @@ var RopUpload = /** @class */ (function () {
637
719
  filename: (_b = config.updateName) !== null && _b !== void 0 ? _b : path$1.basename(config.updatePath),
638
720
  });
639
721
  }
640
- formData.append('accessKey', config.accessKey);
722
+ if (config.accessKey) {
723
+ formData.append('accessKey', config.accessKey);
724
+ }
725
+ if (config.projectId) {
726
+ formData.append('projectId', config.projectId);
727
+ }
728
+ if (config.token) {
729
+ formData.append('token', config.token);
730
+ }
641
731
  formData.append('branch', config.branch);
642
732
  formData.append('version', config.version);
643
733
  formData.append('platform', config.platform);
@@ -645,7 +735,7 @@ var RopUpload = /** @class */ (function () {
645
735
  if (config.signature) {
646
736
  formData.append('signature', config.signature);
647
737
  }
648
- return [4 /*yield*/, fetch("".concat(this.baseDomain, "/api/upload"), {
738
+ return [4 /*yield*/, fetch$1("".concat(this.baseDomain, "/api/upload"), {
649
739
  method: 'POST',
650
740
  headers: formData.getHeaders(),
651
741
  body: formData,
@@ -666,145 +756,559 @@ var RopUpload = /** @class */ (function () {
666
756
  });
667
757
  });
668
758
  };
669
- return RopUpload;
759
+ return RopUploadApi;
670
760
  }());
671
761
 
672
- var program = new Command();
673
- program.name('rop').description('CLI to some JavaScript string utilities').version('0.1.0');
674
- program
675
- .command('init')
676
- .description('init rop')
677
- .action(function () { return __awaiter(void 0, void 0, void 0, function () {
678
- var accessKey, framework, init;
762
+ var InitApi = /** @class */ (function () {
763
+ function InitApi() {
764
+ }
765
+ InitApi.prototype.initProjectConfigJson = function (framework) {
766
+ return __awaiter(this, void 0, void 0, function () {
767
+ var jsonConfigPath, jsonConfigData, str;
768
+ return __generator(this, function (_a) {
769
+ switch (_a.label) {
770
+ case 0:
771
+ jsonConfigPath = path.join('.', 'rop.json');
772
+ if (!fs$1.existsSync(jsonConfigPath)) return [3 /*break*/, 2];
773
+ return [4 /*yield*/, confirm({
774
+ message: "".concat(colors.cyan('rop.json'), " already exists, does it need to be overwritten?"),
775
+ })];
776
+ case 1:
777
+ _a.sent();
778
+ str = fs$1.readFileSync(jsonConfigPath, 'utf8');
779
+ jsonConfigData = JSON.parse(str);
780
+ if (!jsonConfigData.framework) {
781
+ jsonConfigData.framework = {
782
+ name: framework,
783
+ };
784
+ }
785
+ else {
786
+ jsonConfigData.framework.name = framework;
787
+ }
788
+ return [3 /*break*/, 3];
789
+ case 2:
790
+ jsonConfigData = {
791
+ framework: {
792
+ name: framework,
793
+ },
794
+ };
795
+ _a.label = 3;
796
+ case 3:
797
+ fs$1.writeFileSync(jsonConfigPath, JSON.stringify(jsonConfigData, null, 2), 'utf8');
798
+ return [2 /*return*/];
799
+ }
800
+ });
801
+ });
802
+ };
803
+ InitApi.prototype.initRopConfig = function (projectId) {
804
+ return __awaiter(this, void 0, void 0, function () {
805
+ var ropConfigDirPath, ropConfigPath, ropConfigData;
806
+ return __generator(this, function (_a) {
807
+ ropConfigDirPath = path.join('.', '.rop');
808
+ if (!fs$1.existsSync(ropConfigDirPath)) {
809
+ fs$1.mkdirSync(ropConfigDirPath);
810
+ }
811
+ ropConfigPath = path.join(ropConfigDirPath, 'config.json');
812
+ ropConfigData = {};
813
+ if (fs$1.existsSync(ropConfigPath)) {
814
+ ropConfigData = JSON.parse(fs$1.readFileSync(ropConfigPath, 'utf8'));
815
+ }
816
+ ropConfigData.projectId = projectId;
817
+ fs$1.writeFileSync(ropConfigPath, JSON.stringify(ropConfigData, null, 2), 'utf8');
818
+ return [2 /*return*/];
819
+ });
820
+ });
821
+ };
822
+ InitApi.prototype.initGitignore = function () {
823
+ return __awaiter(this, void 0, void 0, function () {
824
+ var gitignorePath, gitignoreData;
825
+ return __generator(this, function (_a) {
826
+ gitignorePath = path.join('.', '.gitignore');
827
+ if (fs$1.existsSync(gitignorePath)) {
828
+ gitignoreData = fs$1.readFileSync(gitignorePath, 'utf8');
829
+ if (!gitignoreData.includes('.rop')) {
830
+ fs$1.appendFileSync(gitignorePath, "\n.rop", 'utf8');
831
+ }
832
+ }
833
+ else {
834
+ fs$1.writeFileSync(gitignorePath, ".rop", 'utf8');
835
+ }
836
+ return [2 /*return*/];
837
+ });
838
+ });
839
+ };
840
+ return InitApi;
841
+ }());
842
+
843
+ var defaultHost = 'http://rop.coolcat.tech:8100';
844
+
845
+ var LOGIN_API = '/api/auth/login';
846
+ var REFRESH_TOKEN_API = '/api/auth/refresh';
847
+ var CHECK_AND_REFRESH_TOKEN_API = '/api/auth/checkAndRefresh';
848
+ var AuthApi = /** @class */ (function () {
849
+ function AuthApi(_a) {
850
+ var baseDomain = _a.baseDomain;
851
+ this.baseDomain = baseDomain !== null && baseDomain !== void 0 ? baseDomain : defaultHost;
852
+ }
853
+ AuthApi.prototype.login = function (req) {
854
+ return __awaiter(this, void 0, void 0, function () {
855
+ var res, resBody, homedir, userFilePath;
856
+ return __generator(this, function (_a) {
857
+ switch (_a.label) {
858
+ case 0: return [4 /*yield*/, fetch("".concat(this.baseDomain).concat(LOGIN_API), {
859
+ method: 'POST',
860
+ headers: {
861
+ 'Content-Type': 'application/json;charset=utf-8',
862
+ },
863
+ body: JSON.stringify(req),
864
+ })];
865
+ case 1:
866
+ res = _a.sent();
867
+ return [4 /*yield*/, res.json()];
868
+ case 2:
869
+ resBody = _a.sent();
870
+ if (!res.ok || !resBody.data) {
871
+ if (!resBody.message || res.status != 400) {
872
+ console.log("Login failed: status=".concat(res.status, ", statusText=").concat(res.statusText));
873
+ }
874
+ else {
875
+ console.log(JSON.stringify(resBody));
876
+ }
877
+ return [2 /*return*/];
878
+ }
879
+ homedir = path.join(os.homedir(), '.rop');
880
+ if (!fs.existsSync(homedir)) {
881
+ fs.mkdirSync(homedir);
882
+ }
883
+ userFilePath = path.join(homedir, 'user');
884
+ fs.writeFileSync(userFilePath, JSON.stringify(resBody.data, null, 2), 'utf8');
885
+ return [2 /*return*/];
886
+ }
887
+ });
888
+ });
889
+ };
890
+ AuthApi.prototype.refreshToken = function () {
891
+ return __awaiter(this, void 0, void 0, function () {
892
+ var homedir, userFilePath, user, res, resBody;
893
+ return __generator(this, function (_a) {
894
+ switch (_a.label) {
895
+ case 0:
896
+ homedir = path.join(os.homedir(), '.rop');
897
+ userFilePath = path.join(homedir, 'user');
898
+ if (!fs.existsSync(userFilePath)) {
899
+ console.log('Unauthorized. Please execute the login command');
900
+ return [2 /*return*/];
901
+ }
902
+ user = JSON.parse(fs.readFileSync(userFilePath, 'utf8'));
903
+ return [4 /*yield*/, fetch("".concat(this.baseDomain).concat(REFRESH_TOKEN_API), {
904
+ method: 'POST',
905
+ headers: {
906
+ 'Content-Type': 'application/json;charset=utf-8',
907
+ },
908
+ body: JSON.stringify({ token: user.auth.refreshToken }),
909
+ })];
910
+ case 1:
911
+ res = _a.sent();
912
+ return [4 /*yield*/, res.json()];
913
+ case 2:
914
+ resBody = _a.sent();
915
+ if (!res.ok || !resBody.data) {
916
+ if (!resBody.message || res.status != 400) {
917
+ console.log("Refresh token failed: status=".concat(res.status, ", statusText=").concat(res.statusText));
918
+ }
919
+ else {
920
+ console.log('Authorization expired please execute the login command');
921
+ fs.rmSync(userFilePath);
922
+ }
923
+ throw new Error('Refresh token failed');
924
+ }
925
+ user.auth = resBody.data;
926
+ fs.writeFileSync(userFilePath, JSON.stringify(user), 'utf8');
927
+ return [2 /*return*/];
928
+ }
929
+ });
930
+ });
931
+ };
932
+ AuthApi.prototype.getToken = function () {
933
+ return __awaiter(this, void 0, void 0, function () {
934
+ var homedir, userFilePath;
935
+ return __generator(this, function (_a) {
936
+ homedir = path.join(os.homedir(), '.rop');
937
+ userFilePath = path.join(homedir, 'user');
938
+ if (!fs.existsSync(userFilePath)) {
939
+ return [2 /*return*/, undefined];
940
+ }
941
+ return [2 /*return*/, JSON.parse(fs.readFileSync(userFilePath, 'utf8'))];
942
+ });
943
+ });
944
+ };
945
+ AuthApi.prototype.checkAndRefreshToken = function () {
946
+ return __awaiter(this, void 0, void 0, function () {
947
+ var user, res, resBody, homedir, userFilePath;
948
+ return __generator(this, function (_a) {
949
+ switch (_a.label) {
950
+ case 0: return [4 /*yield*/, this.getToken()];
951
+ case 1:
952
+ user = _a.sent();
953
+ if (!user) {
954
+ return [2 /*return*/, undefined];
955
+ }
956
+ return [4 /*yield*/, fetch("".concat(this.baseDomain).concat(CHECK_AND_REFRESH_TOKEN_API), {
957
+ method: 'POST',
958
+ headers: {
959
+ 'Content-Type': 'application/json;charset=utf-8',
960
+ },
961
+ body: JSON.stringify(user.auth),
962
+ })];
963
+ case 2:
964
+ res = _a.sent();
965
+ return [4 /*yield*/, res.json()];
966
+ case 3:
967
+ resBody = _a.sent();
968
+ if (!res.ok || !resBody.data) {
969
+ return [2 /*return*/, undefined];
970
+ }
971
+ homedir = path.join(os.homedir(), '.rop');
972
+ userFilePath = path.join(homedir, 'user');
973
+ user = JSON.parse(fs.readFileSync(userFilePath, 'utf8'));
974
+ user.auth = resBody.data;
975
+ fs.writeFileSync(userFilePath, JSON.stringify(user), 'utf8');
976
+ return [2 /*return*/, user];
977
+ }
978
+ });
979
+ });
980
+ };
981
+ AuthApi.prototype.request = function (req) {
982
+ return __awaiter(this, void 0, void 0, function () {
983
+ var user, res, resBody, _a;
984
+ return __generator(this, function (_b) {
985
+ switch (_b.label) {
986
+ case 0: return [4 /*yield*/, this.getToken()];
987
+ case 1:
988
+ user = _b.sent();
989
+ if (!user) {
990
+ console.log('Unauthorized. Please execute the login command');
991
+ return [2 /*return*/, undefined];
992
+ }
993
+ return [4 /*yield*/, req(user.auth.accessToken)];
994
+ case 2:
995
+ res = _b.sent();
996
+ return [4 /*yield*/, res.json()];
997
+ case 3:
998
+ resBody = _b.sent();
999
+ if (!(!res.ok || !resBody.data)) return [3 /*break*/, 10];
1000
+ _a = res.status;
1001
+ switch (_a) {
1002
+ case 400: return [3 /*break*/, 4];
1003
+ case 401: return [3 /*break*/, 5];
1004
+ }
1005
+ return [3 /*break*/, 8];
1006
+ case 4:
1007
+ console.log(JSON.stringify(resBody));
1008
+ return [3 /*break*/, 9];
1009
+ case 5: return [4 /*yield*/, this.refreshToken()];
1010
+ case 6:
1011
+ _b.sent();
1012
+ return [4 /*yield*/, this.request(req)];
1013
+ case 7: return [2 /*return*/, _b.sent()];
1014
+ case 8:
1015
+ console.log("request failed: status=".concat(res.status, ", statusText=").concat(res.statusText));
1016
+ _b.label = 9;
1017
+ case 9: return [2 /*return*/, undefined];
1018
+ case 10: return [2 /*return*/, resBody.data];
1019
+ }
1020
+ });
1021
+ });
1022
+ };
1023
+ return AuthApi;
1024
+ }());
1025
+
1026
+ var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1027
+ var authApi, user, needLink, projectId, framework, projectName_1, project, projectName, body_1, project, init;
679
1028
  return __generator(this, function (_a) {
680
1029
  switch (_a.label) {
681
1030
  case 0:
682
- accessKey = '';
683
- _a.label = 1;
1031
+ authApi = new AuthApi({ baseDomain: defaultHost });
1032
+ return [4 /*yield*/, authApi.checkAndRefreshToken()];
684
1033
  case 1:
685
- if (!!accessKey) return [3 /*break*/, 6];
686
- _a.label = 2;
1034
+ user = _a.sent();
1035
+ if (!user) {
1036
+ throw new Error('Unauthorized. Please execute the login command');
1037
+ }
1038
+ return [4 /*yield*/, confirm({
1039
+ message: "Link to existing project?",
1040
+ })];
687
1041
  case 2:
688
- _a.trys.push([2, 4, , 5]);
689
- return [4 /*yield*/, input({ message: "Please enter ".concat(colors.cyan('access-key')) })];
1042
+ needLink = _a.sent();
1043
+ if (!needLink) return [3 /*break*/, 7];
1044
+ _a.label = 3;
690
1045
  case 3:
691
- accessKey = _a.sent();
692
- return [3 /*break*/, 5];
1046
+ if (!!projectName_1) return [3 /*break*/, 5];
1047
+ return [4 /*yield*/, input({ message: "What\u2019s the name of your existing project?" })];
693
1048
  case 4:
694
- _a.sent();
695
- console.log('cancel');
696
- return [2 /*return*/];
697
- case 5: return [3 /*break*/, 1];
698
- case 6: return [4 /*yield*/, select({
1049
+ projectName_1 = _a.sent();
1050
+ return [3 /*break*/, 3];
1051
+ case 5: return [4 /*yield*/, authApi.request(function (token) { return __awaiter(void 0, void 0, void 0, function () {
1052
+ return __generator(this, function (_a) {
1053
+ return [2 /*return*/, fetch("".concat(defaultHost, "/api/project/").concat(projectName_1), {
1054
+ method: 'GET',
1055
+ headers: {
1056
+ Authorization: "Bearer ".concat(token),
1057
+ },
1058
+ })];
1059
+ });
1060
+ }); })];
1061
+ case 6:
1062
+ project = _a.sent();
1063
+ if (!project) {
1064
+ throw new Error('project not found');
1065
+ }
1066
+ projectId = project.id;
1067
+ framework = project.framework;
1068
+ return [3 /*break*/, 13];
1069
+ case 7:
1070
+ projectName = void 0;
1071
+ _a.label = 8;
1072
+ case 8:
1073
+ if (!!projectName) return [3 /*break*/, 10];
1074
+ return [4 /*yield*/, input({ message: "What\u2019s your project\u2019s name?" })];
1075
+ case 9:
1076
+ projectName = _a.sent();
1077
+ return [3 /*break*/, 8];
1078
+ case 10: return [4 /*yield*/, select({
699
1079
  message: "Please Select ".concat(colors.cyan('framework')),
700
1080
  choices: [
701
1081
  {
702
1082
  name: 'tauri',
703
1083
  value: 'tauri',
704
1084
  },
1085
+ {
1086
+ name: 'ionic',
1087
+ value: 'ionic',
1088
+ },
1089
+ {
1090
+ name: 'flutter',
1091
+ value: 'flutter',
1092
+ },
1093
+ {
1094
+ name: 'other',
1095
+ value: 'other',
1096
+ },
705
1097
  ],
706
1098
  })];
707
- case 7:
1099
+ case 11:
708
1100
  framework = _a.sent();
709
- init = new Init();
1101
+ body_1 = {
1102
+ name: projectName,
1103
+ framework: framework,
1104
+ };
1105
+ return [4 /*yield*/, authApi.request(function (token) { return __awaiter(void 0, void 0, void 0, function () {
1106
+ return __generator(this, function (_a) {
1107
+ return [2 /*return*/, fetch("".concat(defaultHost, "/api/project"), {
1108
+ method: 'POST',
1109
+ headers: {
1110
+ Accept: 'application/json',
1111
+ 'Content-Type': 'application/json;charset=utf-8',
1112
+ Authorization: "Bearer ".concat(token),
1113
+ },
1114
+ body: JSON.stringify(body_1),
1115
+ })];
1116
+ });
1117
+ }); })];
1118
+ case 12:
1119
+ project = _a.sent();
1120
+ if (!project) {
1121
+ throw new Error('project create failed');
1122
+ }
1123
+ projectId = project.id;
1124
+ framework = project.framework;
1125
+ _a.label = 13;
1126
+ case 13:
1127
+ init = new InitApi();
710
1128
  return [4 /*yield*/, init.initProjectConfigJson(framework)];
711
- case 8:
712
- if (!_a.sent()) return [3 /*break*/, 11];
713
- return [4 /*yield*/, init.initRopConfig(accessKey)];
714
- case 9:
1129
+ case 14:
1130
+ _a.sent();
1131
+ return [4 /*yield*/, init.initRopConfig(projectId)];
1132
+ case 15:
715
1133
  _a.sent();
716
1134
  return [4 /*yield*/, init.initGitignore()];
717
- case 10:
1135
+ case 16:
718
1136
  _a.sent();
719
- console.log('done');
720
- _a.label = 11;
721
- case 11: return [2 /*return*/];
1137
+ console.log('Init successful');
1138
+ return [2 /*return*/, projectId];
722
1139
  }
723
1140
  });
724
- }); });
725
- program
726
- .command('set-key')
727
- .description('set access-key')
728
- .argument('<string>', 'projectAccessKey')
729
- .action(function (projectAccessKey) { return __awaiter(void 0, void 0, void 0, function () {
730
- var array, projectName, accessKey, homedir, filePath, content, configData;
1141
+ }); };
1142
+
1143
+ var login = function (options) { return __awaiter(void 0, void 0, void 0, function () {
1144
+ var username, password$1, loginReq, auth;
731
1145
  return __generator(this, function (_a) {
732
- try {
733
- array = projectAccessKey.split('=');
734
- if (array.length != 2) {
735
- throw new Error('parameter format error');
736
- }
737
- projectName = array[0], accessKey = array[1];
738
- homedir = path.join('.', '.rop');
739
- if (!fs.existsSync(homedir)) {
740
- fs.mkdirSync(homedir);
741
- }
742
- filePath = "".concat(homedir, "/config.json");
743
- content = {
744
- accessKey: accessKey,
745
- };
746
- if (!fs.existsSync(filePath)) {
747
- fs.writeFileSync(filePath, JSON.stringify(content, null, 2), 'utf8');
748
- }
749
- else {
750
- configData = fs.readFileSync(filePath, 'utf8');
751
- content = JSON.parse(configData);
752
- content.accessKey = accessKey;
753
- fs.writeFileSync(filePath, JSON.stringify(content, null, 2), 'utf8');
754
- }
755
- }
756
- catch (error) {
757
- console.error('Error reading configuration file or missing required properties:', error);
1146
+ switch (_a.label) {
1147
+ case 0:
1148
+ username = options.username, password$1 = options.password;
1149
+ _a.label = 1;
1150
+ case 1:
1151
+ if (!!username) return [3 /*break*/, 6];
1152
+ _a.label = 2;
1153
+ case 2:
1154
+ _a.trys.push([2, 4, , 5]);
1155
+ return [4 /*yield*/, input({ message: "Please enter ".concat(colors.cyan('username')) })];
1156
+ case 3:
1157
+ username = _a.sent();
1158
+ return [3 /*break*/, 5];
1159
+ case 4:
1160
+ _a.sent();
1161
+ console.log('cancel');
1162
+ return [2 /*return*/];
1163
+ case 5: return [3 /*break*/, 1];
1164
+ case 6:
1165
+ if (!!password$1) return [3 /*break*/, 11];
1166
+ _a.label = 7;
1167
+ case 7:
1168
+ _a.trys.push([7, 9, , 10]);
1169
+ return [4 /*yield*/, password({ mask: true, message: "Please enter ".concat(colors.cyan('password')) })];
1170
+ case 8:
1171
+ password$1 = _a.sent();
1172
+ return [3 /*break*/, 10];
1173
+ case 9:
1174
+ _a.sent();
1175
+ console.log('cancel');
1176
+ return [2 /*return*/];
1177
+ case 10: return [3 /*break*/, 6];
1178
+ case 11:
1179
+ loginReq = {
1180
+ username: username,
1181
+ password: password$1,
1182
+ };
1183
+ auth = new AuthApi({ baseDomain: defaultHost });
1184
+ return [4 /*yield*/, auth.login(loginReq)];
1185
+ case 12:
1186
+ _a.sent();
1187
+ console.log('Login successful. Please use [rop init ]to create a project.');
1188
+ return [2 /*return*/];
758
1189
  }
759
- return [2 /*return*/];
760
1190
  });
761
- }); });
762
- program
763
- .command('upload')
764
- .description('Upload some framework build')
765
- .argument('<string>', 'platform')
766
- .argument('[string]', 'arch')
767
- .option('-a, --accessKey <string>', 'accessKey path')
768
- .action(function (platform, arch, options) { return __awaiter(void 0, void 0, void 0, function () {
769
- var _a, config, targetInfo, accessKey, version, signature, uploadClient;
770
- var _b, _c, _d, _e, _f;
771
- return __generator(this, function (_g) {
772
- switch (_g.label) {
1191
+ }); };
1192
+
1193
+ var _upload = function (config) { return __awaiter(void 0, void 0, void 0, function () {
1194
+ var accessKey, projectId, token, artifact, arch, version, platform, signature, uploadClient;
1195
+ var _a, _b, _c, _d, _e;
1196
+ return __generator(this, function (_f) {
1197
+ switch (_f.label) {
773
1198
  case 0:
774
- _a = loadJsonWithEnv({
775
- platform: platform,
776
- arch: arch,
777
- optionAccessKey: options.accessKey,
778
- }), config = _a.config, targetInfo = _a.targetInfo, accessKey = _a.accessKey, version = _a.version;
779
- if (!targetInfo) {
780
- throw new Error('Missing "targetInfo" property in the configuration file.');
781
- }
782
- if ((_b = targetInfo.sig) === null || _b === void 0 ? void 0 : _b.path) {
783
- if (fs.existsSync(targetInfo.sig.path)) {
784
- signature = fs.readFileSync(targetInfo.sig.path, 'utf8');
1199
+ accessKey = config.accessKey, projectId = config.projectId, token = config.token, artifact = config.artifact, arch = config.arch, version = config.version, platform = config.platform, config.host;
1200
+ if ((_a = artifact.sig) === null || _a === void 0 ? void 0 : _a.path) {
1201
+ if (fs$1.existsSync(artifact.sig.path)) {
1202
+ signature = fs$1.readFileSync(artifact.sig.path, 'utf8');
785
1203
  }
786
1204
  else {
787
1205
  console.warn('Warn sig file not found');
788
1206
  }
789
1207
  }
790
- uploadClient = new RopUpload({ baseDomain: (_c = config.host) !== null && _c !== void 0 ? _c : 'http://localhost:3000' });
1208
+ uploadClient = new RopUploadApi({ baseDomain: (_b = config.host) !== null && _b !== void 0 ? _b : defaultHost });
791
1209
  return [4 /*yield*/, uploadClient.upload({
792
1210
  accessKey: accessKey,
1211
+ projectId: projectId,
1212
+ token: token,
793
1213
  arch: arch,
794
1214
  platform: platform,
795
1215
  version: version,
796
- targetPath: targetInfo.target.path,
797
- targetName: (_d = targetInfo.target) === null || _d === void 0 ? void 0 : _d.name,
798
- updatePath: (_e = targetInfo.update) === null || _e === void 0 ? void 0 : _e.path,
799
- updateName: (_f = targetInfo.update) === null || _f === void 0 ? void 0 : _f.name,
1216
+ targetPath: artifact.target.path,
1217
+ targetName: (_c = artifact.target) === null || _c === void 0 ? void 0 : _c.name,
1218
+ updatePath: (_d = artifact.update) === null || _d === void 0 ? void 0 : _d.path,
1219
+ updateName: (_e = artifact.update) === null || _e === void 0 ? void 0 : _e.name,
800
1220
  signature: signature,
801
1221
  })];
802
1222
  case 1:
803
- _g.sent();
1223
+ _f.sent();
1224
+ return [2 /*return*/];
1225
+ }
1226
+ });
1227
+ }); };
1228
+ var upload = function (platform, arch, options) { return __awaiter(void 0, void 0, void 0, function () {
1229
+ var configFilePath, data, projectId, token, jsonConfig, authApi, user, targetInfos, config, reset, _i, targetInfos_1, item;
1230
+ return __generator(this, function (_a) {
1231
+ switch (_a.label) {
1232
+ case 0:
1233
+ configFilePath = path.join('.', 'rop.json');
1234
+ if (!!fs$1.existsSync(configFilePath)) return [3 /*break*/, 2];
1235
+ return [4 /*yield*/, init()];
1236
+ case 1:
1237
+ _a.sent();
1238
+ _a.label = 2;
1239
+ case 2:
1240
+ data = loadJsonWithEnv({
1241
+ platform: platform,
1242
+ arch: arch,
1243
+ });
1244
+ if (!!options.accessKey) return [3 /*break*/, 7];
1245
+ jsonConfig = loadConfigJSON();
1246
+ if (!!jsonConfig.projectId) return [3 /*break*/, 4];
1247
+ return [4 /*yield*/, init()];
1248
+ case 3:
1249
+ projectId = _a.sent();
1250
+ return [3 /*break*/, 5];
1251
+ case 4:
1252
+ projectId = jsonConfig.projectId;
1253
+ _a.label = 5;
1254
+ case 5:
1255
+ authApi = new AuthApi({ baseDomain: defaultHost });
1256
+ return [4 /*yield*/, authApi.checkAndRefreshToken()];
1257
+ case 6:
1258
+ user = _a.sent();
1259
+ if (!user) {
1260
+ console.log('Unauthorized. Please execute the login command');
1261
+ return [2 /*return*/];
1262
+ }
1263
+ token = user.auth.accessToken;
1264
+ _a.label = 7;
1265
+ case 7:
1266
+ targetInfos = data.targetInfos, config = data.config, reset = __rest(data, ["targetInfos", "config"]);
1267
+ _i = 0, targetInfos_1 = targetInfos;
1268
+ _a.label = 8;
1269
+ case 8:
1270
+ if (!(_i < targetInfos_1.length)) return [3 /*break*/, 11];
1271
+ item = targetInfos_1[_i];
1272
+ return [4 /*yield*/, _upload(__assign(__assign({ accessKey: options.accessKey, projectId: projectId, token: token }, reset), { artifact: item.artifacts, host: config.host, platform: platform }))];
1273
+ case 9:
1274
+ _a.sent();
1275
+ _a.label = 10;
1276
+ case 10:
1277
+ _i++;
1278
+ return [3 /*break*/, 8];
1279
+ case 11: return [2 /*return*/];
1280
+ }
1281
+ });
1282
+ }); };
1283
+
1284
+ var program = new Command();
1285
+ program.name('rop').description('CLI to some JavaScript string utilities').version('0.1.0');
1286
+ program
1287
+ .command('login')
1288
+ .description('login')
1289
+ .option('-u --username <string>', 'username')
1290
+ .option('-p --password <string>', 'password')
1291
+ .action(login);
1292
+ program
1293
+ .command('init')
1294
+ .description('init rop')
1295
+ .action(function () { return __awaiter(void 0, void 0, void 0, function () {
1296
+ return __generator(this, function (_a) {
1297
+ switch (_a.label) {
1298
+ case 0: return [4 /*yield*/, init()];
1299
+ case 1:
1300
+ _a.sent();
804
1301
  return [2 /*return*/];
805
1302
  }
806
1303
  });
807
1304
  }); });
1305
+ program
1306
+ .command('upload')
1307
+ .description('Upload some framework build')
1308
+ .argument('<string>', 'platform')
1309
+ .argument('[string]', 'arch')
1310
+ .option('-a, --accessKey <string>', 'accessKey path')
1311
+ .action(upload);
808
1312
  // 解析命令行参数
809
1313
  program.parse();
810
1314
  // // // 如果没有指定任何命令,则显示帮助信息