tnp-helpers 13.1.1 → 13.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.
Files changed (185) hide show
  1. package/app.d.ts +1 -1
  2. package/app.js +6 -6
  3. package/browser/README.md +24 -24
  4. package/browser/esm2020/lib/base-component.mjs +47 -47
  5. package/browser/esm2020/lib/base-formly-component.mjs +125 -125
  6. package/browser/esm2020/lib/condition-wait.mjs +53 -53
  7. package/browser/esm2020/lib/constants.mjs +6 -6
  8. package/browser/esm2020/lib/dual-component-ctrl.mjs +120 -120
  9. package/browser/esm2020/lib/helpers-array-obj.mjs +80 -80
  10. package/browser/esm2020/lib/helpers-environment.mjs +30 -30
  11. package/browser/esm2020/lib/helpers-numbers.mjs +5 -5
  12. package/browser/esm2020/lib/helpers-strings-regexes.mjs +48 -48
  13. package/browser/esm2020/lib/helpers-strings.mjs +257 -257
  14. package/browser/esm2020/lib/helpers.mjs +276 -276
  15. package/browser/esm2020/lib/index.mjs +14 -14
  16. package/browser/esm2020/lib/long-press.directive.mjs +111 -111
  17. package/browser/esm2020/lib/project.mjs +413 -413
  18. package/browser/esm2020/lib/resize-service.mjs +19 -19
  19. package/browser/esm2020/public-api.mjs +1 -1
  20. package/browser/esm2020/tnp-helpers.mjs +4 -4
  21. package/browser/fesm2015/tnp-helpers.mjs +1535 -1535
  22. package/browser/fesm2020/tnp-helpers.mjs +1527 -1527
  23. package/browser/lib/base-component.d.ts +17 -17
  24. package/browser/lib/base-formly-component.d.ts +31 -31
  25. package/browser/lib/condition-wait.d.ts +8 -8
  26. package/browser/lib/constants.d.ts +6 -6
  27. package/browser/lib/dual-component-ctrl.d.ts +25 -25
  28. package/browser/lib/helpers-array-obj.d.ts +15 -15
  29. package/browser/lib/helpers-environment.d.ts +5 -5
  30. package/browser/lib/helpers-numbers.d.ts +3 -3
  31. package/browser/lib/helpers-strings-regexes.d.ts +28 -28
  32. package/browser/lib/helpers-strings.d.ts +50 -50
  33. package/browser/lib/helpers.d.ts +28 -28
  34. package/browser/lib/index.d.ts +9 -9
  35. package/browser/lib/long-press.directive.d.ts +25 -25
  36. package/browser/lib/project.d.ts +91 -91
  37. package/browser/lib/resize-service.d.ts +9 -9
  38. package/browser/public-api.d.ts +1 -1
  39. package/browser/tnp-helpers.d.ts +5 -5
  40. package/client/README.md +24 -24
  41. package/client/esm2020/lib/base-component.mjs +47 -47
  42. package/client/esm2020/lib/base-formly-component.mjs +125 -125
  43. package/client/esm2020/lib/condition-wait.mjs +53 -53
  44. package/client/esm2020/lib/constants.mjs +6 -6
  45. package/client/esm2020/lib/dual-component-ctrl.mjs +120 -120
  46. package/client/esm2020/lib/helpers-array-obj.mjs +80 -80
  47. package/client/esm2020/lib/helpers-environment.mjs +30 -30
  48. package/client/esm2020/lib/helpers-numbers.mjs +5 -5
  49. package/client/esm2020/lib/helpers-strings-regexes.mjs +48 -48
  50. package/client/esm2020/lib/helpers-strings.mjs +257 -257
  51. package/client/esm2020/lib/helpers.mjs +276 -276
  52. package/client/esm2020/lib/index.mjs +14 -14
  53. package/client/esm2020/lib/long-press.directive.mjs +111 -111
  54. package/client/esm2020/lib/project.mjs +413 -413
  55. package/client/esm2020/lib/resize-service.mjs +19 -19
  56. package/client/esm2020/public-api.mjs +1 -1
  57. package/client/esm2020/tnp-helpers.mjs +4 -4
  58. package/client/fesm2015/tnp-helpers.mjs +1535 -1535
  59. package/client/fesm2020/tnp-helpers.mjs +1527 -1527
  60. package/client/lib/base-component.d.ts +17 -17
  61. package/client/lib/base-formly-component.d.ts +31 -31
  62. package/client/lib/condition-wait.d.ts +8 -8
  63. package/client/lib/constants.d.ts +6 -6
  64. package/client/lib/dual-component-ctrl.d.ts +25 -25
  65. package/client/lib/helpers-array-obj.d.ts +15 -15
  66. package/client/lib/helpers-environment.d.ts +5 -5
  67. package/client/lib/helpers-numbers.d.ts +3 -3
  68. package/client/lib/helpers-strings-regexes.d.ts +28 -28
  69. package/client/lib/helpers-strings.d.ts +50 -50
  70. package/client/lib/helpers.d.ts +28 -28
  71. package/client/lib/index.d.ts +9 -9
  72. package/client/lib/long-press.directive.d.ts +25 -25
  73. package/client/lib/project.d.ts +91 -91
  74. package/client/lib/resize-service.d.ts +9 -9
  75. package/client/public-api.d.ts +1 -1
  76. package/client/tnp-helpers.d.ts +5 -5
  77. package/index.d.ts +1 -1
  78. package/index.js +5 -5
  79. package/lib/angular.helper.d.ts +22 -22
  80. package/lib/angular.helper.js +50 -50
  81. package/lib/base-component.d.ts +1 -1
  82. package/lib/base-component.js +6 -6
  83. package/lib/base-formly-component.d.ts +1 -1
  84. package/lib/base-formly-component.js +6 -6
  85. package/lib/condition-wait.d.ts +8 -8
  86. package/lib/condition-wait.js +94 -94
  87. package/lib/constants.d.ts +6 -6
  88. package/lib/constants.js +10 -10
  89. package/lib/dual-component-ctrl.d.ts +1 -1
  90. package/lib/dual-component-ctrl.js +6 -6
  91. package/lib/git-project.d.ts +44 -44
  92. package/lib/git-project.js +195 -195
  93. package/lib/helpers-array-obj.d.ts +15 -15
  94. package/lib/helpers-array-obj.js +88 -88
  95. package/lib/helpers-cli-tool.backend.d.ts +45 -45
  96. package/lib/helpers-cli-tool.backend.js +293 -293
  97. package/lib/helpers-dependencies.backend.d.ts +11 -11
  98. package/lib/helpers-dependencies.backend.js +105 -105
  99. package/lib/helpers-environment.d.ts +5 -5
  100. package/lib/helpers-environment.js +35 -35
  101. package/lib/helpers-file-folders.backend.d.ts +84 -84
  102. package/lib/helpers-file-folders.backend.js +736 -736
  103. package/lib/helpers-git.backend.d.ts +35 -35
  104. package/lib/helpers-git.backend.js +541 -545
  105. package/lib/helpers-git.backend.js.map +1 -1
  106. package/lib/helpers-json5.backend.d.ts +16 -16
  107. package/lib/helpers-json5.backend.js +70 -70
  108. package/lib/helpers-morphi-framework.backend.d.ts +4 -4
  109. package/lib/helpers-morphi-framework.backend.js +49 -49
  110. package/lib/helpers-network.backend.d.ts +8 -8
  111. package/lib/helpers-network.backend.js +48 -48
  112. package/lib/helpers-npm.backend.d.ts +3 -3
  113. package/lib/helpers-npm.backend.js +17 -17
  114. package/lib/helpers-numbers.d.ts +3 -3
  115. package/lib/helpers-numbers.js +11 -11
  116. package/lib/helpers-path.backend.d.ts +7 -7
  117. package/lib/helpers-path.backend.js +36 -36
  118. package/lib/helpers-process.backend.d.ts +57 -57
  119. package/lib/helpers-process.backend.js +529 -529
  120. package/lib/helpers-process.backend.js.map +1 -1
  121. package/lib/helpers-strings-regexes.d.ts +28 -28
  122. package/lib/helpers-strings-regexes.js +60 -60
  123. package/lib/helpers-strings.d.ts +50 -50
  124. package/lib/helpers-strings.js +265 -265
  125. package/lib/helpers-system-terminal.backend.d.ts +5 -5
  126. package/lib/helpers-system-terminal.backend.js +53 -53
  127. package/lib/helpers.d.ts +67 -67
  128. package/lib/helpers.js +391 -391
  129. package/lib/index.d.ts +6 -6
  130. package/lib/index.js +19 -19
  131. package/lib/long-press.directive.d.ts +22 -22
  132. package/lib/long-press.directive.js +141 -141
  133. package/lib/merge-helpers.backend.d.ts +23 -23
  134. package/lib/merge-helpers.backend.js +108 -108
  135. package/lib/project.d.ts +94 -94
  136. package/lib/project.js +422 -422
  137. package/lib/resize-service.d.ts +6 -6
  138. package/lib/resize-service.js +24 -24
  139. package/lib/ts-code/index.d.ts +1 -1
  140. package/lib/ts-code/index.js +7 -7
  141. package/lib/ts-code/ts-code-extractor.d.ts +14 -14
  142. package/lib/ts-code/ts-code-extractor.js +46 -46
  143. package/lib/ts-code/ts-code-modifier.backend.d.ts +12 -12
  144. package/lib/ts-code/ts-code-modifier.backend.js +70 -70
  145. package/package.json +5 -5
  146. package/package.json_devDependencies.json +222 -222
  147. package/package.json_tnp.json5 +41 -41
  148. package/tmp-environment.json +36 -35
  149. package/websql/README.md +24 -24
  150. package/websql/esm2020/lib/base-component.mjs +47 -47
  151. package/websql/esm2020/lib/base-formly-component.mjs +125 -125
  152. package/websql/esm2020/lib/condition-wait.mjs +53 -53
  153. package/websql/esm2020/lib/constants.mjs +6 -6
  154. package/websql/esm2020/lib/dual-component-ctrl.mjs +120 -120
  155. package/websql/esm2020/lib/helpers-array-obj.mjs +80 -80
  156. package/websql/esm2020/lib/helpers-environment.mjs +30 -30
  157. package/websql/esm2020/lib/helpers-numbers.mjs +5 -5
  158. package/websql/esm2020/lib/helpers-strings-regexes.mjs +48 -48
  159. package/websql/esm2020/lib/helpers-strings.mjs +257 -257
  160. package/websql/esm2020/lib/helpers.mjs +276 -276
  161. package/websql/esm2020/lib/index.mjs +14 -14
  162. package/websql/esm2020/lib/long-press.directive.mjs +111 -111
  163. package/websql/esm2020/lib/project.mjs +413 -413
  164. package/websql/esm2020/lib/resize-service.mjs +19 -19
  165. package/websql/esm2020/public-api.mjs +1 -1
  166. package/websql/esm2020/tnp-helpers.mjs +4 -4
  167. package/websql/fesm2015/tnp-helpers.mjs +1535 -1535
  168. package/websql/fesm2020/tnp-helpers.mjs +1527 -1527
  169. package/websql/lib/base-component.d.ts +17 -17
  170. package/websql/lib/base-formly-component.d.ts +31 -31
  171. package/websql/lib/condition-wait.d.ts +8 -8
  172. package/websql/lib/constants.d.ts +6 -6
  173. package/websql/lib/dual-component-ctrl.d.ts +25 -25
  174. package/websql/lib/helpers-array-obj.d.ts +15 -15
  175. package/websql/lib/helpers-environment.d.ts +5 -5
  176. package/websql/lib/helpers-numbers.d.ts +3 -3
  177. package/websql/lib/helpers-strings-regexes.d.ts +28 -28
  178. package/websql/lib/helpers-strings.d.ts +50 -50
  179. package/websql/lib/helpers.d.ts +28 -28
  180. package/websql/lib/index.d.ts +9 -9
  181. package/websql/lib/long-press.directive.d.ts +25 -25
  182. package/websql/lib/project.d.ts +91 -91
  183. package/websql/lib/resize-service.d.ts +9 -9
  184. package/websql/public-api.d.ts +1 -1
  185. package/websql/tnp-helpers.d.ts +5 -5
