@react-native-windows/cli 0.0.0-canary.28 → 0.0.0-canary.281

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 (150) 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 +433 -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/{config → commands/config}/dependencyConfig.js +229 -171
  19. package/lib-commonjs/commands/config/dependencyConfig.js.map +1 -0
  20. package/lib-commonjs/{config → commands/config}/projectConfig.d.ts +28 -25
  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 +121 -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 +290 -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 +327 -0
  37. package/lib-commonjs/commands/runWindows/runWindows.js.map +1 -0
  38. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.d.ts +54 -52
  39. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.js +128 -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/createRnwApp.test.d.ts +6 -0
  45. package/lib-commonjs/e2etest/createRnwApp.test.js +296 -0
  46. package/lib-commonjs/e2etest/createRnwApp.test.js.map +1 -0
  47. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -6
  48. package/lib-commonjs/e2etest/dependencyConfig.test.js +109 -101
  49. package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -1
  50. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -0
  51. package/lib-commonjs/e2etest/healthChecks.test.js +31 -0
  52. package/lib-commonjs/e2etest/healthChecks.test.js.map +1 -0
  53. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -0
  54. package/lib-commonjs/e2etest/initWindows.test.js +110 -0
  55. package/lib-commonjs/e2etest/initWindows.test.js.map +1 -0
  56. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -6
  57. package/lib-commonjs/e2etest/projectConfig.test.js +107 -101
  58. package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -1
  59. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -0
  60. package/lib-commonjs/e2etest/projectConfig.utils.js +54 -0
  61. package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
  62. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
  63. package/lib-commonjs/e2etest/runWindows.test.js +60 -0
  64. package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
  65. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  66. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  67. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  68. package/lib-commonjs/generator-common/index.d.ts +39 -39
  69. package/lib-commonjs/generator-common/index.js +242 -222
  70. package/lib-commonjs/generator-common/index.js.map +1 -1
  71. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  72. package/lib-commonjs/generator-windows/index.js +331 -366
  73. package/lib-commonjs/generator-windows/index.js.map +1 -1
  74. package/lib-commonjs/index.d.ts +49 -47
  75. package/lib-commonjs/index.js +77 -39
  76. package/lib-commonjs/index.js.map +1 -1
  77. package/lib-commonjs/{runWindows/utils → utils}/build.d.ts +12 -13
  78. package/lib-commonjs/{runWindows/utils → utils}/build.js +89 -91
  79. package/lib-commonjs/utils/build.js.map +1 -0
  80. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.d.ts +6 -6
  81. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.js +69 -65
  82. package/lib-commonjs/utils/checkRequirements.js.map +1 -0
  83. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.d.ts +21 -13
  84. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.js +149 -113
  85. package/lib-commonjs/utils/commandWithProgress.js.map +1 -0
  86. package/lib-commonjs/{runWindows/utils → utils}/deploy.d.ts +12 -12
  87. package/lib-commonjs/utils/deploy.js +351 -0
  88. package/lib-commonjs/utils/deploy.js.map +1 -0
  89. package/lib-commonjs/{runWindows/utils → utils}/info.d.ts +6 -6
  90. package/lib-commonjs/{runWindows/utils → utils}/info.js +28 -25
  91. package/lib-commonjs/utils/info.js.map +1 -0
  92. package/lib-commonjs/utils/msbuildtools.d.ts +28 -0
  93. package/lib-commonjs/utils/msbuildtools.js +280 -0
  94. package/lib-commonjs/utils/msbuildtools.js.map +1 -0
  95. package/lib-commonjs/utils/nameHelpers.d.ts +9 -0
  96. package/lib-commonjs/utils/nameHelpers.js +46 -0
  97. package/lib-commonjs/utils/nameHelpers.js.map +1 -0
  98. package/lib-commonjs/utils/oldArchWarning.d.ts +9 -0
  99. package/lib-commonjs/utils/oldArchWarning.js +29 -0
  100. package/lib-commonjs/utils/oldArchWarning.js.map +1 -0
  101. package/lib-commonjs/utils/pathHelpers.d.ts +6 -0
  102. package/lib-commonjs/utils/pathHelpers.js +19 -0
  103. package/lib-commonjs/utils/pathHelpers.js.map +1 -0
  104. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -0
  105. package/lib-commonjs/utils/telemetryHelpers.js +127 -0
  106. package/lib-commonjs/utils/telemetryHelpers.js.map +1 -0
  107. package/lib-commonjs/{runWindows/utils → utils}/version.d.ts +19 -19
  108. package/lib-commonjs/{runWindows/utils → utils}/version.js +109 -109
  109. package/lib-commonjs/utils/version.js.map +1 -0
  110. package/lib-commonjs/{runWindows/utils → utils}/vsInstalls.d.ts +34 -34
  111. package/lib-commonjs/utils/vsInstalls.js +102 -0
  112. package/lib-commonjs/utils/vsInstalls.js.map +1 -0
  113. package/lib-commonjs/{runWindows/utils → utils}/vstools.d.ts +16 -16
  114. package/lib-commonjs/{runWindows/utils → utils}/vstools.js +189 -157
  115. package/lib-commonjs/utils/vstools.js.map +1 -0
  116. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.d.ts +24 -24
  117. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.js +108 -105
  118. package/lib-commonjs/utils/winappdeploytool.js.map +1 -0
  119. package/package.json +50 -31
  120. package/{powershell → src/powershell}/Add-AppDevPackage.ps1 +2 -2
  121. package/src/powershell/Eval-MsBuildProperties.ps1 +156 -0
  122. package/src/powershell/WindowsStoreAppUtils.psm1 +465 -0
  123. package/CHANGELOG.json +0 -443
  124. package/CHANGELOG.md +0 -216
  125. package/lib-commonjs/config/configUtils.js +0 -253
  126. package/lib-commonjs/config/configUtils.js.map +0 -1
  127. package/lib-commonjs/config/dependencyConfig.js.map +0 -1
  128. package/lib-commonjs/config/projectConfig.js +0 -121
  129. package/lib-commonjs/config/projectConfig.js.map +0 -1
  130. package/lib-commonjs/runWindows/runWindows.js +0 -159
  131. package/lib-commonjs/runWindows/runWindows.js.map +0 -1
  132. package/lib-commonjs/runWindows/runWindowsOptions.js.map +0 -1
  133. package/lib-commonjs/runWindows/utils/autolink.d.ts +0 -7
  134. package/lib-commonjs/runWindows/utils/autolink.js +0 -404
  135. package/lib-commonjs/runWindows/utils/autolink.js.map +0 -1
  136. package/lib-commonjs/runWindows/utils/build.js.map +0 -1
  137. package/lib-commonjs/runWindows/utils/checkRequirements.js.map +0 -1
  138. package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +0 -1
  139. package/lib-commonjs/runWindows/utils/deploy.js +0 -247
  140. package/lib-commonjs/runWindows/utils/deploy.js.map +0 -1
  141. package/lib-commonjs/runWindows/utils/info.js.map +0 -1
  142. package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +0 -22
  143. package/lib-commonjs/runWindows/utils/msbuildtools.js +0 -195
  144. package/lib-commonjs/runWindows/utils/msbuildtools.js.map +0 -1
  145. package/lib-commonjs/runWindows/utils/version.js.map +0 -1
  146. package/lib-commonjs/runWindows/utils/vsInstalls.js +0 -70
  147. package/lib-commonjs/runWindows/utils/vsInstalls.js.map +0 -1
  148. package/lib-commonjs/runWindows/utils/vstools.js.map +0 -1
  149. package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +0 -1
  150. package/powershell/WindowsStoreAppUtils.ps1 +0 -264
