tnp-core 18.0.46 → 18.0.49
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/README.md +20 -20
- package/assets/shared/shared_folder_info.txt +1 -1
- package/browser/README.md +24 -24
- package/browser/esm2022/lib/core-imports.mjs +65 -9
- package/browser/esm2022/lib/core-models.mjs +61 -9
- package/browser/esm2022/lib/helpers-messages.mjs +9 -4
- package/browser/esm2022/lib/helpers.mjs +164 -373
- package/browser/esm2022/lib/utils.mjs +769 -190
- package/browser/fesm2022/tnp-core.mjs +1548 -1062
- package/browser/fesm2022/tnp-core.mjs.map +1 -1
- package/browser/lib/core-imports.d.ts +41 -1
- package/browser/lib/core-models.d.ts +68 -38
- package/browser/lib/helpers-messages.d.ts +6 -3
- package/browser/lib/helpers.d.ts +22 -0
- package/browser/lib/utils.d.ts +77 -13
- package/cli.backend.d.ts +1 -0
- package/cli.backend.js +15 -2
- package/cli.backend.js.map +1 -1
- package/client/README.md +24 -24
- package/client/esm2022/lib/core-imports.mjs +65 -9
- package/client/esm2022/lib/core-models.mjs +61 -9
- package/client/esm2022/lib/helpers-messages.mjs +9 -4
- package/client/esm2022/lib/helpers.mjs +164 -373
- package/client/esm2022/lib/utils.mjs +769 -190
- package/client/fesm2022/tnp-core.mjs +1548 -1062
- package/client/fesm2022/tnp-core.mjs.map +1 -1
- package/client/lib/core-imports.d.ts +41 -1
- package/client/lib/core-models.d.ts +68 -38
- package/client/lib/helpers-messages.d.ts +6 -3
- package/client/lib/helpers.d.ts +22 -0
- package/client/lib/utils.d.ts +77 -13
- package/index.js +15 -2
- package/index.js.map +1 -1
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/command-exists.js +20 -20
- package/lib/command-exists.js.map +1 -1
- package/lib/core-cli.js +49 -66
- package/lib/core-cli.js.map +1 -1
- package/lib/core-config.js.map +1 -1
- package/lib/core-imports.d.ts +41 -25
- package/lib/core-imports.js +202 -80
- package/lib/core-imports.js.map +1 -1
- package/lib/core-models.d.ts +68 -38
- package/lib/core-models.js +62 -8
- package/lib/core-models.js.map +1 -1
- package/lib/framework-name.js +2 -2
- package/lib/framework-name.js.map +1 -1
- package/lib/helpers-isomorphic.js +33 -52
- package/lib/helpers-isomorphic.js.map +1 -1
- package/lib/helpers-messages.d.ts +6 -3
- package/lib/helpers-messages.js +79 -102
- package/lib/helpers-messages.js.map +1 -1
- package/lib/helpers.d.ts +21 -3
- package/lib/helpers.js +723 -971
- package/lib/helpers.js.map +1 -1
- package/lib/index._auto-generated_.js.map +1 -1
- package/lib/index.js +23 -10
- package/lib/index.js.map +1 -1
- package/lib/node-chalk-mock.js +2 -2
- package/lib/node-chalk-mock.js.map +1 -1
- package/lib/node-path-mock.js +2 -2
- package/lib/node-path-mock.js.map +1 -1
- package/lib/progress-data.js +21 -23
- package/lib/progress-data.js.map +1 -1
- package/lib/public-api.js +19 -6
- package/lib/public-api.js.map +1 -1
- package/lib/required-global-npm-packages.js.map +1 -1
- package/lib/required.d.ts +44 -0
- package/lib/safe-types/glob.d.ts +102 -0
- package/lib/safe-types/minimatch/assert-valid-pattern.d.ts +1 -0
- package/lib/safe-types/minimatch/ast.d.ts +17 -0
- package/lib/safe-types/minimatch/brace-expressions.d.ts +7 -0
- package/lib/safe-types/minimatch/escape.d.ts +11 -0
- package/lib/safe-types/minimatch/index.d copy.d.ts +93 -0
- package/lib/safe-types/minimatch/index.d.ts +93 -0
- package/lib/safe-types/minimatch/unescapd.d.ts +16 -0
- package/lib/safe-types/minimatch/unescape.d.ts +16 -0
- package/lib/safe-types/minimatch.d.ts +0 -0
- package/lib/safe-types/rimraf.d.ts +28 -0
- package/lib/utils.d.ts +89 -14
- package/lib/utils.js +1261 -1075
- package/lib/utils.js.map +1 -1
- package/migrations/index.js +15 -2
- package/migrations/index.js.map +1 -1
- package/migrations/migrations_index._auto-generated_.js.map +1 -1
- package/package.json +25 -91
- package/src.d.ts +1 -1
- package/tmp-environment.json +8 -404
- package/websql/README.md +24 -24
- package/websql/esm2022/lib/core-imports.mjs +65 -9
- package/websql/esm2022/lib/core-models.mjs +61 -9
- package/websql/esm2022/lib/helpers-messages.mjs +9 -4
- package/websql/esm2022/lib/helpers.mjs +164 -373
- package/websql/esm2022/lib/utils.mjs +766 -187
- package/websql/fesm2022/tnp-core.mjs +1546 -1060
- package/websql/fesm2022/tnp-core.mjs.map +1 -1
- package/websql/lib/core-imports.d.ts +41 -1
- package/websql/lib/core-models.d.ts +68 -38
- package/websql/lib/helpers-messages.d.ts +6 -3
- package/websql/lib/helpers.d.ts +22 -0
- package/websql/lib/utils.d.ts +77 -13
- package/browser/package.json +0 -25
- package/taon.jsonc +0 -65
- package/websql/package.json +0 -25
package/lib/helpers.js
CHANGED
@@ -1,181 +1,155 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.HelpersCore = void 0;
|
4
|
-
var tslib_1 = require("tslib");
|
5
4
|
//#region import
|
6
5
|
//#region @backend
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
const core_imports_1 = require("./core-imports");
|
7
|
+
const json5Write = require("json10-writer");
|
8
|
+
const buffer_1 = require("buffer");
|
9
|
+
const electron_1 = require("electron");
|
11
10
|
//#endregion
|
12
11
|
/* */
|
13
12
|
/* */
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
const core_imports_2 = require("./core-imports");
|
14
|
+
const utils_1 = require("./utils");
|
15
|
+
const index_1 = require("./index");
|
16
|
+
const helpers_messages_1 = require("./helpers-messages");
|
17
|
+
const core_models_1 = require("./core-models");
|
18
|
+
const encoding = 'utf8';
|
20
19
|
//#region @backend
|
21
|
-
|
20
|
+
const forceTrace = !global.hideLog;
|
22
21
|
//#endregion
|
23
|
-
|
24
|
-
|
22
|
+
const WEBSQL_PROC_MOCK_PROCESSES_PID = {};
|
23
|
+
const WEBSQL_PROC_MOCK_PROCESSES_PPID = {};
|
25
24
|
//#endregion
|
26
25
|
// TODO UNCOMMENT
|
27
26
|
// const globalProcessStdout = {};
|
28
27
|
// const globalProcessStder = {};
|
29
28
|
// const maxProcessHistoryLinesChekc = 20;
|
30
|
-
|
31
|
-
|
29
|
+
class HelpersCore extends helpers_messages_1.HelpersMessages {
|
30
|
+
//#region singleton
|
31
|
+
static _instanceCore;
|
32
|
+
static get InstanceCore() {
|
33
|
+
if (!HelpersCore._instanceCore) {
|
34
|
+
HelpersCore._instanceCore = new HelpersCore();
|
35
|
+
}
|
36
|
+
return HelpersCore._instanceCore;
|
37
|
+
}
|
38
|
+
//#endregion
|
39
|
+
//#region fields / getters
|
40
|
+
//#region @backend
|
41
|
+
processes = [];
|
42
|
+
//#endregion
|
43
|
+
bigMaxBuffer = 2024 * 500;
|
44
|
+
//#region @backend
|
45
|
+
/**
|
46
|
+
* @deprecated use UtilsOs
|
47
|
+
*/
|
48
|
+
get isRunningIn() {
|
49
|
+
return {
|
50
|
+
/**
|
51
|
+
* @deprecated use UtilsOs.isRunningInMochaTest()
|
52
|
+
*/
|
53
|
+
mochaTest() {
|
54
|
+
return index_1.UtilsOs.isRunningInMochaTest();
|
55
|
+
},
|
56
|
+
/**
|
57
|
+
* @deprecated use UtilsOs.isRunningInCliMode()
|
58
|
+
*/
|
59
|
+
cliMode() {
|
60
|
+
return index_1.UtilsOs.isRunningInCliMode();
|
61
|
+
},
|
62
|
+
};
|
63
|
+
}
|
32
64
|
//#endregion
|
33
65
|
//#endregion
|
34
66
|
//#region constructor
|
35
|
-
|
36
|
-
|
37
|
-
//#endregion
|
38
|
-
//#region fields / getters
|
39
|
-
//#region @backend
|
40
|
-
_this.processes = [];
|
41
|
-
//#endregion
|
42
|
-
_this.bigMaxBuffer = 2024 * 500;
|
43
|
-
return _this;
|
67
|
+
constructor() {
|
68
|
+
super();
|
44
69
|
// //#region @backend
|
45
70
|
// process.on('SIGINT', this.cleanExit); // catch ctrl-c
|
46
71
|
// process.on('SIGTERM', this.cleanExit); // catch kill
|
47
72
|
// //#endregion
|
48
73
|
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
configurable: true
|
58
|
-
});
|
59
|
-
Object.defineProperty(HelpersCore.prototype, "isRunningIn", {
|
60
|
-
//#region @backend
|
61
|
-
/**
|
62
|
-
* @deprecated use UtilsOs
|
63
|
-
*/
|
64
|
-
get: function () {
|
65
|
-
return {
|
66
|
-
/**
|
67
|
-
* @deprecated use UtilsOs.isRunningInMochaTest()
|
68
|
-
*/
|
69
|
-
mochaTest: function () {
|
70
|
-
return index_1.UtilsOs.isRunningInMochaTest();
|
71
|
-
},
|
72
|
-
/**
|
73
|
-
* @deprecated use UtilsOs.isRunningInCliMode()
|
74
|
-
*/
|
75
|
-
cliMode: function () {
|
76
|
-
return index_1.UtilsOs.isRunningInCliMode();
|
77
|
-
},
|
78
|
-
};
|
79
|
-
},
|
80
|
-
enumerable: false,
|
81
|
-
configurable: true
|
82
|
-
});
|
83
|
-
Object.defineProperty(HelpersCore.prototype, "isWsl", {
|
84
|
-
//#endregion
|
85
|
-
//#region methods / is wsl
|
86
|
-
/**
|
87
|
-
* @deprecated use UtilsOs.isRunningInsideWsl()
|
88
|
-
*/
|
89
|
-
get: function () {
|
90
|
-
return index_1.UtilsOs.isRunningInWsl();
|
91
|
-
},
|
92
|
-
enumerable: false,
|
93
|
-
configurable: true
|
94
|
-
});
|
74
|
+
//#endregion
|
75
|
+
//#region methods / is wsl
|
76
|
+
/**
|
77
|
+
* @deprecated use UtilsOs.isRunningInsideWsl()
|
78
|
+
*/
|
79
|
+
get isWsl() {
|
80
|
+
return index_1.UtilsOs.isRunningInWsl();
|
81
|
+
}
|
95
82
|
//#endregion
|
96
83
|
//#region methods / is running in docker
|
97
84
|
/**
|
98
85
|
* @deprecated use UtilsOs.isRunningInDocker
|
99
86
|
*/
|
100
|
-
|
87
|
+
isRunningInDocker() {
|
101
88
|
return index_1.UtilsOs.isRunningInDocker();
|
102
|
-
}
|
89
|
+
}
|
103
90
|
//#endregion
|
104
91
|
//#region methods / is running in docker
|
105
92
|
/**
|
106
93
|
* @deprecated use UtilsOs.isRunningInLinuxGraphicEnvironment
|
107
94
|
*/
|
108
|
-
|
95
|
+
isRunningInLinuxGraphicsCapableEnvironment() {
|
109
96
|
return index_1.UtilsOs.isRunningInLinuxGraphicsCapableEnvironment();
|
110
|
-
}
|
97
|
+
}
|
111
98
|
//#endregion
|
112
99
|
//#region clear console
|
113
100
|
/**
|
114
101
|
* @deprecated use UtilsTerminal.clearConsole
|
115
102
|
*/
|
116
|
-
|
103
|
+
clearConsole() {
|
117
104
|
return utils_1.UtilsTerminal.clearConsole();
|
118
|
-
}
|
119
|
-
|
105
|
+
}
|
106
|
+
//#endregion
|
107
|
+
//#region methods / electron ipc renderer
|
108
|
+
/**
|
109
|
+
* get electron browser ipc renderer
|
110
|
+
*/
|
111
|
+
get ipcRenderer() {
|
112
|
+
//#region @backend
|
113
|
+
return;
|
120
114
|
//#endregion
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
enumerable: false,
|
137
|
-
configurable: true
|
138
|
-
});
|
139
|
-
Object.defineProperty(HelpersCore.prototype, "webFrame", {
|
115
|
+
/* */
|
116
|
+
/* */
|
117
|
+
/* */
|
118
|
+
/* */
|
119
|
+
/* */
|
120
|
+
/* */
|
121
|
+
}
|
122
|
+
//#endregion
|
123
|
+
//#region methods / electron webframe
|
124
|
+
/**
|
125
|
+
* get electron web frame
|
126
|
+
*/
|
127
|
+
get webFrame() {
|
128
|
+
//#region @backend
|
129
|
+
return;
|
140
130
|
//#endregion
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
131
|
+
/* */
|
132
|
+
/* */
|
133
|
+
/* */
|
134
|
+
/* */
|
135
|
+
/* */
|
136
|
+
}
|
137
|
+
//#endregion
|
138
|
+
//#region methods / electron ipc renderer
|
139
|
+
/**
|
140
|
+
* get electron backend ipc main proces
|
141
|
+
*/
|
142
|
+
get ipcMain() {
|
143
|
+
//#region @backendFunc
|
144
|
+
if (!this.isElectron) {
|
147
145
|
return;
|
148
|
-
|
149
|
-
|
150
|
-
/* */
|
151
|
-
/* */
|
152
|
-
/* */
|
153
|
-
/* */
|
154
|
-
},
|
155
|
-
enumerable: false,
|
156
|
-
configurable: true
|
157
|
-
});
|
158
|
-
Object.defineProperty(HelpersCore.prototype, "ipcMain", {
|
146
|
+
}
|
147
|
+
return electron_1.ipcMain;
|
159
148
|
//#endregion
|
160
|
-
|
161
|
-
/**
|
162
|
-
* get electron backend ipc main proces
|
163
|
-
*/
|
164
|
-
get: function () {
|
165
|
-
//#region @backendFunc
|
166
|
-
if (!this.isElectron) {
|
167
|
-
return;
|
168
|
-
}
|
169
|
-
return electron_1.ipcMain;
|
170
|
-
//#endregion
|
171
|
-
},
|
172
|
-
enumerable: false,
|
173
|
-
configurable: true
|
174
|
-
});
|
149
|
+
}
|
175
150
|
//#endregion
|
176
151
|
//#region methods / get electron window
|
177
|
-
|
178
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.allowRunningInsecureContent, allowRunningInsecureContent = _c === void 0 ? true : _c;
|
152
|
+
getElectronWindow({ allowRunningInsecureContent = true, } = {}) {
|
179
153
|
//#region @backendFunc
|
180
154
|
// const size = screen.getPrimaryDisplay().workAreaSize;
|
181
155
|
// // Create the browser window.
|
@@ -192,25 +166,24 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
192
166
|
// });
|
193
167
|
// return win
|
194
168
|
//#endregion
|
195
|
-
}
|
169
|
+
}
|
196
170
|
//#endregion
|
197
171
|
//#region methods / media from type
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
return core_imports_2._.first(media
|
202
|
-
}
|
172
|
+
mediaTypeFromSrc(src) {
|
173
|
+
const ext = core_imports_2.path.extname(src);
|
174
|
+
const media = core_models_1.CoreModels.mimeTypes[ext];
|
175
|
+
return core_imports_2._.first(media?.split('/'));
|
176
|
+
}
|
203
177
|
//#endregion
|
204
178
|
//#region methods / sleep
|
205
|
-
|
206
|
-
if (seconds === void 0) { seconds = 1; }
|
179
|
+
sleep(seconds = 1) {
|
207
180
|
//#region @backendFunc
|
208
|
-
return index_1.Helpers.run(
|
181
|
+
return index_1.Helpers.run(`sleep ${seconds}`).sync();
|
209
182
|
//#endregion
|
210
|
-
}
|
183
|
+
}
|
211
184
|
//#endregion
|
212
185
|
//#region methods / remove if exists
|
213
|
-
|
186
|
+
removeIfExists(absoluteFileOrFolderPath) {
|
214
187
|
//#region @backendFunc
|
215
188
|
if (Array.isArray(absoluteFileOrFolderPath)) {
|
216
189
|
absoluteFileOrFolderPath = (0, core_imports_2.crossPlatformPath)(absoluteFileOrFolderPath);
|
@@ -232,18 +205,18 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
232
205
|
}
|
233
206
|
}
|
234
207
|
//#endregion
|
235
|
-
}
|
208
|
+
}
|
236
209
|
//#endregion
|
237
210
|
//#region methods / relative
|
238
211
|
/**
|
239
212
|
* path.relative that return cross platform path
|
240
213
|
*/
|
241
|
-
|
214
|
+
relative(cwd, to) {
|
242
215
|
return (0, core_imports_2.crossPlatformPath)(core_imports_2.path.relative(cwd, to));
|
243
|
-
}
|
216
|
+
}
|
244
217
|
//#endregion
|
245
218
|
//#region methods / remove file if exists
|
246
|
-
|
219
|
+
removeFileIfExists(absoluteFilePath) {
|
247
220
|
//#region @backendFunc
|
248
221
|
if (Array.isArray(absoluteFilePath)) {
|
249
222
|
absoluteFilePath = (0, core_imports_2.crossPlatformPath)(absoluteFilePath);
|
@@ -257,15 +230,15 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
257
230
|
core_imports_1.fse.unlinkSync(absoluteFilePath);
|
258
231
|
}
|
259
232
|
//#endregion
|
260
|
-
}
|
233
|
+
}
|
261
234
|
//#endregion
|
262
235
|
//#region methods / remove folder if exists
|
263
|
-
|
236
|
+
removeFolderIfExists(absoluteFolderPath) {
|
264
237
|
//#region @backendFunc
|
265
238
|
if (Array.isArray(absoluteFolderPath)) {
|
266
239
|
absoluteFolderPath = (0, core_imports_2.crossPlatformPath)(absoluteFolderPath);
|
267
240
|
}
|
268
|
-
index_1.Helpers.log(
|
241
|
+
index_1.Helpers.log(`[helpers] Remove folder: ${absoluteFolderPath}`);
|
269
242
|
if (process.platform === 'win32') {
|
270
243
|
// rimraf.sync(absoluteFolderPath);
|
271
244
|
this.tryRemoveDir(absoluteFolderPath, false, true);
|
@@ -275,17 +248,17 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
275
248
|
core_imports_1.fse.removeSync(absoluteFolderPath);
|
276
249
|
}
|
277
250
|
//#endregion
|
278
|
-
}
|
251
|
+
}
|
279
252
|
//#endregion
|
280
253
|
//#region methods / remove empty line from string
|
281
254
|
/**
|
282
255
|
* leave max 1 empty line
|
283
256
|
*/
|
284
|
-
|
285
|
-
|
286
|
-
|
257
|
+
removeEmptyLineFromString(str) {
|
258
|
+
const lines = (str || '').split('\n');
|
259
|
+
let previousWasEmpty = false;
|
287
260
|
return lines
|
288
|
-
.filter(
|
261
|
+
.filter(line => {
|
289
262
|
if (line.trim() === '') {
|
290
263
|
if (previousWasEmpty) {
|
291
264
|
// Skip this line because the previous line was also empty
|
@@ -304,116 +277,116 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
304
277
|
}
|
305
278
|
})
|
306
279
|
.join('\n');
|
307
|
-
}
|
280
|
+
}
|
308
281
|
//#endregion
|
309
282
|
//#region methods / try remove empty dir
|
310
283
|
/**
|
311
284
|
* @deprecated
|
312
285
|
*/
|
313
|
-
|
314
|
-
if (contentOnly === void 0) { contentOnly = false; }
|
315
|
-
if (omitWarningNotExisted === void 0) { omitWarningNotExisted = false; }
|
286
|
+
tryRemoveDir(dirpath, contentOnly = false, omitWarningNotExisted = false) {
|
316
287
|
//#region @backendFunc
|
317
288
|
if (!core_imports_1.fse.existsSync(dirpath)) {
|
318
289
|
if (!omitWarningNotExisted) {
|
319
|
-
index_1.Helpers.warn(
|
290
|
+
index_1.Helpers.warn(`[taon-helper][tryRemoveDir] Folder ${core_imports_2.path.basename(dirpath)} doesn't exist.`);
|
320
291
|
}
|
321
292
|
return;
|
322
293
|
}
|
323
|
-
index_1.Helpers.log(
|
294
|
+
index_1.Helpers.log(`[taon-helpers][tryRemoveDir]: ${dirpath}`);
|
324
295
|
try {
|
325
296
|
if (contentOnly) {
|
326
|
-
core_imports_1.rimraf.sync(
|
297
|
+
core_imports_1.rimraf.sync(`${dirpath}/*`);
|
327
298
|
}
|
328
299
|
else {
|
329
300
|
core_imports_1.rimraf.sync(dirpath);
|
330
301
|
}
|
331
|
-
index_1.Helpers.log(
|
302
|
+
index_1.Helpers.log(`Remove done: ${dirpath}`);
|
332
303
|
return;
|
333
304
|
}
|
334
305
|
catch (e) {
|
335
|
-
index_1.Helpers.warn(
|
306
|
+
index_1.Helpers.warn(`
|
307
|
+
|
308
|
+
Trying to remove directory: ${dirpath}
|
309
|
+
|
310
|
+
|
311
|
+
(USER ACTION REQUIRED!!!)
|
312
|
+
Please check if you did't open
|
313
|
+
${dirpath}
|
314
|
+
in windows explorer
|
315
|
+
|
316
|
+
or try to unlock file with app Unlocker or File Locksmith (from power tools)
|
317
|
+
|
318
|
+
`);
|
336
319
|
index_1.Helpers.sleep(1);
|
337
320
|
index_1.Helpers.tryRemoveDir(dirpath, contentOnly);
|
338
321
|
}
|
339
322
|
//#endregion
|
340
|
-
}
|
323
|
+
}
|
341
324
|
//#endregion
|
342
325
|
//#region methods / remove file or folder
|
343
|
-
|
344
|
-
if (exactFolder === void 0) { exactFolder = false; }
|
326
|
+
remove(fileOrFolderPathOrPatter, exactFolder = false) {
|
345
327
|
//#region @backendFunc
|
346
328
|
if (Array.isArray(fileOrFolderPathOrPatter)) {
|
347
329
|
fileOrFolderPathOrPatter = (0, core_imports_2.crossPlatformPath)(fileOrFolderPathOrPatter);
|
348
330
|
}
|
349
|
-
index_1.Helpers.log(
|
331
|
+
index_1.Helpers.log(`[taon-core][remove]: ${fileOrFolderPathOrPatter}`, 1);
|
350
332
|
if (exactFolder) {
|
351
333
|
core_imports_1.rimraf.sync(fileOrFolderPathOrPatter, { glob: false, disableGlob: true });
|
352
334
|
return;
|
353
335
|
}
|
354
336
|
core_imports_1.rimraf.sync(fileOrFolderPathOrPatter);
|
355
337
|
//#endregion
|
356
|
-
}
|
338
|
+
}
|
357
339
|
//#endregion
|
358
340
|
//#region methods / clean exit process
|
359
341
|
//#region @backend
|
360
|
-
|
361
|
-
index_1.Helpers.processes.forEach(
|
342
|
+
cleanExit() {
|
343
|
+
index_1.Helpers.processes.forEach(p => {
|
362
344
|
p.kill('SIGINT');
|
363
345
|
p.kill('SIGTERM');
|
364
|
-
index_1.Helpers.log(
|
346
|
+
index_1.Helpers.log(`Killing child process on ${p.pid}`);
|
365
347
|
});
|
366
|
-
index_1.Helpers.log(
|
348
|
+
index_1.Helpers.log(`Killing parent on ${process.pid}`);
|
367
349
|
process.exit();
|
368
|
-
}
|
369
|
-
|
370
|
-
|
350
|
+
}
|
351
|
+
//#endregion
|
352
|
+
//#endregion
|
353
|
+
//#region methods / is running in git bash
|
354
|
+
get isRunningInGitBash() {
|
355
|
+
//#region @backendFunc
|
356
|
+
// console.log('TERM', process.env.TERM);
|
357
|
+
// console.log('MSYSTEM', process.env.MSYSTEM);
|
358
|
+
return ((process.env?.TERM?.search('cygwin') !== -1 ||
|
359
|
+
process.env?.TERM?.search('xterm') !== -1) &&
|
360
|
+
!!process.env?.MSYSTEM);
|
371
361
|
//#endregion
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
//#endregion
|
382
|
-
},
|
383
|
-
enumerable: false,
|
384
|
-
configurable: true
|
385
|
-
});
|
386
|
-
Object.defineProperty(HelpersCore.prototype, "isSupportedTaonTerminal", {
|
362
|
+
}
|
363
|
+
//#endregion
|
364
|
+
//#region methods / check if projects is running in supported terminal
|
365
|
+
/**
|
366
|
+
* Check if the current shell is supported by Taon framework.
|
367
|
+
*/
|
368
|
+
get isSupportedTaonTerminal() {
|
369
|
+
//#region @backendFunc
|
370
|
+
return process.platform === 'win32' ? this.isRunningInGitBash : true;
|
387
371
|
//#endregion
|
388
|
-
|
389
|
-
/**
|
390
|
-
* Check if the current shell is supported by Taon framework.
|
391
|
-
*/
|
392
|
-
get: function () {
|
393
|
-
//#region @backendFunc
|
394
|
-
return process.platform === 'win32' ? this.isRunningInGitBash : true;
|
395
|
-
//#endregion
|
396
|
-
},
|
397
|
-
enumerable: false,
|
398
|
-
configurable: true
|
399
|
-
});
|
372
|
+
}
|
400
373
|
//#endregion
|
401
374
|
//#region methods / check if function is class
|
402
375
|
/**
|
403
376
|
* check if function is class
|
404
377
|
*/
|
405
|
-
|
406
|
-
|
378
|
+
isClass(funcOrClass) {
|
379
|
+
let isClass = false;
|
407
380
|
if (typeof funcOrClass === 'function') {
|
408
381
|
// Check if it has a prototype property
|
409
382
|
// console.log('Object.getOwnPropertyNames(funcOrClass.prototype)', Object.getOwnPropertyNames(funcOrClass.prototype).filter(f => f !== 'constructor'))
|
410
383
|
isClass =
|
411
384
|
!!funcOrClass.prototype &&
|
412
|
-
Object.getOwnPropertyNames(funcOrClass.prototype).filter(
|
385
|
+
Object.getOwnPropertyNames(funcOrClass.prototype).filter(f => f !== 'constructor').length > 0;
|
413
386
|
}
|
414
387
|
// console.log('is class: ' + isClass, funcOrClass)
|
415
388
|
return isClass;
|
416
|
-
}
|
389
|
+
}
|
417
390
|
//#endregion
|
418
391
|
//#region methods / is blob
|
419
392
|
/**
|
@@ -422,10 +395,10 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
422
395
|
* @param maybeBlob
|
423
396
|
* @returns
|
424
397
|
*/
|
425
|
-
|
398
|
+
isBlob(maybeBlob) {
|
426
399
|
// TODO is this needed hmmmm
|
427
400
|
return maybeBlob instanceof buffer_1.Blob; // || toString.call(maybeBlob) === '[object Blob]';
|
428
|
-
}
|
401
|
+
}
|
429
402
|
//#endregion
|
430
403
|
//#region methods / is buffer
|
431
404
|
/**
|
@@ -435,28 +408,28 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
435
408
|
* @returns
|
436
409
|
*/
|
437
410
|
//#region @backend
|
438
|
-
|
411
|
+
isBuffer(maybeNodejsBuffer) {
|
439
412
|
return Buffer.isBuffer(maybeNodejsBuffer);
|
440
|
-
}
|
413
|
+
}
|
441
414
|
//#endregion
|
442
415
|
//#endregion
|
443
416
|
//#region methods / remove slash at the end of string
|
444
|
-
|
445
|
-
s =
|
417
|
+
removeSlashAtEnd(s) {
|
418
|
+
s = s?.endsWith(`/`) ? s.slice(0, s.length - 1) : s;
|
446
419
|
return s;
|
447
|
-
}
|
420
|
+
}
|
448
421
|
//#endregion
|
449
422
|
//#region methods / remove slash at the begin of string
|
450
|
-
|
451
|
-
s =
|
423
|
+
removeSlashAtBegin(s) {
|
424
|
+
s = s?.startsWith(`/`) ? s.slice(1) : s;
|
452
425
|
return s;
|
453
|
-
}
|
426
|
+
}
|
454
427
|
//#endregion
|
455
428
|
//#region methods / stringify object pretty format
|
456
429
|
/**
|
457
430
|
* stringify to pretty json string
|
458
431
|
*/
|
459
|
-
|
432
|
+
stringify(inputObject) {
|
460
433
|
// if (_.isString(inputObject)) {
|
461
434
|
// return inputObject;
|
462
435
|
// }
|
@@ -465,36 +438,38 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
465
438
|
// Helpers.error(`[tnp-helpers] trying to stringify not a object`, false, true);
|
466
439
|
// }
|
467
440
|
return JSON.stringify(inputObject, null, 2);
|
468
|
-
}
|
441
|
+
}
|
469
442
|
//#endregion
|
470
443
|
//#region methods / run sync or async
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
}
|
493
|
-
|
444
|
+
async runSyncOrAsync(fnOrOptions) {
|
445
|
+
if (core_imports_2._.isUndefined(fnOrOptions)) {
|
446
|
+
return void 0;
|
447
|
+
}
|
448
|
+
let promisOrValue;
|
449
|
+
// const optionsMode = _.isObject(fnOrOptions)
|
450
|
+
// && !_.isArray(fnOrOptions)
|
451
|
+
// && !_.isFunction(fnOrOptions)
|
452
|
+
// && !_.isNil(fnOrOptions)
|
453
|
+
// ;
|
454
|
+
// if (optionsMode) {
|
455
|
+
const { functionFn, context, arrayOfParams } = fnOrOptions;
|
456
|
+
promisOrValue = functionFn.apply(context, arrayOfParams);
|
457
|
+
// } else {
|
458
|
+
// // @ts-ignore
|
459
|
+
// promisOrValue = _.isArray(fnOrOptions) ? fnOrOptions[1][fnOrOptions[0]](...firstArg) : fnOrOptions(...firstArg);
|
460
|
+
// }
|
461
|
+
// let wasPromise = false;
|
462
|
+
if (promisOrValue instanceof Promise) {
|
463
|
+
// wasPromise = true;
|
464
|
+
promisOrValue = Promise.resolve(promisOrValue);
|
465
|
+
}
|
466
|
+
// console.log('was promis ', wasPromise)
|
467
|
+
return promisOrValue;
|
468
|
+
}
|
494
469
|
//#endregion
|
495
470
|
//#region methods / create symlink
|
496
471
|
//#region @backend
|
497
|
-
|
472
|
+
createSymLink(existedFileOrFolder, destinationPath, options) {
|
498
473
|
//#region fix parameters
|
499
474
|
existedFileOrFolder = (0, core_imports_2.crossPlatformPath)(existedFileOrFolder);
|
500
475
|
destinationPath = (0, core_imports_2.crossPlatformPath)(destinationPath);
|
@@ -502,7 +477,8 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
502
477
|
// from: ${existedFileOrFolder},
|
503
478
|
// to: ${destinationPath},
|
504
479
|
// `)
|
505
|
-
index_1.Helpers.log(
|
480
|
+
index_1.Helpers.log(`[tnp-code][create link] exited -> dest
|
481
|
+
${existedFileOrFolder} ${destinationPath}`, 1);
|
506
482
|
options = options ? options : {};
|
507
483
|
if (core_imports_2._.isUndefined(options.continueWhenExistedFolderDoesntExists)) {
|
508
484
|
options.continueWhenExistedFolderDoesntExists = false;
|
@@ -519,17 +495,34 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
519
495
|
if (core_imports_2._.isUndefined(options.allowNotAbsolutePathes)) {
|
520
496
|
options.allowNotAbsolutePathes = false;
|
521
497
|
}
|
498
|
+
if (options.dontRenameWhenSlashAtEnd) {
|
499
|
+
destinationPath = index_1.Helpers.removeSlashAtEnd(destinationPath);
|
500
|
+
}
|
501
|
+
if (options.tryRemoveDesPath) {
|
502
|
+
try {
|
503
|
+
core_imports_1.fse.unlinkSync(destinationPath);
|
504
|
+
}
|
505
|
+
catch (error) {
|
506
|
+
try {
|
507
|
+
core_imports_1.fse.removeSync(destinationPath);
|
508
|
+
}
|
509
|
+
catch (error) { }
|
510
|
+
}
|
511
|
+
}
|
522
512
|
//#endregion
|
523
|
-
|
513
|
+
const { continueWhenExistedFolderDoesntExists, windowsHardLink, speedUpProcess, } = options;
|
524
514
|
// console.log('Create link!')
|
525
|
-
|
526
|
-
|
515
|
+
let targetExisted = existedFileOrFolder;
|
516
|
+
let linkDest = destinationPath;
|
527
517
|
if (!core_imports_1.fse.existsSync(existedFileOrFolder)) {
|
528
518
|
if (continueWhenExistedFolderDoesntExists) {
|
529
519
|
// just continue and create link to not existed folder
|
530
520
|
}
|
531
521
|
else {
|
532
|
-
index_1.Helpers.error(
|
522
|
+
index_1.Helpers.error(`[helpers.createLink] target path doesn't exist: ${existedFileOrFolder}
|
523
|
+
use option "continueWhenExistedFolderDoesntExists" to fix this if you know that
|
524
|
+
file will be eventually in place
|
525
|
+
`);
|
533
526
|
}
|
534
527
|
}
|
535
528
|
/**
|
@@ -551,16 +544,22 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
551
544
|
}
|
552
545
|
else {
|
553
546
|
if (!core_imports_2.path.isAbsolute(linkDest)) {
|
554
|
-
index_1.Helpers.error(
|
547
|
+
index_1.Helpers.error(`[createsymlink] path is not absolute:
|
548
|
+
targetExisted: ${targetExisted}
|
549
|
+
linkDest: ${linkDest}
|
550
|
+
`);
|
555
551
|
}
|
556
552
|
if (!core_imports_2.path.isAbsolute(targetExisted)) {
|
557
|
-
index_1.Helpers.error(
|
553
|
+
index_1.Helpers.error(`[createsymlink] path is not absolute:
|
554
|
+
targetExisted: ${targetExisted}
|
555
|
+
linkDest: ${linkDest}
|
556
|
+
`);
|
558
557
|
}
|
559
558
|
}
|
560
559
|
if (linkDest.endsWith('/')) {
|
561
560
|
linkDest = (0, core_imports_2.crossPlatformPath)(core_imports_2.path.join(linkDest, core_imports_2.path.basename(targetExisted)));
|
562
561
|
}
|
563
|
-
|
562
|
+
const parentFolderLinkDest = core_imports_2.path.dirname(linkDest);
|
564
563
|
if (index_1.Helpers.isSymlinkFileExitedOrUnexisted(parentFolderLinkDest)) {
|
565
564
|
core_imports_1.fse.unlinkSync(parentFolderLinkDest);
|
566
565
|
}
|
@@ -577,12 +576,20 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
577
576
|
// console.log(`resolved target from ${targetExisted} = ${resolvedTarget}, isFile: ${targetIsFile}`)
|
578
577
|
if (index_1.Helpers.isSymlinkFileExitedOrUnexisted(targetExisted)) {
|
579
578
|
// Helpers.info(`FIXING TARGET FOR WINDOWS`)
|
580
|
-
|
579
|
+
try {
|
580
|
+
targetExisted = (0, core_imports_2.crossPlatformPath)(core_imports_1.fse.realpathSync(targetExisted));
|
581
|
+
}
|
582
|
+
catch (error) {
|
583
|
+
index_1.Helpers.warn(`[tnp-helpers] Error while resolving target for windows link
|
584
|
+
target: "${targetExisted}"
|
585
|
+
link: "${linkDest}"
|
586
|
+
`, true);
|
587
|
+
}
|
581
588
|
// TODO QUICK_FIX on windows you can't create link to link
|
582
589
|
}
|
583
590
|
// targetExisted = path.win32.normalize(targetExisted).replace(/\\$/, '');
|
584
591
|
// linkDest = path.win32.normalize(linkDest).replace(/\\$/, '');
|
585
|
-
|
592
|
+
const targetIsFile = index_1.Helpers.isFile(targetExisted);
|
586
593
|
// const destIsLink = Helpers.isExistedSymlink(linkDest) || Helpers.isUnexistedLink(linkDest)
|
587
594
|
// console.log({
|
588
595
|
// targetExisted,
|
@@ -598,8 +605,8 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
598
605
|
}
|
599
606
|
else {
|
600
607
|
if (targetIsFile) {
|
601
|
-
|
602
|
-
|
608
|
+
const winLinkCommand = `mklink ${windowsHardLink ? '/D' : targetIsFile ? '/H' : '/j'} "${linkDest}" "${targetExisted}"`;
|
609
|
+
const showSymlinkOutputOnWindows = forceTrace;
|
603
610
|
index_1.Helpers.run(winLinkCommand, {
|
604
611
|
biggerBuffer: false,
|
605
612
|
output: showSymlinkOutputOnWindows,
|
@@ -638,33 +645,33 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
638
645
|
else {
|
639
646
|
core_imports_1.fse.symlinkSync(targetExisted, linkDest);
|
640
647
|
}
|
641
|
-
}
|
648
|
+
}
|
642
649
|
//#endregion
|
643
650
|
//#endregion
|
644
651
|
//#region methods / mkdirp
|
645
652
|
//#region @backend
|
646
|
-
|
653
|
+
createFolder(folderPath) {
|
647
654
|
return index_1.Helpers.mkdirp(folderPath);
|
648
|
-
}
|
649
|
-
|
655
|
+
}
|
656
|
+
mkdirp(folderPath) {
|
650
657
|
if (core_imports_2._.isArray(folderPath)) {
|
651
658
|
folderPath = (0, core_imports_2.crossPlatformPath)(folderPath);
|
652
659
|
}
|
653
660
|
if (!core_imports_2.path.isAbsolute(folderPath)) {
|
654
|
-
index_1.Helpers.warn(
|
661
|
+
index_1.Helpers.warn(`[taon-core][mkdirp] Path is not absolute, abort ${folderPath}`, true);
|
655
662
|
return;
|
656
663
|
}
|
657
664
|
if (core_imports_2._.isString(folderPath) &&
|
658
665
|
folderPath.startsWith('/tmp ') &&
|
659
666
|
core_imports_1.os.platform() === 'darwin') {
|
660
|
-
index_1.Helpers.warn(
|
661
|
-
folderPath = folderPath.replace(
|
667
|
+
index_1.Helpers.warn(`[taon-core][mkdirp] On mac osx /tmp is changed to /private/tmp`, false);
|
668
|
+
folderPath = folderPath.replace(`/tmp/`, '/private/tmp/');
|
662
669
|
}
|
663
670
|
if (index_1.Helpers.isUnexistedLink(folderPath)) {
|
664
671
|
index_1.Helpers.remove(folderPath);
|
665
672
|
}
|
666
673
|
if (core_imports_1.fse.existsSync(folderPath)) {
|
667
|
-
index_1.Helpers.log(
|
674
|
+
index_1.Helpers.log(`[taon-core][mkdirp] folder path already exists: ${folderPath}`);
|
668
675
|
}
|
669
676
|
else {
|
670
677
|
// if (Helpers.isSymlinkFileExitedOrUnexisted(path.dirname(folderPath))) {
|
@@ -673,10 +680,10 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
673
680
|
// Helpers.removeFileIfExists(path.dirname(folderPath));
|
674
681
|
// } catch (error) {}
|
675
682
|
// }
|
676
|
-
index_1.Helpers.log(
|
683
|
+
index_1.Helpers.log(`[taon-core][mkdirp] ${folderPath}`, 1);
|
677
684
|
core_imports_1.fse.mkdirpSync(folderPath);
|
678
685
|
}
|
679
|
-
}
|
686
|
+
}
|
680
687
|
//#endregion
|
681
688
|
//#endregion
|
682
689
|
//#region methods / is symlink that matches url
|
@@ -684,13 +691,12 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
684
691
|
* symlink may have existed or unexisted destiantion url
|
685
692
|
* @param destUrl M
|
686
693
|
*/
|
687
|
-
|
688
|
-
if (absoluteFileMatch === void 0) { absoluteFileMatch = false; }
|
694
|
+
isSymlinkThatMatchesUrl(possibleSymlink, destUrl, absoluteFileMatch = false) {
|
689
695
|
//#region @backendFunc
|
690
696
|
destUrl = (0, core_imports_2.crossPlatformPath)(destUrl);
|
691
697
|
if (index_1.Helpers.exists(possibleSymlink)) {
|
692
698
|
if (index_1.Helpers.isExistedSymlink(possibleSymlink)) {
|
693
|
-
|
699
|
+
let fileLink = core_imports_1.fse.readlinkSync(possibleSymlink);
|
694
700
|
if (absoluteFileMatch) {
|
695
701
|
fileLink = core_imports_1.fse.realpathSync(fileLink);
|
696
702
|
}
|
@@ -702,11 +708,11 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
702
708
|
}
|
703
709
|
}
|
704
710
|
try {
|
705
|
-
|
711
|
+
const linkToUnexitedLink = core_imports_1.fse
|
706
712
|
.lstatSync(possibleSymlink)
|
707
713
|
.isSymbolicLink();
|
708
714
|
if (linkToUnexitedLink) {
|
709
|
-
|
715
|
+
let fileLink = core_imports_1.fse.readlinkSync(possibleSymlink);
|
710
716
|
if (absoluteFileMatch) {
|
711
717
|
fileLink = core_imports_1.fse.realpathSync(fileLink);
|
712
718
|
}
|
@@ -719,29 +725,29 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
719
725
|
return false;
|
720
726
|
}
|
721
727
|
//#endregion
|
722
|
-
}
|
728
|
+
}
|
723
729
|
//#endregion
|
724
730
|
//#region methods / is symlink file existed or unexisted
|
725
|
-
|
731
|
+
isSymlinkFileExitedOrUnexisted(filePath) {
|
726
732
|
//#region @backendFunc
|
727
733
|
if (core_imports_2._.isArray(filePath)) {
|
728
|
-
filePath = (0, core_imports_2.crossPlatformPath)(core_imports_2.path.join
|
734
|
+
filePath = (0, core_imports_2.crossPlatformPath)(core_imports_2.path.join(...filePath));
|
729
735
|
}
|
730
736
|
try {
|
731
|
-
|
737
|
+
const linkToUnexitedLink = core_imports_1.fse.lstatSync(filePath).isSymbolicLink();
|
732
738
|
return linkToUnexitedLink;
|
733
739
|
}
|
734
740
|
catch (error) {
|
735
741
|
return false;
|
736
742
|
}
|
737
743
|
//#endregion
|
738
|
-
}
|
744
|
+
}
|
739
745
|
//#endregion
|
740
746
|
//#region methods / is unexisted link
|
741
747
|
/**
|
742
748
|
* If symbolnk link that target file does not exits
|
743
749
|
*/
|
744
|
-
|
750
|
+
isUnexistedLink(filePath) {
|
745
751
|
//#region @backendFunc
|
746
752
|
if (core_imports_2._.isArray(filePath)) {
|
747
753
|
filePath = (0, core_imports_2.crossPlatformPath)(filePath);
|
@@ -751,7 +757,7 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
751
757
|
filePath = core_imports_2.path.win32.normalize(filePath);
|
752
758
|
}
|
753
759
|
try {
|
754
|
-
|
760
|
+
const linkToUnexitedLink = core_imports_1.fse
|
755
761
|
.lstatSync(filePath)
|
756
762
|
.isSymbolicLink();
|
757
763
|
return (linkToUnexitedLink &&
|
@@ -761,13 +767,13 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
761
767
|
return false;
|
762
768
|
}
|
763
769
|
//#endregion
|
764
|
-
}
|
770
|
+
}
|
765
771
|
//#endregion
|
766
772
|
//#region methods / is exited symlink
|
767
773
|
/**
|
768
774
|
* @param existedLink check if source of link exists
|
769
775
|
*/
|
770
|
-
|
776
|
+
isExistedSymlink(filePath) {
|
771
777
|
//#region @backendFunc
|
772
778
|
if (core_imports_2._.isArray(filePath)) {
|
773
779
|
filePath = (0, core_imports_2.crossPlatformPath)(filePath);
|
@@ -777,7 +783,7 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
777
783
|
filePath = core_imports_2.path.win32.normalize(filePath);
|
778
784
|
}
|
779
785
|
try {
|
780
|
-
|
786
|
+
const linkToUnexitedLink = core_imports_1.fse
|
781
787
|
.lstatSync(filePath)
|
782
788
|
.isSymbolicLink();
|
783
789
|
return (linkToUnexitedLink &&
|
@@ -787,12 +793,12 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
787
793
|
return false;
|
788
794
|
}
|
789
795
|
//#endregion
|
790
|
-
}
|
796
|
+
}
|
791
797
|
//#endregion
|
792
798
|
//#region methods / path contain link
|
793
799
|
//#region @backend
|
794
|
-
|
795
|
-
|
800
|
+
pathContainLink(p) {
|
801
|
+
let previous;
|
796
802
|
while (true) {
|
797
803
|
p = (0, core_imports_2.crossPlatformPath)(core_imports_2.path.dirname(p));
|
798
804
|
// @ts-ignore
|
@@ -807,180 +813,163 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
807
813
|
}
|
808
814
|
previous = p;
|
809
815
|
}
|
810
|
-
}
|
816
|
+
}
|
811
817
|
//#endregion
|
812
818
|
//#endregion
|
813
819
|
//#region methods / exists
|
814
|
-
|
820
|
+
exists(folderOrFilePath) {
|
815
821
|
//#region @backendFunc
|
816
822
|
if (core_imports_2._.isArray(folderOrFilePath)) {
|
817
823
|
folderOrFilePath = (0, core_imports_2.crossPlatformPath)(folderOrFilePath);
|
818
824
|
}
|
819
825
|
if (!folderOrFilePath) {
|
820
|
-
index_1.Helpers.warn(
|
826
|
+
index_1.Helpers.warn(`[taon-core][exists] Path is not a string, abort.. "${folderOrFilePath}"`, true);
|
821
827
|
return false;
|
822
828
|
}
|
823
829
|
if (!core_imports_2.path.isAbsolute(folderOrFilePath)) {
|
824
|
-
index_1.Helpers.warn(
|
830
|
+
index_1.Helpers.warn(`[taon-core]
|
831
|
+
File path is not absolute:
|
832
|
+
${folderOrFilePath}
|
833
|
+
|
834
|
+
`, true);
|
825
835
|
return false;
|
826
836
|
}
|
827
837
|
return core_imports_1.fse.existsSync(folderOrFilePath);
|
828
838
|
//#endregion
|
829
|
-
}
|
839
|
+
}
|
830
840
|
//#endregion
|
831
841
|
//#region methods / fix command
|
832
842
|
/**
|
833
843
|
* this is HACK for running procesess inside processes
|
834
844
|
*/
|
835
|
-
|
845
|
+
_fixCommand(command) {
|
836
846
|
if ((command.startsWith('tnp ') || command.startsWith('taon ')) && // TODO every cli projects here that uses run and need to kill process easly!
|
837
847
|
command.search('-spinner=false') === -1 &&
|
838
848
|
command.search('-spinner=off') === -1) {
|
839
|
-
command =
|
849
|
+
command = `${command} -spinner=false`;
|
840
850
|
}
|
841
851
|
if (global.skipCoreCheck &&
|
842
852
|
(command.startsWith('tnp ') || command.startsWith('taon '))) {
|
843
|
-
command =
|
853
|
+
command = `${command} --skipCoreCheck`;
|
844
854
|
}
|
845
855
|
return command;
|
846
|
-
}
|
856
|
+
}
|
847
857
|
//#endregion
|
848
858
|
//#region methods / command
|
849
|
-
|
859
|
+
command(command) {
|
850
860
|
// console.log({ command })
|
851
861
|
command = index_1.Helpers._fixCommand(command);
|
852
862
|
return {
|
853
863
|
//#region @backend
|
854
|
-
getherOutput
|
864
|
+
getherOutput(options) {
|
855
865
|
if (!options) {
|
856
866
|
options = {};
|
857
867
|
}
|
858
|
-
return new Promise(
|
868
|
+
return new Promise(resolve => {
|
859
869
|
// @ts-ignore
|
860
|
-
|
870
|
+
let { ommitStder, cwd, biggerBuffer, gatherColors } = options;
|
861
871
|
if (!cwd) {
|
862
872
|
cwd = process.cwd();
|
863
873
|
}
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
cwd
|
868
|
-
maxBuffer
|
874
|
+
const maxBuffer = biggerBuffer ? index_1.Helpers.bigMaxBuffer : void 0;
|
875
|
+
const env = gatherColors ? { ...process.env, FORCE_COLOR: '1' } : {};
|
876
|
+
const proc = core_imports_1.child_process.exec(command, {
|
877
|
+
cwd, // @ts-ignore
|
878
|
+
maxBuffer,
|
869
879
|
env: env,
|
870
880
|
});
|
871
|
-
|
872
|
-
proc.on('exit',
|
881
|
+
let gatheredData = '';
|
882
|
+
proc.on('exit', code => {
|
873
883
|
resolve(gatheredData);
|
874
884
|
});
|
875
885
|
// @ts-ignore
|
876
|
-
proc.stdout.on('data',
|
877
|
-
gatheredData =
|
886
|
+
proc.stdout.on('data', data => {
|
887
|
+
gatheredData = `${gatheredData}${data?.toString() || ''}`;
|
878
888
|
});
|
879
889
|
// @ts-ignore
|
880
|
-
proc.stdout.on('error',
|
881
|
-
gatheredData =
|
890
|
+
proc.stdout.on('error', data => {
|
891
|
+
gatheredData = `${gatheredData}${data?.toString() || ''}`;
|
882
892
|
});
|
883
893
|
if (!ommitStder) {
|
884
894
|
// @ts-ignore
|
885
|
-
proc.stderr.on('data',
|
886
|
-
gatheredData =
|
895
|
+
proc.stderr.on('data', data => {
|
896
|
+
gatheredData = `${gatheredData}${data?.toString() || ''}`;
|
887
897
|
});
|
888
898
|
// @ts-ignore
|
889
|
-
proc.stderr.on('error',
|
890
|
-
gatheredData =
|
899
|
+
proc.stderr.on('error', data => {
|
900
|
+
gatheredData = `${gatheredData}${data?.toString() || ''}`;
|
891
901
|
});
|
892
902
|
}
|
893
903
|
});
|
894
904
|
},
|
895
905
|
//#endregion
|
896
906
|
};
|
897
|
-
}
|
907
|
+
}
|
898
908
|
//#endregion
|
899
909
|
//#region methods / wait
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
return tslib_1.__generator(this, function (_a) {
|
910
|
-
switch (_a.label) {
|
911
|
-
case 0: return [4 /*yield*/, index_1.Helpers.wait(seconds)];
|
912
|
-
case 1: return [2 /*return*/, _a.sent()];
|
913
|
-
}
|
914
|
-
});
|
915
|
-
});
|
916
|
-
};
|
910
|
+
/**
|
911
|
+
* @deprecated use UtilsTerminal.wait
|
912
|
+
*/
|
913
|
+
async wait(second) {
|
914
|
+
await utils_1.UtilsTerminal.wait(second);
|
915
|
+
}
|
916
|
+
async timeout(seconds) {
|
917
|
+
return await index_1.Helpers.wait(seconds);
|
918
|
+
}
|
917
919
|
//#endregion
|
918
920
|
//#region methods / command output as string async
|
919
921
|
//#region @backend
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
_a.label = 1;
|
931
|
-
case 1:
|
932
|
-
_a.trys.push([1, 3, , 4]);
|
933
|
-
return [4 /*yield*/, index_1.Helpers.command(command).getherOutput({
|
934
|
-
cwd: cwd, // @ts-ignore
|
935
|
-
biggerBuffer: opt.biggerBuffer, // @ts-ignore
|
936
|
-
ommitStder: !opt.showStder, // @ts-ignore
|
937
|
-
gatherColors: opt.gatherColors,
|
938
|
-
})];
|
939
|
-
case 2:
|
940
|
-
output = _a.sent();
|
941
|
-
// console.log({
|
942
|
-
// output
|
943
|
-
// })
|
944
|
-
// @ts-ignore
|
945
|
-
if (!opt.showOnlyLastLine) {
|
946
|
-
return [2 /*return*/, output.replace(/[^\x00-\xFF]/g, '')];
|
947
|
-
}
|
948
|
-
splited = (output || '').split('\n');
|
949
|
-
output = (splited.pop() || '').replace(/[^\x00-\xFF]/g, '');
|
950
|
-
return [3 /*break*/, 4];
|
951
|
-
case 3:
|
952
|
-
e_1 = _a.sent();
|
953
|
-
// @ts-ignore
|
954
|
-
if (opt.showErrorWarning) {
|
955
|
-
index_1.Helpers.warn("[taon-helepr] Not able to get output from command:\n \"".concat(command, "\"\n "));
|
956
|
-
}
|
957
|
-
return [3 /*break*/, 4];
|
958
|
-
case 4: return [2 /*return*/, output];
|
959
|
-
}
|
922
|
+
async commnadOutputAsStringAsync(command, cwd = (0, core_imports_2.crossPlatformPath)(process.cwd()), options) {
|
923
|
+
command = index_1.Helpers._fixCommand(command);
|
924
|
+
const opt = (options || {});
|
925
|
+
let output = '';
|
926
|
+
try {
|
927
|
+
output = await index_1.Helpers.command(command).getherOutput({
|
928
|
+
cwd, // @ts-ignore
|
929
|
+
biggerBuffer: opt.biggerBuffer, // @ts-ignore
|
930
|
+
ommitStder: !opt.showStder, // @ts-ignore
|
931
|
+
gatherColors: opt.gatherColors,
|
960
932
|
});
|
961
|
-
|
962
|
-
|
933
|
+
// console.log({
|
934
|
+
// output
|
935
|
+
// })
|
936
|
+
// @ts-ignore
|
937
|
+
if (!opt.showOnlyLastLine) {
|
938
|
+
return output.replace(/[^\x00-\xFF]/g, '');
|
939
|
+
}
|
940
|
+
const splited = (output || '').split('\n');
|
941
|
+
output = (splited.pop() || '').replace(/[^\x00-\xFF]/g, '');
|
942
|
+
}
|
943
|
+
catch (e) {
|
944
|
+
// @ts-ignore
|
945
|
+
if (opt.showErrorWarning) {
|
946
|
+
index_1.Helpers.warn(`[taon-helepr] Not able to get output from command:
|
947
|
+
"${command}"
|
948
|
+
`);
|
949
|
+
}
|
950
|
+
}
|
951
|
+
return output;
|
952
|
+
}
|
963
953
|
//#endregion
|
964
954
|
//#endregion
|
965
955
|
//#region methods / command output as string
|
966
956
|
//#region @backend
|
967
|
-
|
968
|
-
var _a;
|
969
|
-
if (cwd === void 0) { cwd = (0, core_imports_2.crossPlatformPath)(process.cwd()); }
|
957
|
+
commnadOutputAsString(command, cwd = (0, core_imports_2.crossPlatformPath)(process.cwd()), options) {
|
970
958
|
command = index_1.Helpers._fixCommand(command);
|
971
|
-
|
972
|
-
|
959
|
+
const opt = (options || {});
|
960
|
+
let output = '';
|
973
961
|
try {
|
974
962
|
// @ts-ignore
|
975
|
-
|
963
|
+
const env = opt.gatherColors ? { ...process.env, FORCE_COLOR: '1' } : {};
|
976
964
|
// output = Helpers.run(command, { output: false, cwd, biggerBuffer }).sync().toString().trim()
|
977
|
-
output = (
|
965
|
+
output = (core_imports_1.child_process
|
978
966
|
.execSync(command, {
|
979
|
-
cwd
|
967
|
+
cwd, // @ts-ignore
|
980
968
|
stdio: ['ignore', 'pipe', opt.showStder ? 'pipe' : 'ignore'], // @ts-ignore
|
981
969
|
maxBuffer: opt.biggerBuffer ? index_1.Helpers.bigMaxBuffer : void 0,
|
982
970
|
env: env,
|
983
|
-
})
|
971
|
+
})
|
972
|
+
?.toString() || '').trim();
|
984
973
|
// console.log({
|
985
974
|
// output
|
986
975
|
// })
|
@@ -988,86 +977,78 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
988
977
|
if (!opt.showOnlyLastLine) {
|
989
978
|
return output.replace(/[^\x00-\xFF]/g, '');
|
990
979
|
}
|
991
|
-
|
980
|
+
const splited = (output || '').split('\n');
|
992
981
|
output = (splited.pop() || '').replace(/[^\x00-\xFF]/g, '');
|
993
982
|
}
|
994
983
|
catch (e) {
|
995
984
|
// @ts-ignore
|
996
985
|
if (opt.showErrorWarning) {
|
997
|
-
index_1.Helpers.warn(
|
986
|
+
index_1.Helpers.warn(`[taon-helpers] Not able to get output from command:
|
987
|
+
"${command}"
|
988
|
+
cwd: ${cwd}
|
989
|
+
`);
|
998
990
|
}
|
999
991
|
}
|
1000
992
|
return output;
|
1001
|
-
}
|
993
|
+
}
|
1002
994
|
//#endregion
|
1003
995
|
//#endregion
|
1004
996
|
//#region methods / kill process by port
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
}
|
1048
|
-
});
|
1049
|
-
});
|
1050
|
-
};
|
997
|
+
async killProcessByPort(portOrPortsToKill, options) {
|
998
|
+
//#region @backendFunc
|
999
|
+
const showOutoput = !options || !options.silent;
|
1000
|
+
if (!core_imports_2._.isArray(portOrPortsToKill)) {
|
1001
|
+
portOrPortsToKill = [portOrPortsToKill];
|
1002
|
+
}
|
1003
|
+
for (let index = 0; index < portOrPortsToKill.length; index++) {
|
1004
|
+
let port = portOrPortsToKill[index];
|
1005
|
+
index_1.Helpers.info(`[taon-helpers] Killing process on port: ${port}`);
|
1006
|
+
const org = port;
|
1007
|
+
port = Number(port);
|
1008
|
+
if (!core_imports_2._.isNumber(port)) {
|
1009
|
+
showOutoput &&
|
1010
|
+
index_1.Helpers.warn(`[taon-helpers] Can't kill on port: "${org}"`);
|
1011
|
+
return;
|
1012
|
+
}
|
1013
|
+
try {
|
1014
|
+
await (0, core_imports_1.fkill)(`:${port}`, { force: true });
|
1015
|
+
// run(`fkill -f :${port} &> /dev/null`, { output: false }).sync()
|
1016
|
+
showOutoput &&
|
1017
|
+
index_1.Helpers.info(`[taon-helpers] Processs killed successfully on port: ${port}`);
|
1018
|
+
}
|
1019
|
+
catch (e) {
|
1020
|
+
showOutoput &&
|
1021
|
+
index_1.Helpers.warn(`[taon-helpers] No process to kill on port: ${port}... `, false);
|
1022
|
+
}
|
1023
|
+
// console.log(`Killing process on port ${port} in progress`);
|
1024
|
+
// try {
|
1025
|
+
// if (os.platform() === 'linux') {
|
1026
|
+
// run(`lsof -i:${port}`, { output: false }).sync()
|
1027
|
+
// } else if (os.platform() === 'darwin') {
|
1028
|
+
// run(`lsof -P | grep ':${port}' | awk '{print $2}' | xargs kill -9 `, { output: false }).sync()
|
1029
|
+
// }
|
1030
|
+
// info(`Process killed on port: ${port}`)
|
1031
|
+
// } catch (e) {
|
1032
|
+
// error(`Problem with killing process on port ${port}:
|
1033
|
+
// ${e}
|
1034
|
+
// `, true)
|
1035
|
+
// }
|
1036
|
+
}
|
1037
|
+
//#endregion
|
1038
|
+
}
|
1051
1039
|
//#endregion
|
1052
1040
|
//#region methods / kill on port
|
1053
|
-
|
1054
|
-
return
|
1055
|
-
|
1056
|
-
switch (_a.label) {
|
1057
|
-
case 0: return [4 /*yield*/, index_1.Helpers.killProcessByPort(portOrPortsToKill, options)];
|
1058
|
-
case 1: return [2 /*return*/, _a.sent()];
|
1059
|
-
}
|
1060
|
-
});
|
1061
|
-
});
|
1062
|
-
};
|
1041
|
+
async killOnPort(portOrPortsToKill, options) {
|
1042
|
+
return await index_1.Helpers.killProcessByPort(portOrPortsToKill, options);
|
1043
|
+
}
|
1063
1044
|
//#endregion
|
1064
1045
|
//#region methods / kill process
|
1065
|
-
|
1046
|
+
killProcess(byPid) {
|
1066
1047
|
//#region @backend
|
1067
1048
|
// Helpers.run(`kill -9 ${byPid}`).sync()
|
1068
1049
|
//#endregion
|
1069
1050
|
//#region @backend
|
1070
|
-
index_1.Helpers.run(
|
1051
|
+
index_1.Helpers.run(`fkill --force ${byPid}`).sync();
|
1071
1052
|
// return;
|
1072
1053
|
//#endregion
|
1073
1054
|
/* */
|
@@ -1092,10 +1073,10 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1092
1073
|
/* */
|
1093
1074
|
/* */
|
1094
1075
|
/* */
|
1095
|
-
}
|
1076
|
+
}
|
1096
1077
|
//#endregion
|
1097
1078
|
//#region methods / run
|
1098
|
-
|
1079
|
+
run(command, options) {
|
1099
1080
|
command = index_1.Helpers._fixCommand(command);
|
1100
1081
|
// console.log({ command })
|
1101
1082
|
//#region @backend
|
@@ -1108,26 +1089,31 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1108
1089
|
if (options.cwd === void 0)
|
1109
1090
|
options.cwd = (0, core_imports_2.crossPlatformPath)(process.cwd());
|
1110
1091
|
if (!core_imports_2._.isString(command)) {
|
1111
|
-
index_1.Helpers.error(
|
1092
|
+
index_1.Helpers.error(`[taon-helpers] command is not a string`);
|
1112
1093
|
}
|
1113
1094
|
//#endregion
|
1114
1095
|
return {
|
1115
1096
|
/**
|
1116
1097
|
* start command as synchronous nodej proces
|
1117
1098
|
*/
|
1118
|
-
sync
|
1099
|
+
sync() {
|
1119
1100
|
// TODO buffer
|
1120
1101
|
//#region @backendFunc
|
1121
1102
|
// @ts-ignore
|
1122
1103
|
if (core_imports_2._.isArray(options.extractFromLine)) {
|
1123
|
-
index_1.Helpers.error(
|
1104
|
+
index_1.Helpers.error(`[tnp-helper] extractFromLine only for:
|
1105
|
+
- asyncAsPromise
|
1106
|
+
- async
|
1107
|
+
- unitlOutputContains
|
1108
|
+
|
1109
|
+
`, false, true);
|
1124
1110
|
}
|
1125
1111
|
// @ts-ignore
|
1126
1112
|
if (core_imports_2._.isNumber(options.tryAgainWhenFailAfter) &&
|
1127
1113
|
options.tryAgainWhenFailAfter > 0) {
|
1128
1114
|
// TODO try again when fail
|
1129
1115
|
// try {
|
1130
|
-
|
1116
|
+
const proc = index_1.Helpers.runSyncIn(command, options);
|
1131
1117
|
return proc;
|
1132
1118
|
// } catch (error) {
|
1133
1119
|
// TODO: WAIT FUNCTION HERE
|
@@ -1141,7 +1127,7 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1141
1127
|
* start command as asynchronous nodej proces
|
1142
1128
|
* @param detach (default: false) - if true process will be detached
|
1143
1129
|
*/
|
1144
|
-
async
|
1130
|
+
async(detach = false) {
|
1145
1131
|
//#region websqlFunc
|
1146
1132
|
//#region mock of process
|
1147
1133
|
/* */
|
@@ -1242,7 +1228,6 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1242
1228
|
/* */
|
1243
1229
|
/* */
|
1244
1230
|
/* */
|
1245
|
-
if (detach === void 0) { detach = false; }
|
1246
1231
|
//#endregion
|
1247
1232
|
//#region @backendFunc
|
1248
1233
|
// @ts-ignore
|
@@ -1254,18 +1239,18 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1254
1239
|
/**
|
1255
1240
|
* start command as asynchronous nodej proces inside promise
|
1256
1241
|
*/
|
1257
|
-
asyncAsPromise
|
1242
|
+
asyncAsPromise() {
|
1258
1243
|
//#region @backendFunc
|
1259
|
-
|
1260
|
-
return new Promise(
|
1261
|
-
|
1262
|
-
proc.on('exit',
|
1244
|
+
let isResolved = false;
|
1245
|
+
return new Promise((resolve, reject) => {
|
1246
|
+
const proc = index_1.Helpers.runAsyncIn(command, options);
|
1247
|
+
proc.on('exit', () => {
|
1263
1248
|
if (!isResolved) {
|
1264
1249
|
isResolved = true;
|
1265
1250
|
resolve(void 0);
|
1266
1251
|
}
|
1267
1252
|
});
|
1268
|
-
proc.on('error',
|
1253
|
+
proc.on('error', () => {
|
1269
1254
|
if (!isResolved) {
|
1270
1255
|
isResolved = true;
|
1271
1256
|
reject();
|
@@ -1274,12 +1259,12 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1274
1259
|
});
|
1275
1260
|
//#endregion
|
1276
1261
|
},
|
1277
|
-
unitlOutput
|
1262
|
+
unitlOutput(optionsOutput) {
|
1278
1263
|
//#region @backendFunc
|
1279
1264
|
optionsOutput = optionsOutput || {};
|
1280
|
-
|
1281
|
-
|
1282
|
-
return new Promise(
|
1265
|
+
let { stdoutMsg, stderMsg, timeout, stdoutOutputContainsCallback } = optionsOutput;
|
1266
|
+
let isResolved = false;
|
1267
|
+
return new Promise((resolve, reject) => {
|
1283
1268
|
if (core_imports_2._.isString(stdoutMsg)) {
|
1284
1269
|
stdoutMsg = [stdoutMsg];
|
1285
1270
|
}
|
@@ -1287,23 +1272,23 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1287
1272
|
stderMsg = [stderMsg];
|
1288
1273
|
}
|
1289
1274
|
if (!core_imports_2._.isArray(stdoutMsg)) {
|
1290
|
-
reject(
|
1275
|
+
reject(`[unitlOutputContains] Message not a array`);
|
1291
1276
|
}
|
1292
|
-
|
1293
|
-
proc.on('exit',
|
1294
|
-
console.info(
|
1277
|
+
const proc = index_1.Helpers.runAsyncIn(command, options);
|
1278
|
+
proc.on('exit', () => {
|
1279
|
+
console.info(`EXIT OF PROCESS`);
|
1295
1280
|
});
|
1296
1281
|
//#region stderr
|
1297
1282
|
// @ts-ignore
|
1298
|
-
proc.stderr.on('data',
|
1299
|
-
|
1283
|
+
proc.stderr.on('data', message => {
|
1284
|
+
const data = message.toString().trim();
|
1300
1285
|
if (!isResolved && core_imports_2._.isArray(stderMsg)) {
|
1301
|
-
for (
|
1302
|
-
|
1286
|
+
for (let index = 0; index < stderMsg.length; index++) {
|
1287
|
+
const rejectm = stderMsg[index];
|
1303
1288
|
if (data.search(rejectm) !== -1) {
|
1304
|
-
console.info(
|
1289
|
+
console.info(`[unitlOutputContains] Rejected move to next step...`);
|
1305
1290
|
isResolved = true;
|
1306
|
-
setTimeout(
|
1291
|
+
setTimeout(() => {
|
1307
1292
|
reject();
|
1308
1293
|
proc.kill('SIGINT');
|
1309
1294
|
}, timeout);
|
@@ -1315,13 +1300,13 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1315
1300
|
//#endregion
|
1316
1301
|
//#region stdout
|
1317
1302
|
// @ts-ignore
|
1318
|
-
proc.stdout.on('data',
|
1319
|
-
|
1303
|
+
proc.stdout.on('data', message => {
|
1304
|
+
const data = message.toString().trim();
|
1320
1305
|
if (isResolved) {
|
1321
|
-
for (
|
1322
|
-
|
1306
|
+
for (let index = 0; index < stdoutMsg.length; index++) {
|
1307
|
+
const m = stdoutMsg[index];
|
1323
1308
|
if (data.search(m) !== -1) {
|
1324
|
-
console.info(
|
1309
|
+
console.info(`[unitlOutputContains][is resolved] Move to next step...`);
|
1325
1310
|
stdoutOutputContainsCallback &&
|
1326
1311
|
stdoutOutputContainsCallback();
|
1327
1312
|
break;
|
@@ -1329,14 +1314,14 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1329
1314
|
}
|
1330
1315
|
}
|
1331
1316
|
else {
|
1332
|
-
for (
|
1333
|
-
|
1317
|
+
for (let index = 0; index < stdoutMsg.length; index++) {
|
1318
|
+
const m = stdoutMsg[index];
|
1334
1319
|
if (data.search(m) !== -1) {
|
1335
|
-
console.info(
|
1320
|
+
console.info(`[unitlOutputContains] Move to next step...`);
|
1336
1321
|
stdoutOutputContainsCallback &&
|
1337
1322
|
stdoutOutputContainsCallback();
|
1338
1323
|
isResolved = true;
|
1339
|
-
setTimeout(
|
1324
|
+
setTimeout(() => {
|
1340
1325
|
resolve(void 0);
|
1341
1326
|
}, timeout);
|
1342
1327
|
break;
|
@@ -1344,12 +1329,12 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1344
1329
|
}
|
1345
1330
|
}
|
1346
1331
|
if (!isResolved && core_imports_2._.isArray(stderMsg)) {
|
1347
|
-
for (
|
1348
|
-
|
1332
|
+
for (let index = 0; index < stderMsg.length; index++) {
|
1333
|
+
const rejectm = stderMsg[index];
|
1349
1334
|
if (data.search(rejectm) !== -1) {
|
1350
|
-
console.info(
|
1335
|
+
console.info(`[unitlOutputContains] Rejected move to next step...`);
|
1351
1336
|
isResolved = true;
|
1352
|
-
setTimeout(
|
1337
|
+
setTimeout(() => {
|
1353
1338
|
reject();
|
1354
1339
|
proc.kill('SIGINT');
|
1355
1340
|
}, timeout);
|
@@ -1367,11 +1352,10 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1367
1352
|
* start command as asynchronous nodej proces inside promise
|
1368
1353
|
* and wait until output contains some string
|
1369
1354
|
*/
|
1370
|
-
unitlOutputContains
|
1371
|
-
if (timeout === void 0) { timeout = 0; }
|
1355
|
+
unitlOutputContains(stdoutMsg, stderMsg, timeout = 0, stdoutOutputContainsCallback) {
|
1372
1356
|
//#region @backendFunc
|
1373
|
-
|
1374
|
-
return new Promise(
|
1357
|
+
let isResolved = false;
|
1358
|
+
return new Promise((resolve, reject) => {
|
1375
1359
|
if (core_imports_2._.isString(stdoutMsg)) {
|
1376
1360
|
stdoutMsg = [stdoutMsg];
|
1377
1361
|
}
|
@@ -1379,19 +1363,19 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1379
1363
|
stderMsg = [stderMsg];
|
1380
1364
|
}
|
1381
1365
|
if (!core_imports_2._.isArray(stdoutMsg)) {
|
1382
|
-
reject(
|
1366
|
+
reject(`[unitlOutputContains] Message not a array`);
|
1383
1367
|
}
|
1384
|
-
|
1368
|
+
const proc = index_1.Helpers.runAsyncIn(command, options);
|
1385
1369
|
// @ts-ignore
|
1386
|
-
proc.stderr.on('data',
|
1387
|
-
|
1370
|
+
proc.stderr.on('data', message => {
|
1371
|
+
const data = message.toString().trim();
|
1388
1372
|
if (!isResolved && core_imports_2._.isArray(stderMsg)) {
|
1389
|
-
for (
|
1390
|
-
|
1373
|
+
for (let index = 0; index < stderMsg.length; index++) {
|
1374
|
+
const rejectm = stderMsg[index];
|
1391
1375
|
if (data.search(rejectm) !== -1) {
|
1392
|
-
index_1.Helpers.info(
|
1376
|
+
index_1.Helpers.info(`[unitlOutputContains] Rejected move to next step...`);
|
1393
1377
|
isResolved = true;
|
1394
|
-
setTimeout(
|
1378
|
+
setTimeout(() => {
|
1395
1379
|
reject();
|
1396
1380
|
proc.kill('SIGINT');
|
1397
1381
|
}, timeout);
|
@@ -1401,11 +1385,11 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1401
1385
|
}
|
1402
1386
|
});
|
1403
1387
|
// @ts-ignore
|
1404
|
-
proc.stdout.on('data',
|
1405
|
-
|
1388
|
+
proc.stdout.on('data', message => {
|
1389
|
+
const data = message.toString().trim();
|
1406
1390
|
if (isResolved) {
|
1407
|
-
for (
|
1408
|
-
|
1391
|
+
for (let index = 0; index < stdoutMsg.length; index++) {
|
1392
|
+
const m = stdoutMsg[index];
|
1409
1393
|
if (data.search(m) !== -1) {
|
1410
1394
|
stdoutOutputContainsCallback &&
|
1411
1395
|
stdoutOutputContainsCallback();
|
@@ -1414,14 +1398,14 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1414
1398
|
}
|
1415
1399
|
}
|
1416
1400
|
else {
|
1417
|
-
for (
|
1418
|
-
|
1401
|
+
for (let index = 0; index < stdoutMsg.length; index++) {
|
1402
|
+
const m = stdoutMsg[index];
|
1419
1403
|
if (data.search(m) !== -1) {
|
1420
|
-
index_1.Helpers.info(
|
1404
|
+
index_1.Helpers.info(`[unitlOutputContains] Move to next step...`);
|
1421
1405
|
stdoutOutputContainsCallback &&
|
1422
1406
|
stdoutOutputContainsCallback();
|
1423
1407
|
isResolved = true;
|
1424
|
-
setTimeout(
|
1408
|
+
setTimeout(() => {
|
1425
1409
|
resolve(void 0);
|
1426
1410
|
}, timeout);
|
1427
1411
|
break;
|
@@ -1429,12 +1413,12 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1429
1413
|
}
|
1430
1414
|
}
|
1431
1415
|
if (!isResolved && core_imports_2._.isArray(stderMsg)) {
|
1432
|
-
for (
|
1433
|
-
|
1416
|
+
for (let index = 0; index < stderMsg.length; index++) {
|
1417
|
+
const rejectm = stderMsg[index];
|
1434
1418
|
if (data.search(rejectm) !== -1) {
|
1435
|
-
index_1.Helpers.info(
|
1419
|
+
index_1.Helpers.info(`[unitlOutputContains] Rejected move to next step...`);
|
1436
1420
|
isResolved = true;
|
1437
|
-
setTimeout(
|
1421
|
+
setTimeout(() => {
|
1438
1422
|
reject();
|
1439
1423
|
proc.kill('SIGINT');
|
1440
1424
|
}, timeout);
|
@@ -1447,45 +1431,36 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1447
1431
|
//#endregion
|
1448
1432
|
},
|
1449
1433
|
};
|
1450
|
-
}
|
1434
|
+
}
|
1451
1435
|
//#endregion
|
1452
1436
|
//#region methods / question yest no
|
1453
1437
|
/**
|
1454
1438
|
* @deprecated use UtilsTerminal.confirm
|
1455
1439
|
*/
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
callbackTrue: callbackTrue,
|
1464
|
-
callbackFalse: callbackFalse,
|
1465
|
-
defaultValue: defaultValue,
|
1466
|
-
})
|
1467
|
-
//#endregion
|
1468
|
-
];
|
1469
|
-
case 1:
|
1470
|
-
//#region @backendFunc
|
1471
|
-
return [2 /*return*/, _a.sent()
|
1472
|
-
//#endregion
|
1473
|
-
];
|
1474
|
-
}
|
1475
|
-
});
|
1440
|
+
async questionYesNo(message, callbackTrue, callbackFalse, defaultValue = true) {
|
1441
|
+
//#region @backendFunc
|
1442
|
+
return await utils_1.UtilsTerminal.confirm({
|
1443
|
+
message,
|
1444
|
+
callbackTrue,
|
1445
|
+
callbackFalse,
|
1446
|
+
defaultValue,
|
1476
1447
|
});
|
1477
|
-
|
1448
|
+
//#endregion
|
1449
|
+
}
|
1478
1450
|
//#endregion
|
1479
1451
|
//#region methods / get stdio
|
1480
1452
|
//#region @backend
|
1481
|
-
|
1482
|
-
|
1453
|
+
getStdio(options) {
|
1454
|
+
const {
|
1483
1455
|
// @ts-ignore
|
1484
|
-
output
|
1456
|
+
output, silence, stdio,
|
1457
|
+
// pipeToParentProcerss = false,
|
1458
|
+
// inheritFromParentProcerss = false
|
1459
|
+
} = options;
|
1485
1460
|
if (typeof stdio !== 'undefined') {
|
1486
1461
|
return stdio;
|
1487
1462
|
}
|
1488
|
-
|
1463
|
+
let resstdio = output
|
1489
1464
|
? [0, 1, 2]
|
1490
1465
|
: core_imports_2._.isBoolean(silence) && silence
|
1491
1466
|
? 'ignore'
|
@@ -1497,37 +1472,37 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1497
1472
|
// stdio = ['inherit', 'inherit', 'inherit'] as any;
|
1498
1473
|
// }
|
1499
1474
|
return resstdio;
|
1500
|
-
}
|
1475
|
+
}
|
1501
1476
|
//#endregion
|
1502
1477
|
//#endregion
|
1503
1478
|
//#region methods / run sync in
|
1504
1479
|
//#region @backend
|
1505
|
-
|
1480
|
+
runSyncIn(command, options) {
|
1506
1481
|
// @ts-ignore
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1482
|
+
const { cwd, biggerBuffer } = options;
|
1483
|
+
const maxBuffer = biggerBuffer ? index_1.Helpers.bigMaxBuffer : undefined;
|
1484
|
+
let stdio = index_1.Helpers.getStdio(options);
|
1510
1485
|
index_1.Helpers.checkProcess(cwd, command);
|
1511
|
-
return core_imports_1.child_process.execSync(command, { stdio
|
1512
|
-
}
|
1486
|
+
return core_imports_1.child_process.execSync(command, { stdio, cwd, maxBuffer });
|
1487
|
+
}
|
1513
1488
|
//#endregion
|
1514
1489
|
//#endregion
|
1515
1490
|
//#region methods / run async in
|
1516
1491
|
//#region @backend
|
1517
|
-
|
1492
|
+
runAsyncIn(command, options) {
|
1518
1493
|
// @ts-ignore
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1494
|
+
const { output, cwd, biggerBuffer, outputLineReplace, extractFromLine, detach, } = options;
|
1495
|
+
const maxBuffer = biggerBuffer ? index_1.Helpers.bigMaxBuffer : undefined;
|
1496
|
+
let stdio = index_1.Helpers.getStdio(options);
|
1522
1497
|
index_1.Helpers.checkProcess(cwd, command);
|
1523
|
-
|
1498
|
+
let proc;
|
1524
1499
|
if (detach) {
|
1525
1500
|
//#region detached
|
1526
|
-
|
1527
|
-
|
1528
|
-
index_1.Helpers.log(
|
1501
|
+
const cmd = core_imports_2._.first(command.split(' '));
|
1502
|
+
const argsForCmd = command.split(' ').slice(1);
|
1503
|
+
index_1.Helpers.log(`cmd: "${cmd}", args: "${argsForCmd.join(' ')}"`);
|
1529
1504
|
if (process.platform === 'win32') {
|
1530
|
-
proc = (0, core_imports_1.spawn)(cmd, argsForCmd, { cwd
|
1505
|
+
proc = (0, core_imports_1.spawn)(cmd, argsForCmd, { cwd, detached: true });
|
1531
1506
|
// proc = child_process.spawn(cmd, argsForCmd, {
|
1532
1507
|
// cwd,
|
1533
1508
|
// detached: true,
|
@@ -1541,16 +1516,20 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1541
1516
|
}
|
1542
1517
|
else {
|
1543
1518
|
// @ts-ignore
|
1544
|
-
proc = core_imports_1.child_process.spawn(cmd, argsForCmd, { cwd
|
1519
|
+
proc = core_imports_1.child_process.spawn(cmd, argsForCmd, { cwd, detached: true });
|
1545
1520
|
}
|
1546
|
-
index_1.Helpers.log(
|
1521
|
+
index_1.Helpers.log(`
|
1522
|
+
|
1523
|
+
DETACHED PROCESS IS WORKING ON PID: ${proc.pid}
|
1524
|
+
|
1525
|
+
`);
|
1547
1526
|
// proc = child.exec(`${command} &`, { cwd, maxBuffer, });
|
1548
1527
|
//#endregion
|
1549
1528
|
}
|
1550
1529
|
else {
|
1551
1530
|
// Helpers.log(`Command to execture: ${command}`)
|
1552
|
-
|
1553
|
-
proc = core_imports_1.child_process.exec(command, { cwd
|
1531
|
+
const env = { ...process.env, FORCE_COLOR: '1' };
|
1532
|
+
proc = core_imports_1.child_process.exec(command, { cwd, maxBuffer, env });
|
1554
1533
|
// if (global.globalSystemToolMode) {
|
1555
1534
|
// proc.on('exit', (code) => {
|
1556
1535
|
// Helpers.log('EXITING BIG PROCESS');
|
@@ -1564,14 +1543,13 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1564
1543
|
}
|
1565
1544
|
return index_1.Helpers.logProc(proc, detach ? true : output, detach ? void 0 : stdio, outputLineReplace, // @ts-ignore
|
1566
1545
|
options.prefix, extractFromLine);
|
1567
|
-
}
|
1546
|
+
}
|
1568
1547
|
//#endregion
|
1569
1548
|
//#endregion
|
1570
1549
|
//#region methods / log process
|
1571
1550
|
//#region @backend
|
1572
1551
|
//#region log process
|
1573
|
-
|
1574
|
-
if (output === void 0) { output = true; }
|
1552
|
+
logProc(proc, output = true, stdio, outputLineReplace, prefix, extractFromLine) {
|
1575
1553
|
index_1.Helpers.processes.push(proc);
|
1576
1554
|
if (stdio) {
|
1577
1555
|
// @ts-ignore
|
@@ -1582,28 +1560,28 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1582
1560
|
}
|
1583
1561
|
if (output) {
|
1584
1562
|
// @ts-ignore
|
1585
|
-
proc.stdout.on('data',
|
1563
|
+
proc.stdout.on('data', data => {
|
1586
1564
|
// if (data?.toString().search('was unexpected at this time') !== -1) {
|
1587
1565
|
// console.log('!!!COMMAND',command)
|
1588
1566
|
// }
|
1589
1567
|
process.stdout.write(index_1.Helpers.modifyLineByLine(data, outputLineReplace, prefix, extractFromLine));
|
1590
1568
|
});
|
1591
1569
|
// @ts-ignore
|
1592
|
-
proc.stdout.on('error',
|
1570
|
+
proc.stdout.on('error', data => {
|
1593
1571
|
// if (data?.toString().search('was unexpected at this time') !== -1) {
|
1594
1572
|
// console.log('!!!COMMAND',command)
|
1595
1573
|
// }
|
1596
1574
|
console.log(index_1.Helpers.modifyLineByLine(data, outputLineReplace, prefix, extractFromLine));
|
1597
1575
|
});
|
1598
1576
|
// @ts-ignore
|
1599
|
-
proc.stderr.on('data',
|
1577
|
+
proc.stderr.on('data', data => {
|
1600
1578
|
// if (data?.toString().search('was unexpected at this time') !== -1) {
|
1601
1579
|
// console.log('!!!COMMAND',command)
|
1602
1580
|
// }
|
1603
1581
|
process.stderr.write(index_1.Helpers.modifyLineByLine(data, outputLineReplace, prefix, extractFromLine));
|
1604
1582
|
});
|
1605
1583
|
// @ts-ignore
|
1606
|
-
proc.stderr.on('error',
|
1584
|
+
proc.stderr.on('error', data => {
|
1607
1585
|
// if (data?.toString().search('was unexpected at this time') !== -1) {
|
1608
1586
|
// console.log('!!!COMMAND',command)
|
1609
1587
|
// }
|
@@ -1611,207 +1589,14 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1611
1589
|
});
|
1612
1590
|
}
|
1613
1591
|
return proc;
|
1614
|
-
}
|
1615
|
-
//#endregion
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
case 0:
|
1623
|
-
_a = options || {}, hideOutput = _a.hideOutput, resolvePromiseMsg = _a.resolvePromiseMsg, outputLineReplace = _a.outputLineReplace, prefix = _a.prefix, extractFromLine = _a.extractFromLine, exitOnErrorCallback = _a.exitOnErrorCallback, askToTryAgainOnError = _a.askToTryAgainOnError, resolvePromiseMsgCallback = _a.resolvePromiseMsgCallback, similarProcessKey = _a.similarProcessKey;
|
1624
|
-
command = index_1.Helpers._fixCommand(command);
|
1625
|
-
_b = resolvePromiseMsgCallback || {}, stderResolvePromiseMsgCallback = _b.stderr, stdoutResolvePromiseMsgCallback = _b.stdout;
|
1626
|
-
// let {
|
1627
|
-
// stderMsgForPromiseResolve,
|
1628
|
-
// stdoutMsgForPromiseResolve
|
1629
|
-
// } = resolvePromiseMsg || {};
|
1630
|
-
// processes.push(proc);
|
1631
|
-
if (!resolvePromiseMsg) {
|
1632
|
-
resolvePromiseMsg = {};
|
1633
|
-
}
|
1634
|
-
if (!hideOutput) {
|
1635
|
-
hideOutput = {};
|
1636
|
-
}
|
1637
|
-
isResolved = false;
|
1638
|
-
if (core_imports_2._.isString(resolvePromiseMsg.stdout)) {
|
1639
|
-
resolvePromiseMsg.stdout = [resolvePromiseMsg.stdout];
|
1640
|
-
}
|
1641
|
-
if (core_imports_2._.isString(resolvePromiseMsg.stderr)) {
|
1642
|
-
resolvePromiseMsg.stderr = [resolvePromiseMsg.stderr];
|
1643
|
-
}
|
1644
|
-
handlProc = function (proc) {
|
1645
|
-
return new Promise(function (resolve, reject) {
|
1646
|
-
// console.log(
|
1647
|
-
// `[execute] Process started...`,
|
1648
|
-
// (resolvePromiseMsg.stdout as string[]).map(c => `"${c}"`).join(','),
|
1649
|
-
// );
|
1650
|
-
//#region handle stdout data
|
1651
|
-
proc.stdout.on('data', function (rawData) {
|
1652
|
-
var data = (rawData === null || rawData === void 0 ? void 0 : rawData.toString()) || '';
|
1653
|
-
data = index_1.Helpers.modifyLineByLine(data, // @ts-ignore
|
1654
|
-
outputLineReplace, prefix, extractFromLine);
|
1655
|
-
if (!hideOutput.stdout) {
|
1656
|
-
process.stdout.write(data);
|
1657
|
-
}
|
1658
|
-
if (core_imports_2._.isArray(resolvePromiseMsg.stdout)) {
|
1659
|
-
for (var index = 0; index < resolvePromiseMsg.stdout.length; index++) {
|
1660
|
-
// console.log(`DATA STDOUT: ${chalk.gray(data)}`);
|
1661
|
-
var resolveCompilationMessage = resolvePromiseMsg.stdout[index];
|
1662
|
-
if (data.search(resolveCompilationMessage) !== -1) {
|
1663
|
-
// Helpers.info(`[unitlOutputContains] AAA...`);
|
1664
|
-
stdoutResolvePromiseMsgCallback &&
|
1665
|
-
stdoutResolvePromiseMsgCallback();
|
1666
|
-
if (!isResolved) {
|
1667
|
-
isResolved = true;
|
1668
|
-
resolve(void 0);
|
1669
|
-
}
|
1670
|
-
break;
|
1671
|
-
}
|
1672
|
-
}
|
1673
|
-
}
|
1674
|
-
// TODO NOT NEEDED
|
1675
|
-
if (core_imports_2._.isArray(resolvePromiseMsg.stderr)) {
|
1676
|
-
for (var index = 0; index < resolvePromiseMsg.stderr.length; index++) {
|
1677
|
-
var rejectm = resolvePromiseMsg.stderr[index];
|
1678
|
-
if (data.search(rejectm) !== -1) {
|
1679
|
-
// Helpers.info(`[unitlOutputContains] Rejected move to next step...`);
|
1680
|
-
stdoutResolvePromiseMsgCallback &&
|
1681
|
-
stdoutResolvePromiseMsgCallback();
|
1682
|
-
if (!isResolved) {
|
1683
|
-
isResolved = true;
|
1684
|
-
reject();
|
1685
|
-
proc.kill('SIGINT');
|
1686
|
-
}
|
1687
|
-
break;
|
1688
|
-
}
|
1689
|
-
}
|
1690
|
-
}
|
1691
|
-
});
|
1692
|
-
//#endregion
|
1693
|
-
//#region handle exit process
|
1694
|
-
proc.on('exit', function (code) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
1695
|
-
var error_2;
|
1696
|
-
return tslib_1.__generator(this, function (_a) {
|
1697
|
-
switch (_a.label) {
|
1698
|
-
case 0:
|
1699
|
-
if (!hideOutput.acceptAllExitCodeAsSuccess) return [3 /*break*/, 1];
|
1700
|
-
resolve(void 0);
|
1701
|
-
return [3 /*break*/, 9];
|
1702
|
-
case 1:
|
1703
|
-
if (!(code !== 0)) return [3 /*break*/, 8];
|
1704
|
-
if (!core_imports_2._.isFunction(exitOnErrorCallback)) return [3 /*break*/, 6];
|
1705
|
-
_a.label = 2;
|
1706
|
-
case 2:
|
1707
|
-
_a.trys.push([2, 4, , 5]);
|
1708
|
-
return [4 /*yield*/, this.runSyncOrAsync({
|
1709
|
-
functionFn: exitOnErrorCallback,
|
1710
|
-
arrayOfParams: [code],
|
1711
|
-
})];
|
1712
|
-
case 3:
|
1713
|
-
_a.sent();
|
1714
|
-
reject("Command failed with code=".concat(code));
|
1715
|
-
return [3 /*break*/, 5];
|
1716
|
-
case 4:
|
1717
|
-
error_2 = _a.sent();
|
1718
|
-
reject(error_2);
|
1719
|
-
return [3 /*break*/, 5];
|
1720
|
-
case 5: return [3 /*break*/, 7];
|
1721
|
-
case 6:
|
1722
|
-
reject("Command failed with code=".concat(code));
|
1723
|
-
_a.label = 7;
|
1724
|
-
case 7: return [3 /*break*/, 9];
|
1725
|
-
case 8:
|
1726
|
-
resolve(void 0);
|
1727
|
-
_a.label = 9;
|
1728
|
-
case 9: return [2 /*return*/];
|
1729
|
-
}
|
1730
|
-
});
|
1731
|
-
}); });
|
1732
|
-
//#endregion
|
1733
|
-
//#region handle stdout error
|
1734
|
-
proc.stdout.on('error', function (rawData) {
|
1735
|
-
var data = (rawData === null || rawData === void 0 ? void 0 : rawData.toString()) || '';
|
1736
|
-
data = index_1.Helpers.modifyLineByLine(data, // @ts-ignore
|
1737
|
-
outputLineReplace, prefix, extractFromLine);
|
1738
|
-
if (!hideOutput.stdout) {
|
1739
|
-
process.stdout.write(JSON.stringify(data));
|
1740
|
-
}
|
1741
|
-
// console.log(data);
|
1742
|
-
});
|
1743
|
-
//#endregion
|
1744
|
-
//#region handle stder data
|
1745
|
-
proc.stderr.on('data', function (rawData) {
|
1746
|
-
var data = (rawData === null || rawData === void 0 ? void 0 : rawData.toString()) || '';
|
1747
|
-
data = index_1.Helpers.modifyLineByLine(data, // @ts-ignore
|
1748
|
-
outputLineReplace, prefix, extractFromLine);
|
1749
|
-
if (!hideOutput.stderr) {
|
1750
|
-
process.stderr.write(data);
|
1751
|
-
}
|
1752
|
-
if (core_imports_2._.isArray(resolvePromiseMsg.stderr)) {
|
1753
|
-
// @ts-ignore
|
1754
|
-
for (var index = 0; index < resolvePromiseMsg.stderr.length; index++) {
|
1755
|
-
// @ts-ignore
|
1756
|
-
var rejectm = resolvePromiseMsg.stderr[index];
|
1757
|
-
if (data.search(rejectm) !== -1) {
|
1758
|
-
// Helpers.info(`[unitlOutputContains] Rejected move to next step...`);
|
1759
|
-
stderResolvePromiseMsgCallback &&
|
1760
|
-
stderResolvePromiseMsgCallback();
|
1761
|
-
if (!isResolved) {
|
1762
|
-
isResolved = true;
|
1763
|
-
reject();
|
1764
|
-
proc.kill('SIGINT');
|
1765
|
-
}
|
1766
|
-
break;
|
1767
|
-
}
|
1768
|
-
}
|
1769
|
-
}
|
1770
|
-
});
|
1771
|
-
//#endregion
|
1772
|
-
//#region handle stder error
|
1773
|
-
proc.stderr.on('error', function (rawData) {
|
1774
|
-
var data = (rawData === null || rawData === void 0 ? void 0 : rawData.toString()) || '';
|
1775
|
-
data = index_1.Helpers.modifyLineByLine(data, // @ts-ignore
|
1776
|
-
outputLineReplace, prefix, extractFromLine);
|
1777
|
-
// @ts-ignore
|
1778
|
-
if (!hideOutput.stderr) {
|
1779
|
-
process.stderr.write(JSON.stringify(data));
|
1780
|
-
}
|
1781
|
-
// console.log(data);
|
1782
|
-
});
|
1783
|
-
//#endregion
|
1784
|
-
});
|
1785
|
-
};
|
1786
|
-
_c.label = 1;
|
1787
|
-
case 1:
|
1788
|
-
if (!true) return [3 /*break*/, 9];
|
1789
|
-
childProcess = core_imports_1.child_process.exec(command, { cwd: cwd });
|
1790
|
-
_c.label = 2;
|
1791
|
-
case 2:
|
1792
|
-
_c.trys.push([2, 4, , 8]);
|
1793
|
-
return [4 /*yield*/, handlProc(childProcess)];
|
1794
|
-
case 3:
|
1795
|
-
_c.sent();
|
1796
|
-
return [3 /*break*/, 9];
|
1797
|
-
case 4:
|
1798
|
-
error_1 = _c.sent();
|
1799
|
-
index_1.Helpers.error("Command failed:\n\n".concat(command, "\n\nin location: ").concat(cwd, "\n\n "), true, true);
|
1800
|
-
if (!askToTryAgainOnError) return [3 /*break*/, 6];
|
1801
|
-
return [4 /*yield*/, index_1.Helpers.questionYesNo("Try again this command ?")];
|
1802
|
-
case 5:
|
1803
|
-
if (!(_c.sent())) {
|
1804
|
-
throw error_1;
|
1805
|
-
}
|
1806
|
-
return [3 /*break*/, 7];
|
1807
|
-
case 6: throw error_1;
|
1808
|
-
case 7: return [3 /*break*/, 8];
|
1809
|
-
case 8: return [3 /*break*/, 1];
|
1810
|
-
case 9: return [2 /*return*/];
|
1811
|
-
}
|
1812
|
-
});
|
1813
|
-
});
|
1814
|
-
};
|
1592
|
+
}
|
1593
|
+
//#endregion
|
1594
|
+
/**
|
1595
|
+
* @deprecated use UtilsProcess.startAsync
|
1596
|
+
*/
|
1597
|
+
async execute(command, cwd, options) {
|
1598
|
+
return utils_1.UtilsProcess.startAsync(command, cwd, options);
|
1599
|
+
}
|
1815
1600
|
//#endregion
|
1816
1601
|
//#endregion
|
1817
1602
|
//#region methods / check process
|
@@ -1819,67 +1604,68 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1819
1604
|
/**
|
1820
1605
|
* @deprecated
|
1821
1606
|
*/
|
1822
|
-
|
1607
|
+
checkProcess(dirPath, command) {
|
1823
1608
|
if (!core_imports_1.fse.existsSync(dirPath)) {
|
1824
|
-
index_1.Helpers.error(
|
1609
|
+
index_1.Helpers.error(`
|
1610
|
+
Path for process cwd doesn't exist: ${dirPath}
|
1611
|
+
command: ${command}
|
1612
|
+
`);
|
1825
1613
|
}
|
1826
1614
|
if (!command) {
|
1827
|
-
index_1.Helpers.error(
|
1615
|
+
index_1.Helpers.error(`Bad command: ${command}`);
|
1828
1616
|
}
|
1829
|
-
}
|
1617
|
+
}
|
1830
1618
|
//#endregion
|
1831
1619
|
//#endregion
|
1832
1620
|
//#region methods / modify line by line
|
1833
1621
|
//#region @backend
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1622
|
+
modifyLineByLine(data, outputLineReplace, prefix, extractFromLine) {
|
1623
|
+
const checkExtract = core_imports_2._.isArray(extractFromLine) && extractFromLine.length > 0;
|
1624
|
+
let modifyOutput = core_imports_2._.isFunction(outputLineReplace);
|
1837
1625
|
if (modifyOutput && core_imports_2._.isString(data)) {
|
1838
1626
|
data = data
|
1839
1627
|
.split(/\r?\n/)
|
1840
|
-
.map(
|
1841
|
-
return outputLineReplace(line);
|
1842
|
-
})
|
1628
|
+
.map(line => outputLineReplace(line))
|
1843
1629
|
.join('\n');
|
1844
1630
|
}
|
1845
1631
|
if (prefix && core_imports_2._.isString(data)) {
|
1846
1632
|
return data
|
1847
1633
|
.split('\n')
|
1848
|
-
.map(
|
1634
|
+
.map(singleLine => {
|
1849
1635
|
if (!singleLine ||
|
1850
1636
|
singleLine.trim().length === 0 ||
|
1851
1637
|
singleLine.trim() === '.') {
|
1852
1638
|
return singleLine;
|
1853
1639
|
}
|
1854
1640
|
if (checkExtract) {
|
1855
|
-
|
1856
|
-
if (sFuncs.filter(
|
1641
|
+
const sFuncs = extractFromLine.filter(f => core_imports_2._.isString(f));
|
1642
|
+
if (sFuncs.filter(f => singleLine.search(f) !== -1)
|
1857
1643
|
.length === sFuncs.length) {
|
1858
|
-
|
1644
|
+
const fun = extractFromLine.find(f => core_imports_2._.isFunction(f));
|
1859
1645
|
if (fun) {
|
1860
|
-
|
1861
|
-
sFuncs.forEach(
|
1862
|
-
|
1646
|
+
let s = singleLine;
|
1647
|
+
sFuncs.forEach(f => {
|
1648
|
+
s = s.replace(f, '');
|
1863
1649
|
});
|
1864
|
-
fun(
|
1650
|
+
fun(s.trim());
|
1865
1651
|
}
|
1866
1652
|
}
|
1867
1653
|
}
|
1868
|
-
return
|
1654
|
+
return `${prefix} ${singleLine}`;
|
1869
1655
|
})
|
1870
1656
|
.join('\n');
|
1871
1657
|
}
|
1872
1658
|
return data;
|
1873
|
-
}
|
1659
|
+
}
|
1874
1660
|
//#endregion
|
1875
1661
|
//#endregion
|
1876
1662
|
//#region methods / is folder
|
1877
1663
|
//#region @backend
|
1878
|
-
|
1664
|
+
isFolder(pathToFileOrMaybeFolder) {
|
1879
1665
|
return !!(pathToFileOrMaybeFolder &&
|
1880
1666
|
core_imports_1.fse.existsSync(pathToFileOrMaybeFolder) &&
|
1881
1667
|
core_imports_1.fse.lstatSync(pathToFileOrMaybeFolder).isDirectory());
|
1882
|
-
}
|
1668
|
+
}
|
1883
1669
|
//#endregion
|
1884
1670
|
//#endregion
|
1885
1671
|
//#region methods / values
|
@@ -1887,10 +1673,10 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1887
1673
|
* Quick fix for object values
|
1888
1674
|
* @deprecated
|
1889
1675
|
*/
|
1890
|
-
|
1676
|
+
values(obj) {
|
1891
1677
|
if (core_imports_2._.isObject(obj) && !Array.isArray(obj)) {
|
1892
|
-
|
1893
|
-
for (
|
1678
|
+
const values = [];
|
1679
|
+
for (const key in obj) {
|
1894
1680
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
1895
1681
|
// @ts-ignore
|
1896
1682
|
values.push(obj[key]);
|
@@ -1899,61 +1685,46 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1899
1685
|
return values;
|
1900
1686
|
}
|
1901
1687
|
return [];
|
1902
|
-
}
|
1688
|
+
}
|
1903
1689
|
//#endregion
|
1904
1690
|
//#region methods / is file
|
1905
|
-
//#region @backend
|
1906
1691
|
/**
|
1907
1692
|
* does not make sense
|
1908
1693
|
* @deprecated
|
1909
1694
|
*/
|
1910
|
-
|
1695
|
+
isFile(pathToFileOrMaybeFolder) {
|
1696
|
+
//#region @backendFunc
|
1911
1697
|
return (pathToFileOrMaybeFolder &&
|
1912
1698
|
core_imports_1.fse.existsSync(pathToFileOrMaybeFolder) &&
|
1913
1699
|
!core_imports_1.fse.lstatSync(pathToFileOrMaybeFolder).isDirectory());
|
1914
|
-
|
1915
|
-
|
1700
|
+
//#endregion
|
1701
|
+
}
|
1916
1702
|
//#endregion
|
1917
1703
|
//#region methods / read file
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
switch (_a.label) {
|
1927
|
-
case 0:
|
1928
|
-
if (!(process.platform === 'win32')) return [3 /*break*/, 6];
|
1929
|
-
_a.label = 1;
|
1930
|
-
case 1:
|
1931
|
-
if (!true) return [3 /*break*/, 6];
|
1932
|
-
_a.label = 2;
|
1933
|
-
case 2:
|
1934
|
-
_a.trys.push([2, 3, , 5]);
|
1935
|
-
fileContent = index_1.Helpers.readFile(absoluteFilePath, defaultValueWhenNotExists, notTrim);
|
1936
|
-
return [2 /*return*/, fileContent];
|
1937
|
-
case 3:
|
1938
|
-
error_3 = _a.sent();
|
1939
|
-
index_1.Helpers.error("Not able to read locked file: ".concat(absoluteFilePath), true, true);
|
1940
|
-
return [4 /*yield*/, index_1.Helpers.wait(2)];
|
1941
|
-
case 4:
|
1942
|
-
_a.sent();
|
1943
|
-
return [3 /*break*/, 5];
|
1944
|
-
case 5: return [3 /*break*/, 1];
|
1945
|
-
case 6: return [2 /*return*/, index_1.Helpers.readFile(absoluteFilePath, defaultValueWhenNotExists, notTrim)];
|
1704
|
+
async tryReadFile(absoluteFilePath, // @ts-ignore
|
1705
|
+
defaultValueWhenNotExists = void 0, notTrim = false) {
|
1706
|
+
//#region @backendFunc
|
1707
|
+
if (process.platform === 'win32') {
|
1708
|
+
while (true) {
|
1709
|
+
try {
|
1710
|
+
const fileContent = index_1.Helpers.readFile(absoluteFilePath, defaultValueWhenNotExists, notTrim);
|
1711
|
+
return fileContent;
|
1946
1712
|
}
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1713
|
+
catch (error) {
|
1714
|
+
index_1.Helpers.error(`Not able to read locked file: ${absoluteFilePath}`, true, true);
|
1715
|
+
await index_1.Helpers.wait(2);
|
1716
|
+
}
|
1717
|
+
}
|
1718
|
+
}
|
1719
|
+
return index_1.Helpers.readFile(absoluteFilePath, defaultValueWhenNotExists, notTrim);
|
1720
|
+
//#endregion
|
1721
|
+
}
|
1950
1722
|
/**
|
1951
1723
|
* wrapper for fs.readFileSync
|
1952
1724
|
*/
|
1953
|
-
|
1954
|
-
defaultValueWhenNotExists, notTrim) {
|
1955
|
-
|
1956
|
-
if (notTrim === void 0) { notTrim = false; }
|
1725
|
+
readFile(absoluteFilePath, // @ts-ignore
|
1726
|
+
defaultValueWhenNotExists = void 0, notTrim = false) {
|
1727
|
+
//#region @backendFunc
|
1957
1728
|
if (core_imports_2._.isArray(absoluteFilePath)) {
|
1958
1729
|
absoluteFilePath = core_imports_2.path.join.apply(this, absoluteFilePath);
|
1959
1730
|
}
|
@@ -1967,28 +1738,26 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1967
1738
|
if (notTrim) {
|
1968
1739
|
return core_imports_1.fse
|
1969
1740
|
.readFileSync(absoluteFilePath, {
|
1970
|
-
encoding
|
1741
|
+
encoding,
|
1971
1742
|
})
|
1972
1743
|
.toString();
|
1973
1744
|
}
|
1974
1745
|
return core_imports_1.fse
|
1975
1746
|
.readFileSync(absoluteFilePath, {
|
1976
|
-
encoding
|
1747
|
+
encoding,
|
1977
1748
|
})
|
1978
1749
|
.toString()
|
1979
1750
|
.trim();
|
1980
|
-
|
1981
|
-
|
1751
|
+
//#endregion
|
1752
|
+
}
|
1982
1753
|
//#endregion
|
1983
1754
|
//#region methods / read json
|
1984
|
-
//#region @backend
|
1985
1755
|
/**
|
1986
1756
|
* read json from absolute path
|
1987
1757
|
* @returns json object
|
1988
1758
|
*/
|
1989
|
-
|
1990
|
-
|
1991
|
-
if (useJson5 === void 0) { useJson5 = false; }
|
1759
|
+
readJson(absoluteFilePath, defaultValue = {}, useJson5 = false) {
|
1760
|
+
//#region @backendFunc
|
1992
1761
|
if (core_imports_2._.isArray(absoluteFilePath)) {
|
1993
1762
|
absoluteFilePath = core_imports_2.path.join.apply(this, absoluteFilePath);
|
1994
1763
|
}
|
@@ -1997,8 +1766,8 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
1997
1766
|
return {};
|
1998
1767
|
}
|
1999
1768
|
try {
|
2000
|
-
|
2001
|
-
|
1769
|
+
const fileContent = index_1.Helpers.readFile(absoluteFilePath);
|
1770
|
+
let json;
|
2002
1771
|
// @ts-ignore
|
2003
1772
|
json = index_1.Helpers.parse(fileContent, useJson5 || absoluteFilePath.endsWith('.json5'));
|
2004
1773
|
return json;
|
@@ -2006,16 +1775,18 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2006
1775
|
catch (error) {
|
2007
1776
|
return defaultValue;
|
2008
1777
|
}
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
1778
|
+
//#endregion
|
1779
|
+
}
|
1780
|
+
readJson5(absoluteFilePath, defaultValue = {}) {
|
1781
|
+
//#region @backendFunc
|
2012
1782
|
return index_1.Helpers.readJson(absoluteFilePath, defaultValue, true);
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
1783
|
+
//#endregion
|
1784
|
+
}
|
1785
|
+
readJsonC(absoluteFilePath, defaultValue = {}) {
|
1786
|
+
//#region @backendFunc
|
2016
1787
|
return this.readJson5(absoluteFilePath, defaultValue);
|
2017
|
-
|
2018
|
-
|
1788
|
+
//#endregion
|
1789
|
+
}
|
2019
1790
|
//#endregion
|
2020
1791
|
//#region methods / parse
|
2021
1792
|
//#region @backend
|
@@ -2023,60 +1794,48 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2023
1794
|
* parse json from string
|
2024
1795
|
* @returns parse json object
|
2025
1796
|
*/
|
2026
|
-
|
2027
|
-
if (useJson5 === void 0) { useJson5 = false; }
|
1797
|
+
parse(jsonInstring, useJson5 = false) {
|
2028
1798
|
if (!core_imports_2._.isString(jsonInstring)) {
|
2029
1799
|
index_1.Helpers.log(jsonInstring);
|
2030
|
-
index_1.Helpers.warn(
|
1800
|
+
index_1.Helpers.warn(`[taon-core] Trying to parse no a string...`);
|
2031
1801
|
return jsonInstring;
|
2032
1802
|
}
|
2033
1803
|
return (useJson5 ? core_imports_1.json5.parse(jsonInstring) : JSON.parse(jsonInstring));
|
2034
|
-
}
|
1804
|
+
}
|
2035
1805
|
//#endregion
|
2036
1806
|
//#endregion
|
2037
1807
|
//#region methods / compilation wrapper
|
2038
1808
|
//#region @backend
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
}
|
2054
|
-
index_1.Helpers.log("".concat(currentDate(), " ").concat(executionType, " \"").concat(taskName, "\" Started.."));
|
2055
|
-
return [4 /*yield*/, index_1.Helpers.runSyncOrAsync({ functionFn: fn })];
|
2056
|
-
case 1:
|
2057
|
-
_a.sent();
|
2058
|
-
index_1.Helpers.log("".concat(currentDate(), " ").concat(executionType, " \"").concat(taskName, "\" Done\u2713"));
|
2059
|
-
return [2 /*return*/];
|
2060
|
-
}
|
2061
|
-
});
|
2062
|
-
});
|
2063
|
-
};
|
1809
|
+
async compilationWrapper(fn, taskName = 'Task', executionType = 'Compilation of') {
|
1810
|
+
// global?.spinner?.start();
|
1811
|
+
function currentDate() {
|
1812
|
+
return `[${(0, core_imports_1.dateformat)(new Date(), 'HH:MM:ss')}]`;
|
1813
|
+
}
|
1814
|
+
if (!fn || !core_imports_2._.isFunction(fn)) {
|
1815
|
+
index_1.Helpers.error(`${executionType} wrapper: "${fn}" is not a function.`);
|
1816
|
+
process.exit(1);
|
1817
|
+
}
|
1818
|
+
index_1.Helpers.log(`${currentDate()} ${executionType} "${taskName}" Started..`);
|
1819
|
+
await index_1.Helpers.runSyncOrAsync({ functionFn: fn });
|
1820
|
+
index_1.Helpers.log(`${currentDate()} ${executionType} "${taskName}" Done\u2713`);
|
1821
|
+
// global?.spinner?.stop();
|
1822
|
+
}
|
2064
1823
|
//#endregion
|
2065
1824
|
//#endregion
|
2066
1825
|
//#region methods / replace in line
|
2067
|
-
|
1826
|
+
replaceLinesInFile(absoluteFilePath, lineReplaceFn) {
|
2068
1827
|
//#region @backend
|
2069
|
-
|
1828
|
+
const file = index_1.Helpers.readFile(absoluteFilePath) || '';
|
2070
1829
|
index_1.Helpers.writeFile(absoluteFilePath, file.split('\n').map(lineReplaceFn).join('\n'));
|
2071
1830
|
//#endregion
|
2072
|
-
}
|
1831
|
+
}
|
2073
1832
|
//#endregion
|
2074
1833
|
//#region methods / write file
|
2075
1834
|
//#region @backend
|
2076
1835
|
/**
|
2077
1836
|
* wrapper for fs.writeFileSync
|
2078
1837
|
*/
|
2079
|
-
|
1838
|
+
writeFile(absoluteFilePath, input,
|
2080
1839
|
//#endregion
|
2081
1840
|
options) {
|
2082
1841
|
if (core_imports_2._.isArray(absoluteFilePath)) {
|
@@ -2086,7 +1845,7 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2086
1845
|
// Helpers.info(`[taon-core] writeFile: ${absoluteFilePath}`);
|
2087
1846
|
// debugger
|
2088
1847
|
if (index_1.Helpers.isExistedSymlink(absoluteFilePath)) {
|
2089
|
-
|
1848
|
+
const beforePath = absoluteFilePath;
|
2090
1849
|
absoluteFilePath = core_imports_1.fse.realpathSync(absoluteFilePath);
|
2091
1850
|
// Helpers.logWarn(
|
2092
1851
|
// `[taon-core] WRITTING JSON into real path:
|
@@ -2096,8 +1855,8 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2096
1855
|
// forceTrace,
|
2097
1856
|
// );
|
2098
1857
|
}
|
2099
|
-
|
2100
|
-
|
1858
|
+
const { preventParentFile, overrideSameFile } = options || {};
|
1859
|
+
const dontWriteSameFile = !overrideSameFile;
|
2101
1860
|
if (preventParentFile) {
|
2102
1861
|
if (index_1.Helpers.isFile(core_imports_2.path.dirname(absoluteFilePath)) &&
|
2103
1862
|
core_imports_1.fse.existsSync(core_imports_2.path.dirname(absoluteFilePath))) {
|
@@ -2106,11 +1865,16 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2106
1865
|
}
|
2107
1866
|
if (core_imports_1.fse.existsSync(absoluteFilePath) &&
|
2108
1867
|
core_imports_1.fse.lstatSync(absoluteFilePath).isDirectory()) {
|
2109
|
-
index_1.Helpers.warn(
|
1868
|
+
index_1.Helpers.warn(`[taon-core] Trying to write file content into directory: ${absoluteFilePath}`);
|
2110
1869
|
return false;
|
2111
1870
|
}
|
2112
1871
|
if (!core_imports_1.fse.existsSync(core_imports_2.path.dirname(absoluteFilePath))) {
|
2113
|
-
|
1872
|
+
try {
|
1873
|
+
index_1.Helpers.mkdirp(core_imports_2.path.dirname(absoluteFilePath));
|
1874
|
+
}
|
1875
|
+
catch (error) {
|
1876
|
+
index_1.Helpers.error(`Not able to create directory: ${core_imports_2.path.dirname(absoluteFilePath)}`);
|
1877
|
+
}
|
2114
1878
|
}
|
2115
1879
|
if (index_1.Helpers.isBuffer(input)) {
|
2116
1880
|
core_imports_1.fse.writeFileSync(absoluteFilePath, input);
|
@@ -2124,7 +1888,7 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2124
1888
|
}
|
2125
1889
|
if (dontWriteSameFile) {
|
2126
1890
|
if (core_imports_1.fse.existsSync(absoluteFilePath)) {
|
2127
|
-
|
1891
|
+
const existedInput = index_1.Helpers.readFile(absoluteFilePath);
|
2128
1892
|
if (input === existedInput) {
|
2129
1893
|
// Helpers.log(`[helpers][writeFile] not writing same file (good thing): ${absoluteFilePath}`);
|
2130
1894
|
return false;
|
@@ -2132,10 +1896,10 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2132
1896
|
}
|
2133
1897
|
}
|
2134
1898
|
core_imports_1.fse.writeFileSync(absoluteFilePath, input, {
|
2135
|
-
encoding
|
1899
|
+
encoding,
|
2136
1900
|
});
|
2137
1901
|
return true;
|
2138
|
-
}
|
1902
|
+
}
|
2139
1903
|
//#endregion
|
2140
1904
|
//#endregion
|
2141
1905
|
//#region methods / write json
|
@@ -2143,12 +1907,12 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2143
1907
|
/**
|
2144
1908
|
* wrapper for fs.writeFileSync
|
2145
1909
|
*/
|
2146
|
-
|
1910
|
+
writeJson(absoluteFilePath, input, optoins) {
|
2147
1911
|
if (core_imports_2._.isArray(absoluteFilePath)) {
|
2148
1912
|
absoluteFilePath = core_imports_2.path.join.apply(this, absoluteFilePath);
|
2149
1913
|
}
|
2150
1914
|
absoluteFilePath = absoluteFilePath;
|
2151
|
-
|
1915
|
+
const { preventParentFile, writeJson5 } = optoins || {};
|
2152
1916
|
if (preventParentFile) {
|
2153
1917
|
if (index_1.Helpers.isFile(core_imports_2.path.dirname(absoluteFilePath)) &&
|
2154
1918
|
core_imports_1.fse.existsSync(core_imports_2.path.dirname(absoluteFilePath))) {
|
@@ -2159,13 +1923,14 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2159
1923
|
index_1.Helpers.mkdirp(core_imports_2.path.dirname(absoluteFilePath));
|
2160
1924
|
}
|
2161
1925
|
if (writeJson5) {
|
2162
|
-
|
1926
|
+
const existedContent = index_1.Helpers.readFile(absoluteFilePath) || '{}';
|
2163
1927
|
try {
|
2164
1928
|
var writer = json5Write.load(existedContent);
|
2165
1929
|
}
|
2166
1930
|
catch (error) {
|
2167
|
-
console.error(error
|
2168
|
-
index_1.Helpers.error(
|
1931
|
+
console.error(error?.message);
|
1932
|
+
index_1.Helpers.error(`Pleas fix your jsonc file (json with comments) in
|
1933
|
+
${absoluteFilePath}`, false, true);
|
2169
1934
|
}
|
2170
1935
|
writer.write(input);
|
2171
1936
|
index_1.Helpers.writeFile(absoluteFilePath, this.removeEmptyLineFromString(writer.toSource({
|
@@ -2176,18 +1941,18 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2176
1941
|
}
|
2177
1942
|
else {
|
2178
1943
|
core_imports_1.fse.writeJSONSync(absoluteFilePath, input, {
|
2179
|
-
encoding
|
1944
|
+
encoding,
|
2180
1945
|
spaces: 2,
|
2181
1946
|
});
|
2182
1947
|
}
|
2183
1948
|
return true;
|
2184
|
-
}
|
2185
|
-
|
1949
|
+
}
|
1950
|
+
writeJson5(absoluteFilePath, input) {
|
2186
1951
|
return index_1.Helpers.writeJson(absoluteFilePath, input, { writeJson5: true });
|
2187
|
-
}
|
2188
|
-
|
1952
|
+
}
|
1953
|
+
writeJsonC(absoluteFilePath, input) {
|
2189
1954
|
return this.writeJson5(absoluteFilePath, input);
|
2190
|
-
}
|
1955
|
+
}
|
2191
1956
|
//#endregion
|
2192
1957
|
//#endregion
|
2193
1958
|
//#region methods / folders from
|
@@ -2196,51 +1961,40 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2196
1961
|
* return absolute paths for folders inside folders
|
2197
1962
|
* @returns absoulte pathes to folders from path
|
2198
1963
|
*/
|
2199
|
-
|
1964
|
+
foldersFrom(pathToFolder, options) {
|
2200
1965
|
if (core_imports_2._.isArray(pathToFolder)) {
|
2201
1966
|
pathToFolder = (0, core_imports_2.crossPlatformPath)(pathToFolder);
|
2202
1967
|
}
|
2203
1968
|
if (!index_1.Helpers.exists(pathToFolder)) {
|
2204
1969
|
return [];
|
2205
1970
|
}
|
2206
|
-
|
2207
|
-
|
1971
|
+
const { recursive } = options || {};
|
1972
|
+
let directories = [];
|
2208
1973
|
// Helper function to read a directory
|
2209
|
-
|
2210
|
-
var e_3, _a;
|
1974
|
+
const readDirectory = (folderPath) => {
|
2211
1975
|
try {
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
if (recursive) {
|
2223
|
-
readDirectory(dirPath);
|
2224
|
-
}
|
1976
|
+
const files = core_imports_1.fse.readdirSync(folderPath, { withFileTypes: true });
|
1977
|
+
for (const file of files) {
|
1978
|
+
if (file.isDirectory() &&
|
1979
|
+
!index_1.Helpers.isSymlinkFileExitedOrUnexisted([folderPath, file.name])) {
|
1980
|
+
const dirPath = (0, core_imports_2.crossPlatformPath)([folderPath, file.name]);
|
1981
|
+
// console.log('dirPath', dirPath)
|
1982
|
+
directories.push(dirPath);
|
1983
|
+
// If recursive, read the directory found
|
1984
|
+
if (recursive) {
|
1985
|
+
readDirectory(dirPath);
|
2225
1986
|
}
|
2226
1987
|
}
|
2227
1988
|
}
|
2228
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
2229
|
-
finally {
|
2230
|
-
try {
|
2231
|
-
if (files_1_1 && !files_1_1.done && (_a = files_1.return)) _a.call(files_1);
|
2232
|
-
}
|
2233
|
-
finally { if (e_3) throw e_3.error; }
|
2234
|
-
}
|
2235
1989
|
}
|
2236
1990
|
catch (err) {
|
2237
|
-
index_1.Helpers.error(
|
1991
|
+
index_1.Helpers.error(`Error reading directory ${folderPath}: ${err}`);
|
2238
1992
|
}
|
2239
1993
|
};
|
2240
1994
|
// Start reading from the initial folder
|
2241
1995
|
readDirectory(pathToFolder);
|
2242
1996
|
return directories;
|
2243
|
-
}
|
1997
|
+
}
|
2244
1998
|
//#endregion
|
2245
1999
|
//#endregion
|
2246
2000
|
//#region methods / links from
|
@@ -2248,21 +2002,20 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2248
2002
|
/**
|
2249
2003
|
* @returns absolute pathes to links from path
|
2250
2004
|
*/
|
2251
|
-
|
2252
|
-
if (outputRealPath === void 0) { outputRealPath = false; }
|
2005
|
+
linksToFoldersFrom(pathToFolder, outputRealPath = false) {
|
2253
2006
|
if (core_imports_2._.isArray(pathToFolder)) {
|
2254
|
-
pathToFolder = core_imports_2.path.join
|
2007
|
+
pathToFolder = core_imports_2.path.join(...pathToFolder);
|
2255
2008
|
}
|
2256
2009
|
if (!index_1.Helpers.exists(pathToFolder)) {
|
2257
2010
|
return [];
|
2258
2011
|
}
|
2259
2012
|
return (core_imports_1.fse
|
2260
2013
|
.readdirSync(pathToFolder)
|
2261
|
-
.map(
|
2262
|
-
.filter(
|
2263
|
-
.map(
|
2264
|
-
|
2265
|
-
|
2014
|
+
.map(f => core_imports_2.path.join(pathToFolder, f))
|
2015
|
+
.filter(f => core_imports_1.fse.existsSync(f) && core_imports_1.fse.lstatSync(f).isSymbolicLink())
|
2016
|
+
.map(f => {
|
2017
|
+
const realPath = core_imports_1.fse.realpathSync(f);
|
2018
|
+
const isFolder = index_1.Helpers.isFolder(realPath);
|
2266
2019
|
if (isFolder) {
|
2267
2020
|
if (outputRealPath) {
|
2268
2021
|
return realPath;
|
@@ -2272,10 +2025,10 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2272
2025
|
}
|
2273
2026
|
}
|
2274
2027
|
})
|
2275
|
-
.filter(
|
2028
|
+
.filter(f => !!f)
|
2276
2029
|
// @ts-ignore
|
2277
|
-
.map(
|
2278
|
-
}
|
2030
|
+
.map(f => (0, core_imports_2.crossPlatformPath)(f)));
|
2031
|
+
}
|
2279
2032
|
//#endregion
|
2280
2033
|
//#endregion
|
2281
2034
|
//#region methods / links to folders from path
|
@@ -2283,30 +2036,30 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2283
2036
|
/**
|
2284
2037
|
* @returns absolute paths for folders inside folders
|
2285
2038
|
*/
|
2286
|
-
|
2039
|
+
linksToFolderFrom(pathToFolder) {
|
2287
2040
|
// options = (options || {}) as any;
|
2288
2041
|
// if (_.isUndefined(options.linksOnlyTo)) {
|
2289
2042
|
// options.linksOnlyTo = 'both';
|
2290
2043
|
// }
|
2291
2044
|
if (core_imports_2._.isArray(pathToFolder)) {
|
2292
|
-
pathToFolder = core_imports_2.path.join
|
2045
|
+
pathToFolder = core_imports_2.path.join(...pathToFolder);
|
2293
2046
|
}
|
2294
2047
|
if (!index_1.Helpers.exists(pathToFolder)) {
|
2295
2048
|
return [];
|
2296
2049
|
}
|
2297
2050
|
return core_imports_1.fse
|
2298
2051
|
.readdirSync(pathToFolder)
|
2299
|
-
.map(
|
2300
|
-
.filter(
|
2301
|
-
|
2052
|
+
.map(f => core_imports_2.path.join(pathToFolder, f))
|
2053
|
+
.filter(f => {
|
2054
|
+
let res = false;
|
2302
2055
|
if (index_1.Helpers.isExistedSymlink(f)) {
|
2303
|
-
|
2056
|
+
const realPath = core_imports_1.fse.realpathSync(f);
|
2304
2057
|
return index_1.Helpers.isFolder(realPath);
|
2305
2058
|
}
|
2306
2059
|
return res;
|
2307
2060
|
})
|
2308
|
-
.map(
|
2309
|
-
}
|
2061
|
+
.map(f => (0, core_imports_2.crossPlatformPath)(f));
|
2062
|
+
}
|
2310
2063
|
//#endregion
|
2311
2064
|
//#endregion
|
2312
2065
|
//#region methods / files from
|
@@ -2314,78 +2067,77 @@ var HelpersCore = /** @class */ (function (_super) {
|
|
2314
2067
|
/**
|
2315
2068
|
* return absolute paths for folders inside folders
|
2316
2069
|
*/
|
2317
|
-
|
2318
|
-
var _this = this;
|
2319
|
-
if (recrusive === void 0) { recrusive = false; }
|
2320
|
-
if (incudeUnexistedLinks === void 0) { incudeUnexistedLinks = false; }
|
2070
|
+
filesFrom(pathToFolder, recrusive = false, incudeUnexistedLinks = false) {
|
2321
2071
|
if (core_imports_2._.isArray(pathToFolder)) {
|
2322
|
-
pathToFolder = core_imports_2.path.join
|
2072
|
+
pathToFolder = core_imports_2.path.join(...pathToFolder);
|
2323
2073
|
}
|
2324
2074
|
if (!index_1.Helpers.exists(pathToFolder)) {
|
2325
2075
|
return [];
|
2326
2076
|
}
|
2327
2077
|
if (recrusive && incudeUnexistedLinks) {
|
2328
|
-
return core_imports_1.glob.sync(
|
2078
|
+
return core_imports_1.glob.sync(`${pathToFolder}/**/*.*`);
|
2329
2079
|
}
|
2330
2080
|
if (recrusive) {
|
2331
|
-
|
2081
|
+
const all = core_imports_1.fse
|
2332
2082
|
.readdirSync(pathToFolder)
|
2333
|
-
.map(
|
2334
|
-
|
2335
|
-
|
2083
|
+
.map(f => (0, core_imports_2.crossPlatformPath)([pathToFolder, f]));
|
2084
|
+
const folders = [];
|
2085
|
+
const files = all.filter(f => {
|
2336
2086
|
if (core_imports_1.fse.lstatSync(f).isDirectory()) {
|
2337
|
-
|
2087
|
+
folders.push(f);
|
2338
2088
|
return false;
|
2339
2089
|
}
|
2340
2090
|
return true;
|
2341
2091
|
});
|
2342
|
-
return
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
2346
|
-
|
2092
|
+
return [
|
2093
|
+
...files,
|
2094
|
+
...folders
|
2095
|
+
.map(f => this.filesFrom(f, recrusive))
|
2096
|
+
.reduce((a, b) => {
|
2097
|
+
return a.concat(b);
|
2098
|
+
}, []),
|
2099
|
+
].map(f => (0, core_imports_2.crossPlatformPath)(f));
|
2347
2100
|
}
|
2348
2101
|
return core_imports_1.fse
|
2349
2102
|
.readdirSync(pathToFolder)
|
2350
|
-
.map(
|
2351
|
-
.filter(
|
2103
|
+
.map(f => (0, core_imports_2.crossPlatformPath)(core_imports_2.path.join(pathToFolder, f)))
|
2104
|
+
.filter(f => {
|
2352
2105
|
return !core_imports_1.fse.lstatSync(f).isDirectory();
|
2353
2106
|
});
|
2354
|
-
}
|
2107
|
+
}
|
2355
2108
|
//#endregion
|
2356
2109
|
//#endregion
|
2357
2110
|
//#region methods / open folder in file explorer
|
2358
2111
|
//#region @backend
|
2359
|
-
|
2112
|
+
openFolderInFileExploer(folderPath) {
|
2360
2113
|
if (process.platform === 'win32') {
|
2361
2114
|
folderPath = (0, core_imports_1.win32Path)(folderPath);
|
2362
2115
|
}
|
2363
2116
|
try {
|
2364
|
-
index_1.Helpers.info(
|
2117
|
+
index_1.Helpers.info(`Opening path.. "${folderPath}"`);
|
2365
2118
|
if (process.platform === 'win32') {
|
2366
|
-
index_1.Helpers.run(
|
2119
|
+
index_1.Helpers.run(`explorer .`, { cwd: folderPath }).sync();
|
2367
2120
|
return;
|
2368
2121
|
}
|
2369
2122
|
if (process.platform === 'darwin') {
|
2370
|
-
index_1.Helpers.run(
|
2123
|
+
index_1.Helpers.run(`open .`, { cwd: folderPath }).sync();
|
2371
2124
|
return;
|
2372
2125
|
}
|
2373
|
-
index_1.Helpers.run(
|
2126
|
+
index_1.Helpers.run(`xdg-open .`, { cwd: folderPath }).sync();
|
2374
2127
|
}
|
2375
2128
|
catch (error) {
|
2376
|
-
index_1.Helpers.warn(
|
2129
|
+
index_1.Helpers.warn(`Not able to open in file explorer: "${folderPath}"`, false);
|
2377
2130
|
}
|
2378
|
-
}
|
2131
|
+
}
|
2379
2132
|
//#endregion
|
2380
2133
|
//#endregion
|
2381
2134
|
//#region methods / hide node warnings
|
2382
|
-
|
2135
|
+
hideNodeWarnings() {
|
2383
2136
|
//#region @backend
|
2384
|
-
|
2137
|
+
const process = require('process');
|
2385
2138
|
process.removeAllListeners('warning');
|
2386
2139
|
//#endregion
|
2387
|
-
}
|
2388
|
-
|
2389
|
-
}(helpers_messages_1.HelpersMessages));
|
2140
|
+
}
|
2141
|
+
}
|
2390
2142
|
exports.HelpersCore = HelpersCore;
|
2391
2143
|
//# sourceMappingURL=helpers.js.map
|