tnp-helpers 19.0.4 → 19.0.6

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 (252) hide show
  1. package/browser/README.md +24 -24
  2. package/browser/fesm2022/tnp-helpers.mjs +1435 -139
  3. package/browser/fesm2022/tnp-helpers.mjs.map +1 -1
  4. package/browser/lib/base/classes/base-node-modules.d.ts +1 -1
  5. package/browser/lib/base/linked-project.d.ts +4 -1
  6. package/browser/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +6 -6
  7. package/browser/lib/build-info._auto-generated_.d.ts +2 -1
  8. package/browser/lib/utils.d.ts +36 -20
  9. package/browser/package.json +1 -1
  10. package/client/README.md +24 -24
  11. package/client/fesm2022/tnp-helpers.mjs +1435 -139
  12. package/client/fesm2022/tnp-helpers.mjs.map +1 -1
  13. package/client/lib/base/classes/base-node-modules.d.ts +1 -1
  14. package/client/lib/base/linked-project.d.ts +4 -1
  15. package/client/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +6 -6
  16. package/client/lib/build-info._auto-generated_.d.ts +2 -1
  17. package/client/lib/utils.d.ts +36 -20
  18. package/client/package.json +1 -1
  19. package/index.js.map +1 -1
  20. package/lib/base/classes/base-bower-json.js +2 -2
  21. package/lib/base/classes/base-bower-json.js.map +1 -1
  22. package/lib/base/classes/base-cli-worker/base-cli-worker-config.js +2 -2
  23. package/lib/base/classes/base-cli-worker/base-cli-worker-config.js.map +1 -1
  24. package/lib/base/classes/base-cli-worker/base-cli-worker-controller.d.ts +1 -1
  25. package/lib/base/classes/base-cli-worker/base-cli-worker-controller.js +14 -14
  26. package/lib/base/classes/base-cli-worker/base-cli-worker-controller.js.map +1 -1
  27. package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js +10 -10
  28. package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js.map +1 -1
  29. package/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +1 -1
  30. package/lib/base/classes/base-cli-worker/base-cli-worker.js +18 -18
  31. package/lib/base/classes/base-cli-worker/base-cli-worker.js.map +1 -1
  32. package/lib/base/classes/base-cli-worker/index.js.map +1 -1
  33. package/lib/base/classes/base-command-line-feature.backend.js +10 -10
  34. package/lib/base/classes/base-command-line-feature.backend.js.map +1 -1
  35. package/lib/base/classes/base-compiler-for-project.d.ts +1 -1
  36. package/lib/base/classes/base-compiler-for-project.js +13 -13
  37. package/lib/base/classes/base-compiler-for-project.js.map +1 -1
  38. package/lib/base/classes/base-db.js +7 -7
  39. package/lib/base/classes/base-db.js.map +1 -1
  40. package/lib/base/classes/base-debounce-compiler-for-project.d.ts +1 -1
  41. package/lib/base/classes/base-debounce-compiler-for-project.js +5 -5
  42. package/lib/base/classes/base-debounce-compiler-for-project.js.map +1 -1
  43. package/lib/base/classes/base-feature-for-project.js.map +1 -1
  44. package/lib/base/classes/base-git.js +24 -24
  45. package/lib/base/classes/base-git.js.map +1 -1
  46. package/lib/base/classes/base-global-command-line.backend.d.ts +3 -1
  47. package/lib/base/classes/base-global-command-line.backend.js +60 -49
  48. package/lib/base/classes/base-global-command-line.backend.js.map +1 -1
  49. package/lib/base/classes/base-ignore-hide.js +2 -2
  50. package/lib/base/classes/base-ignore-hide.js.map +1 -1
  51. package/lib/base/classes/base-json-file-reader.js +24 -24
  52. package/lib/base/classes/base-json-file-reader.js.map +1 -1
  53. package/lib/base/classes/base-library-build.js +52 -52
  54. package/lib/base/classes/base-library-build.js.map +1 -1
  55. package/lib/base/classes/base-linked-projects.js +23 -23
  56. package/lib/base/classes/base-linked-projects.js.map +1 -1
  57. package/lib/base/classes/base-node-modules.d.ts +1 -1
  58. package/lib/base/classes/base-node-modules.js +37 -37
  59. package/lib/base/classes/base-node-modules.js.map +1 -1
  60. package/lib/base/classes/base-npm-helpers.d.ts +1 -1
  61. package/lib/base/classes/base-npm-helpers.js +14 -14
  62. package/lib/base/classes/base-npm-helpers.js.map +1 -1
  63. package/lib/base/classes/base-package-json.d.ts +1 -1
  64. package/lib/base/classes/base-package-json.js +27 -27
  65. package/lib/base/classes/base-package-json.js.map +1 -1
  66. package/lib/base/classes/base-powershell.js +2 -2
  67. package/lib/base/classes/base-powershell.js.map +1 -1
  68. package/lib/base/classes/base-process-manager.js +8 -8
  69. package/lib/base/classes/base-process-manager.js.map +1 -1
  70. package/lib/base/classes/base-project-resolver.js +30 -30
  71. package/lib/base/classes/base-project-resolver.js.map +1 -1
  72. package/lib/base/classes/base-project.d.ts +2 -2
  73. package/lib/base/classes/base-project.js +62 -62
  74. package/lib/base/classes/base-project.js.map +1 -1
  75. package/lib/base/classes/base-quick-fixes.js +9 -9
  76. package/lib/base/classes/base-quick-fixes.js.map +1 -1
  77. package/lib/base/classes/base-release-process.d.ts +1 -1
  78. package/lib/base/classes/base-release-process.js +19 -19
  79. package/lib/base/classes/base-release-process.js.map +1 -1
  80. package/lib/base/classes/base-start-config.backend.js +13 -13
  81. package/lib/base/classes/base-start-config.backend.js.map +1 -1
  82. package/lib/base/classes/base-static-pages.js +6 -6
  83. package/lib/base/classes/base-static-pages.js.map +1 -1
  84. package/lib/base/classes/base-vscode.js +20 -20
  85. package/lib/base/classes/base-vscode.js.map +1 -1
  86. package/lib/base/classes/index.js.map +1 -1
  87. package/lib/base/commit-data.js +25 -25
  88. package/lib/base/commit-data.js.map +1 -1
  89. package/lib/base/config-database.js.map +1 -1
  90. package/lib/base/core-project.d.ts +1 -1
  91. package/lib/base/core-project.js +9 -9
  92. package/lib/base/core-project.js.map +1 -1
  93. package/lib/base/gh-temp-code.js +6 -6
  94. package/lib/base/gh-temp-code.js.map +1 -1
  95. package/lib/base/index-rebuilder.backend.js +1 -1
  96. package/lib/base/index-rebuilder.backend.js.map +1 -1
  97. package/lib/base/index.js.map +1 -1
  98. package/lib/base/linked-project.d.ts +4 -1
  99. package/lib/base/linked-project.js +18 -9
  100. package/lib/base/linked-project.js.map +1 -1
  101. package/lib/base/project-database.js.map +1 -1
  102. package/lib/base/tcp-udp-ports/index.js.map +1 -1
  103. package/lib/base/tcp-udp-ports/not-assignable-port.entity.js +2 -2
  104. package/lib/base/tcp-udp-ports/not-assignable-port.entity.js.map +1 -1
  105. package/lib/base/tcp-udp-ports/ports.controller.d.ts +1 -1
  106. package/lib/base/tcp-udp-ports/ports.controller.js +21 -21
  107. package/lib/base/tcp-udp-ports/ports.controller.js.map +1 -1
  108. package/lib/base/tcp-udp-ports/ports.entity.d.ts +1 -1
  109. package/lib/base/tcp-udp-ports/ports.entity.js +10 -10
  110. package/lib/base/tcp-udp-ports/ports.entity.js.map +1 -1
  111. package/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +9 -9
  112. package/lib/base/tcp-udp-ports/tcp-udp-ports.context.js +9 -9
  113. package/lib/base/tcp-udp-ports/tcp-udp-ports.context.js.map +1 -1
  114. package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js +18 -18
  115. package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js.map +1 -1
  116. package/lib/base/tcp-udp-ports/tcp-upd-ports.worker.js.map +1 -1
  117. package/lib/base/translate.js.map +1 -1
  118. package/lib/build-info._auto-generated_.d.ts +2 -1
  119. package/lib/build-info._auto-generated_.js +3 -2
  120. package/lib/build-info._auto-generated_.js.map +1 -1
  121. package/lib/helpers/for-backend/helpers-cli-tool.backend.js +40 -40
  122. package/lib/helpers/for-backend/helpers-cli-tool.backend.js.map +1 -1
  123. package/lib/helpers/for-backend/helpers-console-gui.js +2 -2
  124. package/lib/helpers/for-backend/helpers-console-gui.js.map +1 -1
  125. package/lib/helpers/for-backend/helpers-dependencies.backend.js +2 -2
  126. package/lib/helpers/for-backend/helpers-dependencies.backend.js.map +1 -1
  127. package/lib/helpers/for-backend/helpers-file-folders.js +131 -131
  128. package/lib/helpers/for-backend/helpers-file-folders.js.map +1 -1
  129. package/lib/helpers/for-backend/helpers-git.backend.js +105 -105
  130. package/lib/helpers/for-backend/helpers-git.backend.js.map +1 -1
  131. package/lib/helpers/for-backend/helpers-network.backend.js +2 -3
  132. package/lib/helpers/for-backend/helpers-network.backend.js.map +1 -1
  133. package/lib/helpers/for-backend/helpers-npm.backend.js +2 -2
  134. package/lib/helpers/for-backend/helpers-npm.backend.js.map +1 -1
  135. package/lib/helpers/for-backend/helpers-path.backend.js +6 -6
  136. package/lib/helpers/for-backend/helpers-path.backend.js.map +1 -1
  137. package/lib/helpers/for-backend/helpers-process.d.ts +1 -1
  138. package/lib/helpers/for-backend/helpers-process.js +41 -41
  139. package/lib/helpers/for-backend/helpers-process.js.map +1 -1
  140. package/lib/helpers/for-backend/helpers-system-terminal.backend.js +2 -2
  141. package/lib/helpers/for-backend/helpers-system-terminal.backend.js.map +1 -1
  142. package/lib/helpers/for-backend/helpers-vscode.backend.d.ts +1 -1
  143. package/lib/helpers/for-backend/helpers-vscode.backend.js +2 -2
  144. package/lib/helpers/for-backend/helpers-vscode.backend.js.map +1 -1
  145. package/lib/helpers/for-browser/angular.helper.js +2 -2
  146. package/lib/helpers/for-browser/angular.helper.js.map +1 -1
  147. package/lib/helpers/for-browser/helpers-browser.js.map +1 -1
  148. package/lib/helpers/helpers-array-obj.js +10 -10
  149. package/lib/helpers/helpers-array-obj.js.map +1 -1
  150. package/lib/helpers/helpers-json5.backend.js +6 -6
  151. package/lib/helpers/helpers-json5.backend.js.map +1 -1
  152. package/lib/helpers/helpers-numbers.js.map +1 -1
  153. package/lib/helpers/helpers-strings-regexes.js +5 -5
  154. package/lib/helpers/helpers-strings-regexes.js.map +1 -1
  155. package/lib/helpers/helpers-strings.js +3 -3
  156. package/lib/helpers/helpers-strings.js.map +1 -1
  157. package/lib/helpers/helpers.js +28 -28
  158. package/lib/helpers/helpers.js.map +1 -1
  159. package/lib/index._auto-generated_.js.map +1 -1
  160. package/lib/index.js.map +1 -1
  161. package/lib/lowdb/adapters/Memory.js.map +1 -1
  162. package/lib/lowdb/adapters/browser/LocalStorage.js.map +1 -1
  163. package/lib/lowdb/adapters/browser/SessionStorage.js.map +1 -1
  164. package/lib/lowdb/adapters/browser/WebStorage.js.map +1 -1
  165. package/lib/lowdb/adapters/node/DataFile.js.map +1 -1
  166. package/lib/lowdb/adapters/node/JSONFile.js.map +1 -1
  167. package/lib/lowdb/adapters/node/TextFile.js +2 -2
  168. package/lib/lowdb/adapters/node/TextFile.js.map +1 -1
  169. package/lib/lowdb/adapters/node/steno.js.map +1 -1
  170. package/lib/lowdb/browser.js.map +1 -1
  171. package/lib/lowdb/core/Low.js.map +1 -1
  172. package/lib/lowdb/examples/browser.js.map +1 -1
  173. package/lib/lowdb/examples/cli.js.map +1 -1
  174. package/lib/lowdb/examples/in-memory.js.map +1 -1
  175. package/lib/lowdb/examples/server.js.map +1 -1
  176. package/lib/lowdb/index.js.map +1 -1
  177. package/lib/lowdb/node.js.map +1 -1
  178. package/lib/lowdb/presets/browser.js.map +1 -1
  179. package/lib/lowdb/presets/node.js.map +1 -1
  180. package/lib/models.d.ts +1 -1
  181. package/lib/models.js +8 -8
  182. package/lib/models.js.map +1 -1
  183. package/lib/old/base-component.js +2 -2
  184. package/lib/old/base-component.js.map +1 -1
  185. package/lib/old/base-formly-component.js +2 -2
  186. package/lib/old/base-formly-component.js.map +1 -1
  187. package/lib/old/condition-wait.js.map +1 -1
  188. package/lib/old/dual-component-ctrl.js +2 -2
  189. package/lib/old/dual-component-ctrl.js.map +1 -1
  190. package/lib/old/execute-command.js.map +1 -1
  191. package/lib/old/helpers.js +2 -2
  192. package/lib/old/helpers.js.map +1 -1
  193. package/lib/old/models.d.ts +1 -1
  194. package/lib/old/models.js.map +1 -1
  195. package/lib/utils.d.ts +36 -20
  196. package/lib/utils.js +288 -52
  197. package/lib/utils.js.map +1 -1
  198. package/lib/validators/validators-firedev.js +6 -6
  199. package/lib/validators/validators-firedev.js.map +1 -1
  200. package/lib/validators/validators-git.js.map +1 -1
  201. package/lib/validators/validators-network.js +2 -2
  202. package/lib/validators/validators-network.js.map +1 -1
  203. package/lib/validators/validators.js.map +1 -1
  204. package/migrations/1736198527297_init.d.ts +1 -1
  205. package/migrations/1736198527297_init.js +5 -5
  206. package/migrations/1736198527297_init.js.map +1 -1
  207. package/migrations/1736199486472_addingNotAssignablePorts.d.ts +1 -1
  208. package/migrations/1736199486472_addingNotAssignablePorts.js +8 -8
  209. package/migrations/1736199486472_addingNotAssignablePorts.js.map +1 -1
  210. package/migrations/1736454437350_addFreePorts.d.ts +1 -1
  211. package/migrations/1736454437350_addFreePorts.js +11 -11
  212. package/migrations/1736454437350_addFreePorts.js.map +1 -1
  213. package/migrations/index.js.map +1 -1
  214. package/migrations/migrations_index._auto-generated_.js.map +1 -1
  215. package/package.json +1 -1
  216. package/tmp-environment.json +4 -4
  217. package/websql/README.md +24 -24
  218. package/websql/fesm2022/tnp-helpers.mjs +1472 -143
  219. package/websql/fesm2022/tnp-helpers.mjs.map +1 -1
  220. package/websql/lib/base/classes/base-node-modules.d.ts +1 -1
  221. package/websql/lib/base/linked-project.d.ts +4 -1
  222. package/websql/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +6 -6
  223. package/websql/lib/build-info._auto-generated_.d.ts +2 -1
  224. package/websql/lib/utils.d.ts +36 -20
  225. package/websql/package.json +1 -1
  226. package/lib/base/classes/base-cli-worker-config.d.ts +0 -27
  227. package/lib/base/classes/base-cli-worker-config.js +0 -64
  228. package/lib/base/classes/base-cli-worker-config.js.map +0 -1
  229. package/lib/base/classes/base-cli-worker-controller.d.ts +0 -15
  230. package/lib/base/classes/base-cli-worker-controller.js +0 -124
  231. package/lib/base/classes/base-cli-worker-controller.js.map +0 -1
  232. package/lib/base/classes/base-cli-worker.d.ts +0 -111
  233. package/lib/base/classes/base-cli-worker.js +0 -535
  234. package/lib/base/classes/base-cli-worker.js.map +0 -1
  235. package/lib/base/classes/base-detached-service.d.ts +0 -6
  236. package/lib/base/classes/base-detached-service.js +0 -16
  237. package/lib/base/classes/base-detached-service.js.map +0 -1
  238. package/lib/base/classes/base-github-pages.d.ts +0 -14
  239. package/lib/base/classes/base-github-pages.js +0 -173
  240. package/lib/base/classes/base-github-pages.js.map +0 -1
  241. package/lib/helpers/for-backend/helpers-file-folders.backend.d.ts +0 -104
  242. package/lib/helpers/for-backend/helpers-file-folders.backend.js +0 -896
  243. package/lib/helpers/for-backend/helpers-file-folders.backend.js.map +0 -1
  244. package/lib/helpers/for-backend/helpers-process.backend.d.ts +0 -87
  245. package/lib/helpers/for-backend/helpers-process.backend.js +0 -456
  246. package/lib/helpers/for-backend/helpers-process.backend.js.map +0 -1
  247. package/lib/helpers/for-backend/ts-code/index.d.ts +0 -1
  248. package/lib/helpers/for-backend/ts-code/index.js +0 -5
  249. package/lib/helpers/for-backend/ts-code/index.js.map +0 -1
  250. package/lib/helpers/for-backend/ts-code/ts-import-export-extractor.d.ts +0 -29
  251. package/lib/helpers/for-backend/ts-code/ts-import-export-extractor.js +0 -81
  252. package/lib/helpers/for-backend/ts-code/ts-import-export-extractor.js.map +0 -1
