@react-native-windows/cli 0.0.0-canary.26 → 0.0.0-canary.260

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 (145) hide show
  1. package/README.md +117 -0
  2. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.d.ts +88 -0
  3. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js +705 -0
  4. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js.map +1 -0
  5. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.d.ts +14 -0
  6. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js +33 -0
  7. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js.map +1 -0
  8. package/lib-commonjs/commands/codegenWindows/codegenWindows.d.ts +27 -0
  9. package/lib-commonjs/commands/codegenWindows/codegenWindows.js +211 -0
  10. package/lib-commonjs/commands/codegenWindows/codegenWindows.js.map +1 -0
  11. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.d.ts +12 -0
  12. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js +23 -0
  13. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js.map +1 -0
  14. package/lib-commonjs/{config → commands/config}/configUtils.d.ts +141 -93
  15. package/lib-commonjs/commands/config/configUtils.js +420 -0
  16. package/lib-commonjs/commands/config/configUtils.js.map +1 -0
  17. package/lib-commonjs/{config → commands/config}/dependencyConfig.d.ts +38 -37
  18. package/lib-commonjs/commands/config/dependencyConfig.js +230 -0
  19. package/lib-commonjs/commands/config/dependencyConfig.js.map +1 -0
  20. package/lib-commonjs/{config → commands/config}/projectConfig.d.ts +28 -24
  21. package/lib-commonjs/commands/config/projectConfig.js +191 -0
  22. package/lib-commonjs/commands/config/projectConfig.js.map +1 -0
  23. package/lib-commonjs/commands/healthCheck/healthCheckList.d.ts +6 -0
  24. package/lib-commonjs/commands/healthCheck/healthCheckList.js +21 -0
  25. package/lib-commonjs/commands/healthCheck/healthCheckList.js.map +1 -0
  26. package/lib-commonjs/commands/healthCheck/healthChecks.d.ts +7 -0
  27. package/lib-commonjs/commands/healthCheck/healthChecks.js +124 -0
  28. package/lib-commonjs/commands/healthCheck/healthChecks.js.map +1 -0
  29. package/lib-commonjs/commands/initWindows/initWindows.d.ts +46 -0
  30. package/lib-commonjs/commands/initWindows/initWindows.js +275 -0
  31. package/lib-commonjs/commands/initWindows/initWindows.js.map +1 -0
  32. package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +16 -0
  33. package/lib-commonjs/commands/initWindows/initWindowsOptions.js +42 -0
  34. package/lib-commonjs/commands/initWindows/initWindowsOptions.js.map +1 -0
  35. package/lib-commonjs/{runWindows → commands/runWindows}/runWindows.d.ts +10 -10
  36. package/lib-commonjs/commands/runWindows/runWindows.js +322 -0
  37. package/lib-commonjs/commands/runWindows/runWindows.js.map +1 -0
  38. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.d.ts +56 -52
  39. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.js +132 -131
  40. package/lib-commonjs/commands/runWindows/runWindowsOptions.js.map +1 -0
  41. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -0
  42. package/lib-commonjs/e2etest/autolink.test.js +367 -0
  43. package/lib-commonjs/e2etest/autolink.test.js.map +1 -0
  44. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -0
  45. package/lib-commonjs/e2etest/dependencyConfig.test.js +130 -0
  46. package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -0
  47. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -0
  48. package/lib-commonjs/e2etest/healthChecks.test.js +31 -0
  49. package/lib-commonjs/e2etest/healthChecks.test.js.map +1 -0
  50. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -0
  51. package/lib-commonjs/e2etest/initWindows.test.js +110 -0
  52. package/lib-commonjs/e2etest/initWindows.test.js.map +1 -0
  53. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -0
  54. package/lib-commonjs/e2etest/projectConfig.test.js +111 -0
  55. package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -0
  56. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -0
  57. package/lib-commonjs/e2etest/projectConfig.utils.js +77 -0
  58. package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
  59. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
  60. package/lib-commonjs/e2etest/runWindows.test.js +61 -0
  61. package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
  62. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  63. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  64. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  65. package/lib-commonjs/generator-common/index.d.ts +39 -23
  66. package/lib-commonjs/generator-common/index.js +242 -221
  67. package/lib-commonjs/generator-common/index.js.map +1 -1
  68. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  69. package/lib-commonjs/generator-windows/index.js +341 -364
  70. package/lib-commonjs/generator-windows/index.js.map +1 -1
  71. package/lib-commonjs/index.d.ts +50 -47
  72. package/lib-commonjs/index.js +77 -39
  73. package/lib-commonjs/index.js.map +1 -1
  74. package/lib-commonjs/{runWindows/utils → utils}/build.d.ts +12 -13
  75. package/lib-commonjs/{runWindows/utils → utils}/build.js +89 -91
  76. package/lib-commonjs/utils/build.js.map +1 -0
  77. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.d.ts +6 -6
  78. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.js +69 -65
  79. package/lib-commonjs/utils/checkRequirements.js.map +1 -0
  80. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.d.ts +21 -13
  81. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.js +149 -113
  82. package/lib-commonjs/utils/commandWithProgress.js.map +1 -0
  83. package/lib-commonjs/{runWindows/utils → utils}/deploy.d.ts +12 -12
  84. package/lib-commonjs/utils/deploy.js +354 -0
  85. package/lib-commonjs/utils/deploy.js.map +1 -0
  86. package/lib-commonjs/{runWindows/utils → utils}/info.d.ts +6 -6
  87. package/lib-commonjs/{runWindows/utils → utils}/info.js +28 -25
  88. package/lib-commonjs/utils/info.js.map +1 -0
  89. package/lib-commonjs/utils/msbuildtools.d.ts +28 -0
  90. package/lib-commonjs/utils/msbuildtools.js +281 -0
  91. package/lib-commonjs/utils/msbuildtools.js.map +1 -0
  92. package/lib-commonjs/utils/nameHelpers.d.ts +9 -0
  93. package/lib-commonjs/utils/nameHelpers.js +46 -0
  94. package/lib-commonjs/utils/nameHelpers.js.map +1 -0
  95. package/lib-commonjs/utils/pathHelpers.d.ts +9 -0
  96. package/lib-commonjs/utils/pathHelpers.js +37 -0
  97. package/lib-commonjs/utils/pathHelpers.js.map +1 -0
  98. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -0
  99. package/lib-commonjs/utils/telemetryHelpers.js +121 -0
  100. package/lib-commonjs/utils/telemetryHelpers.js.map +1 -0
  101. package/lib-commonjs/{runWindows/utils → utils}/version.d.ts +19 -19
  102. package/lib-commonjs/{runWindows/utils → utils}/version.js +109 -109
  103. package/lib-commonjs/utils/version.js.map +1 -0
  104. package/lib-commonjs/{runWindows/utils → utils}/vsInstalls.d.ts +34 -34
  105. package/lib-commonjs/utils/vsInstalls.js +102 -0
  106. package/lib-commonjs/utils/vsInstalls.js.map +1 -0
  107. package/lib-commonjs/{runWindows/utils → utils}/vstools.d.ts +16 -15
  108. package/lib-commonjs/utils/vstools.js +190 -0
  109. package/lib-commonjs/utils/vstools.js.map +1 -0
  110. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.d.ts +24 -24
  111. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.js +108 -105
  112. package/lib-commonjs/utils/winappdeploytool.js.map +1 -0
  113. package/package.json +49 -31
  114. package/{powershell → src/powershell}/Add-AppDevPackage.ps1 +2 -2
  115. package/src/powershell/Eval-MsBuildProperties.ps1 +156 -0
  116. package/{powershell → src/powershell}/WindowsStoreAppUtils.ps1 +10 -0
  117. package/CHANGELOG.json +0 -413
  118. package/CHANGELOG.md +0 -200
  119. package/lib-commonjs/config/configUtils.js +0 -253
  120. package/lib-commonjs/config/configUtils.js.map +0 -1
  121. package/lib-commonjs/config/dependencyConfig.js +0 -167
  122. package/lib-commonjs/config/dependencyConfig.js.map +0 -1
  123. package/lib-commonjs/config/projectConfig.js +0 -121
  124. package/lib-commonjs/config/projectConfig.js.map +0 -1
  125. package/lib-commonjs/runWindows/runWindows.js +0 -159
  126. package/lib-commonjs/runWindows/runWindows.js.map +0 -1
  127. package/lib-commonjs/runWindows/runWindowsOptions.js.map +0 -1
  128. package/lib-commonjs/runWindows/utils/autolink.d.ts +0 -7
  129. package/lib-commonjs/runWindows/utils/autolink.js +0 -353
  130. package/lib-commonjs/runWindows/utils/autolink.js.map +0 -1
  131. package/lib-commonjs/runWindows/utils/build.js.map +0 -1
  132. package/lib-commonjs/runWindows/utils/checkRequirements.js.map +0 -1
  133. package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +0 -1
  134. package/lib-commonjs/runWindows/utils/deploy.js +0 -247
  135. package/lib-commonjs/runWindows/utils/deploy.js.map +0 -1
  136. package/lib-commonjs/runWindows/utils/info.js.map +0 -1
  137. package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +0 -22
  138. package/lib-commonjs/runWindows/utils/msbuildtools.js +0 -195
  139. package/lib-commonjs/runWindows/utils/msbuildtools.js.map +0 -1
  140. package/lib-commonjs/runWindows/utils/version.js.map +0 -1
  141. package/lib-commonjs/runWindows/utils/vsInstalls.js +0 -70
  142. package/lib-commonjs/runWindows/utils/vsInstalls.js.map +0 -1
  143. package/lib-commonjs/runWindows/utils/vstools.js +0 -150
  144. package/lib-commonjs/runWindows/utils/vstools.js.map +0 -1
  145. package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +0 -1
