-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathreact-native.js
93 lines (88 loc) · 3.18 KB
/
react-native.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
const addOptionalRules = require("./helpers/addOptionalRules");
const getAndroidEnvData = require("./helpers/getAndroidEnvData");
module.exports = context => {
// Register this plugin
context.addPlugin({
name: "React Native",
description: "Snapshot solidarity rules for React Native projects",
snapshot: async context => {
// start with template
let solidarity = require("../templates/react-native-template.json");
// add optional rules
addOptionalRules(context, solidarity.requirements);
// write out .solidarity file
context.solidarity.setSolidaritySettings(solidarity, context);
// update file with local versions
await context.system.run("solidarity snapshot");
},
rules: {
androidVersion: {
check: async (rule, context) => {
const {
androidAppGradle,
availableApiVersions,
availableBuildToolsVersions,
projectApiVersion,
projectBuildToolsVersion
} = await getAndroidEnvData(context);
if (androidAppGradle) {
const buildGood = availableBuildToolsVersions.includes(
projectBuildToolsVersion
);
const apiGood = availableApiVersions.includes(projectApiVersion);
if (buildGood && apiGood) {
return {
pass: true,
message: `Android API ${projectApiVersion} & Build Tools ${projectBuildToolsVersion}`
};
} else {
let failMessages = [];
if (!buildGood)
failMessages.push(
`Build Tool ${projectBuildToolsVersion} Not Found`
);
if (!apiGood)
failMessages.push(`API ${projectApiVersion} Not Found`);
return {
pass: false,
message: failMessages.join(" & ")
};
}
} else {
return {
pass: false,
message: "./android/app/build.gradle not found"
};
}
},
report: async (rule, context, report) => {
const { print } = context;
const { colors } = print;
const {
availableApiVersions,
availableBuildToolsVersions,
projectApiVersion,
projectBuildToolsVersion
} = await getAndroidEnvData(context);
const projectAPIMessage = availableApiVersions.includes(
projectApiVersion
)
? colors.green(`API ${projectApiVersion} Available`)
: colors.red(`API ${projectApiVersion} Unavailable`);
const projectBuildToolsMessage = availableBuildToolsVersions.includes(
projectBuildToolsVersion
)
? colors.green(`Build Tools ${projectBuildToolsVersion} Available`)
: colors.red(`Build Tools ${projectBuildToolsVersion} Unavailable`);
report.customRules.push({
title: "Android SDK",
table: [
["Project API Version", "Project Build Tools"],
[projectAPIMessage, projectBuildToolsMessage]
]
});
}
}
}
});
};