tnp-helpers 19.0.2 → 19.0.4
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.
- package/assets/shared/shared_folder_info.txt +1 -1
- package/browser/fesm2022/tnp-helpers.mjs +79 -10
- package/browser/fesm2022/tnp-helpers.mjs.map +1 -1
- package/browser/lib/base/classes/base-git.d.ts +12 -1
- package/browser/lib/base/classes/base-package-json.d.ts +1 -0
- package/browser/lib/base/classes/base-release-process.d.ts +1 -0
- package/browser/lib/build-info._auto-generated_.d.ts +1 -1
- package/browser/lib/helpers/for-backend/helpers-file-folders.d.ts +2 -2
- package/browser/package.json +13 -0
- package/client/fesm2022/tnp-helpers.mjs +79 -10
- package/client/fesm2022/tnp-helpers.mjs.map +1 -1
- package/client/lib/base/classes/base-git.d.ts +12 -1
- package/client/lib/base/classes/base-package-json.d.ts +1 -0
- package/client/lib/base/classes/base-release-process.d.ts +1 -0
- package/client/lib/build-info._auto-generated_.d.ts +1 -1
- package/client/lib/helpers/for-backend/helpers-file-folders.d.ts +2 -2
- package/client/package.json +13 -0
- package/lib/base/classes/base-cli-worker-config.d.ts +27 -0
- package/lib/base/classes/base-cli-worker-config.js +64 -0
- package/lib/base/classes/base-cli-worker-config.js.map +1 -0
- package/lib/base/classes/base-cli-worker-controller.d.ts +15 -0
- package/lib/base/classes/base-cli-worker-controller.js +124 -0
- package/lib/base/classes/base-cli-worker-controller.js.map +1 -0
- package/lib/base/classes/base-cli-worker.d.ts +111 -0
- package/lib/base/classes/base-cli-worker.js +535 -0
- package/lib/base/classes/base-cli-worker.js.map +1 -0
- package/lib/base/classes/base-detached-service.d.ts +6 -0
- package/lib/base/classes/base-detached-service.js +16 -0
- package/lib/base/classes/base-detached-service.js.map +1 -0
- package/lib/base/classes/base-git.d.ts +11 -0
- package/lib/base/classes/base-git.js +31 -0
- package/lib/base/classes/base-git.js.map +1 -1
- package/lib/base/classes/base-github-pages.d.ts +14 -0
- package/lib/base/classes/base-github-pages.js +173 -0
- package/lib/base/classes/base-github-pages.js.map +1 -0
- package/lib/base/classes/base-global-command-line.backend.d.ts +1 -0
- package/lib/base/classes/base-global-command-line.backend.js +9 -1
- package/lib/base/classes/base-global-command-line.backend.js.map +1 -1
- package/lib/base/classes/base-node-modules.js +16 -14
- package/lib/base/classes/base-node-modules.js.map +1 -1
- package/lib/base/classes/base-package-json.d.ts +1 -0
- package/lib/base/classes/base-package-json.js +5 -0
- package/lib/base/classes/base-package-json.js.map +1 -1
- package/lib/base/classes/base-powershell.js +4 -0
- package/lib/base/classes/base-powershell.js.map +1 -1
- package/lib/base/classes/base-release-process.d.ts +1 -0
- package/lib/base/classes/base-release-process.js +40 -13
- package/lib/base/classes/base-release-process.js.map +1 -1
- package/lib/base/tcp-udp-ports/not-assignable-port.entity.js +2 -2
- package/lib/base/tcp-udp-ports/tcp-udp-ports.context.d.ts +9 -9
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/helpers/for-backend/helpers-file-folders.backend.d.ts +104 -0
- package/lib/helpers/for-backend/helpers-file-folders.backend.js +896 -0
- package/lib/helpers/for-backend/helpers-file-folders.backend.js.map +1 -0
- package/lib/helpers/for-backend/helpers-file-folders.d.ts +2 -2
- package/lib/helpers/for-backend/helpers-file-folders.js +9 -8
- package/lib/helpers/for-backend/helpers-file-folders.js.map +1 -1
- package/lib/helpers/for-backend/helpers-git.backend.d.ts +10 -0
- package/lib/helpers/for-backend/helpers-git.backend.js +76 -2
- package/lib/helpers/for-backend/helpers-git.backend.js.map +1 -1
- package/lib/helpers/for-backend/helpers-process.backend.d.ts +87 -0
- package/lib/helpers/for-backend/helpers-process.backend.js +456 -0
- package/lib/helpers/for-backend/helpers-process.backend.js.map +1 -0
- package/lib/helpers/for-backend/ts-code/index.d.ts +1 -0
- package/lib/helpers/for-backend/ts-code/index.js +5 -0
- package/lib/helpers/for-backend/ts-code/index.js.map +1 -0
- package/lib/helpers/for-backend/ts-code/ts-import-export-extractor.d.ts +29 -0
- package/lib/helpers/for-backend/ts-code/ts-import-export-extractor.js +81 -0
- package/lib/helpers/for-backend/ts-code/ts-import-export-extractor.js.map +1 -0
- package/lib/helpers/for-browser/angular.helper.js +2 -2
- package/lib/helpers/helpers.js +5 -1
- package/lib/helpers/helpers.js.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/old/base-component.js +2 -2
- package/lib/old/base-formly-component.js +2 -2
- package/lib/old/dual-component-ctrl.js +2 -2
- package/lib/old/execute-command.d.ts +1 -1
- package/lib/old/execute-command.js +2 -2
- package/lib/old/execute-command.js.map +1 -1
- package/package.json +1 -1
- package/tmp-environment.json +4 -3
- package/websql/fesm2022/tnp-helpers.mjs +79 -10
- package/websql/fesm2022/tnp-helpers.mjs.map +1 -1
- package/websql/lib/base/classes/base-git.d.ts +12 -1
- package/websql/lib/base/classes/base-package-json.d.ts +1 -0
- package/websql/lib/base/classes/base-release-process.d.ts +1 -0
- package/websql/lib/build-info._auto-generated_.d.ts +1 -1
- package/websql/lib/helpers/for-backend/helpers-file-folders.d.ts +2 -2
- package/websql/package.json +13 -0
|
@@ -0,0 +1,896 @@
|
|
|
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
|