@catladder/cli 0.0.0-main-e792d83e → 0.0.0-main-d6307da3

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.
@@ -402,6 +402,74 @@ exports.parseChoice = parseChoice;
402
402
 
403
403
  /***/ }),
404
404
 
405
+ /***/ 2745:
406
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
407
+
408
+ "use strict";
409
+
410
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
411
+ exports.gitConfigSet = exports.gitConfigGet = void 0;
412
+ const child_process_promise_1 = __nccwpck_require__(5763);
413
+ const argsJoin = (args) => args.filter(Boolean).join(" ");
414
+ async function gitConfigGet(key, { location } = {}) {
415
+ const { stdout } = await (0, child_process_promise_1.exec)(`git config get ${argsJoin([location ? `--${location}` : undefined])} ${key}`);
416
+ return stdout.trim();
417
+ }
418
+ exports.gitConfigGet = gitConfigGet;
419
+ const gitConfigSet = (key, value, { location, comment } = {}) => (0, child_process_promise_1.exec)(`git config set ${argsJoin([
420
+ location ? `--${location}` : undefined,
421
+ comment ? `--comment=${comment}` : undefined,
422
+ ])} ${key} ${value}`);
423
+ exports.gitConfigSet = gitConfigSet;
424
+ //# sourceMappingURL=gitConfig.js.map
425
+
426
+ /***/ }),
427
+
428
+ /***/ 8329:
429
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
430
+
431
+ "use strict";
432
+
433
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
434
+ exports.gitProjectInformation = exports.getGitRemoteHostAndPath = exports.getProjectRootPath = void 0;
435
+ const gitConfig_1 = __nccwpck_require__(2745);
436
+ const child_process_promise_1 = __nccwpck_require__(5763);
437
+ /**
438
+ * Find the absolute path of the current git project root.
439
+ */
440
+ const getProjectRootPath = async () => {
441
+ const { stdout } = await (0, child_process_promise_1.exec)(`git rev-parse --show-toplevel`);
442
+ return stdout.trim();
443
+ };
444
+ exports.getProjectRootPath = getProjectRootPath;
445
+ /**
446
+ * Get the git remote hostname and project path from the git config.
447
+ */
448
+ const getGitRemoteHostAndPath = async () => {
449
+ var _a;
450
+ const remoteUrl = await (0, gitConfig_1.gitConfigGet)("remote.origin.url");
451
+ const remoteReg = /(https:\/\/|git@)([^:/]+)[:/]([^.]*)(\.git)?/;
452
+ const match = (_a = remoteUrl.match(remoteReg)) !== null && _a !== void 0 ? _a : [];
453
+ const [, , gitRemoteHost, gitRemotePath] = match;
454
+ if (!(gitRemoteHost === null || gitRemoteHost === void 0 ? void 0 : gitRemoteHost.length) || !(gitRemotePath === null || gitRemotePath === void 0 ? void 0 : gitRemotePath.length)) {
455
+ throw new Error(`Failed to parse git remote hostname and path from git configs remote.origin.url! ${remoteUrl}`);
456
+ }
457
+ return { gitRemoteHost, gitRemotePath };
458
+ };
459
+ exports.getGitRemoteHostAndPath = getGitRemoteHostAndPath;
460
+ const gitProjectInformation = async () => {
461
+ const [{ gitRemoteHost, gitRemotePath }, projectRootPath] = await Promise.all([(0, exports.getGitRemoteHostAndPath)(), (0, exports.getProjectRootPath)()]);
462
+ return {
463
+ gitRemoteHost,
464
+ gitRemotePath,
465
+ projectRootPath,
466
+ };
467
+ };
468
+ exports.gitProjectInformation = gitProjectInformation;
469
+ //# sourceMappingURL=gitProjectInformation.js.map
470
+
471
+ /***/ }),
472
+
405
473
  /***/ 9863:
406
474
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
407
475
 
@@ -436,12 +504,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
436
504
  Object.defineProperty(exports, "__esModule", ({ value: true }));
437
505
  exports.upsertAllVariables = exports.clearBackups = exports.getVariableValueByRawName = exports.getAllVariables = exports.getProjectInfo = exports.doGitlabRequest = exports.getGitlabToken = exports.setupGitlabToken = exports.hasGitlabToken = void 0;
438
506
  const pipeline_1 = __nccwpck_require__(603);
439
- const child_process_promise_1 = __nccwpck_require__(5763);
440
507
  const lodash_1 = __nccwpck_require__(3255);
441
508
  const memoizee_1 = __importDefault(__nccwpck_require__(5839));
