tnp-helpers 13.1.1 → 13.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/app.d.ts +1 -1
  2. package/app.js +6 -6
  3. package/browser/README.md +24 -24
  4. package/browser/esm2020/lib/base-component.mjs +47 -47
  5. package/browser/esm2020/lib/base-formly-component.mjs +125 -125
  6. package/browser/esm2020/lib/condition-wait.mjs +53 -53
  7. package/browser/esm2020/lib/constants.mjs +6 -6
  8. package/browser/esm2020/lib/dual-component-ctrl.mjs +120 -120
  9. package/browser/esm2020/lib/helpers-array-obj.mjs +80 -80
  10. package/browser/esm2020/lib/helpers-environment.mjs +30 -30
  11. package/browser/esm2020/lib/helpers-numbers.mjs +5 -5
  12. package/browser/esm2020/lib/helpers-strings-regexes.mjs +48 -48
  13. package/browser/esm2020/lib/helpers-strings.mjs +257 -257
  14. package/browser/esm2020/lib/helpers.mjs +276 -276
  15. package/browser/esm2020/lib/index.mjs +14 -14
  16. package/browser/esm2020/lib/long-press.directive.mjs +111 -111
  17. package/browser/esm2020/lib/project.mjs +413 -413
  18. package/browser/esm2020/lib/resize-service.mjs +19 -19
  19. package/browser/esm2020/public-api.mjs +1 -1
  20. package/browser/esm2020/tnp-helpers.mjs +4 -4
  21. package/browser/fesm2015/tnp-helpers.mjs +1535 -1535
  22. package/browser/fesm2020/tnp-helpers.mjs +1527 -1527
  23. package/browser/lib/base-component.d.ts +17 -17
  24. package/browser/lib/base-formly-component.d.ts +31 -31
  25. package/browser/lib/condition-wait.d.ts +8 -8
  26. package/browser/lib/constants.d.ts +6 -6
  27. package/browser/lib/dual-component-ctrl.d.ts +25 -25
  28. package/browser/lib/helpers-array-obj.d.ts +15 -15
  29. package/browser/lib/helpers-environment.d.ts +5 -5
  30. package/browser/lib/helpers-numbers.d.ts +3 -3
  31. package/browser/lib/helpers-strings-regexes.d.ts +28 -28
  32. package/browser/lib/helpers-strings.d.ts +50 -50
  33. package/browser/lib/helpers.d.ts +28 -28
  34. package/browser/lib/index.d.ts +9 -9
  35. package/browser/lib/long-press.directive.d.ts +25 -25
  36. package/browser/lib/project.d.ts +91 -91
  37. package/browser/lib/resize-service.d.ts +9 -9
  38. package/browser/public-api.d.ts +1 -1
  39. package/browser/tnp-helpers.d.ts +5 -5
  40. package/client/README.md +24 -24
  41. package/client/esm2020/lib/base-component.mjs +47 -47
  42. package/client/esm2020/lib/base-formly-component.mjs +125 -125
  43. package/client/esm2020/lib/condition-wait.mjs +53 -53
  44. package/client/esm2020/lib/constants.mjs +6 -6
  45. package/client/esm2020/lib/dual-component-ctrl.mjs +120 -120
  46. package/client/esm2020/lib/helpers-array-obj.mjs +80 -80
  47. package/client/esm2020/lib/helpers-environment.mjs +30 -30
  48. package/client/esm2020/lib/helpers-numbers.mjs +5 -5
  49. package/client/esm2020/lib/helpers-strings-regexes.mjs +48 -48
  50. package/client/esm2020/lib/helpers-strings.mjs +257 -257
  51. package/client/esm2020/lib/helpers.mjs +276 -276
  52. package/client/esm2020/lib/index.mjs +14 -14
  53. package/client/esm2020/lib/long-press.directive.mjs +111 -111
  54. package/client/esm2020/lib/project.mjs +413 -413
  55. package/client/esm2020/lib/resize-service.mjs +19 -19
  56. package/client/esm2020/public-api.mjs +1 -1
  57. package/client/esm2020/tnp-helpers.mjs +4 -4
  58. package/client/fesm2015/tnp-helpers.mjs +1535 -1535
  59. package/client/fesm2020/tnp-helpers.mjs +1527 -1527
  60. package/client/lib/base-component.d.ts +17 -17
  61. package/client/lib/base-formly-component.d.ts +31 -31
  62. package/client/lib/condition-wait.d.ts +8 -8
  63. package/client/lib/constants.d.ts +6 -6
  64. package/client/lib/dual-component-ctrl.d.ts +25 -25
  65. package/client/lib/helpers-array-obj.d.ts +15 -15
  66. package/client/lib/helpers-environment.d.ts +5 -5
  67. package/client/lib/helpers-numbers.d.ts +3 -3
  68. package/client/lib/helpers-strings-regexes.d.ts +28 -28
  69. package/client/lib/helpers-strings.d.ts +50 -50
  70. package/client/lib/helpers.d.ts +28 -28
  71. package/client/lib/index.d.ts +9 -9
  72. package/client/lib/long-press.directive.d.ts +25 -25
  73. package/client/lib/project.d.ts +91 -91
  74. package/client/lib/resize-service.d.ts +9 -9
  75. package/client/public-api.d.ts +1 -1
  76. package/client/tnp-helpers.d.ts +5 -5
  77. package/index.d.ts +1 -1
  78. package/index.js +5 -5
  79. package/lib/angular.helper.d.ts +22 -22
  80. package/lib/angular.helper.js +50 -50
  81. package/lib/base-component.d.ts +1 -1
  82. package/lib/base-component.js +6 -6
  83. package/lib/base-formly-component.d.ts +1 -1
  84. package/lib/base-formly-component.js +6 -6
  85. package/lib/condition-wait.d.ts +8 -8
  86. package/lib/condition-wait.js +94 -94
  87. package/lib/constants.d.ts +6 -6
  88. package/lib/constants.js +10 -10
  89. package/lib/dual-component-ctrl.d.ts +1 -1
  90. package/lib/dual-component-ctrl.js +6 -6
  91. package/lib/git-project.d.ts +44 -44
  92. package/lib/git-project.js +195 -195
  93. package/lib/helpers-array-obj.d.ts +15 -15
  94. package/lib/helpers-array-obj.js +88 -88
  95. package/lib/helpers-cli-tool.backend.d.ts +45 -45
  96. package/lib/helpers-cli-tool.backend.js +293 -293
  97. package/lib/helpers-dependencies.backend.d.ts +11 -11
  98. package/lib/helpers-dependencies.backend.js +105 -105
  99. package/lib/helpers-environment.d.ts +5 -5
  100. package/lib/helpers-environment.js +35 -35
  101. package/lib/helpers-file-folders.backend.d.ts +84 -84
  102. package/lib/helpers-file-folders.backend.js +736 -736
  103. package/lib/helpers-git.backend.d.ts +35 -35
  104. package/lib/helpers-git.backend.js +541 -545
  105. package/lib/helpers-git.backend.js.map +1 -1
  106. package/lib/helpers-json5.backend.d.ts +16 -16
  107. package/lib/helpers-json5.backend.js +70 -70
  108. package/lib/helpers-morphi-framework.backend.d.ts +4 -4
  109. package/lib/helpers-morphi-framework.backend.js +49 -49
  110. package/lib/helpers-network.backend.d.ts +8 -8
  111. package/lib/helpers-network.backend.js +48 -48
  112. package/lib/helpers-npm.backend.d.ts +3 -3
  113. package/lib/helpers-npm.backend.js +17 -17
  114. package/lib/helpers-numbers.d.ts +3 -3
  115. package/lib/helpers-numbers.js +11 -11
  116. package/lib/helpers-path.backend.d.ts +7 -7
  117. package/lib/helpers-path.backend.js +36 -36
  118. package/lib/helpers-process.backend.d.ts +57 -57
  119. package/lib/helpers-process.backend.js +529 -529
  120. package/lib/helpers-process.backend.js.map +1 -1
  121. package/lib/helpers-strings-regexes.d.ts +28 -28
  122. package/lib/helpers-strings-regexes.js +60 -60
  123. package/lib/helpers-strings.d.ts +50 -50
  124. package/lib/helpers-strings.js +265 -265
  125. package/lib/helpers-system-terminal.backend.d.ts +5 -5
  126. package/lib/helpers-system-terminal.backend.js +53 -53
  127. package/lib/helpers.d.ts +67 -67
  128. package/lib/helpers.js +391 -391
  129. package/lib/index.d.ts +6 -6
  130. package/lib/index.js +19 -19
  131. package/lib/long-press.directive.d.ts +22 -22
  132. package/lib/long-press.directive.js +141 -141
  133. package/lib/merge-helpers.backend.d.ts +23 -23
  134. package/lib/merge-helpers.backend.js +108 -108
  135. package/lib/project.d.ts +94 -94
  136. package/lib/project.js +422 -422
  137. package/lib/resize-service.d.ts +6 -6
  138. package/lib/resize-service.js +24 -24
  139. package/lib/ts-code/index.d.ts +1 -1
  140. package/lib/ts-code/index.js +7 -7
  141. package/lib/ts-code/ts-code-extractor.d.ts +14 -14
  142. package/lib/ts-code/ts-code-extractor.js +46 -46
  143. package/lib/ts-code/ts-code-modifier.backend.d.ts +12 -12
  144. package/lib/ts-code/ts-code-modifier.backend.js +70 -70
  145. package/package.json +5 -5
  146. package/package.json_devDependencies.json +222 -222
  147. package/package.json_tnp.json5 +41 -41
  148. package/tmp-environment.json +36 -35
  149. package/websql/README.md +24 -24
  150. package/websql/esm2020/lib/base-component.mjs +47 -47
  151. package/websql/esm2020/lib/base-formly-component.mjs +125 -125
  152. package/websql/esm2020/lib/condition-wait.mjs +53 -53
  153. package/websql/esm2020/lib/constants.mjs +6 -6
  154. package/websql/esm2020/lib/dual-component-ctrl.mjs +120 -120
  155. package/websql/esm2020/lib/helpers-array-obj.mjs +80 -80
  156. package/websql/esm2020/lib/helpers-environment.mjs +30 -30
  157. package/websql/esm2020/lib/helpers-numbers.mjs +5 -5
  158. package/websql/esm2020/lib/helpers-strings-regexes.mjs +48 -48
  159. package/websql/esm2020/lib/helpers-strings.mjs +257 -257
  160. package/websql/esm2020/lib/helpers.mjs +276 -276
  161. package/websql/esm2020/lib/index.mjs +14 -14
  162. package/websql/esm2020/lib/long-press.directive.mjs +111 -111
  163. package/websql/esm2020/lib/project.mjs +413 -413
  164. package/websql/esm2020/lib/resize-service.mjs +19 -19
  165. package/websql/esm2020/public-api.mjs +1 -1
  166. package/websql/esm2020/tnp-helpers.mjs +4 -4
  167. package/websql/fesm2015/tnp-helpers.mjs +1535 -1535
  168. package/websql/fesm2020/tnp-helpers.mjs +1527 -1527
  169. package/websql/lib/base-component.d.ts +17 -17
  170. package/websql/lib/base-formly-component.d.ts +31 -31
  171. package/websql/lib/condition-wait.d.ts +8 -8
  172. package/websql/lib/constants.d.ts +6 -6
  173. package/websql/lib/dual-component-ctrl.d.ts +25 -25
  174. package/websql/lib/helpers-array-obj.d.ts +15 -15
  175. package/websql/lib/helpers-environment.d.ts +5 -5
  176. package/websql/lib/helpers-numbers.d.ts +3 -3
  177. package/websql/lib/helpers-strings-regexes.d.ts +28 -28
  178. package/websql/lib/helpers-strings.d.ts +50 -50
  179. package/websql/lib/helpers.d.ts +28 -28
  180. package/websql/lib/index.d.ts +9 -9
  181. package/websql/lib/long-press.directive.d.ts +25 -25
  182. package/websql/lib/project.d.ts +91 -91
  183. package/websql/lib/resize-service.d.ts +9 -9
  184. package/websql/public-api.d.ts +1 -1
  185. package/websql/tnp-helpers.d.ts +5 -5
