tnp-helpers 13.0.37 → 13.1.1

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