@@ -1,367 +1,332 @@
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.7.1',
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
- autolinkPropertiesForProps: '',
190
- autolinkProjectReferencesForTargets: '',
191
- autolinkCsUsingNamespaces: '',
192
- autolinkCsReactPacakgeProviders: '',
193
- autolinkCppIncludes: '',
194
- autolinkCppPackageProviders: '\n UNREFERENCED_PARAMETER(packageProviders);',
195
- };
196
- const commonMappings = projectType === 'app'
197
- ? [
198
- // app common mappings
199
- {
200
- from: path.join(srcRootPath, 'metro.config.js'),
201
- to: 'metro.config.js',
202
- },
203
- {
204
- from: path.join(srcRootPath, '_gitignore'),
205
- to: path.join(windowsDir, '.gitignore'),
206
- },
207
- {
208
- from: path.join(srcRootPath, 'b_gitignore'),
209
- to: path.join(windowsDir, newProjectName, '.gitignore'),
210
- },
211
- {
212
- from: path.join(srcRootPath, 'index.windows.bundle'),
213
- to: path.join(windowsDir, newProjectName, bundleDir, 'index.windows.bundle'),
214
- },
215
- {
216
- from: path.join(srcPath, projDir, 'MyApp.sln'),
217
- to: path.join(windowsDir, newProjectName + '.sln'),
218
- },
219
- ]
220
- : [
221
- // lib common mappings
222
- {
223
- from: path.join(srcRootPath, '_gitignore'),
224
- to: path.join(windowsDir, '.gitignore'),
225
- },
226
- {
227
- from: path.join(srcPath, projDir, 'MyLib.sln'),
228
- to: path.join(windowsDir, newProjectName + '.sln'),
229
- },
230
- ];
231
- for (const mapping of commonMappings) {
232
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
233
- }
234
- if (language === 'cs') {
235
- const csMappings = projectType === 'app'
236
- ? [
237
- // cs app mappings
238
- {
239
- from: path.join(srcPath, projDir, 'MyApp.csproj'),
240
- to: path.join(windowsDir, newProjectName, newProjectName + '.csproj'),
241
- },
242
- ]
243
- : [
244
- // cs lib mappings
245
- {
246
- from: path.join(srcPath, projDir, 'MyLib.csproj'),
247
- to: path.join(windowsDir, newProjectName, newProjectName + '.csproj'),
248
- },
249
- ];
250
- for (const mapping of csMappings) {
251
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
252
- }
253
- }
254
- else {
255
- const cppMappings = projectType === 'app'
256
- ? [
257
- // cpp app mappings
258
- {
259
- from: path.join(srcPath, projDir, 'MyApp.vcxproj'),
260
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
261
- },
262
- {
263
- from: path.join(srcPath, projDir, 'MyApp.vcxproj.filters'),
264
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
265
- },
266
- {
267
- from: path.join(srcPath, projDir, 'packages.config'),
268
- to: path.join(windowsDir, newProjectName, 'packages.config'),
269
- },
270
- ]
271
- : [
272
- // cpp lib mappings
273
- {
274
- from: path.join(srcPath, projDir, 'MyLib.vcxproj'),
275
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
276
- },
277
- {
278
- from: path.join(srcPath, projDir, 'MyLib.vcxproj.filters'),
279
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
280
- },
281
- {
282
- from: path.join(srcPath, projDir, 'MyLib.def'),
283
- to: path.join(windowsDir, newProjectName, newProjectName + '.def'),
284
- },
285
- {
286
- from: path.join(srcPath, projDir, 'packages.config'),
287
- to: path.join(windowsDir, newProjectName, 'packages.config'),
288
- },
289
- ];
290
- for (const mapping of cppMappings) {
291
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
292
- }
293
- }
294
- // shared proj
295
- if (fs.existsSync(path.join(sharedPath, projDir))) {
296
- let sharedProjMappings = [];
297
- // Once we are publishing to nuget.org, this shouldn't be needed anymore
298
- if (options.experimentalNuGetDependency) {
299
- sharedProjMappings.push({
300
- from: path.join(sharedPath, projDir, 'NuGet.Config'),
301
- to: path.join(windowsDir, 'NuGet.Config'),
302
- });
303
- }
304
- if (fs.existsSync(path.join(sharedPath, projDir, 'BuildFlags.props'))) {
305
- sharedProjMappings.push({
306
- from: path.join(sharedPath, projDir, 'BuildFlags.props'),
307
- to: path.join(windowsDir, 'BuildFlags.props'),
308
- });
309
- }
310
- for (const mapping of sharedProjMappings) {
311
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
312
- }
313
- }
314
- // shared assets
315
- if (fs.existsSync(path.join(sharedPath, 'assets'))) {
316
- await generator_common_1.copyAndReplaceAll(path.join(sharedPath, 'assets'), destPath, path.join(windowsDir, newProjectName, 'Assets'), templateVars, options.overwrite);
317
- }
318
- // shared src
319
- if (fs.existsSync(path.join(sharedPath, 'src'))) {
320
- await generator_common_1.copyAndReplaceAll(path.join(sharedPath, 'src'), destPath, path.join(windowsDir, newProjectName), templateVars, options.overwrite);
321
- }
322
- // src
323
- if (fs.existsSync(path.join(srcPath, 'src'))) {
324
- await generator_common_1.copyAndReplaceAll(path.join(srcPath, 'src'), destPath, path.join(windowsDir, newProjectName), templateVars, options.overwrite);
325
- }
326
- if (projectType === 'app') {
327
- console.log(chalk.white.bold('To run your app on UWP:'));
328
- console.log(chalk.white(' npx react-native run-windows'));
329
- }
330
- }
331
- exports.copyProjectTemplateAndReplace = copyProjectTemplateAndReplace;
332
- function toCppNamespace(namespace) {
333
- return namespace.replace(/\./g, '::');
334
- }
335
- function installDependencies(options) {
336
- const cwd = process.cwd();
337
- // Extract react-native peer dependency version
338
- const rnwPackageJsonPath = require.resolve('react-native-windows/package.json', { paths: [process.cwd()] });
339
- const rnwPackageJson = JSON.parse(fs.readFileSync(rnwPackageJsonPath, { encoding: 'UTF8' }));
340
- let rnPeerDependency = rnwPackageJson.peerDependencies['react-native'];
341
- const depDelim = ' || ';
342
- const delimIndex = rnPeerDependency.indexOf(depDelim);
343
- if (delimIndex !== -1) {
344
- rnPeerDependency = rnPeerDependency.slice(0, delimIndex);
345
- }
346
- const rnPackageJsonPath = require.resolve('react-native/package.json', {
347
- paths: [process.cwd()],
348
- });
349
- const rnPackageJson = JSON.parse(fs.readFileSync(rnPackageJsonPath, { encoding: 'UTF8' }));
350
- if (!semver.satisfies(rnPackageJson.version, rnPeerDependency)) {
351
- console.log(chalk.green('Installing a compatible version of react-native:'));
352
- console.log(chalk.white(` ${rnPeerDependency}`));
353
- // Patch package.json to have proper react-native version and install
354
- const projectPackageJsonPath = path.join(cwd, 'package.json');
355
- const projectPackageJson = JSON.parse(fs.readFileSync(projectPackageJsonPath, { encoding: 'UTF8' }));
356
- projectPackageJson.scripts.windows = 'react-native run-windows';
357
- if (projectPackageJson.hasOwnProperty('dependencies')) {
358
- projectPackageJson.dependencies['react-native'] = rnPeerDependency;
359
- }
360
- fs.writeFileSync(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2));
361
- // Install dependencies using correct package manager
362
- const isYarn = fs.existsSync(path.join(cwd, 'yarn.lock'));
363
- childProcess.execSync(isYarn ? 'yarn' : 'npm i', options.verbose ? { stdio: 'inherit' } : {});
364
- }
365
- }
366
- 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
+ if (options.useWinUI3) {
98
+ throw new telemetry_1.CodedError('IncompatibleOptions', 'Experimental WinUI 3 project has been deprecated.');
99
+ }
100
+ const projDir = 'proj';
101
+ const srcPath = path_1.default.join(srcRootPath, `${language}-${projectType}`);
102
+ const sharedPath = path_1.default.join(srcRootPath, `shared-${projectType}`);
103
+ const projectGuid = existingProjectGuid || crypto_1.default.randomUUID();
104
+ const rnwPath = path_1.default.dirname(resolveRnwPath('package.json'));
105
+ const rnwVersion = require(resolveRnwPath('package.json')).version;
106
+ const nugetVersion = options.nuGetTestVersion || rnwVersion;
107
+ const packageGuid = crypto_1.default.randomUUID();
108
+ const currentUser = username_1.default.sync(); // Gets the current username depending on the platform.
109
+ let mainComponentName = newProjectName;
110
+ const appJsonPath = await (0, find_up_1.default)('app.json', { cwd: destPath });
111
+ if (appJsonPath) {
112
+ const appJson = await fs_1.default.readJsonFile(appJsonPath);
113
+ mainComponentName = appJson.name;
114
+ }
115
+ // We should prefer putting new, necessary PackageReference dependencies into the appropriate
116
+ // external property sheets, but this is here if we "must" inject the dependency into the project file
117
+ const csNugetPackages = [];
118
+ const cppNugetPackages = [];
119
+ const templateVars = {
120
+ useMustache: true,
121
+ regExpPatternsToRemove: [],
122
+ name: newProjectName,
123
+ namespace: namespace,
124
+ namespaceCpp: namespaceCpp,
125
+ languageIsCpp: language === 'cpp',
126
+ rnwVersion: await (0, telemetry_1.getVersionOfNpmPackage)('react-native-windows'),
127
+ rnwPathFromProjectRoot: path_1.default
128
+ .relative(destPath, rnwPath)
129
+ .replace(/\//g, '\\'),
130
+ mainComponentName: mainComponentName,
131
+ // Visual Studio is very picky about the casing of the guids for projects, project references and the solution
132
+ // https://www.bing.com/search?q=visual+studio+project+guid+casing&cvid=311a5ad7f9fc41089507b24600d23ee7&FORM=ANAB01&PC=U531
133
+ // we therefore have to precariously use the right casing in the right place or risk building in VS breaking.
134
+ projectGuidLower: `{${projectGuid.toLowerCase()}}`,
135
+ projectGuidUpper: `{${projectGuid.toUpperCase()}}`,
136
+ // packaging and signing variables:
137
+ packageGuid: packageGuid,
138
+ currentUser: currentUser,
139
+ devMode: options.useDevMode,
140
+ useExperimentalNuget: options.experimentalNuGetDependency,
141
+ nuGetTestFeed: options.nuGetTestFeed,
142
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
143
+ nuGetADOFeed: true || nugetVersion.startsWith('0.0.0-'),
144
+ // cpp template variables
145
+ useWinUI3: options.useWinUI3,
146
+ cppNugetPackages: cppNugetPackages,
147
+ // cs template variables
148
+ csNugetPackages: csNugetPackages,
149
+ // autolinking template variables
150
+ autolinkPropertiesForProps: '',
151
+ autolinkProjectReferencesForTargets: '',
152
+ autolinkCsUsingNamespaces: '',
153
+ autolinkCsReactPackageProviders: '',
154
+ autolinkCppIncludes: '',
155
+ autolinkCppPackageProviders: '\n UNREFERENCED_PARAMETER(packageProviders);', // CODESYNC: @react-native-windows\cli\src\commands\autolinkWindows\autolinkWindows.ts
156
+ };
157
+ const commonMappings = projectType === 'app'
158
+ ? [
159
+ // app common mappings
160
+ {
161
+ from: path_1.default.join(srcRootPath, 'metro.config.js'),
162
+ to: 'metro.config.js',
163
+ },
164
+ {
165
+ from: path_1.default.join(srcRootPath, '_gitignore'),
166
+ to: path_1.default.join(windowsDir, '.gitignore'),
167
+ },
168
+ {
169
+ from: path_1.default.join(srcRootPath, 'b_gitignore'),
170
+ to: path_1.default.join(windowsDir, newProjectName, '.gitignore'),
171
+ },
172
+ {
173
+ from: path_1.default.join(srcRootPath, 'index.windows.bundle'),
174
+ to: path_1.default.join(windowsDir, newProjectName, bundleDir, 'index.windows.bundle'),
175
+ },
176
+ {
177
+ from: path_1.default.join(srcPath, projDir, 'MyApp.sln'),
178
+ to: path_1.default.join(windowsDir, newProjectName + '.sln'),
179
+ },
180
+ ]
181
+ : [
182
+ // lib common mappings
183
+ {
184
+ from: path_1.default.join(srcRootPath, '_gitignore'),
185
+ to: path_1.default.join(windowsDir, '.gitignore'),
186
+ },
187
+ {
188
+ from: path_1.default.join(srcPath, projDir, 'MyLib.sln'),
189
+ to: path_1.default.join(windowsDir, newProjectName + '.sln'),
190
+ },
191
+ ];
192
+ for (const mapping of commonMappings) {
193
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
194
+ }
195
+ if (language === 'cs') {
196
+ const csMappings = projectType === 'app'
197
+ ? [
198
+ // cs app mappings
199
+ {
200
+ from: path_1.default.join(srcPath, projDir, 'MyApp.csproj'),
201
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.csproj'),
202
+ },
203
+ ]
204
+ : [
205
+ // cs lib mappings
206
+ {
207
+ from: path_1.default.join(srcPath, projDir, 'MyLib.csproj'),
208
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.csproj'),
209
+ },
210
+ ];
211
+ for (const mapping of csMappings) {
212
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
213
+ }
214
+ }
215
+ else {
216
+ const cppMappings = projectType === 'app'
217
+ ? [
218
+ // cpp app mappings
219
+ {
220
+ from: path_1.default.join(srcPath, projDir, 'MyApp.vcxproj'),
221
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
222
+ },
223
+ {
224
+ from: path_1.default.join(srcPath, projDir, 'MyApp.vcxproj.filters'),
225
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
226
+ },
227
+ ]
228
+ : [
229
+ // cpp lib mappings
230
+ {
231
+ from: path_1.default.join(srcPath, projDir, 'MyLib.vcxproj'),
232
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
233
+ },
234
+ {
235
+ from: path_1.default.join(srcPath, projDir, 'MyLib.vcxproj.filters'),
236
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
237
+ },
238
+ {
239
+ from: path_1.default.join(srcPath, projDir, 'MyLib.def'),
240
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.def'),
241
+ },
242
+ ];
243
+ for (const mapping of cppMappings) {
244
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
245
+ }
246
+ }
247
+ // shared proj
248
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, projDir))) {
249
+ const sharedProjMappings = [];
250
+ sharedProjMappings.push({
251
+ from: path_1.default.join(sharedPath, projDir, 'NuGet_Config'),
252
+ to: path_1.default.join(windowsDir, 'NuGet.Config'),
253
+ });
254
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, projDir, 'ExperimentalFeatures.props'))) {
255
+ sharedProjMappings.push({
256
+ from: path_1.default.join(sharedPath, projDir, 'ExperimentalFeatures.props'),
257
+ to: path_1.default.join(windowsDir, 'ExperimentalFeatures.props'),
258
+ });
259
+ }
260
+ for (const mapping of sharedProjMappings) {
261
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
262
+ }
263
+ }
264
+ // shared assets
265
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, 'assets'))) {
266
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(sharedPath, 'assets'), destPath, path_1.default.join(windowsDir, newProjectName, 'Assets'), templateVars, options.overwrite);
267
+ }
268
+ // shared src
269
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, 'src'))) {
270
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(sharedPath, 'src'), destPath, path_1.default.join(windowsDir, newProjectName), templateVars, options.overwrite);
271
+ }
272
+ // src
273
+ if (fs_1.default.existsSync(path_1.default.join(srcPath, 'src'))) {
274
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(srcPath, 'src'), destPath, path_1.default.join(windowsDir, newProjectName), templateVars, options.overwrite);
275
+ }
276
+ if (projectType === 'app') {
277
+ console.log(chalk_1.default.white.bold('To run your app on UWP:'));
278
+ console.log(chalk_1.default.white(' npx @react-native-community/cli run-windows'));
279
+ }
280
+ }
281
+ exports.copyProjectTemplateAndReplace = copyProjectTemplateAndReplace;
282
+ function toCppNamespace(namespace) {
283
+ return namespace.replace(/\./g, '::');
284
+ }
285
+ async function installScriptsAndDependencies(options) {
286
+ var _a;
287
+ const projectPackage = await package_utils_1.WritableNpmPackage.fromPath(process.cwd());
288
+ if (!projectPackage) {
289
+ throw new Error(`The current directory '${process.cwd()}' is not the root of an npm package`);
290
+ }
291
+ await projectPackage.mergeProps({
292
+ scripts: { windows: 'npx @react-native-community/cli run-windows' },
293
+ });
294
+ const rnwPackage = await (0, package_utils_1.findPackage)('react-native-windows');
295
+ if (!rnwPackage) {
296
+ throw new Error('Could not locate the package for react-native-windows');
297
+ }
298
+ const rnPackage = await (0, package_utils_1.findPackage)('react-native');
299
+ if (!rnPackage) {
300
+ throw new Error('Could not locate the package for react-native');
301
+ }
302
+ // We add an exclusionList from metro config. This will be hoisted, but add
303
+ // an explicit dep because we require it directly.
304
+ const rnMetroConfigPacakge = await (0, package_utils_1.findPackage)('@react-native/metro-config', {
305
+ searchPath: rnPackage.path,
306
+ });
307
+ const metroConfigPackage = await (0, package_utils_1.findPackage)('metro-config', {
308
+ searchPath: (rnMetroConfigPacakge === null || rnMetroConfigPacakge === void 0 ? void 0 : rnMetroConfigPacakge.path) || rnPackage.path,
309
+ });
310
+ if (metroConfigPackage) {
311
+ await projectPackage.mergeProps({
312
+ devDependencies: {
313
+ 'metro-config': `^${metroConfigPackage.json.version}`,
314
+ },
315
+ });
316
+ }
317
+ const rnPeerDependency = rnwPackage.json.peerDependencies['react-native'];
318
+ if (!semver_1.default.satisfies(rnPackage.json.version, rnPeerDependency) &&
319
+ ((_a = projectPackage.json.dependencies) === null || _a === void 0 ? void 0 : _a['react-native'])) {
320
+ console.log(chalk_1.default.green('Installing a compatible version of react-native:'));
321
+ console.log(chalk_1.default.white(` ${rnPeerDependency}`));
322
+ // Patch package.json to have proper react-native version and install
323
+ await projectPackage.mergeProps({
324
+ dependencies: { 'react-native': rnPeerDependency },
325
+ });
326
+ // Install dependencies using correct package manager
327
+ const isYarn = fs_1.default.existsSync(path_1.default.join(process.cwd(), 'yarn.lock'));
328
+ child_process_1.default.execSync(isYarn ? 'yarn' : 'npm i', options.verbose ? { stdio: 'inherit' } : {});
329
+ }
330
+ }
331
+ exports.installScriptsAndDependencies = installScriptsAndDependencies;
367
332
  //# sourceMappingURL=index.js.map