-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
99 lines (87 loc) · 2.08 KB
/
helpers.js
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
import { promises as fs, readFileSync } from "fs";
import { exec } from "child_process";
import chalk from "chalk";
const doesFileExist = async (filePath) => {
try {
await fs.access(filePath);
return true; // Exists
} catch (error) {
return false; // Doesn't exist
}
};
const iFileNameValid = (string) => {
return /^[A-Za-z][A-Za-z0-9-]*$/.test(string);
};
const consoleDone = () => {
console.log(chalk`
{rgb(0, 255, 251) Done!}`);
};
const consoleDryRunMessage = () => {
console.log(
chalk`
{rgb(255, 225, 0) Command executed with dry-run enabled; no files were created}`
);
};
const consoleCreate = (filename) => {
console.log(chalk`{rgb(0, 255, 179) Create:} ${filename}`);
};
const consoleUpdate = (filename) => {
console.log(chalk`{rgb(0, 166, 255) Update:} ${filename}`);
};
const consoleError = (message) => {
console.log(chalk`{rgb(255, 55, 0) Error:} ${message}`);
};
const consoleNote = (message) => {
console.log(chalk`{rgb(255, 225, 0) Note:} ${message}`);
};
function getReactNativeVersion() {
try {
const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
return (
packageJson.dependencies["react-native"] ||
packageJson.devDependencies["react-native"]
);
} catch {
return null;
}
}
function getReactVersion() {
try {
const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
return (
packageJson.dependencies["react"] || packageJson.devDependencies["react"]
);
} catch {
return null;
}
}
function getPeerDependencies(callback) {
exec(
"npm info @testing-library/react-native peerDependencies --json",
(error, stdout) => {
if (error) {
callback(null);
return;
}
try {
const peerDeps = JSON.parse(stdout);
callback(peerDeps);
} catch (parseError) {
callback(null);
}
}
);
}
export {
doesFileExist,
consoleDone,
consoleCreate,
iFileNameValid,
consoleError,
consoleDryRunMessage,
consoleUpdate,
consoleNote,
getReactNativeVersion,
getReactVersion,
getPeerDependencies,
};