forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
react-native.ts
1247 lines (1233 loc) · 33.2 KB
/
react-native.ts
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const JS_ICON =
"https://raw.githubusercontent.com/vscode-icons/vscode-icons/master/icons/file_type_js.svg";
const GRADLE_ICON =
"https://raw.githubusercontent.com/vscode-icons/vscode-icons/master/icons/file_type_gradle.svg";
const APPLE_ICON =
"https://developer.apple.com/library/archive/Resources/1282/Images/apple2.png";
const ANDROID_ICON = "https://www.android.com/static/images/fav/favicon.ico";
const getJsFilesAndFolders = (paths) => {
const jsAndFolders = paths.filter((file) => {
return file.name.endsWith(".js") || file.name.endsWith("/");
});
return jsAndFolders.map((file) => {
return {
...file,
icon: file.type === "file" ? JS_ICON : file.icon,
};
});
};
const workerGenerator = {
script: "sysctl -n hw.ncpu",
postProcess: (scriptOutput: string) => {
return Array.from({ length: Number(scriptOutput) }, (_x, i) => ({
name: `${i}`,
}));
},
};
const xcodeConfigGenerator = {
script: "xcodebuild -project ios/*.xcodeproj -list -json",
postProcess: (scriptOutput: string) => {
const configurations = JSON.parse(scriptOutput).project.configurations;
return configurations.map((name) => ({ name }));
},
};
const xcodeSchemeGenerator = {
script: "xcodebuild -project ios/*.xcodeproj -list -json",
postProcess: (scriptOutput: string) => {
const configurations = JSON.parse(scriptOutput).project.schemes;
return configurations.map((name) => ({ name }));
},
};
const androidGetDevicesGenerator = {
script: "adb devices",
postProcess: (scriptOutput: string) => {
const devices = scriptOutput
.split("\n")
.filter((item) => !item.match(/^(List)|\*/))
.filter(Boolean)
.filter((item) => item.match(/device$/))
.map((item) => item.split(/device/)[0].trim());
return devices.map((item) => ({
name: item,
icon: ANDROID_ICON,
}));
},
};
type IosRecordType = { name: string };
const iosGetDevicesSimulatorGenerator = {
script: "xcrun simctl list --json devices available",
postProcess: (scriptOutput: string) => {
const devices = JSON.parse(scriptOutput).devices;
return Object.entries(devices)
.map(([_, data]) => data)
.reduce<Array<IosRecordType>>(
(
a: Array<IosRecordType>,
b: Array<IosRecordType>
): Array<IosRecordType> => [...a, ...b],
[]
)
.map(({ name }: IosRecordType) => ({ name, icon: APPLE_ICON }));
},
};
const iosGetDevicesGenerator = {
script: "xcrun xctrace list devices",
postProcess: (scriptOutput: string) => {
const devices = scriptOutput
.split("\n")
.filter((item) => !item.match(/^=/))
.filter(Boolean)
.map((item) => item.split(/\([\w\d\-]+\)$/))
.map(([name]) => ({ name: name.trim() }));
return devices;
},
};
const iosGetDevicesUdidGenerator = {
script: "xcrun xctrace list devices",
postProcess: (scriptOutput: string) => {
const devices = scriptOutput
.split("\n")
.filter((item) => !item.match(/^=/))
.filter(Boolean)
.map((item) => item.split(" "))
.map((items) =>
items[items.length - 1].trim().replace("(", "").replace(")", "")
)
.map((name) => ({ name }));
return devices;
},
};
const gradleTasksGenerator = {
script: "cd android/ && ./gradlew tasks",
postProcess: (scriptOutput: string) => {
const tasks = scriptOutput
.split("\n")
.filter((item) => item.match(/^\w+ \- |\*/))
.map((item) => item.split(" - "))
.map(([name, description]) => ({ name, description }));
return tasks;
},
};
export const completionSpec: Fig.Spec = {
name: "react-native",
description:
"Command line tools that ship with react-native in form of the @react-native-community/cli package",
subcommands: [
{
description:
"[EXPERIMENTAL] Diagnose and fix common Node.js, iOS, Android & React Native issues.",
name: "doctor",
options: [
{
name: ["--fix"],
description: "Attempt to fix all diagnosed issues.",
},
{
name: ["--contributor"],
description:
"Add healthchecks required to installations required for contributing to React Native.",
},
{
name: ["-h", "--help"],
description: "output usage information",
},
],
},
{
description: "builds the javascript bundle for offline use",
name: "bundle",
options: [
{
name: ["--entry-file"],
description:
"Path to the root JS file, either absolute or relative to JS root",
args: [
{
name: "file",
generators: {
template: "filepaths",
filterTemplateSuggestions: getJsFilesAndFolders,
},
},
],
},
{
name: ["--platform"],
description: 'Either "ios" or "android" (default: "ios")',
args: [
{
name: "platform",
suggestions: [
{
name: "android",
icon: ANDROID_ICON,
},
{
name: "ios",
icon: APPLE_ICON,
},
],
},
],
},
{
name: ["--transformer"],
description: "Specify a custom transformer to be used",
args: [
{
name: "transformer",
},
],
},
{
name: ["--dev"],
description:
"If false, warnings are disabled and the bundle is minified (default: true)",
args: [
{
name: "boolean",
isOptional: true,
suggestions: [
{ name: "true", icon: "✅" },
{ name: "false", icon: "❌" },
],
},
],
},
{
name: ["--minify"],
description:
"Allows overriding whether bundle is minified. This defaults to false if dev is true, and true if dev is false. Disabling minification can be useful for speeding up production builds for testing purposes.",
args: [
{
name: "boolean",
isOptional: true,
suggestions: [
{ name: "true", icon: "✅" },
{ name: "false", icon: "❌" },
],
},
],
},
{
name: ["--bundle-output"],
description:
"File name where to store the resulting bundle, ex. /tmp/groups.bundle",
args: [
{
name: "bundle file",
},
],
},
{
name: ["--bundle-encoding"],
description:
'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer). (default: "utf8")',
args: [
{
name: "encoding",
suggestions: [
{
name: "utf8",
},
{
name: "utf16le",
},
{
name: "latin1",
},
],
},
],
},
{
name: ["--max-workers"],
description:
"Specifies the maximum number of workers the worker-pool will spawn for transforming files. This defaults to the number of the cores available on your machine.",
args: [
{
name: "Number of workers",
generators: workerGenerator,
},
],
},
{
name: ["--sourcemap-output"],
description:
"File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map",
args: [
{
name: "sourcemap-output",
},
],
},
{
name: ["--sourcemap-sources-root"],
description:
"Path to make sourcemap's sources entries relative to, ex. /root/dir",
args: [
{
template: "folders",
name: "root",
},
],
},
{
name: ["--sourcemap-use-absolute-path"],
description: "Report SourceMapURL using its full path",
},
{
name: ["--assets-dest"],
description:
"Directory name where to store assets referenced in the bundle",
args: [
{
name: "directory",
template: "folders",
},
],
},
{
name: ["--unstable-transform-profile"],
description:
"Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default",
args: [
{
name: "transform-profile",
suggestions: [
{
name: "hermes",
icon: "https://reactnative.dev/docs/assets/HermesLogo.svg",
},
{
name: "hermes-canary",
icon: "https://reactnative.dev/docs/assets/HermesLogo.svg",
},
{
name: "default",
},
],
},
],
},
{
name: ["--reset-cache"],
description: "Removes cached files",
},
{
name: ["--read-global-cache"],
description:
"Try to fetch transformed JS code from the global cache, if configured.",
},
{
name: ["--config"],
description: "Path to the CLI configuration file",
icon: "🛠",
args: [
{
template: "filepaths",
name: "string",
},
],
},
{
name: ["-h", "--help"],
description: "output usage information",
},
],
},
{
description:
"Initialize a new React Native project named <projectName> in a directory of the same name.",
name: "init",
options: [
{
name: ["--version"],
description: "Shortcut for `--template react-native@version`",
args: [
{
name: "version",
},
],
},
{
name: ["--template"],
description:
"Uses a custom template. Valid arguments are the ones supported by `yarn add [package]` or `npm install [package]`, if you are using `--npm` option",
args: [
{
name: "template",
},
],
},
{
name: ["--npm"],
description: "Forces using npm for initialization",
icon:
"https://img.pngio.com/publishing-to-npm-from-kentcdodds-on-eggheadio-npm-png-800_800.png",
},
{
name: ["--directory"],
description: "Uses a custom directory instead of `<projectName>`.",
args: [
{
template: "folders",
name: "string",
},
],
},
{
name: ["--title"],
description: "Uses a custom app title name for application",
args: [
{
name: "title",
},
],
},
{
name: ["--skip-install"],
description: "Skips dependencies installation step",
icon: "⏭️",
},
{
name: ["-h", "--help"],
description: "output usage information",
},
],
args: [
{
name: "projectName",
},
],
},
{
description: "uninstall and unlink native dependencies",
name: "uninstall",
options: [
{
name: ["-h", "--help"],
description: "output usage information",
},
],
args: [
{
name: "packageName",
},
],
},
{
description: "starts the webserver",
name: "start",
options: [
{
name: ["--port"],
description: "port on which to listen to",
args: [
{
name: "free port",
},
],
},
{
name: ["--host"],
description: "change the default host",
args: [
{
name: "new host",
},
],
},
{
name: ["--projectRoot"],
description: "Path to a custom project root",
args: [
{
name: "path",
template: "folders",
},
],
},
{
name: ["--watchFolders"],
description:
"Specify any additional folders to be added to the watch list",
args: [
{
template: "folders",
name: "folders",
},
],
},
{
name: ["--assetPlugins"],
description:
"Specify any additional asset plugins to be used by the packager by full filepath",
args: [
{
template: "folders",
name: "plugins",
},
],
},
{
name: ["--sourceExts"],
description:
"Specify any additional source extensions to be used by the packager",
args: [
{
name: "sourceExts",
suggestions: [
{
name: "js",
},
{
name: "css",
},
{
name: "png",
},
{
name: "xml",
},
],
},
],
},
{
name: ["--max-workers"],
description:
"Specifies the maximum number of workers the worker-pool will spawn for transforming files. This defaults to the number of the cores available on your machine.",
args: [
{
name: "Number of workers",
generators: workerGenerator,
},
],
},
{
name: ["--transformer"],
description: "Specify a custom transformer to be used",
args: [
{
name: "transformer",
},
],
},
{
name: ["--reset-cache", "--resetCache"],
description: "Removes cached files",
},
{
name: ["--custom-log-reporter-path", "--customLogReporterPath"],
description:
"Path to a JavaScript file that exports a log reporter as a replacement for TerminalReporter",
args: [
{
name: "logFile",
generators: {
template: "filepaths",
filterTemplateSuggestions: getJsFilesAndFolders,
},
},
],
},
{
name: ["--verbose"],
icon: "🔊",
description: "Enables logging",
},
{
name: ["--https"],
icon: "🌐",
description: "Enables https connections to the server",
},
{
name: ["--key"],
description: "Path to custom SSL key",
args: [
{
template: "filepaths",
name: "path",
},
],
},
{
name: ["--cert"],
description: "Path to custom SSL cert",
args: [
{
template: "filepaths",
name: "path",
},
],
},
{
name: ["--config"],
icon: "🛠",
description: "Path to the CLI configuration file",
args: [
{
name: "string",
},
],
},
{
name: ["--no-interactive"],
description: "Disables interactive mode",
},
{
name: ["-h", "--help"],
description: "output usage information",
},
],
},
{
description:
'builds javascript as a "Random Access Module" bundle for offline use',
name: "ram-bundle",
options: [
{
name: ["--entry-file"],
description:
"Path to the root JS file, either absolute or relative to JS root",
args: [
{
name: "file",
generators: {
template: "filepaths",
filterTemplateSuggestions: getJsFilesAndFolders,
},
},
],
},
{
name: ["--platform"],
description: 'Either "ios" or "android" (default: "ios")',
args: [
{
name: "platform",
suggestions: [
{
name: "android",
icon: ANDROID_ICON,
},
{
name: "ios",
icon: APPLE_ICON,
},
],
},
],
},
{
name: ["--transformer"],
description: "Specify a custom transformer to be used",
args: [
{
name: "transformer",
},
],
},
{
name: ["--dev"],
description:
"If false, warnings are disabled and the bundle is minified (default: true)",
args: [
{
name: "boolean",
isOptional: true,
suggestions: [
{ name: "true", icon: "✅" },
{ name: "false", icon: "❌" },
],
},
],
},
{
name: ["--minify"],
description:
"Allows overriding whether bundle is minified. This defaults to false if dev is true, and true if dev is false. Disabling minification can be useful for speeding up production builds for testing purposes.",
args: [
{
name: "boolean",
isOptional: true,
suggestions: [
{ name: "true", icon: "✅" },
{ name: "false", icon: "❌" },
],
},
],
},
{
name: ["--bundle-output"],
description:
"File name where to store the resulting bundle, ex. /tmp/groups.bundle",
args: [
{
name: "output file",
},
],
},
{
name: ["--bundle-encoding"],
description:
'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer). (default: "utf8")',
args: [
{
name: "encoding",
suggestions: [
{
name: "utf8",
},
{
name: "utf16le",
},
{
name: "latin1",
},
],
},
],
},
{
name: ["--max-workers"],
description:
"Specifies the maximum number of workers the worker-pool will spawn for transforming files. This defaults to the number of the cores available on your machine.",
args: [
{
name: "Number of workers",
generators: workerGenerator,
},
],
},
{
name: ["--sourcemap-output"],
description:
"File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map",
args: [
{
name: "sourcemap-output",
},
],
},
{
name: ["--sourcemap-sources-root"],
description:
"Path to make sourcemap's sources entries relative to, ex. /root/dir",
args: [
{
template: "folders",
name: "root",
},
],
},
{
name: ["--sourcemap-use-absolute-path"],
description: "Report SourceMapURL using its full path",
},
{
name: ["--assets-dest"],
description:
"Directory name where to store assets referenced in the bundle",
args: [
{
name: "directory",
template: "folders",
},
],
},
{
name: ["--unstable-transform-profile"],
description:
"Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default",
args: [
{
name: "transform-profile",
suggestions: [
{
name: "hermes",
icon: "https://reactnative.dev/docs/assets/HermesLogo.svg",
},
{
name: "hermes-canary",
icon: "https://reactnative.dev/docs/assets/HermesLogo.svg",
},
{
name: "default",
},
],
},
],
},
{
name: ["--reset-cache"],
description: "Removes cached files",
},
{
name: ["--read-global-cache"],
description:
"Try to fetch transformed JS code from the global cache, if configured.",
},
{
name: ["--config"],
icon: "🛠",
description: "Path to the CLI configuration file",
args: [
{
name: "string",
},
],
},
{
name: ["--indexed-ram-bundle"],
description:
'Force the "Indexed RAM" bundle file format, even when building for android',
},
{
name: ["-h", "--help"],
description: "output usage information",
},
],
},
{
description: "links assets and optionally native modules",
name: "link",
options: [
{
name: ["--platforms"],
description: "Scope linking to specified platforms",
args: [
{
name: "list",
isOptional: true,
},
],
},
{
name: ["--all"],
description: "Link all native modules and assets",
},
{
name: ["-h", "--help"],
description: "output usage information",
},
],
args: [
{
name: "packageName",
isOptional: true,
},
],
},
{
description:
"Upgrade your app's template files to the specified or latest npm version using `rn-diff-purge` project. Only valid semver versions are allowed.",
name: "upgrade",
options: [
{
name: ["-h", "--help"],
description: "output usage information",
},
],
args: [
{
name: "version",
isOptional: true,
},
],
},
{
description:
"Get relevant version info about OS, toolchain and libraries",
name: "info",
options: [
{
name: ["-h", "--help"],
description: "output usage information",
},
],
},
{
description: "install and link native dependencies",
name: "install",
options: [
{
name: ["-h", "--help"],
description: "output usage information",
},
],
args: [
{
name: "packageName",
},
],
},
{
description: "Print CLI configuration",
icon: "🛠",
name: "config",
options: [
{
name: ["-h", "--help"],
description: "output usage information",
},
],
},
{
description: "unlink native dependency",
name: "unlink",
options: [
{
name: ["--platforms"],
description: "Scope unlinking to specified platforms",
args: [
{
name: "list",
isOptional: true,
},
],
},
{
name: ["-h", "--help"],
description: "output usage information",
},
],
args: [
{
name: "packageName",
},
],
},
{
description: "starts iOS device syslog tail",
name: "log-ios",
options: [
{
name: ["-h", "--help"],
description: "output usage information",
},
],
},
{
description:
"Pull and convert a Hermes tracing profile to Chrome tracing profile, then store it in the directory <destinationDir> of the local machine",
name: "profile-hermes",
options: [
{
name: ["--filename"],
description:
"File name of the profile to be downloaded, eg. sampling-profiler-trace8593107139682635366.cpuprofile",
args: [
{
template: "filepaths",
name: "profile",
},
],
},
{
name: ["--raw"],
description:
"Pulls the original Hermes tracing profile without any transformation",
},
{
name: ["--sourcemap-path"],
description:
"The local path to your source map file, eg. /tmp/sourcemap.json",
args: [
{
name: "sourcemap-path",
template: "filepaths",
},
],
},
{
name: ["--generate-sourcemap"],
description: "Generates the JS bundle and source map",
},
{
name: ["--port"],
description: 'default: "8081"',
args: [
{
name: "free port",
},
],
},
{
name: ["-h", "--help"],
description: "output usage information",
},
],
args: [
{
name: "destinationDir",
template: "folders",
isOptional: true,
},
],
},
{
description: "starts logkitty",
name: "log-android",
options: [
{
name: ["-h", "--help"],
description: "output usage information",
},
],
},
{
description:
"builds your app and starts it on a connected Android emulator or device",
name: "run-android",
options: [
{
name: ["--root"],