@sevenvip666/rop 0.1.6 → 0.1.8

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 os__default from 'node:os';
18
19
 
19
20
  /******************************************************************************
20
21
  Copyright (c) Microsoft Corporation.
@@ -1059,7 +1060,7 @@ var AuthApi = /** @class */ (function () {
1059
1060
  }());
1060
1061
 
1061
1062
  var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1062
- var host, authApi, user, needLink, projectId, framework, accessKey, projectName_1, project, projectName, body_1, project, init;
1063
+ var host, authApi, user, chooseTeam, teamSign, loginRes, homedir, teamSignFile, needLink, projectId, framework, accessKey, projectName_1, currentFolderName, project, projectName, currentFolderName, body_1, project, init;
1063
1064
  return __generator(this, function (_a) {
1064
1065
  switch (_a.label) {
1065
1066
  case 0:
@@ -1073,30 +1074,76 @@ var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1073
1074
  process.exit(1);
1074
1075
  }
1075
1076
  return [4 /*yield*/, confirm({
1076
- message: "Link to existing project?",
1077
+ message: "Do you want to choose a team?",
1077
1078
  })];
1078
1079
  case 2:
1079
- needLink = _a.sent();
1080
- accessKey = undefined;
1081
- if (!needLink) return [3 /*break*/, 7];
1082
- _a.label = 3;
1080
+ chooseTeam = _a.sent();
1081
+ if (!chooseTeam) return [3 /*break*/, 5];
1082
+ return [4 /*yield*/, authApi.request(function (token) { return __awaiter(void 0, void 0, void 0, function () {
1083
+ return __generator(this, function (_a) {
1084
+ return [2 /*return*/, fetch("".concat(host, "/api/user"), {
1085
+ method: 'GET',
1086
+ headers: {
1087
+ Authorization: "Bearer ".concat(token),
1088
+ },
1089
+ })];
1090
+ });
1091
+ }); })];
1083
1092
  case 3:
1084
- if (!!projectName_1) return [3 /*break*/, 5];
1085
- return [4 /*yield*/, input({ message: "What\u2019s the name of your existing project?" })];
1093
+ loginRes = _a.sent();
1094
+ if (!loginRes) {
1095
+ console.log(colors.red("No permission! Please execute [rop login]"));
1096
+ process.exit(1);
1097
+ }
1098
+ if ((loginRes === null || loginRes === void 0 ? void 0 : loginRes.teams.length) <= 0) {
1099
+ console.log(colors.yellow("You are not currently in a team, Unable to choose"));
1100
+ process.exit(1);
1101
+ }
1102
+ return [4 /*yield*/, select({
1103
+ message: "Please Select ".concat(colors.cyan('team')),
1104
+ choices: loginRes === null || loginRes === void 0 ? void 0 : loginRes.teams.map(function (item) { return ({ name: item.name, value: item.sign }); }),
1105
+ })];
1086
1106
  case 4:
1107
+ teamSign = _a.sent();
1108
+ homedir = path.join(os__default.homedir(), '.rop');
1109
+ teamSignFile = path.join(homedir, 'team_sign');
1110
+ fs.writeFileSync(teamSignFile, teamSign, 'utf8');
1111
+ _a.label = 5;
1112
+ case 5: return [4 /*yield*/, confirm({
1113
+ message: "Link to existing project?",
1114
+ })];
1115
+ case 6:
1116
+ needLink = _a.sent();
1117
+ accessKey = undefined;
1118
+ if (!needLink) return [3 /*break*/, 11];
1119
+ currentFolderName = getCurrentFolderName();
1120
+ _a.label = 7;
1121
+ case 7:
1122
+ if (!!projectName_1) return [3 /*break*/, 9];
1123
+ return [4 /*yield*/, input({
1124
+ message: "What\u2019s the name of your existing project?",
1125
+ default: currentFolderName,
1126
+ })];
1127
+ case 8:
1087
1128
  projectName_1 = _a.sent();
1088
- return [3 /*break*/, 3];
1089
- case 5: return [4 /*yield*/, authApi.request(function (token) { return __awaiter(void 0, void 0, void 0, function () {
1129
+ return [3 /*break*/, 7];
1130
+ case 9: return [4 /*yield*/, authApi.request(function (token) { return __awaiter(void 0, void 0, void 0, function () {
1131
+ var headers;
1090
1132
  return __generator(this, function (_a) {
1133
+ headers = {
1134
+ Authorization: "Bearer ".concat(token),
1135
+ };
1136
+ if (teamSign) {
1137
+ // @ts-ignore
1138
+ headers['Team-sign'] = teamSign;
1139
+ }
1091
1140
  return [2 /*return*/, fetch("".concat(host, "/api/project/").concat(projectName_1), {
1092
1141
  method: 'GET',
1093
- headers: {
1094
- Authorization: "Bearer ".concat(token),
1095
- },
1142
+ headers: headers,
1096
1143
  })];
1097
1144
  });
1098
1145
  }); })];
1099
- case 6:
1146
+ case 10:
1100
1147
  project = _a.sent();
1101
1148
  if (!project) {
1102
1149
  console.log(colors.yellow("project not found"));
@@ -1104,17 +1151,18 @@ var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1104
1151
  }
1105
1152
  projectId = project.id;
1106
1153
  framework = project.framework;
1107
- return [3 /*break*/, 13];
1108
- case 7:
1154
+ return [3 /*break*/, 17];
1155
+ case 11:
1109
1156
  projectName = void 0;
1110
- _a.label = 8;
1111
- case 8:
1112
- if (!!projectName) return [3 /*break*/, 10];
1113
- return [4 /*yield*/, input({ message: "What\u2019s your project\u2019s name?" })];
1114
- case 9:
1157
+ currentFolderName = getCurrentFolderName();
1158
+ _a.label = 12;
1159
+ case 12:
1160
+ if (!!projectName) return [3 /*break*/, 14];
1161
+ return [4 /*yield*/, input({ message: "What\u2019s your project\u2019s name?", default: currentFolderName })];
1162
+ case 13:
1115
1163
  projectName = _a.sent();
1116
- return [3 /*break*/, 8];
1117
- case 10: return [4 /*yield*/, select({
1164
+ return [3 /*break*/, 12];
1165
+ case 14: return [4 /*yield*/, select({
1118
1166
  message: "Please Select ".concat(colors.cyan('framework')),
1119
1167
  choices: [
1120
1168
  {
@@ -1135,26 +1183,30 @@ var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1135
1183
  },
1136
1184
  ],
1137
1185
  })];
1138
- case 11:
1186
+ case 15:
1139
1187
  framework = _a.sent();
1140
1188
  body_1 = {
1141
1189
  name: projectName,
1142
1190
  framework: framework,
1143
1191
  };
1144
1192
  return [4 /*yield*/, authApi.request(function (token) { return __awaiter(void 0, void 0, void 0, function () {
1193
+ var headers;
1145
1194
  return __generator(this, function (_a) {
1195
+ headers = {
1196
+ Authorization: "Bearer ".concat(token),
1197
+ };
1198
+ if (teamSign) {
1199
+ // @ts-ignore
1200
+ headers['Team-sign'] = teamSign;
1201
+ }
1146
1202
  return [2 /*return*/, fetch("".concat(host, "/api/project"), {
1147
1203
  method: 'POST',
1148
- headers: {
1149
- Accept: 'application/json',
1150
- 'Content-Type': 'application/json;charset=utf-8',
1151
- Authorization: "Bearer ".concat(token),
1152
- },
1204
+ headers: __assign({ Accept: 'application/json', 'Content-Type': 'application/json;charset=utf-8' }, headers),
1153
1205
  body: JSON.stringify(body_1),
1154
1206
  })];
1155
1207
  });
1156
1208
  }); })];
1157
- case 12:
1209
+ case 16:
1158
1210
  project = _a.sent();
1159
1211
  if (!project) {
1160
1212
  console.log(colors.red("project create failed"));
@@ -1163,31 +1215,48 @@ var init = function () { return __awaiter(void 0, void 0, void 0, function () {
1163
1215
  projectId = project.id;
1164
1216
  framework = project.framework;
1165
1217
  accessKey = project.accessKeys[0].accessKey;
1166
- _a.label = 13;
1167
- case 13:
1218
+ _a.label = 17;
1219
+ case 17:
1168
1220
  init = new InitApi();
1169
1221
  return [4 /*yield*/, init.initProjectConfigJson(framework)];
1170
- case 14:
1171
- if (!_a.sent()) return [3 /*break*/, 17];
1222
+ case 18:
1223
+ if (!_a.sent()) return [3 /*break*/, 21];
1172
1224
  return [4 /*yield*/, init.initRopConfig(projectId, accessKey)];
1173
- case 15:
1225
+ case 19:
1174
1226
  _a.sent();
1175
1227
  return [4 /*yield*/, init.initGitignore()];
1176
- case 16:
1228
+ case 20:
1177
1229
  _a.sent();
1178
1230
  console.log(colors.green("Initialize project successfully!"));
1179
1231
  if (framework.toLowerCase() === 'tauri') {
1180
1232
  console.log(colors.blue("updater endpoints : ".concat(host, "/api/tauri/").concat(projectId, "/[your branch]/{{target}}/{{arch}}/{{current_version}}")));
1181
1233
  console.log('Please replace [your branch] with your own branch');
1182
1234
  }
1183
- _a.label = 17;
1184
- case 17: return [2 /*return*/, {
1235
+ _a.label = 21;
1236
+ case 21: return [2 /*return*/, {
1185
1237
  projectId: projectId,
1186
1238
  accessKey: accessKey,
1187
1239
  }];
1188
1240
  }
1189
1241
  });
1190
1242
  }); };
1243
+ var getTeamSign = function () { return __awaiter(void 0, void 0, void 0, function () {
1244
+ var homedir, teamSignFilePath;
1245
+ return __generator(this, function (_a) {
1246
+ homedir = path.join(os__default.homedir(), '.rop');
1247
+ teamSignFilePath = path.join(homedir, 'team_sign');
1248
+ if (fs.existsSync(teamSignFilePath)) {
1249
+ return [2 /*return*/, fs.readFileSync(teamSignFilePath, 'utf8')];
1250
+ }
1251
+ else {
1252
+ return [2 /*return*/, undefined];
1253
+ }
1254
+ });
1255
+ }); };
1256
+ function getCurrentFolderName() {
1257
+ var __dirname = path.resolve();
1258
+ return path.basename(__dirname);
1259
+ }
1191
1260
 
1192
1261
  var login = function (options) { return __awaiter(void 0, void 0, void 0, function () {
1193
1262
  var username, password$1, loginReq, auth, result;
@@ -1245,13 +1314,13 @@ var login = function (options) { return __awaiter(void 0, void 0, void 0, functi
1245
1314
  }); };
1246
1315
 
1247
1316
  var upload = function (platform, arch, options) { return __awaiter(void 0, void 0, void 0, function () {
1248
- var host, projectId, token, jsonConfig, initConfig, authApi, user, configFilePath, data, targetInfos, reset, _i, targetInfos_1, item;
1317
+ var host, projectId, token, teamSign, jsonConfig, initConfig, authApi, user, configFilePath, data, targetInfos, reset, _i, targetInfos_1, item;
1249
1318
  var _a;
1250
1319
  return __generator(this, function (_b) {
1251
1320
  switch (_b.label) {
1252
1321
  case 0:
1253
1322
  host = getHost();
1254
- if (!!options.accessKey) return [3 /*break*/, 5];
1323
+ if (!!options.accessKey) return [3 /*break*/, 6];
1255
1324
  jsonConfig = loadConfigJSON();
1256
1325
  if (!!jsonConfig.projectId) return [3 /*break*/, 2];
1257
1326
  return [4 /*yield*/, init()];
@@ -1277,8 +1346,11 @@ var upload = function (platform, arch, options) { return __awaiter(void 0, void
1277
1346
  process.exit(1);
1278
1347
  }
1279
1348
  token = user.auth.accessToken;
1280
- _b.label = 5;
1349
+ return [4 /*yield*/, getTeamSign()];
1281
1350
  case 5:
1351
+ teamSign = _b.sent();
1352
+ _b.label = 6;
1353
+ case 6:
1282
1354
  configFilePath = path.join('.', 'rop.json');
1283
1355
  if (!fs$1.existsSync(configFilePath)) {
1284
1356
  console.log(colors.red('rop.json not found'));
@@ -1293,28 +1365,28 @@ var upload = function (platform, arch, options) { return __awaiter(void 0, void
1293
1365
  }
1294
1366
  targetInfos = data.targetInfos, data.config, reset = __rest(data, ["targetInfos", "config"]);
1295
1367
  _i = 0, targetInfos_1 = targetInfos;
1296
- _b.label = 6;
1297
- case 6:
1298
- if (!(_i < targetInfos_1.length)) return [3 /*break*/, 9];
1299
- item = targetInfos_1[_i];
1300
- return [4 /*yield*/, _upload(__assign(__assign({ accessKey: options.accessKey, projectId: projectId, token: token }, reset), { artifact: item.artifacts, host: host, platform: platform, branch: options.branch, autoRelease: (_a = options.release) !== null && _a !== void 0 ? _a : false }))];
1368
+ _b.label = 7;
1301
1369
  case 7:
1302
- _b.sent();
1303
- _b.label = 8;
1370
+ if (!(_i < targetInfos_1.length)) return [3 /*break*/, 10];
1371
+ item = targetInfos_1[_i];
1372
+ return [4 /*yield*/, _upload(__assign(__assign({ accessKey: options.accessKey, projectId: projectId, token: token, teamSign: teamSign }, reset), { artifact: item.artifacts, host: host, platform: platform, branch: options.branch, autoRelease: (_a = options.release) !== null && _a !== void 0 ? _a : false }))];
1304
1373
  case 8:
1374
+ _b.sent();
1375
+ _b.label = 9;
1376
+ case 9:
1305
1377
  _i++;
1306
- return [3 /*break*/, 6];
1307
- case 9: return [2 /*return*/];
1378
+ return [3 /*break*/, 7];
1379
+ case 10: return [2 /*return*/];
1308
1380
  }
1309
1381
  });
1310
1382
  }); };
1311
1383
  var _upload = function (config) { return __awaiter(void 0, void 0, void 0, function () {
1312
- var accessKey, projectId, token, artifact, arch, version, platform, autoRelease, signature, uploadClient;
1384
+ var accessKey, projectId, token, teamSign, artifact, arch, version, platform, autoRelease, signature, uploadClient;
1313
1385
  var _a, _b, _c, _d, _e;
1314
1386
  return __generator(this, function (_f) {
1315
1387
  switch (_f.label) {
1316
1388
  case 0:
1317
- 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;
1389
+ accessKey = config.accessKey, projectId = config.projectId, token = config.token, teamSign = config.teamSign, artifact = config.artifact, arch = config.arch, version = config.version, platform = config.platform, config.host, autoRelease = config.autoRelease;
1318
1390
  if ((_a = artifact.sig) === null || _a === void 0 ? void 0 : _a.path) {
1319
1391
  if (fs$1.existsSync(artifact.sig.path)) {
1320
1392
  signature = fs$1.readFileSync(artifact.sig.path, 'utf8');
@@ -1328,6 +1400,7 @@ var _upload = function (config) { return __awaiter(void 0, void 0, void 0, funct
1328
1400
  accessKey: accessKey,
1329
1401
  projectId: projectId,
1330
1402
  token: token,
1403
+ teamSign: teamSign,
1331
1404
  arch: arch,
1332
1405
  platform: platform,
1333
1406
  version: version,
@@ -21,6 +21,7 @@ export interface UploadDto {
21
21
  platform: Platform;
22
22
  accessKey?: string;
23
23
  token?: string;
24
+ teamSign?: string;
24
25
  projectId?: string;
25
26
  branch?: string;
26
27
  version?: string;
@@ -68,6 +69,7 @@ export type LoginReq = {
68
69
  };
69
70
  export type LoginRes = {
70
71
  auth: RefreshTokenType;
72
+ user: UserInfoType;
71
73
  };
72
74
  export type RefreshTokenType = {
73
75
  accessToken: string;
@@ -92,4 +94,17 @@ export type AccessKeyType = {
92
94
  enabled: boolean;
93
95
  projectId: string;
94
96
  };
97
+ export type UserInfoType = {
98
+ username: string;
99
+ accountId: string;
100
+ teams: TeamType[];
101
+ };
102
+ export type TeamType = {
103
+ key: string;
104
+ name: string;
105
+ description: string;
106
+ role: string;
107
+ accountId: string;
108
+ sign: string;
109
+ };
95
110
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sevenvip666/rop",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "files": [
5
5
  "dist"
6
6
  ],