-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.mjs
More file actions
138 lines (129 loc) · 3.23 KB
/
utils.mjs
File metadata and controls
138 lines (129 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { join, basename } from "node:path";
import { readdirSync, statSync } from "node:fs";
import { spawnSync } from "node:child_process";
const IGNORE_DIRS = process.env.ASTGEN_IGNORE_DIRS
? process.env.ASTGEN_IGNORE_DIRS.split(",")
: [
"venv",
"docs",
"e2e",
"e2e-beta",
"examples",
"cypress",
"jest-cache",
"eslint-rules",
"codemods",
"flow-typed",
"i18n"
];
const IGNORE_FILE_PATTERN = new RegExp(
process.env.ASTGEN_IGNORE_FILE_PATTERN || "(three|\\.d)\\.(js|ts|jsx|tsx)$",
"i"
);
export const getAllFiles = (
dir,
extn,
files,
result,
regex,
ignore_node_modules = true
) => {
files = files || readdirSync(dir);
result = result || [];
regex = regex || new RegExp(`\\${extn}$`);
for (let i = 0; i < files.length; i++) {
const file = files[i];
if (
(ignore_node_modules && file.startsWith(".")) ||
IGNORE_FILE_PATTERN.test(file)
) {
continue;
}
const fileWithDir = join(dir, file);
if (statSync(fileWithDir).isDirectory()) {
// Ignore directories
const dirName = basename(fileWithDir);
if (
(ignore_node_modules && dirName.startsWith(".")) ||
IGNORE_DIRS.includes(dirName.toLowerCase()) ||
(ignore_node_modules && dirName.toLowerCase() === "node_modules")
) {
continue;
}
try {
result = getAllFiles(
fileWithDir,
extn,
readdirSync(fileWithDir),
result,
regex,
ignore_node_modules
);
} catch (error) {
// ignore
}
} else {
if (
regex.test(fileWithDir) ||
(extn &&
!extn.includes(".") &&
fileWithDir.toLowerCase().endsWith(extn.toLowerCase()))
) {
result.push(fileWithDir);
}
}
}
return result;
};
export const detectJava = () => {
let result = spawnSync(process.env.JAVA_CMD || "java", ["-version"], {
encoding: "utf-8"
});
if (result.status !== 0 || result.error) {
return false;
}
return true;
};
export const detectPhp = () => {
let result = spawnSync(process.env.PHP_CMD || "php", ["--version"], {
encoding: "utf-8"
});
if (result.status !== 0 || result.error) {
return false;
}
return true;
};
export const detectRuby = (versionNeeded) => {
let result = spawnSync(process.env.RUBY_CMD || "ruby", ["--version"], {
encoding: "utf-8"
});
if (result.status !== 0 || result.error) {
return false;
}
const stdout = result.stdout;
if (versionNeeded && stdout) {
versionNeeded = versionNeeded.replaceAll(".x", ".");
const cmdOutput = Buffer.from(stdout).toString();
const versionStr = cmdOutput.trim().replaceAll("\r", "");
return versionStr.startsWith(`ruby ${versionNeeded}`);
}
return true;
};
export const detectScala = () => {
let result = spawnSync(process.env.SCALA_CMD || "scala", ["--version"], {
encoding: "utf-8"
});
if (result.status !== 0 || result.error) {
return false;
}
return true;
};
export const detectScalac = () => {
let result = spawnSync(process.env.SCALAC_CMD || "scalac", ["--version"], {
encoding: "utf-8"
});
if (result.status !== 0 || result.error) {
return false;
}
return true;
};