tnp-helpers 19.0.65 → 19.0.67

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 (211) hide show
  1. package/browser/README.md +24 -24
  2. package/browser/fesm2022/tnp-helpers.mjs +3459 -320
  3. package/browser/fesm2022/tnp-helpers.mjs.map +1 -1
  4. package/browser/lib/base/classes/base-cli-worker/base-cli-worker-config.d.ts +4 -0
  5. package/browser/lib/base/classes/base-cli-worker/base-cli-worker-controller.d.ts +3 -4
  6. package/browser/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +4 -3
  7. package/browser/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +86 -35
  8. package/browser/lib/base/classes/base-cli-worker/base-cli-worker.models.d.ts +45 -0
  9. package/browser/lib/base/classes/base-cli-worker/base-cli-worker.utils.d.ts +6 -0
  10. package/browser/lib/base/classes/base-cli-worker/index.d.ts +3 -1
  11. package/browser/lib/base/classes/base-docker.d.ts +4 -7
  12. package/browser/lib/base/classes/base-git.d.ts +2 -0
  13. package/browser/lib/base/classes/base-global-command-line.d.ts +265 -0
  14. package/browser/lib/base/classes/base-node-modules.d.ts +1 -0
  15. package/browser/lib/base/classes/base-npm-helpers.d.ts +1 -0
  16. package/browser/lib/base/classes/base-release-process.d.ts +3 -1
  17. package/browser/lib/base/classes/base-vscode.d.ts +1 -1
  18. package/browser/lib/base/classes/index.d.ts +2 -1
  19. package/browser/lib/base/gh-temp-code.d.ts +17 -0
  20. package/browser/lib/build-info._auto-generated_.d.ts +1 -1
  21. package/browser/lib/helpers/helpers.d.ts +0 -5
  22. package/browser/lib/utils.d.ts +24 -35
  23. package/browser/package.json +1 -1
  24. package/lib/base/classes/base-cli-worker/base-cli-worker-config.d.ts +4 -0
  25. package/lib/base/classes/base-cli-worker/base-cli-worker-config.js +4 -0
  26. package/lib/base/classes/base-cli-worker/base-cli-worker-config.js.map +1 -1
  27. package/lib/base/classes/base-cli-worker/base-cli-worker-controller.d.ts +3 -4
  28. package/lib/base/classes/base-cli-worker/base-cli-worker-controller.js +28 -15
  29. package/lib/base/classes/base-cli-worker/base-cli-worker-controller.js.map +1 -1
  30. package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +4 -3
  31. package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js +28 -9
  32. package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js.map +1 -1
  33. package/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +84 -33
  34. package/lib/base/classes/base-cli-worker/base-cli-worker.js +375 -209
  35. package/lib/base/classes/base-cli-worker/base-cli-worker.js.map +1 -1
  36. package/lib/base/classes/base-cli-worker/base-cli-worker.models.d.ts +44 -0
  37. package/lib/base/classes/base-cli-worker/base-cli-worker.models.js +35 -0
  38. package/lib/base/classes/base-cli-worker/base-cli-worker.models.js.map +1 -0
  39. package/lib/base/classes/base-cli-worker/base-cli-worker.utils.d.ts +5 -0
  40. package/lib/base/classes/base-cli-worker/base-cli-worker.utils.js +30 -0
  41. package/lib/base/classes/base-cli-worker/base-cli-worker.utils.js.map +1 -0
  42. package/lib/base/classes/base-cli-worker/index.d.ts +2 -0
  43. package/lib/base/classes/base-cli-worker/index.js +2 -0
  44. package/lib/base/classes/base-cli-worker/index.js.map +1 -1
  45. package/lib/base/classes/base-command-line-feature.backend.d.ts +47 -0
  46. package/lib/base/classes/base-command-line-feature.backend.js +147 -0
  47. package/lib/base/classes/base-command-line-feature.backend.js.map +1 -0
  48. package/lib/base/classes/base-docker.d.ts +4 -7
  49. package/lib/base/classes/base-docker.js +12 -18
  50. package/lib/base/classes/base-docker.js.map +1 -1
  51. package/lib/base/classes/base-git.d.ts +2 -0
  52. package/lib/base/classes/base-git.js +29 -9
  53. package/lib/base/classes/base-git.js.map +1 -1
  54. package/lib/base/classes/base-global-command-line.backend.d.ts +14 -1
  55. package/lib/base/classes/base-global-command-line.backend.js +463 -65
  56. package/lib/base/classes/base-global-command-line.backend.js.map +1 -1
  57. package/lib/base/classes/base-global-command-line.d.ts +271 -0
  58. package/lib/base/classes/base-global-command-line.js +2484 -0
  59. package/lib/base/classes/base-global-command-line.js.map +1 -0
  60. package/lib/base/classes/base-ignore-hide.js +4 -0
  61. package/lib/base/classes/base-ignore-hide.js.map +1 -1
  62. package/lib/base/classes/base-node-modules.d.ts +1 -0
  63. package/lib/base/classes/base-node-modules.js +22 -1
  64. package/lib/base/classes/base-node-modules.js.map +1 -1
  65. package/lib/base/classes/base-npm-helpers.d.ts +1 -0
  66. package/lib/base/classes/base-npm-helpers.js +2 -2
  67. package/lib/base/classes/base-npm-helpers.js.map +1 -1
  68. package/lib/base/classes/base-powershell.d.ts +1 -0
  69. package/lib/base/classes/base-powershell.js +13 -0
  70. package/lib/base/classes/base-powershell.js.map +1 -1
  71. package/lib/base/classes/base-process/base-process-api.service.d.ts +7 -0
  72. package/lib/base/classes/base-process/base-process.context.d.ts +19 -0
  73. package/lib/base/classes/base-process/base-process.context.js +22 -0
  74. package/lib/base/classes/base-process/base-process.context.js.map +1 -0
  75. package/lib/base/classes/base-process/base-process.controller.d.ts +17 -0
  76. package/lib/base/classes/base-process/base-process.controller.js +91 -0
  77. package/lib/base/classes/base-process/base-process.controller.js.map +1 -0
  78. package/lib/base/classes/base-process/base-process.d.ts +8 -0
  79. package/lib/base/classes/base-process/base-process.defaults-values.d.ts +2 -0
  80. package/lib/base/classes/base-process/base-process.defaults-values.js +9 -0
  81. package/lib/base/classes/base-process/base-process.defaults-values.js.map +1 -0
  82. package/lib/base/classes/base-process/base-process.js +62 -0
  83. package/lib/base/classes/base-process/base-process.js.map +1 -0
  84. package/lib/base/classes/base-process/base-process.models.d.ts +6 -0
  85. package/lib/base/classes/base-process/base-process.models.js +3 -0
  86. package/lib/base/classes/base-process/base-process.models.js.map +1 -0
  87. package/lib/base/classes/base-process/base-process.provider.d.ts +16 -0
  88. package/lib/base/classes/base-process/base-process.provider.js +69 -0
  89. package/lib/base/classes/base-process/base-process.provider.js.map +1 -0
  90. package/lib/base/classes/base-process/base-process.repository copy.d.ts +8 -0
  91. package/lib/base/classes/base-process/base-process.repository copy.js +32 -0
  92. package/lib/base/classes/base-process/base-process.repository copy.js.map +1 -0
  93. package/lib/base/classes/base-process/base-process.repository.d.ts +8 -0
  94. package/lib/base/classes/base-process/base-process.repository.js +32 -0
  95. package/lib/base/classes/base-process/base-process.repository.js.map +1 -0
  96. package/lib/base/classes/base-process/base-process.terminal-ui.d.ts +11 -0
  97. package/lib/base/classes/base-process/base-process.terminal-ui.js +54 -0
  98. package/lib/base/classes/base-process/base-process.terminal-ui.js.map +1 -0
  99. package/lib/base/classes/base-process/base-process.worker.d.ts +16 -0
  100. package/lib/base/classes/base-process/base-process.worker.js +29 -0
  101. package/lib/base/classes/base-process/base-process.worker.js.map +1 -0
  102. package/lib/base/classes/base-process/index.d.ts +1 -0
  103. package/lib/base/classes/base-process/index.js +22 -0
  104. package/lib/base/classes/base-process/index.js.map +1 -0
  105. package/lib/base/classes/base-process/processes.repository.d.ts +0 -0
  106. package/lib/base/classes/base-process/processes.repository.js +5 -0
  107. package/lib/base/classes/base-process/processes.repository.js.map +1 -0
  108. package/lib/base/classes/base-project-resolver.js +2 -1
  109. package/lib/base/classes/base-project-resolver.js.map +1 -1
  110. package/lib/base/classes/base-project.d.ts +1 -1
  111. package/lib/base/classes/base-project.js +8 -6
  112. package/lib/base/classes/base-project.js.map +1 -1
  113. package/lib/base/classes/base-release-process.d.ts +3 -1
  114. package/lib/base/classes/base-release-process.js +4 -3
  115. package/lib/base/classes/base-release-process.js.map +1 -1
  116. package/lib/base/classes/base-vscode.d.ts +1 -1
  117. package/lib/base/classes/base-vscode.js +9 -1
  118. package/lib/base/classes/base-vscode.js.map +1 -1
  119. package/lib/base/classes/index.d.ts +1 -1
  120. package/lib/base/classes/index.js +2 -4
  121. package/lib/base/classes/index.js.map +1 -1
  122. package/lib/base/tcp-udp-ports/not-assignable-port.entity.js +2 -2
  123. package/lib/base/tcp-udp-ports/ports.entity.d.ts +1 -1
  124. package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js +27 -14
  125. package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js.map +1 -1
  126. package/lib/build-info._auto-generated_.d.ts +1 -1
  127. package/lib/build-info._auto-generated_.js +1 -1
  128. package/lib/env/env.angular-node-app.d.ts +1 -2
  129. package/lib/env/env.angular-node-app.js +3 -4
  130. package/lib/env/env.angular-node-app.js.map +1 -1
  131. package/lib/env/env.docs-webapp.d.ts +1 -2
  132. package/lib/env/env.docs-webapp.js +3 -4
  133. package/lib/env/env.docs-webapp.js.map +1 -1
  134. package/lib/env/env.electron-app.d.ts +1 -2
  135. package/lib/env/env.electron-app.js +3 -4
  136. package/lib/env/env.electron-app.js.map +1 -1
  137. package/lib/env/env.mobile-app.d.ts +1 -2
  138. package/lib/env/env.mobile-app.js +3 -4
  139. package/lib/env/env.mobile-app.js.map +1 -1
  140. package/lib/env/env.npm-lib-and-cli-tool.d.ts +1 -2
  141. package/lib/env/env.npm-lib-and-cli-tool.js +3 -4
  142. package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
  143. package/lib/env/env.vscode-plugin.d.ts +1 -2
  144. package/lib/env/env.vscode-plugin.js +3 -4
  145. package/lib/env/env.vscode-plugin.js.map +1 -1
  146. package/lib/env-backend._auto-generated_.d.ts +34 -0
  147. package/lib/env-backend._auto-generated_.js +38 -0
  148. package/lib/env-backend._auto-generated_.js.map +1 -0
  149. package/lib/env-browser._auto-generated_.d.ts +34 -0
  150. package/lib/env-browser._auto-generated_.js +38 -0
  151. package/lib/env-browser._auto-generated_.js.map +1 -0
  152. package/lib/env.backend.d.ts +34 -0
  153. package/lib/env.backend.js +40 -0
  154. package/lib/env.backend.js.map +1 -0
  155. package/lib/env.browser.d.ts +34 -0
  156. package/lib/helpers/for-backend/helpers-dependencies.backend.d.ts +2 -0
  157. package/lib/helpers/for-backend/helpers-dependencies.backend.js +7 -0
  158. package/lib/helpers/for-backend/helpers-dependencies.backend.js.map +1 -0
  159. package/lib/helpers/for-backend/helpers-file-folders.js +11 -3
  160. package/lib/helpers/for-backend/helpers-file-folders.js.map +1 -1
  161. package/lib/helpers/for-backend/helpers-git.backend.d.ts +1 -0
  162. package/lib/helpers/for-backend/helpers-git.backend.js +46 -17
  163. package/lib/helpers/for-backend/helpers-git.backend.js.map +1 -1
  164. package/lib/helpers/for-browser/angular.helper.js +2 -2
  165. package/lib/helpers/helpers-numbers.js.map +1 -1
  166. package/lib/helpers/helpers.d.ts +0 -8
  167. package/lib/helpers/helpers.js +1 -55
  168. package/lib/helpers/helpers.js.map +1 -1
  169. package/lib/old/base-component.js +2 -2
  170. package/lib/old/base-formly-component.js +2 -2
  171. package/lib/old/dual-component-ctrl.js +2 -2
  172. package/lib/utils.d.ts +24 -35
  173. package/lib/utils.js +165 -105
  174. package/lib/utils.js.map +1 -1
  175. package/lib/validators/validators-firedev.d.ts +3 -0
  176. package/lib/validators/validators-firedev.js +34 -0
  177. package/lib/validators/validators-firedev.js.map +1 -0
  178. package/lib/validators/validators-git.d.ts +3 -0
  179. package/lib/validators/validators-git.js +13 -0
  180. package/lib/validators/validators-git.js.map +1 -0
  181. package/lib/validators/validators-network.d.ts +3 -0
  182. package/lib/validators/validators-network.js +19 -0
  183. package/lib/validators/validators-network.js.map +1 -0
  184. package/lib/validators/validators.d.ts +6 -0
  185. package/lib/validators/validators.js +11 -0
  186. package/lib/validators/validators.js.map +1 -0
  187. package/package.json +1 -1
  188. package/tmp-environment.json +33 -0
  189. package/websql/README.md +24 -24
  190. package/websql/fesm2022/tnp-helpers.mjs +3460 -321
  191. package/websql/fesm2022/tnp-helpers.mjs.map +1 -1
  192. package/websql/lib/base/classes/base-cli-worker/base-cli-worker-config.d.ts +4 -0
  193. package/websql/lib/base/classes/base-cli-worker/base-cli-worker-controller.d.ts +3 -4
  194. package/websql/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +4 -3
  195. package/websql/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +86 -35
  196. package/websql/lib/base/classes/base-cli-worker/base-cli-worker.models.d.ts +45 -0
  197. package/websql/lib/base/classes/base-cli-worker/base-cli-worker.utils.d.ts +6 -0
  198. package/websql/lib/base/classes/base-cli-worker/index.d.ts +3 -1
  199. package/websql/lib/base/classes/base-docker.d.ts +4 -7
  200. package/websql/lib/base/classes/base-git.d.ts +2 -0
  201. package/websql/lib/base/classes/base-global-command-line.d.ts +265 -0
  202. package/websql/lib/base/classes/base-node-modules.d.ts +1 -0
  203. package/websql/lib/base/classes/base-npm-helpers.d.ts +1 -0
  204. package/websql/lib/base/classes/base-release-process.d.ts +3 -1
  205. package/websql/lib/base/classes/base-vscode.d.ts +1 -1
  206. package/websql/lib/base/classes/index.d.ts +2 -1
  207. package/websql/lib/base/gh-temp-code.d.ts +17 -0
  208. package/websql/lib/build-info._auto-generated_.d.ts +1 -1
  209. package/websql/lib/helpers/helpers.d.ts +0 -5
  210. package/websql/lib/utils.d.ts +24 -35
  211. package/websql/package.json +1 -1