@@ -1,293 +1,293 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelpersCliTool = void 0;
4
- var tnp_core_1 = require("tnp-core");
5
- var index_1 = require("./index");
6
- var typescript_class_helpers_1 = require("typescript-class-helpers");
7
- var tnp_config_1 = require("tnp-config");
8
- var HelpersCliTool = /** @class */ (function () {
9
- function HelpersCliTool() {
10
- }
11
- /**
12
- * return simplified version of command:
13
- * example: tnp HELLO:WORLD
14
- * will be: tnp helloworld
15
- *
16
- * or: `tnp ${$START}`
17
- * will be `tnp start`
18
- *
19
- * @param commandStringOrClass
20
- */
21
- HelpersCliTool.prototype.simplifiedCmd = function (commandStringOrClass, shortVersion) {
22
- if (shortVersion === void 0) { shortVersion = false; }
23
- if (tnp_core_1._.isFunction(commandStringOrClass)) {
24
- commandStringOrClass = typescript_class_helpers_1.CLASS.getName(commandStringOrClass);
25
- }
26
- if (!commandStringOrClass) {
27
- commandStringOrClass = '';
28
- }
29
- commandStringOrClass = tnp_core_1._
30
- .kebabCase(commandStringOrClass)
31
- .replace(/\$/g, '')
32
- .replace(/\-/g, '')
33
- .replace(/\:/g, '')
34
- .replace(/\_/g, '')
35
- .toLowerCase();
36
- if (shortVersion) {
37
- var shortKey = Object.keys(tnp_config_1.config.argsReplacements).find(function (key) {
38
- var v = index_1.Helpers.cliTool.simplifiedCmd(tnp_config_1.config.argsReplacements[key]);
39
- return v.trim() === commandStringOrClass.trim();
40
- });
41
- return shortKey;
42
- }
43
- return commandStringOrClass;
44
- };
45
- HelpersCliTool.prototype.argsFromBegin = function (argumentsCommands, argsFunc) {
46
- var tmpArgumentsCommands = argumentsCommands;
47
- var resolved = [];
48
- if (tnp_core_1._.isString(tmpArgumentsCommands)) {
49
- tmpArgumentsCommands = tmpArgumentsCommands.split(' ');
50
- }
51
- var commandString = (tmpArgumentsCommands || []);
52
- if (tnp_core_1._.isArray(commandString) && commandString.length > 0) {
53
- while (true) {
54
- if (commandString.length === 0) {
55
- break;
56
- }
57
- var a = commandString.shift();
58
- var v = argsFunc(a);
59
- if (!tnp_core_1._.isNil(v)) {
60
- resolved.push(v);
61
- continue;
62
- }
63
- commandString.unshift(a);
64
- break;
65
- }
66
- }
67
- else {
68
- commandString = [];
69
- }
70
- return { resolved: resolved, commandString: (commandString).join(' ') };
71
- };
72
- HelpersCliTool.prototype.cleanCommand = function (command, minimistOption) {
73
- var isArray = tnp_core_1._.isArray(command);
74
- if (isArray) {
75
- command = command.join(' ');
76
- }
77
- command = command;
78
- minimistOption = tnp_core_1._.cloneDeep(minimistOption);
79
- delete minimistOption['_'];
80
- delete minimistOption['>'];
81
- if (!tnp_core_1._.isString(command)) {
82
- command = '';
83
- }
84
- tnp_core_1._.keys(minimistOption).forEach(function (paramName) {
85
- var value = minimistOption[paramName];
86
- if (!tnp_core_1._.isArray(value)) {
87
- value = [value];
88
- }
89
- value.map(function (v) { return v.toString(); })
90
- .forEach(function (v) {
91
- [
92
- paramName,
93
- tnp_core_1._.kebabCase(paramName),
94
- tnp_core_1._.camelCase(paramName)
95
- ].forEach(function (p) {
96
- command = command
97
- .replace(new RegExp(("\\-\\-".concat(p, "\\=").concat(v)), 'g'), '')
98
- .replace(new RegExp(("\\-\\-".concat(p, "\\ *").concat(v)), 'g'), '')
99
- .replace(new RegExp(("\\-\\-".concat(p)), 'g'), '');
100
- });
101
- });
102
- });
103
- return command.trim();
104
- };
105
- HelpersCliTool.prototype.argsFrom = function (args) {
106
- if (tnp_core_1._.isArray(args)) {
107
- args = index_1.Helpers.cliTool.removeStartEndCommandChars(args.join(' ')).split(' ');
108
- }
109
- if (tnp_core_1._.isString(args)) {
110
- args = index_1.Helpers.cliTool.removeStartEndCommandChars(args).split(' ');
111
- }
112
- var obj = require('minimist')(args || []);
113
- Object.keys(obj).forEach(function (key) {
114
- var v = obj[key];
115
- if (v === 'true') {
116
- obj[key] = true;
117
- }
118
- if (v === 'false') {
119
- obj[key] = false;
120
- }
121
- });
122
- return (tnp_core_1._.isObject(obj) ? obj : {});
123
- };
124
- HelpersCliTool.prototype.removeStartEndCommandChars = function (command) {
125
- return (command || '')
126
- .replace(/^\"/, '')
127
- .replace(/^\'/, '')
128
- .replace(/\"$/, '')
129
- .replace(/\'$/, '')
130
- .trim();
131
- };
132
- HelpersCliTool.prototype.resolveProject = function (args, CurrentProject, ProjectClass) {
133
- if (!CurrentProject) {
134
- return void 0;
135
- }
136
- if (tnp_core_1._.isString(args)) {
137
- args = args.split(' ');
138
- }
139
- var firstArg = tnp_core_1._.first(args).replace(/\/$/, '');
140
- if (firstArg) {
141
- if (tnp_core_1.path.isAbsolute(firstArg)) {
142
- return ProjectClass.From(firstArg);
143
- }
144
- return ProjectClass.From(tnp_core_1.path.join(CurrentProject.location, firstArg));
145
- }
146
- };
147
- /**
148
- * Resolve child project when accessing from parent workspace, container etc...
149
- * @param args string or string[] from cli args
150
- * @param CurrentProject project from process.cwd()
151
- */
152
- HelpersCliTool.prototype.resolveChildProject = function (args, CurrentProject) {
153
- if (!CurrentProject) {
154
- return void 0;
155
- }
156
- if (tnp_core_1._.isString(args)) {
157
- args = args.split(' ');
158
- }
159
- var firstArg = tnp_core_1._.first(args);
160
- if (firstArg) {
161
- firstArg = firstArg.replace(/\/$/, '');
162
- var child = CurrentProject.children.find(function (c) { return c.name === firstArg; });
163
- if (child) {
164
- CurrentProject = child;
165
- }
166
- }
167
- return CurrentProject;
168
- };
169
- HelpersCliTool.prototype.resolveProjectsFromArgs = function (args, CurrentProject, ProjectClass) {
170
- var projects = [];
171
- if (!CurrentProject) {
172
- return [];
173
- }
174
- if (tnp_core_1._.isString(args)) {
175
- args = args.split(' ');
176
- }
177
- args.forEach(function (a) {
178
- var child = ProjectClass.From(tnp_core_1.path.join(CurrentProject.location, a));
179
- if (child) {
180
- projects.push(child);
181
- }
182
- });
183
- return projects;
184
- };
185
- /**
186
- * Check if your function name fits into command line param
187
- *
188
- * @param name name of function
189
- * @param restOfArgs arguments from command line
190
- */
191
- HelpersCliTool.prototype.match = function (name, restOfArgs) {
192
- var isMatch = false;
193
- var counter = 0;
194
- isMatch = !!restOfArgs
195
- .filter(function (a) { return !a.startsWith('--'); }) // TODO fix this also for other special paramters
196
- .find(function (vv, i) {
197
- if (++counter > 3) {
198
- // console.log(`counter NOT OK ${vv}`)
199
- return false;
200
- }
201
- // console.log(`counter ok for ${vv}`)
202
- var nameInKC = index_1.Helpers.cliTool.simplifiedCmd(name);
203
- var argInKC = index_1.Helpers.cliTool.simplifiedCmd(vv);
204
- var condition = (nameInKC === argInKC);
205
- if (condition) {
206
- restOfArgs = tnp_core_1._.slice(restOfArgs, i + 1, restOfArgs.length);
207
- }
208
- return condition;
209
- });
210
- return { isMatch: isMatch, restOfArgs: restOfArgs };
211
- };
212
- //#region @backend
213
- HelpersCliTool.prototype.globalArgumentsParser = function (argsv) {
214
- var options = require('minimist')(argsv);
215
- var toCheck = {
216
- 'tnpNonInteractive': void 0,
217
- 'findNearestProject': void 0,
218
- 'findNearestProjectWithGitRoot': void 0,
219
- 'findNearestProjectType': void 0,
220
- 'findNearestProjectTypeWithGitRoot': void 0,
221
- 'cwd': void 0
222
- };
223
- Object.keys(toCheck).forEach(function (key) {
224
- toCheck[key] = options[key];
225
- });
226
- options = tnp_core_1._.cloneDeep(toCheck);
227
- var findNearestProjectWithGitRoot = options.findNearestProjectWithGitRoot, findNearestProjectTypeWithGitRoot = options.findNearestProjectTypeWithGitRoot, cwd = options.cwd;
228
- var findNearestProject = options.findNearestProject, findNearestProjectType = options.findNearestProjectType;
229
- Object
230
- .keys(options)
231
- .filter(function (key) { return key.startsWith('tnp'); })
232
- .forEach(function (key) {
233
- options[key] = !!options[key];
234
- global[key] = options[key];
235
- });
236
- var cwdFromArgs = cwd;
237
- var findProjectWithGitRoot = !!findNearestProjectWithGitRoot ||
238
- !!findNearestProjectTypeWithGitRoot;
239
- if (!!findNearestProjectWithGitRoot) {
240
- findNearestProject = findNearestProjectWithGitRoot;
241
- }
242
- if (tnp_core_1._.isString(findNearestProjectTypeWithGitRoot)) {
243
- findNearestProjectType = findNearestProjectTypeWithGitRoot;
244
- }
245
- if (tnp_core_1._.isString(cwdFromArgs)) {
246
- var nearest = void 0;
247
- if (findNearestProject || tnp_core_1._.isString(findNearestProjectType)) {
248
- var classProject = typescript_class_helpers_1.CLASS.getBy('Project');
249
- nearest = classProject.nearestTo(cwdFromArgs, {
250
- type: findNearestProjectType,
251
- findGitRoot: findProjectWithGitRoot,
252
- });
253
- if (!nearest) {
254
- index_1.Helpers.error("Not able to find neerest project for arguments: [\n ".concat(argsv.join(',\n'), "\n]"), false, true);
255
- }
256
- }
257
- if (nearest) {
258
- cwdFromArgs = nearest.location;
259
- }
260
- if (tnp_core_1.fse.existsSync(cwdFromArgs) && !tnp_core_1.fse.lstatSync(cwdFromArgs).isDirectory()) {
261
- cwdFromArgs = tnp_core_1.path.dirname(cwdFromArgs);
262
- }
263
- if (tnp_core_1.fse.existsSync(cwdFromArgs) && tnp_core_1.fse.lstatSync(cwdFromArgs).isDirectory()) {
264
- process.chdir(cwdFromArgs);
265
- }
266
- else {
267
- index_1.Helpers.error("Incorrect --cwd argument for args: [\n ".concat(argsv.join(',\n'), "\n]"), false, true);
268
- }
269
- }
270
- argsv = removeArg('findNearestProjectType', argsv);
271
- Object.keys(toCheck).forEach(function (argName) {
272
- argsv = removeArg(argName, argsv);
273
- });
274
- return argsv;
275
- };
276
- return HelpersCliTool;
277
- }());
278
- exports.HelpersCliTool = HelpersCliTool;
279
- function removeArg(arg, argsv) {
280
- argsv = argsv.filter(function (f, i) {
281
- var regexString = "^\\-\\-(".concat(arg, "$|").concat(arg, "\\=)+");
282
- if ((new RegExp(regexString)).test(f)) {
283
- var nextParam = argsv[i + 1];
284
- if (nextParam && !nextParam.startsWith("--")) {
285
- argsv[i + 1] = '';
286
- }
287
- return false;
288
- }
289
- return true;
290
- }).filter(function (f) { return !!f; });
291
- return argsv;
292
- }
293
- //# sourceMappingURL=C:/Users/darek/projects/npm/tnp-helpers/tmp-bundle-release/bundle/project/tnp-helpers/bundle-nocutsrc/lib/helpers-cli-tool.backend.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HelpersCliTool = void 0;
4
+ var tnp_core_1 = require("tnp-core");
5
+ var index_1 = require("./index");
6
+ var typescript_class_helpers_1 = require("typescript-class-helpers");
7
+ var tnp_config_1 = require("tnp-config");
8
+ var HelpersCliTool = /** @class */ (function () {
9
+ function HelpersCliTool() {
10
+ }
11
+ /**
12
+ * return simplified version of command:
13
+ * example: tnp HELLO:WORLD
14
+ * will be: tnp helloworld
15
+ *
16
+ * or: `tnp ${$START}`
17
+ * will be `tnp start`
18
+ *
19
+ * @param commandStringOrClass
20
+ */
21
+ HelpersCliTool.prototype.simplifiedCmd = function (commandStringOrClass, shortVersion) {
22
+ if (shortVersion === void 0) { shortVersion = false; }
23
+ if (tnp_core_1._.isFunction(commandStringOrClass)) {
24
+ commandStringOrClass = typescript_class_helpers_1.CLASS.getName(commandStringOrClass);
25
+ }
26
+ if (!commandStringOrClass) {
27
+ commandStringOrClass = '';
28
+ }
29
+ commandStringOrClass = tnp_core_1._
30
+ .kebabCase(commandStringOrClass)
31
+ .replace(/\$/g, '')
32
+ .replace(/\-/g, '')
33
+ .replace(/\:/g, '')
34
+ .replace(/\_/g, '')
35
+ .toLowerCase();
36
+ if (shortVersion) {
37
+ var shortKey = Object.keys(tnp_config_1.config.argsReplacements).find(function (key) {
38
+ var v = index_1.Helpers.cliTool.simplifiedCmd(tnp_config_1.config.argsReplacements[key]);
39
+ return v.trim() === commandStringOrClass.trim();
40
+ });
41
+ return shortKey;
42
+ }
43
+ return commandStringOrClass;
44
+ };
45
+ HelpersCliTool.prototype.argsFromBegin = function (argumentsCommands, argsFunc) {
46
+ var tmpArgumentsCommands = argumentsCommands;
47
+ var resolved = [];
48
+ if (tnp_core_1._.isString(tmpArgumentsCommands)) {
49
+ tmpArgumentsCommands = tmpArgumentsCommands.split(' ');
50
+ }
51
+ var commandString = (tmpArgumentsCommands || []);
52
+ if (tnp_core_1._.isArray(commandString) && commandString.length > 0) {
53
+ while (true) {
54
+ if (commandString.length === 0) {
55
+ break;
56
+ }
57
+ var a = commandString.shift();
58
+ var v = argsFunc(a);
59
+ if (!tnp_core_1._.isNil(v)) {
60
+ resolved.push(v);
61
+ continue;
62
+ }
63
+ commandString.unshift(a);
64
+ break;
65
+ }
66
+ }
67
+ else {
68
+ commandString = [];
69
+ }
70
+ return { resolved: resolved, commandString: (commandString).join(' ') };
71
+ };
72
+ HelpersCliTool.prototype.cleanCommand = function (command, minimistOption) {
73
+ var isArray = tnp_core_1._.isArray(command);
74
+ if (isArray) {
75
+ command = command.join(' ');
76
+ }
77
+ command = command;
78
+ minimistOption = tnp_core_1._.cloneDeep(minimistOption);
79
+ delete minimistOption['_'];
80
+ delete minimistOption['>'];
81
+ if (!tnp_core_1._.isString(command)) {
82
+ command = '';
83
+ }
84
+ tnp_core_1._.keys(minimistOption).forEach(function (paramName) {
85
+ var value = minimistOption[paramName];
86
+ if (!tnp_core_1._.isArray(value)) {
87
+ value = [value];
88
+ }
89
+ value.map(function (v) { return v.toString(); })
90
+ .forEach(function (v) {
91
+ [
92
+ paramName,
93
+ tnp_core_1._.kebabCase(paramName),
94
+ tnp_core_1._.camelCase(paramName)
95
+ ].forEach(function (p) {
96
+ command = command
97
+ .replace(new RegExp(("\\-\\-".concat(p, "\\=").concat(v)), 'g'), '')
98
+ .replace(new RegExp(("\\-\\-".concat(p, "\\ *").concat(v)), 'g'), '')
99
+ .replace(new RegExp(("\\-\\-".concat(p)), 'g'), '');
100
+ });
101
+ });
102
+ });
103
+ return command.trim();
104
+ };
105
+ HelpersCliTool.prototype.argsFrom = function (args) {
106
+ if (tnp_core_1._.isArray(args)) {
107
+ args = index_1.Helpers.cliTool.removeStartEndCommandChars(args.join(' ')).split(' ');
108
+ }
109
+ if (tnp_core_1._.isString(args)) {
110
+ args = index_1.Helpers.cliTool.removeStartEndCommandChars(args).split(' ');
111
+ }
112
+ var obj = require('minimist')(args || []);
113
+ Object.keys(obj).forEach(function (key) {
114
+ var v = obj[key];
115
+ if (v === 'true') {
116
+ obj[key] = true;
117
+ }
118
+ if (v === 'false') {
119
+ obj[key] = false;
120
+ }
121
+ });
122
+ return (tnp_core_1._.isObject(obj) ? obj : {});
123
+ };
124
+ HelpersCliTool.prototype.removeStartEndCommandChars = function (command) {
125
+ return (command || '')
126
+ .replace(/^\"/, '')
127
+ .replace(/^\'/, '')
128
+ .replace(/\"$/, '')
129
+ .replace(/\'$/, '')
130
+ .trim();
131
+ };
132
+ HelpersCliTool.prototype.resolveProject = function (args, CurrentProject, ProjectClass) {
133
+ if (!CurrentProject) {
134
+ return void 0;
135
+ }
136
+ if (tnp_core_1._.isString(args)) {
137
+ args = args.split(' ');
138
+ }
139
+ var firstArg = tnp_core_1._.first(args).replace(/\/$/, '');
140
+ if (firstArg) {
141
+ if (tnp_core_1.path.isAbsolute(firstArg)) {
142
+ return ProjectClass.From(firstArg);
143
+ }
144
+ return ProjectClass.From(tnp_core_1.path.join(CurrentProject.location, firstArg));
145
+ }
146
+ };
147
+ /**
148
+ * Resolve child project when accessing from parent workspace, container etc...
149
+ * @param args string or string[] from cli args
150
+ * @param CurrentProject project from process.cwd()
151
+ */
152
+ HelpersCliTool.prototype.resolveChildProject = function (args, CurrentProject) {
153
+ if (!CurrentProject) {
154
+ return void 0;
155
+ }
156
+ if (tnp_core_1._.isString(args)) {
157
+ args = args.split(' ');
158
+ }
159
+ var firstArg = tnp_core_1._.first(args);
160
+ if (firstArg) {
161
+ firstArg = firstArg.replace(/\/$/, '');
162
+ var child = CurrentProject.children.find(function (c) { return c.name === firstArg; });
163
+ if (child) {
164
+ CurrentProject = child;
165
+ }
166
+ }
167
+ return CurrentProject;
168
+ };
169
+ HelpersCliTool.prototype.resolveProjectsFromArgs = function (args, CurrentProject, ProjectClass) {
170
+ var projects = [];
171
+ if (!CurrentProject) {
172
+ return [];
173
+ }
174
+ if (tnp_core_1._.isString(args)) {
175
+ args = args.split(' ');
176
+ }
177
+ args.forEach(function (a) {
178
+ var child = ProjectClass.From(tnp_core_1.path.join(CurrentProject.location, a));
179
+ if (child) {
180
+ projects.push(child);
181
+ }
182
+ });
183
+ return projects;
184
+ };
185
+ /**
186
+ * Check if your function name fits into command line param
187
+ *
188
+ * @param name name of function
189
+ * @param restOfArgs arguments from command line
190
+ */
191
+ HelpersCliTool.prototype.match = function (name, restOfArgs) {
192
+ var isMatch = false;
193
+ var counter = 0;
194
+ isMatch = !!restOfArgs
195
+ .filter(function (a) { return !a.startsWith('--'); }) // TODO fix this also for other special paramters
196
+ .find(function (vv, i) {
197
+ if (++counter > 3) {
198
+ // console.log(`counter NOT OK ${vv}`)
199
+ return false;
200
+ }
201
+ // console.log(`counter ok for ${vv}`)
202
+ var nameInKC = index_1.Helpers.cliTool.simplifiedCmd(name);
203
+ var argInKC = index_1.Helpers.cliTool.simplifiedCmd(vv);
204
+ var condition = (nameInKC === argInKC);
205
+ if (condition) {
206
+ restOfArgs = tnp_core_1._.slice(restOfArgs, i + 1, restOfArgs.length);
207
+ }
208
+ return condition;
209
+ });
210
+ return { isMatch: isMatch, restOfArgs: restOfArgs };
211
+ };
212
+ //#region @backend
213
+ HelpersCliTool.prototype.globalArgumentsParser = function (argsv) {
214
+ var options = require('minimist')(argsv);
215
+ var toCheck = {
216
+ 'tnpNonInteractive': void 0,
217
+ 'findNearestProject': void 0,
218
+ 'findNearestProjectWithGitRoot': void 0,
219
+ 'findNearestProjectType': void 0,
220
+ 'findNearestProjectTypeWithGitRoot': void 0,
221
+ 'cwd': void 0
222
+ };
223
+ Object.keys(toCheck).forEach(function (key) {
224
+ toCheck[key] = options[key];
225
+ });
226
+ options = tnp_core_1._.cloneDeep(toCheck);
227
+ var findNearestProjectWithGitRoot = options.findNearestProjectWithGitRoot, findNearestProjectTypeWithGitRoot = options.findNearestProjectTypeWithGitRoot, cwd = options.cwd;
228
+ var findNearestProject = options.findNearestProject, findNearestProjectType = options.findNearestProjectType;
229
+ Object
230
+ .keys(options)
231
+ .filter(function (key) { return key.startsWith('tnp'); })
232
+ .forEach(function (key) {
233
+ options[key] = !!options[key];
234
+ global[key] = options[key];
235
+ });
236
+ var cwdFromArgs = cwd;
237
+ var findProjectWithGitRoot = !!findNearestProjectWithGitRoot ||
238
+ !!findNearestProjectTypeWithGitRoot;
239
+ if (!!findNearestProjectWithGitRoot) {
240
+ findNearestProject = findNearestProjectWithGitRoot;
241
+ }
242
+ if (tnp_core_1._.isString(findNearestProjectTypeWithGitRoot)) {
243
+ findNearestProjectType = findNearestProjectTypeWithGitRoot;
244
+ }
245
+ if (tnp_core_1._.isString(cwdFromArgs)) {
246
+ var nearest = void 0;
247
+ if (findNearestProject || tnp_core_1._.isString(findNearestProjectType)) {
248
+ var classProject = typescript_class_helpers_1.CLASS.getBy('Project');
249
+ nearest = classProject.nearestTo(cwdFromArgs, {
250
+ type: findNearestProjectType,
251
+ findGitRoot: findProjectWithGitRoot,
252
+ });
253
+ if (!nearest) {
254
+ index_1.Helpers.error("Not able to find neerest project for arguments: [\n ".concat(argsv.join(',\n'), "\n]"), false, true);
255
+ }
256
+ }
257
+ if (nearest) {
258
+ cwdFromArgs = nearest.location;
259
+ }
260
+ if (tnp_core_1.fse.existsSync(cwdFromArgs) && !tnp_core_1.fse.lstatSync(cwdFromArgs).isDirectory()) {
261
+ cwdFromArgs = tnp_core_1.path.dirname(cwdFromArgs);
262
+ }
263
+ if (tnp_core_1.fse.existsSync(cwdFromArgs) && tnp_core_1.fse.lstatSync(cwdFromArgs).isDirectory()) {
264
+ process.chdir(cwdFromArgs);
265
+ }
266
+ else {
267
+ index_1.Helpers.error("Incorrect --cwd argument for args: [\n ".concat(argsv.join(',\n'), "\n]"), false, true);
268
+ }
269
+ }
270
+ argsv = removeArg('findNearestProjectType', argsv);
271
+ Object.keys(toCheck).forEach(function (argName) {
272
+ argsv = removeArg(argName, argsv);
273
+ });
274
+ return argsv;
275
+ };
276
+ return HelpersCliTool;
277
+ }());
278
+ exports.HelpersCliTool = HelpersCliTool;
279
+ function removeArg(arg, argsv) {
280
+ argsv = argsv.filter(function (f, i) {
281
+ var regexString = "^\\-\\-(".concat(arg, "$|").concat(arg, "\\=)+");
282
+ if ((new RegExp(regexString)).test(f)) {
283
+ var nextParam = argsv[i + 1];
284
+ if (nextParam && !nextParam.startsWith("--")) {
285
+ argsv[i + 1] = '';
286
+ }
287
+ return false;
288
+ }
289
+ return true;
290
+ }).filter(function (f) { return !!f; });
291
+ return argsv;
292
+ }
293
+ //# sourceMappingURL=/Users/dariusz/projects/npm/tnp-helpers/tmp-bundle-release/bundle/project/tnp-helpers/bundle-nocutsrc/lib/helpers-cli-tool.backend.js.map
@@ -1,11 +1,11 @@
1
- import { Project } from './project';
2
- export declare class HelpersDependencies {
3
- sort<P extends Project = Project>(deps: {
4
- project: P;
5
- copyto: P[];
6
- }[]): {
7
- project: P;
8
- copyto: P[];
9
- }[];
10
- recrusiveFind<P extends Project = Project>(currentProj: P, allAvailableProjects: P[], deps?: P[], orgProj?: P): P[];
11
- }
1
+ import { Project } from './project';
2
+ export declare class HelpersDependencies {
3
+ sort<P extends Project = Project>(deps: {
4
+ project: P;
5
+ copyto: P[];
6
+ }[]): {
7
+ project: P;
8
+ copyto: P[];
9
+ }[];
10
+ recrusiveFind<P extends Project = Project>(currentProj: P, allAvailableProjects: P[], deps?: P[], orgProj?: P): P[];
11
+ }