@rg-dev/stdlib 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/common-env.cjs +167 -167
- package/lib/common-env.d.cts +5 -5
- package/lib/common-env.d.ts +5 -5
- package/lib/common-env.js +145 -145
- package/lib/node-download.cjs +6113 -6113
- package/lib/node-download.d.cts +3 -3
- package/lib/node-download.d.ts +3 -3
- package/lib/node-download.js +6117 -6117
- package/lib/node-env.cjs +252 -252
- package/lib/node-env.d.cts +3 -3
- package/lib/node-env.d.ts +3 -3
- package/lib/node-env.js +252 -252
- package/package.json +4 -4
package/lib/node-env.js
CHANGED
|
@@ -1,252 +1,252 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined")
|
|
11
|
-
return require.apply(this, arguments);
|
|
12
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
-
});
|
|
14
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
-
};
|
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
-
for (let key of __getOwnPropNames(from))
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
-
}
|
|
23
|
-
return to;
|
|
24
|
-
};
|
|
25
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
-
mod
|
|
32
|
-
));
|
|
33
|
-
|
|
34
|
-
// node_modules/command-exists/lib/command-exists.js
|
|
35
|
-
var require_command_exists = __commonJS({
|
|
36
|
-
"node_modules/command-exists/lib/command-exists.js"(exports, module) {
|
|
37
|
-
"use strict";
|
|
38
|
-
var exec = __require("child_process").exec;
|
|
39
|
-
var execSync = __require("child_process").execSync;
|
|
40
|
-
var fs2 = __require("fs");
|
|
41
|
-
var path2 = __require("path");
|
|
42
|
-
var access = fs2.access;
|
|
43
|
-
var accessSync = fs2.accessSync;
|
|
44
|
-
var constants = fs2.constants || fs2;
|
|
45
|
-
var isUsingWindows = process.platform == "win32";
|
|
46
|
-
var fileNotExists = function(commandName, callback) {
|
|
47
|
-
access(
|
|
48
|
-
commandName,
|
|
49
|
-
constants.F_OK,
|
|
50
|
-
function(err) {
|
|
51
|
-
callback(!err);
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
var fileNotExistsSync = function(commandName) {
|
|
56
|
-
try {
|
|
57
|
-
accessSync(commandName, constants.F_OK);
|
|
58
|
-
return false;
|
|
59
|
-
} catch (e) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
var localExecutable = function(commandName, callback) {
|
|
64
|
-
access(
|
|
65
|
-
commandName,
|
|
66
|
-
constants.F_OK | constants.X_OK,
|
|
67
|
-
function(err) {
|
|
68
|
-
callback(null, !err);
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
};
|
|
72
|
-
var localExecutableSync = function(commandName) {
|
|
73
|
-
try {
|
|
74
|
-
accessSync(commandName, constants.F_OK | constants.X_OK);
|
|
75
|
-
return true;
|
|
76
|
-
} catch (e) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var commandExistsUnix = function(commandName, cleanedCommandName, callback) {
|
|
81
|
-
fileNotExists(commandName, function(isFile) {
|
|
82
|
-
if (!isFile) {
|
|
83
|
-
var child = exec(
|
|
84
|
-
"command -v " + cleanedCommandName + " 2>/dev/null && { echo >&1 " + cleanedCommandName + "; exit 0; }",
|
|
85
|
-
function(error, stdout, stderr) {
|
|
86
|
-
callback(null, !!stdout);
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
localExecutable(commandName, callback);
|
|
92
|
-
});
|
|
93
|
-
};
|
|
94
|
-
var commandExistsWindows = function(commandName, cleanedCommandName, callback) {
|
|
95
|
-
if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName)) {
|
|
96
|
-
callback(null, false);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
var child = exec(
|
|
100
|
-
"where " + cleanedCommandName,
|
|
101
|
-
function(error) {
|
|
102
|
-
if (error !== null) {
|
|
103
|
-
callback(null, false);
|
|
104
|
-
} else {
|
|
105
|
-
callback(null, true);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
);
|
|
109
|
-
};
|
|
110
|
-
var commandExistsUnixSync = function(commandName, cleanedCommandName) {
|
|
111
|
-
if (fileNotExistsSync(commandName)) {
|
|
112
|
-
try {
|
|
113
|
-
var stdout = execSync(
|
|
114
|
-
"command -v " + cleanedCommandName + " 2>/dev/null && { echo >&1 " + cleanedCommandName + "; exit 0; }"
|
|
115
|
-
);
|
|
116
|
-
return !!stdout;
|
|
117
|
-
} catch (error) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return localExecutableSync(commandName);
|
|
122
|
-
};
|
|
123
|
-
var commandExistsWindowsSync = function(commandName, cleanedCommandName, callback) {
|
|
124
|
-
if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName)) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
var stdout = execSync("where " + cleanedCommandName, { stdio: [] });
|
|
129
|
-
return !!stdout;
|
|
130
|
-
} catch (error) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
var cleanInput = function(s) {
|
|
135
|
-
if (/[^A-Za-z0-9_\/:=-]/.test(s)) {
|
|
136
|
-
s = "'" + s.replace(/'/g, "'\\''") + "'";
|
|
137
|
-
s = s.replace(/^(?:'')+/g, "").replace(/\\'''/g, "\\'");
|
|
138
|
-
}
|
|
139
|
-
return s;
|
|
140
|
-
};
|
|
141
|
-
if (isUsingWindows) {
|
|
142
|
-
cleanInput = function(s) {
|
|
143
|
-
var isPathName = /[\\]/.test(s);
|
|
144
|
-
if (isPathName) {
|
|
145
|
-
var dirname = '"' + path2.dirname(s) + '"';
|
|
146
|
-
var basename = '"' + path2.basename(s) + '"';
|
|
147
|
-
return dirname + ":" + basename;
|
|
148
|
-
}
|
|
149
|
-
return '"' + s + '"';
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
module.exports = function commandExists2(commandName, callback) {
|
|
153
|
-
var cleanedCommandName = cleanInput(commandName);
|
|
154
|
-
if (!callback && typeof Promise !== "undefined") {
|
|
155
|
-
return new Promise(function(resolve, reject) {
|
|
156
|
-
commandExists2(commandName, function(error, output) {
|
|
157
|
-
if (output) {
|
|
158
|
-
resolve(commandName);
|
|
159
|
-
} else {
|
|
160
|
-
reject(error);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
if (isUsingWindows) {
|
|
166
|
-
commandExistsWindows(commandName, cleanedCommandName, callback);
|
|
167
|
-
} else {
|
|
168
|
-
commandExistsUnix(commandName, cleanedCommandName, callback);
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
module.exports.sync = function(commandName) {
|
|
172
|
-
var cleanedCommandName = cleanInput(commandName);
|
|
173
|
-
if (isUsingWindows) {
|
|
174
|
-
return commandExistsWindowsSync(commandName, cleanedCommandName);
|
|
175
|
-
} else {
|
|
176
|
-
return commandExistsUnixSync(commandName, cleanedCommandName);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// node_modules/command-exists/index.js
|
|
183
|
-
var require_command_exists2 = __commonJS({
|
|
184
|
-
"node_modules/command-exists/index.js"(exports, module) {
|
|
185
|
-
module.exports = require_command_exists();
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// src/node-env.ts
|
|
190
|
-
var import_command_exists = __toESM(require_command_exists2(), 1);
|
|
191
|
-
import * as fs from "fs-extra";
|
|
192
|
-
import os from "os";
|
|
193
|
-
import path from "path";
|
|
194
|
-
function isWindows() {
|
|
195
|
-
return os.platform() === "win32";
|
|
196
|
-
}
|
|
197
|
-
async function checkIfDirExistsOrThrow(path2) {
|
|
198
|
-
if (!path2)
|
|
199
|
-
throw "path is empty";
|
|
200
|
-
path2 = removeQuotes(path2);
|
|
201
|
-
if (!await fs.pathExists(path2))
|
|
202
|
-
throw new Error(`path ${path2} not exists`);
|
|
203
|
-
if (!(await fs.stat(path2)).isDirectory())
|
|
204
|
-
throw new Error(`${path2} is a file, require dir`);
|
|
205
|
-
}
|
|
206
|
-
function createTempDir() {
|
|
207
|
-
const tmpDir = os.tmpdir();
|
|
208
|
-
const timestamp = Date.now();
|
|
209
|
-
const tempDirName = `temp_dir_${timestamp}`;
|
|
210
|
-
const tempDirPath = path.join(tmpDir, tempDirName);
|
|
211
|
-
console.log("tempDir", tempDirPath);
|
|
212
|
-
fs.mkdirSync(tempDirPath);
|
|
213
|
-
return tempDirPath;
|
|
214
|
-
}
|
|
215
|
-
async function throwIfDirNotEmpty(dir_path) {
|
|
216
|
-
if (!await fs.pathExists(dir_path))
|
|
217
|
-
throw new Error("dir not exists");
|
|
218
|
-
const isEmpty = await fs.readdir(dir_path).then((x) => x.length === 0);
|
|
219
|
-
if (!isEmpty)
|
|
220
|
-
throw new Error(`dir ${dir_path} must be empty`);
|
|
221
|
-
}
|
|
222
|
-
async function checkCommandExistsOrThrow(cmd) {
|
|
223
|
-
try {
|
|
224
|
-
await (0, import_command_exists.default)(cmd);
|
|
225
|
-
} catch (e) {
|
|
226
|
-
throw new Error(`cmd ${cmd} not exists`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
async function checkIfFileExistsOrThrow(the_path) {
|
|
230
|
-
if (!the_path)
|
|
231
|
-
throw "path is empty";
|
|
232
|
-
the_path = removeQuotes(the_path);
|
|
233
|
-
if (!await fs.pathExists(the_path))
|
|
234
|
-
throw new Error(`path ${the_path} not exists`);
|
|
235
|
-
if (!(await fs.stat(the_path)).isFile())
|
|
236
|
-
throw new Error(`${the_path} is a dir, require file`);
|
|
237
|
-
}
|
|
238
|
-
function removeQuotes(str) {
|
|
239
|
-
if (str.startsWith('"') && str.endsWith('"')) {
|
|
240
|
-
return str.slice(1, -1);
|
|
241
|
-
} else {
|
|
242
|
-
return str;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
export {
|
|
246
|
-
checkCommandExistsOrThrow,
|
|
247
|
-
checkIfDirExistsOrThrow,
|
|
248
|
-
checkIfFileExistsOrThrow,
|
|
249
|
-
createTempDir,
|
|
250
|
-
isWindows,
|
|
251
|
-
throwIfDirNotEmpty
|
|
252
|
-
};
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined")
|
|
11
|
+
return require.apply(this, arguments);
|
|
12
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
13
|
+
});
|
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
// node_modules/command-exists/lib/command-exists.js
|
|
35
|
+
var require_command_exists = __commonJS({
|
|
36
|
+
"node_modules/command-exists/lib/command-exists.js"(exports, module) {
|
|
37
|
+
"use strict";
|
|
38
|
+
var exec = __require("child_process").exec;
|
|
39
|
+
var execSync = __require("child_process").execSync;
|
|
40
|
+
var fs2 = __require("fs");
|
|
41
|
+
var path2 = __require("path");
|
|
42
|
+
var access = fs2.access;
|
|
43
|
+
var accessSync = fs2.accessSync;
|
|
44
|
+
var constants = fs2.constants || fs2;
|
|
45
|
+
var isUsingWindows = process.platform == "win32";
|
|
46
|
+
var fileNotExists = function(commandName, callback) {
|
|
47
|
+
access(
|
|
48
|
+
commandName,
|
|
49
|
+
constants.F_OK,
|
|
50
|
+
function(err) {
|
|
51
|
+
callback(!err);
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
};
|
|
55
|
+
var fileNotExistsSync = function(commandName) {
|
|
56
|
+
try {
|
|
57
|
+
accessSync(commandName, constants.F_OK);
|
|
58
|
+
return false;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var localExecutable = function(commandName, callback) {
|
|
64
|
+
access(
|
|
65
|
+
commandName,
|
|
66
|
+
constants.F_OK | constants.X_OK,
|
|
67
|
+
function(err) {
|
|
68
|
+
callback(null, !err);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
var localExecutableSync = function(commandName) {
|
|
73
|
+
try {
|
|
74
|
+
accessSync(commandName, constants.F_OK | constants.X_OK);
|
|
75
|
+
return true;
|
|
76
|
+
} catch (e) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var commandExistsUnix = function(commandName, cleanedCommandName, callback) {
|
|
81
|
+
fileNotExists(commandName, function(isFile) {
|
|
82
|
+
if (!isFile) {
|
|
83
|
+
var child = exec(
|
|
84
|
+
"command -v " + cleanedCommandName + " 2>/dev/null && { echo >&1 " + cleanedCommandName + "; exit 0; }",
|
|
85
|
+
function(error, stdout, stderr) {
|
|
86
|
+
callback(null, !!stdout);
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
localExecutable(commandName, callback);
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
var commandExistsWindows = function(commandName, cleanedCommandName, callback) {
|
|
95
|
+
if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName)) {
|
|
96
|
+
callback(null, false);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
var child = exec(
|
|
100
|
+
"where " + cleanedCommandName,
|
|
101
|
+
function(error) {
|
|
102
|
+
if (error !== null) {
|
|
103
|
+
callback(null, false);
|
|
104
|
+
} else {
|
|
105
|
+
callback(null, true);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
};
|
|
110
|
+
var commandExistsUnixSync = function(commandName, cleanedCommandName) {
|
|
111
|
+
if (fileNotExistsSync(commandName)) {
|
|
112
|
+
try {
|
|
113
|
+
var stdout = execSync(
|
|
114
|
+
"command -v " + cleanedCommandName + " 2>/dev/null && { echo >&1 " + cleanedCommandName + "; exit 0; }"
|
|
115
|
+
);
|
|
116
|
+
return !!stdout;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return localExecutableSync(commandName);
|
|
122
|
+
};
|
|
123
|
+
var commandExistsWindowsSync = function(commandName, cleanedCommandName, callback) {
|
|
124
|
+
if (!/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName)) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
var stdout = execSync("where " + cleanedCommandName, { stdio: [] });
|
|
129
|
+
return !!stdout;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var cleanInput = function(s) {
|
|
135
|
+
if (/[^A-Za-z0-9_\/:=-]/.test(s)) {
|
|
136
|
+
s = "'" + s.replace(/'/g, "'\\''") + "'";
|
|
137
|
+
s = s.replace(/^(?:'')+/g, "").replace(/\\'''/g, "\\'");
|
|
138
|
+
}
|
|
139
|
+
return s;
|
|
140
|
+
};
|
|
141
|
+
if (isUsingWindows) {
|
|
142
|
+
cleanInput = function(s) {
|
|
143
|
+
var isPathName = /[\\]/.test(s);
|
|
144
|
+
if (isPathName) {
|
|
145
|
+
var dirname = '"' + path2.dirname(s) + '"';
|
|
146
|
+
var basename = '"' + path2.basename(s) + '"';
|
|
147
|
+
return dirname + ":" + basename;
|
|
148
|
+
}
|
|
149
|
+
return '"' + s + '"';
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
module.exports = function commandExists2(commandName, callback) {
|
|
153
|
+
var cleanedCommandName = cleanInput(commandName);
|
|
154
|
+
if (!callback && typeof Promise !== "undefined") {
|
|
155
|
+
return new Promise(function(resolve, reject) {
|
|
156
|
+
commandExists2(commandName, function(error, output) {
|
|
157
|
+
if (output) {
|
|
158
|
+
resolve(commandName);
|
|
159
|
+
} else {
|
|
160
|
+
reject(error);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (isUsingWindows) {
|
|
166
|
+
commandExistsWindows(commandName, cleanedCommandName, callback);
|
|
167
|
+
} else {
|
|
168
|
+
commandExistsUnix(commandName, cleanedCommandName, callback);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
module.exports.sync = function(commandName) {
|
|
172
|
+
var cleanedCommandName = cleanInput(commandName);
|
|
173
|
+
if (isUsingWindows) {
|
|
174
|
+
return commandExistsWindowsSync(commandName, cleanedCommandName);
|
|
175
|
+
} else {
|
|
176
|
+
return commandExistsUnixSync(commandName, cleanedCommandName);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// node_modules/command-exists/index.js
|
|
183
|
+
var require_command_exists2 = __commonJS({
|
|
184
|
+
"node_modules/command-exists/index.js"(exports, module) {
|
|
185
|
+
module.exports = require_command_exists();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// src/node-env.ts
|
|
190
|
+
var import_command_exists = __toESM(require_command_exists2(), 1);
|
|
191
|
+
import * as fs from "fs-extra";
|
|
192
|
+
import os from "os";
|
|
193
|
+
import path from "path";
|
|
194
|
+
function isWindows() {
|
|
195
|
+
return os.platform() === "win32";
|
|
196
|
+
}
|
|
197
|
+
async function checkIfDirExistsOrThrow(path2) {
|
|
198
|
+
if (!path2)
|
|
199
|
+
throw "path is empty";
|
|
200
|
+
path2 = removeQuotes(path2);
|
|
201
|
+
if (!await fs.pathExists(path2))
|
|
202
|
+
throw new Error(`path ${path2} not exists`);
|
|
203
|
+
if (!(await fs.stat(path2)).isDirectory())
|
|
204
|
+
throw new Error(`${path2} is a file, require dir`);
|
|
205
|
+
}
|
|
206
|
+
function createTempDir() {
|
|
207
|
+
const tmpDir = os.tmpdir();
|
|
208
|
+
const timestamp = Date.now();
|
|
209
|
+
const tempDirName = `temp_dir_${timestamp}`;
|
|
210
|
+
const tempDirPath = path.join(tmpDir, tempDirName);
|
|
211
|
+
console.log("tempDir", tempDirPath);
|
|
212
|
+
fs.mkdirSync(tempDirPath);
|
|
213
|
+
return tempDirPath;
|
|
214
|
+
}
|
|
215
|
+
async function throwIfDirNotEmpty(dir_path) {
|
|
216
|
+
if (!await fs.pathExists(dir_path))
|
|
217
|
+
throw new Error("dir not exists");
|
|
218
|
+
const isEmpty = await fs.readdir(dir_path).then((x) => x.length === 0);
|
|
219
|
+
if (!isEmpty)
|
|
220
|
+
throw new Error(`dir ${dir_path} must be empty`);
|
|
221
|
+
}
|
|
222
|
+
async function checkCommandExistsOrThrow(cmd) {
|
|
223
|
+
try {
|
|
224
|
+
await (0, import_command_exists.default)(cmd);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
throw new Error(`cmd ${cmd} not exists`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async function checkIfFileExistsOrThrow(the_path) {
|
|
230
|
+
if (!the_path)
|
|
231
|
+
throw "path is empty";
|
|
232
|
+
the_path = removeQuotes(the_path);
|
|
233
|
+
if (!await fs.pathExists(the_path))
|
|
234
|
+
throw new Error(`path ${the_path} not exists`);
|
|
235
|
+
if (!(await fs.stat(the_path)).isFile())
|
|
236
|
+
throw new Error(`${the_path} is a dir, require file`);
|
|
237
|
+
}
|
|
238
|
+
function removeQuotes(str) {
|
|
239
|
+
if (str.startsWith('"') && str.endsWith('"')) {
|
|
240
|
+
return str.slice(1, -1);
|
|
241
|
+
} else {
|
|
242
|
+
return str;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
export {
|
|
246
|
+
checkCommandExistsOrThrow,
|
|
247
|
+
checkIfDirExistsOrThrow,
|
|
248
|
+
checkIfFileExistsOrThrow,
|
|
249
|
+
createTempDir,
|
|
250
|
+
isWindows,
|
|
251
|
+
throwIfDirNotEmpty
|
|
252
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rg-dev/stdlib",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
],
|
|
14
14
|
"typesVersions": {
|
|
15
15
|
"*": {
|
|
16
|
-
"
|
|
16
|
+
"lib/common-env": [
|
|
17
17
|
"lib/common-env.d.ts"
|
|
18
18
|
],
|
|
19
|
-
"
|
|
19
|
+
"lib/node-env": [
|
|
20
20
|
"lib/node-env.d.ts"
|
|
21
21
|
],
|
|
22
|
-
"
|
|
22
|
+
"lib/node-download": [
|
|
23
23
|
"lib/node-download.d.ts"
|
|
24
24
|
]
|
|
25
25
|
}
|