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,736 +1,736 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelpersFileFolders = void 0;
4
- var tslib_1 = require("tslib");
5
- var tnp_core_1 = require("tnp-core");
6
- var underscore = require("underscore");
7
- var glob = require("glob");
8
- var crypto = require("crypto");
9
- var index_1 = require("./index");
10
- var tnp_config_1 = require("tnp-config");
11
- var trace = !global.hideLog;
12
- var HelpersFileFolders = /** @class */ (function () {
13
- function HelpersFileFolders() {
14
- }
15
- /**
16
- * Calculate file or string checksum
17
- */
18
- HelpersFileFolders.prototype.checksum = function (absolutePathToFileOrContent, algorithm) {
19
- var fileContent = tnp_core_1.path.isAbsolute(absolutePathToFileOrContent)
20
- ? index_1.Helpers.readFile(absolutePathToFileOrContent)
21
- : absolutePathToFileOrContent;
22
- return crypto
23
- .createHash(algorithm || 'md5')
24
- .update(fileContent, 'utf8')
25
- .digest('hex');
26
- };
27
- HelpersFileFolders.prototype.getValueFromJSON = function (filepath, lodashGetPath, defaultValue) {
28
- if (defaultValue === void 0) { defaultValue = void 0; }
29
- if (!tnp_core_1.fse.existsSync(filepath)) {
30
- return defaultValue;
31
- }
32
- var json = index_1.Helpers.readJson(filepath);
33
- return tnp_core_1._.get(json, lodashGetPath, defaultValue);
34
- };
35
- HelpersFileFolders.prototype.readValueFromJson = function (filepath, lodashGetPath, defaultValue) {
36
- if (defaultValue === void 0) { defaultValue = void 0; }
37
- return index_1.Helpers.getValueFromJSON(filepath, lodashGetPath, defaultValue);
38
- };
39
- HelpersFileFolders.prototype.setValueToJSON = function (filepath, lodashGetPath, value) {
40
- if (!tnp_core_1.fse.existsSync(filepath)) {
41
- index_1.Helpers.error("Not able to set value in json: ".concat(filepath), true, true);
42
- return;
43
- }
44
- var json = index_1.Helpers.readJson(filepath);
45
- tnp_core_1._.set(json, lodashGetPath, value);
46
- index_1.Helpers.writeFile(filepath, json);
47
- };
48
- /**
49
- * file size in bytes
50
- */
51
- HelpersFileFolders.prototype.size = function (filePath) {
52
- if (!index_1.Helpers.exists(filePath) || index_1.Helpers.isFolder(filePath)) {
53
- return null;
54
- }
55
- return tnp_core_1.fse.lstatSync(filePath).size;
56
- };
57
- HelpersFileFolders.prototype.pathFromLink = function (filePath) {
58
- return tnp_core_1.fse.readlinkSync(filePath);
59
- };
60
- HelpersFileFolders.prototype.renameFolder = function (from, to, cwd) {
61
- // const command = `mv ${from} ${to}`;
62
- var command = "renamer --find ".concat(from, " --replace ").concat(to, " *");
63
- index_1.Helpers.run(command, { cwd: cwd }).sync();
64
- };
65
- HelpersFileFolders.prototype.getTempFolder = function () {
66
- var tmp = '/tmp';
67
- if (process.platform === 'darwin') {
68
- tmp = '/private/tmp';
69
- }
70
- if (process.platform === 'win32') {
71
- tmp = (0, tnp_core_1.crossPlatformPath)(tnp_core_1.path.join((0, tnp_core_1.crossPlatformPath)(tnp_core_1.os.homedir()), '/AppData/Local/Temp'));
72
- }
73
- if (!index_1.Helpers.exists(tmp)) {
74
- index_1.Helpers.mkdirp(tmp);
75
- }
76
- return tmp;
77
- };
78
- // createMultiplatformLink(target: string, link: string) {
79
- // if (this.isPlainFileOrFolder(link)) {
80
- // link = path.join(process.cwd(), link);
81
- // }
82
- // let command: string;
83
- // if (os.platform() === 'win32') {
84
- // if (target.startsWith('./')) {
85
- // target = path.win32.normalize(path.join(process.cwd(), path.basename(target)))
86
- // } else {
87
- // if (target === '.' || target === './') {
88
- // target = path.win32.normalize(path.join(process.cwd(), path.basename(link)))
89
- // } else {
90
- // target = path.win32.normalize(path.join(target, path.basename(link)))
91
- // }
92
- // }
93
- // if (fse.existsSync(target)) {
94
- // fse.unlinkSync(target);
95
- // }
96
- // target = path.win32.normalize(target)
97
- // if (link === '.' || link === './') {
98
- // link = process.cwd()
99
- // }
100
- // link = path.win32.normalize(link);
101
- // // if (path.resolve(target) === path.resolve(link)) { // TODO
102
- // // Helpers.warn(`[createMultiplatformLink][win32] Trying to link same location`);
103
- // // return;
104
- // // }
105
- // command = "mklink \/D "
106
- // + target
107
- // + " "
108
- // + link
109
- // + " >nul 2>&1 "
110
- // } else {
111
- // if (target.startsWith('./')) {
112
- // target = target.replace(/^\.\//g, '');
113
- // }
114
- // if (link === '.' || link === './') {
115
- // link = process.cwd()
116
- // }
117
- // if (path.resolve(target) === path.resolve(link)) {
118
- // Helpers.warn(`[createMultiplatformLink] Trying to link same location`);
119
- // return;
120
- // }
121
- // command = `ln -sf "${link}" "${target}"`;
122
- // }
123
- // child_process.execSync(command);
124
- // }
125
- HelpersFileFolders.prototype.isPlainFileOrFolder = function (filePath) {
126
- return /^([a-zA-Z]|\-|\_|\@|\#|\$|\!|\^|\&|\*|\(|\))+$/.test(filePath);
127
- };
128
- HelpersFileFolders.prototype.requireUncached = function (module) {
129
- delete require.cache[require.resolve(module)];
130
- return require(module);
131
- };
132
- /**
133
- * get default export object from js file
134
- * @param jsFilePath
135
- */
136
- HelpersFileFolders.prototype.require = function (jsFilePath) {
137
- var orgPath = jsFilePath;
138
- if (!tnp_core_1.fse.existsSync(jsFilePath)) {
139
- jsFilePath = "".concat(jsFilePath, ".js");
140
- }
141
- if (!tnp_core_1.fse.existsSync(jsFilePath)) {
142
- index_1.Helpers.error("Not able to find path: ".concat(orgPath));
143
- }
144
- var fileContent = tnp_core_1.fse.readFileSync(jsFilePath).toLocaleString();
145
- (function () {
146
- var stringForRegex = "require\\((\"|')\\.\\/([a-zA-Z0-9]|\\/|\\-|\\_|\\+|\\.)*(\"|')\\)";
147
- index_1.Helpers.log("[tnp-helpre][require][".concat(jsFilePath, "] stringForRegex: ").concat(stringForRegex), 1);
148
- fileContent = fileContent.split('\n').map(function (line) {
149
- var matches = line.match(new RegExp(stringForRegex));
150
- if (matches !== null) {
151
- // console.log('matched', matches)
152
- var rep = tnp_core_1._.first(matches);
153
- if (rep) {
154
- var newFilename = tnp_core_1.path.join(tnp_core_1.path.dirname(jsFilePath), rep.split('(')[1].replace(/("|'|\))/g, ''));
155
- line = line.replace(rep, "require('".concat(newFilename, "')"));
156
- }
157
- // console.log(line)
158
- }
159
- // console.log('matched', matches)
160
- return line;
161
- }).join('\n');
162
- })();
163
- (function () {
164
- var stringForRegex = "require\\((\"|')([a-zA-Z0-9]|\\/|\\-|\\_|\\+|\\.)*(\"|')\\)";
165
- index_1.Helpers.log("[tnp-helpre][require][".concat(jsFilePath, "] stringForRegex: ").concat(stringForRegex), 1);
166
- fileContent = fileContent.split('\n').map(function (line) {
167
- // console.log(`LINE: "${line}"`)
168
- var matches = line.match(new RegExp(stringForRegex));
169
- if (matches !== null) {
170
- // console.log('matched', matches)
171
- var rep = tnp_core_1._.first(matches);
172
- if (rep) {
173
- var relativePart = rep.split('(')[1].replace(/("|'|\))/g, '');
174
- // console.log(`RELATIVE PART: "${relativePart}"`)
175
- if (relativePart.search('/') !== -1 && !relativePart.startsWith('/')) {
176
- var newFilename = tnp_core_1.path.join(tnp_core_1.path.dirname(jsFilePath), 'node_modules', relativePart);
177
- line = line.replace(rep, "require('".concat(newFilename, "')"));
178
- }
179
- }
180
- // console.log(line)
181
- }
182
- // console.log('matched', matches)
183
- return line;
184
- }).join('\n');
185
- })();
186
- return eval(fileContent);
187
- };
188
- HelpersFileFolders.prototype.tryRecreateDir = function (dirpath) {
189
- try {
190
- index_1.Helpers.mkdirp(dirpath);
191
- }
192
- catch (error) {
193
- index_1.Helpers.log("Trying to recreate directory: ".concat(dirpath));
194
- index_1.Helpers.sleep(1);
195
- index_1.Helpers.mkdirp(dirpath);
196
- }
197
- };
198
- HelpersFileFolders.prototype.tryCopyFrom = function (source, destination, options) {
199
- if (options === void 0) { options = {}; }
200
- index_1.Helpers.log("Trying to copy from: ".concat(source, " to ").concat(destination));
201
- destination = (0, tnp_core_1.crossPlatformPath)(destination);
202
- source = (0, tnp_core_1.crossPlatformPath)(source);
203
- if (source === destination) {
204
- index_1.Helpers.warn('[tnp-helpers] Probably error... trying to copy the same folder...');
205
- return;
206
- }
207
- if (tnp_core_1.fse.existsSync(source) && !tnp_core_1.fse.lstatSync(source).isDirectory()) {
208
- // Helpers.warn(`[tryCopyFrom] This source is not directory: ${source} to ${destination}`);
209
- index_1.Helpers.copyFile(source, destination);
210
- return;
211
- }
212
- if (tnp_core_1.fse.existsSync(destination.replace(/\/$/, ''))) {
213
- var destMaybe = destination.replace(/\/$/, '');
214
- var stats = tnp_core_1.fse.lstatSync(destMaybe);
215
- var isNotDirectory = !stats.isDirectory();
216
- var isSymbolicLink = stats.isSymbolicLink();
217
- if (isNotDirectory || isSymbolicLink) {
218
- tnp_core_1.rimraf.sync(destMaybe);
219
- }
220
- }
221
- options = tnp_core_1._.merge({
222
- overwrite: true,
223
- recursive: true,
224
- }, options);
225
- if (process.platform === 'win32') { // TODO QUICK_FIX
226
- options['dereference'] = true;
227
- }
228
- try {
229
- tnp_core_1.fse.copySync(source, destination, options);
230
- }
231
- catch (error) {
232
- tnp_core_1.rimraf.sync(destination);
233
- tnp_core_1.fse.copySync(source, destination, options);
234
- }
235
- };
236
- HelpersFileFolders.prototype.removeIfExists = function (absoluteFileOrFolderPath) {
237
- if (process.platform === 'win32') {
238
- tnp_core_1.rimraf.sync(absoluteFileOrFolderPath);
239
- return;
240
- }
241
- try {
242
- tnp_core_1.fse.unlinkSync(absoluteFileOrFolderPath);
243
- }
244
- catch (error) { }
245
- if (tnp_core_1.fse.existsSync(absoluteFileOrFolderPath)) {
246
- if (tnp_core_1.fse.lstatSync(absoluteFileOrFolderPath).isDirectory()) {
247
- tnp_core_1.fse.removeSync(absoluteFileOrFolderPath);
248
- }
249
- else {
250
- tnp_core_1.fse.unlinkSync(absoluteFileOrFolderPath);
251
- }
252
- }
253
- };
254
- HelpersFileFolders.prototype.removeFileIfExists = function (absoluteFilePath, options) {
255
- if (process.platform === 'win32') {
256
- tnp_core_1.rimraf.sync(absoluteFilePath);
257
- return;
258
- }
259
- // console.log(`removeFileIfExists: ${absoluteFilePath}`)
260
- var modifiedFiles = (options || { modifiedFiles: { modifiedFiles: [] } }).modifiedFiles;
261
- if (tnp_core_1.fse.existsSync(absoluteFilePath)) {
262
- tnp_core_1.fse.unlinkSync(absoluteFilePath);
263
- modifiedFiles.modifiedFiles.push(absoluteFilePath);
264
- }
265
- };
266
- HelpersFileFolders.prototype.removeFolderIfExists = function (absoluteFolderPath, options) {
267
- index_1.Helpers.log("[helpers] Remove folder: ".concat(absoluteFolderPath));
268
- if (process.platform === 'win32') {
269
- // rimraf.sync(absoluteFolderPath);
270
- this.tryRemoveDir(absoluteFolderPath);
271
- return;
272
- }
273
- var modifiedFiles = (options || { modifiedFiles: { modifiedFiles: [] } }).modifiedFiles;
274
- if (tnp_core_1.fse.existsSync(absoluteFolderPath)) {
275
- tnp_core_1.fse.removeSync(absoluteFolderPath);
276
- modifiedFiles.modifiedFiles.push(absoluteFolderPath);
277
- }
278
- };
279
- // private deleteFolderRecursive = (pathToFolder) => {
280
- // if (fs.existsSync(pathToFolder)) {
281
- // fs.readdirSync(pathToFolder).forEach((file, index) => {
282
- // const curPath = path.join(pathToFolder, file);
283
- // if (fs.lstatSync(curPath).isDirectory()) { // recurse
284
- // this.deleteFolderRecursive(curPath);
285
- // } else { // delete file
286
- // fs.unlinkSync(curPath);
287
- // }
288
- // });
289
- // fs.rmdirSync(pathToFolder);
290
- // }
291
- // };
292
- HelpersFileFolders.prototype.tryRemoveDir = function (dirpath, contentOnly) {
293
- if (contentOnly === void 0) { contentOnly = false; }
294
- if (!tnp_core_1.fse.existsSync(dirpath)) {
295
- index_1.Helpers.warn("Folder ".concat(tnp_core_1.path.basename(dirpath), " doesn't exist."));
296
- return;
297
- }
298
- index_1.Helpers.log("[tnp-helpers][tryRemoveDir]: ".concat(dirpath));
299
- try {
300
- if (contentOnly) {
301
- tnp_core_1.rimraf.sync("".concat(dirpath, "/*"));
302
- }
303
- else {
304
- tnp_core_1.rimraf.sync(dirpath);
305
- }
306
- index_1.Helpers.log("Remove done: ".concat(dirpath));
307
- return;
308
- }
309
- catch (e) {
310
- index_1.Helpers.warn("\n\n Trying to remove directory: ".concat(dirpath, "\n\n\n (USER ACTION REQUIRED!!!)\n Please check if you did't open\n ").concat(dirpath, "\n in windows explorer\n\n\n "));
311
- index_1.Helpers.sleep(1);
312
- index_1.Helpers.tryRemoveDir(dirpath, contentOnly);
313
- }
314
- };
315
- HelpersFileFolders.prototype.move = function (from, to) {
316
- if (!tnp_core_1.fse.existsSync(from)) {
317
- index_1.Helpers.warn("[move] File or folder doesnt not exists: ".concat(from));
318
- return;
319
- }
320
- if (!tnp_core_1.path.isAbsolute(from)) {
321
- index_1.Helpers.warn("[move] Source path is not absolute: ".concat(from));
322
- return;
323
- }
324
- if (!tnp_core_1.path.isAbsolute(to)) {
325
- index_1.Helpers.warn("[move] Destination path is not absolute: ".concat(to));
326
- return;
327
- }
328
- tnp_core_1.fse.moveSync(from, to, {
329
- overwrite: true
330
- });
331
- };
332
- HelpersFileFolders.prototype.remove = function (fileOrFolderPathOrPatter, exactFolder) {
333
- if (exactFolder === void 0) { exactFolder = false; }
334
- if (Array.isArray(fileOrFolderPathOrPatter)) {
335
- fileOrFolderPathOrPatter = tnp_core_1.path.join.apply(tnp_core_1.path, tslib_1.__spreadArray([], tslib_1.__read(fileOrFolderPathOrPatter), false));
336
- }
337
- index_1.Helpers.log("[tnp-helpers][remove]: ".concat(fileOrFolderPathOrPatter));
338
- if (exactFolder) {
339
- tnp_core_1.rimraf.sync(fileOrFolderPathOrPatter, { glob: false, disableGlob: true, });
340
- return;
341
- }
342
- tnp_core_1.rimraf.sync(fileOrFolderPathOrPatter);
343
- };
344
- HelpersFileFolders.prototype.findChildren = function (location, createFn) {
345
- var notAllowed = tslib_1.__spreadArray(tslib_1.__spreadArray([
346
- '\.vscode', 'node\_modules'
347
- ], tslib_1.__read(index_1.Helpers.values(tnp_config_1.config.folder)), false), [
348
- 'e2e', 'tmp.*', 'dist.*', 'tests', 'module', 'browser', 'bundle*',
349
- 'components', '\.git', 'bin', 'custom'
350
- ], false).filter(function (f) {
351
- return ![tnp_config_1.config.folder.external].includes(f) && tnp_core_1._.isString(f);
352
- }).map(function (s) { return new RegExp(s); });
353
- var isDirectory = function (source) { return tnp_core_1.fse.lstatSync(source).isDirectory(); };
354
- var getDirectories = function (source) {
355
- return tnp_core_1.fse.readdirSync(source).map(function (name) { return tnp_core_1.path.join(source, name); }).filter(isDirectory);
356
- };
357
- var subdirectories = getDirectories(location)
358
- .filter(function (f) {
359
- var folderNam = tnp_core_1.path.basename(f);
360
- var allowed = (notAllowed.filter(function (p) { return p.test(folderNam); }).length === 0);
361
- return allowed;
362
- });
363
- return subdirectories
364
- .map(function (dir) {
365
- // console.log('child:', dir)
366
- return createFn(dir);
367
- })
368
- .filter(function (c) { return !!c; });
369
- };
370
- HelpersFileFolders.prototype.findChildrenNavi = function (location, createFn) {
371
- if (!tnp_core_1.fse.existsSync(location)) {
372
- return [];
373
- }
374
- var notAllowed = tslib_1.__spreadArray(tslib_1.__spreadArray([
375
- '\.vscode', 'node\_modules'
376
- ], tslib_1.__read(index_1.Helpers.values(tnp_config_1.config.folder)), false), [
377
- 'e2e', 'tmp.*', 'dist.*', 'tests',
378
- 'module', 'browser', 'bundle*',
379
- 'components', '\.git', '\.build', 'bin', 'custom'
380
- ], false).map(function (s) { return new RegExp(s); });
381
- var isDirectory = function (source) { return tnp_core_1.fse.lstatSync(source).isDirectory(); };
382
- var getDirectories = function (source) {
383
- return tnp_core_1.fse.readdirSync(source).map(function (name) { return tnp_core_1.path.join(source, name); }).filter(isDirectory);
384
- };
385
- var subdirectories = getDirectories(location)
386
- .filter(function (f) {
387
- var folderName = tnp_core_1.path.basename(f);
388
- if (/.*es\-.*/.test(folderName)) {
389
- return true;
390
- }
391
- return (notAllowed.filter(function (p) { return p.test(folderName); }).length === 0);
392
- });
393
- return subdirectories
394
- .map(function (dir) {
395
- return createFn(dir);
396
- })
397
- .filter(function (c) { return !!c; });
398
- };
399
- HelpersFileFolders.prototype.getRecrusiveFilesFrom = function (dir, ommitFolders, options) {
400
- if (ommitFolders === void 0) { ommitFolders = []; }
401
- options = options ? options : {};
402
- // const withNameOnly = options.withNameOnly;
403
- var files = [];
404
- var readedFilesAndFolders = tnp_core_1.fse.existsSync(dir) ? tnp_core_1.fse.readdirSync(dir) : [];
405
- var readed = readedFilesAndFolders
406
- .map(function (f) {
407
- var fullPath = tnp_core_1.path.join(dir, f);
408
- // console.log(`is direcotry ${fse.lstatSync(fullPath).isDirectory()} `, fullPath)
409
- if (tnp_core_1.fse.lstatSync(fullPath).isDirectory()) {
410
- if (ommitFolders.includes(tnp_core_1.path.basename(fullPath)) ||
411
- ommitFolders.includes(tnp_core_1.path.basename(tnp_core_1.path.dirname(fullPath)))) {
412
- // Helpers.log(`Omitting: ${fullPath}`)
413
- }
414
- else {
415
- index_1.Helpers
416
- .getRecrusiveFilesFrom(fullPath, ommitFolders, options)
417
- .forEach(function (aa) { return files.push(aa); });
418
- }
419
- return;
420
- }
421
- return fullPath;
422
- })
423
- .filter(function (f) { return !!f; });
424
- if (Array.isArray(readed)) {
425
- readed.forEach(function (r) { return files.push(r); });
426
- }
427
- return files;
428
- };
429
- HelpersFileFolders.prototype.getLinesFromFiles = function (filename, lineCount) {
430
- return new Promise(function (resolve, reject) {
431
- var stream = tnp_core_1.fse.createReadStream(filename, {
432
- flags: 'r',
433
- encoding: 'utf-8',
434
- fd: null,
435
- mode: 438, // 0666 in Octal
436
- // bufferSize: 64 * 1024 as any
437
- });
438
- var data = '';
439
- var lines = [];
440
- stream.on('data', function (moreData) {
441
- data += moreData;
442
- lines = data.split('\n');
443
- // probably that last line is "corrupt" - halfway read - why > not >=
444
- if (lines.length > lineCount + 1) {
445
- stream.destroy();
446
- lines = lines.slice(0, lineCount); // junk as above
447
- resolve(lines);
448
- }
449
- });
450
- stream.on('error', function () {
451
- reject("Error reading ".concat(filename));
452
- });
453
- stream.on('end', function () {
454
- resolve(lines);
455
- });
456
- });
457
- };
458
- ;
459
- /**
460
- * Get the most recent changes file in direcory
461
- * @param dir absoulute path to file
462
- */
463
- HelpersFileFolders.prototype.getMostRecentFileName = function (dir) {
464
- var files = index_1.Helpers.getRecrusiveFilesFrom(dir);
465
- // use underscore for max()
466
- return underscore.max(files, function (f) {
467
- // console.log(f);
468
- // ctime = creation time is used
469
- // replace with mtime for modification time
470
- // console.log( `${fse.statSync(f).mtimeMs} for ${f}` )
471
- return tnp_core_1.fse.statSync(f).mtimeMs;
472
- });
473
- };
474
- HelpersFileFolders.prototype.getMostRecentFilesNames = function (dir) {
475
- var allFiles = index_1.Helpers.getRecrusiveFilesFrom(dir);
476
- var mrf = index_1.Helpers.getMostRecentFileName(dir);
477
- var mfrMtime = tnp_core_1.fse.lstatSync(mrf).mtimeMs;
478
- return allFiles.filter(function (f) {
479
- var info = tnp_core_1.fse.lstatSync(f);
480
- return (info.mtimeMs === mfrMtime && !info.isDirectory());
481
- });
482
- };
483
- HelpersFileFolders.prototype.removeExcept = function (fromPath, exceptFolderAndFiles) {
484
- tnp_core_1.fse.readdirSync(fromPath)
485
- .filter(function (f) {
486
- return !exceptFolderAndFiles.includes(f);
487
- })
488
- .map(function (f) { return tnp_core_1.path.join(fromPath, f); })
489
- .forEach(function (af) { return index_1.Helpers.removeFolderIfExists(af); });
490
- (glob.sync("".concat(fromPath, "/*.*")))
491
- .filter(function (f) {
492
- return !exceptFolderAndFiles.includes(tnp_core_1.path.basename(f));
493
- })
494
- .forEach(function (af) { return index_1.Helpers.removeFileIfExists(af); });
495
- };
496
- HelpersFileFolders.prototype.copy = function (sourceDir, destinationDir, options) {
497
- index_1.Helpers.log("Copying from:\n\n ".concat(sourceDir, "\n to\n ").concat(destinationDir, "\n\n "));
498
- index_1.Helpers.log(options);
499
- // sourceDir = sourceDir ? (sourceDir.replace(/\/$/, '')) : sourceDir;
500
- // destinationDir = destinationDir ? (destinationDir.replace(/\/$/, '')) : destinationDir;
501
- if (!tnp_core_1.fse.existsSync(sourceDir)) {
502
- index_1.Helpers.warn("[tnp-helper][copy] Source dir doesnt exist: ".concat(sourceDir, " for destination: ").concat(destinationDir), trace);
503
- return;
504
- }
505
- if (!tnp_core_1.fse.existsSync(tnp_core_1.path.dirname(destinationDir))) {
506
- index_1.Helpers.mkdirp(tnp_core_1.path.dirname(destinationDir));
507
- }
508
- if (!options) {
509
- options = {};
510
- }
511
- if (tnp_core_1._.isUndefined(options.overwrite)) {
512
- options.overwrite = true;
513
- }
514
- if (tnp_core_1._.isUndefined(options.recursive)) {
515
- options.recursive = true;
516
- }
517
- if (tnp_core_1._.isUndefined(options.useTempFolder)) {
518
- options.useTempFolder = false;
519
- }
520
- if (options.copySymlinksAsFiles) {
521
- options['dereference'] = true;
522
- }
523
- if (!options.omitFolders) {
524
- options.omitFolders = [];
525
- }
526
- if (options.asSeparatedFilesSymlinkAsFile) {
527
- options.asSeparatedFilesSymlinkAsFile = true;
528
- }
529
- // const [srcStat, destStat] = [
530
- // fse.existsSync(sourceDir) && fse.statSync(sourceDir),
531
- // fse.existsSync(destinationDir) && fse.statSync(destinationDir),
532
- // ];
533
- // if (destStat && destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) {
534
- // Helpers.warn(`[tnp-helper][copy] Same location stats.. Trying to copy same source and destination:
535
- // from: ${sourceDir}
536
- // to: ${destinationDir}
537
- // `);
538
- // return;
539
- // }
540
- if (tnp_core_1._.isArray(options.omitFolders) && options.omitFolders.length >= 1
541
- && tnp_core_1._.isNil(options.filter) && tnp_core_1._.isString(options.omitFoldersBaseFolder)
542
- && tnp_core_1.path.isAbsolute(options.omitFoldersBaseFolder)) {
543
- options.filter = index_1.Helpers.filterDontCopy(options.omitFolders, options.omitFoldersBaseFolder);
544
- }
545
- if (sourceDir === destinationDir || tnp_core_1.path.resolve(sourceDir) === tnp_core_1.path.resolve(destinationDir)) {
546
- index_1.Helpers.warn("[tnp-helper][copy] Trying to copy same source and destination\n from: ".concat(sourceDir, "\n to: ").concat(destinationDir, "\n "));
547
- }
548
- else {
549
- // Helpers.warn('filter', _.isFunction(options.filter));
550
- // Helpers.warn('sourceDir', sourceDir);
551
- // Helpers.warn('destinationDir', destinationDir);
552
- // Helpers.log(JSON.stringify(options))
553
- // try {
554
- if (options.useTempFolder) {
555
- var tempDestination = "".concat(tnp_core_1.os.platform() === 'darwin' ? '/private/tmp' : '/tmp', "/").concat(tnp_core_1._.camelCase(destinationDir));
556
- index_1.Helpers.removeFolderIfExists(tempDestination);
557
- tnp_core_1.fse.copySync(sourceDir, tempDestination, options);
558
- tnp_core_1.fse.copySync(tempDestination, destinationDir, options);
559
- }
560
- else {
561
- if ((sourceDir === tnp_core_1.path.resolve(sourceDir))
562
- && index_1.Helpers.isExistedSymlink(sourceDir)
563
- && !index_1.Helpers.exists(tnp_core_1.fse.readlinkSync(sourceDir))) {
564
- index_1.Helpers.warn("[tnp-helpers] Not copying empty link from: ".concat(sourceDir, "\n "));
565
- }
566
- else {
567
- var copyFn_1 = function () {
568
- try {
569
- if (options.asSeparatedFiles) {
570
- var copyRecFn_1 = function (cwdForFiles) {
571
- // if (path.basename(cwdForFiles) === 'plugins') {
572
- // debugger
573
- // }
574
- var files = index_1.Helpers.getRecrusiveFilesFrom(cwdForFiles, options.omitFolders);
575
- var _loop_1 = function (index) {
576
- var from = files[index];
577
- var to = from.replace(sourceDir, destinationDir);
578
- if (index_1.Helpers.isFolder(from)) {
579
- if (options.omitFolders.includes(tnp_core_1.path.basename(tnp_core_1.path.dirname(from))) ||
580
- options.omitFolders.includes(tnp_core_1.path.basename(from))) {
581
- return "continue";
582
- }
583
- else {
584
- copyRecFn_1(from);
585
- }
586
- }
587
- else {
588
- var copyFileFn = function () {
589
- if (!options.asSeparatedFilesSymlinkAsFile && index_1.Helpers.isExistedSymlink(from)) {
590
- index_1.Helpers.createSymLink(from, to);
591
- }
592
- else {
593
- index_1.Helpers.copyFile(from, to);
594
- }
595
- };
596
- if (options.asSeparatedFilesAllowNotCopied) {
597
- try {
598
- copyFileFn();
599
- }
600
- catch (e) { }
601
- }
602
- else {
603
- copyFileFn();
604
- }
605
- }
606
- };
607
- for (var index = 0; index < files.length; index++) {
608
- _loop_1(index);
609
- }
610
- };
611
- copyRecFn_1(sourceDir);
612
- }
613
- else {
614
- tnp_core_1.fse.copySync(sourceDir, destinationDir, options);
615
- }
616
- }
617
- catch (error) {
618
- var exitOnError = global['tnpNonInteractive'];
619
- index_1.Helpers.log(error);
620
- index_1.Helpers.error("[tnp-helper] Not able to copy folder:\n from: ".concat(sourceDir, "\n to: ").concat(destinationDir, "\n options: ").concat(tnp_core_1.json5.stringify(options), "\n error: ").concat(error === null || error === void 0 ? void 0 : error.message, "\n "), !exitOnError, !trace);
621
- index_1.Helpers.pressKeyAndContinue("Press any key to repeat copy action...");
622
- copyFn_1();
623
- }
624
- };
625
- copyFn_1();
626
- }
627
- }
628
- // } catch (error) {
629
- // console.trace(error);
630
- // process.exit(0)
631
- // }
632
- }
633
- };
634
- HelpersFileFolders.prototype.filterDontCopy = function (basePathFoldersTosSkip, projectOrBasepath) {
635
- return function (src, dest) {
636
- // console.log('src', src)
637
- src = (0, tnp_core_1.crossPlatformPath)(src);
638
- var baseFolder = tnp_core_1._.first((0, tnp_core_1.crossPlatformPath)(src)
639
- .replace((0, tnp_core_1.crossPlatformPath)(tnp_core_1._.isString(projectOrBasepath) ? projectOrBasepath : projectOrBasepath.location), '')
640
- .replace(/^\//, '').split('/'));
641
- // console.log('baseFolder', baseFolder)
642
- if (!baseFolder || baseFolder.trim() === '') {
643
- return true;
644
- }
645
- var isAllowed = tnp_core_1._.isUndefined(basePathFoldersTosSkip
646
- .find(function (f) { return baseFolder.startsWith((0, tnp_core_1.crossPlatformPath)(f)); }));
647
- // console.log('isAllowed', isAllowed)
648
- return isAllowed;
649
- };
650
- };
651
- HelpersFileFolders.prototype.filterOnlyCopy = function (basePathFoldersOnlyToInclude, projectOrBasepath) {
652
- return function (src, dest) {
653
- src = (0, tnp_core_1.crossPlatformPath)(src);
654
- var baseFolder = tnp_core_1._.first((0, tnp_core_1.crossPlatformPath)(src)
655
- .replace((0, tnp_core_1.crossPlatformPath)(tnp_core_1._.isString(projectOrBasepath) ? projectOrBasepath : projectOrBasepath.location), '')
656
- .replace(/^\//, '').split('/'));
657
- if (!baseFolder || baseFolder.trim() === '') {
658
- return true;
659
- }
660
- var isAllowed = !tnp_core_1._.isUndefined(basePathFoldersOnlyToInclude
661
- .find(function (f) { return baseFolder.startsWith((0, tnp_core_1.crossPlatformPath)(f)); }));
662
- return isAllowed;
663
- };
664
- };
665
- HelpersFileFolders.prototype.copyFile = function (sourcePath, destinationPath, options) {
666
- if (tnp_core_1._.isUndefined(options)) {
667
- options = {};
668
- }
669
- if (tnp_core_1._.isUndefined(options.debugMode)) {
670
- options.debugMode = false;
671
- }
672
- if (tnp_core_1._.isUndefined(options.debugMode)) {
673
- options.fast = true;
674
- }
675
- if (tnp_core_1._.isUndefined(options.dontCopySameContent)) {
676
- options.dontCopySameContent = true;
677
- }
678
- var debugMode = options.debugMode, fast = options.fast, transformTextFn = options.transformTextFn, dontCopySameContent = options.dontCopySameContent, modifiedFiles = options.modifiedFiles;
679
- if (tnp_core_1._.isFunction(transformTextFn) && fast) {
680
- index_1.Helpers.error("[copyFile] You cannot use transformTextFn in fast mode");
681
- }
682
- if (!tnp_core_1.fse.existsSync(sourcePath)) {
683
- index_1.Helpers.warn("[copyFile] No able to find source of ".concat(sourcePath));
684
- return false;
685
- }
686
- if (tnp_core_1.fse.lstatSync(sourcePath).isDirectory()) {
687
- index_1.Helpers.warn("[copyFile] Trying to copy directory as file: ".concat(sourcePath), false);
688
- return false;
689
- }
690
- if (sourcePath === destinationPath) {
691
- index_1.Helpers.warn("[copyFile] Trying to copy same file ".concat(sourcePath));
692
- return false;
693
- }
694
- var destDirPath = tnp_core_1.path.dirname(destinationPath);
695
- if (!tnp_core_1.fse.existsSync(destDirPath)) {
696
- index_1.Helpers.mkdirp(destDirPath);
697
- }
698
- if (dontCopySameContent && tnp_core_1.fse.existsSync(destinationPath)) {
699
- var destinationContent = index_1.Helpers.readFile(destinationPath);
700
- var sourceContent = index_1.Helpers.readFile(sourcePath).toString();
701
- if (destinationContent === sourceContent) {
702
- // @REMEMBER uncomment if any problem
703
- // Helpers.log(`Destination has the same content as source: ${path.basename(sourcePath)}`);
704
- return false;
705
- }
706
- }
707
- debugMode && index_1.Helpers.log("path.extname(sourcePath) ".concat(tnp_core_1.path.extname(sourcePath)));
708
- if (fast || !tnp_config_1.config.extensions.modificableByReplaceFn.includes(tnp_core_1.path.extname(sourcePath))) {
709
- tnp_core_1.fse.copyFileSync(sourcePath, destinationPath);
710
- }
711
- else {
712
- var sourceData = index_1.Helpers.readFile(sourcePath).toString();
713
- if (tnp_core_1._.isFunction(transformTextFn)) {
714
- sourceData = transformTextFn(sourceData);
715
- }
716
- debugMode && index_1.Helpers.log("\n[copyFile] Write to: ".concat(destinationPath, " file:\n============================================================================================\n").concat(sourceData, "\n============================================================================================\n "));
717
- index_1.Helpers.writeFile(destinationPath, sourceData);
718
- }
719
- if (modifiedFiles && tnp_core_1._.isArray(modifiedFiles.modifiedFiles)) {
720
- modifiedFiles.modifiedFiles.push(destinationPath);
721
- }
722
- return true;
723
- };
724
- /**
725
- * get real absolute path
726
- */
727
- HelpersFileFolders.prototype.resolve = function (fileOrFolderPath) {
728
- if (fileOrFolderPath.startsWith('~')) {
729
- fileOrFolderPath = tnp_core_1.path.join(tnp_core_1.os.homedir(), fileOrFolderPath.replace("~/", ''));
730
- }
731
- return tnp_core_1.path.resolve(fileOrFolderPath);
732
- };
733
- return HelpersFileFolders;
734
- }());
735
- exports.HelpersFileFolders = HelpersFileFolders;
736
- //# sourceMappingURL=C:/Users/darek/projects/npm/tnp-helpers/tmp-bundle-release/bundle/project/tnp-helpers/bundle-nocutsrc/lib/helpers-file-folders.backend.js.map
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HelpersFileFolders = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var tnp_core_1 = require("tnp-core");
6
+ var underscore = require("underscore");
7
+ var glob = require("glob");
8
+ var crypto = require("crypto");
9
+ var index_1 = require("./index");
10
+ var tnp_config_1 = require("tnp-config");
11
+ var trace = !global.hideLog;
12
+ var HelpersFileFolders = /** @class */ (function () {
13
+ function HelpersFileFolders() {
14
+ }
15
+ /**
16
+ * Calculate file or string checksum
17
+ */
18
+ HelpersFileFolders.prototype.checksum = function (absolutePathToFileOrContent, algorithm) {
19
+ var fileContent = tnp_core_1.path.isAbsolute(absolutePathToFileOrContent)
20
+ ? index_1.Helpers.readFile(absolutePathToFileOrContent)
21
+ : absolutePathToFileOrContent;
22
+ return crypto
23
+ .createHash(algorithm || 'md5')
24
+ .update(fileContent, 'utf8')
25
+ .digest('hex');
26
+ };
27
+ HelpersFileFolders.prototype.getValueFromJSON = function (filepath, lodashGetPath, defaultValue) {
28
+ if (defaultValue === void 0) { defaultValue = void 0; }
29
+ if (!tnp_core_1.fse.existsSync(filepath)) {
30
+ return defaultValue;
31
+ }
32
+ var json = index_1.Helpers.readJson(filepath);
33
+ return tnp_core_1._.get(json, lodashGetPath, defaultValue);
34
+ };
35
+ HelpersFileFolders.prototype.readValueFromJson = function (filepath, lodashGetPath, defaultValue) {
36
+ if (defaultValue === void 0) { defaultValue = void 0; }
37
+ return index_1.Helpers.getValueFromJSON(filepath, lodashGetPath, defaultValue);
38
+ };
39
+ HelpersFileFolders.prototype.setValueToJSON = function (filepath, lodashGetPath, value) {
40
+ if (!tnp_core_1.fse.existsSync(filepath)) {
41
+ index_1.Helpers.error("Not able to set value in json: ".concat(filepath), true, true);
42
+ return;
43
+ }
44
+ var json = index_1.Helpers.readJson(filepath);
45
+ tnp_core_1._.set(json, lodashGetPath, value);
46
+ index_1.Helpers.writeFile(filepath, json);
47
+ };
48
+ /**
49
+ * file size in bytes
50
+ */
51
+ HelpersFileFolders.prototype.size = function (filePath) {
52
+ if (!index_1.Helpers.exists(filePath) || index_1.Helpers.isFolder(filePath)) {
53
+ return null;
54
+ }
55
+ return tnp_core_1.fse.lstatSync(filePath).size;
56
+ };
57
+ HelpersFileFolders.prototype.pathFromLink = function (filePath) {
58
+ return tnp_core_1.fse.readlinkSync(filePath);
59
+ };
60
+ HelpersFileFolders.prototype.renameFolder = function (from, to, cwd) {
61
+ // const command = `mv ${from} ${to}`;
62
+ var command = "renamer --find ".concat(from, " --replace ").concat(to, " *");
63
+ index_1.Helpers.run(command, { cwd: cwd }).sync();
64
+ };
65
+ HelpersFileFolders.prototype.getTempFolder = function () {
66
+ var tmp = '/tmp';
67
+ if (process.platform === 'darwin') {
68
+ tmp = '/private/tmp';
69
+ }
70
+ if (process.platform === 'win32') {
71
+ tmp = (0, tnp_core_1.crossPlatformPath)(tnp_core_1.path.join((0, tnp_core_1.crossPlatformPath)(tnp_core_1.os.homedir()), '/AppData/Local/Temp'));
72
+ }
73
+ if (!index_1.Helpers.exists(tmp)) {
74
+ index_1.Helpers.mkdirp(tmp);
75
+ }
76
+ return tmp;
77
+ };
78
+ // createMultiplatformLink(target: string, link: string) {
79
+ // if (this.isPlainFileOrFolder(link)) {
80
+ // link = path.join(process.cwd(), link);
81
+ // }
82
+ // let command: string;
83
+ // if (os.platform() === 'win32') {
84
+ // if (target.startsWith('./')) {
85
+ // target = path.win32.normalize(path.join(process.cwd(), path.basename(target)))
86
+ // } else {
87
+ // if (target === '.' || target === './') {
88
+ // target = path.win32.normalize(path.join(process.cwd(), path.basename(link)))
89
+ // } else {
90
+ // target = path.win32.normalize(path.join(target, path.basename(link)))
91
+ // }
92
+ // }
93
+ // if (fse.existsSync(target)) {
94
+ // fse.unlinkSync(target);
95
+ // }
96
+ // target = path.win32.normalize(target)
97
+ // if (link === '.' || link === './') {
98
+ // link = process.cwd()
99
+ // }
100
+ // link = path.win32.normalize(link);
101
+ // // if (path.resolve(target) === path.resolve(link)) { // TODO
102
+ // // Helpers.warn(`[createMultiplatformLink][win32] Trying to link same location`);
103
+ // // return;
104
+ // // }
105
+ // command = "mklink \/D "
106
+ // + target
107
+ // + " "
108
+ // + link
109
+ // + " >nul 2>&1 "
110
+ // } else {
111
+ // if (target.startsWith('./')) {
112
+ // target = target.replace(/^\.\//g, '');
113
+ // }
114
+ // if (link === '.' || link === './') {
115
+ // link = process.cwd()
116
+ // }
117
+ // if (path.resolve(target) === path.resolve(link)) {
118
+ // Helpers.warn(`[createMultiplatformLink] Trying to link same location`);
119
+ // return;
120
+ // }
121
+ // command = `ln -sf "${link}" "${target}"`;
122
+ // }
123
+ // child_process.execSync(command);
124
+ // }
125
+ HelpersFileFolders.prototype.isPlainFileOrFolder = function (filePath) {
126
+ return /^([a-zA-Z]|\-|\_|\@|\#|\$|\!|\^|\&|\*|\(|\))+$/.test(filePath);
127
+ };
128
+ HelpersFileFolders.prototype.requireUncached = function (module) {
129
+ delete require.cache[require.resolve(module)];
130
+ return require(module);
131
+ };
132
+ /**
133
+ * get default export object from js file
134
+ * @param jsFilePath
135
+ */
136
+ HelpersFileFolders.prototype.require = function (jsFilePath) {
137
+ var orgPath = jsFilePath;
138
+ if (!tnp_core_1.fse.existsSync(jsFilePath)) {
139
+ jsFilePath = "".concat(jsFilePath, ".js");
140
+ }
141
+ if (!tnp_core_1.fse.existsSync(jsFilePath)) {
142
+ index_1.Helpers.error("Not able to find path: ".concat(orgPath));
143
+ }
144
+ var fileContent = tnp_core_1.fse.readFileSync(jsFilePath).toLocaleString();
145
+ (function () {
146
+ var stringForRegex = "require\\((\"|')\\.\\/([a-zA-Z0-9]|\\/|\\-|\\_|\\+|\\.)*(\"|')\\)";
147
+ index_1.Helpers.log("[tnp-helpre][require][".concat(jsFilePath, "] stringForRegex: ").concat(stringForRegex), 1);
148
+ fileContent = fileContent.split('\n').map(function (line) {
149
+ var matches = line.match(new RegExp(stringForRegex));
150
+ if (matches !== null) {
151
+ // console.log('matched', matches)
152
+ var rep = tnp_core_1._.first(matches);
153
+ if (rep) {
154
+ var newFilename = tnp_core_1.path.join(tnp_core_1.path.dirname(jsFilePath), rep.split('(')[1].replace(/("|'|\))/g, ''));
155
+ line = line.replace(rep, "require('".concat(newFilename, "')"));
156
+ }
157
+ // console.log(line)
158
+ }
159
+ // console.log('matched', matches)
160
+ return line;
161
+ }).join('\n');
162
+ })();
163
+ (function () {
164
+ var stringForRegex = "require\\((\"|')([a-zA-Z0-9]|\\/|\\-|\\_|\\+|\\.)*(\"|')\\)";
165
+ index_1.Helpers.log("[tnp-helpre][require][".concat(jsFilePath, "] stringForRegex: ").concat(stringForRegex), 1);
166
+ fileContent = fileContent.split('\n').map(function (line) {
167
+ // console.log(`LINE: "${line}"`)
168
+ var matches = line.match(new RegExp(stringForRegex));
169
+ if (matches !== null) {
170
+ // console.log('matched', matches)
171
+ var rep = tnp_core_1._.first(matches);
172
+ if (rep) {
173
+ var relativePart = rep.split('(')[1].replace(/("|'|\))/g, '');
174
+ // console.log(`RELATIVE PART: "${relativePart}"`)
175
+ if (relativePart.search('/') !== -1 && !relativePart.startsWith('/')) {
176
+ var newFilename = tnp_core_1.path.join(tnp_core_1.path.dirname(jsFilePath), 'node_modules', relativePart);
177
+ line = line.replace(rep, "require('".concat(newFilename, "')"));
178
+ }
179
+ }
180
+ // console.log(line)
181
+ }
182
+ // console.log('matched', matches)
183
+ return line;
184
+ }).join('\n');
185
+ })();
186
+ return eval(fileContent);
187
+ };
188
+ HelpersFileFolders.prototype.tryRecreateDir = function (dirpath) {
189
+ try {
190
+ index_1.Helpers.mkdirp(dirpath);
191
+ }
192
+ catch (error) {
193
+ index_1.Helpers.log("Trying to recreate directory: ".concat(dirpath));
194
+ index_1.Helpers.sleep(1);
195
+ index_1.Helpers.mkdirp(dirpath);
196
+ }
197
+ };
198
+ HelpersFileFolders.prototype.tryCopyFrom = function (source, destination, options) {
199
+ if (options === void 0) { options = {}; }
200
+ index_1.Helpers.log("Trying to copy from: ".concat(source, " to ").concat(destination));
201
+ destination = (0, tnp_core_1.crossPlatformPath)(destination);
202
+ source = (0, tnp_core_1.crossPlatformPath)(source);
203
+ if (source === destination) {
204
+ index_1.Helpers.warn('[tnp-helpers] Probably error... trying to copy the same folder...');
205
+ return;
206
+ }
207
+ if (tnp_core_1.fse.existsSync(source) && !tnp_core_1.fse.lstatSync(source).isDirectory()) {
208
+ // Helpers.warn(`[tryCopyFrom] This source is not directory: ${source} to ${destination}`);
209
+ index_1.Helpers.copyFile(source, destination);
210
+ return;
211
+ }
212
+ if (tnp_core_1.fse.existsSync(destination.replace(/\/$/, ''))) {
213
+ var destMaybe = destination.replace(/\/$/, '');
214
+ var stats = tnp_core_1.fse.lstatSync(destMaybe);
215
+ var isNotDirectory = !stats.isDirectory();
216
+ var isSymbolicLink = stats.isSymbolicLink();
217
+ if (isNotDirectory || isSymbolicLink) {
218
+ tnp_core_1.rimraf.sync(destMaybe);
219
+ }
220
+ }
221
+ options = tnp_core_1._.merge({
222
+ overwrite: true,
223
+ recursive: true,
224
+ }, options);
225
+ if (process.platform === 'win32') { // TODO QUICK_FIX
226
+ options['dereference'] = true;
227
+ }
228
+ try {
229
+ tnp_core_1.fse.copySync(source, destination, options);
230
+ }
231
+ catch (error) {
232
+ tnp_core_1.rimraf.sync(destination);
233
+ tnp_core_1.fse.copySync(source, destination, options);
234
+ }
235
+ };
236
+ HelpersFileFolders.prototype.removeIfExists = function (absoluteFileOrFolderPath) {
237
+ if (process.platform === 'win32') {
238
+ tnp_core_1.rimraf.sync(absoluteFileOrFolderPath);
239
+ return;
240
+ }
241
+ try {
242
+ tnp_core_1.fse.unlinkSync(absoluteFileOrFolderPath);
243
+ }
244
+ catch (error) { }
245
+ if (tnp_core_1.fse.existsSync(absoluteFileOrFolderPath)) {
246
+ if (tnp_core_1.fse.lstatSync(absoluteFileOrFolderPath).isDirectory()) {
247
+ tnp_core_1.fse.removeSync(absoluteFileOrFolderPath);
248
+ }
249
+ else {
250
+ tnp_core_1.fse.unlinkSync(absoluteFileOrFolderPath);
251
+ }
252
+ }
253
+ };
254
+ HelpersFileFolders.prototype.removeFileIfExists = function (absoluteFilePath, options) {
255
+ if (process.platform === 'win32') {
256
+ tnp_core_1.rimraf.sync(absoluteFilePath);
257
+ return;
258
+ }
259
+ // console.log(`removeFileIfExists: ${absoluteFilePath}`)
260
+ var modifiedFiles = (options || { modifiedFiles: { modifiedFiles: [] } }).modifiedFiles;
261
+ if (tnp_core_1.fse.existsSync(absoluteFilePath)) {
262
+ tnp_core_1.fse.unlinkSync(absoluteFilePath);
263
+ modifiedFiles.modifiedFiles.push(absoluteFilePath);
264
+ }
265
+ };
266
+ HelpersFileFolders.prototype.removeFolderIfExists = function (absoluteFolderPath, options) {
267
+ index_1.Helpers.log("[helpers] Remove folder: ".concat(absoluteFolderPath));
268
+ if (process.platform === 'win32') {
269
+ // rimraf.sync(absoluteFolderPath);
270
+ this.tryRemoveDir(absoluteFolderPath);
271
+ return;
272
+ }
273
+ var modifiedFiles = (options || { modifiedFiles: { modifiedFiles: [] } }).modifiedFiles;
274
+ if (tnp_core_1.fse.existsSync(absoluteFolderPath)) {
275
+ tnp_core_1.fse.removeSync(absoluteFolderPath);
276
+ modifiedFiles.modifiedFiles.push(absoluteFolderPath);
277
+ }
278
+ };
279
+ // private deleteFolderRecursive = (pathToFolder) => {
280
+ // if (fs.existsSync(pathToFolder)) {
281
+ // fs.readdirSync(pathToFolder).forEach((file, index) => {
282
+ // const curPath = path.join(pathToFolder, file);
283
+ // if (fs.lstatSync(curPath).isDirectory()) { // recurse
284
+ // this.deleteFolderRecursive(curPath);
285
+ // } else { // delete file
286
+ // fs.unlinkSync(curPath);
287
+ // }
288
+ // });
289
+ // fs.rmdirSync(pathToFolder);
290
+ // }
291
+ // };
292
+ HelpersFileFolders.prototype.tryRemoveDir = function (dirpath, contentOnly) {
293
+ if (contentOnly === void 0) { contentOnly = false; }
294
+ if (!tnp_core_1.fse.existsSync(dirpath)) {
295
+ index_1.Helpers.warn("Folder ".concat(tnp_core_1.path.basename(dirpath), " doesn't exist."));
296
+ return;
297
+ }
298
+ index_1.Helpers.log("[tnp-helpers][tryRemoveDir]: ".concat(dirpath));
299
+ try {
300
+ if (contentOnly) {
301
+ tnp_core_1.rimraf.sync("".concat(dirpath, "/*"));
302
+ }
303
+ else {
304
+ tnp_core_1.rimraf.sync(dirpath);
305
+ }
306
+ index_1.Helpers.log("Remove done: ".concat(dirpath));
307
+ return;
308
+ }
309
+ catch (e) {
310
+ index_1.Helpers.warn("\n\n Trying to remove directory: ".concat(dirpath, "\n\n\n (USER ACTION REQUIRED!!!)\n Please check if you did't open\n ").concat(dirpath, "\n in windows explorer\n\n\n "));
311
+ index_1.Helpers.sleep(1);
312
+ index_1.Helpers.tryRemoveDir(dirpath, contentOnly);
313
+ }
314
+ };
315
+ HelpersFileFolders.prototype.move = function (from, to) {
316
+ if (!tnp_core_1.fse.existsSync(from)) {
317
+ index_1.Helpers.warn("[move] File or folder doesnt not exists: ".concat(from));
318
+ return;
319
+ }
320
+ if (!tnp_core_1.path.isAbsolute(from)) {
321
+ index_1.Helpers.warn("[move] Source path is not absolute: ".concat(from));
322
+ return;
323
+ }
324
+ if (!tnp_core_1.path.isAbsolute(to)) {
325
+ index_1.Helpers.warn("[move] Destination path is not absolute: ".concat(to));
326
+ return;
327
+ }
328
+ tnp_core_1.fse.moveSync(from, to, {
329
+ overwrite: true
330
+ });
331
+ };
332
+ HelpersFileFolders.prototype.remove = function (fileOrFolderPathOrPatter, exactFolder) {
333
+ if (exactFolder === void 0) { exactFolder = false; }
334
+ if (Array.isArray(fileOrFolderPathOrPatter)) {
335
+ fileOrFolderPathOrPatter = tnp_core_1.path.join.apply(tnp_core_1.path, tslib_1.__spreadArray([], tslib_1.__read(fileOrFolderPathOrPatter), false));
336
+ }
337
+ index_1.Helpers.log("[tnp-helpers][remove]: ".concat(fileOrFolderPathOrPatter));
338
+ if (exactFolder) {
339
+ tnp_core_1.rimraf.sync(fileOrFolderPathOrPatter, { glob: false, disableGlob: true, });
340
+ return;
341
+ }
342
+ tnp_core_1.rimraf.sync(fileOrFolderPathOrPatter);
343
+ };
344
+ HelpersFileFolders.prototype.findChildren = function (location, createFn) {
345
+ var notAllowed = tslib_1.__spreadArray(tslib_1.__spreadArray([
346
+ '\.vscode', 'node\_modules'
347
+ ], tslib_1.__read(index_1.Helpers.values(tnp_config_1.config.folder)), false), [
348
+ 'e2e', 'tmp.*', 'dist.*', 'tests', 'module', 'browser', 'bundle*',
349
+ 'components', '\.git', 'bin', 'custom'
350
+ ], false).filter(function (f) {
351
+ return ![tnp_config_1.config.folder.external].includes(f) && tnp_core_1._.isString(f);
352
+ }).map(function (s) { return new RegExp(s); });
353
+ var isDirectory = function (source) { return tnp_core_1.fse.lstatSync(source).isDirectory(); };
354
+ var getDirectories = function (source) {
355
+ return tnp_core_1.fse.readdirSync(source).map(function (name) { return tnp_core_1.path.join(source, name); }).filter(isDirectory);
356
+ };
357
+ var subdirectories = getDirectories(location)
358
+ .filter(function (f) {
359
+ var folderNam = tnp_core_1.path.basename(f);
360
+ var allowed = (notAllowed.filter(function (p) { return p.test(folderNam); }).length === 0);
361
+ return allowed;
362
+ });
363
+ return subdirectories
364
+ .map(function (dir) {
365
+ // console.log('child:', dir)
366
+ return createFn(dir);
367
+ })
368
+ .filter(function (c) { return !!c; });
369
+ };
370
+ HelpersFileFolders.prototype.findChildrenNavi = function (location, createFn) {
371
+ if (!tnp_core_1.fse.existsSync(location)) {
372
+ return [];
373
+ }
374
+ var notAllowed = tslib_1.__spreadArray(tslib_1.__spreadArray([
375
+ '\.vscode', 'node\_modules'
376
+ ], tslib_1.__read(index_1.Helpers.values(tnp_config_1.config.folder)), false), [
377
+ 'e2e', 'tmp.*', 'dist.*', 'tests',
378
+ 'module', 'browser', 'bundle*',
379
+ 'components', '\.git', '\.build', 'bin', 'custom'
380
+ ], false).map(function (s) { return new RegExp(s); });
381
+ var isDirectory = function (source) { return tnp_core_1.fse.lstatSync(source).isDirectory(); };
382
+ var getDirectories = function (source) {
383
+ return tnp_core_1.fse.readdirSync(source).map(function (name) { return tnp_core_1.path.join(source, name); }).filter(isDirectory);
384
+ };
385
+ var subdirectories = getDirectories(location)
386
+ .filter(function (f) {
387
+ var folderName = tnp_core_1.path.basename(f);
388
+ if (/.*es\-.*/.test(folderName)) {
389
+ return true;
390
+ }
391
+ return (notAllowed.filter(function (p) { return p.test(folderName); }).length === 0);
392
+ });
393
+ return subdirectories
394
+ .map(function (dir) {
395
+ return createFn(dir);
396
+ })
397
+ .filter(function (c) { return !!c; });
398
+ };
399
+ HelpersFileFolders.prototype.getRecrusiveFilesFrom = function (dir, ommitFolders, options) {
400
+ if (ommitFolders === void 0) { ommitFolders = []; }
401
+ options = options ? options : {};
402
+ // const withNameOnly = options.withNameOnly;
403
+ var files = [];
404
+ var readedFilesAndFolders = tnp_core_1.fse.existsSync(dir) ? tnp_core_1.fse.readdirSync(dir) : [];
405
+ var readed = readedFilesAndFolders
406
+ .map(function (f) {
407
+ var fullPath = tnp_core_1.path.join(dir, f);
408
+ // console.log(`is direcotry ${fse.lstatSync(fullPath).isDirectory()} `, fullPath)
409
+ if (tnp_core_1.fse.lstatSync(fullPath).isDirectory()) {
410
+ if (ommitFolders.includes(tnp_core_1.path.basename(fullPath)) ||
411
+ ommitFolders.includes(tnp_core_1.path.basename(tnp_core_1.path.dirname(fullPath)))) {
412
+ // Helpers.log(`Omitting: ${fullPath}`)
413
+ }
414
+ else {
415
+ index_1.Helpers
416
+ .getRecrusiveFilesFrom(fullPath, ommitFolders, options)
417
+ .forEach(function (aa) { return files.push(aa); });
418
+ }
419
+ return;
420
+ }
421
+ return fullPath;
422
+ })
423
+ .filter(function (f) { return !!f; });
424
+ if (Array.isArray(readed)) {
425
+ readed.forEach(function (r) { return files.push(r); });
426
+ }
427
+ return files;
428
+ };
429
+ HelpersFileFolders.prototype.getLinesFromFiles = function (filename, lineCount) {
430
+ return new Promise(function (resolve, reject) {
431
+ var stream = tnp_core_1.fse.createReadStream(filename, {
432
+ flags: 'r',
433
+ encoding: 'utf-8',
434
+ fd: null,
435
+ mode: 438, // 0666 in Octal
436
+ // bufferSize: 64 * 1024 as any
437
+ });
438
+ var data = '';
439
+ var lines = [];
440
+ stream.on('data', function (moreData) {
441
+ data += moreData;
442
+ lines = data.split('\n');
443
+ // probably that last line is "corrupt" - halfway read - why > not >=
444
+ if (lines.length > lineCount + 1) {
445
+ stream.destroy();
446
+ lines = lines.slice(0, lineCount); // junk as above
447
+ resolve(lines);
448
+ }
449
+ });
450
+ stream.on('error', function () {
451
+ reject("Error reading ".concat(filename));
452
+ });
453
+ stream.on('end', function () {
454
+ resolve(lines);
455
+ });
456
+ });
457
+ };
458
+ ;
459
+ /**
460
+ * Get the most recent changes file in direcory
461
+ * @param dir absoulute path to file
462
+ */
463
+ HelpersFileFolders.prototype.getMostRecentFileName = function (dir) {
464
+ var files = index_1.Helpers.getRecrusiveFilesFrom(dir);
465
+ // use underscore for max()
466
+ return underscore.max(files, function (f) {
467
+ // console.log(f);
468
+ // ctime = creation time is used
469
+ // replace with mtime for modification time
470
+ // console.log( `${fse.statSync(f).mtimeMs} for ${f}` )
471
+ return tnp_core_1.fse.statSync(f).mtimeMs;
472
+ });
473
+ };
474
+ HelpersFileFolders.prototype.getMostRecentFilesNames = function (dir) {
475
+ var allFiles = index_1.Helpers.getRecrusiveFilesFrom(dir);
476
+ var mrf = index_1.Helpers.getMostRecentFileName(dir);
477
+ var mfrMtime = tnp_core_1.fse.lstatSync(mrf).mtimeMs;
478
+ return allFiles.filter(function (f) {
479
+ var info = tnp_core_1.fse.lstatSync(f);
480
+ return (info.mtimeMs === mfrMtime && !info.isDirectory());
481
+ });
482
+ };
483
+ HelpersFileFolders.prototype.removeExcept = function (fromPath, exceptFolderAndFiles) {
484
+ tnp_core_1.fse.readdirSync(fromPath)
485
+ .filter(function (f) {
486
+ return !exceptFolderAndFiles.includes(f);
487
+ })
488
+ .map(function (f) { return tnp_core_1.path.join(fromPath, f); })
489
+ .forEach(function (af) { return index_1.Helpers.removeFolderIfExists(af); });
490
+ (glob.sync("".concat(fromPath, "/*.*")))
491
+ .filter(function (f) {
492
+ return !exceptFolderAndFiles.includes(tnp_core_1.path.basename(f));
493
+ })
494
+ .forEach(function (af) { return index_1.Helpers.removeFileIfExists(af); });
495
+ };
496
+ HelpersFileFolders.prototype.copy = function (sourceDir, destinationDir, options) {
497
+ index_1.Helpers.log("Copying from:\n\n ".concat(sourceDir, "\n to\n ").concat(destinationDir, "\n\n "));
498
+ index_1.Helpers.log(options);
499
+ // sourceDir = sourceDir ? (sourceDir.replace(/\/$/, '')) : sourceDir;
500
+ // destinationDir = destinationDir ? (destinationDir.replace(/\/$/, '')) : destinationDir;
501
+ if (!tnp_core_1.fse.existsSync(sourceDir)) {
502
+ index_1.Helpers.warn("[tnp-helper][copy] Source dir doesnt exist: ".concat(sourceDir, " for destination: ").concat(destinationDir), trace);
503
+ return;
504
+ }
505
+ if (!tnp_core_1.fse.existsSync(tnp_core_1.path.dirname(destinationDir))) {
506
+ index_1.Helpers.mkdirp(tnp_core_1.path.dirname(destinationDir));
507
+ }
508
+ if (!options) {
509
+ options = {};
510
+ }
511
+ if (tnp_core_1._.isUndefined(options.overwrite)) {
512
+ options.overwrite = true;
513
+ }
514
+ if (tnp_core_1._.isUndefined(options.recursive)) {
515
+ options.recursive = true;
516
+ }
517
+ if (tnp_core_1._.isUndefined(options.useTempFolder)) {
518
+ options.useTempFolder = false;
519
+ }
520
+ if (options.copySymlinksAsFiles) {
521
+ options['dereference'] = true;
522
+ }
523
+ if (!options.omitFolders) {
524
+ options.omitFolders = [];
525
+ }
526
+ if (options.asSeparatedFilesSymlinkAsFile) {
527
+ options.asSeparatedFilesSymlinkAsFile = true;
528
+ }
529
+ // const [srcStat, destStat] = [
530
+ // fse.existsSync(sourceDir) && fse.statSync(sourceDir),
531
+ // fse.existsSync(destinationDir) && fse.statSync(destinationDir),
532
+ // ];
533
+ // if (destStat && destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) {
534
+ // Helpers.warn(`[tnp-helper][copy] Same location stats.. Trying to copy same source and destination:
535
+ // from: ${sourceDir}
536
+ // to: ${destinationDir}
537
+ // `);
538
+ // return;
539
+ // }
540
+ if (tnp_core_1._.isArray(options.omitFolders) && options.omitFolders.length >= 1
541
+ && tnp_core_1._.isNil(options.filter) && tnp_core_1._.isString(options.omitFoldersBaseFolder)
542
+ && tnp_core_1.path.isAbsolute(options.omitFoldersBaseFolder)) {
543
+ options.filter = index_1.Helpers.filterDontCopy(options.omitFolders, options.omitFoldersBaseFolder);
544
+ }
545
+ if (sourceDir === destinationDir || tnp_core_1.path.resolve(sourceDir) === tnp_core_1.path.resolve(destinationDir)) {
546
+ index_1.Helpers.warn("[tnp-helper][copy] Trying to copy same source and destination\n from: ".concat(sourceDir, "\n to: ").concat(destinationDir, "\n "));
547
+ }
548
+ else {
549
+ // Helpers.warn('filter', _.isFunction(options.filter));
550
+ // Helpers.warn('sourceDir', sourceDir);
551
+ // Helpers.warn('destinationDir', destinationDir);
552
+ // Helpers.log(JSON.stringify(options))
553
+ // try {
554
+ if (options.useTempFolder) {
555
+ var tempDestination = "".concat(tnp_core_1.os.platform() === 'darwin' ? '/private/tmp' : '/tmp', "/").concat(tnp_core_1._.camelCase(destinationDir));
556
+ index_1.Helpers.removeFolderIfExists(tempDestination);
557
+ tnp_core_1.fse.copySync(sourceDir, tempDestination, options);
558
+ tnp_core_1.fse.copySync(tempDestination, destinationDir, options);
559
+ }
560
+ else {
561
+ if ((sourceDir === tnp_core_1.path.resolve(sourceDir))
562
+ && index_1.Helpers.isExistedSymlink(sourceDir)
563
+ && !index_1.Helpers.exists(tnp_core_1.fse.readlinkSync(sourceDir))) {
564
+ index_1.Helpers.warn("[tnp-helpers] Not copying empty link from: ".concat(sourceDir, "\n "));
565
+ }
566
+ else {
567
+ var copyFn_1 = function () {
568
+ try {
569
+ if (options.asSeparatedFiles) {
570
+ var copyRecFn_1 = function (cwdForFiles) {
571
+ // if (path.basename(cwdForFiles) === 'plugins') {
572
+ // debugger
573
+ // }
574
+ var files = index_1.Helpers.getRecrusiveFilesFrom(cwdForFiles, options.omitFolders);
575
+ var _loop_1 = function (index) {
576
+ var from = files[index];
577
+ var to = from.replace(sourceDir, destinationDir);
578
+ if (index_1.Helpers.isFolder(from)) {
579
+ if (options.omitFolders.includes(tnp_core_1.path.basename(tnp_core_1.path.dirname(from))) ||
580
+ options.omitFolders.includes(tnp_core_1.path.basename(from))) {
581
+ return "continue";
582
+ }
583
+ else {
584
+ copyRecFn_1(from);
585
+ }
586
+ }
587
+ else {
588
+ var copyFileFn = function () {
589
+ if (!options.asSeparatedFilesSymlinkAsFile && index_1.Helpers.isExistedSymlink(from)) {
590
+ index_1.Helpers.createSymLink(from, to);
591
+ }
592
+ else {
593
+ index_1.Helpers.copyFile(from, to);
594
+ }
595
+ };
596
+ if (options.asSeparatedFilesAllowNotCopied) {
597
+ try {
598
+ copyFileFn();
599
+ }
600
+ catch (e) { }
601
+ }
602
+ else {
603
+ copyFileFn();
604
+ }
605
+ }
606
+ };
607
+ for (var index = 0; index < files.length; index++) {
608
+ _loop_1(index);
609
+ }
610
+ };
611
+ copyRecFn_1(sourceDir);
612
+ }
613
+ else {
614
+ tnp_core_1.fse.copySync(sourceDir, destinationDir, options);
615
+ }
616
+ }
617
+ catch (error) {
618
+ var exitOnError = global['tnpNonInteractive'];
619
+ index_1.Helpers.log(error);
620
+ index_1.Helpers.error("[tnp-helper] Not able to copy folder:\n from: ".concat(sourceDir, "\n to: ").concat(destinationDir, "\n options: ").concat(tnp_core_1.json5.stringify(options), "\n error: ").concat(error === null || error === void 0 ? void 0 : error.message, "\n "), !exitOnError, !trace);
621
+ index_1.Helpers.pressKeyAndContinue("Press any key to repeat copy action...");
622
+ copyFn_1();
623
+ }
624
+ };
625
+ copyFn_1();
626
+ }
627
+ }
628
+ // } catch (error) {
629
+ // console.trace(error);
630
+ // process.exit(0)
631
+ // }
632
+ }
633
+ };
634
+ HelpersFileFolders.prototype.filterDontCopy = function (basePathFoldersTosSkip, projectOrBasepath) {
635
+ return function (src, dest) {
636
+ // console.log('src', src)
637
+ src = (0, tnp_core_1.crossPlatformPath)(src);
638
+ var baseFolder = tnp_core_1._.first((0, tnp_core_1.crossPlatformPath)(src)
639
+ .replace((0, tnp_core_1.crossPlatformPath)(tnp_core_1._.isString(projectOrBasepath) ? projectOrBasepath : projectOrBasepath.location), '')
640
+ .replace(/^\//, '').split('/'));
641
+ // console.log('baseFolder', baseFolder)
642
+ if (!baseFolder || baseFolder.trim() === '') {
643
+ return true;
644
+ }
645
+ var isAllowed = tnp_core_1._.isUndefined(basePathFoldersTosSkip
646
+ .find(function (f) { return baseFolder.startsWith((0, tnp_core_1.crossPlatformPath)(f)); }));
647
+ // console.log('isAllowed', isAllowed)
648
+ return isAllowed;
649
+ };
650
+ };
651
+ HelpersFileFolders.prototype.filterOnlyCopy = function (basePathFoldersOnlyToInclude, projectOrBasepath) {
652
+ return function (src, dest) {
653
+ src = (0, tnp_core_1.crossPlatformPath)(src);
654
+ var baseFolder = tnp_core_1._.first((0, tnp_core_1.crossPlatformPath)(src)
655
+ .replace((0, tnp_core_1.crossPlatformPath)(tnp_core_1._.isString(projectOrBasepath) ? projectOrBasepath : projectOrBasepath.location), '')
656
+ .replace(/^\//, '').split('/'));
657
+ if (!baseFolder || baseFolder.trim() === '') {
658
+ return true;
659
+ }
660
+ var isAllowed = !tnp_core_1._.isUndefined(basePathFoldersOnlyToInclude
661
+ .find(function (f) { return baseFolder.startsWith((0, tnp_core_1.crossPlatformPath)(f)); }));
662
+ return isAllowed;
663
+ };
664
+ };
665
+ HelpersFileFolders.prototype.copyFile = function (sourcePath, destinationPath, options) {
666
+ if (tnp_core_1._.isUndefined(options)) {
667
+ options = {};
668
+ }
669
+ if (tnp_core_1._.isUndefined(options.debugMode)) {
670
+ options.debugMode = false;
671
+ }
672
+ if (tnp_core_1._.isUndefined(options.debugMode)) {
673
+ options.fast = true;
674
+ }
675
+ if (tnp_core_1._.isUndefined(options.dontCopySameContent)) {
676
+ options.dontCopySameContent = true;
677
+ }
678
+ var debugMode = options.debugMode, fast = options.fast, transformTextFn = options.transformTextFn, dontCopySameContent = options.dontCopySameContent, modifiedFiles = options.modifiedFiles;
679
+ if (tnp_core_1._.isFunction(transformTextFn) && fast) {
680
+ index_1.Helpers.error("[copyFile] You cannot use transformTextFn in fast mode");
681
+ }
682
+ if (!tnp_core_1.fse.existsSync(sourcePath)) {
683
+ index_1.Helpers.warn("[copyFile] No able to find source of ".concat(sourcePath));
684
+ return false;
685
+ }
686
+ if (tnp_core_1.fse.lstatSync(sourcePath).isDirectory()) {
687
+ index_1.Helpers.warn("[copyFile] Trying to copy directory as file: ".concat(sourcePath), false);
688
+ return false;
689
+ }
690
+ if (sourcePath === destinationPath) {
691
+ index_1.Helpers.warn("[copyFile] Trying to copy same file ".concat(sourcePath));
692
+ return false;
693
+ }
694
+ var destDirPath = tnp_core_1.path.dirname(destinationPath);
695
+ if (!tnp_core_1.fse.existsSync(destDirPath)) {
696
+ index_1.Helpers.mkdirp(destDirPath);
697
+ }
698
+ if (dontCopySameContent && tnp_core_1.fse.existsSync(destinationPath)) {
699
+ var destinationContent = index_1.Helpers.readFile(destinationPath);
700
+ var sourceContent = index_1.Helpers.readFile(sourcePath).toString();
701
+ if (destinationContent === sourceContent) {
702
+ // @REMEMBER uncomment if any problem
703
+ // Helpers.log(`Destination has the same content as source: ${path.basename(sourcePath)}`);
704
+ return false;
705
+ }
706
+ }
707
+ debugMode && index_1.Helpers.log("path.extname(sourcePath) ".concat(tnp_core_1.path.extname(sourcePath)));
708
+ if (fast || !tnp_config_1.config.extensions.modificableByReplaceFn.includes(tnp_core_1.path.extname(sourcePath))) {
709
+ tnp_core_1.fse.copyFileSync(sourcePath, destinationPath);
710
+ }
711
+ else {
712
+ var sourceData = index_1.Helpers.readFile(sourcePath).toString();
713
+ if (tnp_core_1._.isFunction(transformTextFn)) {
714
+ sourceData = transformTextFn(sourceData);
715
+ }
716
+ debugMode && index_1.Helpers.log("\n[copyFile] Write to: ".concat(destinationPath, " file:\n============================================================================================\n").concat(sourceData, "\n============================================================================================\n "));
717
+ index_1.Helpers.writeFile(destinationPath, sourceData);
718
+ }
719
+ if (modifiedFiles && tnp_core_1._.isArray(modifiedFiles.modifiedFiles)) {
720
+ modifiedFiles.modifiedFiles.push(destinationPath);
721
+ }
722
+ return true;
723
+ };
724
+ /**
725
+ * get real absolute path
726
+ */
727
+ HelpersFileFolders.prototype.resolve = function (fileOrFolderPath) {
728
+ if (fileOrFolderPath.startsWith('~')) {
729
+ fileOrFolderPath = tnp_core_1.path.join(tnp_core_1.os.homedir(), fileOrFolderPath.replace("~/", ''));
730
+ }
731
+ return tnp_core_1.path.resolve(fileOrFolderPath);
732
+ };
733
+ return HelpersFileFolders;
734
+ }());
735
+ exports.HelpersFileFolders = HelpersFileFolders;
736
+ //# sourceMappingURL=/Users/dariusz/projects/npm/tnp-helpers/tmp-bundle-release/bundle/project/tnp-helpers/bundle-nocutsrc/lib/helpers-file-folders.backend.js.map