@sevenvip666/rop 0.1.1 → 0.1.3

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.
@@ -15,6 +15,7 @@ import JSON5 from 'json5';
15
15
  import yaml from 'js-yaml';
16
16
  import { confirm, select, input, password } from '@inquirer/prompts';
17
17
  import * as os from 'node:os';
18
+ import chalk from 'chalk';
18
19
 
19
20
  /******************************************************************************
20
21
  Copyright (c) Microsoft Corporation.
@@ -210,7 +211,6 @@ var TauriConfig = /** @class */ (function () {
210
211
  this.identifier = identifier;
211
212
  }
212
213
  TauriConfig.fromBaseConfig = function (tauriDir) {
213
- console.log(tauriDir);
214
214
  if (existsSync(join(tauriDir, 'tauri.conf.json'))) {
215
215
  var contents = readFileSync(join(tauriDir, 'tauri.conf.json')).toString();
216
216
  var config = _tryParseJsonConfig(contents);
@@ -559,13 +559,15 @@ function loadJsonWithEnv(_a) {
559
559
  config = inputConfig;
560
560
  }
561
561
  if (!config.platforms || Object.keys(config.platforms).length == 0) {
562
- throw new Error('platforms is not null');
562
+ console.log(colors.red('The platforms property in rop.json cannot be empty.'));
563
+ return;
563
564
  }
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);
565
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 : {}));
566
567
  // 确保配置文件中存在 host 属性
567
568
  if (!env.version) {
568
- throw new Error('Missing "version" property in the configuration file.');
569
+ console.log(colors.red('The version property in rop.json cannot be empty.'));
570
+ return;
569
571
  }
570
572
  // 递归函数来替换对象中的字符串值
571
573
  function replaceEnvInObject(obj) {
@@ -582,8 +584,8 @@ function loadJsonWithEnv(_a) {
582
584
  }
583
585
  replaceEnvInObject(config);
584
586
  var targetInfos = getTargetInfo(config.platforms, platform, _arch);
585
- console.log('find target file:');
586
- console.log(targetInfos);
587
+ console.log(colors.cyan("find target file:"));
588
+ console.log("".concat(JSON.stringify(targetInfos)));
587
589
  return { config: config, targetInfos: targetInfos, version: env.version, arch: _arch };
588
590
  }