@@ -1,365 +1,342 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- * @format
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.installDependencies = exports.copyProjectTemplateAndReplace = void 0;
9
- const chalk = require("chalk");
10
- const path = require("path");
11
- const username = require("username");
12
- const uuid = require("uuid");
13
- const childProcess = require("child_process");
14
- const fs = require("fs");
15
- const os = require("os");
16
- const semver = require("semver");
17
- const _ = require("lodash");
18
- const configUtils_1 = require("../config/configUtils");
19
- const generator_common_1 = require("../generator-common");
20
- const windowsDir = 'windows';
21
- const bundleDir = 'Bundle';
22
- async function generateCertificate(srcPath, destPath, newProjectName, currentUser) {
23
- console.log('Generating self-signed certificate...');
24
- let toCopyTempKey = false;
25
- if (os.platform() === 'win32') {
26
- try {
27
- const timeout = 10000; // 10 seconds;
28
- const thumbprint = childProcess
29
- .execSync(`powershell -NoProfile -Command "Write-Output (New-SelfSignedCertificate -KeyUsage DigitalSignature -KeyExportPolicy Exportable -Subject 'CN=${currentUser}' -TextExtension @('2.5.29.37={text}1.3.6.1.5.5.7.3.3', '2.5.29.19={text}Subject Type:End Entity') -CertStoreLocation 'Cert:\\CurrentUser\\My').Thumbprint"`, { timeout })
30
- .toString()
31
- .trim();
32
- if (!fs.existsSync(path.join(windowsDir, newProjectName))) {
33
- fs.mkdirSync(path.join(windowsDir, newProjectName));
34
- }
35
- childProcess.execSync(`powershell -NoProfile -Command "$pwd = (ConvertTo-SecureString -String password -Force -AsPlainText); Export-PfxCertificate -Cert 'cert:\\CurrentUser\\My\\${thumbprint}' -FilePath ${path.join(windowsDir, newProjectName, newProjectName)}_TemporaryKey.pfx -Password $pwd"`, { timeout });
36
- console.log(chalk.green('Self-signed certificate generated successfully.'));
37
- return thumbprint;
38
- }
39
- catch (err) {
40
- console.log(chalk.yellow('Failed to generate Self-signed certificate. Using Default Certificate. Use Visual Studio to renew it.'));
41
- toCopyTempKey = true;
42
- }
43
- }
44
- else {
45
- console.log(chalk.yellow('Using Default Certificate. Use Visual Studio to renew it.'));
46
- toCopyTempKey = true;
47
- }
48
- if (toCopyTempKey) {
49
- await generator_common_1.copyAndReplaceWithChangedCallback(path.join(srcPath, 'keys', 'MyApp_TemporaryKey.pfx'), destPath, path.join(windowsDir, newProjectName, newProjectName + '_TemporaryKey.pfx'));
50
- }
51
- return null;
52
- }
53
- function pascalCase(str) {
54
- const camelCase = _.camelCase(str);
55
- return camelCase[0].toUpperCase() + camelCase.substr(1);
56
- }
57
- async function copyProjectTemplateAndReplace(srcRootPath, destPath, newProjectName, namespace, options) {
58
- if (!srcRootPath) {
59
- throw new Error('Need a path to copy from');
60
- }
61
- if (!destPath) {
62
- throw new Error('Need a path to copy to');
63
- }
64
- if (!newProjectName) {
65
- throw new Error('Need a project name');
66
- }
67
- const projectType = options.projectType;
68
- // React-native init only allows alphanumerics in project names, but other
69
- // new project tools (like create-react-native-module) are less strict.
70
- if (projectType === 'lib') {
71
- newProjectName = pascalCase(newProjectName);
72
- }
73
- // Similar to the above, but we want to retain namespace separators
74
- if (projectType === 'lib') {
75
- namespace = namespace
76
- .split(/[\.\:]+/)
77
- .map(pascalCase)
78
- .join('.');
79
- }
80
- generator_common_1.createDir(path.join(destPath, windowsDir));
81
- generator_common_1.createDir(path.join(destPath, windowsDir, newProjectName));
82
- if (projectType === 'app') {
83
- generator_common_1.createDir(path.join(destPath, windowsDir, newProjectName, bundleDir));
84
- generator_common_1.createDir(path.join(destPath, windowsDir, newProjectName, 'BundleBuilder'));
85
- }
86
- const language = options.language;
87
- const namespaceCpp = toCppNamespace(namespace);
88
- if (options.experimentalNuGetDependency) {
89
- console.log('Using experimental NuGet dependency.');
90
- }
91
- if (options.useWinUI3) {
92
- console.log('Using experimental WinUI3 dependency.');
93
- }
94
- const projDir = 'proj';
95
- const srcPath = path.join(srcRootPath, `${language}-${projectType}`);
96
- const sharedPath = path.join(srcRootPath, `shared-${projectType}`);
97
- const projectGuid = uuid.v4();
98
- const rnwVersion = require('react-native-windows/package.json').version;
99
- const nugetVersion = options.nuGetTestVersion || rnwVersion;
100
- const packageGuid = uuid.v4();
101
- const currentUser = username.sync(); // Gets the current username depending on the platform.
102
- const certificateThumbprint = projectType === 'app'
103
- ? await generateCertificate(srcPath, destPath, newProjectName, currentUser)
104
- : null;
105
- const xamlNamespace = options.useWinUI3
106
- ? 'Microsoft.UI.Xaml'
107
- : 'Windows.UI.Xaml';
108
- const xamlNamespaceCpp = toCppNamespace(xamlNamespace);
109
- const winui3PropsPath = require.resolve('react-native-windows/PropertySheets/WinUI.props', { paths: [process.cwd()] });
110
- const winui3Props = configUtils_1.readProjectFile(winui3PropsPath);
111
- const winui3Version = configUtils_1.findPropertyValue(winui3Props, 'WinUI3Version');
112
- if (winui3Version === null) {
113
- throw new Error('Unable to find WinUI3 version from property sheets');
114
- }
115
- const csNugetPackages = [
116
- {
117
- id: 'Microsoft.NETCore.UniversalWindowsPlatform',
118
- version: '6.2.9',
119
- },
120
- ];
121
- const cppNugetPackages = [
122
- {
123
- id: 'Microsoft.Windows.CppWinRT',
124
- version: '2.0.200615.7',
125
- propsTopOfFile: true,
126
- hasProps: true,
127
- hasTargets: true,
128
- },
129
- {
130
- id: options.useWinUI3 ? 'Microsoft.WinUI' : 'Microsoft.UI.Xaml',
131
- version: options.useWinUI3 ? winui3Version : '2.3.191129002',
132
- hasProps: false,
133
- hasTargets: false,
134
- },
135
- ];
136
- if (options.experimentalNuGetDependency) {
137
- csNugetPackages.push({
138
- id: 'Microsoft.ReactNative.Managed',
139
- version: nugetVersion,
140
- });
141
- cppNugetPackages.push({
142
- id: 'Microsoft.ReactNative',
143
- version: nugetVersion,
144
- hasProps: false,
145
- hasTargets: true,
146
- });
147
- cppNugetPackages.push({
148
- id: 'Microsoft.ReactNative.Cxx',
149
- version: nugetVersion,
150
- hasProps: false,
151
- hasTargets: true,
152
- });
153
- }
154
- if (options.useHermes) {
155
- cppNugetPackages.push({
156
- id: 'ReactNative.Hermes.Windows',
157
- version: '0.6.3',
158
- hasProps: false,
159
- hasTargets: true,
160
- });
161
- }
162
- const templateVars = {
163
- useMustache: true,
164
- regExpPatternsToRemove: ['//\\sclang-format\\s(on|off)\\s'],
165
- name: newProjectName,
166
- namespace: namespace,
167
- namespaceCpp: namespaceCpp,
168
- languageIsCpp: language === 'cpp',
169
- // Visual Studio is very picky about the casing of the guids for projects, project references and the solution
170
- // https://www.bing.com/search?q=visual+studio+project+guid+casing&cvid=311a5ad7f9fc41089507b24600d23ee7&FORM=ANAB01&PC=U531
171
- // we therefore have to precariously use the right casing in the right place or risk building in VS breaking.
172
- projectGuidLower: `{${projectGuid.toLowerCase()}}`,
173
- projectGuidUpper: `{${projectGuid.toUpperCase()}}`,
174
- // packaging and signing variables:
175
- packageGuid: packageGuid,
176
- currentUser: currentUser,
177
- certificateThumbprint: certificateThumbprint,
178
- useExperimentalNuget: options.experimentalNuGetDependency,
179
- nuGetTestFeed: options.nuGetTestFeed,
180
- // cpp template variables
181
- useWinUI3: options.useWinUI3,
182
- useHermes: options.useHermes,
183
- xamlNamespace: xamlNamespace,
184
- xamlNamespaceCpp: xamlNamespaceCpp,
185
- cppNugetPackages: cppNugetPackages,
186
- // cs template variables
187
- csNugetPackages: csNugetPackages,
188
- // autolinking template variables
189
- autolinkProjectReferencesForTargets: '',
190
- autolinkCsUsingNamespaces: '',
191
- autolinkCsReactPacakgeProviders: '',
192
- autolinkCppIncludes: '',
193
- autolinkCppPackageProviders: '\n UNREFERENCED_PARAMETER(packageProviders);',
194
- };
195
- const commonMappings = projectType === 'app'
196
- ? [
197
- // app common mappings
198
- {
199
- from: path.join(srcRootPath, 'metro.config.js'),
200
- to: 'metro.config.js',
201
- },
202
- {
203
- from: path.join(srcRootPath, '_gitignore'),
204
- to: path.join(windowsDir, '.gitignore'),
205
- },
206
- {
207
- from: path.join(srcRootPath, 'b_gitignore'),
208
- to: path.join(windowsDir, newProjectName, '.gitignore'),
209
- },
210
- {
211
- from: path.join(srcRootPath, 'index.windows.bundle'),
212
- to: path.join(windowsDir, newProjectName, bundleDir, 'index.windows.bundle'),
213
- },
214
- {
215
- from: path.join(srcPath, projDir, 'MyApp.sln'),
216
- to: path.join(windowsDir, newProjectName + '.sln'),
217
- },
218
- {
219
- from: path.join(sharedPath, projDir, 'BuildFlags.props'),
220
- to: path.join(windowsDir, 'BuildFlags.props'),
221
- },
222
- ]
223
- : [
224
- // lib common mappings
225
- {
226
- from: path.join(srcRootPath, '_gitignore'),
227
- to: path.join(windowsDir, '.gitignore'),
228
- },
229
- {
230
- from: path.join(srcPath, projDir, 'MyLib.sln'),
231
- to: path.join(windowsDir, newProjectName + '.sln'),
232
- },
233
- ];
234
- for (const mapping of commonMappings) {
235
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
236
- }
237
- if (language === 'cs') {
238
- const csMappings = projectType === 'app'
239
- ? [
240
- // cs app mappings
241
- {
242
- from: path.join(srcPath, projDir, 'MyApp.csproj'),
243
- to: path.join(windowsDir, newProjectName, newProjectName + '.csproj'),
244
- },
245
- ]
246
- : [
247
- // cs lib mappings
248
- {
249
- from: path.join(srcPath, projDir, 'MyLib.csproj'),
250
- to: path.join(windowsDir, newProjectName, newProjectName + '.csproj'),
251
- },
252
- ];
253
- for (const mapping of csMappings) {
254
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
255
- }
256
- }
257
- else {
258
- const cppMappings = projectType === 'app'
259
- ? [
260
- // cpp app mappings
261
- {
262
- from: path.join(srcPath, projDir, 'MyApp.vcxproj'),
263
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
264
- },
265
- {
266
- from: path.join(srcPath, projDir, 'MyApp.vcxproj.filters'),
267
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
268
- },
269
- {
270
- from: path.join(srcPath, projDir, 'packages.config'),
271
- to: path.join(windowsDir, newProjectName, 'packages.config'),
272
- },
273
- ]
274
- : [
275
- // cpp lib mappings
276
- {
277
- from: path.join(srcPath, projDir, 'MyLib.vcxproj'),
278
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
279
- },
280
- {
281
- from: path.join(srcPath, projDir, 'MyLib.vcxproj.filters'),
282
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
283
- },
284
- {
285
- from: path.join(srcPath, projDir, 'MyLib.def'),
286
- to: path.join(windowsDir, newProjectName, newProjectName + '.def'),
287
- },
288
- {
289
- from: path.join(srcPath, projDir, 'packages.config'),
290
- to: path.join(windowsDir, newProjectName, 'packages.config'),
291
- },
292
- ];
293
- for (const mapping of cppMappings) {
294
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
295
- }
296
- }
297
- // shared proj
298
- if (fs.existsSync(path.join(sharedPath, projDir))) {
299
- // Once we are publishing to nuget.org, this shouldn't be needed anymore
300
- if (options.experimentalNuGetDependency) {
301
- const nugetMappings = [
302
- {
303
- from: path.join(sharedPath, projDir, 'NuGet.Config'),
304
- to: path.join(windowsDir, 'NuGet.Config'),
305
- },
306
- ];
307
- for (const mapping of nugetMappings) {
308
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
309
- }
310
- }
311
- }
312
- // shared assets
313
- if (fs.existsSync(path.join(sharedPath, 'assets'))) {
314
- await generator_common_1.copyAndReplaceAll(path.join(sharedPath, 'assets'), destPath, path.join(windowsDir, newProjectName, 'Assets'), templateVars, options.overwrite);
315
- }
316
- // shared src
317
- if (fs.existsSync(path.join(sharedPath, 'src'))) {
318
- await generator_common_1.copyAndReplaceAll(path.join(sharedPath, 'src'), destPath, path.join(windowsDir, newProjectName), templateVars, options.overwrite);
319
- }
320
- // src
321
- if (fs.existsSync(path.join(srcPath, 'src'))) {
322
- await generator_common_1.copyAndReplaceAll(path.join(srcPath, 'src'), destPath, path.join(windowsDir, newProjectName), templateVars, options.overwrite);
323
- }
324
- if (projectType === 'app') {
325
- console.log(chalk.white.bold('To run your app on UWP:'));
326
- console.log(chalk.white(' npx react-native run-windows'));
327
- }
328
- }
329
- exports.copyProjectTemplateAndReplace = copyProjectTemplateAndReplace;
330
- function toCppNamespace(namespace) {
331
- return namespace.replace(/\./g, '::');
332
- }
333
- function installDependencies(options) {
334
- const cwd = process.cwd();
335
- // Extract react-native peer dependency version
336
- const rnwPackageJsonPath = require.resolve('react-native-windows/package.json', { paths: [process.cwd()] });
337
- const rnwPackageJson = JSON.parse(fs.readFileSync(rnwPackageJsonPath, { encoding: 'UTF8' }));
338
- let rnPeerDependency = rnwPackageJson.peerDependencies['react-native'];
339
- const depDelim = ' || ';
340
- const delimIndex = rnPeerDependency.indexOf(depDelim);
341
- if (delimIndex !== -1) {
342
- rnPeerDependency = rnPeerDependency.slice(0, delimIndex);
343
- }
344
- const rnPackageJsonPath = require.resolve('react-native/package.json', {
345
- paths: [process.cwd()],
346
- });
347
- const rnPackageJson = JSON.parse(fs.readFileSync(rnPackageJsonPath, { encoding: 'UTF8' }));
348
- if (!semver.satisfies(rnPackageJson.version, rnPeerDependency)) {
349
- console.log(chalk.green('Installing a compatible version of react-native:'));
350
- console.log(chalk.white(` ${rnPeerDependency}`));
351
- // Patch package.json to have proper react-native version and install
352
- const projectPackageJsonPath = path.join(cwd, 'package.json');
353
- const projectPackageJson = JSON.parse(fs.readFileSync(projectPackageJsonPath, { encoding: 'UTF8' }));
354
- projectPackageJson.scripts.windows = 'react-native run-windows';
355
- if (projectPackageJson.hasOwnProperty('dependencies')) {
356
- projectPackageJson.dependencies['react-native'] = rnPeerDependency;
357
- }
358
- fs.writeFileSync(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2));
359
- // Install dependencies using correct package manager
360
- const isYarn = fs.existsSync(path.join(cwd, 'yarn.lock'));
361
- childProcess.execSync(isYarn ? 'yarn' : 'npm i', options.verbose ? { stdio: 'inherit' } : {});
362
- }
363
- }
364
- exports.installDependencies = installDependencies;
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || function (mod) {
24
+ if (mod && mod.__esModule) return mod;
25
+ var result = {};
26
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
+ __setModuleDefault(result, mod);
28
+ return result;
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.installScriptsAndDependencies = exports.copyProjectTemplateAndReplace = void 0;
35
+ const chalk_1 = __importDefault(require("chalk"));
36
+ const path_1 = __importDefault(require("path"));
37
+ const username_1 = __importDefault(require("username"));
38
+ const child_process_1 = __importDefault(require("child_process"));
39
+ const crypto_1 = __importDefault(require("crypto"));
40
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
41
+ const semver_1 = __importDefault(require("semver"));
42
+ const find_up_1 = __importDefault(require("find-up"));
43
+ const configUtils_1 = require("../commands/config/configUtils");
44
+ const nameHelpers = __importStar(require("../utils/nameHelpers"));
45
+ const generator_common_1 = require("../generator-common");
46
+ const telemetry_1 = require("@react-native-windows/telemetry");
47
+ const package_utils_1 = require("@react-native-windows/package-utils");
48
+ const windowsDir = 'windows';
49
+ const bundleDir = 'Bundle';
50
+ function resolveRnwPath(subpath) {
51
+ return require.resolve(path_1.default.join('react-native-windows', subpath), {
52
+ paths: [process.cwd()],
53
+ });
54
+ }
55
+ // Existing high cyclomatic complexity
56
+ // eslint-disable-next-line complexity
57
+ async function copyProjectTemplateAndReplace(srcRootPath, destPath, newProjectName, namespace, options) {
58
+ if (!srcRootPath) {
59
+ throw new telemetry_1.CodedError('CopyProjectTemplateNoSourcePath', 'Need a path to copy from');
60
+ }
61
+ if (!destPath) {
62
+ throw new telemetry_1.CodedError('CopyProjectTemplateNoDestPath', 'Need a path to copy to');
63
+ }
64
+ if (!newProjectName) {
65
+ throw new telemetry_1.CodedError('CopyProjectTemplateNoProjectName', 'Need a project name');
66
+ }
67
+ const projectType = options.projectType;
68
+ const language = options.language;
69
+ // @react-native-community/cli init only allows alphanumerics in project names, but other
70
+ // new project tools (like expo and create-react-native-module) are less strict.
71
+ // The default (legacy) behavior of this flow is to clean the name rather than throw an error.
72
+ if (!nameHelpers.isValidProjectName(newProjectName)) {
73
+ newProjectName = nameHelpers.cleanName(newProjectName);
74
+ }
75
+ // Similar to the above, but we want to retain namespace separators
76
+ // The default (legacy) behavior of this flow is to clean the name rather than throw an error.
77
+ if (!nameHelpers.isValidProjectNamespace(namespace)) {
78
+ namespace = nameHelpers.cleanNamespace(namespace);
79
+ }
80
+ // Checking if we're overwriting an existing project and re-uses their projectGUID
81
+ const existingProjectPath = path_1.default.join(destPath, windowsDir, newProjectName, newProjectName + (language === 'cs' ? '.csproj' : '.vcxproj'));
82
+ let existingProjectGuid;
83
+ if (fs_1.default.existsSync(existingProjectPath)) {
84
+ console.log('Found existing project, extracting ProjectGuid.');
85
+ existingProjectGuid = (0, configUtils_1.findPropertyValue)((0, configUtils_1.readProjectFile)(existingProjectPath), 'ProjectGuid', existingProjectPath).replace(/[{}]/g, '');
86
+ }
87
+ (0, generator_common_1.createDir)(path_1.default.join(destPath, windowsDir));
88
+ (0, generator_common_1.createDir)(path_1.default.join(destPath, windowsDir, newProjectName));
89
+ if (projectType === 'app') {
90
+ (0, generator_common_1.createDir)(path_1.default.join(destPath, windowsDir, newProjectName, bundleDir));
91
+ (0, generator_common_1.createDir)(path_1.default.join(destPath, windowsDir, newProjectName, 'BundleBuilder'));
92
+ }
93
+ const namespaceCpp = toCppNamespace(namespace);
94
+ if (options.experimentalNuGetDependency) {
95
+ console.log('Using experimental NuGet dependency.');
96
+ }
97
+ const experimentalPropsPath = path_1.default.join(destPath, windowsDir, 'ExperimentalFeatures.props');
98
+ let existingUseHermes = null;
99
+ if (fs_1.default.existsSync(experimentalPropsPath)) {
100
+ existingUseHermes = (0, configUtils_1.tryFindPropertyValueAsBoolean)((0, configUtils_1.readProjectFile)(experimentalPropsPath), 'UseHermes');
101
+ }
102
+ if (existingUseHermes === false) {
103
+ console.warn('Hermes is now the default JS engine and will be enabled for this project. Support for Chakra will be deprecated in the future. To disable Hermes and keep using Chakra for now, see https://microsoft.github.io/react-native-windows/docs/hermes#disabling-hermes.');
104
+ }
105
+ options.useHermes = true;
106
+ if (options.useWinUI3) {
107
+ throw new telemetry_1.CodedError('IncompatibleOptions', 'Experimental WinUI 3 project has been deprecated.');
108
+ }
109
+ const projDir = 'proj';
110
+ const srcPath = path_1.default.join(srcRootPath, `${language}-${projectType}`);
111
+ const sharedPath = path_1.default.join(srcRootPath, `shared-${projectType}`);
112
+ const projectGuid = existingProjectGuid || crypto_1.default.randomUUID();
113
+ const rnwPath = path_1.default.dirname(resolveRnwPath('package.json'));
114
+ const rnwVersion = require(resolveRnwPath('package.json')).version;
115
+ const nugetVersion = options.nuGetTestVersion || rnwVersion;
116
+ const packageGuid = crypto_1.default.randomUUID();
117
+ const currentUser = username_1.default.sync(); // Gets the current username depending on the platform.
118
+ let mainComponentName = newProjectName;
119
+ const appJsonPath = await (0, find_up_1.default)('app.json', { cwd: destPath });
120
+ if (appJsonPath) {
121
+ const appJson = await fs_1.default.readJsonFile(appJsonPath);
122
+ mainComponentName = appJson.name;
123
+ }
124
+ // We should prefer putting new, necessary PackageReference dependencies into the appropriate
125
+ // external property sheets, but this is here if we "must" inject the dependency into the project file
126
+ const csNugetPackages = [];
127
+ const cppNugetPackages = [];
128
+ const templateVars = {
129
+ useMustache: true,
130
+ regExpPatternsToRemove: [],
131
+ name: newProjectName,
132
+ namespace: namespace,
133
+ namespaceCpp: namespaceCpp,
134
+ languageIsCpp: language === 'cpp',
135
+ rnwVersion: await (0, telemetry_1.getVersionOfNpmPackage)('react-native-windows'),
136
+ rnwPathFromProjectRoot: path_1.default
137
+ .relative(destPath, rnwPath)
138
+ .replace(/\//g, '\\'),
139
+ mainComponentName: mainComponentName,
140
+ // Visual Studio is very picky about the casing of the guids for projects, project references and the solution
141
+ // https://www.bing.com/search?q=visual+studio+project+guid+casing&cvid=311a5ad7f9fc41089507b24600d23ee7&FORM=ANAB01&PC=U531
142
+ // we therefore have to precariously use the right casing in the right place or risk building in VS breaking.
143
+ projectGuidLower: `{${projectGuid.toLowerCase()}}`,
144
+ projectGuidUpper: `{${projectGuid.toUpperCase()}}`,
145
+ // packaging and signing variables:
146
+ packageGuid: packageGuid,
147
+ currentUser: currentUser,
148
+ devMode: options.useDevMode,
149
+ useExperimentalNuget: options.experimentalNuGetDependency,
150
+ nuGetTestFeed: options.nuGetTestFeed,
151
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
152
+ nuGetADOFeed: true || nugetVersion.startsWith('0.0.0-'),
153
+ // cpp template variables
154
+ useWinUI3: options.useWinUI3,
155
+ useHermes: options.useHermes,
156
+ cppNugetPackages: cppNugetPackages,
157
+ // cs template variables
158
+ csNugetPackages: csNugetPackages,
159
+ // autolinking template variables
160
+ autolinkPropertiesForProps: '',
161
+ autolinkProjectReferencesForTargets: '',
162
+ autolinkCsUsingNamespaces: '',
163
+ autolinkCsReactPackageProviders: '',
164
+ autolinkCppIncludes: '',
165
+ autolinkCppPackageProviders: '\n UNREFERENCED_PARAMETER(packageProviders);', // CODESYNC: @react-native-windows\cli\src\commands\autolinkWindows\autolinkWindows.ts
166
+ };
167
+ const commonMappings = projectType === 'app'
168
+ ? [
169
+ // app common mappings
170
+ {
171
+ from: path_1.default.join(srcRootPath, 'metro.config.js'),
172
+ to: 'metro.config.js',
173
+ },
174
+ {
175
+ from: path_1.default.join(srcRootPath, '_gitignore'),
176
+ to: path_1.default.join(windowsDir, '.gitignore'),
177
+ },
178
+ {
179
+ from: path_1.default.join(srcRootPath, 'b_gitignore'),
180
+ to: path_1.default.join(windowsDir, newProjectName, '.gitignore'),
181
+ },
182
+ {
183
+ from: path_1.default.join(srcRootPath, 'index.windows.bundle'),
184
+ to: path_1.default.join(windowsDir, newProjectName, bundleDir, 'index.windows.bundle'),
185
+ },
186
+ {
187
+ from: path_1.default.join(srcPath, projDir, 'MyApp.sln'),
188
+ to: path_1.default.join(windowsDir, newProjectName + '.sln'),
189
+ },
190
+ ]
191
+ : [
192
+ // lib common mappings
193
+ {
194
+ from: path_1.default.join(srcRootPath, '_gitignore'),
195
+ to: path_1.default.join(windowsDir, '.gitignore'),
196
+ },
197
+ {
198
+ from: path_1.default.join(srcPath, projDir, 'MyLib.sln'),
199
+ to: path_1.default.join(windowsDir, newProjectName + '.sln'),
200
+ },
201
+ ];
202
+ for (const mapping of commonMappings) {
203
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
204
+ }
205
+ if (language === 'cs') {
206
+ const csMappings = projectType === 'app'
207
+ ? [
208
+ // cs app mappings
209
+ {
210
+ from: path_1.default.join(srcPath, projDir, 'MyApp.csproj'),
211
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.csproj'),
212
+ },
213
+ ]
214
+ : [
215
+ // cs lib mappings
216
+ {
217
+ from: path_1.default.join(srcPath, projDir, 'MyLib.csproj'),
218
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.csproj'),
219
+ },
220
+ ];
221
+ for (const mapping of csMappings) {
222
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
223
+ }
224
+ }
225
+ else {
226
+ const cppMappings = projectType === 'app'
227
+ ? [
228
+ // cpp app mappings
229
+ {
230
+ from: path_1.default.join(srcPath, projDir, 'MyApp.vcxproj'),
231
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
232
+ },
233
+ {
234
+ from: path_1.default.join(srcPath, projDir, 'MyApp.vcxproj.filters'),
235
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
236
+ },
237
+ ]
238
+ : [
239
+ // cpp lib mappings
240
+ {
241
+ from: path_1.default.join(srcPath, projDir, 'MyLib.vcxproj'),
242
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
243
+ },
244
+ {
245
+ from: path_1.default.join(srcPath, projDir, 'MyLib.vcxproj.filters'),
246
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
247
+ },
248
+ {
249
+ from: path_1.default.join(srcPath, projDir, 'MyLib.def'),
250
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.def'),
251
+ },
252
+ ];
253
+ for (const mapping of cppMappings) {
254
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
255
+ }
256
+ }
257
+ // shared proj
258
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, projDir))) {
259
+ const sharedProjMappings = [];
260
+ sharedProjMappings.push({
261
+ from: path_1.default.join(sharedPath, projDir, 'NuGet_Config'),
262
+ to: path_1.default.join(windowsDir, 'NuGet.Config'),
263
+ });
264
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, projDir, 'ExperimentalFeatures.props'))) {
265
+ sharedProjMappings.push({
266
+ from: path_1.default.join(sharedPath, projDir, 'ExperimentalFeatures.props'),
267
+ to: path_1.default.join(windowsDir, 'ExperimentalFeatures.props'),
268
+ });
269
+ }
270
+ for (const mapping of sharedProjMappings) {
271
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
272
+ }
273
+ }
274
+ // shared assets
275
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, 'assets'))) {
276
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(sharedPath, 'assets'), destPath, path_1.default.join(windowsDir, newProjectName, 'Assets'), templateVars, options.overwrite);
277
+ }
278
+ // shared src
279
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, 'src'))) {
280
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(sharedPath, 'src'), destPath, path_1.default.join(windowsDir, newProjectName), templateVars, options.overwrite);
281
+ }
282
+ // src
283
+ if (fs_1.default.existsSync(path_1.default.join(srcPath, 'src'))) {
284
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(srcPath, 'src'), destPath, path_1.default.join(windowsDir, newProjectName), templateVars, options.overwrite);
285
+ }
286
+ if (projectType === 'app') {
287
+ console.log(chalk_1.default.white.bold('To run your app on UWP:'));
288
+ console.log(chalk_1.default.white(' npx @react-native-community/cli run-windows'));
289
+ }
290
+ }
291
+ exports.copyProjectTemplateAndReplace = copyProjectTemplateAndReplace;
292
+ function toCppNamespace(namespace) {
293
+ return namespace.replace(/\./g, '::');
294
+ }
295
+ async function installScriptsAndDependencies(options) {
296
+ var _a;
297
+ const projectPackage = await package_utils_1.WritableNpmPackage.fromPath(process.cwd());
298
+ if (!projectPackage) {
299
+ throw new Error(`The current directory '${process.cwd()}' is not the root of an npm package`);
300
+ }
301
+ await projectPackage.mergeProps({
302
+ scripts: { windows: 'npx @react-native-community/cli run-windows' },
303
+ });
304
+ const rnwPackage = await (0, package_utils_1.findPackage)('react-native-windows');
305
+ if (!rnwPackage) {
306
+ throw new Error('Could not locate the package for react-native-windows');
307
+ }
308
+ const rnPackage = await (0, package_utils_1.findPackage)('react-native');
309
+ if (!rnPackage) {
310
+ throw new Error('Could not locate the package for react-native');
311
+ }
312
+ // We add an exclusionList from metro config. This will be hoisted, but add
313
+ // an explicit dep because we require it directly.
314
+ const cliPackage = await (0, package_utils_1.findPackage)('@react-native-community/cli', {
315
+ searchPath: rnPackage.path,
316
+ });
317
+ const metroConfigPackage = await (0, package_utils_1.findPackage)('metro-config', {
318
+ searchPath: (cliPackage === null || cliPackage === void 0 ? void 0 : cliPackage.path) || rnPackage.path,
319
+ });
320
+ if (metroConfigPackage) {
321
+ await projectPackage.mergeProps({
322
+ devDependencies: {
323
+ 'metro-config': `^${metroConfigPackage.json.version}`,
324
+ },
325
+ });
326
+ }
327
+ const rnPeerDependency = rnwPackage.json.peerDependencies['react-native'];
328
+ if (!semver_1.default.satisfies(rnPackage.json.version, rnPeerDependency) &&
329
+ ((_a = projectPackage.json.dependencies) === null || _a === void 0 ? void 0 : _a['react-native'])) {
330
+ console.log(chalk_1.default.green('Installing a compatible version of react-native:'));
331
+ console.log(chalk_1.default.white(` ${rnPeerDependency}`));
332
+ // Patch package.json to have proper react-native version and install
333
+ await projectPackage.mergeProps({
334
+ dependencies: { 'react-native': rnPeerDependency },
335
+ });
336
+ // Install dependencies using correct package manager
337
+ const isYarn = fs_1.default.existsSync(path_1.default.join(process.cwd(), 'yarn.lock'));
338
+ child_process_1.default.execSync(isYarn ? 'yarn' : 'npm i', options.verbose ? { stdio: 'inherit' } : {});
339
+ }
340
+ }
341
+ exports.installScriptsAndDependencies = installScriptsAndDependencies;
365
342
  //# sourceMappingURL=index.js.map