-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathtest-app.js
executable file
·850 lines (793 loc) · 24.6 KB
/
test-app.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
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
#!/usr/bin/env node
// @ts-check
"use strict";
const fs = require("fs");
const os = require("os");
const path = require("path");
const uuidv5 = (() => {
try {
// @ts-ignore [email protected]
return require("uuid/v5");
} catch (_) {
// [email protected] and above
const { v5 } = require("uuid");
return v5;
}
})();
/**
* @typedef {{
* assetItems: string[];
* assetItemFilters: string[];
* assetFilters: string[];
* }} AssetItems;
*
* @typedef {{
* assetItems: string;
* assetItemFilters: string;
* assetFilters: string;
* }} Assets;
*/
const templateView = {
name: "ReactTestApp",
projectGuidUpper: "{B44CEAD7-FBFF-4A17-95EA-FF5434BBD79D}",
useExperimentalNuget: false,
};
const uniqueFilterIdentifier = "e48dc53e-40b1-40cb-970a-f89935452892";
/** @type {{ recursive: true, mode: 0o755 }} */
const mkdirRecursiveOptions = { recursive: true, mode: 0o755 };
/** @type {{ encoding: "utf-8" }} */
const textFileReadOptions = { encoding: "utf-8" };
/** @type {{ encoding: "utf-8", mode: 0o644 }} */
const textFileWriteOptions = { encoding: "utf-8", mode: 0o644 };
/**
* Copies the specified directory.
* @param {string} src
* @param {string} dest
*/
function copy(src, dest) {
fs.mkdir(dest, mkdirRecursiveOptions, (err) => {
rethrow(err);
fs.readdir(src, { withFileTypes: true }, (err, files) => {
rethrow(err);
files.forEach((file) => {
const source = path.join(src, file.name);
const target = path.join(dest, file.name);
file.isDirectory()
? copy(source, target)
: fs.copyFile(source, target, rethrow);
});
});
});
}
/**
* Finds nearest relative path to a file or directory from current path.
* @param {string} fileOrDirName Path to the file or directory to find.
* @param {string=} currentDir The current working directory. Mostly used for unit tests.
* @returns {string | null} Nearest path to given file or directory; null if not found
*/
function findNearest(fileOrDirName, currentDir = path.resolve("")) {
const rootDirectory =
process.platform === "win32"
? currentDir.split(path.sep)[0] + path.sep
: "/";
while (currentDir !== rootDirectory) {
const candidatePath = path.join(currentDir, fileOrDirName);
if (fs.existsSync(candidatePath)) {
return path.relative("", candidatePath);
}
// Get parent folder
currentDir = path.dirname(currentDir);
}
return null;
}
/**
* Finds all Visual Studio projects in specified directory.
* @param {string} projectDir
* @param {{ path: string; name: string; guid: string; }[]=} projects
* @returns {{ path: string; name: string; guid: string; }[]}
*/
function findUserProjects(projectDir, projects = []) {
return fs.readdirSync(projectDir).reduce((projects, file) => {
const fullPath = path.join(projectDir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
if (!["android", "ios", "macos", "node_modules"].includes(file)) {
findUserProjects(fullPath, projects);
}
} else if (fullPath.endsWith(".vcxproj")) {
const vcxproj = fs.readFileSync(fullPath, textFileReadOptions);
const guidMatch = vcxproj.match(
/<ProjectGuid>({[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}})<\/ProjectGuid>/
);
if (guidMatch) {
const projectNameMatch = vcxproj.match(
/<ProjectName>(.*?)<\/ProjectName>/
);
projects.push({
path: fullPath,
name: projectNameMatch
? projectNameMatch[1]
: path.basename(file, ".vcxproj"),
guid: guidMatch[1],
});
}
}
return projects;
}, projects);
}
/**
* Returns whether specified object is Error-like.
* @param {unknown} e
* @returns {e is Error}
*/
function isErrorLike(e) {
return typeof e === "object" && e !== null && "name" in e && "message" in e;
}
/**
* Normalizes specified path.
* @param {string} p
* @returns {string}
*/
function normalizePath(p) {
return p.replace(/[/\\]+/g, "\\");
}
/**
* Returns a NuGet package entry for specified package id and version.
* @param {string} id NuGet package id
* @param {string} version NuGet package version
* @returns {string}
*/
function nuGetPackage(id, version) {
return `<package id="${id}" version="${version}" targetFramework="native"/>`;
}
/**
* @param {{
* certificateKeyFile?: string;
* certificateThumbprint?: string;
* certificatePassword?: string;
* }} certificate
* @param {string} projectPath
* @returns {string}
*/
function generateCertificateItems(
{ certificateKeyFile, certificateThumbprint, certificatePassword },
projectPath
) {
const items = [];
if (typeof certificateKeyFile === "string") {
items.push(
"<AppxPackageSigningEnabled>true</AppxPackageSigningEnabled>",
`<PackageCertificateKeyFile>$(ProjectRootDir)\\${projectRelativePath(
projectPath,
certificateKeyFile
)}</PackageCertificateKeyFile>`
);
}
if (typeof certificateThumbprint === "string") {
items.push(
`<PackageCertificateThumbprint>${certificateThumbprint}</PackageCertificateThumbprint>`
);
}
if (typeof certificatePassword === "string") {
items.push(
`<PackageCertificatePassword>${certificatePassword}</PackageCertificatePassword>`
);
}
return items.join("\n ");
}
/**
* @param {string[]} resources
* @param {string} projectPath
* @param {AssetItems} assets
* @param {string} currentFilter
* @param {string} source
* @returns {AssetItems}
*/
function generateContentItems(
resources,
projectPath,
assets = { assetFilters: [], assetItemFilters: [], assetItems: [] },
currentFilter = "Assets",
source = ""
) {
const { assetFilters, assetItemFilters, assetItems } = assets;
for (const resource of resources) {
if (path.basename(resource) === "app.json") {
// `app.json` is always included
continue;
}
const resourcePath = path.isAbsolute(resource)
? path.relative(projectPath, resource)
: resource;
if (!fs.existsSync(resourcePath)) {
console.warn(`warning: resource with path '${resource}' was not found`);
continue;
}
if (fs.statSync(resourcePath).isDirectory()) {
const filter =
"Assets\\" +
normalizePath(
source ? path.relative(source, resource) : path.basename(resource)
);
const id = uuidv5(filter, uniqueFilterIdentifier);
assetFilters.push(
`<Filter Include="${filter}">`,
` <UniqueIdentifier>{${id}}</UniqueIdentifier>`,
`</Filter>`
);
const files = fs
.readdirSync(resourcePath)
.map((file) => path.join(resource, file));
generateContentItems(
files,
projectPath,
assets,
filter,
source || path.dirname(resource)
);
} else {
const assetPath = normalizePath(path.relative(projectPath, resourcePath));
/**
* When a resources folder is included in the manifest, the directory
* structure within the folder must be maintained. For example, given
* `dist/assets`, we must output:
*
* `<DestinationFolders>$(OutDir)\\Bundle\\assets\\...</DestinationFolders>`
* `<DestinationFolders>$(OutDir)\\Bundle\\assets\\node_modules\\...</DestinationFolders>`
* ...
*
* Resource paths are always prefixed with `$(OutDir)\\Bundle`.
*/
const destination =
source &&
`\\${normalizePath(path.relative(source, path.dirname(resource)))}`;
assetItems.push(
`<CopyFileToFolders Include="$(ProjectRootDir)\\${assetPath}">`,
` <DestinationFolders>$(OutDir)\\Bundle${destination}</DestinationFolders>`,
"</CopyFileToFolders>"
);
assetItemFilters.push(
`<CopyFileToFolders Include="$(ProjectRootDir)\\${assetPath}">`,
` <Filter>${currentFilter}</Filter>`,
"</CopyFileToFolders>"
);
}
}
return assets;
}
/**
* @param {string[] | { windows?: string[] } | undefined} resources
* @param {string} projectPath
* @param {string} vcxProjectPath
* @returns {Assets}
*/
function parseResources(resources, projectPath, vcxProjectPath) {
if (!Array.isArray(resources)) {
if (resources && resources.windows) {
return parseResources(resources.windows, projectPath, vcxProjectPath);
}
return { assetItems: "", assetItemFilters: "", assetFilters: "" };
}
const { assetItems, assetItemFilters, assetFilters } = generateContentItems(
resources,
projectPath
);
return {
assetItems: assetItems.join("\n "),
assetItemFilters: assetItemFilters.join("\n "),
assetFilters: assetFilters.join("\n "),
};
}
/**
* Returns path to the specified asset relative to the project path.
* @param {string} projectPath
* @param {string} assetPath
* @returns {string}
*/
function projectRelativePath(projectPath, assetPath) {
return normalizePath(
path.isAbsolute(assetPath)
? path.relative(projectPath, assetPath)
: assetPath
);
}
/**
* Replaces parts in specified content.
* @param {string} content Content to be replaced.
* @param {{ [pattern: string]: string }} replacements e.g. {'TextToBeReplaced': 'Replacement'}
* @returns {string} The contents of the file with the replacements applied.
*/
function replaceContent(content, replacements) {
return Object.keys(replacements).reduce(
(content, regex) =>
content.replace(new RegExp(regex, "g"), replacements[regex]),
content
);
}
/**
* Rethrows specified error.
* @param {Error | null} error
*/
function rethrow(error) {
if (error) {
throw error;
}
}
/**
* Returns a solution entry for specified project.
* @param {{ path: string; name: string; guid: string; }} project
* @param {string} destPath
*/
function toProjectEntry(project, destPath) {
return [
`Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "${
project.name
}", "${path.relative(destPath, project.path)}", "${project.guid}"`,
"\tProjectSection(ProjectDependencies) = postProject",
`\t\t${templateView.projectGuidUpper} = ${templateView.projectGuidUpper}`,
"\tEndProjectSection",
"EndProject",
].join(os.EOL);
}
/**
* Copies a file to given destination, replacing parts of its contents.
* @param {string} srcPath Path to the file to be copied.
* @param {string} destPath Destination path.
* @param {Record<string, string> | undefined} replacements e.g. {'TextToBeReplaced': 'Replacement'}
* @param {(error: Error | null) => void=} callback Callback for when the copy operation is done.
*/
function copyAndReplace(srcPath, destPath, replacements, callback = rethrow) {
const stat = fs.statSync(srcPath);
if (stat.isDirectory()) {
copy(srcPath, destPath);
} else if (!replacements) {
fs.copyFile(srcPath, destPath, callback);
} else {
// Treat as text file
fs.readFile(srcPath, textFileReadOptions, (err, data) => {
if (err) {
callback(err);
return;
}
fs.writeFile(
destPath,
replaceContent(data, replacements),
{
encoding: "utf-8",
mode: stat.mode,
},
callback
);
});
}
}
/**
* Reads manifest file and and resolves paths to bundle resources.
* @param {string | null} manifestFilePath Path to the closest manifest file.
* @param {string} projectFilesDestPath Resolved paths will be relative to this path.
* @returns {{
* appName: string;
* appxManifest: string;
* assetItems: string;
* assetItemFilters: string;
* assetFilters: string;
* packageCertificate: string;
* }} Application name, and paths to directories and files to include.
*/
function getBundleResources(manifestFilePath, projectFilesDestPath) {
// Default value if manifest or 'name' field don't exist.
const defaultName = "ReactTestApp";
// Default `Package.appxmanifest` path. The project will automatically use our
// fallback if there is no file at this path.
const defaultAppxManifest = "windows/Package.appxmanifest";
if (manifestFilePath) {
try {
const content = fs.readFileSync(manifestFilePath, textFileReadOptions);
const { name, resources, windows } = JSON.parse(content);
const projectPath = path.dirname(manifestFilePath);
return {
appName: name || defaultName,
appxManifest: projectRelativePath(
projectPath,
(windows && windows.appxManifest) || defaultAppxManifest
),
packageCertificate: generateCertificateItems(
windows || {},
projectPath
),
...parseResources(resources, projectPath, projectFilesDestPath),
};
} catch (e) {
if (isErrorLike(e)) {
console.warn(`Could not parse 'app.json':\n${e.message}`);
} else {
throw e;
}
}
} else {
console.warn("Could not find 'app.json' file.");
}
return {
appName: defaultName,
appxManifest: defaultAppxManifest,
assetItems: "",
assetItemFilters: "",
assetFilters: "",
packageCertificate: "",
};
}
/**
* Returns the version of Hermes that should be installed.
* @param {string} rnwPath Path to `react-native-windows`.
* @returns {string | null}
*/
function getHermesVersion(rnwPath) {
const jsEnginePropsPath = path.join(
rnwPath,
"PropertySheets",
"JSEngine.props"
);
const props = fs.readFileSync(jsEnginePropsPath, textFileReadOptions);
const m = props.match(/<HermesVersion.*?>(.+?)<\/HermesVersion>/);
return m && m[1];
}
/**
* Returns the version number the package at specified path.
* @param {string} packagePath
* @returns {string}
*/
function getPackageVersion(packagePath) {
const { version } = JSON.parse(
fs.readFileSync(path.join(packagePath, "package.json"), textFileReadOptions)
);
return version;
}
/**
* Returns a single number for the specified version, suitable as a value for a
* preprocessor definition.
* @param {string} version
* @returns {number}
*/
function getVersionNumber(version) {
const components = version.split("-")[0].split(".");
const lastIndex = components.length - 1;
return components.reduce(
/** @type {(sum: number, value: string, index: number) => number} */
(sum, value, index) => {
return sum + parseInt(value) * Math.pow(100, lastIndex - index);
},
0
);
}
/**
* Generates Visual Studio solution.
* @param {string} destPath Destination path.
* @param {{ autolink: boolean; useHermes: boolean | undefined; useNuGet: boolean; }} options
* @returns {string | undefined} An error message; `undefined` otherwise.
*/
function generateSolution(destPath, { autolink, useHermes, useNuGet }) {
if (!destPath) {
throw "Missing or invalid destination path";
}
const nodeModulesDir = "node_modules";
const nodeModulesPath = findNearest(nodeModulesDir);
if (!nodeModulesPath) {
return "Could not find 'node_modules'";
}
const rnWindowsPath = findNearest(
path.join(nodeModulesDir, "react-native-windows")
);
if (!rnWindowsPath) {
return "Could not find 'react-native-windows'";
}
const rnTestAppPath = findNearest(
path.join(nodeModulesDir, "react-native-test-app")
);
if (!rnTestAppPath) {
return "Could not find 'react-native-test-app'";
}
const projDir = "ReactTestApp";
const projectFilesDestPath = path.join(
nodeModulesPath,
".generated",
"windows",
projDir
);
fs.mkdirSync(projectFilesDestPath, { recursive: true });
fs.mkdirSync(destPath, { recursive: true });
const manifestFilePath = findNearest("app.json", destPath);
const {
appName,
appxManifest,
assetItems,
assetItemFilters,
assetFilters,
packageCertificate,
} = getBundleResources(manifestFilePath, projectFilesDestPath);
const rnWindowsVersion = getPackageVersion(rnWindowsPath);
const rnWindowsVersionNumber = getVersionNumber(rnWindowsVersion);
const hermesVersion = useHermes && getHermesVersion(rnWindowsPath);
const xamlVersion = rnWindowsVersionNumber < 6700 ? "2.6.0" : "2.7.0";
/** @type {[string, Record<string, string>?][]} */
const projectFiles = [
["Assets"],
["AutolinkedNativeModules.g.cpp"],
["AutolinkedNativeModules.g.props"],
["AutolinkedNativeModules.g.targets"],
["Package.appxmanifest"],
["PropertySheet.props"],
[
"ReactTestApp.vcxproj",
{
"1000\\.0\\.0": rnWindowsVersion,
"REACT_NATIVE_VERSION=10000000;": `REACT_NATIVE_VERSION=${rnWindowsVersionNumber};`,
"<!-- ReactTestApp asset items -->": assetItems,
"\\$\\(ReactTestAppPackageManifest\\)": appxManifest,
...(useNuGet
? {
"<UseExperimentalNuget>false</UseExperimentalNuget>":
"<UseExperimentalNuget>true</UseExperimentalNuget>",
"<WinUI2xVersionDisabled />": `<WinUI2xVersion>${xamlVersion}</WinUI2xVersion>`,
}
: undefined),
...(packageCertificate
? {
"<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>":
packageCertificate,
}
: undefined),
},
],
[
"ReactTestApp.vcxproj.filters",
{
"<!-- ReactTestApp asset item filters -->": assetItemFilters,
"<!-- ReactTestApp asset filters -->": assetFilters,
"\\$\\(ReactTestAppPackageManifest\\)": appxManifest,
},
],
[
"packages.config",
{
'<package id="Microsoft.UI.Xaml" version="0.0.0" targetFramework="native"/>':
nuGetPackage("Microsoft.UI.Xaml", xamlVersion),
...(useNuGet
? {
'<!-- package id="Microsoft.ReactNative" version="1000.0.0" targetFramework="native"/ -->':
nuGetPackage("Microsoft.ReactNative", rnWindowsVersion),
'<!-- package id="Microsoft.ReactNative.Cxx" version="1000.0.0" targetFramework="native"/ -->':
nuGetPackage("Microsoft.ReactNative.Cxx", rnWindowsVersion),
}
: undefined),
...(hermesVersion
? {
'<!-- package id="ReactNative.Hermes.Windows" version="0.0.0" targetFramework="native"/ -->':
nuGetPackage("ReactNative.Hermes.Windows", hermesVersion),
}
: undefined),
},
],
];
const copyTasks = projectFiles.map(([file, replacements]) =>
copyAndReplace(
path.join(__dirname, projDir, file),
path.join(projectFilesDestPath, file),
replacements
)
);
const additionalProjectEntries = findUserProjects(destPath)
.map((project) => toProjectEntry(project, destPath))
.join(os.EOL);
// The mustache template was introduced in 0.63
const solutionTemplatePath =
findNearest(
// In 0.64, the template was moved into `react-native-windows`
path.join(
nodeModulesDir,
"react-native-windows",
"template",
"cpp-app",
"proj",
"MyApp.sln"
)
) ||
findNearest(
// In 0.63, the template is in `@react-native-windows/cli`
path.join(
nodeModulesDir,
"@react-native-windows",
"cli",
"templates",
"cpp",
"proj",
"MyApp.sln"
)
);
if (!solutionTemplatePath) {
copyAndReplace(
path.join(__dirname, "ReactTestApp.sln"),
path.join(destPath, `${appName}.sln`),
{
"\\$\\(ReactNativeModulePath\\)": path.relative(
destPath,
rnWindowsPath
),
"\\$\\(ReactTestAppProjectPath\\)": path.relative(
destPath,
projectFilesDestPath
),
"\\$\\(AdditionalProjects\\)": additionalProjectEntries,
}
);
} else {
const mustache = require("mustache");
const reactTestAppProjectPath = path.join(
projectFilesDestPath,
"ReactTestApp.vcxproj"
);
const solutionTask = fs.writeFile(
path.join(destPath, `${appName}.sln`),
mustache
.render(fs.readFileSync(solutionTemplatePath, textFileReadOptions), {
...templateView,
useExperimentalNuget: useNuGet,
})
// The current version of this template (v0.63.18) assumes that
// `react-native-windows` is always installed in
// `..\node_modules\react-native-windows`.
.replace(
/"\.\.\\node_modules\\react-native-windows\\/g,
`"${path.relative(destPath, rnWindowsPath)}\\`
)
.replace(
"ReactTestApp\\ReactTestApp.vcxproj",
path.relative(destPath, reactTestAppProjectPath)
)
.replace(
/EndProject\r?\nGlobal/,
["EndProject", additionalProjectEntries, "Global"].join(os.EOL)
),
textFileWriteOptions,
rethrow
);
copyAndReplace(
path.join(__dirname, "ExperimentalFeatures.props"),
path.join(destPath, "ExperimentalFeatures.props"),
{
...(hermesVersion
? { "<UseHermes>false</UseHermes>": `<UseHermes>true</UseHermes>` }
: undefined),
}
);
// TODO: Remove when we drop support for 0.67.
// Patch building with Visual Studio 2022. For more details, see
// https://github.com/microsoft/react-native-windows/issues/9559
if (rnWindowsVersionNumber < 6800) {
const dispatchQueue = path.join(
rnWindowsPath,
"Mso",
"dispatchQueue",
"dispatchQueue.h"
);
copyAndReplace(dispatchQueue, dispatchQueue, {
"template <typename T>\\s*inline void MustBeNoExceptVoidFunctor\\(\\) {\\s*static_assert\\(false":
"namespace details {\n template <typename>\n constexpr bool always_false = false;\n}\n\ntemplate <typename T>\ninline void MustBeNoExceptVoidFunctor() {\n static_assert(details::always_false<T>",
});
}
if (useNuGet) {
const nugetConfigPath =
findNearest(
// In 0.64, the template was moved into `react-native-windows`
path.join(
nodeModulesDir,
"react-native-windows",
"template",
"shared-app",
"proj",
"NuGet.Config"
)
) ||
findNearest(
// In 0.63, the template is in `@react-native-windows/cli`
path.join(
nodeModulesDir,
"@react-native-windows",
"cli",
"templates",
"shared",
"proj",
"NuGet.Config"
)
);
if (nugetConfigPath) {
fs.writeFile(
path.join(destPath, "NuGet.Config"),
mustache.render(
fs.readFileSync(nugetConfigPath, textFileReadOptions),
{}
),
textFileWriteOptions,
rethrow
);
}
}
if (autolink) {
Promise.all([...copyTasks, solutionTask]).then(() => {
const { spawn } = require("child_process");
spawn(
path.join(path.dirname(process.argv0), "npx.cmd"),
[
"react-native",
"autolink-windows",
"--proj",
reactTestAppProjectPath,
],
{ stdio: "inherit" }
).on("close", (code) => {
if (code !== 0) {
process.exit(code || 1);
}
});
});
}
}
return undefined;
}
if (require.main === module) {
require("../scripts/link")(module);
require("yargs").usage(
"$0 [options]",
"Generate a Visual Studio solution for React Test App",
{
"project-directory": {
alias: "p",
type: "string",
description: "Directory where solution will be created",
default: "windows",
},
autolink: {
type: "boolean",
description: "Run autolink after generating the solution",
default: true,
},
"use-hermes": {
type: "boolean",
description: "Use Hermes JavaScript engine (experimental)",
},
"use-nuget": {
type: "boolean",
description: "Use NuGet packages (experimental)",
default: false,
},
},
({
"project-directory": projectDirectory,
autolink,
"use-hermes": useHermes,
"use-nuget": useNuGet,
}) => {
const error = generateSolution(path.resolve(projectDirectory), {
autolink,
useHermes,
useNuGet,
});
if (error) {
console.error(error);
process.exit(1);
}
}
).argv;
} else {
exports.copy = copy;
exports.copyAndReplace = copyAndReplace;
exports.findNearest = findNearest;
exports.findUserProjects = findUserProjects;
exports.generateSolution = generateSolution;
exports.getBundleResources = getBundleResources;
exports.getHermesVersion = getHermesVersion;
exports.getPackageVersion = getPackageVersion;
exports.getVersionNumber = getVersionNumber;
exports.nuGetPackage = nuGetPackage;
exports.parseResources = parseResources;
exports.replaceContent = replaceContent;
exports.toProjectEntry = toProjectEntry;
}