@@ -1,545 +1,541 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelpersGit = void 0;
4
- var tslib_1 = require("tslib");
5
- //#region imports
6
- var tnp_core_1 = require("tnp-core");
7
- var tnp_cli_1 = require("tnp-cli");
8
- var index_1 = require("./index");
9
- var tnp_config_1 = require("tnp-config");
10
- //#endregion
11
- var HelpersGit = /** @class */ (function () {
12
- function HelpersGit() {
13
- }
14
- //#region get last commit hash
15
- HelpersGit.prototype.lastCommitHash = function (directoryPath) {
16
- try {
17
- var cwd = directoryPath;
18
- var hash = this.isGitRepo(cwd) && tnp_core_1.child_process.execSync("git log -1 --format=\"%H\"", { cwd: cwd }).toString().trim();
19
- return hash;
20
- }
21
- catch (e) {
22
- index_1.Helpers.log(e, 1);
23
- index_1.Helpers.log("[lastCommitHash] Not able to get last commit hash for repository in ".concat(directoryPath), 1);
24
- return null;
25
- }
26
- };
27
- //#endregion
28
- //#region get penultimate commit hash
29
- HelpersGit.prototype.penultimageCommitHash = function (directoryPath) {
30
- try {
31
- var cwd = directoryPath;
32
- var hash = this.isGitRepo(cwd) && tnp_core_1.child_process.execSync("git log -2 --format=\"%H\"", { cwd: cwd }).toString().trim();
33
- return hash;
34
- }
35
- catch (e) {
36
- index_1.Helpers.log(e, 1);
37
- index_1.Helpers.log("[lastCommitHash] Not able to get last commit hash for repository in ".concat(directoryPath), 1);
38
- return null;
39
- }
40
- };
41
- //#endregion
42
- //#region check tag exists
43
- HelpersGit.prototype.checkTagExists = function (tag, cwd) {
44
- if (cwd === void 0) { cwd = process.cwd(); }
45
- var command = "git show-ref --tags ".concat(tag).trim();
46
- var result = (index_1.Helpers.commnadOutputAsString(command, cwd) || '') !== '';
47
- return result;
48
- };
49
- //#endregion
50
- HelpersGit.prototype.lastTagVersionName = function (directoryPath) {
51
- try {
52
- var cwd = directoryPath;
53
- var command = "git describe --tags $(git rev-list --tags --max-count=1)";
54
- if (process.platform === 'win32') {
55
- command = 'git describe --tags --abbrev=0';
56
- }
57
- var tag = index_1.Helpers.commnadOutputAsString(command, cwd);
58
- if (!tag) {
59
- return void 0;
60
- }
61
- return tag;
62
- }
63
- catch (e) {
64
- index_1.Helpers.warn("[lastCommitHash] Not able to get last commit version name for repository in ".concat(directoryPath), false);
65
- return void 0;
66
- }
67
- };
68
- //#region get last tag hash
69
- HelpersGit.prototype.lastTagHash = function (directoryPath) {
70
- try {
71
- var cwd = directoryPath;
72
- var command = "git describe --tags $(git rev-list --tags --max-count=1)";
73
- if (process.platform === 'win32') {
74
- command = 'git describe --tags --abbrev=0';
75
- }
76
- var tag = index_1.Helpers.commnadOutputAsString(command, cwd);
77
- if (!tag) {
78
- return null;
79
- }
80
- var hash = tnp_core_1.child_process.execSync("git log -1 --format=format:\"%H\" ".concat(tag), { cwd: cwd }).toString().trim();
81
- return hash;
82
- }
83
- catch (e) {
84
- index_1.Helpers.log(e, 1);
85
- index_1.Helpers.log("[lastCommitHash] Not able to get last commit hash for repository in ".concat(directoryPath), 1);
86
- return null;
87
- }
88
- };
89
- //#endregion
90
- //#region get last commit date
91
- HelpersGit.prototype.lastCommitDate = function (cwd) {
92
- try {
93
- var unixTimestamp = this.isGitRepo(cwd)
94
- && tnp_core_1.child_process
95
- .execSync("git log -1 --pretty=format:%ct", { cwd: cwd })
96
- .toString()
97
- .trim();
98
- return new Date(Number(unixTimestamp) * 1000);
99
- }
100
- catch (e) {
101
- index_1.Helpers.log(e, 1);
102
- index_1.Helpers.log("[lastCommitDate] Cannot counts commits in branch in: ".concat(cwd), 1);
103
- return null;
104
- }
105
- };
106
- //#endregion
107
- //#region get last commit date
108
- HelpersGit.prototype.lastCommitMessage = function (directoryPath) {
109
- try {
110
- var cwd = directoryPath;
111
- var unixTimestamp = tnp_core_1.child_process.execSync("git log -1 --pretty=%B", { cwd: cwd }).toString().trim();
112
- return unixTimestamp;
113
- }
114
- catch (e) {
115
- index_1.Helpers.log(e, 1);
116
- index_1.Helpers.log("[lastCommitMessage] Cannot display last commit message in branch in: ".concat(directoryPath), 1);
117
- return null;
118
- }
119
- };
120
- //#endregion
121
- //#region get number of commit in repository
122
- HelpersGit.prototype.countCommits = function (cwd) {
123
- try {
124
- // git rev-parse HEAD &> /dev/null check if any commits
125
- var currentLocalBranch = this.currentBranchName(cwd);
126
- var value = this.isGitRepo(cwd) && tnp_core_1.child_process
127
- .execSync("git rev-list --count ".concat(currentLocalBranch), { cwd: cwd })
128
- .toString()
129
- .trim();
130
- return Number(value);
131
- }
132
- catch (e) {
133
- index_1.Helpers.log(e, 1);
134
- index_1.Helpers.log("[countCommits] Cannot counts commits in branch in: ".concat(cwd), 1);
135
- return 0;
136
- }
137
- };
138
- //#endregion
139
- //#region get branches names
140
- HelpersGit.prototype.getBranchesNames = function (cwd, pattern) {
141
- try {
142
- var branchPattern_1 = pattern;
143
- if (tnp_core_1._.isString(pattern)) {
144
- branchPattern_1 = new RegExp(pattern.replace(/[^a-zA-Z0-9]+/g, '.*'));
145
- }
146
- var command = "git branch -a";
147
- // console.log({ command, cwd })
148
- var branchNames = index_1.Helpers.commnadOutputAsString(command, cwd, true, true);
149
- // console.log({ branchNames })
150
- var _branchNames = branchNames
151
- .toString()
152
- .trim()
153
- .split('\n')
154
- .map(function (l) { return l.replace('*', '').trim(); })
155
- .filter(function (l) {
156
- // console.log('testing: ' + l)
157
- if (tnp_core_1._.isRegExp(branchPattern_1)) {
158
- var match = branchPattern_1.test(l);
159
- return match;
160
- }
161
- // if (_.isString(pattern)) {
162
- // return l.search(pattern)
163
- // }
164
- return true;
165
- });
166
- return _branchNames;
167
- }
168
- catch (e) {
169
- index_1.Helpers.log(e);
170
- return [];
171
- }
172
- };
173
- //#endregion
174
- //#region get current branch name
175
- HelpersGit.prototype.currentBranchName = function (cwd) {
176
- try {
177
- var branchName = tnp_core_1.child_process.execSync("git branch | sed -n '/* /s///p'", { cwd: cwd }).toString().trim();
178
- return branchName;
179
- }
180
- catch (e) {
181
- index_1.Helpers.error(e);
182
- }
183
- };
184
- //#endregion
185
- //#region commit "what is"
186
- HelpersGit.prototype.commitWhatIs = function (customMessage) {
187
- if (customMessage === void 0) { customMessage = 'changes'; }
188
- try {
189
- index_1.Helpers.run("git add --all . ").sync();
190
- }
191
- catch (error) {
192
- index_1.Helpers.warn("Failed to git add --all .");
193
- }
194
- try {
195
- index_1.Helpers.run("git commit -m \"".concat(customMessage, "\"")).sync();
196
- }
197
- catch (error) {
198
- index_1.Helpers.warn("Failed to git commit -m \"".concat(customMessage, "\""));
199
- }
200
- };
201
- //#endregion
202
- //#region commit
203
- HelpersGit.prototype.commit = function (cwd, ProjectClass, args) {
204
- if (!tnp_core_1._.isString(args)) {
205
- args = 'update';
206
- }
207
- var gitRootProject = ProjectClass.nearestTo(cwd, { findGitRoot: true });
208
- try {
209
- index_1.Helpers.info("[git][commit] Adding current git changes in git root:\n ".concat(gitRootProject.location, "\n "));
210
- gitRootProject.run("git add --all . ").sync();
211
- }
212
- catch (error) {
213
- index_1.Helpers.log(error);
214
- index_1.Helpers.warn("Failed to 'git add --all .' in:\n ".concat(gitRootProject.location));
215
- }
216
- if (args.search('-m') === -1 && args.search('-msg') === -1) {
217
- var addBrackets = !((args.startsWith('\'') ||
218
- args.startsWith('"')) &&
219
- (args.endsWith('\'') ||
220
- args.endsWith('"')));
221
- args = "-m ".concat(addBrackets ? "\"".concat(args, "\"") : args);
222
- }
223
- try {
224
- index_1.Helpers.info("[git][commit] trying to commit what it with argument:\n \"".concat(args, "\"\n location: ").concat(cwd, "\n "));
225
- var cmdddd = "git commit --no-verify ".concat(args);
226
- index_1.Helpers.run(cmdddd, { cwd: cwd }).sync();
227
- }
228
- catch (error) {
229
- index_1.Helpers.log(error);
230
- index_1.Helpers.warn("[git][commit] not able to commit what is with command: ".concat(cmdddd));
231
- }
232
- };
233
- //#endregion
234
- //#region get remote origin
235
- HelpersGit.prototype.getOriginURL = function (cwd, differentOriginName) {
236
- if (differentOriginName === void 0) { differentOriginName = ''; }
237
- var url = '';
238
- try {
239
- // git config --get remote.origin.url
240
- url = index_1.Helpers.run("git config --get remote.".concat(differentOriginName ? differentOriginName : 'origin', ".url"), { output: false, cwd: cwd }).sync().toString().trim();
241
- }
242
- catch (error) {
243
- return '< not able to get origin >';
244
- }
245
- return url;
246
- };
247
- //#endregion
248
- //#region is git root
249
- HelpersGit.prototype.isGitRoot = function (cwd) {
250
- return this.isGitRepo(cwd) && tnp_core_1.fse.existsSync(tnp_core_1.path.join(cwd, '.git'));
251
- };
252
- //#endregion
253
- //#region is git repo
254
- HelpersGit.prototype.isGitRepo = function (cwd) {
255
- // if(this.isGitRoot(cwd)) {
256
- // return true;
257
- // }
258
- try {
259
- var test = index_1.Helpers.run('git rev-parse --is-inside-work-tree', {
260
- biggerBuffer: false,
261
- cwd: cwd,
262
- output: false
263
- }).sync();
264
- }
265
- catch (e) {
266
- return false;
267
- }
268
- return !!test;
269
- };
270
- //#endregion
271
- HelpersGit.prototype.pull = function (branchName, cwd) {
272
- if (branchName === void 0) { branchName = 'master'; }
273
- if (cwd === void 0) { cwd = (0, tnp_core_1.crossPlatformPath)(process.cwd()); }
274
- tnp_core_1.child_process.execSync("git pull --tags --rebase origin ".concat(branchName), { cwd: cwd });
275
- };
276
- //#region pull current branch
277
- HelpersGit.prototype.pullBranch = function (branchName, directoryPath, askToRetry) {
278
- if (askToRetry === void 0) { askToRetry = false; }
279
- return tslib_1.__awaiter(this, void 0, void 0, function () {
280
- var cwd, e_1;
281
- var _this = this;
282
- return tslib_1.__generator(this, function (_a) {
283
- switch (_a.label) {
284
- case 0:
285
- if (this.getOriginURL(directoryPath) === '') {
286
- index_1.Helpers.warn("Not pulling branch without "
287
- + "remote origin url.... in folder ".concat(tnp_core_1.path.basename(directoryPath)));
288
- return [2 /*return*/];
289
- }
290
- index_1.Helpers.info("Pulling git changes in \"".concat(directoryPath, "\" , origin=").concat(index_1.Helpers.git.getOriginURL(directoryPath), " "));
291
- _a.label = 1;
292
- case 1:
293
- _a.trys.push([1, 2, , 5]);
294
- cwd = directoryPath;
295
- index_1.Helpers.git.pull(branchName, cwd);
296
- index_1.Helpers.info("Branch \"".concat(branchName, "\" updated successfully in ").concat(tnp_core_1.path.basename(directoryPath)));
297
- return [3 /*break*/, 5];
298
- case 2:
299
- e_1 = _a.sent();
300
- // console.log(e)
301
- index_1.Helpers.error("Cannot update current branch in: ".concat(directoryPath), askToRetry, true);
302
- if (!askToRetry) return [3 /*break*/, 4];
303
- return [4 /*yield*/, index_1.Helpers.questionYesNo("Do you wanna try again ?", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
304
- return tslib_1.__generator(this, function (_a) {
305
- switch (_a.label) {
306
- case 0: return [4 /*yield*/, index_1.Helpers.git.pullCurrentBranch(directoryPath, askToRetry)];
307
- case 1:
308
- _a.sent();
309
- return [2 /*return*/];
310
- }
311
- });
312
- }); }, function () {
313
- process.exit(0);
314
- })];
315
- case 3:
316
- _a.sent();
317
- _a.label = 4;
318
- case 4: return [3 /*break*/, 5];
319
- case 5: return [2 /*return*/];
320
- }
321
- });
322
- });
323
- };
324
- //#endregion
325
- //#region pull current branch
326
- HelpersGit.prototype.pullCurrentBranch = function (directoryPath, askToRetry) {
327
- if (askToRetry === void 0) { askToRetry = true; }
328
- return tslib_1.__awaiter(this, void 0, void 0, function () {
329
- var cwd, currentLocalBranch, e_2;
330
- var _this = this;
331
- return tslib_1.__generator(this, function (_a) {
332
- switch (_a.label) {
333
- case 0:
334
- if (global['tnpNonInteractive']) {
335
- askToRetry = false;
336
- }
337
- index_1.Helpers.log("askToRetry: ".concat(askToRetry));
338
- if (this.getOriginURL(directoryPath) === '') {
339
- index_1.Helpers.warn("Not pulling branch without "
340
- + "remote origin url.... in folder ".concat(tnp_core_1.path.basename(directoryPath)));
341
- return [2 /*return*/];
342
- }
343
- index_1.Helpers.info("Pulling git changes in \"".concat(directoryPath, "\", origin=").concat(index_1.Helpers.git.getOriginURL(directoryPath), " "));
344
- _a.label = 1;
345
- case 1:
346
- _a.trys.push([1, 2, , 5]);
347
- cwd = directoryPath;
348
- currentLocalBranch = tnp_core_1.child_process.execSync("git branch | sed -n '/* /s///p'", { cwd: cwd }).toString().trim();
349
- index_1.Helpers.git.pull(currentLocalBranch, cwd);
350
- index_1.Helpers.info("Branch \"".concat(currentLocalBranch, "\" updated successfully in ").concat(tnp_core_1.path.basename(directoryPath)));
351
- return [3 /*break*/, 5];
352
- case 2:
353
- e_2 = _a.sent();
354
- console.log(e_2);
355
- index_1.Helpers.error("Cannot update current branch in: ".concat(directoryPath), askToRetry, true);
356
- if (!askToRetry) return [3 /*break*/, 4];
357
- return [4 /*yield*/, index_1.Helpers.questionYesNo("Do you wanna try again ?", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
358
- return tslib_1.__generator(this, function (_a) {
359
- switch (_a.label) {
360
- case 0: return [4 /*yield*/, index_1.Helpers.git.pullCurrentBranch(directoryPath, askToRetry)];
361
- case 1:
362
- _a.sent();
363
- return [2 /*return*/];
364
- }
365
- });
366
- }); }, function () {
367
- process.exit(1);
368
- })];
369
- case 3:
370
- _a.sent();
371
- _a.label = 4;
372
- case 4: return [3 /*break*/, 5];
373
- case 5:
374
- index_1.Helpers.info("DONE PULLING");
375
- return [2 /*return*/];
376
- }
377
- });
378
- });
379
- };
380
- //#endregion
381
- //#region push current branch
382
- HelpersGit.prototype.pushCurrentBranch = function (cwd, force, origin) {
383
- if (force === void 0) { force = false; }
384
- if (origin === void 0) { origin = 'origin'; }
385
- var currentBranchName = index_1.Helpers.git.currentBranchName(cwd);
386
- var taskName = "\n Pushing current branch (remote=".concat(origin, "): ").concat(currentBranchName, "\n ");
387
- index_1.Helpers.info(taskName);
388
- while (true) {
389
- try {
390
- var command = "git push ".concat(force ? '-f' : '', " ").concat(origin, " ").concat(currentBranchName, " --tags");
391
- index_1.Helpers.info("[git][push] ".concat(force ? 'force' : '', " pushing current branch ").concat(currentBranchName, " ,")
392
- + " origin=".concat(index_1.Helpers.git.getOriginURL(cwd, origin)));
393
- index_1.Helpers.run(command, { cwd: cwd }).sync();
394
- index_1.Helpers.info(taskName);
395
- break;
396
- }
397
- catch (err) {
398
- index_1.Helpers.error("[tnp-helpers] Not able to push branch ".concat(currentBranchName, " in (origin=").concat(origin, "):\n ").concat(cwd), true, true);
399
- index_1.Helpers.pressKeyAndContinue("Press any key to try again: ");
400
- // TODO issue 1: issue with press any key
401
- // TODO issue 2: Updates were rejected because the tag already exists in the remote
402
- continue;
403
- }
404
- }
405
- };
406
- //#endregion
407
- //#region get default branch for repo
408
- HelpersGit.prototype.defaultRepoBranch = function (cwd) {
409
- try {
410
- var defaultBranch = tnp_core_1.child_process
411
- .execSync("git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'", { cwd: cwd })
412
- .toString().trim();
413
- return defaultBranch;
414
- }
415
- catch (e) {
416
- index_1.Helpers.log(e);
417
- index_1.Helpers.error("Cannot find default branch for repo in : ".concat(cwd));
418
- }
419
- };
420
- //#endregion
421
- //#region checkout default branch
422
- HelpersGit.prototype.checkoutDefaultBranch = function (directoryPath) {
423
- var cwd = directoryPath;
424
- var defaultBranch = tnp_core_1.child_process
425
- .execSync("git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'", { cwd: cwd })
426
- .toString().trim();
427
- tnp_core_1.child_process.execSync("git checkout ".concat(defaultBranch), { cwd: cwd });
428
- };
429
- //#endregion
430
- //#region clone
431
- HelpersGit.prototype.clone = function (_a) {
432
- // const ALWAYS_HTTPS = true;
433
- var _b, _c;
434
- var cwd = _a.cwd, url = _a.url, _d = _a.destinationFolderName, destinationFolderName = _d === void 0 ? '' : _d, throwErrors = _a.throwErrors, override = _a.override;
435
- if (url.split(' ').length > 2) {
436
- // const [rUrl, rDest] = url.split(' ');
437
- index_1.Helpers.error("[tnp-helpers]incorrect clone url \"".concat(url, "\""));
438
- }
439
- if (url.split(' ').length === 2) {
440
- var _e = tslib_1.__read(url.split(' '), 2), rUrl = _e[0], rDest = _e[1];
441
- if (destinationFolderName) {
442
- index_1.Helpers.error("[tnp-helpers] wrong cloning argument\n\n url = \"".concat(url, "\"\n destinationFolderName = \"").concat(destinationFolderName, "\"\n\n cant use both at the same time\n "));
443
- }
444
- else {
445
- destinationFolderName = rDest;
446
- url = rUrl;
447
- }
448
- }
449
- if (!url.endsWith('.git')) {
450
- url = (url + '.git');
451
- }
452
- var cloneFolderPath = tnp_core_1.path.join(cwd, (!!destinationFolderName && destinationFolderName.trim() !== '')
453
- ? destinationFolderName
454
- : tnp_core_1.path.basename(url)).trim().replace('.git', '');
455
- // console.log({ cloneFolderPath })
456
- if (override) {
457
- index_1.Helpers.remove(cloneFolderPath);
458
- }
459
- else if (index_1.Helpers.exists(cloneFolderPath) && index_1.Helpers.exists(tnp_core_1.path.join(cloneFolderPath, '.git'))) {
460
- index_1.Helpers.warn("Alread cloned ".concat(tnp_core_1.path.basename(cloneFolderPath), "..."));
461
- return;
462
- }
463
- var commnad = url.startsWith("https://")
464
- ? "git -c http.sslVerify=false clone ".concat(url, " ").concat(tnp_core_1.path.basename(cloneFolderPath))
465
- : "git clone ".concat(url, " ").concat(tnp_core_1.path.basename(cloneFolderPath));
466
- index_1.Helpers.info("\n\n Cloning:\n ".concat(commnad, "\n\n "));
467
- if (throwErrors) {
468
- index_1.Helpers.run(commnad, { cwd: cwd }).sync();
469
- }
470
- else {
471
- try {
472
- index_1.Helpers.run(commnad, { cwd: cwd, output: false }).sync();
473
- }
474
- catch (error) {
475
- if (((_c = (_b = error === null || error === void 0 ? void 0 : error.stderr) === null || _b === void 0 ? void 0 : _b.toString()) === null || _c === void 0 ? void 0 : _c.search('remote: Not Found')) !== -1) {
476
- index_1.Helpers.warn("[tnp-helpers][git] Project not found :".concat(url));
477
- }
478
- else {
479
- index_1.Helpers.error("Can't clone from url: ".concat(tnp_cli_1.CLI.chalk.bold(url), ".."), false, true);
480
- }
481
- }
482
- }
483
- var packageJson = tnp_core_1.path.join(cloneFolderPath, tnp_config_1.config.file.package_json);
484
- // Helpers.info(packageJson)
485
- if (!index_1.Helpers.exists(packageJson)) {
486
- index_1.Helpers.info("Recreating unexited package.json for project ".concat(tnp_core_1.path.basename(cloneFolderPath), ".."));
487
- try {
488
- index_1.Helpers.run("npm init -y", { cwd: cloneFolderPath, output: false }).sync();
489
- }
490
- catch (error) { }
491
- }
492
- };
493
- //#endregion
494
- //#region check if there are some uncommited changes
495
- HelpersGit.prototype.checkIfthereAreSomeUncommitedChange = function (cwd) {
496
- return index_1.Helpers.git.thereAreSomeUncommitedChangeExcept([], cwd);
497
- };
498
- //#endregion
499
- HelpersGit.prototype.thereAreSomeUncommitedChangeExcept = function (filesList, cwd) {
500
- if (filesList === void 0) { filesList = []; }
501
- filesList = filesList.map(function (f) { return (0, tnp_core_1.crossPlatformPath)(f); });
502
- try {
503
- var res = index_1.Helpers.run("git ls-files --deleted --modified --others --exclude-standard", { output: false, cwd: cwd }).sync().toString().trim();
504
- var list = !res ? [] : res
505
- .split(/\r\n|\n|\r/)
506
- .filter(function (f) {
507
- f = f === null || f === void 0 ? void 0 : f.trim();
508
- return !!f && !filesList.includes((0, tnp_core_1.crossPlatformPath)(f));
509
- });
510
- return list.length > 0;
511
- }
512
- catch (error) {
513
- return false;
514
- }
515
- };
516
- //#region restore last version
517
- HelpersGit.prototype.restoreLastVersion = function (cwd, localFilePath) {
518
- try {
519
- index_1.Helpers.info("[git] restoring last verion of file ".concat(tnp_core_1.path.basename(cwd), "/").concat(localFilePath));
520
- index_1.Helpers.run("git checkout -- ".concat(localFilePath), { cwd: cwd }).sync();
521
- }
522
- catch (error) {
523
- index_1.Helpers.warn("[tnp-git] Not able to resotre last version of file ".concat(localFilePath));
524
- }
525
- };
526
- //#endregion
527
- //#region reset files
528
- HelpersGit.prototype.resetFiles = function (cwd) {
529
- var relativePathes = [];
530
- for (var _i = 1; _i < arguments.length; _i++) {
531
- relativePathes[_i - 1] = arguments[_i];
532
- }
533
- relativePathes.forEach(function (p) {
534
- try {
535
- index_1.Helpers.run("git checkout HEAD -- ".concat(p), { cwd: cwd }).sync();
536
- }
537
- catch (err) {
538
- index_1.Helpers.error("[project.git] Not able to reset files: ".concat(p, " inside project ").concat(tnp_core_1.path.basename(cwd), "."), true, true);
539
- }
540
- });
541
- };
542
- return HelpersGit;
543
- }());
544
- exports.HelpersGit = HelpersGit;
545
- //# sourceMappingURL=C:/Users/darek/projects/npm/tnp-helpers/tmp-bundle-release/bundle/project/tnp-helpers/bundle-nocutsrc/lib/helpers-git.backend.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HelpersGit = void 0;
4
+ var tslib_1 = require("tslib");
5
+ //#region imports
6
+ var tnp_core_1 = require("tnp-core");
7
+ var tnp_cli_1 = require("tnp-cli");
8
+ var index_1 = require("./index");
9
+ var tnp_config_1 = require("tnp-config");
10
+ //#endregion
11
+ var HelpersGit = /** @class */ (function () {
12
+ function HelpersGit() {
13
+ }
14
+ //#region get last commit hash
15
+ HelpersGit.prototype.lastCommitHash = function (directoryPath) {
16
+ try {
17
+ var cwd = directoryPath;
18
+ var hash = this.isGitRepo(cwd) && tnp_core_1.child_process.execSync("git log -1 --format=\"%H\"", { cwd: cwd }).toString().trim();
19
+ return hash;
20
+ }
21
+ catch (e) {
22
+ index_1.Helpers.log(e, 1);
23
+ index_1.Helpers.log("[lastCommitHash] Not able to get last commit hash for repository in ".concat(directoryPath), 1);
24
+ return null;
25
+ }
26
+ };
27
+ //#endregion
28
+ //#region get penultimate commit hash
29
+ HelpersGit.prototype.penultimageCommitHash = function (directoryPath) {
30
+ try {
31
+ var cwd = directoryPath;
32
+ var hash = this.isGitRepo(cwd) && tnp_core_1.child_process.execSync("git log -2 --format=\"%H\"", { cwd: cwd }).toString().trim();
33
+ return hash;
34
+ }
35
+ catch (e) {
36
+ index_1.Helpers.log(e, 1);
37
+ index_1.Helpers.log("[lastCommitHash] Not able to get last commit hash for repository in ".concat(directoryPath), 1);
38
+ return null;
39
+ }
40
+ };
41
+ //#endregion
42
+ //#region check tag exists
43
+ HelpersGit.prototype.checkTagExists = function (tag, cwd) {
44
+ if (cwd === void 0) { cwd = process.cwd(); }
45
+ var command = "git show-ref --tags ".concat(tag).trim();
46
+ var result = (index_1.Helpers.commnadOutputAsString(command, cwd) || '') !== '';
47
+ return result;
48
+ };
49
+ //#endregion
50
+ HelpersGit.prototype.lastTagVersionName = function (directoryPath) {
51
+ try {
52
+ var cwd = directoryPath;
53
+ var command = "git describe --tags $(git rev-list --tags --max-count=1)";
54
+ if (process.platform === 'win32') {
55
+ command = 'git describe --tags --abbrev=0';
56
+ }
57
+ var tag = index_1.Helpers.commnadOutputAsString(command, cwd);
58
+ if (!tag) {
59
+ return void 0;
60
+ }
61
+ return tag;
62
+ }
63
+ catch (e) {
64
+ index_1.Helpers.warn("[lastCommitHash] Not able to get last commit version name for repository in ".concat(directoryPath), false);
65
+ return void 0;
66
+ }
67
+ };
68
+ //#region get last tag hash
69
+ HelpersGit.prototype.lastTagHash = function (directoryPath) {
70
+ try {
71
+ var cwd = directoryPath;
72
+ var tag = index_1.Helpers.git.lastTagVersionName(cwd);
73
+ if (!tag) {
74
+ return null;
75
+ }
76
+ var hash = tnp_core_1.child_process.execSync("git log -1 --format=format:\"%H\" ".concat(tag), { cwd: cwd }).toString().trim();
77
+ return hash;
78
+ }
79
+ catch (e) {
80
+ index_1.Helpers.log(e, 1);
81
+ index_1.Helpers.log("[lastCommitHash] Not able to get last commit hash for repository in ".concat(directoryPath), 1);
82
+ return null;
83
+ }
84
+ };
85
+ //#endregion
86
+ //#region get last commit date
87
+ HelpersGit.prototype.lastCommitDate = function (cwd) {
88
+ try {
89
+ var unixTimestamp = this.isGitRepo(cwd)
90
+ && tnp_core_1.child_process
91
+ .execSync("git log -1 --pretty=format:%ct", { cwd: cwd })
92
+ .toString()
93
+ .trim();
94
+ return new Date(Number(unixTimestamp) * 1000);
95
+ }
96
+ catch (e) {
97
+ index_1.Helpers.log(e, 1);
98
+ index_1.Helpers.log("[lastCommitDate] Cannot counts commits in branch in: ".concat(cwd), 1);
99
+ return null;
100
+ }
101
+ };
102
+ //#endregion
103
+ //#region get last commit date
104
+ HelpersGit.prototype.lastCommitMessage = function (directoryPath) {
105
+ try {
106
+ var cwd = directoryPath;
107
+ var unixTimestamp = tnp_core_1.child_process.execSync("git log -1 --pretty=%B", { cwd: cwd }).toString().trim();
108
+ return unixTimestamp;
109
+ }
110
+ catch (e) {
111
+ index_1.Helpers.log(e, 1);
112
+ index_1.Helpers.log("[lastCommitMessage] Cannot display last commit message in branch in: ".concat(directoryPath), 1);
113
+ return null;
114
+ }
115
+ };
116
+ //#endregion
117
+ //#region get number of commit in repository
118
+ HelpersGit.prototype.countCommits = function (cwd) {
119
+ try {
120
+ // git rev-parse HEAD &> /dev/null check if any commits
121
+ var currentLocalBranch = this.currentBranchName(cwd);
122
+ var value = this.isGitRepo(cwd) && tnp_core_1.child_process
123
+ .execSync("git rev-list --count ".concat(currentLocalBranch), { cwd: cwd })
124
+ .toString()
125
+ .trim();
126
+ return Number(value);
127
+ }
128
+ catch (e) {
129
+ index_1.Helpers.log(e, 1);
130
+ index_1.Helpers.log("[countCommits] Cannot counts commits in branch in: ".concat(cwd), 1);
131
+ return 0;
132
+ }
133
+ };
134
+ //#endregion
135
+ //#region get branches names
136
+ HelpersGit.prototype.getBranchesNames = function (cwd, pattern) {
137
+ try {
138
+ var branchPattern_1 = pattern;
139
+ if (tnp_core_1._.isString(pattern)) {
140
+ branchPattern_1 = new RegExp(pattern.replace(/[^a-zA-Z0-9]+/g, '.*'));
141
+ }
142
+ var command = "git branch -a";
143
+ // console.log({ command, cwd })
144
+ var branchNames = index_1.Helpers.commnadOutputAsString(command, cwd, true, true);
145
+ // console.log({ branchNames })
146
+ var _branchNames = branchNames
147
+ .toString()
148
+ .trim()
149
+ .split('\n')
150
+ .map(function (l) { return l.replace('*', '').trim(); })
151
+ .filter(function (l) {
152
+ // console.log('testing: ' + l)
153
+ if (tnp_core_1._.isRegExp(branchPattern_1)) {
154
+ var match = branchPattern_1.test(l);
155
+ return match;
156
+ }
157
+ // if (_.isString(pattern)) {
158
+ // return l.search(pattern)
159
+ // }
160
+ return true;
161
+ });
162
+ return _branchNames;
163
+ }
164
+ catch (e) {
165
+ index_1.Helpers.log(e);
166
+ return [];
167
+ }
168
+ };
169
+ //#endregion
170
+ //#region get current branch name
171
+ HelpersGit.prototype.currentBranchName = function (cwd) {
172
+ try {
173
+ var branchName = tnp_core_1.child_process.execSync("git branch | sed -n '/* /s///p'", { cwd: cwd }).toString().trim();
174
+ return branchName;
175
+ }
176
+ catch (e) {
177
+ index_1.Helpers.error(e);
178
+ }
179
+ };
180
+ //#endregion
181
+ //#region commit "what is"
182
+ HelpersGit.prototype.commitWhatIs = function (customMessage) {
183
+ if (customMessage === void 0) { customMessage = 'changes'; }
184
+ try {
185
+ index_1.Helpers.run("git add --all . ").sync();
186
+ }
187
+ catch (error) {
188
+ index_1.Helpers.warn("Failed to git add --all .");
189
+ }
190
+ try {
191
+ index_1.Helpers.run("git commit -m \"".concat(customMessage, "\"")).sync();
192
+ }
193
+ catch (error) {
194
+ index_1.Helpers.warn("Failed to git commit -m \"".concat(customMessage, "\""));
195
+ }
196
+ };
197
+ //#endregion
198
+ //#region commit
199
+ HelpersGit.prototype.commit = function (cwd, ProjectClass, args) {
200
+ if (!tnp_core_1._.isString(args)) {
201
+ args = 'update';
202
+ }
203
+ var gitRootProject = ProjectClass.nearestTo(cwd, { findGitRoot: true });
204
+ try {
205
+ index_1.Helpers.info("[git][commit] Adding current git changes in git root:\n ".concat(gitRootProject.location, "\n "));
206
+ gitRootProject.run("git add --all . ").sync();
207
+ }
208
+ catch (error) {
209
+ index_1.Helpers.log(error);
210
+ index_1.Helpers.warn("Failed to 'git add --all .' in:\n ".concat(gitRootProject.location));
211
+ }
212
+ if (args.search('-m') === -1 && args.search('-msg') === -1) {
213
+ var addBrackets = !((args.startsWith('\'') ||
214
+ args.startsWith('"')) &&
215
+ (args.endsWith('\'') ||
216
+ args.endsWith('"')));
217
+ args = "-m ".concat(addBrackets ? "\"".concat(args, "\"") : args);
218
+ }
219
+ try {
220
+ index_1.Helpers.info("[git][commit] trying to commit what it with argument:\n \"".concat(args, "\"\n location: ").concat(cwd, "\n "));
221
+ var cmdddd = "git commit --no-verify ".concat(args);
222
+ index_1.Helpers.run(cmdddd, { cwd: cwd }).sync();
223
+ }
224
+ catch (error) {
225
+ index_1.Helpers.log(error);
226
+ index_1.Helpers.warn("[git][commit] not able to commit what is with command: ".concat(cmdddd));
227
+ }
228
+ };
229
+ //#endregion
230
+ //#region get remote origin
231
+ HelpersGit.prototype.getOriginURL = function (cwd, differentOriginName) {
232
+ if (differentOriginName === void 0) { differentOriginName = ''; }
233
+ var url = '';
234
+ try {
235
+ // git config --get remote.origin.url
236
+ url = index_1.Helpers.run("git config --get remote.".concat(differentOriginName ? differentOriginName : 'origin', ".url"), { output: false, cwd: cwd }).sync().toString().trim();
237
+ }
238
+ catch (error) {
239
+ return '< not able to get origin >';
240
+ }
241
+ return url;
242
+ };
243
+ //#endregion
244
+ //#region is git root
245
+ HelpersGit.prototype.isGitRoot = function (cwd) {
246
+ return this.isGitRepo(cwd) && tnp_core_1.fse.existsSync(tnp_core_1.path.join(cwd, '.git'));
247
+ };
248
+ //#endregion
249
+ //#region is git repo
250
+ HelpersGit.prototype.isGitRepo = function (cwd) {
251
+ // if(this.isGitRoot(cwd)) {
252
+ // return true;
253
+ // }
254
+ try {
255
+ var test = index_1.Helpers.run('git rev-parse --is-inside-work-tree', {
256
+ biggerBuffer: false,
257
+ cwd: cwd,
258
+ output: false
259
+ }).sync();
260
+ }
261
+ catch (e) {
262
+ return false;
263
+ }
264
+ return !!test;
265
+ };
266
+ //#endregion
267
+ HelpersGit.prototype.pull = function (branchName, cwd) {
268
+ if (branchName === void 0) { branchName = 'master'; }
269
+ if (cwd === void 0) { cwd = (0, tnp_core_1.crossPlatformPath)(process.cwd()); }
270
+ tnp_core_1.child_process.execSync("git pull --tags --rebase origin ".concat(branchName), { cwd: cwd });
271
+ };
272
+ //#region pull current branch
273
+ HelpersGit.prototype.pullBranch = function (branchName, directoryPath, askToRetry) {
274
+ if (askToRetry === void 0) { askToRetry = false; }
275
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
276
+ var cwd, e_1;
277
+ var _this = this;
278
+ return tslib_1.__generator(this, function (_a) {
279
+ switch (_a.label) {
280
+ case 0:
281
+ if (this.getOriginURL(directoryPath) === '') {
282
+ index_1.Helpers.warn("Not pulling branch without "
283
+ + "remote origin url.... in folder ".concat(tnp_core_1.path.basename(directoryPath)));
284
+ return [2 /*return*/];
285
+ }
286
+ index_1.Helpers.info("Pulling git changes in \"".concat(directoryPath, "\" , origin=").concat(index_1.Helpers.git.getOriginURL(directoryPath), " "));
287
+ _a.label = 1;
288
+ case 1:
289
+ _a.trys.push([1, 2, , 5]);
290
+ cwd = directoryPath;
291
+ index_1.Helpers.git.pull(branchName, cwd);
292
+ index_1.Helpers.info("Branch \"".concat(branchName, "\" updated successfully in ").concat(tnp_core_1.path.basename(directoryPath)));
293
+ return [3 /*break*/, 5];
294
+ case 2:
295
+ e_1 = _a.sent();
296
+ // console.log(e)
297
+ index_1.Helpers.error("Cannot update current branch in: ".concat(directoryPath), askToRetry, true);
298
+ if (!askToRetry) return [3 /*break*/, 4];
299
+ return [4 /*yield*/, index_1.Helpers.questionYesNo("Do you wanna try again ?", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
300
+ return tslib_1.__generator(this, function (_a) {
301
+ switch (_a.label) {
302
+ case 0: return [4 /*yield*/, index_1.Helpers.git.pullCurrentBranch(directoryPath, askToRetry)];
303
+ case 1:
304
+ _a.sent();
305
+ return [2 /*return*/];
306
+ }
307
+ });
308
+ }); }, function () {
309
+ process.exit(0);
310
+ })];
311
+ case 3:
312
+ _a.sent();
313
+ _a.label = 4;
314
+ case 4: return [3 /*break*/, 5];
315
+ case 5: return [2 /*return*/];
316
+ }
317
+ });
318
+ });
319
+ };
320
+ //#endregion
321
+ //#region pull current branch
322
+ HelpersGit.prototype.pullCurrentBranch = function (directoryPath, askToRetry) {
323
+ if (askToRetry === void 0) { askToRetry = true; }
324
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
325
+ var cwd, currentLocalBranch, e_2;
326
+ var _this = this;
327
+ return tslib_1.__generator(this, function (_a) {
328
+ switch (_a.label) {
329
+ case 0:
330
+ if (global['tnpNonInteractive']) {
331
+ askToRetry = false;
332
+ }
333
+ index_1.Helpers.log("askToRetry: ".concat(askToRetry));
334
+ if (this.getOriginURL(directoryPath) === '') {
335
+ index_1.Helpers.warn("Not pulling branch without "
336
+ + "remote origin url.... in folder ".concat(tnp_core_1.path.basename(directoryPath)));
337
+ return [2 /*return*/];
338
+ }
339
+ index_1.Helpers.info("Pulling git changes in \"".concat(directoryPath, "\", origin=").concat(index_1.Helpers.git.getOriginURL(directoryPath), " "));
340
+ _a.label = 1;
341
+ case 1:
342
+ _a.trys.push([1, 2, , 5]);
343
+ cwd = directoryPath;
344
+ currentLocalBranch = tnp_core_1.child_process.execSync("git branch | sed -n '/* /s///p'", { cwd: cwd }).toString().trim();
345
+ index_1.Helpers.git.pull(currentLocalBranch, cwd);
346
+ index_1.Helpers.info("Branch \"".concat(currentLocalBranch, "\" updated successfully in ").concat(tnp_core_1.path.basename(directoryPath)));
347
+ return [3 /*break*/, 5];
348
+ case 2:
349
+ e_2 = _a.sent();
350
+ console.log(e_2);
351
+ index_1.Helpers.error("Cannot update current branch in: ".concat(directoryPath), askToRetry, true);
352
+ if (!askToRetry) return [3 /*break*/, 4];
353
+ return [4 /*yield*/, index_1.Helpers.questionYesNo("Do you wanna try again ?", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
354
+ return tslib_1.__generator(this, function (_a) {
355
+ switch (_a.label) {
356
+ case 0: return [4 /*yield*/, index_1.Helpers.git.pullCurrentBranch(directoryPath, askToRetry)];
357
+ case 1:
358
+ _a.sent();
359
+ return [2 /*return*/];
360
+ }
361
+ });
362
+ }); }, function () {
363
+ process.exit(1);
364
+ })];
365
+ case 3:
366
+ _a.sent();
367
+ _a.label = 4;
368
+ case 4: return [3 /*break*/, 5];
369
+ case 5:
370
+ index_1.Helpers.info("DONE PULLING");
371
+ return [2 /*return*/];
372
+ }
373
+ });
374
+ });
375
+ };
376
+ //#endregion
377
+ //#region push current branch
378
+ HelpersGit.prototype.pushCurrentBranch = function (cwd, force, origin) {
379
+ if (force === void 0) { force = false; }
380
+ if (origin === void 0) { origin = 'origin'; }
381
+ var currentBranchName = index_1.Helpers.git.currentBranchName(cwd);
382
+ var taskName = "\n Pushing current branch (remote=".concat(origin, "): ").concat(currentBranchName, "\n ");
383
+ index_1.Helpers.info(taskName);
384
+ while (true) {
385
+ try {
386
+ var command = "git push ".concat(force ? '-f' : '', " ").concat(origin, " ").concat(currentBranchName, " --tags");
387
+ index_1.Helpers.info("[git][push] ".concat(force ? 'force' : '', " pushing current branch ").concat(currentBranchName, " ,")
388
+ + " origin=".concat(index_1.Helpers.git.getOriginURL(cwd, origin)));
389
+ index_1.Helpers.run(command, { cwd: cwd }).sync();
390
+ index_1.Helpers.info(taskName);
391
+ break;
392
+ }
393
+ catch (err) {
394
+ index_1.Helpers.error("[tnp-helpers] Not able to push branch ".concat(currentBranchName, " in (origin=").concat(origin, "):\n ").concat(cwd), true, true);
395
+ index_1.Helpers.pressKeyAndContinue("Press any key to try again: ");
396
+ // TODO issue 1: issue with press any key
397
+ // TODO issue 2: Updates were rejected because the tag already exists in the remote
398
+ continue;
399
+ }
400
+ }
401
+ };
402
+ //#endregion
403
+ //#region get default branch for repo
404
+ HelpersGit.prototype.defaultRepoBranch = function (cwd) {
405
+ try {
406
+ var defaultBranch = tnp_core_1.child_process
407
+ .execSync("git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'", { cwd: cwd })
408
+ .toString().trim();
409
+ return defaultBranch;
410
+ }
411
+ catch (e) {
412
+ index_1.Helpers.log(e);
413
+ index_1.Helpers.error("Cannot find default branch for repo in : ".concat(cwd));
414
+ }
415
+ };
416
+ //#endregion
417
+ //#region checkout default branch
418
+ HelpersGit.prototype.checkoutDefaultBranch = function (directoryPath) {
419
+ var cwd = directoryPath;
420
+ var defaultBranch = tnp_core_1.child_process
421
+ .execSync("git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'", { cwd: cwd })
422
+ .toString().trim();
423
+ tnp_core_1.child_process.execSync("git checkout ".concat(defaultBranch), { cwd: cwd });
424
+ };
425
+ //#endregion
426
+ //#region clone
427
+ HelpersGit.prototype.clone = function (_a) {
428
+ // const ALWAYS_HTTPS = true;
429
+ var _b, _c;
430
+ var cwd = _a.cwd, url = _a.url, _d = _a.destinationFolderName, destinationFolderName = _d === void 0 ? '' : _d, throwErrors = _a.throwErrors, override = _a.override;
431
+ if (url.split(' ').length > 2) {
432
+ // const [rUrl, rDest] = url.split(' ');
433
+ index_1.Helpers.error("[tnp-helpers]incorrect clone url \"".concat(url, "\""));
434
+ }
435
+ if (url.split(' ').length === 2) {
436
+ var _e = tslib_1.__read(url.split(' '), 2), rUrl = _e[0], rDest = _e[1];
437
+ if (destinationFolderName) {
438
+ index_1.Helpers.error("[tnp-helpers] wrong cloning argument\n\n url = \"".concat(url, "\"\n destinationFolderName = \"").concat(destinationFolderName, "\"\n\n cant use both at the same time\n "));
439
+ }
440
+ else {
441
+ destinationFolderName = rDest;
442
+ url = rUrl;
443
+ }
444
+ }
445
+ if (!url.endsWith('.git')) {
446
+ url = (url + '.git');
447
+ }
448
+ var cloneFolderPath = tnp_core_1.path.join(cwd, (!!destinationFolderName && destinationFolderName.trim() !== '')
449
+ ? destinationFolderName
450
+ : tnp_core_1.path.basename(url)).trim().replace('.git', '');
451
+ // console.log({ cloneFolderPath })
452
+ if (override) {
453
+ index_1.Helpers.remove(cloneFolderPath);
454
+ }
455
+ else if (index_1.Helpers.exists(cloneFolderPath) && index_1.Helpers.exists(tnp_core_1.path.join(cloneFolderPath, '.git'))) {
456
+ index_1.Helpers.warn("Alread cloned ".concat(tnp_core_1.path.basename(cloneFolderPath), "..."));
457
+ return;
458
+ }
459
+ var commnad = url.startsWith("https://")
460
+ ? "git -c http.sslVerify=false clone ".concat(url, " ").concat(tnp_core_1.path.basename(cloneFolderPath))
461
+ : "git clone ".concat(url, " ").concat(tnp_core_1.path.basename(cloneFolderPath));
462
+ index_1.Helpers.info("\n\n Cloning:\n ".concat(commnad, "\n\n "));
463
+ if (throwErrors) {
464
+ index_1.Helpers.run(commnad, { cwd: cwd }).sync();
465
+ }
466
+ else {
467
+ try {
468
+ index_1.Helpers.run(commnad, { cwd: cwd, output: false }).sync();
469
+ }
470
+ catch (error) {
471
+ if (((_c = (_b = error === null || error === void 0 ? void 0 : error.stderr) === null || _b === void 0 ? void 0 : _b.toString()) === null || _c === void 0 ? void 0 : _c.search('remote: Not Found')) !== -1) {
472
+ index_1.Helpers.warn("[tnp-helpers][git] Project not found :".concat(url));
473
+ }
474
+ else {
475
+ index_1.Helpers.error("Can't clone from url: ".concat(tnp_cli_1.CLI.chalk.bold(url), ".."), false, true);
476
+ }
477
+ }
478
+ }
479
+ var packageJson = tnp_core_1.path.join(cloneFolderPath, tnp_config_1.config.file.package_json);
480
+ // Helpers.info(packageJson)
481
+ if (!index_1.Helpers.exists(packageJson)) {
482
+ index_1.Helpers.info("Recreating unexited package.json for project ".concat(tnp_core_1.path.basename(cloneFolderPath), ".."));
483
+ try {
484
+ index_1.Helpers.run("npm init -y", { cwd: cloneFolderPath, output: false }).sync();
485
+ }
486
+ catch (error) { }
487
+ }
488
+ };
489
+ //#endregion
490
+ //#region check if there are some uncommited changes
491
+ HelpersGit.prototype.checkIfthereAreSomeUncommitedChange = function (cwd) {
492
+ return index_1.Helpers.git.thereAreSomeUncommitedChangeExcept([], cwd);
493
+ };
494
+ //#endregion
495
+ HelpersGit.prototype.thereAreSomeUncommitedChangeExcept = function (filesList, cwd) {
496
+ if (filesList === void 0) { filesList = []; }
497
+ filesList = filesList.map(function (f) { return (0, tnp_core_1.crossPlatformPath)(f); });
498
+ try {
499
+ var res = index_1.Helpers.run("git ls-files --deleted --modified --others --exclude-standard", { output: false, cwd: cwd }).sync().toString().trim();
500
+ var list = !res ? [] : res
501
+ .split(/\r\n|\n|\r/)
502
+ .filter(function (f) {
503
+ f = f === null || f === void 0 ? void 0 : f.trim();
504
+ return !!f && !filesList.includes((0, tnp_core_1.crossPlatformPath)(f));
505
+ });
506
+ return list.length > 0;
507
+ }
508
+ catch (error) {
509
+ return false;
510
+ }
511
+ };
512
+ //#region restore last version
513
+ HelpersGit.prototype.restoreLastVersion = function (cwd, localFilePath) {
514
+ try {
515
+ index_1.Helpers.info("[git] restoring last verion of file ".concat(tnp_core_1.path.basename(cwd), "/").concat(localFilePath));
516
+ index_1.Helpers.run("git checkout -- ".concat(localFilePath), { cwd: cwd }).sync();
517
+ }
518
+ catch (error) {
519
+ index_1.Helpers.warn("[tnp-git] Not able to resotre last version of file ".concat(localFilePath));
520
+ }
521
+ };
522
+ //#endregion
523
+ //#region reset files
524
+ HelpersGit.prototype.resetFiles = function (cwd) {
525
+ var relativePathes = [];
526
+ for (var _i = 1; _i < arguments.length; _i++) {
527
+ relativePathes[_i - 1] = arguments[_i];
528
+ }
529
+ relativePathes.forEach(function (p) {
530
+ try {
531
+ index_1.Helpers.run("git checkout HEAD -- ".concat(p), { cwd: cwd }).sync();
532
+ }
533
+ catch (err) {
534
+ index_1.Helpers.error("[project.git] Not able to reset files: ".concat(p, " inside project ").concat(tnp_core_1.path.basename(cwd), "."), true, true);
535
+ }
536
+ });
537
+ };
538
+ return HelpersGit;
539
+ }());
540
+ exports.HelpersGit = HelpersGit;
541
+ //# sourceMappingURL=/Users/dariusz/projects/npm/tnp-helpers/tmp-bundle-release/bundle/project/tnp-helpers/bundle-nocutsrc/lib/helpers-git.backend.js.map