tnp-helpers 13.0.37 → 13.1.1

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