@react-native-windows/cli 0.0.0-canary.17 → 0.0.0-canary.171

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 (89) hide show
  1. package/README.md +47 -0
  2. package/lib-commonjs/codegen.d.ts +32 -0
  3. package/lib-commonjs/codegen.js +194 -0
  4. package/lib-commonjs/codegen.js.map +1 -0
  5. package/lib-commonjs/config/configUtils.d.ts +25 -2
  6. package/lib-commonjs/config/configUtils.js +138 -30
  7. package/lib-commonjs/config/configUtils.js.map +1 -1
  8. package/lib-commonjs/config/dependencyConfig.js +104 -43
  9. package/lib-commonjs/config/dependencyConfig.js.map +1 -1
  10. package/lib-commonjs/config/projectConfig.d.ts +4 -1
  11. package/lib-commonjs/config/projectConfig.js +72 -12
  12. package/lib-commonjs/config/projectConfig.js.map +1 -1
  13. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -0
  14. package/lib-commonjs/e2etest/autolink.test.js +366 -0
  15. package/lib-commonjs/e2etest/autolink.test.js.map +1 -0
  16. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -0
  17. package/lib-commonjs/e2etest/dependencyConfig.test.js +130 -0
  18. package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -0
  19. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -0
  20. package/lib-commonjs/e2etest/healthChecks.test.js +31 -0
  21. package/lib-commonjs/e2etest/healthChecks.test.js.map +1 -0
  22. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -0
  23. package/lib-commonjs/e2etest/projectConfig.test.js +111 -0
  24. package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -0
  25. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -0
  26. package/lib-commonjs/e2etest/projectConfig.utils.js +77 -0
  27. package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
  28. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
  29. package/lib-commonjs/e2etest/runWindows.test.js +61 -0
  30. package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
  31. package/lib-commonjs/generator-common/index.d.ts +17 -1
  32. package/lib-commonjs/generator-common/index.js +60 -39
  33. package/lib-commonjs/generator-common/index.js.map +1 -1
  34. package/lib-commonjs/generator-windows/index.d.ts +2 -2
  35. package/lib-commonjs/generator-windows/index.js +184 -202
  36. package/lib-commonjs/generator-windows/index.js.map +1 -1
  37. package/lib-commonjs/healthCheckList.d.ts +1 -0
  38. package/lib-commonjs/healthCheckList.js +16 -0
  39. package/lib-commonjs/healthCheckList.js.map +1 -0
  40. package/lib-commonjs/healthChecks.d.ts +2 -0
  41. package/lib-commonjs/healthChecks.js +84 -0
  42. package/lib-commonjs/healthChecks.js.map +1 -0
  43. package/lib-commonjs/index.d.ts +4 -0
  44. package/lib-commonjs/index.js +30 -9
  45. package/lib-commonjs/index.js.map +1 -1
  46. package/lib-commonjs/runWindows/runWindows.js +220 -55
  47. package/lib-commonjs/runWindows/runWindows.js.map +1 -1
  48. package/lib-commonjs/runWindows/runWindowsOptions.d.ts +15 -11
  49. package/lib-commonjs/runWindows/runWindowsOptions.js +19 -11
  50. package/lib-commonjs/runWindows/runWindowsOptions.js.map +1 -1
  51. package/lib-commonjs/runWindows/utils/autolink.d.ts +88 -1
  52. package/lib-commonjs/runWindows/utils/autolink.js +593 -260
  53. package/lib-commonjs/runWindows/utils/autolink.js.map +1 -1
  54. package/lib-commonjs/runWindows/utils/build.d.ts +1 -2
  55. package/lib-commonjs/runWindows/utils/build.js +24 -31
  56. package/lib-commonjs/runWindows/utils/build.js.map +1 -1
  57. package/lib-commonjs/runWindows/utils/checkRequirements.js +11 -7
  58. package/lib-commonjs/runWindows/utils/checkRequirements.js.map +1 -1
  59. package/lib-commonjs/runWindows/utils/commandWithProgress.d.ts +11 -3
  60. package/lib-commonjs/runWindows/utils/commandWithProgress.js +58 -22
  61. package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +1 -1
  62. package/lib-commonjs/runWindows/utils/deploy.d.ts +1 -1
  63. package/lib-commonjs/runWindows/utils/deploy.js +168 -82
  64. package/lib-commonjs/runWindows/utils/deploy.js.map +1 -1
  65. package/lib-commonjs/runWindows/utils/info.js +5 -2
  66. package/lib-commonjs/runWindows/utils/info.js.map +1 -1
  67. package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +12 -6
  68. package/lib-commonjs/runWindows/utils/msbuildtools.js +145 -66
  69. package/lib-commonjs/runWindows/utils/msbuildtools.js.map +1 -1
  70. package/lib-commonjs/runWindows/utils/telemetryHelpers.d.ts +29 -0
  71. package/lib-commonjs/runWindows/utils/telemetryHelpers.js +113 -0
  72. package/lib-commonjs/runWindows/utils/telemetryHelpers.js.map +1 -0
  73. package/lib-commonjs/runWindows/utils/version.d.ts +4 -4
  74. package/lib-commonjs/runWindows/utils/version.js.map +1 -1
  75. package/lib-commonjs/runWindows/utils/vsInstalls.d.ts +2 -2
  76. package/lib-commonjs/runWindows/utils/vsInstalls.js +40 -10
  77. package/lib-commonjs/runWindows/utils/vsInstalls.js.map +1 -1
  78. package/lib-commonjs/runWindows/utils/vstools.d.ts +1 -0
  79. package/lib-commonjs/runWindows/utils/vstools.js +73 -33
  80. package/lib-commonjs/runWindows/utils/vstools.js.map +1 -1
  81. package/lib-commonjs/runWindows/utils/winappdeploytool.d.ts +3 -3
  82. package/lib-commonjs/runWindows/utils/winappdeploytool.js +17 -14
  83. package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +1 -1
  84. package/package.json +46 -23
  85. package/powershell/Add-AppDevPackage.ps1 +2 -2
  86. package/powershell/Eval-MsBuildProperties.ps1 +156 -0
  87. package/powershell/WindowsStoreAppUtils.ps1 +10 -0
  88. package/CHANGELOG.json +0 -251
  89. package/CHANGELOG.md +0 -126
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator-common/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,yBAAyB;AACzB,+BAA+B;AAC/B,q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AAW,CAAC,CAAC,CAAC,MAAM,CAAC;KAC7C;IACD,IAAI,cAAc,KAAK,WAAW,EAAE;QAClC,OAAO,MAAM,CAAC;KACf;IACD,MAAM,IAAI,sBAAU,CAClB,aAAa,EACb,+BAA+B,gBAAgB,KAAK,cAAc,EAAE,CACrE,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport fs from '@react-native-windows/fs';\nimport chalk from 'chalk';\nimport prompts from 'prompts';\nimport path from 'path';\nimport mustache from 'mustache';\nimport {CodedError} from '@react-native-windows/telemetry';\n\n/**\n * Text to replace, + config options\n */\nexport type Replacements = {\n useMustache?: boolean;\n regExpPatternsToRemove?: RegExp[];\n [key: string]: any;\n};\n\nfunction walk(current: string): string[] {\n if (!fs.lstatSync(current).isDirectory()) {\n return [current];\n }\n\n const files = fs\n .readdirSync(current)\n .map(child => walk(path.join(current, child)));\n const result: string[] = [];\n return result.concat.apply([current], files);\n}\n\n/**\n * Get a source file and replace parts of its contents.\n * @param srcPath Path to the source file.\n * @param replacements e.g. {'TextToBeReplaced': 'Replacement'}\n * @return The contents of the file with the replacements applied.\n */\nexport function resolveContents(\n srcPath: string,\n replacements: Replacements,\n): string {\n let content = fs.readFileSync(srcPath, 'utf8');\n\n if (content.includes('\\r\\n')) {\n // CRLF file, make sure multiline replacements are also CRLF\n for (const key of Object.keys(replacements)) {\n if (typeof replacements[key] === 'string') {\n replacements[key] = replacements[key].replace(/(?<!\\r)\\n/g, '\\r\\n');\n }\n }\n } else {\n // LF file, make sure multiline replacements are also LF\n for (const key of Object.keys(replacements)) {\n if (typeof replacements[key] === 'string') {\n replacements[key] = replacements[key].replace(/\\r\\n/g, '\\n');\n }\n }\n }\n\n if (replacements.useMustache) {\n content = mustache.render(content, replacements);\n (replacements.regExpPatternsToRemove || []).forEach(regexPattern => {\n content = content.replace(new RegExp(regexPattern, 'g'), '');\n });\n } else {\n Object.keys(replacements).forEach(regex => {\n content = content.replace(new RegExp(regex, 'g'), replacements[regex]);\n });\n }\n return content;\n}\n\n// Binary files, don't process these (avoid decoding as utf8)\nconst binaryExtensions = ['.png', '.jar', '.keystore'];\n\ntype ContentChangedCallbackOption = 'identical' | 'changed' | 'new' | null;\n\ntype ContentChangedCallback = (\n path: string,\n option: ContentChangedCallbackOption,\n) => Promise<'keep' | 'overwrite'>;\n\n/**\n * Copy a file to given destination, replacing parts of its contents.\n * @param srcPath Path to a file to be copied.\n * @param destPath Destination path.\n * @param replacements: e.g. {'TextToBeReplaced': 'Replacement'}\n * @param contentChangedCallback\n * Used when upgrading projects. Based on if file contents would change\n * when being replaced, allows the caller to specify whether the file\n * should be replaced or not.\n * If null, files will be overwritten.\n * Function(path, 'identical' | 'changed' | 'new') => 'keep' | 'overwrite'\n */\nexport async function copyAndReplace(\n srcPath: string,\n destPath: string,\n replacements: Replacements,\n contentChangedCallback: ContentChangedCallback | null,\n) {\n if (fs.lstatSync(srcPath).isDirectory()) {\n if (!fs.existsSync(destPath)) {\n fs.mkdirSync(destPath);\n }\n // Not recursive\n return;\n }\n\n const extension = path.extname(srcPath);\n if (binaryExtensions.includes(extension)) {\n // Binary file\n let shouldOverwrite = 'overwrite';\n if (contentChangedCallback) {\n const newContentBuffer = fs.readFileSync(srcPath);\n let contentChanged: ContentChangedCallbackOption = 'identical';\n try {\n const origContentBuffer = fs.readFileSync(destPath);\n if (Buffer.compare(origContentBuffer, newContentBuffer) !== 0) {\n contentChanged = 'changed';\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n contentChanged = 'new';\n } else {\n throw err;\n }\n }\n shouldOverwrite = await contentChangedCallback(destPath, contentChanged);\n }\n if (shouldOverwrite === 'overwrite') {\n copyBinaryFile(srcPath, destPath, err => {\n if (err) {\n throw err;\n }\n });\n }\n } else {\n // Text file\n const srcPermissions = fs.statSync(srcPath).mode;\n const content = resolveContents(srcPath, replacements);\n\n let shouldOverwrite = 'overwrite';\n if (contentChangedCallback) {\n // Check if contents changed and ask to overwrite\n let contentChanged: ContentChangedCallbackOption = 'identical';\n try {\n const origContent = fs.readFileSync(destPath, 'utf8');\n if (content !== origContent) {\n // logger.info('Content changed: ' + destPath);\n contentChanged = 'changed';\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') {\n contentChanged = 'new';\n } else {\n throw err;\n }\n }\n shouldOverwrite = await contentChangedCallback(destPath, contentChanged);\n }\n if (shouldOverwrite === 'overwrite') {\n fs.writeFileSync(destPath, content, {\n encoding: 'utf8',\n mode: srcPermissions,\n });\n }\n }\n}\n\n/**\n * Same as 'cp' on Unix. Don't do any replacements.\n */\nfunction copyBinaryFile(\n srcPath: string,\n destPath: string,\n cb: (err?: Error) => void,\n) {\n let cbCalled = false;\n const srcPermissions = fs.statSync(srcPath).mode;\n const readStream = fs.createReadStream(srcPath);\n readStream.on('error', err => {\n done(err);\n });\n const writeStream = fs.createWriteStream(destPath, {\n mode: srcPermissions,\n });\n writeStream.on('error', err => {\n done(err);\n });\n writeStream.on('close', () => {\n done();\n });\n readStream.pipe(writeStream);\n function done(err?: Error) {\n if (!cbCalled) {\n cb(err);\n cbCalled = true;\n }\n }\n}\n\nexport function createDir(destPath: string) {\n if (!fs.existsSync(destPath)) {\n fs.mkdirSync(destPath);\n }\n}\n\nexport async function copyAndReplaceWithChangedCallback(\n srcPath: string,\n destRoot: string,\n relativeDestPath: string,\n replacements?: Record<string, string>,\n alwaysOverwrite?: boolean,\n) {\n if (!replacements) {\n replacements = {};\n }\n const contentChangedCallback: ContentChangedCallback = alwaysOverwrite\n ? (_, contentChanged) =>\n alwaysOverwriteContentChangedCallback(\n srcPath,\n relativeDestPath,\n contentChanged,\n )\n : (_, contentChanged) =>\n upgradeFileContentChangedCallback(\n srcPath,\n relativeDestPath,\n contentChanged,\n );\n\n await copyAndReplace(\n srcPath,\n path.join(destRoot, relativeDestPath),\n replacements,\n contentChangedCallback,\n );\n}\n\nexport async function copyAndReplaceAll(\n srcPath: string,\n destPath: string,\n relativeDestDir: string,\n replacements: Replacements,\n alwaysOverwrite: boolean,\n) {\n for (const absoluteSrcFilePath of walk(srcPath)) {\n const filename = path.relative(srcPath, absoluteSrcFilePath);\n const relativeDestPath = path.join(relativeDestDir, filename);\n await copyAndReplaceWithChangedCallback(\n absoluteSrcFilePath,\n destPath,\n relativeDestPath,\n replacements,\n alwaysOverwrite,\n );\n }\n}\n\nasync function alwaysOverwriteContentChangedCallback(\n absoluteSrcFilePath: string,\n relativeDestPath: string,\n contentChanged: ContentChangedCallbackOption,\n): Promise<'keep' | 'overwrite'> {\n if (contentChanged === 'new') {\n console.log(`${chalk.bold('new')} ${relativeDestPath}`);\n return 'overwrite';\n }\n if (contentChanged === 'changed') {\n console.log(\n `${chalk.bold('changed')} ${relativeDestPath} ${chalk.yellow(\n '[overwriting]',\n )}`,\n );\n return 'overwrite';\n }\n if (contentChanged === 'identical') {\n return 'keep';\n }\n throw new CodedError(\n 'Autolinking',\n `Unknown file changed state: ${relativeDestPath}, ${contentChanged}`,\n );\n}\n\nasync function upgradeFileContentChangedCallback(\n absoluteSrcFilePath: string,\n relativeDestPath: string,\n contentChanged: ContentChangedCallbackOption,\n): Promise<'keep' | 'overwrite'> {\n if (contentChanged === 'new') {\n console.log(`${chalk.bold('new')} ${relativeDestPath}`);\n return 'overwrite';\n }\n if (contentChanged === 'changed') {\n console.log(\n `${chalk.bold(relativeDestPath)} ` +\n `has changed in the new version.\\nDo you want to keep your ${relativeDestPath} or replace it with the ` +\n 'latest version?\\nMake sure you have any changes you made to this file saved somewhere.\\n' +\n `You can see the new version here: ${absoluteSrcFilePath}`,\n );\n\n const {shouldReplace} = await prompts([\n {\n name: 'shouldReplace',\n type: 'confirm',\n message: `Do you want to replace ${relativeDestPath}?`,\n initial: false,\n },\n ]);\n\n return shouldReplace ? 'overwrite' : 'keep';\n }\n if (contentChanged === 'identical') {\n return 'keep';\n }\n throw new CodedError(\n 'Autolinking',\n `Unknown file changed state: ${relativeDestPath}, ${contentChanged}`,\n );\n}\n"]}
@@ -5,6 +5,6 @@
5
5
  */
6
6
  import { GenerateOptions } from '..';
7
7
  export declare function copyProjectTemplateAndReplace(srcRootPath: string, destPath: string, newProjectName: string, namespace: string, options: GenerateOptions): Promise<void>;
8
- export declare function installDependencies(options: {
8
+ export declare function installScriptsAndDependencies(options: {
9
9
  verbose: boolean;
10
- }): void;
10
+ }): Promise<void>;
@@ -4,153 +4,117 @@
4
4
  * Licensed under the MIT License.
5
5
  * @format
6
6
  */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
7
10
  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");
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"));
18
21
  const configUtils_1 = require("../config/configUtils");
19
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");
20
25
  const windowsDir = 'windows';
21
26
  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 -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 -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;
27
+ function pascalCase(str) {
28
+ const camelCase = lodash_1.default.camelCase(str);
29
+ return camelCase[0].toUpperCase() + camelCase.substr(1);
52
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
53
38
  async function copyProjectTemplateAndReplace(srcRootPath, destPath, newProjectName, namespace, options) {
54
39
  if (!srcRootPath) {
55
- throw new Error('Need a path to copy from');
40
+ throw new telemetry_1.CodedError('CopyProjectTemplateNoSourcePath', 'Need a path to copy from');
56
41
  }
57
42
  if (!destPath) {
58
- throw new Error('Need a path to copy to');
43
+ throw new telemetry_1.CodedError('CopyProjectTemplateNoDestPath', 'Need a path to copy to');
59
44
  }
60
45
  if (!newProjectName) {
61
- throw new Error('Need a project name');
46
+ throw new telemetry_1.CodedError('CopyProjectTemplateNoProjectName', 'Need a project name');
62
47
  }
63
48
  const projectType = options.projectType;
49
+ const language = options.language;
64
50
  // React-native init only allows alphanumerics in project names, but other
65
51
  // new project tools (like create-react-native-module) are less strict.
66
- newProjectName = _.camelCase(newProjectName);
52
+ if (projectType === 'lib') {
53
+ newProjectName = pascalCase(newProjectName);
54
+ }
67
55
  // Similar to the above, but we want to retain namespace separators
68
- namespace = namespace
69
- .split(/[\.\:]+/)
70
- .map(_.camelCase)
71
- .join('.');
72
- generator_common_1.createDir(path.join(destPath, windowsDir));
73
- generator_common_1.createDir(path.join(destPath, windowsDir, newProjectName));
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));
74
68
  if (projectType === 'app') {
75
- generator_common_1.createDir(path.join(destPath, windowsDir, newProjectName, bundleDir));
76
- generator_common_1.createDir(path.join(destPath, windowsDir, newProjectName, 'BundleBuilder'));
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'));
77
71
  }
78
- const language = options.language;
79
72
  const namespaceCpp = toCppNamespace(namespace);
80
73
  if (options.experimentalNuGetDependency) {
81
74
  console.log('Using experimental NuGet dependency.');
82
75
  }
76
+ let realProjectType = projectType;
83
77
  if (options.useWinUI3) {
84
78
  console.log('Using experimental WinUI3 dependency.');
85
- fs.writeFileSync(path.join(destPath, windowsDir, 'UseWinUI3'), '');
79
+ if (projectType === 'lib') {
80
+ throw new telemetry_1.CodedError('IncompatibleOptions', 'WinUI 3 project template only supports apps at the moment', {
81
+ detail: 'useWinUI3 and lib',
82
+ });
83
+ }
84
+ else if (language !== 'cs') {
85
+ throw new telemetry_1.CodedError('IncompatibleOptions', 'WinUI 3 project template only support C# at the moment', {
86
+ detail: 'useWinUI3 and cpp',
87
+ });
88
+ }
89
+ realProjectType += '-WinAppSDK';
86
90
  }
87
91
  const projDir = 'proj';
88
- const srcPath = path.join(srcRootPath, `${language}-${projectType}`);
89
- const sharedPath = path.join(srcRootPath, `shared-${projectType}`);
90
- const projectGuid = uuid.v4();
91
- const rnwVersion = require('react-native-windows/package.json').version;
92
+ const srcPath = path_1.default.join(srcRootPath, `${language}-${realProjectType}`);
93
+ const sharedPath = path_1.default.join(srcRootPath, `shared-${projectType}`);
94
+ const projectGuid = existingProjectGuid || uuid_1.default.v4();
95
+ const rnwVersion = require(resolveRnwPath('package.json')).version;
92
96
  const nugetVersion = options.nuGetTestVersion || rnwVersion;
93
- const packageGuid = uuid.v4();
94
- const currentUser = username.sync(); // Gets the current username depending on the platform.
95
- const certificateThumbprint = projectType === 'app'
96
- ? await generateCertificate(srcPath, destPath, newProjectName, currentUser)
97
- : null;
98
- const xamlNamespace = options.useWinUI3
99
- ? 'Microsoft.UI.Xaml'
100
- : 'Windows.UI.Xaml';
101
- const xamlNamespaceCpp = toCppNamespace(xamlNamespace);
102
- const winui3PropsPath = require.resolve('react-native-windows/PropertySheets/WinUI.props', { paths: [process.cwd()] });
103
- const winui3Props = configUtils_1.readProjectFile(winui3PropsPath);
104
- const winui3Version = configUtils_1.findPropertyValue(winui3Props, 'WinUI3Version');
105
- if (winui3Version === null) {
106
- throw new Error('Unable to find WinUI3 version from property sheets');
107
- }
108
- const csNugetPackages = [
109
- {
110
- id: 'Microsoft.NETCore.UniversalWindowsPlatform',
111
- version: '6.2.9',
112
- },
113
- ];
114
- const cppNugetPackages = [
115
- {
116
- id: 'Microsoft.Windows.CppWinRT',
117
- version: '2.0.200615.7',
118
- propsTopOfFile: true,
119
- hasProps: true,
120
- hasTargets: true,
121
- },
122
- {
123
- id: options.useWinUI3 ? 'Microsoft.WinUI' : 'Microsoft.UI.Xaml',
124
- version: options.useWinUI3 ? winui3Version : '2.3.191129002',
125
- hasProps: false,
126
- hasTargets: false,
127
- },
128
- ];
129
- if (options.experimentalNuGetDependency) {
130
- csNugetPackages.push({
131
- id: 'Microsoft.ReactNative.Managed',
132
- version: nugetVersion,
133
- });
134
- cppNugetPackages.push({
135
- id: 'Microsoft.ReactNative',
136
- version: nugetVersion,
137
- hasProps: false,
138
- hasTargets: true,
139
- });
140
- cppNugetPackages.push({
141
- id: 'Microsoft.ReactNative.Cxx',
142
- version: nugetVersion,
143
- hasProps: false,
144
- hasTargets: true,
145
- });
97
+ const packageGuid = uuid_1.default.v4();
98
+ const currentUser = username_1.default.sync(); // Gets the current username depending on the platform.
99
+ let mainComponentName = newProjectName;
100
+ const appJsonPath = await (0, find_up_1.default)('app.json', { cwd: destPath });
101
+ if (appJsonPath) {
102
+ const appJson = await fs_1.default.readJsonFile(appJsonPath);
103
+ mainComponentName = appJson.name;
146
104
  }
105
+ // We should prefer putting new, necessary PackageReference dependencies into the appropriate
106
+ // external property sheets, but this is here if we "must" inject the dependency into the project file
107
+ const csNugetPackages = [];
108
+ const cppNugetPackages = [];
147
109
  const templateVars = {
148
110
  useMustache: true,
149
- regExpPatternsToRemove: ['//\\sclang-format\\s(on|off)\\s'],
111
+ regExpPatternsToRemove: [],
150
112
  name: newProjectName,
151
113
  namespace: namespace,
152
114
  namespaceCpp: namespaceCpp,
153
115
  languageIsCpp: language === 'cpp',
116
+ rnwVersion: await (0, telemetry_1.getVersionOfNpmPackage)('react-native-windows'),
117
+ mainComponentName: mainComponentName,
154
118
  // Visual Studio is very picky about the casing of the guids for projects, project references and the solution
155
119
  // https://www.bing.com/search?q=visual+studio+project+guid+casing&cvid=311a5ad7f9fc41089507b24600d23ee7&FORM=ANAB01&PC=U531
156
120
  // we therefore have to precariously use the right casing in the right place or risk building in VS breaking.
@@ -159,79 +123,81 @@ async function copyProjectTemplateAndReplace(srcRootPath, destPath, newProjectNa
159
123
  // packaging and signing variables:
160
124
  packageGuid: packageGuid,
161
125
  currentUser: currentUser,
162
- certificateThumbprint: certificateThumbprint,
163
126
  useExperimentalNuget: options.experimentalNuGetDependency,
164
127
  nuGetTestFeed: options.nuGetTestFeed,
128
+ nuGetADOFeed: nugetVersion.startsWith('0.0.0-'),
165
129
  // cpp template variables
166
130
  useWinUI3: options.useWinUI3,
167
- xamlNamespace: xamlNamespace,
168
- xamlNamespaceCpp: xamlNamespaceCpp,
131
+ useHermes: options.useHermes,
169
132
  cppNugetPackages: cppNugetPackages,
170
133
  // cs template variables
171
134
  csNugetPackages: csNugetPackages,
172
135
  // autolinking template variables
136
+ autolinkPropertiesForProps: '',
173
137
  autolinkProjectReferencesForTargets: '',
174
138
  autolinkCsUsingNamespaces: '',
175
- autolinkCsReactPacakgeProviders: '',
139
+ autolinkCsReactPackageProviders: '',
176
140
  autolinkCppIncludes: '',
177
- autolinkCppPackageProviders: '\n UNREFERENCED_PARAMETER(packageProviders);',
141
+ autolinkCppPackageProviders: '\n UNREFERENCED_PARAMETER(packageProviders);', // CODESYNC: vnext\local-cli\runWindows\utils\autolink.js
178
142
  };
179
143
  const commonMappings = projectType === 'app'
180
144
  ? [
181
145
  // app common mappings
182
146
  {
183
- from: path.join(srcRootPath, 'metro.config.js'),
147
+ from: path_1.default.join(srcRootPath, options.useDevMode
148
+ ? 'metro.devMode.config.js'
149
+ : 'metro.config.js'),
184
150
  to: 'metro.config.js',
185
151
  },
186
152
  {
187
- from: path.join(srcRootPath, '_gitignore'),
188
- to: path.join(windowsDir, '.gitignore'),
153
+ from: path_1.default.join(srcRootPath, '_gitignore'),
154
+ to: path_1.default.join(windowsDir, '.gitignore'),
189
155
  },
190
156
  {
191
- from: path.join(srcRootPath, 'b_gitignore'),
192
- to: path.join(windowsDir, newProjectName, '.gitignore'),
157
+ from: path_1.default.join(srcRootPath, 'b_gitignore'),
158
+ to: path_1.default.join(windowsDir, newProjectName, '.gitignore'),
193
159
  },
194
160
  {
195
- from: path.join(srcRootPath, 'index.windows.bundle'),
196
- to: path.join(windowsDir, newProjectName, bundleDir, 'index.windows.bundle'),
161
+ from: path_1.default.join(srcRootPath, 'index.windows.bundle'),
162
+ to: path_1.default.join(windowsDir, newProjectName, bundleDir, 'index.windows.bundle'),
197
163
  },
198
164
  {
199
- from: path.join(srcPath, projDir, 'MyApp.sln'),
200
- to: path.join(windowsDir, newProjectName + '.sln'),
165
+ from: path_1.default.join(srcPath, projDir, 'MyApp.sln'),
166
+ to: path_1.default.join(windowsDir, newProjectName + '.sln'),
201
167
  },
202
168
  ]
203
169
  : [
204
170
  // lib common mappings
205
171
  {
206
- from: path.join(srcRootPath, '_gitignore'),
207
- to: path.join(windowsDir, '.gitignore'),
172
+ from: path_1.default.join(srcRootPath, '_gitignore'),
173
+ to: path_1.default.join(windowsDir, '.gitignore'),
208
174
  },
209
175
  {
210
- from: path.join(srcPath, projDir, 'MyLib.sln'),
211
- to: path.join(windowsDir, newProjectName + '.sln'),
176
+ from: path_1.default.join(srcPath, projDir, 'MyLib.sln'),
177
+ to: path_1.default.join(windowsDir, newProjectName + '.sln'),
212
178
  },
213
179
  ];
214
180
  for (const mapping of commonMappings) {
215
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
181
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
216
182
  }
217
183
  if (language === 'cs') {
218
184
  const csMappings = projectType === 'app'
219
185
  ? [
220
186
  // cs app mappings
221
187
  {
222
- from: path.join(srcPath, projDir, 'MyApp.csproj'),
223
- to: path.join(windowsDir, newProjectName, newProjectName + '.csproj'),
188
+ from: path_1.default.join(srcPath, projDir, 'MyApp.csproj'),
189
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.csproj'),
224
190
  },
225
191
  ]
226
192
  : [
227
193
  // cs lib mappings
228
194
  {
229
- from: path.join(srcPath, projDir, 'MyLib.csproj'),
230
- to: path.join(windowsDir, newProjectName, newProjectName + '.csproj'),
195
+ from: path_1.default.join(srcPath, projDir, 'MyLib.csproj'),
196
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.csproj'),
231
197
  },
232
198
  ];
233
199
  for (const mapping of csMappings) {
234
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
200
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
235
201
  }
236
202
  }
237
203
  else {
@@ -239,107 +205,123 @@ async function copyProjectTemplateAndReplace(srcRootPath, destPath, newProjectNa
239
205
  ? [
240
206
  // cpp app mappings
241
207
  {
242
- from: path.join(srcPath, projDir, 'MyApp.vcxproj'),
243
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
244
- },
245
- {
246
- from: path.join(srcPath, projDir, 'MyApp.vcxproj.filters'),
247
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
208
+ from: path_1.default.join(srcPath, projDir, 'MyApp.vcxproj'),
209
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
248
210
  },
249
211
  {
250
- from: path.join(srcPath, projDir, 'packages.config'),
251
- to: path.join(windowsDir, newProjectName, 'packages.config'),
212
+ from: path_1.default.join(srcPath, projDir, 'MyApp.vcxproj.filters'),
213
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
252
214
  },
253
215
  ]
254
216
  : [
255
217
  // cpp lib mappings
256
218
  {
257
- from: path.join(srcPath, projDir, 'MyLib.vcxproj'),
258
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
259
- },
260
- {
261
- from: path.join(srcPath, projDir, 'MyLib.vcxproj.filters'),
262
- to: path.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
219
+ from: path_1.default.join(srcPath, projDir, 'MyLib.vcxproj'),
220
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj'),
263
221
  },
264
222
  {
265
- from: path.join(srcPath, projDir, 'MyLib.def'),
266
- to: path.join(windowsDir, newProjectName, newProjectName + '.def'),
223
+ from: path_1.default.join(srcPath, projDir, 'MyLib.vcxproj.filters'),
224
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.vcxproj.filters'),
267
225
  },
268
226
  {
269
- from: path.join(srcPath, projDir, 'packages.config'),
270
- to: path.join(windowsDir, newProjectName, 'packages.config'),
227
+ from: path_1.default.join(srcPath, projDir, 'MyLib.def'),
228
+ to: path_1.default.join(windowsDir, newProjectName, newProjectName + '.def'),
271
229
  },
272
230
  ];
273
231
  for (const mapping of cppMappings) {
274
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
232
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
275
233
  }
276
234
  }
277
235
  // shared proj
278
- if (fs.existsSync(path.join(sharedPath, projDir))) {
279
- // Once we are publishing to nuget.org, this shouldn't be needed anymore
280
- if (options.experimentalNuGetDependency) {
281
- const nugetMappings = [
282
- {
283
- from: path.join(sharedPath, projDir, 'NuGet.Config'),
284
- to: path.join(windowsDir, 'NuGet.Config'),
285
- },
286
- ];
287
- for (const mapping of nugetMappings) {
288
- await generator_common_1.copyAndReplaceWithChangedCallback(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
289
- }
236
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, projDir))) {
237
+ const sharedProjMappings = [];
238
+ sharedProjMappings.push({
239
+ from: path_1.default.join(sharedPath, projDir, 'NuGet_Config'),
240
+ to: path_1.default.join(windowsDir, 'NuGet.Config'),
241
+ });
242
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, projDir, 'ExperimentalFeatures.props'))) {
243
+ sharedProjMappings.push({
244
+ from: path_1.default.join(sharedPath, projDir, 'ExperimentalFeatures.props'),
245
+ to: path_1.default.join(windowsDir, 'ExperimentalFeatures.props'),
246
+ });
247
+ }
248
+ for (const mapping of sharedProjMappings) {
249
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(mapping.from, destPath, mapping.to, templateVars, options.overwrite);
290
250
  }
291
251
  }
292
252
  // shared assets
293
- if (fs.existsSync(path.join(sharedPath, 'assets'))) {
294
- await generator_common_1.copyAndReplaceAll(path.join(sharedPath, 'assets'), destPath, path.join(windowsDir, newProjectName, 'Assets'), templateVars, options.overwrite);
253
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, 'assets'))) {
254
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(sharedPath, 'assets'), destPath, path_1.default.join(windowsDir, newProjectName, 'Assets'), templateVars, options.overwrite);
295
255
  }
