@react-native-community/cli-config 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/build/assign.d.ts +9 -0
  2. package/build/assign.d.ts.map +1 -0
  3. package/build/assign.js +39 -0
  4. package/build/assign.js.map +1 -0
  5. package/build/commands/config.d.ts +8 -0
  6. package/build/commands/config.d.ts.map +1 -0
  7. package/build/commands/config.js +32 -0
  8. package/build/commands/config.js.map +1 -0
  9. package/build/errors.d.ts +6 -0
  10. package/build/errors.d.ts.map +1 -0
  11. package/build/errors.js +49 -0
  12. package/build/errors.js.map +1 -0
  13. package/build/findAssets.d.ts +8 -0
  14. package/build/findAssets.d.ts.map +1 -0
  15. package/build/findAssets.js +53 -0
  16. package/build/findAssets.js.map +1 -0
  17. package/build/findDependencies.d.ts +5 -0
  18. package/build/findDependencies.d.ts.map +1 -0
  19. package/build/findDependencies.js +46 -0
  20. package/build/findDependencies.js.map +1 -0
  21. package/build/index.d.ts +7 -0
  22. package/build/index.d.ts.map +1 -0
  23. package/build/index.js +23 -0
  24. package/build/index.js.map +1 -0
  25. package/build/loadConfig.d.ts +7 -0
  26. package/build/loadConfig.d.ts.map +1 -0
  27. package/build/loadConfig.js +149 -0
  28. package/build/loadConfig.js.map +1 -0
  29. package/build/merge.d.ts +6 -0
  30. package/build/merge.d.ts.map +1 -0
  31. package/build/merge.js +30 -0
  32. package/build/merge.js.map +1 -0
  33. package/build/readConfigFromDisk.d.ts +12 -0
  34. package/build/readConfigFromDisk.d.ts.map +1 -0
  35. package/build/readConfigFromDisk.js +86 -0
  36. package/build/readConfigFromDisk.js.map +1 -0
  37. package/build/resolveReactNativePath.d.ts +6 -0
  38. package/build/resolveReactNativePath.d.ts.map +1 -0
  39. package/build/resolveReactNativePath.js +39 -0
  40. package/build/resolveReactNativePath.js.map +1 -0
  41. package/build/schema.d.ts +10 -0
  42. package/build/schema.d.ts.map +1 -0
  43. package/build/schema.js +177 -0
  44. package/build/schema.js.map +1 -0
  45. package/package.json +33 -0
  46. package/src/__tests__/__snapshots__/index-test.ts.snap +185 -0
  47. package/src/__tests__/findAssets-test.ts +51 -0
  48. package/src/__tests__/findDependencies-test.ts +23 -0
  49. package/src/__tests__/index-test.ts +350 -0
  50. package/src/assign.ts +27 -0
  51. package/src/commands/config.ts +30 -0
  52. package/src/errors.ts +31 -0
  53. package/src/findAssets.ts +28 -0
  54. package/src/findDependencies.ts +24 -0
  55. package/src/index.ts +5 -0
  56. package/src/loadConfig.ts +157 -0
  57. package/src/merge.ts +12 -0
  58. package/src/readConfigFromDisk.ts +68 -0
  59. package/src/resolveReactNativePath.ts +25 -0
  60. package/src/schema.ts +201 -0
  61. package/tsconfig.json +8 -0
  62. package/tsconfig.tsbuildinfo +1957 -0
