@catladder/cli 0.0.0-refactor-cli-add-improved-git-utilities-224e6ee7 → 0.0.0-refactor-cli-add-improved-git-utilities-583a3a54
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.
- package/dist/bundles/catenv/index.js +23 -13
- package/dist/bundles/cli/index.js +23 -13
- package/dist/cli/src/gitlab/apiClient.js +1 -1
- package/dist/cli/src/gitlab/apiClient.js.map +1 -1
- package/dist/cli/src/gitlab/getGitlabProjectInfo.d.ts +3 -0
- package/dist/cli/src/gitlab/getGitlabProjectInfo.js +25 -0
- package/dist/cli/src/gitlab/getGitlabProjectInfo.js.map +1 -0
- package/dist/cli/src/utils/preferences.js +23 -13
- package/dist/cli/src/utils/preferences.js.map +1 -1
- package/dist/cli/src/utils/projectPreferences.d.ts +6 -0
- package/dist/cli/src/utils/projectPreferences.js +56 -0
- package/dist/cli/src/utils/projectPreferences.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/gitlab/apiClient.ts +1 -1
- package/src/gitlab/getGitlabProjectInfo.ts +25 -0
- package/src/utils/preferences.ts +40 -20
- package/src/utils/projectPreferences.ts +81 -0
|
@@ -650,11 +650,13 @@ exports.upsertAllVariables = upsertAllVariables;
|
|
|
650
650
|
|
|
651
651
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
652
652
|
exports.setPreference = exports.getPreference = exports.hasPreference = exports.getPreferences = void 0;
|
|
653
|
-
const
|
|
653
|
+
const promises_1 = __nccwpck_require__(3292);
|
|
654
|
+
const fs_1 = __nccwpck_require__(7147);
|
|
654
655
|
const os_1 = __nccwpck_require__(2037);
|
|
655
656
|
const yaml_1 = __nccwpck_require__(8033);
|
|
656
|
-
const
|
|
657
|
-
const
|
|
657
|
+
const path_1 = __nccwpck_require__(1017);
|
|
658
|
+
const directory = (0, path_1.join)((0, os_1.homedir)(), ".catladder");
|
|
659
|
+
const file = (0, path_1.join)(directory, "preferences.yml");
|
|
658
660
|
const perfKeys = [
|
|
659
661
|
"gitlab-personal-access-token",
|
|
660
662
|
"googleAuthUserNumber",
|
|
@@ -665,14 +667,26 @@ const fallbackValues = {
|
|
|
665
667
|
gitlabTokens: {},
|
|
666
668
|
googleAuthUserNumber: null,
|
|
667
669
|
};
|
|
670
|
+
const perferencesWithParsed = (parsed) => perfKeys.reduce((acc, key) => { var _a; return Object.assign(acc, { [key]: (_a = parsed[key]) !== null && _a !== void 0 ? _a : fallbackValues[key] }); }, {});
|
|
671
|
+
const encoding = "utf-8";
|
|
672
|
+
const readPreferences = () => (0, promises_1.readFile)(file, { encoding });
|
|
673
|
+
const writePreferences = (preferences) => (0, promises_1.writeFile)(file, (0, yaml_1.stringify)(preferences), { encoding, mode: 0o600 });
|
|
674
|
+
const ensureDir = async () => (0, fs_1.existsSync)(directory)
|
|
675
|
+
? directory
|
|
676
|
+
: (0, promises_1.mkdir)(directory, { recursive: true, mode: 0o700 });
|
|
677
|
+
const ensureFile = async () => {
|
|
678
|
+
if ((0, fs_1.existsSync)(file)) {
|
|
679
|
+
return file;
|
|
680
|
+
}
|
|
681
|
+
await ensureDir();
|
|
682
|
+
return writePreferences(perferencesWithParsed({}));
|
|
683
|
+
};
|
|
668
684
|
const getPreferences = async () => {
|
|
669
685
|
var _a;
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
673
|
-
const fileString = await (0, fs_extra_1.readFile)(file, { encoding: "utf-8" });
|
|
686
|
+
await ensureFile();
|
|
687
|
+
const fileString = await readPreferences();
|
|
674
688
|
const fileParsed = (_a = (0, yaml_1.parse)(fileString || "---\nnull")) !== null && _a !== void 0 ? _a : {};
|
|
675
|
-
return
|
|
689
|
+
return perferencesWithParsed(fileParsed);
|
|
676
690
|
};
|
|
677
691
|
exports.getPreferences = getPreferences;
|
|
678
692
|
const hasPreference = async (key) => {
|
|
@@ -690,11 +704,7 @@ const getPreference = async (key) => {
|
|
|
690
704
|
exports.getPreference = getPreference;
|
|
691
705
|
const setPreference = async (key, value) => {
|
|
692
706
|
const preferences = await (0, exports.getPreferences)();
|
|
693
|
-
|
|
694
|
-
...preferences,
|
|
695
|
-
[key]: value,
|
|
696
|
-
};
|
|
697
|
-
await (0, fs_extra_1.writeFile)(file, (0, yaml_1.stringify)(newPreferences));
|
|
707
|
+
return writePreferences({ ...preferences, [key]: value });
|
|
698
708
|
};
|
|
699
709
|
exports.setPreference = setPreference;
|
|
700
710
|
//# sourceMappingURL=preferences.js.map
|
|
@@ -3643,11 +3643,13 @@ exports.stopAllPortForwards = stopAllPortForwards;
|
|
|
3643
3643
|
|
|
3644
3644
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
3645
3645
|
exports.setPreference = exports.getPreference = exports.hasPreference = exports.getPreferences = void 0;
|
|
3646
|
-
const
|
|
3646
|
+
const promises_1 = __nccwpck_require__(73292);
|
|
3647
|
+
const fs_1 = __nccwpck_require__(57147);
|
|
3647
3648
|
const os_1 = __nccwpck_require__(22037);
|
|
3648
3649
|
const yaml_1 = __nccwpck_require__(68033);
|
|
3649
|
-
const
|
|
3650
|
-
const
|
|
3650
|
+
const path_1 = __nccwpck_require__(71017);
|
|
3651
|
+
const directory = (0, path_1.join)((0, os_1.homedir)(), ".catladder");
|
|
3652
|
+
const file = (0, path_1.join)(directory, "preferences.yml");
|
|
3651
3653
|
const perfKeys = [
|
|
3652
3654
|
"gitlab-personal-access-token",
|
|
3653
3655
|
"googleAuthUserNumber",
|
|
@@ -3658,14 +3660,26 @@ const fallbackValues = {
|
|
|
3658
3660
|
gitlabTokens: {},
|
|
3659
3661
|
googleAuthUserNumber: null,
|
|
3660
3662
|
};
|
|
3663
|
+
const perferencesWithParsed = (parsed) => perfKeys.reduce((acc, key) => { var _a; return Object.assign(acc, { [key]: (_a = parsed[key]) !== null && _a !== void 0 ? _a : fallbackValues[key] }); }, {});
|
|
3664
|
+
const encoding = "utf-8";
|
|
3665
|
+
const readPreferences = () => (0, promises_1.readFile)(file, { encoding });
|
|
3666
|
+
const writePreferences = (preferences) => (0, promises_1.writeFile)(file, (0, yaml_1.stringify)(preferences), { encoding, mode: 0o600 });
|
|
3667
|
+
const ensureDir = async () => (0, fs_1.existsSync)(directory)
|
|
3668
|
+
? directory
|
|
3669
|
+
: (0, promises_1.mkdir)(directory, { recursive: true, mode: 0o700 });
|
|
3670
|
+
const ensureFile = async () => {
|
|
3671
|
+
if ((0, fs_1.existsSync)(file)) {
|
|
3672
|
+
return file;
|
|
3673
|
+
}
|
|
3674
|
+
await ensureDir();
|
|
3675
|
+
return writePreferences(perferencesWithParsed({}));
|
|
3676
|
+
};
|
|
3661
3677
|
const getPreferences = async () => {
|
|
3662
3678
|
var _a;
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
}
|
|
3666
|
-
const fileString = await (0, fs_extra_1.readFile)(file, { encoding: "utf-8" });
|
|
3679
|
+
await ensureFile();
|
|
3680
|
+
const fileString = await readPreferences();
|
|
3667
3681
|
const fileParsed = (_a = (0, yaml_1.parse)(fileString || "---\nnull")) !== null && _a !== void 0 ? _a : {};
|
|
3668
|
-
return
|
|
3682
|
+
return perferencesWithParsed(fileParsed);
|
|
3669
3683
|
};
|
|
3670
3684
|
exports.getPreferences = getPreferences;
|
|
3671
3685
|
const hasPreference = async (key) => {
|
|
@@ -3683,11 +3697,7 @@ const getPreference = async (key) => {
|
|
|
3683
3697
|
exports.getPreference = getPreference;
|
|
3684
3698
|
const setPreference = async (key, value) => {
|
|
3685
3699
|
const preferences = await (0, exports.getPreferences)();
|
|
3686
|
-
|
|
3687
|
-
...preferences,
|
|
3688
|
-
[key]: value,
|
|
3689
|
-
};
|
|
3690
|
-
await (0, fs_extra_1.writeFile)(file, (0, yaml_1.stringify)(newPreferences));
|
|
3700
|
+
return writePreferences({ ...preferences, [key]: value });
|
|
3691
3701
|
};
|
|
3692
3702
|
exports.setPreference = setPreference;
|
|
3693
3703
|
//# sourceMappingURL=preferences.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apiClient.js","sourceRoot":"","sources":["../../../../src/gitlab/apiClient.ts"],"names":[],"mappings":";;;AAAA,0CAAyC;AACzC,+CAA+C;AAExC,MAAM,eAAe,GAAG,KAAK,EAAE,EACpC,UAAU,MAGR,EAAE,EAAE,EAAE;IACR,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,MAAM,IAAA,4BAAc,EAAC,UAAU,CAAC,CAAC;IAClE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,IAAI,aAAM,CAAC;QAChB,KAAK;QACL,IAAI,EAAE,aAAa;
|
|
1
|
+
{"version":3,"file":"apiClient.js","sourceRoot":"","sources":["../../../../src/gitlab/apiClient.ts"],"names":[],"mappings":";;;AAAA,0CAAyC;AACzC,+CAA+C;AAExC,MAAM,eAAe,GAAG,KAAK,EAAE,EACpC,UAAU,MAGR,EAAE,EAAE,EAAE;IACR,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,MAAM,IAAA,4BAAc,EAAC,UAAU,CAAC,CAAC;IAClE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,IAAI,aAAM,CAAC;QAChB,KAAK;QACL,IAAI,EAAE,WAAW,aAAa,EAAE;KACjC,CAAC,CAAC;AACL,CAAC,CAAC;AAhBW,QAAA,eAAe,mBAgB1B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGitlabProjectId = exports.getGitlabProjectInfo = void 0;
|
|
4
|
+
const getGitRemoteHostAndPath_1 = require("../git/getGitRemoteHostAndPath");
|
|
5
|
+
const apiClient_1 = require("./apiClient");
|
|
6
|
+
const projectPreferences_1 = require("../utils/projectPreferences");
|
|
7
|
+
const getGitlabProjectInfo = async () => {
|
|
8
|
+
const api = await (0, apiClient_1.gitlabApiClient)();
|
|
9
|
+
const { gitRemotePath } = await (0, getGitRemoteHostAndPath_1.getGitRemoteHostAndPath)();
|
|
10
|
+
const projectInfo = await api.Projects.show(gitRemotePath);
|
|
11
|
+
// write unawaited intentionally
|
|
12
|
+
(0, projectPreferences_1.upsertProjectPerferences)({ gitlabProjectId: projectInfo.id });
|
|
13
|
+
return projectInfo;
|
|
14
|
+
};
|
|
15
|
+
exports.getGitlabProjectInfo = getGitlabProjectInfo;
|
|
16
|
+
const getGitlabProjectId = async () => {
|
|
17
|
+
const { gitlabProjectId } = await (0, projectPreferences_1.getProjectPreferences)();
|
|
18
|
+
if (gitlabProjectId) {
|
|
19
|
+
return gitlabProjectId;
|
|
20
|
+
}
|
|
21
|
+
const projectInfo = await (0, exports.getGitlabProjectInfo)();
|
|
22
|
+
return projectInfo.id;
|
|
23
|
+
};
|
|
24
|
+
exports.getGitlabProjectId = getGitlabProjectId;
|
|
25
|
+
//# sourceMappingURL=getGitlabProjectInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGitlabProjectInfo.js","sourceRoot":"","sources":["../../../../src/gitlab/getGitlabProjectInfo.ts"],"names":[],"mappings":";;;AACA,4EAAyE;AACzE,2CAA8C;AAC9C,oEAGqC;AAE9B,MAAM,oBAAoB,GAAG,KAAK,IAA4B,EAAE;IACrE,MAAM,GAAG,GAAG,MAAM,IAAA,2BAAe,GAAE,CAAC;IACpC,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,IAAA,iDAAuB,GAAE,CAAC;IAC1D,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC3D,gCAAgC;IAChC,IAAA,6CAAwB,EAAC,EAAE,eAAe,EAAE,WAAW,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAPW,QAAA,oBAAoB,wBAO/B;AAEK,MAAM,kBAAkB,GAAG,KAAK,IAAqB,EAAE;IAC5D,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,IAAA,0CAAqB,GAAE,CAAC;IAC1D,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,IAAA,4BAAoB,GAAE,CAAC;IACjD,OAAO,WAAW,CAAC,EAAE,CAAC;AACxB,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setPreference = exports.getPreference = exports.hasPreference = exports.getPreferences = void 0;
|
|
4
|
-
const
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const fs_1 = require("fs");
|
|
5
6
|
const os_1 = require("os");
|
|
6
7
|
const yaml_1 = require("yaml");
|
|
7
|
-
const
|
|
8
|
-
const
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const directory = (0, path_1.join)((0, os_1.homedir)(), ".catladder");
|
|
10
|
+
const file = (0, path_1.join)(directory, "preferences.yml");
|
|
9
11
|
const perfKeys = [
|
|
10
12
|
"gitlab-personal-access-token",
|
|
11
13
|
"googleAuthUserNumber",
|
|
@@ -16,14 +18,26 @@ const fallbackValues = {
|
|
|
16
18
|
gitlabTokens: {},
|
|
17
19
|
googleAuthUserNumber: null,
|
|
18
20
|
};
|
|
21
|
+
const perferencesWithParsed = (parsed) => perfKeys.reduce((acc, key) => { var _a; return Object.assign(acc, { [key]: (_a = parsed[key]) !== null && _a !== void 0 ? _a : fallbackValues[key] }); }, {});
|
|
22
|
+
const encoding = "utf-8";
|
|
23
|
+
const readPreferences = () => (0, promises_1.readFile)(file, { encoding });
|
|
24
|
+
const writePreferences = (preferences) => (0, promises_1.writeFile)(file, (0, yaml_1.stringify)(preferences), { encoding, mode: 0o600 });
|
|
25
|
+
const ensureDir = async () => (0, fs_1.existsSync)(directory)
|
|
26
|
+
? directory
|
|
27
|
+
: (0, promises_1.mkdir)(directory, { recursive: true, mode: 0o700 });
|
|
28
|
+
const ensureFile = async () => {
|
|
29
|
+
if ((0, fs_1.existsSync)(file)) {
|
|
30
|
+
return file;
|
|
31
|
+
}
|
|
32
|
+
await ensureDir();
|
|
33
|
+
return writePreferences(perferencesWithParsed({}));
|
|
34
|
+
};
|
|
19
35
|
const getPreferences = async () => {
|
|
20
36
|
var _a;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const fileString = await (0, fs_extra_1.readFile)(file, { encoding: "utf-8" });
|
|
37
|
+
await ensureFile();
|
|
38
|
+
const fileString = await readPreferences();
|
|
25
39
|
const fileParsed = (_a = (0, yaml_1.parse)(fileString || "---\nnull")) !== null && _a !== void 0 ? _a : {};
|
|
26
|
-
return
|
|
40
|
+
return perferencesWithParsed(fileParsed);
|
|
27
41
|
};
|
|
28
42
|
exports.getPreferences = getPreferences;
|
|
29
43
|
const hasPreference = async (key) => {
|
|
@@ -41,11 +55,7 @@ const getPreference = async (key) => {
|
|
|
41
55
|
exports.getPreference = getPreference;
|
|
42
56
|
const setPreference = async (key, value) => {
|
|
43
57
|
const preferences = await (0, exports.getPreferences)();
|
|
44
|
-
|
|
45
|
-
...preferences,
|
|
46
|
-
[key]: value,
|
|
47
|
-
};
|
|
48
|
-
await (0, fs_extra_1.writeFile)(file, (0, yaml_1.stringify)(newPreferences));
|
|
58
|
+
return writePreferences({ ...preferences, [key]: value });
|
|
49
59
|
};
|
|
50
60
|
exports.setPreference = setPreference;
|
|
51
61
|
//# sourceMappingURL=preferences.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preferences.js","sourceRoot":"","sources":["../../../../src/utils/preferences.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"preferences.js","sourceRoot":"","sources":["../../../../src/utils/preferences.ts"],"names":[],"mappings":";;;AAAA,0CAAyD;AACzD,2BAAgC;AAChC,2BAA6B;AAC7B,+BAAwC;AACxC,+BAA4B;AAE5B,MAAM,SAAS,GAAG,IAAA,WAAI,EAAC,IAAA,YAAO,GAAE,EAAE,YAAY,CAAC,CAAC;AAChD,MAAM,IAAI,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAQhD,MAAM,QAAQ,GAAG;IACf,8BAA8B;IAC9B,sBAAsB;IACtB,cAAc;CAC6B,CAAC;AAE9C,MAAM,cAAc,GAAG;IACrB,8BAA8B,EAAE,IAAI;IACpC,YAAY,EAAE,EAAE;IAChB,oBAAoB,EAAE,IAAI;CACO,CAAC;AAEpC,MAAM,qBAAqB,GAAG,CAC5B,MAAwC,EACf,EAAE,CAC3B,QAAQ,CAAC,MAAM,CACb,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,WACX,OAAA,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAA,MAAM,CAAC,GAAG,CAAC,mCAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA,EAAA,EACnE,EAA6B,CAC9B,CAAC;AAEJ,MAAM,QAAQ,GAAG,OAAO,CAAC;AAEzB,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,IAAA,mBAAQ,EAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE3D,MAAM,gBAAgB,GAAG,CAAC,WAAoC,EAAE,EAAE,CAChE,IAAA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sBAAc,GAAE,CAAC;IAC3C,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;QACvB,OAAO,WAAW,CAAC,GAAG,CAA+B,CAAC;IACxD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AARW,QAAA,aAAa,iBAQxB;AAEK,MAAM,aAAa,GAAG,KAAK,EAChC,GAAkB,EAClB,KAA0C,EAC1C,EAAE;IACF,MAAM,WAAW,GAAG,MAAM,IAAA,sBAAc,GAAE,CAAC;IAC3C,OAAO,gBAAgB,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5D,CAAC,CAAC;AANW,QAAA,aAAa,iBAMxB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type CatladderCliProjectPreferences = {
|
|
2
|
+
gitlabProjectId?: number | null;
|
|
3
|
+
gitlabHttpUrlToRepo?: string | null;
|
|
4
|
+
};
|
|
5
|
+
export declare const getProjectPreferences: (givenFilePath?: string) => Promise<CatladderCliProjectPreferences>;
|
|
6
|
+
export declare const upsertProjectPerferences: (newPerfs?: Partial<CatladderCliProjectPreferences>, givenFilePath?: string) => Promise<void>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upsertProjectPerferences = exports.getProjectPreferences = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const git_1 = require("../git");
|
|
8
|
+
const directory = ".catladder";
|
|
9
|
+
const file = "preferences.json";
|
|
10
|
+
const perfKeys = [
|
|
11
|
+
"gitlabProjectId",
|
|
12
|
+
"gitlabHttpUrlToRepo",
|
|
13
|
+
];
|
|
14
|
+
const fallbackValues = {
|
|
15
|
+
gitlabProjectId: null,
|
|
16
|
+
gitlabHttpUrlToRepo: null,
|
|
17
|
+
};
|
|
18
|
+
const perferencesWithParsed = (parsed) => perfKeys.reduce((acc, key) => { var _a, _b; return Object.assign(acc, { [key]: (_b = (_a = parsed[key]) !== null && _a !== void 0 ? _a : fallbackValues[key]) !== null && _b !== void 0 ? _b : null }); }, {});
|
|
19
|
+
const encoding = "utf-8";
|
|
20
|
+
const readPreferences = (filePath) => (0, promises_1.readFile)(filePath, { encoding });
|
|
21
|
+
const writePreferences = (filePath, preferences) => (0, promises_1.writeFile)(filePath, JSON.stringify(preferences, null, 2), {
|
|
22
|
+
encoding,
|
|
23
|
+
mode: 0o600,
|
|
24
|
+
});
|
|
25
|
+
const ensureDir = async (dirPath) => (0, fs_1.existsSync)(dirPath)
|
|
26
|
+
? dirPath
|
|
27
|
+
: (0, promises_1.mkdir)(dirPath, { recursive: true, mode: 0o700 });
|
|
28
|
+
const ensureFile = async (givenFilePath) => {
|
|
29
|
+
if ((givenFilePath === null || givenFilePath === void 0 ? void 0 : givenFilePath.length) && (0, fs_1.existsSync)(givenFilePath)) {
|
|
30
|
+
return givenFilePath;
|
|
31
|
+
}
|
|
32
|
+
const rootPath = await (0, git_1.getProjectRootPath)();
|
|
33
|
+
const dirPath = (0, path_1.join)(rootPath, directory);
|
|
34
|
+
const filePath = (0, path_1.join)(dirPath, file);
|
|
35
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
|
36
|
+
return filePath;
|
|
37
|
+
}
|
|
38
|
+
await ensureDir(dirPath);
|
|
39
|
+
await writePreferences(filePath, perferencesWithParsed({}));
|
|
40
|
+
return filePath;
|
|
41
|
+
};
|
|
42
|
+
const getProjectPreferences = async (givenFilePath) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const filePath = await ensureFile(givenFilePath);
|
|
45
|
+
const fileString = await readPreferences(filePath);
|
|
46
|
+
const fileParsed = (_a = JSON.parse(fileString || "null")) !== null && _a !== void 0 ? _a : {};
|
|
47
|
+
return perferencesWithParsed(fileParsed);
|
|
48
|
+
};
|
|
49
|
+
exports.getProjectPreferences = getProjectPreferences;
|
|
50
|
+
const upsertProjectPerferences = async (newPerfs = {}, givenFilePath) => {
|
|
51
|
+
const filePath = await ensureFile(givenFilePath);
|
|
52
|
+
const currentPerfs = await (0, exports.getProjectPreferences)(filePath);
|
|
53
|
+
return writePreferences(filePath, { ...currentPerfs, ...newPerfs });
|
|
54
|
+
};
|
|
55
|
+
exports.upsertProjectPerferences = upsertProjectPerferences;
|
|
56
|
+
//# sourceMappingURL=projectPreferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projectPreferences.js","sourceRoot":"","sources":["../../../../src/utils/projectPreferences.ts"],"names":[],"mappings":";;;AAAA,0CAAyD;AACzD,2BAAgC;AAChC,+BAA4B;AAC5B,gCAA4C;AAE5C,MAAM,SAAS,GAAG,YAAY,CAAC;AAC/B,MAAM,IAAI,GAAG,kBAAkB,CAAC;AAOhC,MAAM,QAAQ,GAAG;IACf,iBAAiB;IACjB,qBAAqB;CAC6B,CAAC;AACrD,MAAM,cAAc,GAAG;IACrB,eAAe,EAAE,IAAI;IACrB,mBAAmB,EAAE,IAAI;CACe,CAAC;AAE3C,MAAM,qBAAqB,GAAG,CAC5B,MAA+C,EACf,EAAE,CAClC,QAAQ,CAAC,MAAM,CACb,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,eACX,OAAA,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAA,MAAA,MAAM,CAAC,GAAG,CAAC,mCAAI,cAAc,CAAC,GAAG,CAAC,mCAAI,IAAI,EAAE,CAAC,CAAA,EAAA,EAC3E,EAAoC,CACrC,CAAC;AAEJ,MAAM,QAAQ,GAAG,OAAO,CAAC;AAEzB,MAAM,eAAe,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,IAAA,mBAAQ,EAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE/E,MAAM,gBAAgB,GAAG,CACvB,QAAgB,EA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