296
- // shared src
297
- if (fs.existsSync(path.join(sharedPath, 'src'))) {
298
- await generator_common_1.copyAndReplaceAll(path.join(sharedPath, 'src'), destPath, path.join(windowsDir, newProjectName), templateVars, options.overwrite);
256
+ if (!options.useWinUI3) {
257
+ // shared src
258
+ if (fs_1.default.existsSync(path_1.default.join(sharedPath, 'src'))) {
259
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(sharedPath, 'src'), destPath, path_1.default.join(windowsDir, newProjectName), templateVars, options.overwrite);
260
+ }
261
+ }
262
+ else {
263
+ if (fs_1.default.existsSync(path_1.default.join(srcPath, 'MyApp'))) {
264
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(srcPath, 'MyApp'), destPath, path_1.default.join(windowsDir, newProjectName), templateVars, options.overwrite);
265
+ }
299
266
  }
300
267
  // src
301
- if (fs.existsSync(path.join(srcPath, 'src'))) {
302
- await generator_common_1.copyAndReplaceAll(path.join(srcPath, 'src'), destPath, path.join(windowsDir, newProjectName), templateVars, options.overwrite);
268
+ if (fs_1.default.existsSync(path_1.default.join(srcPath, 'src'))) {
269
+ await (0, generator_common_1.copyAndReplaceAll)(path_1.default.join(srcPath, 'src'), destPath, path_1.default.join(windowsDir, newProjectName), templateVars, options.overwrite);
303
270
  }
304
271
  if (projectType === 'app') {
305
- console.log(chalk.white.bold('To run your app on UWP:'));
306
- console.log(chalk.white(' npx react-native run-windows'));
272
+ console.log(chalk_1.default.white.bold('To run your app on UWP:'));
273
+ console.log(chalk_1.default.white(' npx react-native run-windows'));
307
274
  }
308
275
  }