@@ -0,0 +1,2484 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseGlobalCommandLine = void 0;
4
+ //#region imports
5
+ const readline = require("readline"); // @backend
6
+ const rxjs_1 = require("rxjs");
7
+ const lib_1 = require("tnp-config/lib");
8
+ const lib_2 = require("tnp-core/lib");
9
+ const lib_3 = require("tnp-core/lib");
10
+ const lib_4 = require("tnp-core/lib");
11
+ const lib_5 = require("tnp-core/lib");
12
+ const lib_6 = require("tnp-core/lib"); //@backend
13
+ const index_1 = require("../../index");
14
+ const commit_data_1 = require("../commit-data");
15
+ const gh_temp_code_1 = require("../gh-temp-code");
16
+ const base_command_line_feature_1 = require("./base-command-line-feature");
17
+ //#endregion
18
+ class BaseGlobalCommandLine extends base_command_line_feature_1.BaseCommandLineFeature {
19
+ _() {
20
+ index_1.Helpers.error('Please select git command');
21
+ }
22
+ //#region commands / prevent cwd is not project
23
+ /**
24
+ * TODO return argument not need for now
25
+ */
26
+ async cwdIsProject(options) {
27
+ //#region @backendFunc
28
+ const { requireProjectWithGitRoot } = options || {};
29
+ if (!!this.project && !requireProjectWithGitRoot) {
30
+ return true;
31
+ }
32
+ if (requireProjectWithGitRoot &&
33
+ (!this.project || !this.project.git.isGitRoot)) {
34
+ const proj = this.ins.nearestTo(this.cwd, { findGitRoot: true });
35
+ if (proj) {
36
+ index_1.Helpers.info(`
37
+ Current folder (${this.cwd})
38
+ is not a git root folder, but nearest project with
39
+ git root has been found in: ${lib_2.chalk.bold(proj.genericName)}
40
+
41
+ `);
42
+ const useRoot = await index_1.Helpers.questionYesNo('Would you like to use this project ?');
43
+ if (useRoot) {
44
+ this.project = proj;
45
+ this.cwd = proj.location;
46
+ return true;
47
+ }
48
+ else {
49
+ index_1.Helpers.error(`[${lib_1.config.frameworkName}] This is not git root project folder`, true, true);
50
+ }
51
+ }
52
+ else {
53
+ index_1.Helpers.error(`[${lib_1.config.frameworkName}] This folder is not project folder`, false, true);
54
+ }
55
+ }
56
+ return true;
57
+ //#endregion
58
+ }
59
+ //#endregion
60
+ //#region commands / hosts
61
+ hosts() {
62
+ //#region @backendFunc
63
+ index_1.Helpers.run(`code ${(0, lib_3.crossPlatformPath)(lib_5.UtilsNetwork.getEtcHostsPath())}`).sync();
64
+ process.exit(0);
65
+ //#endregion
66
+ }
67
+ //#endregion
68
+ //#region commands / count commits
69
+ countCommits() {
70
+ //#region @backendFunc
71
+ console.log(index_1.Helpers.git.countCommits(this.cwd));
72
+ this._exit();
73
+ //#endregion
74
+ }
75
+ //#endregion
76
+ //#region commands / remove submodules
77
+ removeSubmodules() {
78
+ //#region @backendFunc
79
+ index_1.Helpers.taskStarted('Removing submodules...');
80
+ for (const folderAbsPath of index_1.Helpers.foldersFrom(this.cwd, {
81
+ recursive: false,
82
+ })) {
83
+ if (index_1.Helpers.exists((0, lib_3.crossPlatformPath)([folderAbsPath, '.git']))) {
84
+ try {
85
+ index_1.Helpers.run(`git rm --cached ${lib_2.path.basename(folderAbsPath)}`).sync();
86
+ }
87
+ catch (error) { }
88
+ }
89
+ }
90
+ index_1.Helpers.taskDone('Done');
91
+ this._exit();
92
+ //#endregion
93
+ }
94
+ removeSubmodule() {
95
+ //#region @backendFunc
96
+ index_1.Helpers.taskStarted(`Removing submodules.. ${this.firstArg}`);
97
+ if (index_1.Helpers.exists((0, lib_3.crossPlatformPath)([this.cwd, this.firstArg || '', '.git']))) {
98
+ try {
99
+ index_1.Helpers.run(`git rm --cached ${this.firstArg}`).sync();
100
+ }
101
+ catch (error) { }
102
+ }
103
+ index_1.Helpers.taskDone('Done');
104
+ this._exit();
105
+ //#endregion
106
+ }
107
+ //#endregion
108
+ //#region commands / set editor
109
+ async setEditor() {
110
+ //#region @backendFunc
111
+ await this.ins.configDb.selectCodeEditor();
112
+ this._exit();
113
+ //#endregion
114
+ }
115
+ //#endregion
116
+ //#region commands / api update
117
+ async upapi() {
118
+ //#region @backendFunc
119
+ await this.apiUpdate();
120
+ //#endregion
121
+ }
122
+ async apiup() {
123
+ //#region @backendFunc
124
+ await this.apiUpdate();
125
+ //#endregion
126
+ }
127
+ async apiUpdate() {
128
+ //#region @backendFunc
129
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
130
+ return;
131
+ }
132
+ index_1.Helpers.info('Updating & push project...');
133
+ try {
134
+ this.project.git.addAndCommit(`chore: api ${!!this.firstArg ? this.firstArg : 'update'}`);
135
+ }
136
+ catch (error) { }
137
+ await this.project.git.pushCurrentBranch({
138
+ askToRetry: true,
139
+ forcePushNoQuestion: true,
140
+ });
141
+ index_1.Helpers.info('Done');
142
+ this._exit();
143
+ //#endregion
144
+ }
145
+ //#endregion
146
+ //#region commands / chore update
147
+ async cu() {
148
+ //#region @backendFunc
149
+ await this.update();
150
+ //#endregion
151
+ }
152
+ async choreUpdate() {
153
+ //#region @backendFunc
154
+ await this.update();
155
+ //#endregion
156
+ }
157
+ //#endregion
158
+ //#region commands / color vscode
159
+ colorvscode() {
160
+ //#region @backendFunc
161
+ this.settingsVscode();
162
+ //#endregion
163
+ }
164
+ //#endregion
165
+ //#region commands / settings vscode
166
+ /**
167
+ * Generate or update .vscode/settings.json file color settings
168
+ */
169
+ settingsVscode() {
170
+ //#region @backendFunc
171
+ this.refreshVscodeColors();
172
+ //#endregion
173
+ }
174
+ refreshVscodeColors() {
175
+ //#region @backendFunc
176
+ this._regenerateVscodeSettingsColors();
177
+ this._exit();
178
+ //#endregion
179
+ }
180
+ _regenerateVscodeSettingsColors(overideBottomColor) {
181
+ //#region @backendFunc
182
+ index_1.UtilsVSCode.regenerateVsCodeSettingsColors(this.cwd, overideBottomColor);
183
+ //#endregion
184
+ }
185
+ //#endregion
186
+ //#region commands / quick git update
187
+ /**
188
+ * quick git update push
189
+ */
190
+ async update() {
191
+ //#region @backendFunc
192
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
193
+ return;
194
+ }
195
+ index_1.Helpers.info('Updating & push project...');
196
+ try {
197
+ this.project.git.addAndCommit(`chore: ${!!this.firstArg ? this.firstArg : 'update'}`);
198
+ }
199
+ catch (error) { }
200
+ await this.project.git.pushCurrentBranch({
201
+ askToRetry: true,
202
+ forcePushNoQuestion: true,
203
+ });
204
+ index_1.Helpers.info('Done');
205
+ this._exit();
206
+ //#endregion
207
+ }
208
+ async updateProject(project, force = false) {
209
+ //#region @backendFunc
210
+ try {
211
+ await project.packageJson.bumpPatchVersion();
212
+ }
213
+ catch (error) { }
214
+ try {
215
+ project.git.addAndCommit(`chore: ${!!this.firstArg ? this.args.join(' ') : 'update'}`);
216
+ }
217
+ catch (error) { }
218
+ await project.git.pushCurrentBranch({
219
+ askToRetry: true,
220
+ forcePushNoQuestion: true,
221
+ force,
222
+ });
223
+ if (!project.isMonorepo) {
224
+ for (const child of project.children) {
225
+ if (child.git.isGitRoot) {
226
+ await this.updateProject(child, force);
227
+ }
228
+ }
229
+ }
230
+ //#endregion
231
+ }
232
+ async deepUp(noExit = false) {
233
+ //#region @backendFunc
234
+ await this.deepUpdate(noExit);
235
+ //#endregion
236
+ }
237
+ async upAll(noExit = false) {
238
+ //#region @backendFunc
239
+ await this.deepUpdate(noExit);
240
+ //#endregion
241
+ }
242
+ async deepUpForce(noExit = false) {
243
+ //#region @backendFunc
244
+ await this.deepUpdateForce(noExit);
245
+ //#endregion
246
+ }
247
+ async deepUpdateForce(noExit = false) {
248
+ //#region @backendFunc
249
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
250
+ return;
251
+ }
252
+ index_1.Helpers.info('(force) Deep updating & force pushing project with children...');
253
+ await this.updateProject(this.project, true);
254
+ index_1.Helpers.info('Done');
255
+ this._exit();
256
+ //#endregion
257
+ }
258
+ async deepUpdate(noExit = false) {
259
+ //#region @backendFunc
260
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
261
+ return;
262
+ }
263
+ index_1.Helpers.info('Deep updating & pushing project with children...');
264
+ await this.updateProject(this.project);
265
+ index_1.Helpers.info('Done');
266
+ this._exit();
267
+ //#endregion
268
+ }
269
+ /**
270
+ * Push update
271
+ */
272
+ async up() {
273
+ //#region @backendFunc
274
+ await this.update();
275
+ //#endregion
276
+ }
277
+ /**
278
+ * Push update
279
+ */
280
+ async pu() {
281
+ //#region @backendFunc
282
+ await this.update();
283
+ //#endregion
284
+ }
285
+ //#endregion
286
+ //#region commands / develop
287
+ async develop() {
288
+ //#region @backendFunc
289
+ // Helpers.clearConsole();
290
+ index_1.Helpers.taskStarted(`getting all projects...`);
291
+ const founded = ((await this.ins.projectsDb.getAllProjectsFromDB()) || [])
292
+ .filter(p => index_1.Helpers.exists(p.location))
293
+ .map(p => {
294
+ const proj = this.ins.From(p.location);
295
+ // console.log(`Proj for ${p.location} `, !!proj)
296
+ if (proj) {
297
+ return proj;
298
+ // return proj.embeddedProject ? proj.embeddedProject : proj;
299
+ }
300
+ // const nereset = this.ins.nearestTo(p.location);
301
+ // if (nereset) {
302
+ // const embeded = nereset.linkedProjects.find(l => crossPlatformPath([nereset.location, l.relativeClonePath]) === p.location);
303
+ // if (embeded) {
304
+ // return this.ins.From([nereset.location, embeded.relativeClonePath]);
305
+ // }
306
+ // }
307
+ })
308
+ .filter(p => !!p);
309
+ index_1.Helpers.taskDone(`found ${founded.length} projects...`);
310
+ index_1.Helpers.taskStarted(`searching for project...`);
311
+ // @ts-ignore
312
+ const results = index_1.Helpers.uniqArray([
313
+ ...index_1.Helpers.arrays.fuzzy(this.args.join(' '), founded, p => p.name)
314
+ .results,
315
+ ...index_1.Helpers.arrays.fuzzy(this.args.join(' '), founded, p => p.basename)
316
+ .results,
317
+ ...index_1.Helpers.arrays.fuzzy(this.args.join(' '), founded, p => p.location)
318
+ .results,
319
+ ], 'location');
320
+ index_1.Helpers.taskDone(`found ${results.length} projects...`);
321
+ const openInEditor = async (proj) => {
322
+ index_1.Helpers.taskStarted(`Getting code editor info...`);
323
+ const editor = await this.ins.configDb.getCodeEditor();
324
+ index_1.Helpers.taskDone(`Got code editor info...`);
325
+ const embededProject = proj.linkedProjects.embeddedProject;
326
+ const porjToOpen = embededProject || proj;
327
+ const locaitonFolderToOpen = porjToOpen.location;
328
+ index_1.Helpers.info('Initing and opening project...');
329
+ try {
330
+ await porjToOpen?.struct();
331
+ }
332
+ catch (error) { }
333
+ index_1.Helpers.run(`${editor} ${locaitonFolderToOpen}`).sync();
334
+ };
335
+ if (results.length === 1) {
336
+ await openInEditor(lib_2._.first(results));
337
+ }
338
+ else if (results.length === 0) {
339
+ index_1.Helpers.error(`No project found by name: "${this.args.join(' ')}"`, false, true);
340
+ }
341
+ else {
342
+ index_1.Helpers.info(`Opening console gui to select project...`);
343
+ const res = await index_1.Helpers.consoleGui.select('Select project to open', results.map(p => {
344
+ return {
345
+ name: p.genericName,
346
+ value: p.location,
347
+ };
348
+ }), true);
349
+ await openInEditor(this.ins.From(res));
350
+ }
351
+ this._exit();
352
+ //#endregion
353
+ }
354
+ async dev() {
355
+ //#region @backendFunc
356
+ return await this.develop();
357
+ //#endregion
358
+ }
359
+ //#endregion
360
+ //#region commands / repulll
361
+ async repul() {
362
+ //#region @backendFunc
363
+ await this.repull();
364
+ //#endregion
365
+ }
366
+ async repull() {
367
+ //#region @backendFunc
368
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
369
+ return;
370
+ }
371
+ await this.project.git.resetHard({ HEAD: 10 });
372
+ await this.pull();
373
+ //#endregion
374
+ }
375
+ //#endregion
376
+ //#region commands / pull
377
+ async pul() {
378
+ //#region @backendFunc
379
+ await this.pull();
380
+ //#endregion
381
+ }
382
+ async pull() {
383
+ //#region @backendFunc
384
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
385
+ return;
386
+ }
387
+ await this.project.git.pullProcess({
388
+ setOrigin: this.params['setOrigin'],
389
+ });
390
+ this._exit();
391
+ //#endregion
392
+ }
393
+ //#endregion
394
+ //#region commands / pull all
395
+ async pullAll() {
396
+ //#region @backendFunc
397
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
398
+ return;
399
+ }
400
+ await this.project.git.pullProcess({
401
+ setOrigin: this.params['setOrigin'],
402
+ });
403
+ this._exit();
404
+ //#endregion
405
+ }
406
+ //#endregion
407
+ //#region commands / push and pull
408
+ async pp() {
409
+ //#region @backendFunc
410
+ const currentBranch = this.project.git.currentBranchName;
411
+ this.project
412
+ .run(`git push origin ${currentBranch} && git pull origin ${currentBranch}`)
413
+ .sync();
414
+ console.log('Done push and pull');
415
+ this._exit();
416
+ //#endregion
417
+ }
418
+ //#endregion
419
+ //#region commands / reset
420
+ __resetInfo(branchToReset, withChildren) {
421
+ //#region @backendFunc
422
+ index_1.Helpers.info(`
423
+
424
+ YOU ARE RESETING ${withChildren ? 'EVERYTHING' : 'PROJECT'} ` +
425
+ `TO BRANCH: ${lib_2.chalk.bold(branchToReset)}
426
+
427
+ - curret project (${this.project.name})
428
+ ${withChildren &&
429
+ lib_2._.isArray(this.project.children) &&
430
+ this.project.children.length > 0
431
+ ? `- modules:\n${this.project.children
432
+ .map(c => `\t${c.basename} (${lib_2.chalk.yellow(c.name)})`)
433
+ .join('\n')}`
434
+ : ''}
435
+ `);
436
+ //#endregion
437
+ }
438
+ async fetch() {
439
+ //#region @backendFunc
440
+ try {
441
+ this.project?.git?.fetch();
442
+ }
443
+ catch (error) { }
444
+ this._exit();
445
+ //#endregion
446
+ }
447
+ async reset() {
448
+ //#region @backendFunc
449
+ // Helpers.clearConsole();
450
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
451
+ return;
452
+ }
453
+ const parent = this.project.parent;
454
+ const branchFromLinkedProjectConfig = parent?.linkedProjects?.linkedProjects.find(l => {
455
+ return ((0, lib_3.crossPlatformPath)([parent.location, l.relativeClonePath]) ===
456
+ this.project.location);
457
+ })?.defaultBranch;
458
+ let overrideBranchToReset = this.firstArg ||
459
+ branchFromLinkedProjectConfig ||
460
+ this.project.core?.branch ||
461
+ this.project.git.getDefaultDevelopmentBranch() ||
462
+ this.project.git.currentBranchName;
463
+ if (this.project.core?.branch) {
464
+ index_1.Helpers.info(`
465
+
466
+ Core branch for project: ${this.project.core?.branch}
467
+
468
+ `);
469
+ }
470
+ const resetOnlyChildren = !!this.project.linkedProjects.getLinkedProjectsConfig().resetOnlyChildren;
471
+ const branches = index_1.Helpers.uniqArray([
472
+ ...this.__filterBranchesByPattern(overrideBranchToReset),
473
+ ...this.__filterBranchesByPattern(''),
474
+ ]);
475
+ const resetChildren = this.project.git.resetIsRestingAlsoChildren();
476
+ if (resetChildren && resetOnlyChildren) {
477
+ index_1.Helpers.info(`Reseting only children...for defualt branches.`);
478
+ }
479
+ else {
480
+ if (branches.length > 0) {
481
+ overrideBranchToReset = await this.__selectBrach(branches, 'reset');
482
+ }
483
+ else {
484
+ index_1.Helpers.error(`No branch found by name "${overrideBranchToReset || this.firstArg}"`, false, true);
485
+ }
486
+ }
487
+ overrideBranchToReset = overrideBranchToReset || '';
488
+ this.__resetInfo(overrideBranchToReset
489
+ ? overrideBranchToReset
490
+ : this.project.git.getDefaultDevelopmentBranch(), resetChildren);
491
+ let resetProject = this.project;
492
+ if (this.project.git.isInsideGitRepo && !this.project.git.isGitRoot) {
493
+ index_1.Helpers.warn(`You are not in root of git repo...`, false);
494
+ resetProject = this.ins.nearestTo((0, lib_3.crossPlatformPath)([this.project.location, '..']), {
495
+ findGitRoot: true,
496
+ });
497
+ if (!(await index_1.Helpers.questionYesNo(`Would you like to reset root repo instead (project=${lib_2.chalk.bold.red(resetProject.genericName)}) ?`))) {
498
+ index_1.Helpers.error(`Aborted`, false, true);
499
+ }
500
+ }
501
+ const res = await index_1.Helpers.questionYesNo(`Reset hard and pull current project ` +
502
+ `${resetChildren && resetProject.linkedProjects.linkedProjects.length > 0 ? '(and children)' : ''} ?`);
503
+ if (res) {
504
+ await resetProject.resetProcess(overrideBranchToReset);
505
+ }
506
+ this._exit();
507
+ //#endregion
508
+ }
509
+ //#endregion
510
+ //#region commands / soft
511
+ async soft() {
512
+ //#region @backendFunc
513
+ // TODO when aciton commit
514
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
515
+ return;
516
+ }
517
+ const howManyCommits = Number(this.firstArg) || 1;
518
+ lib_2._.times(howManyCommits, n => {
519
+ console.log(`Resetting soft ${n + 1} commit "${this.project.git.lastCommitMessage()}"`);
520
+ this.project.git.resetSoftHEAD(1);
521
+ });
522
+ this._exit();
523
+ //#endregion
524
+ }
525
+ //#endregion
526
+ //#region commands / rebase
527
+ async rebase() {
528
+ //#region @backendFunc
529
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
530
+ return;
531
+ }
532
+ const currentBranch = this.project.git.currentBranchName;
533
+ let safeReset = 10;
534
+ let rebaseBranch = this.firstArg || this.project.git.getDefaultDevelopmentBranch();
535
+ const branches = this.__filterBranchesByPattern(rebaseBranch);
536
+ if (branches.length > 1) {
537
+ rebaseBranch = await this.__selectBrach(branches, 'rebase');
538
+ }
539
+ else if (branches.length === 1) {
540
+ rebaseBranch = lib_2._.first(branches);
541
+ }
542
+ else {
543
+ index_1.Helpers.error(`No rebase branch found by name "${rebaseBranch}"`, false, true);
544
+ }
545
+ index_1.Helpers.info(`
546
+ You are rebasing current branch (${currentBranch}) to ${rebaseBranch}
547
+
548
+ Files from last commit:
549
+
550
+ "${lib_2.chalk.gray(await this.project.git.getCommitMessageByHash(this.project.git.lastCommitHash()))}"
551
+ (hash: ${lib_2.chalk.gray(this.project.git.lastCommitHash())})
552
+
553
+ are going to be applied after rebase.
554
+
555
+
556
+ `);
557
+ if (!(await lib_4.UtilsTerminal.confirm({
558
+ message: `Do you want to continue ?`,
559
+ defaultValue: true,
560
+ }))) {
561
+ this._exit();
562
+ }
563
+ try {
564
+ this.project.git.resetHard();
565
+ this.project.git.checkout(rebaseBranch);
566
+ this.project.git.resetHard({ HEAD: safeReset });
567
+ await this.project.git.pullCurrentBranch();
568
+ this.project.git.checkout(currentBranch);
569
+ this.project.git.resetSoftHEAD(1);
570
+ this.project.git.stageAllFiles();
571
+ this.project.git.stash();
572
+ this.project.git.resetHard({ HEAD: safeReset });
573
+ this.project.git.rebase(rebaseBranch);
574
+ this.project.git.stashApply();
575
+ await this.project.struct();
576
+ index_1.Helpers.info('REBASE DONE');
577
+ }
578
+ catch (error) {
579
+ index_1.Helpers.renderError(error);
580
+ try {
581
+ // dummy init to get back to previous vscode settings
582
+ await this.project.init();
583
+ }
584
+ catch (error) { }
585
+ index_1.Helpers.error('Not able to rebase', true, true);
586
+ }
587
+ this._exit();
588
+ //#endregion
589
+ }
590
+ //#endregion
591
+ //#region commands / stash
592
+ /**
593
+ * stash only staged files
594
+ */
595
+ async stash() {
596
+ //#region @backendFunc
597
+ index_1.Helpers.info(`Stashing only staged files...`);
598
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
599
+ return;
600
+ }
601
+ this.project.git.stash({ onlyStaged: true });
602
+ this._exit();
603
+ //#endregion
604
+ }
605
+ //#endregion
606
+ //#region commands / stash all
607
+ /**
608
+ * stash all files
609
+ */
610
+ async stashAll() {
611
+ //#region @backendFunc
612
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
613
+ return;
614
+ }
615
+ this.project.git.stageAllFiles();
616
+ this.project.git.stash();
617
+ this._exit();
618
+ //#endregion
619
+ }
620
+ //#endregion
621
+ //#region commands / push all origins
622
+ /**
623
+ * push force to all origins
624
+ */
625
+ async pushAllForce() {
626
+ //#region @backendFunc
627
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
628
+ return;
629
+ }
630
+ await this.pushAll(true);
631
+ //#endregion
632
+ }
633
+ async pAllForce() {
634
+ //#region @backendFunc
635
+ await this.pushAllForce();
636
+ //#endregion
637
+ }
638
+ async pAllf() {
639
+ //#region @backendFunc
640
+ await this.pushAllForce();
641
+ //#endregion
642
+ }
643
+ async pAll() {
644
+ //#region @backendFunc
645
+ await this.pushAll();
646
+ //#endregion
647
+ }
648
+ /**
649
+ * push to all origins
650
+ */
651
+ async pushAll(force = false) {
652
+ //#region @backendFunc
653
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
654
+ return;
655
+ }
656
+ const remotes = this.project.git.allOrigins;
657
+ index_1.Helpers.info(`
658
+
659
+ Remotes for repo:
660
+
661
+ ${remotes.map((r, i) => `${i + 1}. ${r.origin} ${r.url}`).join('\n')}
662
+
663
+ `);
664
+ for (let index = 0; index < remotes.length; index++) {
665
+ const { origin, url } = remotes[index];
666
+ index_1.Helpers.taskStarted(`Pushing to ${lib_2.chalk.bold(origin)} (${url})...`);
667
+ await this.push({ force, origin, noExit: true });
668
+ index_1.Helpers.taskDone(`Pushed to ${origin}`);
669
+ }
670
+ this._exit();
671
+ //#endregion
672
+ }
673
+ //#endregion
674
+ //#region commands / push force
675
+ async forcePush() {
676
+ //#region @backendFunc
677
+ await this.push({ force: true, typeofCommit: 'feature' });
678
+ //#endregion
679
+ }
680
+ async pushForce() {
681
+ //#region @backendFunc
682
+ await this.push({ force: true, typeofCommit: 'feature' });
683
+ //#endregion
684
+ }
685
+ //#endregion
686
+ //#region commands / commit
687
+ /**
688
+ * Commit and push this for single repo
689
+ */
690
+ async commit(options = {}) {
691
+ //#region @backendFunc
692
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
693
+ return;
694
+ }
695
+ await this.project.git.meltActionCommits();
696
+ await this.project.git.pushProcess({
697
+ ...options,
698
+ forcePushNoQuestion: options.force,
699
+ args: this.args,
700
+ exitCallBack: () => {
701
+ this._exit();
702
+ },
703
+ skipChildren: true,
704
+ overrideCommitMessage: this.args.join(' '),
705
+ setOrigin: this.params['setOrigin'],
706
+ currentOrigin: this.project.git.originURL,
707
+ });
708
+ if (options.noExit) {
709
+ return;
710
+ }
711
+ this._exit();
712
+ //#endregion
713
+ }
714
+ //#endregion
715
+ //#region commands / push
716
+ async _preventPushPullFromNotCorrectBranch() {
717
+ //#region @backendFunc
718
+ while (true) {
719
+ const devBranch = this.project.git.duringPushWarnIfProjectNotOnSpecyficDevBranch();
720
+ if (!!devBranch && devBranch !== this.project.git.currentBranchName) {
721
+ index_1.Helpers.warn(`
722
+
723
+ ${this.project.genericName}
724
+
725
+ You are not on ${devBranch} branch. Please switch to this branch and try again
726
+
727
+
728
+
729
+ `, false);
730
+ const options = {
731
+ open: { name: 'Open in vscode' },
732
+ continue: { name: 'Continue (check again)' },
733
+ continueForce: { name: 'Continue (without checking)' },
734
+ exit: { name: 'Exit process' },
735
+ };
736
+ const res = await index_1.Helpers.selectChoicesAsk('What you want to do ?', Object.keys(options).map(k => {
737
+ return { name: options[k].name, value: k };
738
+ }));
739
+ if (res === 'continue') {
740
+ continue;
741
+ }
742
+ if (res === 'exit') {
743
+ this._exit();
744
+ }
745
+ if (res === 'open') {
746
+ this.project.run('code . ').sync();
747
+ continue;
748
+ }
749
+ if (res === 'continueForce') {
750
+ return;
751
+ }
752
+ }
753
+ return;
754
+ }
755
+ //#endregion
756
+ }
757
+ async qPush() {
758
+ //#region @backendFunc
759
+ await this.quickPush();
760
+ //#endregion
761
+ }
762
+ async quickPush() {
763
+ //#region @backendFunc
764
+ await this.push({ skipLint: true });
765
+ //#endregion
766
+ }
767
+ async repushauto() {
768
+ //#region @backendFunc
769
+ await this.rePush(true);
770
+ //#endregion
771
+ }
772
+ async rePush(skipQuesion = false) {
773
+ //#region @backendFunc
774
+ const lastCommitMessage = this.project.git.lastCommitMessage();
775
+ this.project.git.resetSoftHEAD();
776
+ this.project.git.stageAllFiles();
777
+ this.project.git.commit(lastCommitMessage);
778
+ if (!skipQuesion) {
779
+ index_1.Helpers.info(`Last fixed commit:
780
+ ${lastCommitMessage}
781
+
782
+ ...`);
783
+ await lib_4.UtilsTerminal.pressAnyKeyToContinueAsync({
784
+ message: `Press any key to force push`,
785
+ });
786
+ }
787
+ await this.project.git.pushCurrentBranch({
788
+ forcePushNoQuestion: true,
789
+ force: true,
790
+ });
791
+ this._exit();
792
+ //#endregion
793
+ }
794
+ async push(options = {}) {
795
+ //#region @backendFunc
796
+ // console.log('args', this.args);
797
+ // console.log(`argsWithParams "${this.argsWithParams}"` );
798
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
799
+ return;
800
+ }
801
+ await this._preventPushPullFromNotCorrectBranch();
802
+ if (!options.overrideCommitMessage &&
803
+ this.project.git.useBranchNameDirectlyAsCommitMessage()) {
804
+ options.overrideCommitMessage = (this.project.git.currentBranchName || '')
805
+ .split('-')
806
+ .join(' ');
807
+ const jiraNumbers = commit_data_1.CommitData.extractAndOrderJiraNumbers(this.project.git.currentBranchName) || [];
808
+ for (const jiraNum of jiraNumbers) {
809
+ options.overrideCommitMessage = options.overrideCommitMessage.replace(jiraNum.replace('-', ' '), jiraNum);
810
+ }
811
+ }
812
+ await this.project.git.pushProcess({
813
+ ...options,
814
+ forcePushNoQuestion: options.force,
815
+ args: options?.overrideCommitMessage
816
+ ? (options?.overrideCommitMessage || '').split(' ')
817
+ : this.args,
818
+ exitCallBack: () => {
819
+ this._exit();
820
+ },
821
+ setOrigin: this.params['setOrigin'],
822
+ currentOrigin: this.project.git.originURL,
823
+ });
824
+ if (options.noExit) {
825
+ return;
826
+ }
827
+ this._exit();
828
+ //#endregion
829
+ }
830
+ //#endregion
831
+ //#region commands / melt
832
+ async melt() {
833
+ //#region @backendFunc
834
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
835
+ return;
836
+ }
837
+ await this.meltUpdateCommits({ hideInfo: true });
838
+ this._exit();
839
+ //#endregion
840
+ }
841
+ //#endregion
842
+ //#region commands / melt
843
+ async meltUp() {
844
+ //#region @backendFunc
845
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
846
+ return;
847
+ }
848
+ const alreadyProcessedOrigins = [];
849
+ const processProject = async (proj) => {
850
+ if (alreadyProcessedOrigins.includes(proj.git.originURL)) {
851
+ return;
852
+ }
853
+ alreadyProcessedOrigins.push(proj.git.originURL);
854
+ index_1.Helpers.clearConsole();
855
+ await proj.git.resolveLastChanges({
856
+ tryAutomaticActionFirst: false,
857
+ projectNameAsOutputPrefix: this.project.location !== proj.location ? proj.name : void 0,
858
+ });
859
+ for (const child of proj.children) {
860
+ await processProject(child);
861
+ }
862
+ };
863
+ await processProject(this.project);
864
+ index_1.Helpers.info('All projects are up to date with remote');
865
+ this._exit();
866
+ //#endregion
867
+ }
868
+ //#endregion
869
+ //#region commands / melt
870
+ async meltAll() {
871
+ //#region @backendFunc
872
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
873
+ return;
874
+ }
875
+ await this.meltUpdateCommits({ hideInfo: true });
876
+ for (const child of this.project.children) {
877
+ await this.__meltCommitsFunc(child, { hideInfo: true });
878
+ }
879
+ this._exit();
880
+ //#endregion
881
+ }
882
+ //#endregion
883
+ //#region commands / melt updat ecommits
884
+ async __meltCommitsFunc(project, options) {
885
+ //#region @backendFunc
886
+ options = options || {};
887
+ const meltedCommits = project.git.meltActionCommits();
888
+ if (meltedCommits > 0) {
889
+ index_1.Helpers.logInfo(`${meltedCommits} has been soft reset (melted) in ${project.genericName}`);
890
+ }
891
+ else {
892
+ index_1.Helpers.logInfo(`No commits to melt for project ${project.genericName}`);
893
+ }
894
+ //#endregion
895
+ }
896
+ async meltUpdateCommits(options) {
897
+ //#region @backendFunc
898
+ await this.__meltCommitsFunc(this.project, options);
899
+ //#endregion
900
+ }
901
+ //#endregion
902
+ //#region commands / push feature
903
+ async pf() {
904
+ //#region @backendFunc
905
+ await this.pushFeature();
906
+ //#endregion
907
+ }
908
+ async pRel() {
909
+ //#region @backendFunc
910
+ await this.pushRelease();
911
+ //#endregion
912
+ }
913
+ async pRelease() {
914
+ //#region @backendFunc
915
+ await this.pushRelease();
916
+ //#endregion
917
+ }
918
+ async pushRelease() {
919
+ //#region @backendFunc
920
+ await this.meltUpdateCommits();
921
+ await this.push({
922
+ typeofCommit: 'release',
923
+ commitMessageRequired: true,
924
+ overrideCommitMessage: `${lib_2._.first(this.project.releaseProcess.getReleaseWords())} ` +
925
+ `version ${this.project.packageJson.version}`,
926
+ });
927
+ //#endregion
928
+ }
929
+ async mPush() {
930
+ //#region @backendFunc
931
+ await this.meltPush();
932
+ //#endregion
933
+ }
934
+ async fmPush() {
935
+ //#region @backendFunc
936
+ await this.forceMeltPush();
937
+ //#endregion
938
+ }
939
+ async mfPush() {
940
+ //#region @backendFunc
941
+ await this.forceMeltPush();
942
+ //#endregion
943
+ }
944
+ async mforcePush() {
945
+ //#region @backendFunc
946
+ await this.forceMeltPush();
947
+ //#endregion
948
+ }
949
+ async meltforcePush() {
950
+ //#region @backendFunc
951
+ await this.forceMeltPush();
952
+ //#endregion
953
+ }
954
+ async forceMeltPush() {
955
+ //#region @backendFunc
956
+ await this.meltPush(true);
957
+ //#endregion
958
+ }
959
+ async meltPush(force = false) {
960
+ //#region @backendFunc
961
+ await this.meltUpdateCommits();
962
+ await this.push({
963
+ mergeUpdateCommits: true,
964
+ force,
965
+ });
966
+ //#endregion
967
+ }
968
+ async pushFeature() {
969
+ //#region @backendFunc
970
+ await this.meltUpdateCommits();
971
+ await this.push({ typeofCommit: 'feature', commitMessageRequired: true });
972
+ //#endregion
973
+ }
974
+ //#endregion
975
+ //#region commands / push fix
976
+ async pushFix() {
977
+ //#region @backendFunc
978
+ await this.meltUpdateCommits();
979
+ await this.push({ typeofCommit: 'bugfix', commitMessageRequired: true });
980
+ //#endregion
981
+ }
982
+ pfix() {
983
+ //#region @backendFunc
984
+ this.pushFix();
985
+ //#endregion
986
+ }
987
+ //#endregion
988
+ //#region commands / push chore
989
+ async pushChore() {
990
+ //#region @backendFunc
991
+ await this.meltUpdateCommits();
992
+ await this.push({ typeofCommit: 'chore', commitMessageRequired: true });
993
+ //#endregion
994
+ }
995
+ async pc() {
996
+ //#region @backendFunc
997
+ await this.pushChore();
998
+ //#endregion
999
+ }
1000
+ //#endregion
1001
+ //#region commands / push refactor
1002
+ async pushRefactor() {
1003
+ //#region @backendFunc
1004
+ await this.meltUpdateCommits();
1005
+ await this.push({ typeofCommit: 'refactor', commitMessageRequired: true });
1006
+ //#endregion
1007
+ }
1008
+ async pushref() {
1009
+ //#region @backendFunc
1010
+ await this.pushRefactor();
1011
+ //#endregion
1012
+ }
1013
+ async pref() {
1014
+ //#region @backendFunc
1015
+ await this.pushRefactor();
1016
+ //#endregion
1017
+ }
1018
+ //#endregion
1019
+ //#region commands / push style
1020
+ async pushStyle() {
1021
+ //#region @backendFunc
1022
+ await this.meltUpdateCommits();
1023
+ await this.push({ typeofCommit: 'style', commitMessageRequired: true });
1024
+ //#endregion
1025
+ }
1026
+ async pstyl() {
1027
+ //#region @backendFunc
1028
+ await this.pushStyle();
1029
+ //#endregion
1030
+ }
1031
+ async pstyle() {
1032
+ //#region @backendFunc
1033
+ await this.pushStyle();
1034
+ //#endregion
1035
+ }
1036
+ //#endregion
1037
+ //#region commands / push docs
1038
+ async pushDocs() {
1039
+ //#region @backendFunc
1040
+ await this.meltUpdateCommits();
1041
+ await this.push({ typeofCommit: 'docs', commitMessageRequired: true });
1042
+ //#endregion
1043
+ }
1044
+ async pd() {
1045
+ //#region @backendFunc
1046
+ await this.pushDocs();
1047
+ //#endregion
1048
+ }
1049
+ async pdocs() {
1050
+ //#region @backendFunc
1051
+ await this.pushDocs();
1052
+ //#endregion
1053
+ }
1054
+ //#endregion
1055
+ //#region commands / push test
1056
+ async pushTest() {
1057
+ //#region @backendFunc
1058
+ await this.meltUpdateCommits();
1059
+ await this.push({ typeofCommit: 'test', commitMessageRequired: true });
1060
+ //#endregion
1061
+ }
1062
+ async pTest() {
1063
+ //#region @backendFunc
1064
+ await this.pushTest();
1065
+ //#endregion
1066
+ }
1067
+ async pTests() {
1068
+ //#region @backendFunc
1069
+ await this.pushTest();
1070
+ //#endregion
1071
+ }
1072
+ //#endregion
1073
+ //#region commands / push perf
1074
+ async pushPerf() {
1075
+ //#region @backendFunc
1076
+ await this.meltUpdateCommits();
1077
+ await this.push({
1078
+ typeofCommit: 'performance',
1079
+ commitMessageRequired: true,
1080
+ });
1081
+ //#endregion
1082
+ }
1083
+ //#endregion
1084
+ //#region commands / push ci
1085
+ async pushCi() {
1086
+ //#region @backendFunc
1087
+ await this.meltUpdateCommits();
1088
+ await this.push({ typeofCommit: 'ci', commitMessageRequired: true });
1089
+ //#endregion
1090
+ }
1091
+ //#endregion
1092
+ //#region commands / select branch
1093
+ async branch() {
1094
+ //#region @backendFunc
1095
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
1096
+ return;
1097
+ }
1098
+ await this.project.struct();
1099
+ try {
1100
+ this.project.git.fetch();
1101
+ }
1102
+ catch (error) { }
1103
+ let branchName = this.firstArg;
1104
+ const branches = this.__filterBranchesByPattern(branchName);
1105
+ if (branches.length > 0) {
1106
+ branchName = await this.__selectBrach(branches, 'checkout');
1107
+ }
1108
+ else {
1109
+ index_1.Helpers.error(`No branch found by name "${branchName}"`, false, true);
1110
+ }
1111
+ try {
1112
+ this.project.git.stageAllFiles();
1113
+ this.project.git.stash();
1114
+ }
1115
+ catch (error) { }
1116
+ this.project.git.checkout(branchName);
1117
+ this._exit();
1118
+ //#endregion
1119
+ }
1120
+ //#endregion
1121
+ //#region commands / push build
1122
+ async pushBuild() {
1123
+ //#region @backendFunc
1124
+ await this.meltUpdateCommits();
1125
+ await this.push({ typeofCommit: 'build', commitMessageRequired: true });
1126
+ //#endregion
1127
+ }
1128
+ //#endregion
1129
+ //#region commands / set origin
1130
+ async SET_ORIGIN() {
1131
+ //#region @backendFunc
1132
+ let newOriginNameOrUrl = this.firstArg;
1133
+ if (newOriginNameOrUrl === 'ssh') {
1134
+ newOriginNameOrUrl = index_1.Helpers.git.originHttpToSsh(index_1.Helpers.git.getOriginURL(this.cwd));
1135
+ }
1136
+ if (newOriginNameOrUrl === 'http') {
1137
+ newOriginNameOrUrl = index_1.Helpers.git.originSshToHttp(index_1.Helpers.git.getOriginURL(this.cwd));
1138
+ }
1139
+ if (index_1.Helpers.git.isInsideGitRepo(this.cwd)) {
1140
+ index_1.Helpers.run(`git remote rm origin`, { cwd: this.cwd }).sync();
1141
+ index_1.Helpers.run(`git remote add origin ${newOriginNameOrUrl} `, {
1142
+ cwd: this.cwd,
1143
+ }).sync();
1144
+ index_1.Helpers.info(`Done`);
1145
+ }
1146
+ else {
1147
+ index_1.Helpers.error(`This folder is not a git repo... `, false, true);
1148
+ }
1149
+ this._exit();
1150
+ //#endregion
1151
+ }
1152
+ //#endregion
1153
+ //#region commands / rename origin
1154
+ async RENAME_ORIGIN() {
1155
+ //#region @backendFunc
1156
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
1157
+ return;
1158
+ }
1159
+ const newOriginNameOrUrl = this.firstArg;
1160
+ const proj = this.project;
1161
+ if (proj && proj.git.isInsideGitRepo) {
1162
+ proj.git.renameOrigin(newOriginNameOrUrl);
1163
+ }
1164
+ else {
1165
+ index_1.Helpers.error(`This folder is not a git repo... `, false, true);
1166
+ }
1167
+ this._exit();
1168
+ //#endregion
1169
+ }
1170
+ //#endregion
1171
+ //#region commands / last hash tag
1172
+ async LAST_TAG_HASH() {
1173
+ //#region @backendFunc
1174
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
1175
+ return;
1176
+ }
1177
+ index_1.Helpers.info(this.project.git.lastTagHash());
1178
+ this._exit();
1179
+ //#endregion
1180
+ }
1181
+ //#endregion
1182
+ //#region commands / last tag
1183
+ async LAST_TAG() {
1184
+ //#region @backendFunc
1185
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
1186
+ return;
1187
+ }
1188
+ const proj = this.project;
1189
+ index_1.Helpers.info(`
1190
+
1191
+ last tag: ${proj.git.lastTagVersionName}
1192
+ last tag hash: ${proj.git.lastTagHash()}
1193
+
1194
+ `);
1195
+ this._exit();
1196
+ //#endregion
1197
+ }
1198
+ //#endregion
1199
+ //#region commands / check tag exists
1200
+ CHECK_TAG_EXISTS() {
1201
+ //#region @backendFunc
1202
+ index_1.Helpers.info(`tag "${this.firstArg}" exits = ${index_1.Helpers.git.checkTagExists(this.firstArg)} `);
1203
+ this._exit();
1204
+ //#endregion
1205
+ }
1206
+ //#endregion
1207
+ //#region commands / lint
1208
+ /**
1209
+ * TODO move somewhere
1210
+ */
1211
+ async lint() {
1212
+ //#region @backendFunc
1213
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
1214
+ return;
1215
+ }
1216
+ await this.project.lint();
1217
+ //#endregion
1218
+ }
1219
+ //#endregion
1220
+ //#region commands / version
1221
+ /**
1222
+ * TODO move somewhere
1223
+ */
1224
+ async version() {
1225
+ //#region @backendFunc
1226
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: false }))) {
1227
+ return;
1228
+ }
1229
+ console.log('Current project verison: ' + this.project.packageJson.version);
1230
+ this._exit();
1231
+ //#endregion
1232
+ }
1233
+ //#endregion
1234
+ //#region commands / init
1235
+ /**
1236
+ * TODO move somewhere
1237
+ */
1238
+ async init() {
1239
+ //#region @backendFunc
1240
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: false }))) {
1241
+ return;
1242
+ }
1243
+ await this.project.init();
1244
+ this._exit();
1245
+ //#endregion
1246
+ }
1247
+ /**
1248
+ * init parent and first level children
1249
+ */
1250
+ async initAll() {
1251
+ //#region @backendFunc
1252
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: false }))) {
1253
+ return;
1254
+ }
1255
+ await this.project.init();
1256
+ for (const child of this.project.children) {
1257
+ await child.init();
1258
+ }
1259
+ this._exit();
1260
+ //#endregion
1261
+ }
1262
+ //#endregion
1263
+ //#region commands / struct
1264
+ /**
1265
+ * TODO move somewhere
1266
+ */
1267
+ async struct() {
1268
+ //#region @backendFunc
1269
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: false }))) {
1270
+ return;
1271
+ }
1272
+ await this.project.struct();
1273
+ this._exit();
1274
+ //#endregion
1275
+ }
1276
+ //#endregion
1277
+ //#region commands / info
1278
+ /**
1279
+ * TODO move somewhere
1280
+ */
1281
+ async info() {
1282
+ //#region @backendFunc
1283
+ if (!(await this.cwdIsProject({
1284
+ requireProjectWithGitRoot: false,
1285
+ }))) {
1286
+ return;
1287
+ }
1288
+ index_1.Helpers.clearConsole();
1289
+ index_1.Helpers.info(await this.project.info());
1290
+ await this.project.linkedProjects.saveAllLinkedProjectsToDB();
1291
+ this._exit();
1292
+ //#endregion
1293
+ }
1294
+ //#endregion
1295
+ //#region commands / info
1296
+ async modified() {
1297
+ //#region @backendFunc
1298
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
1299
+ return;
1300
+ }
1301
+ const proj = this.project;
1302
+ const libs = proj.children.filter(child => {
1303
+ process.stdout.write('.');
1304
+ return child.git.thereAreSomeUncommitedChangeExcept([
1305
+ lib_1.config.file.package_json,
1306
+ ]);
1307
+ });
1308
+ console.log('\n' + index_1.Helpers.terminalLine());
1309
+ index_1.Helpers.info(libs.length
1310
+ ? libs
1311
+ .map(c => `${lib_2.chalk.bold(c.name)} (${c.git.uncommitedFiles.map(p => lib_2.chalk.black(lib_2.path.basename(p))).join(', ')})`)
1312
+ .join('\n')
1313
+ : 'Nothing modifed');
1314
+ this._exit();
1315
+ //#endregion
1316
+ }
1317
+ //#endregion
1318
+ //#region commands / update
1319
+ async refresh() {
1320
+ //#region @backendFunc
1321
+ await this.project.refreshChildrenProjects({
1322
+ askUserAboutUpdate: true,
1323
+ });
1324
+ this._exit(0);
1325
+ //#endregion
1326
+ }
1327
+ //#endregion
1328
+ //#region commands / changes
1329
+ async changes() {
1330
+ //#region @backendFunc
1331
+ index_1.Helpers.info(await this.project.git.changesSummary());
1332
+ index_1.Helpers.terminalLine();
1333
+ for (const chil of this.project.children) {
1334
+ index_1.Helpers.info(await chil.git.changesSummary());
1335
+ }
1336
+ this._exit();
1337
+ //#endregion
1338
+ }
1339
+ //#endregion
1340
+ //#region commands / all tags
1341
+ async allTags() {
1342
+ //#region @backendFunc
1343
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: true }))) {
1344
+ return;
1345
+ }
1346
+ const allTags = await index_1.Helpers.git.getAllTags(this.cwd);
1347
+ console.log(allTags);
1348
+ this._exit();
1349
+ //#endregion
1350
+ }
1351
+ //#endregion
1352
+ //#region commands / remove tag
1353
+ async removeTag() {
1354
+ //#region @backendFunc
1355
+ let tagToRemove = this.firstArg;
1356
+ if (!tagToRemove) {
1357
+ const allTags = await index_1.Helpers.git.getAllTags(this.cwd);
1358
+ tagToRemove = await lib_4.UtilsTerminal.select({
1359
+ question: `Select tag to remove`,
1360
+ autocomplete: true,
1361
+ choices: allTags.map(t => {
1362
+ return { name: t, value: t };
1363
+ }),
1364
+ });
1365
+ }
1366
+ index_1.Helpers.git.removeTag(this.cwd, tagToRemove);
1367
+ this._exit();
1368
+ //#endregion
1369
+ }
1370
+ //#endregion
1371
+ //#region commands / branch name
1372
+ BRANCH_NAME() {
1373
+ //#region @backendFunc
1374
+ console.log(`current branch name: "${index_1.Helpers.git.currentBranchName(process.cwd())}"`);
1375
+ this._exit();
1376
+ //#endregion
1377
+ }
1378
+ //#endregion
1379
+ //#region commands / remotes
1380
+ REMOTES() {
1381
+ //#region @backendFunc
1382
+ console.log(index_1.Helpers.git.allOrigins(this.cwd));
1383
+ this._exit();
1384
+ //#endregion
1385
+ }
1386
+ async SET_REMOTE_SSH() {
1387
+ //#region @backendFunc
1388
+ await index_1.Helpers.git.changeRemoteFromHttpsToSSh(this.cwd);
1389
+ this._exit();
1390
+ //#endregion
1391
+ }
1392
+ async SET_REMOTE_http() {
1393
+ //#region @backendFunc
1394
+ await index_1.Helpers.git.changeRemoveFromSshToHttps(this.cwd);
1395
+ this._exit();
1396
+ //#endregion
1397
+ }
1398
+ async SET_REMOTE_https() {
1399
+ //#region @backendFunc
1400
+ await this.SET_REMOTE_http();
1401
+ //#endregion
1402
+ }
1403
+ _resolveChildFromArg() {
1404
+ //#region @backendFunc
1405
+ const { resolved: projFromArg, clearedCommand } = index_1.Helpers.cliTool.resolveItemFromArgsBegin(this.args, arg => this.ins.From([this.cwd, arg]));
1406
+ if (!!projFromArg) {
1407
+ this.args = clearedCommand.split(' ');
1408
+ this.cwd = projFromArg.location;
1409
+ this.project = projFromArg;
1410
+ }
1411
+ //#endregion
1412
+ }
1413
+ origin() {
1414
+ //#region @backendFunc
1415
+ this._resolveChildFromArg();
1416
+ console.log(index_1.Helpers.git.getOriginURL(this.cwd));
1417
+ this._exit();
1418
+ //#endregion
1419
+ }
1420
+ remote() {
1421
+ //#region @backendFunc
1422
+ console.log(index_1.Helpers.git.getOriginURL(this.cwd));
1423
+ this._exit();
1424
+ //#endregion
1425
+ }
1426
+ originHttp() {
1427
+ //#region @backendFunc
1428
+ console.log(index_1.Helpers.git.originSshToHttp(index_1.Helpers.git.getOriginURL(this.cwd)));
1429
+ this._exit();
1430
+ //#endregion
1431
+ }
1432
+ originHttps() {
1433
+ //#region @backendFunc
1434
+ console.log(index_1.Helpers.git.originSshToHttp(index_1.Helpers.git.getOriginURL(this.cwd)));
1435
+ this._exit();
1436
+ //#endregion
1437
+ }
1438
+ originssh() {
1439
+ //#region @backendFunc
1440
+ console.log(index_1.Helpers.git.originHttpToSsh(index_1.Helpers.git.getOriginURL(this.cwd)));
1441
+ this._exit();
1442
+ //#endregion
1443
+ }
1444
+ origins() {
1445
+ //#region @backendFunc
1446
+ this.REMOTES();
1447
+ //#endregion
1448
+ }
1449
+ //#endregion
1450
+ //#region commands / git config
1451
+ gitConfig() {
1452
+ //#region @backendFunc
1453
+ const root = index_1.Helpers.git.findGitRoot(this.cwd);
1454
+ index_1.Helpers.run(`code ${(0, lib_3.crossPlatformPath)([root, '.git', 'config'])}`).sync();
1455
+ this._exit();
1456
+ //#endregion
1457
+ }
1458
+ //#endregion
1459
+ //#region commands / lastCommitHash
1460
+ LAST_COMMIT_HASH() {
1461
+ //#region @backendFunc
1462
+ console.log(index_1.Helpers.git.lastCommitHash(this.cwd));
1463
+ this._exit();
1464
+ //#endregion
1465
+ }
1466
+ //#endregion
1467
+ //#region commands / commit message by hash
1468
+ async COMMIT_MESSAGE_BY_HASH() {
1469
+ //#region @backendFunc
1470
+ const hash = this.firstArg;
1471
+ console.log(await this.project.git.getCommitMessageByHash(hash));
1472
+ this._exit();
1473
+ //#endregion
1474
+ }
1475
+ //#endregion
1476
+ //#region commands / last 5 commit hashes
1477
+ async LAST_5_COMMITS() {
1478
+ //#region @backendFunc
1479
+ for (let index = 0; index < 5; index++) {
1480
+ const hash = await this.project.git.getCommitHashByIndex(index);
1481
+ console.log(hash);
1482
+ }
1483
+ this._exit();
1484
+ //#endregion
1485
+ }
1486
+ //#endregion
1487
+ //#region commands / update deps from
1488
+ async updateDepsFrom() {
1489
+ //#region @backendFunc
1490
+ let locations = this.args.join(' ').trim() === '' ? [] : this.args;
1491
+ if (lib_2._.isArray(locations)) {
1492
+ locations = locations.map(l => {
1493
+ if (lib_2.path.isAbsolute(l)) {
1494
+ return lib_2.path.resolve(l);
1495
+ }
1496
+ return lib_2.path.resolve(lib_2.path.join(this.cwd, l));
1497
+ });
1498
+ }
1499
+ this.project.packageJson.updateDepsFrom(locations);
1500
+ this._exit();
1501
+ //#endregion
1502
+ }
1503
+ //#endregion
1504
+ //#region is terminal supported
1505
+ isSupportedTaonTerminal() {
1506
+ //#region @backendFunc
1507
+ console.log(`Terminal is supported: ${index_1.Helpers.isSupportedTaonTerminal}`);
1508
+ this._exit();
1509
+ //#endregion
1510
+ }
1511
+ //#endregion
1512
+ //#region is terminal running inside cmd
1513
+ isRunningInWindowsCmd() {
1514
+ //#region @backendFunc
1515
+ console.log(`Is terminal running insdie cmd.exe: ${lib_2.UtilsOs.isRunningInWindowsCmd()}`);
1516
+ this._exit();
1517
+ //#endregion
1518
+ }
1519
+ //#endregion
1520
+ //#region is running inside powershell
1521
+ isRunningInWindowsPowerShell() {
1522
+ //#region @backendFunc
1523
+ console.log(`Is terminal running insdie powershell: ${lib_2.UtilsOs.isRunningInWindowsPowerShell()}`);
1524
+ this._exit();
1525
+ //#endregion
1526
+ }
1527
+ //#endregion
1528
+ //#region prox ext
1529
+ async INSTALL_PROJECT_EXTENSIONS() {
1530
+ //#region @backendFunc
1531
+ await this.INSTALL_PROJ_EXT();
1532
+ //#endregion
1533
+ }
1534
+ async INSTALL_PROJECT_EXT() {
1535
+ //#region @backendFunc
1536
+ await this.INSTALL_PROJ_EXT();
1537
+ //#endregion
1538
+ }
1539
+ async INS_PROJ_EXT() {
1540
+ //#region @backendFunc
1541
+ await this.INSTALL_PROJ_EXT();
1542
+ //#endregion
1543
+ }
1544
+ async INSTALL_PROJ_EXT() {
1545
+ //#region @backendFunc
1546
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: false }))) {
1547
+ return;
1548
+ }
1549
+ this.project.vsCodeHelpers.recreateExtensions();
1550
+ const p = this.project.pathFor('.vscode/extensions.json');
1551
+ const extensions = index_1.Helpers.readJson(p, { recommendations: [] }, true);
1552
+ index_1.Helpers.clearConsole();
1553
+ await this.project.vsCodeHelpers.installExtensions(extensions.recommendations, true);
1554
+ this._exit();
1555
+ //#endregion
1556
+ }
1557
+ //#endregion
1558
+ //#region proj db
1559
+ async projdb() {
1560
+ //#region @backendFunc
1561
+ if (!(await this.cwdIsProject({ requireProjectWithGitRoot: false }))) {
1562
+ return;
1563
+ }
1564
+ index_1.Helpers.info(`Projects db location:
1565
+ ${this.project.linkedProjects.projectsDbLocation}
1566
+
1567
+ opening in vscode...
1568
+
1569
+ `);
1570
+ index_1.Helpers.run(`code ${this.project.linkedProjects.projectsDbLocation}`).sync();
1571
+ this._exit();
1572
+ //#endregion
1573
+ }
1574
+ //#endregion
1575
+ //#region filter all project branches by pattern
1576
+ __filterBranchesByPattern(branchPatternOrBranchName) {
1577
+ //#region @backendFunc
1578
+ const branches = index_1.Helpers.arrays.uniqArray(this.project.git.getBranchesNamesBy(branchPatternOrBranchName) ||
1579
+ this.project.getMainBranches());
1580
+ // console.log('branches', branches);
1581
+ return branches;
1582
+ //#endregion
1583
+ }
1584
+ //#endregion
1585
+ //#region select branch from list of branches
1586
+ async __selectBrach(branches, task) {
1587
+ //#region @backendFunc
1588
+ const actionWithoutChildren = task === 'reset' && !this.project.git.resetIsRestingAlsoChildren();
1589
+ const childrenMsg = actionWithoutChildren
1590
+ ? '(without children)'
1591
+ : this.project.children.length == 0
1592
+ ? '(no children in project)'
1593
+ : '(with children)';
1594
+ return await index_1.Helpers.autocompleteAsk(`Choose branch to ${task} in this project ${childrenMsg}: `, branches.map(b => {
1595
+ return { name: b, value: b };
1596
+ }));
1597
+ //#endregion
1598
+ }
1599
+ //#endregion
1600
+ //#region commands / clone
1601
+ async clone() {
1602
+ //#region @backendFunc
1603
+ let url = this.firstArg;
1604
+ const originType = this.params['setOrigin'];
1605
+ if (originType) {
1606
+ if (originType === 'ssh') {
1607
+ url = index_1.Helpers.git.originHttpToSsh(url);
1608
+ }
1609
+ if (originType === 'http') {
1610
+ url = index_1.Helpers.git.originSshToHttp(url);
1611
+ }
1612
+ }
1613
+ await index_1.Helpers.git.clone({
1614
+ url,
1615
+ cwd: this.cwd,
1616
+ });
1617
+ this._exit();
1618
+ //#endregion
1619
+ }
1620
+ //#endregion
1621
+ //#region commands / gh temp
1622
+ async ghSave() {
1623
+ //#region @backendFunc
1624
+ await new gh_temp_code_1.GhTempCode(this.cwd, this.project).init().save();
1625
+ this._exit();
1626
+ //#endregion
1627
+ }
1628
+ async ghRestore() {
1629
+ //#region @backendFunc
1630
+ await new gh_temp_code_1.GhTempCode(this.cwd, this.project).init().restore();
1631
+ this._exit();
1632
+ //#endregion
1633
+ }
1634
+ //#endregion
1635
+ //#region commands / start cli service ports worker
1636
+ async ports() {
1637
+ //#region @backendFunc
1638
+ await this.ins.portsWorker.terminalUI.infoScreen();
1639
+ //#endregion
1640
+ }
1641
+ /**
1642
+ * tnp startCliServicePortsWorker --restart
1643
+ */
1644
+ async startCliServicePortsWorker() {
1645
+ //#region @backendFunc
1646
+ await this.ins.portsWorker.cliStartProcedure({
1647
+ methodOptions: {
1648
+ calledFrom: 'terminal command',
1649
+ cliParams: {
1650
+ ...this.params,
1651
+ mode: index_1.BaseCLiWorkerStartMode.IN_CURRENT_PROCESS,
1652
+ },
1653
+ },
1654
+ });
1655
+ //#endregion
1656
+ }
1657
+ //#endregion
1658
+ //#region commands / wait for any key
1659
+ async waitForUserAnyKey() {
1660
+ //#region @backendFunc
1661
+ console.log('Press any key to exit...');
1662
+ await lib_4.UtilsTerminal.waitForUserAnyKey(async () => {
1663
+ console.log('Exiting...');
1664
+ this._exit();
1665
+ });
1666
+ //#endregion
1667
+ }
1668
+ //#endregion
1669
+ //#region commands / pause terminal
1670
+ pauseTerminal() {
1671
+ //#region @backendFunc
1672
+ index_1.Helpers.pressKeyAndContinue();
1673
+ this._exit();
1674
+ //#endregion
1675
+ }
1676
+ //#endregion
1677
+ //#region commands / sleep terminal
1678
+ sleepTerminal() {
1679
+ //#region @backendFunc
1680
+ index_1.Helpers.info(`Sleeping terminal for 1 second... before exit`);
1681
+ index_1.Helpers.sleep(1);
1682
+ this._exit();
1683
+ //#endregion
1684
+ }
1685
+ //#endregion
1686
+ //#region commands / gh pages init
1687
+ async ghPagesInit() {
1688
+ //#region @backendFunc
1689
+ await this.project.init();
1690
+ await this.project.staticPages.init(this.params['provider'] || 'github', !!this.params['full']);
1691
+ index_1.Helpers.run('code .', {
1692
+ cwd: this.project.staticPages.mainFolderAbsPath,
1693
+ }).sync();
1694
+ this._exit();
1695
+ //#endregion
1696
+ }
1697
+ //#endregion
1698
+ //#region commands / is port in use
1699
+ async isPortInUse() {
1700
+ //#region @backendFunc
1701
+ const port = parseInt(this.firstArg);
1702
+ console.log(`Port ${port} is in use: ${await lib_2.UtilsOs.isPortInUse(port)}`);
1703
+ this._exit();
1704
+ //#endregion
1705
+ }
1706
+ //#endregion
1707
+ //#region commands / proc menu
1708
+ /* */
1709
+ /* */
1710
+ /* */
1711
+ /* */
1712
+ /* */
1713
+ /* */
1714
+ /* */
1715
+ /* */
1716
+ /* */
1717
+ /* */
1718
+ /* */
1719
+ /* */
1720
+ /* */
1721
+ /* */
1722
+ /* */
1723
+ /* */
1724
+ /* */
1725
+ /* */
1726
+ /* */
1727
+ /* */
1728
+ /* */
1729
+ /* */
1730
+ /* */
1731
+ /* */
1732
+ /* */
1733
+ /* */
1734
+ /* */
1735
+ /* */
1736
+ /* */
1737
+ /* */
1738
+ /* */
1739
+ /* */
1740
+ /* */
1741
+ /* */
1742
+ /* */
1743
+ /* */
1744
+ /* */
1745
+ /* */
1746
+ /* */
1747
+ /* */
1748
+ /* */
1749
+ /* */
1750
+ /* */
1751
+ /* */
1752
+ /* */
1753
+ /* */
1754
+ /* */
1755
+ /* */
1756
+ /* */
1757
+ /* */
1758
+ /* */
1759
+ /* */
1760
+ /* */
1761
+ /* */
1762
+ /* */
1763
+ /* */
1764
+ /* */
1765
+ /* */
1766
+ //#endregion
1767
+ //#region commands / proc info
1768
+ procInfo() {
1769
+ //#region @backendFunc
1770
+ this.processInfo();
1771
+ //#endregion
1772
+ }
1773
+ processInfo() {
1774
+ //#region @backendFunc
1775
+ index_1.Helpers.info(`
1776
+
1777
+ Is running in CLI mode: ${lib_2.UtilsOs.isRunningInCliMode()}
1778
+ Is running in Mocha test: ${lib_2.UtilsOs.isRunningInMochaTest()}
1779
+ Is running in VSCode extension: ${lib_2.UtilsOs.isRunningInVscodeExtension()}
1780
+ Is running in Electron: ${lib_2.UtilsOs.isRunningInElectron()}
1781
+ Is running in Docker: ${lib_2.UtilsOs.isRunningInDocker()}
1782
+ Is running in WebSQL: ${lib_2.UtilsOs.isRunningInWebSQL()}
1783
+ Is running in WSL: ${lib_2.UtilsOs.isRunningInWsl()}
1784
+ Is running in Linux graphics capable environment: ${lib_2.UtilsOs.isRunningInLinuxGraphicsCapableEnvironment()}
1785
+ Is running in Node: ${lib_2.UtilsOs.isRunningInNode()}
1786
+ Is running in Browser: ${lib_2.UtilsOs.isRunningInBrowser()}
1787
+
1788
+ `);
1789
+ this._exit();
1790
+ //#endregion
1791
+ }
1792
+ //#endregion
1793
+ //#region commands / last git tag
1794
+ lastGitTag() {
1795
+ //#region @backendFunc
1796
+ console.log('Latest tag');
1797
+ console.log(this.project?.git.lastTagVersionName);
1798
+ this._exit();
1799
+ //#endregion
1800
+ }
1801
+ //#endregion
1802
+ //#region commands / check ports
1803
+ async checkPort() {
1804
+ //#region @backendFunc
1805
+ await this.checkPorts();
1806
+ //#endregion
1807
+ }
1808
+ async checkPorts() {
1809
+ //#region @backendFunc
1810
+ const ports = this.args
1811
+ .join(' ')
1812
+ .replace(/\,/, '')
1813
+ .split(' ')
1814
+ .map(p => {
1815
+ return parseInt(p);
1816
+ });
1817
+ console.log(`Checking ports: ${ports.join(', ')}`);
1818
+ if (ports.length === 0) {
1819
+ index_1.Helpers.error(`No ports provided`, false, true);
1820
+ }
1821
+ for (const port of ports) {
1822
+ const isPortInUse = await lib_2.UtilsOs.isPortInUse(port);
1823
+ console.log(`Port ${port} is in use: ${isPortInUse ? lib_2.chalk.red('YES') : lib_2.chalk.green('NO')}`);
1824
+ }
1825
+ this._exit();
1826
+ //#endregion
1827
+ }
1828
+ //#endregion
1829
+ //#region commands / remove symlinks
1830
+ removeSymlinksDryRun() {
1831
+ //#region @backendFunc
1832
+ index_1.Helpers.removeSymlinks(this.project.nodeModules.path, {
1833
+ dryRun: true,
1834
+ });
1835
+ //#endregion
1836
+ }
1837
+ //#endregion
1838
+ //#region commands / select java
1839
+ async selectJava() {
1840
+ //#region @backendFunc
1841
+ const selectedJava = await index_1.UtilsJava.selectJdkVersion();
1842
+ index_1.UtilsJava.updateJavaHomePath(selectedJava);
1843
+ //#endregion
1844
+ }
1845
+ //#endregion
1846
+ //#region commands / select tomcat
1847
+ async selectTomcat() {
1848
+ //#region @backendFunc
1849
+ const selectedTomcat = await index_1.UtilsJava.selectTomcatVersion();
1850
+ index_1.UtilsJava.updateTomcatHomePath(selectedTomcat);
1851
+ this._exit();
1852
+ //#endregion
1853
+ }
1854
+ //#endregion
1855
+ //#region commands / ln
1856
+ LN() {
1857
+ //#region @backendFunc
1858
+ const [source, dest] = this.args;
1859
+ index_1.Helpers.createSymLink(source, dest);
1860
+ this._exit();
1861
+ //#endregion
1862
+ }
1863
+ //#endregion
1864
+ //#region commands / copy
1865
+ copy() {
1866
+ //#region @backendFunc
1867
+ let [from, to] = this.args;
1868
+ from = lib_2.path.isAbsolute(from)
1869
+ ? (0, lib_3.crossPlatformPath)(from)
1870
+ : (0, lib_3.crossPlatformPath)([this.cwd, from]);
1871
+ to = lib_2.path.isAbsolute(to)
1872
+ ? (0, lib_3.crossPlatformPath)(to)
1873
+ : (0, lib_3.crossPlatformPath)([this.cwd, to]);
1874
+ if (lib_2.path.basename(to) !== lib_2.path.basename(from)) {
1875
+ to = (0, lib_3.crossPlatformPath)([to, lib_2.path.basename(from)]);
1876
+ }
1877
+ index_1.Helpers.taskStarted(`Copying from ${from} to ${to}`);
1878
+ if (!index_1.Helpers.exists(from)) {
1879
+ index_1.Helpers.error(`Source file or folder "${from}" does not exist`, false, true);
1880
+ }
1881
+ if (index_1.Helpers.isFolder(from)) {
1882
+ index_1.Helpers.copy(from, to);
1883
+ }
1884
+ else {
1885
+ index_1.Helpers.copyFile(from, to);
1886
+ }
1887
+ index_1.Helpers.taskDone(`Copied`);
1888
+ this._exit();
1889
+ //#endregion
1890
+ }
1891
+ //#endregion
1892
+ //#region commands / simulate domain
1893
+ async simulateDomain() {
1894
+ //#region @backendFunc
1895
+ // UtilsTerminal.clearConsole();
1896
+ await lib_5.UtilsNetwork.simulateDomain(this.args);
1897
+ this._exit();
1898
+ //#endregion
1899
+ }
1900
+ //#endregion
1901
+ //#region commands / preview
1902
+ async preview() {
1903
+ //#region @backendFunc
1904
+ //#region handle preview of docker compose
1905
+ if ([lib_1.fileName.docker_compose_yml, lib_1.fileName.compose_yml].includes(lib_2.path.basename(this.firstArg))) {
1906
+ const simulateDomain = this.params['domain'] || this.params['domains'];
1907
+ const firstArg = lib_2.path.isAbsolute(this.firstArg)
1908
+ ? this.firstArg
1909
+ : (0, lib_3.crossPlatformPath)([this.cwd, this.firstArg]);
1910
+ const cwd = (0, lib_3.crossPlatformPath)(lib_2.path.dirname(firstArg));
1911
+ const composeFileName = lib_2.path.basename(firstArg);
1912
+ // import { spawn } from 'child_process';
1913
+ // import { readFileSync } from 'fs';
1914
+ // import { resolve } from 'path';
1915
+ const envPath = (0, lib_3.crossPlatformPath)([cwd, '.env']);
1916
+ const COMPOSE_PROJECT_NAME = lib_5.UtilsDotFile.getValueFromDotFile(envPath, 'COMPOSE_PROJECT_NAME');
1917
+ const envContent = lib_5.UtilsDotFile.getValuesKeysAsJsonObject(envPath) || {};
1918
+ const allDomains = lib_2.Utils.uniqArray(Object.keys(envContent)
1919
+ .filter(key => {
1920
+ return key.startsWith('FRONTEND_HOST_URL_');
1921
+ })
1922
+ .map(domainKey => envContent[domainKey]));
1923
+ if (simulateDomain && allDomains.length === 0) {
1924
+ index_1.Helpers.error(`No domains to simulate found in .env file.
1925
+
1926
+ Before release build update your
1927
+
1928
+ env.ts or env.angular-node-app.ENVIRONTMENT_NAME.ts with
1929
+
1930
+ ${lib_2.chalk.bold(`website.useDomain = true;`)}
1931
+
1932
+ `, false, true);
1933
+ }
1934
+ const project = this.ins.From(cwd);
1935
+ await project.docker.updateDockerComposePorts();
1936
+ let closing = false;
1937
+ const triggerRevertChangesToEtcHosts = new rxjs_1.Subject();
1938
+ if (simulateDomain) {
1939
+ await lib_5.UtilsNetwork.simulateDomain(allDomains, {
1940
+ triggerRevertChangesToEtcHosts,
1941
+ });
1942
+ }
1943
+ const child = project.docker.getDockerComposeActionChildProcess('up');
1944
+ console.log(`
1945
+
1946
+
1947
+ ${lib_2.chalk.bold('PRESS ANY KEY TO STOP')} RUNNING CONTAINER(S) ` +
1948
+ `FOR ${lib_2.chalk.bold.underline(COMPOSE_PROJECT_NAME)}
1949
+ ${simulateDomain ? `AND SIMULATING DOMAINS: ${allDomains.join(', ')} IN ETC/HOST` : ''}
1950
+
1951
+
1952
+ `);
1953
+ process.stdin.setRawMode(true);
1954
+ process.stdin.resume();
1955
+ process.stdin.on('data', () => {
1956
+ if (closing) {
1957
+ return;
1958
+ }
1959
+ // If we are already closing, ignore further input
1960
+ closing = true;
1961
+ triggerRevertChangesToEtcHosts.next();
1962
+ console.log('Stopping container...');
1963
+ // TODO probably UtilsProcess.killProcess() better
1964
+ child.kill('SIGINT');
1965
+ console.log('Exiting...');
1966
+ const downProcess = project.docker.getDockerComposeActionChildProcess('down');
1967
+ downProcess.on('close', code => {
1968
+ console.log(`docker compose down exited with code ${code}`);
1969
+ process.exit(0);
1970
+ });
1971
+ });
1972
+ }
1973
+ else {
1974
+ index_1.Helpers.error(`You can preview only docker-compose.yml or compose.yml files`, false, true);
1975
+ }
1976
+ //#endregion
1977
+ //#endregion
1978
+ }
1979
+ //#endregion
1980
+ //#region commands / shorten
1981
+ /**
1982
+ * read huge file and display only lines with specyfic words
1983
+ */
1984
+ async shorten() {
1985
+ //#region @backendFunc
1986
+ const rl = readline.createInterface({
1987
+ input: lib_2.fse.createReadStream(lib_2.path.isAbsolute(this.firstArg)
1988
+ ? (0, lib_3.crossPlatformPath)(this.firstArg)
1989
+ : (0, lib_3.crossPlatformPath)([this.cwd, this.firstArg]), { encoding: 'utf8' }),
1990
+ crlfDelay: Infinity,
1991
+ });
1992
+ const keywords = this.args.splice(1);
1993
+ console.log(`Searching for keywords: ${keywords.join(', ')}`);
1994
+ for await (const line of rl) {
1995
+ if (keywords.some(word => line.includes(word))) {
1996
+ console.log(line);
1997
+ }
1998
+ }
1999
+ index_1.Helpers.info(`File processed`);
2000
+ this._exit();
2001
+ //#endregion
2002
+ }
2003
+ //#endregion
2004
+ //#region commands / dump packages versions
2005
+ dumpPackagesVersions() {
2006
+ //#region @backendFunc
2007
+ const getData = (location) => {
2008
+ const version = index_1.Helpers.readValueFromJson((0, lib_3.crossPlatformPath)([location, lib_1.fileName.package_json]), 'version');
2009
+ const name = index_1.Helpers.readValueFromJson((0, lib_3.crossPlatformPath)([location, lib_1.fileName.package_json]), 'name');
2010
+ return { version, name };
2011
+ };
2012
+ const pkgs = index_1.Helpers.foldersFrom([this.cwd, lib_1.folderName.node_modules], {
2013
+ recursive: false,
2014
+ })
2015
+ .reduce((arr, c) => {
2016
+ if (lib_2.path.basename(c).startsWith('@')) {
2017
+ const newData = index_1.Helpers.foldersFrom([
2018
+ this.cwd,
2019
+ lib_1.folderName.node_modules,
2020
+ lib_2.path.basename(c),
2021
+ ]).map(c2 => getData(c2));
2022
+ return arr.concat(newData);
2023
+ }
2024
+ return arr.concat(getData(c));
2025
+ }, [])
2026
+ .reduce((arr, c) => {
2027
+ return lib_2._.merge(arr, { [c.name]: c.version });
2028
+ }, {});
2029
+ index_1.Helpers.writeJson([this.cwd, 'packages-versions.json'], pkgs);
2030
+ index_1.Helpers.info(`packages-versions.json created with ${pkgs.length} packages`);
2031
+ this._exit();
2032
+ //#endregion
2033
+ }
2034
+ //#endregion
2035
+ //#region commands / zip
2036
+ async zip() {
2037
+ //#region @backendFunc
2038
+ let folderPath = (0, lib_3.crossPlatformPath)(this.firstArg);
2039
+ if (!lib_2.path.isAbsolute(folderPath)) {
2040
+ folderPath = (0, lib_3.crossPlatformPath)([this.cwd, this.firstArg]);
2041
+ }
2042
+ if (!index_1.Helpers.exists(folderPath)) {
2043
+ index_1.Helpers.error(`File or folder to zip does not exist: ${folderPath}`, false, true);
2044
+ }
2045
+ if (!index_1.Helpers.isFolder(folderPath)) {
2046
+ index_1.Helpers.error(`You can zip only folders. Provided path is not a folder: ${folderPath}`, false, true);
2047
+ }
2048
+ const zipFilePath = await index_1.UtilsZip.zipDir(folderPath, {
2049
+ overrideIfZipFileExists: true,
2050
+ });
2051
+ index_1.Helpers.info(`Created zip file: ${zipFilePath}`);
2052
+ this._exit();
2053
+ //#endregion
2054
+ }
2055
+ //#endregion
2056
+ //#region commands / unzip
2057
+ async unzip() {
2058
+ //#region @backendFunc
2059
+ let folderPath = (0, lib_3.crossPlatformPath)(this.firstArg);
2060
+ if (!lib_2.path.isAbsolute(folderPath)) {
2061
+ folderPath = (0, lib_3.crossPlatformPath)([this.cwd, this.firstArg]);
2062
+ }
2063
+ if (!index_1.Helpers.exists(folderPath)) {
2064
+ index_1.Helpers.error(`File or folder to zip does not exist: ${folderPath}`, false, true);
2065
+ }
2066
+ await index_1.UtilsZip.unzipArchive(folderPath);
2067
+ index_1.Helpers.info(`Created zip file: ${folderPath.replace('.zip', '')}`);
2068
+ this._exit();
2069
+ //#endregion
2070
+ }
2071
+ //#endregion
2072
+ //#region commands / start transmission
2073
+ async startTransmission() {
2074
+ //#region @backendFunc
2075
+ await this._removeTransmission();
2076
+ const userProfile = process.env.USERPROFILE || lib_2.os.homedir();
2077
+ const downloadsDir = lib_2.path.join(userProfile, 'Downloads');
2078
+ const configDir = lib_2.path.join(userProfile, 'transmission-config');
2079
+ await lib_2.UtilsProcess.killProcessOnPort(9091);
2080
+ const ctrl = await this.ins.portsWorker.getRemoteControllerFor({
2081
+ methodOptions: {
2082
+ calledFrom: `${lib_1.config.frameworkName} startTransmission`,
2083
+ },
2084
+ });
2085
+ const data = await ctrl
2086
+ .registerAndAssignPort('transmission service for whole system')
2087
+ .request();
2088
+ const mainPort = data.body.json.port;
2089
+ index_1.Helpers.info(`Transmission will use port: ${mainPort}`);
2090
+ const args = [
2091
+ 'run',
2092
+ '-d',
2093
+ '--name',
2094
+ 'transmission',
2095
+ '-p',
2096
+ '9091:9091',
2097
+ '-p',
2098
+ `${mainPort}:${mainPort}`,
2099
+ '-p',
2100
+ `${mainPort}:${mainPort}/udp`,
2101
+ '-e',
2102
+ 'TZ=Europe/Warsaw',
2103
+ '-e',
2104
+ `TRANSMISSION_PEER_PORT=${mainPort}`,
2105
+ '-v',
2106
+ `${downloadsDir}:/downloads`,
2107
+ '-v',
2108
+ `${configDir}:/config`,
2109
+ '--restart',
2110
+ 'unless-stopped',
2111
+ 'linuxserver/transmission:latest',
2112
+ ];
2113
+ console.log('Running:', 'docker', args.join(' '));
2114
+ const child = lib_6.child_process.spawn('docker', args, { stdio: 'inherit' });
2115
+ child.on('exit', code => {
2116
+ if (code === 0) {
2117
+ console.log('✅ Transmission container started');
2118
+ console.log('➡ Open http://localhost:9091 in your browser');
2119
+ }
2120
+ else {
2121
+ console.error('❌ Docker exited with code', code);
2122
+ }
2123
+ this._exit();
2124
+ });
2125
+ //#endregion
2126
+ }
2127
+ async _removeTransmission() {
2128
+ //#region @backendFunc
2129
+ return new Promise(resolve => {
2130
+ const args = ['rm', '-f', 'transmission'];
2131
+ console.log('Running:', 'docker', args.join(' '));
2132
+ const child = lib_6.child_process.spawn('docker', args, { stdio: 'inherit' });
2133
+ child.on('exit', code => {
2134
+ if (code === 0) {
2135
+ console.log('🗑️ Transmission container removed');
2136
+ }
2137
+ else {
2138
+ // In bash `2>$null` would silence errors; here we just log a note
2139
+ console.warn('⚠️ Could not remove container (maybe it doesn’t exist)');
2140
+ }
2141
+ resolve();
2142
+ });
2143
+ });
2144
+ //#endregion
2145
+ }
2146
+ //#endregion
2147
+ //#region commands / backup branch
2148
+ async backupBranch() {
2149
+ //#region @backendFunc
2150
+ await this.project.git.backupBranch(this.firstArg);
2151
+ this._exit();
2152
+ //#endregion
2153
+ }
2154
+ async bb() {
2155
+ //#region @backendFunc
2156
+ await this.backupBranch();
2157
+ //#endregion
2158
+ }
2159
+ //#endregion
2160
+ //#region commands / count code lines
2161
+ async countCodeLines() {
2162
+ //#region @backendFunc
2163
+ await this.countLines();
2164
+ //#endregion
2165
+ }
2166
+ async countCode() {
2167
+ //#region @backendFunc
2168
+ await this.countLines();
2169
+ //#endregion
2170
+ }
2171
+ async countLines() {
2172
+ //#region @backendFunc
2173
+ let extensions = (this.args || []).filter(f => !!f).map(ext => `.${ext}`);
2174
+ extensions = extensions.length ? extensions : ['.ts', '.tsx'];
2175
+ console.log('Counting SLOC for extensions: ', extensions.join(', '));
2176
+ const sloc = require('sloc');
2177
+ let total = {
2178
+ source: 0,
2179
+ comment: 0,
2180
+ single: 0,
2181
+ block: 0,
2182
+ empty: 0,
2183
+ total: 0,
2184
+ };
2185
+ const skip = [
2186
+ 'node_modules',
2187
+ '.',
2188
+ 'tmp-',
2189
+ 'environments',
2190
+ 'dist',
2191
+ 'browser',
2192
+ ];
2193
+ const walk = (folder) => {
2194
+ const entries = lib_2.fse.readdirSync(folder, { withFileTypes: true });
2195
+ for (const entry of entries) {
2196
+ const fullPath = lib_2.path.join(folder, entry.name);
2197
+ if (skip.some(s => entry.name.startsWith(s))) {
2198
+ continue;
2199
+ }
2200
+ if (entry.isDirectory()) {
2201
+ // console.log('Processing: ', path.basename(fullPath));
2202
+ walk(fullPath);
2203
+ }
2204
+ else if (extensions.includes(lib_2.path.extname(entry.name))) {
2205
+ const code = lib_2.fse.readFileSync(fullPath, 'utf8');
2206
+ const stats = sloc(code, lib_2.path.extname(entry.name).slice(1)); // e.g., "ts" or "js"
2207
+ for (const key in total) {
2208
+ total[key] += stats[key] ?? 0;
2209
+ }
2210
+ }
2211
+ }
2212
+ };
2213
+ walk((0, lib_3.crossPlatformPath)([
2214
+ this.cwd,
2215
+ // 'src'
2216
+ ]));
2217
+ console.log('📊 SLOC Results:');
2218
+ console.table(total);
2219
+ this._exit?.(); // your existing exit hook
2220
+ return total;
2221
+ //#endregion
2222
+ }
2223
+ //#endregion
2224
+ //#region commands / is node version ok
2225
+ isNodeVersionOk() {
2226
+ //#region @backendFunc
2227
+ try {
2228
+ lib_2.UtilsOs.isNodeVersionOk({
2229
+ throwErrorIfNotOk: true,
2230
+ });
2231
+ console.info(`Node.js version is OK: ${process.version}`);
2232
+ this._exit();
2233
+ }
2234
+ catch (error) {
2235
+ console.error(error);
2236
+ this._exit(1);
2237
+ }
2238
+ //#endregion
2239
+ }
2240
+ //#endregion
2241
+ //#region commands / pwd
2242
+ pwd() {
2243
+ lib_1.config.frameworkName = 'taon';
2244
+ console.log((0, lib_3.crossPlatformPath)(this.cwd));
2245
+ this._exit();
2246
+ }
2247
+ //#endregion
2248
+ //#region commands / less-more big text files preview
2249
+ async more() {
2250
+ //#region @backendFunc
2251
+ const pathToFile = lib_2.path.isAbsolute(this.firstArg)
2252
+ ? (0, lib_3.crossPlatformPath)(this.firstArg)
2253
+ : (0, lib_3.crossPlatformPath)([this.cwd, this.firstArg]);
2254
+ console.log(`Displaying file: ${pathToFile}`);
2255
+ await lib_4.UtilsTerminal.previewLongListGitLogLike(index_1.Helpers.readFile(pathToFile) || '< empty log file >');
2256
+ this._exit();
2257
+ //#endregion
2258
+ }
2259
+ async less() {
2260
+ //#region @backendFunc
2261
+ await this.more();
2262
+ //#endregion
2263
+ }
2264
+ //#endregion
2265
+ //#region commands / mp3
2266
+ /**
2267
+ * npm install --global bin-version-check-cli
2268
+ * npm i -g yt-dlp
2269
+ * choco install ffmpeg
2270
+ */
2271
+ MP3(args) {
2272
+ //#region @backendFunc
2273
+ const downloadPath = (0, lib_3.crossPlatformPath)([
2274
+ lib_2.UtilsOs.getRealHomeDir(),
2275
+ 'Downloads',
2276
+ 'mp3-from-websites',
2277
+ ]);
2278
+ if (!index_1.Helpers.exists(downloadPath)) {
2279
+ index_1.Helpers.mkdirp(downloadPath);
2280
+ }
2281
+ index_1.Helpers.run(`cd ${downloadPath} && yt-dlp --verbose --extract-audio --audio-format mp3 ` +
2282
+ args, {
2283
+ output: true,
2284
+ cwd: downloadPath,
2285
+ }).sync();
2286
+ this._exit();
2287
+ //#endregion
2288
+ }
2289
+ //#endregion
2290
+ //#region commands / mp4
2291
+ MP4(args) {
2292
+ //#region @backendFunc
2293
+ const downloadPath = (0, lib_3.crossPlatformPath)([
2294
+ lib_2.UtilsOs.getRealHomeDir(),
2295
+ 'Downloads',
2296
+ 'mp4-from-websites',
2297
+ ]);
2298
+ // yt-dlp --print filename -o "%(uploader)s-%(upload_date)s-%(title)s.%(ext)s"
2299
+ index_1.Helpers.run('yt-dlp --verbose -S "res:1080,fps" -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best" ' +
2300
+ args, {
2301
+ output: true,
2302
+ cwd: downloadPath,
2303
+ }).sync();
2304
+ this._exit();
2305
+ //#endregion
2306
+ }
2307
+ //#endregion
2308
+ //#region commands / gif from video
2309
+ gif() {
2310
+ //#region @backendFunc
2311
+ const cwdToProcess = lib_2.path.isAbsolute(this.firstArg)
2312
+ ? lib_2.path.dirname(this.firstArg)
2313
+ : this.cwd;
2314
+ const basenameToProcess = lib_2.path.basename(this.firstArg);
2315
+ const gifDownloadPath = (0, lib_3.crossPlatformPath)([
2316
+ lib_2.UtilsOs.getRealHomeDir(),
2317
+ 'Downloads',
2318
+ 'gif-from-videos',
2319
+ basenameToProcess.replace(lib_2.path.extname(basenameToProcess), '.gif'),
2320
+ ]);
2321
+ const palleteBasename = `${lib_2._.kebabCase(lib_2.path.basename(gifDownloadPath))}-palette.png`;
2322
+ index_1.Helpers.removeFileIfExists([cwdToProcess, palleteBasename]);
2323
+ const quality = `fps=10,scale=960`;
2324
+ index_1.Helpers.info(`Preparing gif from video (creating palette)...`);
2325
+ index_1.Helpers.run(`ffmpeg -i ${basenameToProcess} -vf "${quality}:-1:flags=lanczos,palettegen"` +
2326
+ ` ${palleteBasename} `, {
2327
+ output: true,
2328
+ cwd: cwdToProcess,
2329
+ }).sync();
2330
+ index_1.Helpers.info(`Preparing gif from video (creating video)...`);
2331
+ index_1.Helpers.run(`ffmpeg -i ${basenameToProcess} -i ` +
2332
+ ` ${palleteBasename} -filter_complex ` +
2333
+ `"${quality}:-1:flags=lanczos[x];[x][1:v]paletteuse" ${lib_2.path.basename(gifDownloadPath)}`, {
2334
+ output: true,
2335
+ cwd: cwdToProcess,
2336
+ }).sync();
2337
+ index_1.Helpers.removeFileIfExists(gifDownloadPath);
2338
+ index_1.Helpers.move((0, lib_3.crossPlatformPath)([cwdToProcess, lib_2.path.basename(gifDownloadPath)]), gifDownloadPath);
2339
+ index_1.Helpers.taskDone(`Done creating gif from video:
2340
+
2341
+ ${gifDownloadPath}
2342
+
2343
+ `);
2344
+ index_1.Helpers.openFolderInFileExplorer(lib_2.path.dirname(gifDownloadPath));
2345
+ this._exit();
2346
+ //#endregion
2347
+ }
2348
+ //#endregion
2349
+ //#region commands / kill zscaller
2350
+ killZs() {
2351
+ //#region @backendFunc
2352
+ this.killZscaller();
2353
+ //#endregion
2354
+ }
2355
+ startZs() {
2356
+ //#region @backendFunc
2357
+ this.startZscaller();
2358
+ //#endregion
2359
+ }
2360
+ zsKill() {
2361
+ //#region @backendFunc
2362
+ this.killZscaller();
2363
+ //#endregion
2364
+ }
2365
+ zsStart() {
2366
+ //#region @backendFunc
2367
+ this.startZscaller();
2368
+ //#endregion
2369
+ }
2370
+ startZscaller() {
2371
+ //#region @backendFunc
2372
+ const commands = [
2373
+ // `open -a /Applications/Zscaler/Zscaler.app --hide`,
2374
+ `open -a /Applications/Zscaler/Zscaler.app`,
2375
+ `sudo find /Library/LaunchDaemons -name '*zscaler*' -exec launchctl load {} \\;`,
2376
+ ];
2377
+ for (const cmd of commands) {
2378
+ try {
2379
+ index_1.Helpers.run(cmd, {
2380
+ // stdio that will let me pass password in child process
2381
+ stdio: 'inherit',
2382
+ }).sync();
2383
+ }
2384
+ catch (error) { }
2385
+ }
2386
+ index_1.Helpers.info(`Zscaller started`);
2387
+ this._exit();
2388
+ //#endregion
2389
+ }
2390
+ killZscaller() {
2391
+ //#region @backendFunc
2392
+ const commands = [
2393
+ `find /Library/LaunchAgents -name '*zscaler*' -exec launchctl unload {} \\;`,
2394
+ `sudo find /Library/LaunchDaemons -name '*zscaler*' -exec launchctl unload {} \\;`,
2395
+ `sudo killall -9 Zscaler ZscalerTunnel ZscalerAppServices`,
2396
+ ];
2397
+ for (const cmd of commands) {
2398
+ try {
2399
+ index_1.Helpers.run(cmd, {
2400
+ // stdio that will let me pass password in child process
2401
+ stdio: 'inherit',
2402
+ }).sync();
2403
+ }
2404
+ catch (error) { }
2405
+ }
2406
+ index_1.Helpers.info(`Zscaller killed`);
2407
+ this._exit();
2408
+ //#endregion
2409
+ }
2410
+ //#endregion
2411
+ //#region commands / has command
2412
+ async hasCommand() {
2413
+ //#region @backendFunc
2414
+ if (!this.firstArg) {
2415
+ index_1.Helpers.error(`You need to provide command name to check`, false, true);
2416
+ }
2417
+ const hasSudo = await lib_2.UtilsOs.commandExistsAsync(this.firstArg);
2418
+ console.log(`[ASYNC] Your os has "${this.firstArg}" command: ${hasSudo}`);
2419
+ this._exit();
2420
+ //#endregion
2421
+ }
2422
+ hasCommandSync() {
2423
+ //#region @backendFunc
2424
+ if (!this.firstArg) {
2425
+ index_1.Helpers.error(`You need to provide command name to check`, false, true);
2426
+ }
2427
+ const hasSudo = lib_2.UtilsOs.commandExistsSync(this.firstArg);
2428
+ console.log(`[sync version] Your os has "${this.firstArg}" command: ${hasSudo}`);
2429
+ this._exit();
2430
+ //#endregion
2431
+ }
2432
+ //#endregion
2433
+ //#region commands / public ip address
2434
+ async publicIpAddress() {
2435
+ const ip = await lib_5.UtilsNetwork.getCurrentPublicIpAddress();
2436
+ console.log(`Your public IP address is: ${ip}`);
2437
+ this._exit();
2438
+ }
2439
+ async publicIp() {
2440
+ //#region @backendFunc
2441
+ await this.publicIpAddress();
2442
+ //#endregion
2443
+ }
2444
+ //#endregion
2445
+ //#region commands / open origins in vscode
2446
+ async localIps() {
2447
+ const firstActiveLocalIp = await lib_5.UtilsNetwork.getFirstIpV4LocalActiveIpAddress();
2448
+ console.log(`Your first active local IP address is: ${firstActiveLocalIp} `);
2449
+ const ips = await lib_5.UtilsNetwork.getLocalIpAddresses();
2450
+ for (let index = 0; index < ips.length; index++) {
2451
+ const ip = ips[index];
2452
+ // console.log(ip);
2453
+ console.log(`${index + 1}. Local IP address is: ` +
2454
+ `${ip.address}, type: ${ip.type}`);
2455
+ }
2456
+ this._exit();
2457
+ }
2458
+ //#endregion
2459
+ //#region commands / is online
2460
+ async isOnline() {
2461
+ //#region @backendFunc
2462
+ console.log(`Is online: ${await lib_5.UtilsNetwork.checkIfServerPings(this.firstArg)}`);
2463
+ this._exit();
2464
+ //#endregion
2465
+ }
2466
+ //#endregion
2467
+ //#region commands / configure bash and shell
2468
+ async configureBash() {
2469
+ // ! TODO @UNCOMMENT
2470
+ // await UtilsTerminal.configureBashOrShell();
2471
+ }
2472
+ async configureShell() {
2473
+ // ! TODO @UNCOMMENT
2474
+ // await UtilsTerminal.configureBashOrShell();
2475
+ }
2476
+ confBash() {
2477
+ this.configureBash();
2478
+ }
2479
+ confShell() {
2480
+ this.configureShell();
2481
+ }
2482
+ }
2483
+ exports.BaseGlobalCommandLine = BaseGlobalCommandLine;
2484
+ //# sourceMappingURL=base-global-command-line.js.map