@react-native-windows/cli 0.0.0-canary.99 → 0.0.1-0

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