309
276
  exports.copyProjectTemplateAndReplace = copyProjectTemplateAndReplace;
310
277
  function toCppNamespace(namespace) {
311
278
  return namespace.replace(/\./g, '::');
312
279
  }
313
- function installDependencies(options) {
314
- const cwd = process.cwd();
315
- // Extract react-native peer dependency version
316
- const rnwPackageJsonPath = require.resolve('react-native-windows/package.json', { paths: [process.cwd()] });
317
- const rnwPackageJson = JSON.parse(fs.readFileSync(rnwPackageJsonPath, { encoding: 'UTF8' }));
318
- let rnPeerDependency = rnwPackageJson.peerDependencies['react-native'];
319
- const depDelim = ' || ';
320
- const delimIndex = rnPeerDependency.indexOf(depDelim);
321
- if (delimIndex !== -1) {
322
- rnPeerDependency = rnPeerDependency.slice(0, delimIndex);
280
+ async function installScriptsAndDependencies(options) {
281
+ var _a;
282
+ const projectPackage = await package_utils_1.WritableNpmPackage.fromPath(process.cwd());
283
+ if (!projectPackage) {
284
+ throw new Error(`The current directory '${process.cwd()}' is not the root of an npm package`);
323
285
  }
324
- const rnPackageJsonPath = require.resolve('react-native/package.json', {
325
- paths: [process.cwd()],
286
+ await projectPackage.mergeProps({
287
+ scripts: { windows: 'react-native run-windows' },
288
+ });
289
+ const rnwPackage = await (0, package_utils_1.findPackage)('react-native-windows');
290
+ if (!rnwPackage) {
291
+ throw new Error('Could not locate the package for react-native-windows');
292
+ }
293
+ const rnPackage = await (0, package_utils_1.findPackage)('react-native');
294
+ if (!rnPackage) {
295
+ throw new Error('Could not locate the package for react-native');
296
+ }
297
+ // We add an exclusionList from metro config. This will be hoisted, but add
298
+ // an explicit dep because we require it directly.
299
+ const cliPackage = await (0, package_utils_1.findPackage)('@react-native-community/cli', {
300
+ searchPath: rnPackage.path,
301
+ });
302
+ const metroConfigPackage = await (0, package_utils_1.findPackage)('metro-config', {
303
+ searchPath: (cliPackage === null || cliPackage === void 0 ? void 0 : cliPackage.path) || rnPackage.path,
326
304
  });
327
- const rnPackageJson = JSON.parse(fs.readFileSync(rnPackageJsonPath, { encoding: 'UTF8' }));
328
- if (!semver.satisfies(rnPackageJson.version, rnPeerDependency)) {
329
- console.log(chalk.green('Installing a compatible version of react-native:'));
330
- console.log(chalk.white(` ${rnPeerDependency}`));
305
+ if (metroConfigPackage) {
306
+ await projectPackage.mergeProps({
307
+ devDependencies: {
308
+ 'metro-config': `^${metroConfigPackage.json.version}`,
309
+ },
310
+ });
311
+ }
312
+ const rnPeerDependency = rnwPackage.json.peerDependencies['react-native'];
313
+ if (!semver_1.default.satisfies(rnPackage.json.version, rnPeerDependency) &&
314
+ ((_a = projectPackage.json.dependencies) === null || _a === void 0 ? void 0 : _a['react-native'])) {
315
+ console.log(chalk_1.default.green('Installing a compatible version of react-native:'));
316
+ console.log(chalk_1.default.white(` ${rnPeerDependency}`));
331
317
  // Patch package.json to have proper react-native version and install
332
- const projectPackageJsonPath = path.join(cwd, 'package.json');
333
- const projectPackageJson = JSON.parse(fs.readFileSync(projectPackageJsonPath, { encoding: 'UTF8' }));
334
- projectPackageJson.scripts.windows = 'react-native run-windows';
335
- if (projectPackageJson.hasOwnProperty('dependencies')) {
336
- projectPackageJson.dependencies['react-native'] = rnPeerDependency;
337
- }
338
- fs.writeFileSync(projectPackageJsonPath, JSON.stringify(projectPackageJson, null, 2));
318
+ await projectPackage.mergeProps({
319
+ dependencies: { 'react-native': rnPeerDependency },
320
+ });
339
321
  // Install dependencies using correct package manager
340
- const isYarn = fs.existsSync(path.join(cwd, 'yarn.lock'));
341
- childProcess.execSync(isYarn ? 'yarn' : 'npm i', options.verbose ? { stdio: 'inherit' } : {});
322
+ const isYarn = fs_1.default.existsSync(path_1.default.join(process.cwd(), 'yarn.lock'));
323
+ child_process_1.default.execSync(isYarn ? 'yarn' : 'npm i', options.verbose ? { stdio: 'inherit' } : {});
342
324
  }
343
325
  }
344
- exports.installDependencies = installDependencies;
326
+ exports.installScriptsAndDependencies = installScriptsAndDependencies;
345
327
  //# sourceMappingURL=index.js.map