@sevenvip666/rop 0.0.9 → 0.1.0

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