1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.removeExtension = exports.fileExistsAsync = exports.readJsonFromDiskAsync = exports.readJsonFromDiskSync = exports.fileExistsSync = void 0;
|
4 | var fs = require("fs");
|
5 | function fileExistsSync(path) {
|
6 |
|
7 | if (!fs.existsSync(path)) {
|
8 | return false;
|
9 | }
|
10 | try {
|
11 | var stats = fs.statSync(path);
|
12 | return stats.isFile();
|
13 | }
|
14 | catch (err) {
|
15 |
|
16 | return false;
|
17 | }
|
18 | }
|
19 | exports.fileExistsSync = fileExistsSync;
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function readJsonFromDiskSync(packageJsonPath) {
|
27 | if (!fs.existsSync(packageJsonPath)) {
|
28 | return undefined;
|
29 | }
|
30 |
|
31 | return require(packageJsonPath);
|
32 | }
|
33 | exports.readJsonFromDiskSync = readJsonFromDiskSync;
|
34 | function readJsonFromDiskAsync(path,
|
35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
36 | callback) {
|
37 | fs.readFile(path, "utf8", function (err, result) {
|
38 |
|
39 | if (err || !result) {
|
40 | return callback();
|
41 | }
|
42 | var json = JSON.parse(result);
|
43 | return callback(undefined, json);
|
44 | });
|
45 | }
|
46 | exports.readJsonFromDiskAsync = readJsonFromDiskAsync;
|
47 | function fileExistsAsync(path2, callback2) {
|
48 | fs.stat(path2, function (err, stats) {
|
49 | if (err) {
|
50 |
|
51 | return callback2(undefined, false);
|
52 | }
|
53 | callback2(undefined, stats ? stats.isFile() : false);
|
54 | });
|
55 | }
|
56 | exports.fileExistsAsync = fileExistsAsync;
|
57 | function removeExtension(path) {
|
58 | return path.substring(0, path.lastIndexOf(".")) || path;
|
59 | }
|
60 | exports.removeExtension = removeExtension;
|
61 |
|
\ | No newline at end of file |