442
509
  const node_fetch_1 = __importDefault(__nccwpck_require__(6372));
443
510
  const open_1 = __importDefault(__nccwpck_require__(4247));
444
- const preferences_1 = __nccwpck_require__(2636);
511
+ const preferences_1 = __nccwpck_require__(3511);
512
+ const gitProjectInformation_1 = __nccwpck_require__(8329);
445
513
  const TOKEN_KEY = "gitlab-personal-access-token";
446
514
  const hasGitlabToken = async () => await (0, preferences_1.hasPreference)(TOKEN_KEY);
447
515
  exports.hasGitlabToken = hasGitlabToken;
@@ -452,13 +520,16 @@ const setupGitlabToken = async (vorpal) => {
452
520
  vorpal.log("");
453
521
  vorpal.log("☝ we open up the settings page for you!");
454
522
  vorpal.log("");
455
- const { shouldContinue } = await vorpal.prompt({
456
- default: true,
457
- message: "Ok",
458
- name: "shouldContinue",
459
- type: "prompt",
460
- });
461
- (0, open_1.default)("https://git.panter.ch/-/profile/personal_access_tokens");
523
+ const [{ shouldContinue }, { gitRemoteHost }] = await Promise.all([
524
+ vorpal.prompt({
525
+ default: true,
526
+ message: "Ok",
527
+ name: "shouldContinue",
528
+ type: "prompt",
529
+ }),
530
+ (0, gitProjectInformation_1.getGitRemoteHostAndPath)(),
531
+ ]);
532
+ (0, open_1.default)(`https://${gitRemoteHost}/-/profile/personal_access_tokens`);
462
533
  vorpal.log("Please type in gitlab's personal access token");
463
534
  const { personalToken } = await vorpal.prompt({
464
535
  type: "string",
@@ -483,9 +554,12 @@ const getGitlabToken = async (vorpal) => {
483
554
  };
484
555
  exports.getGitlabToken = getGitlabToken;
485
556
  const doGitlabRequest = async (vorpal, path, data = undefined, method = "GET") => {
486
- const rootToken = await (0, exports.getGitlabToken)(vorpal);
557
+ const [rootToken, { gitRemoteHost }] = await Promise.all([
558
+ (0, exports.getGitlabToken)(vorpal),
559
+ (0, gitProjectInformation_1.getGitRemoteHostAndPath)(),
560
+ ]);
487
561
  //const method = data ? (update ? "PUT" : "POST") : "GET";
488
- const result = await (0, node_fetch_1.default)(`https://git.panter.ch/api/v4/${path}`, {
562
+ const result = await (0, node_fetch_1.default)(`https://${gitRemoteHost}/api/v4/${path}`, {
489
563
  method,
490
564
  headers: {
491
565
  "Content-Type": "application/json",
@@ -506,9 +580,8 @@ const doGitlabRequest = async (vorpal, path, data = undefined, method = "GET") =
506
580
  };
507
581
  exports.doGitlabRequest = doGitlabRequest;
508
582
  const getProjectInfo = async (vorpal) => {
509
- const gitRemoteOriginUrl = (await (0, child_process_promise_1.exec)("git config --get remote.origin.url")).stdout.trim();
510
- const projectPath = /(https:\/\/|git@)git\.panter\.ch[:/]([^.]*)(\.git)?/g.exec(gitRemoteOriginUrl);
511
- const project = await (0, exports.doGitlabRequest)(vorpal, `projects/${encodeURIComponent(projectPath[2])}`);
583
+ const { gitRemotePath } = await (0, gitProjectInformation_1.getGitRemoteHostAndPath)();
584
+ const project = await (0, exports.doGitlabRequest)(vorpal, `projects/${encodeURIComponent(gitRemotePath)}`);
512
585
  return project;
513
586
  };
514
587
  exports.getProjectInfo = getProjectInfo;
@@ -638,24 +711,42 @@ exports.upsertAllVariables = upsertAllVariables;
638
711
 
639
712
  /***/ }),
640
713
 
641
- /***/ 2636:
714
+ /***/ 3511:
642
715
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
643
716
 
644
717
  "use strict";
645
718
 
646
719
  Object.defineProperty(exports, "__esModule", ({ value: true }));
647
720
  exports.setPreference = exports.getPreference = exports.hasPreference = void 0;
648
- const fs_extra_1 = __nccwpck_require__(7564);
721
+ const promises_1 = __nccwpck_require__(3292);
722
+ const fs_1 = __nccwpck_require__(7147);
723
+ const path_1 = __nccwpck_require__(1017);
649
724
  const os_1 = __nccwpck_require__(2037);
650
725
  const yaml_1 = __nccwpck_require__(8033);
651
- const directory = `${(0, os_1.homedir)()}/.catladder`;
652
- const file = `${directory}/preferences.yml`;
726
+ const legacyPreferencesPath = (0, path_1.join)((0, os_1.homedir)(), ".catladder/preferences.yml");
727
+ const preferencesPath = (0, path_1.join)((0, os_1.homedir)(), ".config/catladder/preferences.yml");
728
+ const ensurePreferencesFile = async () => {
729
+ if ((0, fs_1.existsSync)(preferencesPath)) {
730
+ return preferencesPath;
731
+ }
732
+ await (0, promises_1.mkdir)((0, path_1.dirname)(preferencesPath), { recursive: true, mode: 0o700 });
733
+ await (0, promises_1.writeFile)(preferencesPath, "---\n{}", {
734
+ encoding: "utf-8",
735
+ mode: 0o600,
736
+ });
737
+ if ((0, fs_1.existsSync)(legacyPreferencesPath)) {
738
+ return legacyPreferencesPath;
739
+ }
740
+ return preferencesPath;
741
+ };
742
+ const loadPreferences = async () => {
743
+ const currentLoadPath = await ensurePreferencesFile();
744
+ return (0, promises_1.readFile)(currentLoadPath, { encoding: "utf-8" });
745
+ };
653
746
  const getPreferences = async () => {
654
747
  var _a;
655
- if (!(await (0, fs_extra_1.pathExists)(file))) {
656
- await (0, fs_extra_1.createFile)(file);
657
- }
658
- return ((_a = (0, yaml_1.parse)(await (0, fs_extra_1.readFile)(file, { encoding: "utf-8" }))) !== null && _a !== void 0 ? _a : {});
748
+ const yamlContent = await loadPreferences();
749
+ return ((_a = (0, yaml_1.parse)(yamlContent)) !== null && _a !== void 0 ? _a : {});
659
750
  };
660
751
  const hasPreference = async (key) => {
661
752
  const preferences = await getPreferences();
@@ -673,10 +764,13 @@ const setPreference = async (key, value) => {
673
764
  ...preferences,
674
765
  [key]: value,
675
766
  };
676
- await (0, fs_extra_1.writeFile)(file, (0, yaml_1.stringify)(newPreferences));
767
+ await (0, promises_1.writeFile)(legacyPreferencesPath, (0, yaml_1.stringify)(newPreferences), {
768
+ encoding: "utf-8",
769
+ mode: 0o600,
770
+ });
677
771
  };
678
772
  exports.setPreference = setPreference;
679
- //# sourceMappingURL=index.js.map
773
+ //# sourceMappingURL=preferences.js.map
680
774
 
681
775
  /***/ }),
682
776
 
@@ -2458,7 +2458,7 @@ exports["default"] = async (vorpal) => {
2458
2458
 
2459
2459
  Object.defineProperty(exports, "__esModule", ({ value: true }));
2460
2460
  exports.getGoogleAuthUserNumber = void 0;
2461
- const preferences_1 = __nccwpck_require__(62636);
2461
+ const preferences_1 = __nccwpck_require__(13511);
2462
2462
  const KEY = "googleAuthUserNumber";
2463
2463
  const getGoogleAuthUserNumber = async function () {
2464
2464
  if (!(await (0, preferences_1.hasPreference)(KEY))) {
@@ -2952,6 +2952,74 @@ const hash = (str, length) => {
2952
2952
 
2953
2953
  /***/ }),
2954
2954
 
2955
+ /***/ 72745:
2956
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
2957
+
2958
+ "use strict";
2959
+
2960
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2961
+ exports.gitConfigSet = exports.gitConfigGet = void 0;
2962
+ const child_process_promise_1 = __nccwpck_require__(75763);
2963
+ const argsJoin = (args) => args.filter(Boolean).join(" ");
2964
+ async function gitConfigGet(key, { location } = {}) {
2965
+ const { stdout } = await (0, child_process_promise_1.exec)(`git config get ${argsJoin([location ? `--${location}` : undefined])} ${key}`);
2966
+ return stdout.trim();
2967
+ }
2968
+ exports.gitConfigGet = gitConfigGet;
2969
+ const gitConfigSet = (key, value, { location, comment } = {}) => (0, child_process_promise_1.exec)(`git config set ${argsJoin([
2970
+ location ? `--${location}` : undefined,
2971
+ comment ? `--comment=${comment}` : undefined,
2972
+ ])} ${key} ${value}`);
2973
+ exports.gitConfigSet = gitConfigSet;
2974
+ //# sourceMappingURL=gitConfig.js.map
2975
+
2976
+ /***/ }),
2977
+
2978
+ /***/ 78329:
2979
+ /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
2980
+
2981
+ "use strict";
2982
+
2983
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
2984
+ exports.gitProjectInformation = exports.getGitRemoteHostAndPath = exports.getProjectRootPath = void 0;
2985
+ const gitConfig_1 = __nccwpck_require__(72745);
2986
+ const child_process_promise_1 = __nccwpck_require__(75763);
2987
+ /**
2988
+ * Find the absolute path of the current git project root.
2989
+ */
2990
+ const getProjectRootPath = async () => {
2991
+ const { stdout } = await (0, child_process_promise_1.exec)(`git rev-parse --show-toplevel`);
2992
+ return stdout.trim();
2993
+ };
2994
+ exports.getProjectRootPath = getProjectRootPath;
2995
+ /**
2996
+ * Get the git remote hostname and project path from the git config.
2997
+ */
2998
+ const getGitRemoteHostAndPath = async () => {
2999
+ var _a;
3000
+ const remoteUrl = await (0, gitConfig_1.gitConfigGet)("remote.origin.url");
3001
+ const remoteReg = /(https:\/\/|git@)([^:/]+)[:/]([^.]*)(\.git)?/;
3002
+ const match = (_a = remoteUrl.match(remoteReg)) !== null && _a !== void 0 ? _a : [];
3003
+ const [, , gitRemoteHost, gitRemotePath] = match;
3004
+ if (!(gitRemoteHost === null || gitRemoteHost === void 0 ? void 0 : gitRemoteHost.length) || !(gitRemotePath === null || gitRemotePath === void 0 ? void 0 : gitRemotePath.length)) {
3005
+ throw new Error(`Failed to parse git remote hostname and path from git configs remote.origin.url! ${remoteUrl}`);
3006
+ }
3007
+ return { gitRemoteHost, gitRemotePath };
3008
+ };
3009
+ exports.getGitRemoteHostAndPath = getGitRemoteHostAndPath;
3010
+ const gitProjectInformation = async () => {
3011
+ const [{ gitRemoteHost, gitRemotePath }, projectRootPath] = await Promise.all([(0, exports.getGitRemoteHostAndPath)(), (0, exports.getProjectRootPath)()]);
3012
+ return {
3013
+ gitRemoteHost,
3014
+ gitRemotePath,
3015
+ projectRootPath,
3016
+ };
3017
+ };
3018
+ exports.gitProjectInformation = gitProjectInformation;
3019
+ //# sourceMappingURL=gitProjectInformation.js.map
3020
+
3021
+ /***/ }),
3022
+
2955
3023
  /***/ 79672:
2956
3024
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
2957
3025
 
@@ -3247,12 +3315,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3247
3315
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3248
3316
  exports.upsertAllVariables = exports.clearBackups = exports.getVariableValueByRawName = exports.getAllVariables = exports.getProjectInfo = exports.doGitlabRequest = exports.getGitlabToken = exports.setupGitlabToken = exports.hasGitlabToken = void 0;
3249
3317
  const pipeline_1 = __nccwpck_require__(10603);
3250
- const child_process_promise_1 = __nccwpck_require__(75763);
3251
3318
  const lodash_1 = __nccwpck_require__(23255);
3252
3319
  const memoizee_1 = __importDefault(__nccwpck_require__(85839));
3253
3320
  const node_fetch_1 = __importDefault(__nccwpck_require__(26372));
3254
3321
  const open_1 = __importDefault(__nccwpck_require__(14247));
3255
- const preferences_1 = __nccwpck_require__(62636);
3322
+ const preferences_1 = __nccwpck_require__(13511);
3323
+ const gitProjectInformation_1 = __nccwpck_require__(78329);
3256
3324
  const TOKEN_KEY = "gitlab-personal-access-token";
3257
3325
  const hasGitlabToken = async () => await (0, preferences_1.hasPreference)(TOKEN_KEY);
3258
3326
  exports.hasGitlabToken = hasGitlabToken;
@@ -3263,13 +3331,16 @@ const setupGitlabToken = async (vorpal) => {
3263
3331
  vorpal.log("");
3264
3332
  vorpal.log("☝ we open up the settings page for you!");
3265
3333
  vorpal.log("");
3266
- const { shouldContinue } = await vorpal.prompt({
3267
- default: true,
3268
- message: "Ok",
3269
- name: "shouldContinue",
3270
- type: "prompt",
3271
- });
3272
- (0, open_1.default)("https://git.panter.ch/-/profile/personal_access_tokens");
3334
+ const [{ shouldContinue }, { gitRemoteHost }] = await Promise.all([
3335
+ vorpal.prompt({
3336
+ default: true,
3337
+ message: "Ok",
3338
+ name: "shouldContinue",
3339
+ type: "prompt",
3340
+ }),
3341
+ (0, gitProjectInformation_1.getGitRemoteHostAndPath)(),
3342
+ ]);
3343
+ (0, open_1.default)(`https://${gitRemoteHost}/-/profile/personal_access_tokens`);
3273
3344
  vorpal.log("Please type in gitlab's personal access token");
3274
3345
  const { personalToken } = await vorpal.prompt({
3275
3346
  type: "string",
@@ -3294,9 +3365,12 @@ const getGitlabToken = async (vorpal) => {
3294
3365
  };
3295
3366
  exports.getGitlabToken = getGitlabToken;
3296
3367
  const doGitlabRequest = async (vorpal, path, data = undefined, method = "GET") => {
3297
- const rootToken = await (0, exports.getGitlabToken)(vorpal);
3368
+ const [rootToken, { gitRemoteHost }] = await Promise.all([
3369
+ (0, exports.getGitlabToken)(vorpal),
3370
+ (0, gitProjectInformation_1.getGitRemoteHostAndPath)(),
3371
+ ]);
3298
3372
  //const method = data ? (update ? "PUT" : "POST") : "GET";
3299
- const result = await (0, node_fetch_1.default)(`https://git.panter.ch/api/v4/${path}`, {
3373
+ const result = await (0, node_fetch_1.default)(`https://${gitRemoteHost}/api/v4/${path}`, {
3300
3374
  method,
3301
3375
  headers: {
3302
3376
  "Content-Type": "application/json",
@@ -3317,9 +3391,8 @@ const doGitlabRequest = async (vorpal, path, data = undefined, method = "GET") =
3317
3391
  };
3318
3392
  exports.doGitlabRequest = doGitlabRequest;
3319
3393
  const getProjectInfo = async (vorpal) => {
3320
- const gitRemoteOriginUrl = (await (0, child_process_promise_1.exec)("git config --get remote.origin.url")).stdout.trim();
3321
- const projectPath = /(https:\/\/|git@)git\.panter\.ch[:/]([^.]*)(\.git)?/g.exec(gitRemoteOriginUrl);
3322
- const project = await (0, exports.doGitlabRequest)(vorpal, `projects/${encodeURIComponent(projectPath[2])}`);
3394
+ const { gitRemotePath } = await (0, gitProjectInformation_1.getGitRemoteHostAndPath)();
3395
+ const project = await (0, exports.doGitlabRequest)(vorpal, `projects/${encodeURIComponent(gitRemotePath)}`);
3323
3396
  return project;
3324
3397
  };
3325
3398
  exports.getProjectInfo = getProjectInfo;
@@ -3525,24 +3598,42 @@ exports.stopAllPortForwards = stopAllPortForwards;
3525
3598
 
3526
3599
  /***/ }),
3527
3600
 
3528
- /***/ 62636:
3601
+ /***/ 13511:
3529
3602
  /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
3530
3603
 
3531
3604
  "use strict";
3532
3605
 
3533
3606
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3534
3607
  exports.setPreference = exports.getPreference = exports.hasPreference = void 0;
3535
- const fs_extra_1 = __nccwpck_require__(85501);
3608
+ const promises_1 = __nccwpck_require__(73292);
3609
+ const fs_1 = __nccwpck_require__(57147);
3610
+ const path_1 = __nccwpck_require__(71017);
3536
3611
  const os_1 = __nccwpck_require__(22037);
3537
3612
  const yaml_1 = __nccwpck_require__(68033);
3538
- const directory = `${(0, os_1.homedir)()}/.catladder`;
3539
- const file = `${directory}/preferences.yml`;
3613
+ const legacyPreferencesPath = (0, path_1.join)((0, os_1.homedir)(), ".catladder/preferences.yml");
3614
+ const preferencesPath = (0, path_1.join)((0, os_1.homedir)(), ".config/catladder/preferences.yml");
3615
+ const ensurePreferencesFile = async () => {
3616
+ if ((0, fs_1.existsSync)(preferencesPath)) {
3617
+ return preferencesPath;
3618
+ }
3619
+ await (0, promises_1.mkdir)((0, path_1.dirname)(preferencesPath), { recursive: true, mode: 0o700 });
3620
+ await (0, promises_1.writeFile)(preferencesPath, "---\n{}", {
3621
+ encoding: "utf-8",
3622
+ mode: 0o600,
3623
+ });
3624
+ if ((0, fs_1.existsSync)(legacyPreferencesPath)) {
3625
+ return legacyPreferencesPath;
3626
+ }
3627
+ return preferencesPath;
3628
+ };
3629
+ const loadPreferences = async () => {
3630
+ const currentLoadPath = await ensurePreferencesFile();
3631
+ return (0, promises_1.readFile)(currentLoadPath, { encoding: "utf-8" });
3632
+ };
3540
3633
  const getPreferences = async () => {
3541
3634
  var _a;
3542
- if (!(await (0, fs_extra_1.pathExists)(file))) {
3543
- await (0, fs_extra_1.createFile)(file);
3544
- }
3545
- return ((_a = (0, yaml_1.parse)(await (0, fs_extra_1.readFile)(file, { encoding: "utf-8" }))) !== null && _a !== void 0 ? _a : {});
3635
+ const yamlContent = await loadPreferences();
3636
+ return ((_a = (0, yaml_1.parse)(yamlContent)) !== null && _a !== void 0 ? _a : {});
3546
3637
  };
3547
3638
  const hasPreference = async (key) => {
3548
3639
  const preferences = await getPreferences();
@@ -3560,10 +3651,13 @@ const setPreference = async (key, value) => {
3560
3651
  ...preferences,
3561
3652
  [key]: value,
3562
3653
  };
3563
- await (0, fs_extra_1.writeFile)(file, (0, yaml_1.stringify)(newPreferences));
3654
+ await (0, promises_1.writeFile)(legacyPreferencesPath, (0, yaml_1.stringify)(newPreferences), {
3655
+ encoding: "utf-8",
3656
+ mode: 0o600,
3657
+ });
3564
3658
  };
3565
3659
  exports.setPreference = setPreference;
3566
- //# sourceMappingURL=index.js.map
3660
+ //# sourceMappingURL=preferences.js.map
3567
3661
 
3568
3662
  /***/ }),
3569
3663
 
@@ -0,0 +1,9 @@
1
+ export type GitLocationScope = "global" | "local" | "system" | "worktree";
2
+ export type GitConfigOptions = {
3
+ location?: GitLocationScope;
4
+ comment?: string;
5
+ };
6
+ export declare function gitConfigGet(key: string, { location }?: Pick<GitConfigOptions, "location">): Promise<string>;
7
+ export declare const gitConfigSet: (key: string, value: string, { location, comment }?: GitConfigOptions) => Promise<{
8
+ stdout: string;
9
+ }>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gitConfigSet = exports.gitConfigGet = void 0;
4
+ const child_process_promise_1 = require("child-process-promise");
5
+ const argsJoin = (args) => args.filter(Boolean).join(" ");
6
+ async function gitConfigGet(key, { location } = {}) {
7
+ const { stdout } = await (0, child_process_promise_1.exec)(`git config get ${argsJoin([location ? `--${location}` : undefined])} ${key}`);
8
+ return stdout.trim();
9
+ }
10
+ exports.gitConfigGet = gitConfigGet;
11
+ const gitConfigSet = (key, value, { location, comment } = {}) => (0, child_process_promise_1.exec)(`git config set ${argsJoin([
12
+ location ? `--${location}` : undefined,
13
+ comment ? `--comment=${comment}` : undefined,
14
+ ])} ${key} ${value}`);
15
+ exports.gitConfigSet = gitConfigSet;
16
+ //# sourceMappingURL=gitConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitConfig.js","sourceRoot":"","sources":["../../../../src/git/gitConfig.ts"],"names":[],"mappings":";;;AAAA,iEAA6C;AAQ7C,MAAM,QAAQ,GAAG,CAAC,IAA4B,EAAU,EAAE,CACxD,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE1B,KAAK,UAAU,YAAY,CAChC,GAAW,EACX,EAAE,QAAQ,KAAyC,EAAE;IAErD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,4BAAI,EAC3B,kBAAkB,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,GAAG,EAAE,CAC9E,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC;AARD,oCAQC;AAEM,MAAM,YAAY,GAAG,CAC1B,GAAW,EACX,KAAa,EACb,EAAE,QAAQ,EAAE,OAAO,KAAuB,EAAE,EAC5C,EAAE,CACF,IAAA,4BAAI,EACF,kBAAkB,QAAQ,CAAC;IACzB,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC,CAAC,SAAS;IACtC,OAAO,CAAC,CAAC,CAAC,aAAa,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;CAC7C,CAAC,IAAI,GAAG,IAAI,KAAK,EAAE,CACrB,CAAC;AAVS,QAAA,YAAY,gBAUrB"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Find the absolute path of the current git project root.
3
+ */
4
+ export declare const getProjectRootPath: () => Promise<string>;
5
+ /**
6
+ * Get the git remote hostname and project path from the git config.
7
+ */
8
+ export declare const getGitRemoteHostAndPath: () => Promise<{
9
+ gitRemoteHost: string;
10
+ gitRemotePath: string;
11
+ }>;
12
+ export declare const gitProjectInformation: () => Promise<{
13
+ gitRemoteHost: string;
14
+ gitRemotePath: string;
15
+ projectRootPath: string;
16
+ }>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gitProjectInformation = exports.getGitRemoteHostAndPath = exports.getProjectRootPath = void 0;
4
+ const gitConfig_1 = require("./gitConfig");
5
+ const child_process_promise_1 = require("child-process-promise");
6
+ /**
7
+ * Find the absolute path of the current git project root.
8
+ */
9
+ const getProjectRootPath = async () => {
10
+ const { stdout } = await (0, child_process_promise_1.exec)(`git rev-parse --show-toplevel`);
11
+ return stdout.trim();
12
+ };
13
+ exports.getProjectRootPath = getProjectRootPath;
14
+ /**
15
+ * Get the git remote hostname and project path from the git config.
16
+ */
17
+ const getGitRemoteHostAndPath = async () => {
18
+ var _a;
19
+ const remoteUrl = await (0, gitConfig_1.gitConfigGet)("remote.origin.url");
20
+ const remoteReg = /(https:\/\/|git@)([^:/]+)[:/]([^.]*)(\.git)?/;
21
+ const match = (_a = remoteUrl.match(remoteReg)) !== null && _a !== void 0 ? _a : [];
22
+ const [, , gitRemoteHost, gitRemotePath] = match;
23
+ if (!(gitRemoteHost === null || gitRemoteHost === void 0 ? void 0 : gitRemoteHost.length) || !(gitRemotePath === null || gitRemotePath === void 0 ? void 0 : gitRemotePath.length)) {
24
+ throw new Error(`Failed to parse git remote hostname and path from git configs remote.origin.url! ${remoteUrl}`);
25
+ }
26
+ return { gitRemoteHost, gitRemotePath };
27
+ };
28
+ exports.getGitRemoteHostAndPath = getGitRemoteHostAndPath;
29
+ const gitProjectInformation = async () => {
30
+ const [{ gitRemoteHost, gitRemotePath }, projectRootPath] = await Promise.all([(0, exports.getGitRemoteHostAndPath)(), (0, exports.getProjectRootPath)()]);
31
+ return {
32
+ gitRemoteHost,
33
+ gitRemotePath,
34
+ projectRootPath,
35
+ };
36
+ };
37
+ exports.gitProjectInformation = gitProjectInformation;
38
+ //# sourceMappingURL=gitProjectInformation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitProjectInformation.js","sourceRoot":"","sources":["../../../../src/git/gitProjectInformation.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAC3C,iEAA6C;AAE7C;;GAEG;AACI,MAAM,kBAAkB,GAAG,KAAK,IAAqB,EAAE;IAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,4BAAI,EAAC,+BAA+B,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC;AAHW,QAAA,kBAAkB,sBAG7B;AAEF;;GAEG;AACI,MAAM,uBAAuB,GAAG,KAAK,IAGzC,EAAE;;IACH,MAAM,SAAS,GAAG,MAAM,IAAA,wBAAY,EAAC,mBAAmB,CAAC,CAAC;IAC1D,MAAM,SAAS,GAAG,8CAA8C,CAAC;IACjE,MAAM,KAAK,GAAG,MAAA,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,mCAAI,EAAE,CAAC;IAC/C,MAAM,CAAC,EAAE,AAAD,EAAG,aAAa,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC;IACjD,IAAI,CAAC,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,MAAM,CAAA,IAAI,CAAC,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,MAAM,CAAA,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CACb,oFAAoF,SAAS,EAAE,CAChG,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC;AAC1C,CAAC,CAAC;AAdW,QAAA,uBAAuB,2BAclC;AAEK,MAAM,qBAAqB,GAAG,KAAK,IAAI,EAAE;IAC9C,MAAM,CAAC,EAAE,aAAa,EAAE,aAAa,EAAE,EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAC3E,CAAC,IAAA,+BAAuB,GAAE,EAAE,IAAA,0BAAkB,GAAE,CAAC,CAClD,CAAC;IACF,OAAO;QACL,aAAa;QACb,aAAa;QACb,eAAe;KAChB,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,qBAAqB,yBAShC"}
@@ -0,0 +1,2 @@
1
+ export * from "./gitConfig";
2
+ export * from "./gitProjectInformation";
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./gitConfig"), exports);
18
+ __exportStar(require("./gitProjectInformation"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/git/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0DAAwC"}
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.upsertAllVariables = exports.clearBackups = exports.getVariableValueByRawName = exports.getAllVariables = exports.getProjectInfo = exports.doGitlabRequest = exports.getGitlabToken = exports.setupGitlabToken = exports.hasGitlabToken = void 0;
7
7
  const pipeline_1 = require("../../../pipeline/src/index.js");
8
- const child_process_promise_1 = require("child-process-promise");
9
8
  const lodash_1 = require("lodash");
10
9
  const memoizee_1 = __importDefault(require("memoizee"));
11
10
  const node_fetch_1 = __importDefault(require("node-fetch"));
12
11
  const open_1 = __importDefault(require("open"));
13
12
  const preferences_1 = require("./preferences");
13
+ const gitProjectInformation_1 = require("../git/gitProjectInformation");
14
14
  const TOKEN_KEY = "gitlab-personal-access-token";
15
15
  const hasGitlabToken = async () => await (0, preferences_1.hasPreference)(TOKEN_KEY);
16
16
  exports.hasGitlabToken = hasGitlabToken;
@@ -21,13 +21,16 @@ const setupGitlabToken = async (vorpal) => {
21
21
  vorpal.log("");
22
22
  vorpal.log("☝ we open up the settings page for you!");
23
23
  vorpal.log("");
24
- const { shouldContinue } = await vorpal.prompt({
25
- default: true,
26
- message: "Ok",
27
- name: "shouldContinue",
28
- type: "prompt",
29
- });
30
- (0, open_1.default)("https://git.panter.ch/-/profile/personal_access_tokens");
24
+ const [{ shouldContinue }, { gitRemoteHost }] = await Promise.all([
25
+ vorpal.prompt({
26
+ default: true,
27
+ message: "Ok",
28
+ name: "shouldContinue",
29
+ type: "prompt",
30
+ }),
31
+ (0, gitProjectInformation_1.getGitRemoteHostAndPath)(),
32
+ ]);
33
+ (0, open_1.default)(`https://${gitRemoteHost}/-/profile/personal_access_tokens`);
31
34
  vorpal.log("Please type in gitlab's personal access token");
32
35
  const { personalToken } = await vorpal.prompt({
33
36
  type: "string",
@@ -52,9 +55,12 @@ const getGitlabToken = async (vorpal) => {
52
55
  };
53
56
  exports.getGitlabToken = getGitlabToken;
54
57
  const doGitlabRequest = async (vorpal, path, data = undefined, method = "GET") => {
55
- const rootToken = await (0, exports.getGitlabToken)(vorpal);
58
+ const [rootToken, { gitRemoteHost }] = await Promise.all([
59
+ (0, exports.getGitlabToken)(vorpal),
60
+ (0, gitProjectInformation_1.getGitRemoteHostAndPath)(),
61
+ ]);
56
62
  //const method = data ? (update ? "PUT" : "POST") : "GET";
57
- const result = await (0, node_fetch_1.default)(`https://git.panter.ch/api/v4/${path}`, {
63
+ const result = await (0, node_fetch_1.default)(`https://${gitRemoteHost}/api/v4/${path}`, {
58
64
  method,
59
65
  headers: {
60
66
  "Content-Type": "application/json",
@@ -75,9 +81,8 @@ const doGitlabRequest = async (vorpal, path, data = undefined, method = "GET") =
75
81
  };
76
82
  exports.doGitlabRequest = doGitlabRequest;
77
83
  const getProjectInfo = async (vorpal) => {
78
- const gitRemoteOriginUrl = (await (0, child_process_promise_1.exec)("git config --get remote.origin.url")).stdout.trim();
79
- const projectPath = /(https:\/\/|git@)git\.panter\.ch[:/]([^.]*)(\.git)?/g.exec(gitRemoteOriginUrl);
80
- const project = await (0, exports.doGitlabRequest)(vorpal, `projects/${encodeURIComponent(projectPath[2])}`);
84
+ const { gitRemotePath } = await (0, gitProjectInformation_1.getGitRemoteHostAndPath)();
85
+ const project = await (0, exports.doGitlabRequest)(vorpal, `projects/${encodeURIComponent(gitRemotePath)}`);
81
86
  return project;
82
87
  };
83
88
  exports.getProjectInfo = getProjectInfo;