589
591
  var loadConfigJSON = function () {
@@ -597,6 +599,7 @@ var loadConfigJSON = function () {
597
599
  var configData = JSON.parse(configDataStr);
598
600
  return {
599
601
  projectId: configData.projectId,
602
+ accessKey: configData.accessKey,
600
603
  };
601
604
  };
602
605
  var getAutoEnvByFramework = function (framework, projectPath) {
@@ -636,8 +639,13 @@ var RopUploadApi = /** @class */ (function () {
636
639
  switch (_c.label) {
637
640
  case 0:
638
641
  if (!config.accessKey) {
639
- if (!config.token || !config.projectId) {
640
- throw new Error('accessKey, token, projectId cannot be empty at the same time');
642
+ if (!config.token) {
643
+ console.log(colors.red("Either accessKey or token must be used"));
644
+ return [2 /*return*/, false];
645
+ }
646
+ if (!config.projectId) {
647
+ console.log(colors.red("projectId cannot be empty"));
648
+ return [2 /*return*/, false];
641
649
  }
642
650
  }
643
651
  if (!((_b = config.branch) !== null && _b !== void 0)) return [3 /*break*/, 1];
@@ -650,22 +658,27 @@ var RopUploadApi = /** @class */ (function () {
650
658
  case 3:
651
659
  branch = _a;
652
660
  if (!branch) {
653
- throw new Error('branch not null');
661
+ console.log(colors.red("branch cannot be empty"));
662
+ return [2 /*return*/, false];
654
663
  }
655
664
  else {
656
665
  config.branch = branch;
657
666
  }
658
667
  if (!config.platform) {
659
- throw new Error('platform not null');
668
+ console.log(colors.red("platform cannot be empty"));
669
+ return [2 /*return*/, false];
660
670
  }
661
671
  if (!config.arch) {
662
- throw new Error('arch not null');
672
+ console.log(colors.red("arch cannot be empty"));
673
+ return [2 /*return*/, false];
663
674
  }
664
675
  if (!config.targetPath) {
665
- throw new Error('target path not null');
676
+ console.log(colors.red("target path cannot be empty"));
677
+ return [2 /*return*/, false];
666
678
  }
667
679
  if (!fs.existsSync(config.targetPath)) {
668
- throw new Error("target file not found, file path: ".concat(config.targetPath));
680
+ console.log(colors.red("target file not found, file path: ".concat(config.targetPath)));
681
+ return [2 /*return*/, false];
669
682
  }
670
683
  // 如果更新包不存在的情况使用本身的包
671
684
  if (config.updatePath && !fs.existsSync(config.updatePath)) {
@@ -673,7 +686,8 @@ var RopUploadApi = /** @class */ (function () {
673
686
  config.updateName = config.targetName;
674
687
  }
675
688
  if (!config.version) {
676
- throw new Error('version not null');
689
+ console.log(colors.red("version cannot be empty"));
690
+ return [2 /*return*/, false];
677
691
  }
678
692
  return [2 /*return*/, config];
679
693
  }
@@ -690,6 +704,9 @@ var RopUploadApi = /** @class */ (function () {
690
704
  case 0: return [4 /*yield*/, this.checkParams(_config)];
691
705
  case 1:
692
706
  config = _c.sent();
707
+ if (!config) {
708
+ return [2 /*return*/];
709
+ }
693
710
  formData = new FormData();
694
711
  fileStream = fs.createReadStream(config.targetPath);
695
712
  multibar = new cliProgress.MultiBar({
@@ -735,6 +752,9 @@ var RopUploadApi = /** @class */ (function () {
735
752
  if (config.signature) {
736
753
  formData.append('signature', config.signature);
737
754
  }
755
+ if (config.autoRelease) {
756
+ formData.append('autoRelease', String(config.autoRelease));
757
+ }
738
758
  return [4 /*yield*/, fetch$1("".concat(this.baseDomain, "/api/upload"), {
739
759
  method: 'POST',
740
760
  headers: formData.getHeaders(),
@@ -751,6 +771,7 @@ var RopUploadApi = /** @class */ (function () {
751
771
  multibar.stop();
752
772
  fileStream.destroy();
753
773
  updateFileStream === null || updateFileStream === void 0 ? void 0 : updateFileStream.destroy();
774
+ console.log(colors.green("Upload success!"));
754
775
  return [2 /*return*/, { success: res.ok, body: body }];
755
776
  }
756
777
  });
@@ -764,7 +785,7 @@ var InitApi = /** @class */ (function () {
764
785
  }
765
786
  InitApi.prototype.initProjectConfigJson = function (framework) {
766
787
  return __awaiter(this, void 0, void 0, function () {
767
- var jsonConfigPath, jsonConfigData, str;
788
+ var jsonConfigPath, jsonConfigData, flag, str;
768
789
  return __generator(this, function (_a) {
769
790
  switch (_a.label) {
770
791
  case 0:
@@ -774,7 +795,10 @@ var InitApi = /** @class */ (function () {
774
795
  message: "".concat(colors.cyan('rop.json'), " already exists, does it need to be overwritten?"),
775
796
  })];
776
797
  case 1:
777
- _a.sent();
798
+ flag = _a.sent();
799
+ if (!flag) {
800
+ return [2 /*return*/, false];
801
+ }
778
802
  str = fs$1.readFileSync(jsonConfigPath, 'utf8');
779
803
  jsonConfigData = JSON.parse(str);
780
804
  if (!jsonConfigData.framework) {
@@ -795,12 +819,12 @@ var InitApi = /** @class */ (function () {
795
819
  _a.label = 3;
796
820
  case 3:
797
821
  fs$1.writeFileSync(jsonConfigPath, JSON.stringify(jsonConfigData, null, 2), 'utf8');
798
- return [2 /*return*/];
822
+ return [2 /*return*/, true];
799
823
  }
800
824
  });
801
825
  });
802
826
  };
803
- InitApi.prototype.initRopConfig = function (projectId) {
827
+ InitApi.prototype.initRopConfig = function (projectId, accessKey) {
804
828
  return __awaiter(this, void 0, void 0, function () {
805
829
  var ropConfigDirPath, ropConfigPath, ropConfigData;
806
830
  return __generator(this, function (_a) {
@@ -814,6 +838,9 @@ var InitApi = /** @class */ (function () {
814
838
  ropConfigData = JSON.parse(fs$1.readFileSync(ropConfigPath, 'utf8'));
815
839
  }
816
840
  ropConfigData.projectId = projectId;
841
+ if (accessKey) {
842
+ ropConfigData.accessKey = accessKey;
843
+ }
817
844
  fs$1.writeFileSync(ropConfigPath, JSON.stringify(ropConfigData, null, 2), 'utf8');
818
845
  return [2 /*return*/];
819
846
  });
@@ -840,7 +867,7 @@ var InitApi = /** @class */ (function () {
840
867
  return InitApi;
841
868
  }());
842
869
 
843
- var defaultHost = 'http://rop.coolcat.tech:8100';
870
+ var defaultHost = 'https://rop.xh920.com';
844
871
 
845
872
  var LOGIN_API = '/api/auth/login';
846
873
  var REFRESH_TOKEN_API = '/api/auth/refresh';
@@ -853,8 +880,9 @@ var AuthApi = /** @class */ (function () {
853
880
  AuthApi.prototype.login = function (req) {
854
881
  return __awaiter(this, void 0, void 0, function () {
855
882
  var res, resBody, homedir, userFilePath;
856
- return __generator(this, function (_a) {
857
- switch (_a.label) {
883
+ var _a;
884
+ return __generator(this, function (_b) {
885
+ switch (_b.label) {
858
886
  case 0: return [4 /*yield*/, fetch("".concat(this.baseDomain).concat(LOGIN_API), {
859
887
  method: 'POST',
860
888
  headers: {
@@ -863,18 +891,13 @@ var AuthApi = /** @class */ (function () {
863
891
  body: JSON.stringify(req),
864
892
  })];
865
893
  case 1:
866
- res = _a.sent();
894
+ res = _b.sent();
867
895
  return [4 /*yield*/, res.json()];
868
896
  case 2:
869
- resBody = _a.sent();
897
+ resBody = _b.sent();
870
898
  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*/];
899
+ console.log(chalk.red("Login failed: status:".concat(res.status, ", message:").concat((_a = resBody.message) !== null && _a !== void 0 ? _a : res.statusText)));
900
+ return [2 /*return*/, false];
878
901
  }
879
902
  homedir = path.join(os.homedir(), '.rop');
880
903
  if (!fs.existsSync(homedir)) {
@@ -882,7 +905,7 @@ var AuthApi = /** @class */ (function () {
882
905
  }
883
906
  userFilePath = path.join(homedir, 'user');
884
907
  fs.writeFileSync(userFilePath, JSON.stringify(resBody.data, null, 2), 'utf8');
885
- return [2 /*return*/];
908
+ return [2 /*return*/, true];
886
909
  }
887
910
  });
888
911
  });
@@ -896,8 +919,8 @@ var AuthApi = /** @class */ (function () {
896
919
  homedir = path.join(os.homedir(), '.rop');
897
920
  userFilePath = path.join(homedir, 'user');
898
921
  if (!fs.existsSync(userFilePath)) {
899
- console.log('Unauthorized. Please execute the login command');
900
- return [2 /*return*/];
922
+ console.log(chalk.red("No permission! Please execute [rop login] or use --accessKey"));
923
+ return [2 /*return*/, false];
901
924
  }
902
925
  user = JSON.parse(fs.readFileSync(userFilePath, 'utf8'));
903
926
  return [4 /*yield*/, fetch("".concat(this.baseDomain).concat(REFRESH_TOKEN_API), {
@@ -914,17 +937,17 @@ var AuthApi = /** @class */ (function () {
914
937
  resBody = _a.sent();
915
938
  if (!res.ok || !resBody.data) {
916
939
  if (!resBody.message || res.status != 400) {
917
- console.log("Refresh token failed: status=".concat(res.status, ", statusText=").concat(res.statusText));
940
+ console.log(chalk.red("Refresh token failed: status:".concat(res.status, ", statusText:").concat(res.statusText)));
918
941
  }
919
942
  else {
920
- console.log('Authorization expired please execute the login command');
943
+ console.log(chalk.red("Authorization expired please execute the login command"));
921
944
  fs.rmSync(userFilePath);
922
945
  }
923
- throw new Error('Refresh token failed');
946
+ return [2 /*return*/, false];
924
947
  }
925
948
  user.auth = resBody.data;
926
949
  fs.writeFileSync(userFilePath, JSON.stringify(user), 'utf8');
927
- return [2 /*return*/];
950
+ return [2 /*return*/, true];
928
951
  }
929
952
  });
930
953
  });
@@ -980,14 +1003,14 @@ var AuthApi = /** @class */ (function () {
980
1003
  };
981
1004
  AuthApi.prototype.request = function (req) {
982
1005
  return __awaiter(this, void 0, void 0, function () {
983
- var user, res, resBody, _a;
1006
+ var user, res, resBody, _a, result;
984
1007
  return __generator(this, function (_b) {
985
1008
  switch (_b.label) {
986
1009
  case 0: return [4 /*yield*/, this.getToken()];
987
1010
  case 1:
988
1011
  user = _b.sent();
989
1012
  if (!user) {
990
- console.log('Unauthorized. Please execute the login command');
1013
+ console.log(colors.red("No permission! Please execute [rop login]"));
991
1014
  return [2 /*return*/, undefined];
992
1015
  }
993
1016
  return [4 /*yield*/, req(user.auth.accessToken)];
@@ -996,26 +1019,28 @@ var AuthApi = /** @class */ (function () {
996
1019
  return [4 /*yield*/, res.json()];
997
1020
  case 3:
998
1021
  resBody = _b.sent();
999
- if (!(!res.ok || !resBody.data)) return [3 /*break*/, 10];
1022
+ if (!(!res.ok || !resBody.data)) return [3 /*break*/, 11];
1000
1023
  _a = res.status;
1001
1024
  switch (_a) {
1002
1025
  case 400: return [3 /*break*/, 4];
1003
1026
  case 401: return [3 /*break*/, 5];
1004
1027
  }
1005
- return [3 /*break*/, 8];
1028
+ return [3 /*break*/, 9];
1006
1029
  case 4:
1007
1030
  console.log(JSON.stringify(resBody));
1008
- return [3 /*break*/, 9];
1031
+ return [3 /*break*/, 10];
1009
1032
  case 5: return [4 /*yield*/, this.refreshToken()];
1010
1033
  case 6:
1011
- _b.sent();
1034
+ result = _b.sent();
1035
+ if (!result) return [3 /*break*/, 8];
1012
1036
  return [4 /*yield*/, this.request(req)];
1013
1037
  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];
1038
+ case 8: return [3 /*break*/, 10];
1039
+ case 9:
1040
+ console.log(colors.red("request failed: status:".concat(res.status, ", statusText:").concat(res.statusText)));
1041
+ _b.label = 10;
1042
+ case 10: return [2 /*return*/, undefined];
1043
+ case 11: return [2 /*return*/, resBody.data];
1019
1044
  }
1020
1045
  });
1021
1046
  });
@@ -1024,7 +1049,7 @@ var AuthApi = /** @class */ (function () {
1024
1049
  }());
1025
1050
 
1026
1051
  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;
1052
+ var authApi, user, needLink, projectId, framework, accessKey, projectName_1, project, projectName, body_1, project, init;
1028
1053
  return __generator(this, function (_a) {
1029
1054
  switch (_a.label) {
1030
1055
  case 0:
@@ -1033,13 +1058,15 @@ var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1033
1058
  case 1:
1034
1059
  user = _a.sent();
1035
1060
  if (!user) {
1036
- throw new Error('Unauthorized. Please execute the login command');
1061
+ console.log(colors.red("No permission! Please execute [rop login]"));
1062
+ return [2 /*return*/];
1037
1063
  }
1038
1064
  return [4 /*yield*/, confirm({
1039
1065
  message: "Link to existing project?",
1040
1066
  })];
1041
1067
  case 2:
1042
1068
  needLink = _a.sent();
1069
+ accessKey = undefined;
1043
1070
  if (!needLink) return [3 /*break*/, 7];
1044
1071
  _a.label = 3;
1045
1072
  case 3:
@@ -1061,7 +1088,8 @@ var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1061
1088
  case 6:
1062
1089
  project = _a.sent();
1063
1090
  if (!project) {
1064
- throw new Error('project not found');
1091
+ console.log(colors.yellow("project not found"));
1092
+ return [2 /*return*/];
1065
1093
  }
1066
1094
  projectId = project.id;
1067
1095
  framework = project.framework;
@@ -1118,30 +1146,43 @@ var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1118
1146
  case 12:
1119
1147
  project = _a.sent();
1120
1148
  if (!project) {
1121
- throw new Error('project create failed');
1149
+ console.log(colors.red("project create failed"));
1150
+ return [2 /*return*/];
1122
1151
  }
1123
1152
  projectId = project.id;
1124
1153
  framework = project.framework;
1154
+ accessKey = project.accessKeys[0].accessKey;
1125
1155
  _a.label = 13;
1126
1156
  case 13:
1127
1157
  init = new InitApi();
1128
1158
  return [4 /*yield*/, init.initProjectConfigJson(framework)];
1129
1159
  case 14:
1130
- _a.sent();
1131
- return [4 /*yield*/, init.initRopConfig(projectId)];
1160
+ if (!_a.sent()) return [3 /*break*/, 17];
1161
+ return [4 /*yield*/, init.initRopConfig(projectId, accessKey)];
1132
1162
  case 15:
1133
1163
  _a.sent();
1134
1164
  return [4 /*yield*/, init.initGitignore()];
1135
1165
  case 16:
1136
1166
  _a.sent();
1137
- console.log('Init successful');
1138
- return [2 /*return*/, projectId];
1167
+ console.log(colors.green("Initialize project successfully!"));
1168
+ if (framework.toLowerCase() === 'tauri') {
1169
+ console.log(colors.blue("updater endpoints : ".concat(defaultHost, "/api/tauri/").concat(projectId, "/[your branch]/{{target}}/{{arch}}/{{current_version}}")));
1170
+ console.log('Please replace [your branch] with your own branch');
1171
+ }
1172
+ return [2 /*return*/, {
1173
+ projectId: projectId,
1174
+ accessKey: accessKey,
1175
+ }];
1176
+ case 17: return [2 /*return*/, {
1177
+ projectId: undefined,
1178
+ accessKey: undefined,
1179
+ }];
1139
1180
  }
1140
1181
  });
1141
1182
  }); };
1142
1183
 
1143
1184
  var login = function (options) { return __awaiter(void 0, void 0, void 0, function () {
1144
- var username, password$1, loginReq, auth;
1185
+ var username, password$1, loginReq, auth, result;
1145
1186
  return __generator(this, function (_a) {
1146
1187
  switch (_a.label) {
1147
1188
  case 0:
@@ -1158,7 +1199,7 @@ var login = function (options) { return __awaiter(void 0, void 0, void 0, functi
1158
1199
  return [3 /*break*/, 5];
1159
1200
  case 4:
1160
1201
  _a.sent();
1161
- console.log('cancel');
1202
+ console.log(colors.gray('cancel'));
1162
1203
  return [2 /*return*/];
1163
1204
  case 5: return [3 /*break*/, 1];
1164
1205
  case 6:
@@ -1172,7 +1213,7 @@ var login = function (options) { return __awaiter(void 0, void 0, void 0, functi
1172
1213
  return [3 /*break*/, 10];
1173
1214
  case 9:
1174
1215
  _a.sent();
1175
- console.log('cancel');
1216
+ console.log(colors.gray('cancel'));
1176
1217
  return [2 /*return*/];
1177
1218
  case 10: return [3 /*break*/, 6];
1178
1219
  case 11:
@@ -1183,26 +1224,28 @@ var login = function (options) { return __awaiter(void 0, void 0, void 0, functi
1183
1224
  auth = new AuthApi({ baseDomain: defaultHost });
1184
1225
  return [4 /*yield*/, auth.login(loginReq)];
1185
1226
  case 12:
1186
- _a.sent();
1187
- console.log('Login successful. Please use [rop init ]to create a project.');
1227
+ result = _a.sent();
1228
+ if (result) {
1229
+ console.log(colors.green("Login successful. Please use [rop init] to create a project."));
1230
+ }
1188
1231
  return [2 /*return*/];
1189
1232
  }
1190
1233
  });
1191
1234
  }); };
1192
1235
 
1193
1236
  var _upload = function (config) { return __awaiter(void 0, void 0, void 0, function () {
1194
- var accessKey, projectId, token, artifact, arch, version, platform, signature, uploadClient;
1237
+ var accessKey, projectId, token, artifact, arch, version, platform, autoRelease, signature, uploadClient;
1195
1238
  var _a, _b, _c, _d, _e;
1196
1239
  return __generator(this, function (_f) {
1197
1240
  switch (_f.label) {
1198
1241
  case 0:
1199
- accessKey = config.accessKey, projectId = config.projectId, token = config.token, artifact = config.artifact, arch = config.arch, version = config.version, platform = config.platform, config.host;
1242
+ accessKey = config.accessKey, projectId = config.projectId, token = config.token, artifact = config.artifact, arch = config.arch, version = config.version, platform = config.platform, config.host, autoRelease = config.autoRelease;
1200
1243
  if ((_a = artifact.sig) === null || _a === void 0 ? void 0 : _a.path) {
1201
1244
  if (fs$1.existsSync(artifact.sig.path)) {
1202
1245
  signature = fs$1.readFileSync(artifact.sig.path, 'utf8');
1203
1246
  }
1204
1247
  else {
1205
- console.warn('Warn sig file not found');
1248
+ console.log(colors.cyan('Warn sig file not found'));
1206
1249
  }
1207
1250
  }
1208
1251
  uploadClient = new RopUploadApi({ baseDomain: (_b = config.host) !== null && _b !== void 0 ? _b : defaultHost });
@@ -1218,6 +1261,8 @@ var _upload = function (config) { return __awaiter(void 0, void 0, void 0, funct
1218
1261
  updatePath: (_d = artifact.update) === null || _d === void 0 ? void 0 : _d.path,
1219
1262
  updateName: (_e = artifact.update) === null || _e === void 0 ? void 0 : _e.name,
1220
1263
  signature: signature,
1264
+ branch: config.branch,
1265
+ autoRelease: autoRelease,
1221
1266
  })];
1222
1267
  case 1:
1223
1268
  _f.sent();
@@ -1226,53 +1271,66 @@ var _upload = function (config) { return __awaiter(void 0, void 0, void 0, funct
1226
1271
  });
1227
1272
  }); };
1228
1273
  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) {
1274
+ var configFilePath, res, data, projectId, token, jsonConfig, initConfig, authApi, user, targetInfos, config, reset, _i, targetInfos_1, item;
1275
+ var _a;
1276
+ return __generator(this, function (_b) {
1277
+ switch (_b.label) {
1232
1278
  case 0:
1233
1279
  configFilePath = path.join('.', 'rop.json');
1234
1280
  if (!!fs$1.existsSync(configFilePath)) return [3 /*break*/, 2];
1235
1281
  return [4 /*yield*/, init()];
1236
1282
  case 1:
1237
- _a.sent();
1238
- _a.label = 2;
1283
+ res = _b.sent();
1284
+ if (!res) {
1285
+ return [2 /*return*/];
1286
+ }
1287
+ _b.label = 2;
1239
1288
  case 2:
1240
1289
  data = loadJsonWithEnv({
1241
1290
  platform: platform,
1242
1291
  arch: arch,
1243
1292
  });
1293
+ if (!data) {
1294
+ return [2 /*return*/];
1295
+ }
1244
1296
  if (!!options.accessKey) return [3 /*break*/, 7];
1245
1297
  jsonConfig = loadConfigJSON();
1246
1298
  if (!!jsonConfig.projectId) return [3 /*break*/, 4];
1247
1299
  return [4 /*yield*/, init()];
1248
1300
  case 3:
1249
- projectId = _a.sent();
1301
+ initConfig = _b.sent();
1302
+ if (initConfig) {
1303
+ projectId = initConfig.projectId;
1304
+ }
1305
+ else {
1306
+ return [2 /*return*/];
1307
+ }
1250
1308
  return [3 /*break*/, 5];
1251
1309
  case 4:
1252
1310
  projectId = jsonConfig.projectId;
1253
- _a.label = 5;
1311
+ _b.label = 5;
1254
1312
  case 5:
1255
1313
  authApi = new AuthApi({ baseDomain: defaultHost });
1256
1314
  return [4 /*yield*/, authApi.checkAndRefreshToken()];
1257
1315
  case 6:
1258
- user = _a.sent();
1316
+ user = _b.sent();
1259
1317
  if (!user) {
1260
- console.log('Unauthorized. Please execute the login command');
1318
+ console.log(colors.red("No permission! Please execute [rop login]"));
1261
1319
  return [2 /*return*/];
1262
1320
  }
1263
1321
  token = user.auth.accessToken;
1264
- _a.label = 7;
1322
+ _b.label = 7;
1265
1323
  case 7:
1266
1324
  targetInfos = data.targetInfos, config = data.config, reset = __rest(data, ["targetInfos", "config"]);
1267
1325
  _i = 0, targetInfos_1 = targetInfos;
1268
- _a.label = 8;
1326
+ _b.label = 8;
1269
1327
  case 8:
1270
1328
  if (!(_i < targetInfos_1.length)) return [3 /*break*/, 11];
1271
1329
  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 }))];
1330
+ return [4 /*yield*/, _upload(__assign(__assign({ accessKey: options.accessKey, projectId: projectId, token: token }, reset), { artifact: item.artifacts, host: config.host, platform: platform, branch: options.branch, autoRelease: (_a = options.release) !== null && _a !== void 0 ? _a : false }))];
1273
1331
  case 9:
1274
- _a.sent();
1275
- _a.label = 10;
1332
+ _b.sent();
1333
+ _b.label = 10;
1276
1334
  case 10:
1277
1335
  _i++;
1278
1336
  return [3 /*break*/, 8];
@@ -1308,6 +1366,8 @@ program
1308
1366
  .argument('<string>', 'platform')
1309
1367
  .argument('[string]', 'arch')
1310
1368
  .option('-a, --accessKey <string>', 'accessKey path')
1369
+ .option('-r, --release [boolean]', 'auto release')
1370
+ .option('-b, --branch <string>', 'branch')
1311
1371
  .action(upload);
1312
1372
  // 解析命令行参数
1313
1373
  program.parse();