@@ -1,896 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HelpersFileFolders = void 0;
4
- const tnp_core_1 = require("tnp-core");
5
- const underscore = require("underscore");
6
- const glob = require("glob");
7
- const crypto = require("crypto");
8
- const index_1 = require("../../index");
9
- const tnp_config_1 = require("tnp-config");
10
- class HelpersFileFolders {
11
- /**
12
- * Calculate file or string checksum
13
- */
14
- checksum(absolutePathToFileOrContent, algorithm) {
15
- const fileContent = tnp_core_1.path.isAbsolute(absolutePathToFileOrContent)
16
- ? index_1.Helpers.readFile(absolutePathToFileOrContent)
17
- : absolutePathToFileOrContent;
18
- return crypto
19
- .createHash(algorithm || 'md5')
20
- .update(fileContent, 'utf8')
21
- .digest('hex');
22
- }
23
- getValueFromJSON(filepath, lodashGetPath, defaultValue = void 0) {
24
- if (!tnp_core_1.fse.existsSync(filepath)) {
25
- return defaultValue;
26
- }
27
- const json = index_1.Helpers.readJson(filepath);
28
- return tnp_core_1._.get(json, lodashGetPath, defaultValue);
29
- }
30
- getValueFromJSONC(filepath, lodashGetPath, defaultValue = void 0) {
31
- if (!tnp_core_1.fse.existsSync(filepath)) {
32
- return defaultValue;
33
- }
34
- const json = index_1.Helpers.readJson5(filepath);
35
- return tnp_core_1._.get(json, lodashGetPath, defaultValue);
36
- }
37
- readValueFromJson(filepath, lodashGetPath, defaultValue = void 0) {
38
- return index_1.Helpers.getValueFromJSON(filepath, lodashGetPath, defaultValue);
39
- }
40
- readValueFromJsonC(filepath, lodashGetPath, defaultValue = void 0) {
41
- return index_1.Helpers.getValueFromJSONC(filepath, lodashGetPath, defaultValue);
42
- }
43
- setValueToJSON(filepath, lodashGetPath, value) {
44
- if (!tnp_core_1.fse.existsSync(filepath)) {
45
- index_1.Helpers.warn(`Recreating unexised json file: ${filepath}`);
46
- index_1.Helpers.writeFile(filepath, '{}');
47
- }
48
- const json = index_1.Helpers.readJson(filepath);
49
- tnp_core_1._.set(json, lodashGetPath, value);
50
- index_1.Helpers.writeJson(filepath, json);
51
- }
52
- setValueToJSONC(filepath, lodashGetPath, value) {
53
- if (!tnp_core_1.fse.existsSync(filepath)) {
54
- index_1.Helpers.warn(`Recreating unexised json file: ${filepath}`);
55
- index_1.Helpers.writeFile(filepath, '{}');
56
- }
57
- const json = index_1.Helpers.readJsonC(filepath);
58
- tnp_core_1._.set(json, lodashGetPath, value);
59
- index_1.Helpers.writeJsonC(filepath, json);
60
- }
61
- /**
62
- * file size in bytes
63
- */
64
- size(filePath) {
65
- if (!index_1.Helpers.exists(filePath) || index_1.Helpers.isFolder(filePath)) {
66
- return null;
67
- }
68
- return tnp_core_1.fse.lstatSync(filePath).size;
69
- }
70
- pathFromLink(filePath) {
71
- return tnp_core_1.fse.readlinkSync(filePath);
72
- }
73
- // renameFolder(from: string, to: string, cwd?: string) {
74
- // // const command = `mv ${from} ${to}`;
75
- // const command = `renamer --find ${from} --replace ${to} *`;
76
- // Helpers.run(command, { cwd }).sync()
77
- // }
78
- /**
79
- * @deprecated
80
- */
81
- renameFolder(from, to, cwd) {
82
- index_1.Helpers.renameFiles(from, to, cwd);
83
- }
84
- /**
85
- * @deprecated
86
- */
87
- renameFiles(from, to, cwd) {
88
- try {
89
- const directoryPath = cwd || '.';
90
- // Read all files in the directory
91
- const files = tnp_core_1.fse.readdirSync(directoryPath);
92
- files.forEach(file => {
93
- // Check if the file name includes the 'from' pattern
94
- if (file.includes(from)) {
95
- const newFileName = file.replace(from, to);
96
- const currentPath = tnp_core_1.path.join(directoryPath, file);
97
- const newPath = tnp_core_1.path.join(directoryPath, newFileName);
98
- // Rename the file
99
- tnp_core_1.fse.renameSync(currentPath, newPath);
100
- console.log(`Renamed file from ${currentPath} to ${newPath}`);
101
- }
102
- });
103
- }
104
- catch (error) {
105
- console.error(`Error renaming files from ${from} to ${to}:`, error);
106
- }
107
- }
108
- getTempFolder() {
109
- let tmp = '/tmp';
110
- if (process.platform === 'darwin') {
111
- tmp = '/private/tmp';
112
- }
113
- if (process.platform === 'win32') {
114
- tmp = (0, tnp_core_1.crossPlatformPath)(tnp_core_1.path.join((0, tnp_core_1.crossPlatformPath)(tnp_core_1.os.homedir()), '/AppData/Local/Temp'));
115
- }
116
- if (!index_1.Helpers.exists(tmp)) {
117
- index_1.Helpers.mkdirp(tmp);
118
- }
119
- return tmp;
120
- }
121
- // createMultiplatformLink(target: string, link: string) {
122
- // if (this.isPlainFileOrFolder(link)) {
123
- // link = path.join(process.cwd(), link);
124
- // }
125
- // let command: string;
126
- // if (os.platform() === 'win32') {
127
- // if (target.startsWith('./')) {
128
- // target = path.win32.normalize(path.join(process.cwd(), path.basename(target)))
129
- // } else {
130
- // if (target === '.' || target === './') {
131
- // target = path.win32.normalize(path.join(process.cwd(), path.basename(link)))
132
- // } else {
133
- // target = path.win32.normalize(path.join(target, path.basename(link)))
134
- // }
135
- // }
136
- // if (fse.existsSync(target)) {
137
- // fse.unlinkSync(target);
138
- // }
139
- // target = path.win32.normalize(target)
140
- // if (link === '.' || link === './') {
141
- // link = process.cwd()
142
- // }
143
- // link = path.win32.normalize(link);
144
- // // if (path.resolve(target) === path.resolve(link)) { // TODO
145
- // // Helpers.warn(`[createMultiplatformLink][win32] Trying to link same location`);
146
- // // return;
147
- // // }
148
- // command = "mklink \/D "
149
- // + target
150
- // + " "
151
- // + link
152
- // + " >nul 2>&1 "
153
- // } else {
154
- // if (target.startsWith('./')) {
155
- // target = target.replace(/^\.\//g, '');
156
- // }
157
- // if (link === '.' || link === './') {
158
- // link = process.cwd()
159
- // }
160
- // if (path.resolve(target) === path.resolve(link)) {
161
- // Helpers.warn(`[createMultiplatformLink] Trying to link same location`);
162
- // return;
163
- // }
164
- // command = `ln -sf "${link}" "${target}"`;
165
- // }
166
- // child_process.execSync(command);
167
- // }
168
- isPlainFileOrFolder(filePath) {
169
- return /^([a-zA-Z]|\-|\_|\@|\#|\$|\!|\^|\&|\*|\(|\))+$/.test(filePath);
170
- }
171
- /**
172
- * @deprecated
173
- * use import (or modules only on backend)
174
- */
175
- requireUncached(module) {
176
- delete require.cache[require.resolve(module)];
177
- return require(module);
178
- }
179
- /**
180
- * @deprecated
181
- * use import (or modules only on backend)
182
- *
183
- * get default export object from js file
184
- * @param jsFilePath
185
- */
186
- require(jsFilePath) {
187
- //#region @backendFunc
188
- const orgPath = jsFilePath;
189
- if (!tnp_core_1.fse.existsSync(jsFilePath)) {
190
- jsFilePath = `${jsFilePath}.js`;
191
- }
192
- if (!tnp_core_1.fse.existsSync(jsFilePath)) {
193
- index_1.Helpers.error(`Not able to find path: ${orgPath}`);
194
- }
195
- let fileContent = tnp_core_1.fse.readFileSync(jsFilePath).toLocaleString();
196
- (() => {
197
- const stringForRegex = `require\\(("|')\\.\\/([a-zA-Z0-9]|\\/|\\-|\\_|\\+|\\.)*("|')\\)`;
198
- index_1.Helpers.log(`[taon-helpre][require][${jsFilePath}] stringForRegex: ${stringForRegex}`, 1);
199
- fileContent = fileContent
200
- .split('\n')
201
- .map(line => {
202
- const matches = line.match(new RegExp(stringForRegex));
203
- if (matches !== null) {
204
- // console.log('matched', matches)
205
- const rep = tnp_core_1._.first(matches);
206
- if (rep) {
207
- const newFilename = (0, tnp_core_1.crossPlatformPath)([
208
- tnp_core_1.path.dirname(jsFilePath),
209
- rep.split('(')[1].replace(/("|'|\))/g, ''),
210
- ]);
211
- line = line.replace(rep, `require('${newFilename}')`);
212
- }
213
- // console.log(line)
214
- }
215
- // console.log('matched', matches)
216
- return line;
217
- })
218
- .join('\n');
219
- })();
220
- (() => {
221
- const stringForRegex = `require\\(("|')([a-zA-Z0-9]|\\/|\\-|\\_|\\+|\\.)*("|')\\)`;
222
- index_1.Helpers.log(`[taon-helpre][require][${jsFilePath}] stringForRegex: ${stringForRegex}`, 1);
223
- fileContent = fileContent
224
- .split('\n')
225
- .map(line => {
226
- // console.log(`LINE: "${line}"`)
227
- const matches = line.match(new RegExp(stringForRegex));
228
- if (matches !== null) {
229
- // console.log('matched', matches)
230
- const rep = tnp_core_1._.first(matches);
231
- if (rep) {
232
- const relativePart = rep.split('(')[1].replace(/("|'|\))/g, '');
233
- // console.log(`RELATIVE PART: "${relativePart}"`)
234
- if (relativePart.search('/') !== -1 &&
235
- !relativePart.startsWith('/')) {
236
- const newFilename = (0, tnp_core_1.crossPlatformPath)([
237
- tnp_core_1.path.dirname(jsFilePath),
238
- 'node_modules',
239
- relativePart,
240
- ]);
241
- line = line.replace(rep, `require('${newFilename}')`);
242
- }
243
- }
244
- // console.log(line)
245
- }
246
- // console.log('matched', matches)
247
- return line;
248
- })
249
- .join('\n');
250
- })();
251
- return eval(fileContent);
252
- //#endregion
253
- }
254
- tryRecreateDir(dirpath) {
255
- try {
256
- index_1.Helpers.mkdirp(dirpath);
257
- }
258
- catch (error) {
259
- index_1.Helpers.log(`Trying to recreate directory: ${dirpath}`);
260
- index_1.Helpers.sleep(1);
261
- index_1.Helpers.mkdirp(dirpath);
262
- }
263
- }
264
- /**
265
- * @deprecated
266
- */
267
- tryCopyFrom(source, destination, options = {}) {
268
- index_1.Helpers.log(`Trying to copy from: ${source} to ${destination}`);
269
- destination = (0, tnp_core_1.crossPlatformPath)(destination);
270
- source = (0, tnp_core_1.crossPlatformPath)(source);
271
- if (source === destination) {
272
- index_1.Helpers.warn('[taon-helpers] Probably error... trying to copy the same folder...');
273
- return;
274
- }
275
- if (tnp_core_1.fse.existsSync(source) && !tnp_core_1.fse.lstatSync(source).isDirectory()) {
276
- // Helpers.warn(`[tryCopyFrom] This source is not directory: ${source} to ${destination}`);
277
- index_1.Helpers.copyFile(source, destination);
278
- return;
279
- }
280
- if (tnp_core_1.fse.existsSync(destination.replace(/\/$/, ''))) {
281
- const destMaybe = destination.replace(/\/$/, '');
282
- const stats = tnp_core_1.fse.lstatSync(destMaybe);
283
- const isNotDirectory = !stats.isDirectory();
284
- const isSymbolicLink = stats.isSymbolicLink();
285
- if (isNotDirectory || isSymbolicLink) {
286
- tnp_core_1.rimraf.sync(destMaybe);
287
- }
288
- }
289
- options = tnp_core_1._.merge({
290
- overwrite: true,
291
- recursive: true,
292
- }, options);
293
- if (process.platform === 'win32') {
294
- // TODO QUICK_FIX
295
- options['dereference'] = true;
296
- }
297
- try {
298
- tnp_core_1.fse.copySync(source, destination, options);
299
- }
300
- catch (error) {
301
- tnp_core_1.rimraf.sync(destination);
302
- tnp_core_1.fse.copySync(source, destination, options);
303
- }
304
- }
305
- // private deleteFolderRecursive = (pathToFolder) => {
306
- // if (fs.existsSync(pathToFolder)) {
307
- // fs.readdirSync(pathToFolder).forEach((file, index) => {
308
- // const curPath = path.join(pathToFolder, file);
309
- // if (fs.lstatSync(curPath).isDirectory()) { // recurse
310
- // this.deleteFolderRecursive(curPath);
311
- // } else { // delete file
312
- // fs.unlinkSync(curPath);
313
- // }
314
- // });
315
- // fs.rmdirSync(pathToFolder);
316
- // }
317
- // };
318
- move(from, to) {
319
- if (!tnp_core_1.fse.existsSync(from)) {
320
- index_1.Helpers.warn(`[move] File or folder doesnt not exists: ${from}`);
321
- return;
322
- }
323
- if (!tnp_core_1.path.isAbsolute(from)) {
324
- index_1.Helpers.warn(`[move] Source path is not absolute: ${from}`);
325
- return;
326
- }
327
- if (!tnp_core_1.path.isAbsolute(to)) {
328
- index_1.Helpers.warn(`[move] Destination path is not absolute: ${to}`);
329
- return;
330
- }
331
- if (index_1.Helpers.isUnexistedLink(to)) {
332
- index_1.Helpers.remove(to);
333
- }
334
- if (index_1.Helpers.isUnexistedLink(tnp_core_1.path.dirname(to))) {
335
- index_1.Helpers.remove(tnp_core_1.path.dirname(to));
336
- }
337
- // if (!Helpers.exists(path.dirname(to))) {
338
- // if (Helpers.isUnexistedLink(path.dirname(to))) {
339
- // Helpers.remove(path.dirname(to));
340
- // } else {
341
- // Helpers.remove(path.dirname(to));
342
- // Helpers.mkdirp(path.dirname(to));
343
- // }
344
- // }
345
- // if(Helpers.isSymlinkFileExitedOrUnexisted(to)) {
346
- // Helpers.error(`You are trying to move into symlink location:
347
- // from: ${from}
348
- // to: ${to}
349
- // `)
350
- // }
351
- while (true) {
352
- try {
353
- tnp_core_1.fse.moveSync(from, to, {
354
- overwrite: true,
355
- });
356
- break;
357
- }
358
- catch (error) {
359
- if (global['tnpNonInteractive']) {
360
- console.log(error);
361
- index_1.Helpers.error(`[${tnp_config_1.config.frameworkName}-helpers] Not able to move files
362
-
363
- from: ${from}
364
- to: ${to}
365
-
366
- `);
367
- }
368
- index_1.Helpers.info(`
369
- Moving things:
370
-
371
- from: ${from}
372
- to: ${to}
373
-
374
- `);
375
- index_1.Helpers.pressKeyAndContinue('Press any to try again this action');
376
- }
377
- }
378
- }
379
- findChildren(location, createFn, options) {
380
- const { allowAllNames } = options || {};
381
- let folders = index_1.Helpers.values(tnp_config_1.config.folder);
382
- folders = folders.filter(f => ![
383
- tnp_config_1.config.folder.shared,
384
- // TODO add something more here ?
385
- ].includes(f));
386
- const notAllowed = [
387
- '.vscode',
388
- 'node_modules',
389
- ...(allowAllNames
390
- ? []
391
- : [
392
- ...folders,
393
- 'e2e',
394
- 'tmp.*',
395
- 'dist.*',
396
- 'tests',
397
- 'module',
398
- 'browser',
399
- 'bundle*',
400
- 'components',
401
- '.git',
402
- 'bin',
403
- 'custom',
404
- ]),
405
- ]
406
- .filter(f => {
407
- return ![tnp_config_1.config.folder.external].includes(f) && tnp_core_1._.isString(f);
408
- })
409
- .map(s => new RegExp(`^${index_1.Helpers.escapeStringForRegEx(s)}$`));
410
- const isDirectory = (source) => tnp_core_1.fse.lstatSync(source).isDirectory();
411
- const getDirectories = (source) => tnp_core_1.fse
412
- .readdirSync(source)
413
- .map(name => tnp_core_1.path.join(source, name))
414
- .filter(isDirectory);
415
- let subdirectories = getDirectories(location).filter(f => {
416
- const folderNam = tnp_core_1.path.basename(f);
417
- const allowed = notAllowed.filter(p => p.test(folderNam)).length === 0;
418
- return allowed;
419
- });
420
- // console.log(subdirectories)
421
- return subdirectories
422
- .map(dir => {
423
- // console.log('child:', dir)
424
- return createFn(dir);
425
- })
426
- .filter(c => !!c);
427
- }
428
- /**
429
- * @deprecated
430
- */
431
- findChildrenNavi(location, createFn) {
432
- if (!tnp_core_1.fse.existsSync(location)) {
433
- return [];
434
- }
435
- const notAllowed = [
436
- '.vscode',
437
- 'node_modules',
438
- ...index_1.Helpers.values(tnp_config_1.config.folder),
439
- 'e2e',
440
- 'tmp.*',
441
- 'dist.*',
442
- 'tests',
443
- 'module',
444
- 'browser',
445
- 'bundle*',
446
- 'components',
447
- '.git',
448
- '.build',
449
- 'bin',
450
- 'custom',
451
- ].map(s => new RegExp(s));
452
- const isDirectory = source => tnp_core_1.fse.lstatSync(source).isDirectory();
453
- const getDirectories = source => tnp_core_1.fse
454
- .readdirSync(source)
455
- .map(name => tnp_core_1.path.join(source, name))
456
- .filter(isDirectory);
457
- let subdirectories = getDirectories(location).filter(f => {
458
- const folderName = tnp_core_1.path.basename(f);
459
- if (/.*es\-.*/.test(folderName)) {
460
- return true;
461
- }
462
- return notAllowed.filter(p => p.test(folderName)).length === 0;
463
- });
464
- return subdirectories
465
- .map(dir => {
466
- return createFn(dir);
467
- })
468
- .filter(c => !!c);
469
- }
470
- /**
471
- * get all files from folder
472
- * absolute paths
473
- */
474
- getRecrusiveFilesFrom(dir, ommitFolders = [], options) {
475
- options = options ? options : {};
476
- // const withNameOnly = options.withNameOnly;
477
- let files = [];
478
- const readedFilesAndFolders = tnp_core_1.fse.existsSync(dir)
479
- ? tnp_core_1.fse.readdirSync(dir)
480
- : [];
481
- const readed = readedFilesAndFolders
482
- .map(relativePathToFile => {
483
- const fullPath = (0, tnp_core_1.crossPlatformPath)([dir, relativePathToFile]);
484
- // console.log(`is direcotry ${fse.lstatSync(fullPath).isDirectory()} `, fullPath)
485
- if (tnp_core_1.fse.lstatSync(fullPath).isDirectory()) {
486
- if (ommitFolders.includes(tnp_core_1.path.basename(fullPath)) ||
487
- ommitFolders.includes(tnp_core_1.path.basename(tnp_core_1.path.dirname(fullPath)))) {
488
- // Helpers.log(`Omitting: ${fullPath}`)
489
- }
490
- else {
491
- index_1.Helpers.getRecrusiveFilesFrom(fullPath, ommitFolders, options).forEach(aa => files.push(aa));
492
- }
493
- return;
494
- }
495
- return fullPath;
496
- })
497
- .filter(f => !!f);
498
- if (Array.isArray(readed)) {
499
- readed.forEach(r => files.push(r));
500
- }
501
- return files;
502
- }
503
- checkIfNameAllowedForTaonProj(folderName) {
504
- const notAllowed = [
505
- '^.vscode$',
506
- '^node_modules$',
507
- ...index_1.Helpers.values(tnp_config_1.config.tempFolders).map(v => `^${v}$`),
508
- '^e2e$',
509
- '^tmp.*',
510
- '^dist.*',
511
- '^tests$',
512
- '^module$',
513
- '^browser',
514
- 'bundle*',
515
- '^components$',
516
- '.git',
517
- '^bin$',
518
- '^custom$',
519
- '^linked-repos$',
520
- ].map(s => new RegExp(s));
521
- return notAllowed.filter(p => p.test(folderName)).length === 0;
522
- }
523
- getLinesFromFiles(filename, lineCount) {
524
- return new Promise((resolve, reject) => {
525
- let stream = tnp_core_1.fse.createReadStream(filename, {
526
- flags: 'r',
527
- encoding: 'utf-8',
528
- fd: null,
529
- mode: 438, // 0666 in Octal
530
- // bufferSize: 64 * 1024 as any
531
- });
532
- let data = '';
533
- let lines = [];
534
- stream.on('data', function (moreData) {
535
- data += moreData;
536
- lines = data.split('\n');
537
- // probably that last line is "corrupt" - halfway read - why > not >=
538
- if (lines.length > lineCount + 1) {
539
- stream.destroy();
540
- lines = lines.slice(0, lineCount); // junk as above
541
- resolve(lines);
542
- }
543
- });
544
- stream.on('error', function () {
545
- reject(`Error reading ${filename}`);
546
- });
547
- stream.on('end', function () {
548
- resolve(lines);
549
- });
550
- });
551
- }
552
- /**
553
- * Get the most recent changes file in direcory
554
- * @param dir absoulute path to file
555
- */
556
- getMostRecentFileName(dir) {
557
- let files = index_1.Helpers.getRecrusiveFilesFrom(dir);
558
- // use underscore for max()
559
- return underscore.max(files, f => {
560
- // TODO refactor to lodash
561
- // console.log(f);
562
- // ctime = creation time is used
563
- // replace with mtime for modification time
564
- // console.log( `${fse.statSync(f).mtimeMs} for ${f}` )
565
- return tnp_core_1.fse.statSync(f).mtimeMs;
566
- });
567
- }
568
- getMostRecentFilesNames(dir) {
569
- const allFiles = index_1.Helpers.getRecrusiveFilesFrom(dir);
570
- const mrf = index_1.Helpers.getMostRecentFileName(dir);
571
- const mfrMtime = tnp_core_1.fse.lstatSync(mrf).mtimeMs;
572
- return allFiles.filter(f => {
573
- const info = tnp_core_1.fse.lstatSync(f);
574
- return info.mtimeMs === mfrMtime && !info.isDirectory();
575
- });
576
- }
577
- removeExcept(fromPath, exceptFolderAndFiles) {
578
- tnp_core_1.fse
579
- .readdirSync(fromPath)
580
- .filter(f => {
581
- return !exceptFolderAndFiles.includes(f);
582
- })
583
- .map(f => tnp_core_1.path.join(fromPath, f))
584
- .forEach(af => index_1.Helpers.removeFolderIfExists(af));
585
- glob
586
- .sync(`${fromPath}/*.*`)
587
- .filter(f => {
588
- return !exceptFolderAndFiles.includes(tnp_core_1.path.basename(f));
589
- })
590
- .forEach(af => index_1.Helpers.removeFileIfExists(af));
591
- }
592
- copy(sourceDir, destinationDir, options) {
593
- index_1.Helpers.log(`Copying from:
594
-
595
- ${sourceDir}
596
- to
597
- ${destinationDir}
598
-
599
- `, 1);
600
- index_1.Helpers.log(options, 1);
601
- // sourceDir = sourceDir ? (sourceDir.replace(/\/$/, '')) : sourceDir;
602
- // destinationDir = destinationDir ? (destinationDir.replace(/\/$/, '')) : destinationDir;
603
- if (!tnp_core_1.fse.existsSync(sourceDir)) {
604
- index_1.Helpers.warn(`[taon-helper][copy] Source dir doesnt exist: ${sourceDir} for destination: ${destinationDir}`);
605
- return;
606
- }
607
- if (!tnp_core_1.fse.existsSync(tnp_core_1.path.dirname(destinationDir))) {
608
- if (index_1.Helpers.isUnexistedLink(tnp_core_1.path.dirname(destinationDir))) {
609
- index_1.Helpers.removeFileIfExists(tnp_core_1.path.dirname(destinationDir));
610
- }
611
- index_1.Helpers.mkdirp(tnp_core_1.path.dirname(destinationDir));
612
- }
613
- if (!options) {
614
- options = {};
615
- }
616
- if (tnp_core_1._.isUndefined(options.overwrite)) {
617
- options.overwrite = true;
618
- }
619
- if (tnp_core_1._.isUndefined(options.recursive)) {
620
- options.recursive = true;
621
- }
622
- if (tnp_core_1._.isUndefined(options.useTempFolder)) {
623
- options.useTempFolder = false;
624
- }
625
- if (options.copySymlinksAsFiles) {
626
- options['dereference'] = true;
627
- }
628
- if (!options.omitFolders) {
629
- options.omitFolders = [];
630
- }
631
- if (options.asSeparatedFilesSymlinkAsFile) {
632
- options.asSeparatedFilesSymlinkAsFile = true;
633
- }
634
- // const [srcStat, destStat] = [
635
- // fse.existsSync(sourceDir) && fse.statSync(sourceDir),
636
- // fse.existsSync(destinationDir) && fse.statSync(destinationDir),
637
- // ];
638
- // if (destStat && destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev) {
639
- // Helpers.warn(`[taon-helper][copy] Same location stats.. Trying to copy same source and destination:
640
- // from: ${sourceDir}
641
- // to: ${destinationDir}
642
- // `);
643
- // return;
644
- // }
645
- if (tnp_core_1._.isArray(options.omitFolders) &&
646
- options.omitFolders.length >= 1 &&
647
- tnp_core_1._.isNil(options.filter) &&
648
- tnp_core_1._.isString(options.omitFoldersBaseFolder) &&
649
- tnp_core_1.path.isAbsolute(options.omitFoldersBaseFolder)) {
650
- options.filter = index_1.Helpers.filterDontCopy(options.omitFolders, options.omitFoldersBaseFolder);
651
- }
652
- if (options.copySymlinksAsFilesDeleteUnexistedLinksFromSourceFirst) {
653
- const files = index_1.Helpers.filesFrom(sourceDir, true, true);
654
- for (let index = 0; index < files.length; index++) {
655
- const file = files[index];
656
- if (index_1.Helpers.isUnexistedLink(file)) {
657
- index_1.Helpers.remove(file, true);
658
- }
659
- }
660
- }
661
- if ((0, tnp_core_1.crossPlatformPath)(sourceDir) === (0, tnp_core_1.crossPlatformPath)(destinationDir) ||
662
- (0, tnp_core_1.crossPlatformPath)(tnp_core_1.path.resolve(sourceDir)) ===
663
- (0, tnp_core_1.crossPlatformPath)(tnp_core_1.path.resolve(destinationDir))) {
664
- index_1.Helpers.warn(`[taon-helper][copy] Trying to copy same source and destination
665
- from: ${sourceDir}
666
- to: ${destinationDir}
667
- `);
668
- }
669
- else {
670
- // Helpers.warn('filter', _.isFunction(options.filter));
671
- // Helpers.warn('sourceDir', sourceDir);
672
- // Helpers.warn('destinationDir', destinationDir);
673
- // Helpers.log(JSON.stringify(options))
674
- // try {
675
- if (options.useTempFolder) {
676
- let tempDestination = `${tnp_core_1.os.platform() === 'darwin' ? '/private/tmp' : '/tmp'}/${tnp_core_1._.camelCase(destinationDir)}`;
677
- index_1.Helpers.removeFolderIfExists(tempDestination);
678
- tnp_core_1.fse.copySync(sourceDir, tempDestination, options);
679
- tnp_core_1.fse.copySync(tempDestination, destinationDir, options);
680
- }
681
- else {
682
- if ((0, tnp_core_1.crossPlatformPath)(sourceDir) ===
683
- (0, tnp_core_1.crossPlatformPath)(tnp_core_1.path.resolve(sourceDir)) &&
684
- index_1.Helpers.isExistedSymlink(sourceDir) &&
685
- !index_1.Helpers.exists(tnp_core_1.fse.readlinkSync(sourceDir))) {
686
- index_1.Helpers.warn(`[taon-helpers] Not copying empty link from: ${sourceDir}
687
- `);
688
- }
689
- else {
690
- const copyFn = () => {
691
- try {
692
- if (options.asSeparatedFiles) {
693
- const copyRecFn = (cwdForFiles) => {
694
- const files = index_1.Helpers.getRecrusiveFilesFrom(cwdForFiles, options.omitFolders);
695
- for (let index = 0; index < files.length; index++) {
696
- const from = files[index];
697
- const to = from.replace(sourceDir, destinationDir);
698
- if (index_1.Helpers.isFolder(from)) {
699
- if (options.omitFolders.includes(tnp_core_1.path.basename(tnp_core_1.path.dirname(from))) ||
700
- options.omitFolders.includes(tnp_core_1.path.basename(from))) {
701
- continue;
702
- }
703
- else {
704
- copyRecFn(from);
705
- }
706
- }
707
- else {
708
- const copyFileFn = () => {
709
- if (!options.asSeparatedFilesSymlinkAsFile &&
710
- index_1.Helpers.isExistedSymlink(from)) {
711
- index_1.Helpers.createSymLink(from, to);
712
- }
713
- else {
714
- index_1.Helpers.copyFile(from, to);
715
- }
716
- };
717
- if (options.asSeparatedFilesAllowNotCopied) {
718
- try {
719
- copyFileFn();
720
- }
721
- catch (e) { }
722
- }
723
- else {
724
- copyFileFn();
725
- }
726
- }
727
- }
728
- };
729
- copyRecFn(sourceDir);
730
- }
731
- else {
732
- tnp_core_1.fse.copySync(sourceDir, destinationDir, options);
733
- }
734
- }
735
- catch (error) {
736
- const exitOnError = global['tnpNonInteractive'];
737
- index_1.Helpers.log(error);
738
- if (!options.dontAskOnError) {
739
- index_1.Helpers.error(`[taon-helper] Not able to copy folder:
740
- from: ${(0, tnp_core_1.crossPlatformPath)(sourceDir)}
741
- to: ${(0, tnp_core_1.crossPlatformPath)(destinationDir)}
742
- options: ${tnp_core_1.json5.stringify(options)}
743
- error: ${error?.message}
744
- `, !exitOnError);
745
- index_1.Helpers.pressKeyAndContinue(`Press any key to repeat copy action...`);
746
- }
747
- copyFn();
748
- }
749
- };
750
- if (process.platform === 'win32') {
751
- while (true) {
752
- try {
753
- copyFn();
754
- break;
755
- }
756
- catch (error) {
757
- index_1.Helpers.warn(`WARNING not able to copy .. trying again`);
758
- index_1.Helpers.sleep(1);
759
- continue;
760
- }
761
- }
762
- }
763
- else {
764
- copyFn();
765
- }
766
- }
767
- }
768
- // } catch (error) {
769
- // console.trace(error);
770
- // process.exit(0)
771
- // }
772
- }
773
- }
774
- filterDontCopy(basePathFoldersTosSkip, projectOrBasepath) {
775
- return (src, dest) => {
776
- // console.log('src', src)
777
- src = (0, tnp_core_1.crossPlatformPath)(src);
778
- const baseFolder = tnp_core_1._.first((0, tnp_core_1.crossPlatformPath)(src)
779
- .replace((0, tnp_core_1.crossPlatformPath)(projectOrBasepath), '')
780
- .replace(/^\//, '')
781
- .split('/'));
782
- // console.log('baseFolder', baseFolder)
783
- if (!baseFolder || baseFolder.trim() === '') {
784
- return true;
785
- }
786
- const isAllowed = tnp_core_1._.isUndefined(basePathFoldersTosSkip.find(f => baseFolder.startsWith((0, tnp_core_1.crossPlatformPath)(f))));
787
- // console.log('isAllowed', isAllowed)
788
- return isAllowed;
789
- };
790
- }
791
- filterOnlyCopy(basePathFoldersOnlyToInclude, projectOrBasepath) {
792
- return (src, dest) => {
793
- src = (0, tnp_core_1.crossPlatformPath)(src);
794
- const baseFolder = tnp_core_1._.first((0, tnp_core_1.crossPlatformPath)(src)
795
- .replace((0, tnp_core_1.crossPlatformPath)(projectOrBasepath), '')
796
- .replace(/^\//, '')
797
- .split('/'));
798
- if (!baseFolder || baseFolder.trim() === '') {
799
- return true;
800
- }
801
- const isAllowed = !tnp_core_1._.isUndefined(basePathFoldersOnlyToInclude.find(f => baseFolder.startsWith((0, tnp_core_1.crossPlatformPath)(f))));
802
- return isAllowed;
803
- };
804
- }
805
- copyFile(sourcePath, destinationPath, options) {
806
- if (tnp_core_1._.isUndefined(options)) {
807
- options = {};
808
- }
809
- if (tnp_core_1._.isUndefined(options.debugMode)) {
810
- options.debugMode = false;
811
- }
812
- if (tnp_core_1._.isUndefined(options.debugMode)) {
813
- options.fast = true;
814
- }
815
- if (tnp_core_1._.isUndefined(options.dontCopySameContent)) {
816
- options.dontCopySameContent = true;
817
- }
818
- const { debugMode, fast, transformTextFn, dontCopySameContent } = options;
819
- if (tnp_core_1._.isFunction(transformTextFn) && fast) {
820
- index_1.Helpers.error(`[taon-helpers][copyFile] You cannot use transformTextFn in fast mode`);
821
- }
822
- if (!tnp_core_1.fse.existsSync(sourcePath)) {
823
- index_1.Helpers.logWarn(`[taon-helpers][copyFile] No able to find source of ${sourcePath}`);
824
- return false;
825
- }
826
- if (tnp_core_1.fse.lstatSync(sourcePath).isDirectory()) {
827
- index_1.Helpers.warn(`[taon-helpers][copyFile] Trying to copy directory as file: ${sourcePath}`, false);
828
- return false;
829
- }
830
- if (sourcePath === destinationPath) {
831
- index_1.Helpers.warn(`[taon-helpers][copyFile] Trying to copy same file ${sourcePath}`);
832
- return false;
833
- }
834
- let destDirPath = tnp_core_1.path.dirname(destinationPath);
835
- if (index_1.Helpers.isFolder(destinationPath)) {
836
- index_1.Helpers.removeFolderIfExists(destinationPath);
837
- }
838
- if (!index_1.Helpers.isSymlinkFileExitedOrUnexisted(destDirPath) &&
839
- !tnp_core_1.fse.existsSync(destDirPath)) {
840
- index_1.Helpers.mkdirp(destDirPath);
841
- }
842
- //#region it is good code
843
- if (index_1.Helpers.isExistedSymlink(destDirPath)) {
844
- destDirPath = tnp_core_1.fse.realpathSync(destDirPath);
845
- const newDestinationPath = (0, tnp_core_1.crossPlatformPath)(tnp_core_1.path.join(destDirPath, tnp_core_1.path.basename(destinationPath)));
846
- if (index_1.Helpers.isFolder(newDestinationPath)) {
847
- index_1.Helpers.removeFolderIfExists(newDestinationPath);
848
- }
849
- destinationPath = newDestinationPath;
850
- }
851
- //#endregion
852
- if (dontCopySameContent && tnp_core_1.fse.existsSync(destinationPath)) {
853
- const destinationContent = index_1.Helpers.readFile(destinationPath);
854
- const sourceContent = index_1.Helpers.readFile(sourcePath).toString();
855
- if (destinationContent === sourceContent) {
856
- // @REMEMBER uncomment if any problem
857
- // Helpers.log(`Destination has the same content as source: ${path.basename(sourcePath)}`);
858
- return false;
859
- }
860
- }
861
- debugMode &&
862
- index_1.Helpers.log(`path.extname(sourcePath) ${tnp_core_1.path.extname(sourcePath)}`);
863
- if (fast || !tnp_config_1.extAllowedToReplace.includes(tnp_core_1.path.extname(sourcePath))) {
864
- tnp_core_1.fse.copyFileSync(sourcePath, destinationPath);
865
- }
866
- else {
867
- let sourceData = index_1.Helpers.readFile(sourcePath).toString();
868
- if (tnp_core_1._.isFunction(transformTextFn)) {
869
- sourceData = transformTextFn(sourceData);
870
- }
871
- debugMode &&
872
- index_1.Helpers.log(`
873
- [taon-helpers][copyFile] Write to: ${destinationPath} file:
874
- ============================================================================================
875
- ${sourceData}
876
- ============================================================================================
877
- `);
878
- index_1.Helpers.writeFile(destinationPath, sourceData);
879
- }
880
- return true;
881
- }
882
- /**
883
- * get real absolute path
884
- */
885
- resolve(fileOrFolderPath) {
886
- if (fileOrFolderPath.startsWith('~')) {
887
- fileOrFolderPath = (0, tnp_core_1.crossPlatformPath)([
888
- tnp_core_1.os.homedir(),
889
- fileOrFolderPath.replace(`~/`, ''),
890
- ]);
891
- }
892
- return (0, tnp_core_1.crossPlatformPath)(tnp_core_1.path.resolve(fileOrFolderPath));
893
- }
894
- }
895
- exports.HelpersFileFolders = HelpersFileFolders;
896
- //# sourceMappingURL=helpers-file-folders.backend.js.map