forked from microsoft/react-native-test-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-native.config.js
More file actions
110 lines (104 loc) · 2.66 KB
/
react-native.config.js
File metadata and controls
110 lines (104 loc) · 2.66 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
// @ts-check
"use strict";
const {
findNearest,
getPackageVersion,
readJSONFile,
} = require("./scripts/helpers");
/**
* @template Args
* @typedef {{
* name: string,
* description?: string,
* examples?: Array<{
* desc: string;
* cmd: string;
* }>,
* func: (argv: Array<string>, config: {}, args: Args) => void | Promise<void>,
* options?: Array<{
* name: string;
* description?: string;
* parse?: (val: string) => any;
* default?: string | number | boolean;
* }>,
* }} Command;
*/
/**
* Infers project name by finding and parsing the nearest `package.json`.
* @returns {string | undefined}
*/
function inferProjectName() {
const packageJson = findNearest("package.json");
if (packageJson) {
try {
const name = readJSONFile(packageJson)["name"];
return typeof name === "string" && name ? `${name}-test-app` : undefined;
} catch (_) {
// Ignore
}
}
return undefined;
}
/**
* @param {string} choice
* @returns {import("./scripts/configure").Platform[]}
*/
function sanitizePlatformChoice(choice) {
switch (choice) {
case "all":
return ["android", "ios", "macos", "windows"];
case "android":
case "ios":
case "macos":
case "windows":
return [choice];
default:
throw new Error(`Unknown platform: ${choice}`);
}
}
/** @type {{ commands: Command<{ destination: string; name: string; platform: string; }>[] }} */
module.exports = {
commands: [
{
name: "init-test-app",
description: "Initializes a new test app project",
func: (_argv, _config, { destination, name, platform }) => {
const { configure } = require("./scripts/configure");
configure({
name,
packagePath: destination,
testAppPath: __dirname,
targetVersion: getPackageVersion("react-native"),
platforms: sanitizePlatformChoice(platform),
flatten: true,
force: true,
init: true,
});
},
options: [
{
name: "--destination [string]",
description:
"Path to the directory where the test app should be created",
default: require("path").join(process.cwd(), "test-app"),
},
{
name: "--name [string]",
description: "Display name of the test app",
default: inferProjectName() || "ReactTestApp",
},
{
name: "--platform [string]",
description:
"Specific platform to support: all, android, ios, macos, windows",
default: "all",
},
],
},
],
dependency: {
platforms: {
windows: null,
},
},
};