@@ -0,0 +1,68 @@
1
+ import cosmiconfig from 'cosmiconfig';
2
+ import {JoiError} from './errors';
3
+ import * as schema from './schema';
4
+ import {
5
+ UserConfig,
6
+ UserDependencyConfig,
7
+ } from '@react-native-community/cli-types';
8
+
9
+ /**
10
+ * Places to look for the configuration file.
11
+ */
12
+ const searchPlaces = ['react-native.config.js'];
13
+
14
+ /**
15
+ * Reads a project configuration as defined by the user in the current
16
+ * workspace.
17
+ */
18
+ export function readConfigFromDisk(rootFolder: string): UserConfig {
19
+ const explorer = cosmiconfig('react-native', {
20
+ searchPlaces,
21
+ stopDir: rootFolder,
22
+ });
23
+
24
+ const searchResult = explorer.searchSync(rootFolder);
25
+ const config = searchResult ? searchResult.config : undefined;
26
+ const result = schema.projectConfig.validate(config);
27
+
28
+ if (result.error) {
29
+ throw new JoiError(result.error);
30
+ }
31
+
32
+ return result.value as UserConfig;
33
+ }
34
+
35
+ /**
36
+ * Reads a dependency configuration as defined by the developer
37
+ * inside `node_modules`.
38
+ */
39
+ export function readDependencyConfigFromDisk(
40
+ rootFolder: string,
41
+ ): UserDependencyConfig {
42
+ const explorer = cosmiconfig('react-native', {
43
+ stopDir: rootFolder,
44
+ searchPlaces,
45
+ });
46
+
47
+ const searchResult = explorer.searchSync(rootFolder);
48
+ const config = searchResult ? searchResult.config : emptyDependencyConfig;
49
+
50
+ const result = schema.dependencyConfig.validate(config);
51
+
52
+ if (result.error) {
53
+ throw new JoiError(result.error);
54
+ }
55
+
56
+ return result.value as UserDependencyConfig;
57
+ }
58
+
59
+ const emptyDependencyConfig = {
60
+ dependency: {
61
+ platforms: {},
62
+ assets: [],
63
+ hooks: {},
64
+ params: [],
65
+ },
66
+ commands: [],
67
+ platforms: {},
68
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ CLIError,
3
+ resolveNodeModuleDir,
4
+ } from '@react-native-community/cli-tools';
5
+
6
+ /**
7
+ * Finds path to React Native inside `node_modules` or throws
8
+ * an error otherwise.
9
+ */
10
+ export default function resolveReactNativePath(root: string) {
11
+ try {
12
+ return resolveNodeModuleDir(root, 'react-native');
13
+ } catch (_ignored) {
14
+ throw new CLIError(`
15
+ Unable to find React Native files looking up from ${root}. Make sure "react-native" module is installed
16
+ in your project dependencies.
17
+
18
+ If you are using React Native from a non-standard location, consider setting:
19
+ {
20
+ reactNativePath: "./path/to/react-native"
21
+ }
22
+ in your \`react-native.config.js\`.
23
+ `);
24
+ }
25
+ }
package/src/schema.ts ADDED
@@ -0,0 +1,201 @@
1
+ import t, {SchemaLike} from 'joi';
2
+
3
+ const map = (key: RegExp | SchemaLike, value: SchemaLike) =>
4
+ t.object().unknown(true).pattern(key, value);
5
+
6
+ /**
7
+ * Schema for CommandT
8
+ */
9
+ const command = t.object({
10
+ name: t.string().required(),
11
+ description: t.string(),
12
+ usage: t.string(),
13
+ func: t.func().required(),
14
+ options: t.array().items(
15
+ t
16
+ .object({
17
+ name: t.string().required(),
18
+ description: t.string(),
19
+ parse: t.func(),
20
+ default: t
21
+ .alternatives()
22
+ .try(t.bool(), t.number(), t.string().allow(''), t.func()),
23
+ })
24
+ .rename('command', 'name', {ignoreUndefined: true}),
25
+ ),
26
+ examples: t.array().items(
27
+ t.object({
28
+ desc: t.string().required(),
29
+ cmd: t.string().required(),
30
+ }),
31
+ ),
32
+ });
33
+
34
+ /**
35
+ * Schema for HealthChecksT
36
+ */
37
+ const healthCheck = t.object({
38
+ label: t.string().required(),
39
+ healthchecks: t.array().items(
40
+ t.object({
41
+ label: t.string().required(),
42
+ isRequired: t.bool(),
43
+ description: t.string(),
44
+ getDiagnostics: t.func(),
45
+ win32AutomaticFix: t.func(),
46
+ darwinAutomaticFix: t.func(),
47
+ linuxAutomaticFix: t.func(),
48
+ runAutomaticFix: t.func().required(),
49
+ }),
50
+ ),
51
+ });
52
+
53
+ /**
54
+ * Schema for UserDependencyConfigT
55
+ */
56
+ export const dependencyConfig = t
57
+ .object({
58
+ dependency: t
59
+ .object({
60
+ platforms: map(t.string(), t.any())
61
+ .keys({
62
+ ios: t
63
+ .object({
64
+ project: t.string(),
65
+ podspecPath: t.string(),
66
+ sharedLibraries: t.array().items(t.string()),
67
+ libraryFolder: t.string(),
68
+ scriptPhases: t.array().items(t.object()),
69
+ configurations: t.array().items(t.string()).default([]),
70
+ })
71
+ .default({}),
72
+ android: t
73
+ .object({
74
+ sourceDir: t.string(),
75
+ manifestPath: t.string(),
76
+ packageImportPath: t.string(),
77
+ packageInstance: t.string(),
78
+ dependencyConfiguration: t.string(),
79
+ buildTypes: t.array().items(t.string()).default([]),
80
+ })
81
+ .default({}),
82
+ })
83
+ .default(),
84
+ assets: t.array().items(t.string()).default([]),
85
+ hooks: map(t.string(), t.string()).default({}),
86
+ params: t
87
+ .array()
88
+ .items(
89
+ t.object({
90
+ name: t.string(),
91
+ type: t.string(),
92
+ message: t.string(),
93
+ }),
94
+ )
95
+ .default([]),
96
+ })
97
+ .default(),
98
+ platforms: map(
99
+ t.string(),
100
+ t.object({
101
+ npmPackageName: t.string().optional(),
102
+ dependencyConfig: t.func(),
103
+ projectConfig: t.func(),
104
+ linkConfig: t.func(),
105
+ }),
106
+ ).default({}),
107
+ commands: t.array().items(command).default([]),
108
+ healthChecks: t.array().items(healthCheck).default([]),
109
+ })
110
+ .unknown(true)
111
+ .default();
112
+
113
+ /**
114
+ * Schema for ProjectConfigT
115
+ */
116
+ export const projectConfig = t
117
+ .object({
118
+ dependencies: map(
119
+ t.string(),
120
+ t
121
+ .object({
122
+ root: t.string(),
123
+ platforms: map(t.string(), t.any()).keys({
124
+ ios: t
125
+ .object({
126
+ sourceDir: t.string(),
127
+ folder: t.string(),
128
+ pbxprojPath: t.string(),
129
+ podfile: t.string(),
130
+ podspecPath: t.string(),
131
+ projectPath: t.string(),
132
+ projectName: t.string(),
133
+ libraryFolder: t.string(),
134
+ sharedLibraries: t.array().items(t.string()),
135
+ configurations: t.array().items(t.string()).default([]),
136
+ })
137
+ .allow(null),
138
+ android: t
139
+ .object({
140
+ sourceDir: t.string(),
141
+ folder: t.string(),
142
+ packageImportPath: t.string(),
143
+ packageInstance: t.string(),
144
+ dependencyConfiguration: t.string(),
145
+ buildTypes: t.array().items(t.string()).default([]),
146
+ })
147
+ .allow(null),
148
+ }),
149
+ assets: t.array().items(t.string()),
150
+ hooks: map(t.string(), t.string()),
151
+ params: t.array().items(
152
+ t.object({
153
+ name: t.string(),
154
+ type: t.string(),
155
+ message: t.string(),
156
+ }),
157
+ ),
158
+ })
159
+ .allow(null),
160
+ ).default({}),
161
+ reactNativePath: t.string(),
162
+ project: map(t.string(), t.any())
163
+ .keys({
164
+ ios: t
165
+ .object({
166
+ project: t.string(),
167
+ sharedLibraries: t.array().items(t.string()),
168
+ libraryFolder: t.string(),
169
+ })
170
+ .default({}),
171
+ android: t
172
+ .object({
173
+ sourceDir: t.string(),
174
+ manifestPath: t.string(),
175
+ packageName: t.string(),
176
+ packageFolder: t.string(),
177
+ mainFilePath: t.string(),
178
+ stringsPath: t.string(),
179
+ settingsGradlePath: t.string(),
180
+ assetsPath: t.string(),
181
+ buildGradlePath: t.string(),
182
+ appName: t.string(),
183
+ dependencyConfiguration: t.string(),
184
+ })
185
+ .default({}),
186
+ })
187
+ .default(),
188
+ assets: t.array().items(t.string()).default([]),
189
+ commands: t.array().items(command).default([]),
190
+ platforms: map(
191
+ t.string(),
192
+ t.object({
193
+ npmPackageName: t.string().optional(),
194
+ dependencyConfig: t.func(),
195
+ projectConfig: t.func(),
196
+ linkConfig: t.func(),
197
+ }),
198
+ ).default({}),
199
+ })
200
+ .unknown(true)
201
+ .default();
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "build"
6
+ },
7
+ "references": [{"path": "../tools"}, {"path": "../cli-types"}]
8
+ }