@react-native-windows/cli 0.0.0-canary.13 → 0.0.0-canary.130

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 (80) hide show
  1. package/README.md +47 -0
  2. package/lib-commonjs/config/configUtils.d.ts +25 -2
  3. package/lib-commonjs/config/configUtils.js +138 -30
  4. package/lib-commonjs/config/configUtils.js.map +1 -1
  5. package/lib-commonjs/config/dependencyConfig.js +104 -43
  6. package/lib-commonjs/config/dependencyConfig.js.map +1 -1
  7. package/lib-commonjs/config/projectConfig.d.ts +4 -1
  8. package/lib-commonjs/config/projectConfig.js +72 -12
  9. package/lib-commonjs/config/projectConfig.js.map +1 -1
  10. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -0
  11. package/lib-commonjs/e2etest/autolink.test.js +386 -0
  12. package/lib-commonjs/e2etest/autolink.test.js.map +1 -0
  13. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -0
  14. package/lib-commonjs/e2etest/dependencyConfig.test.js +130 -0
  15. package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -0
  16. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -0
  17. package/lib-commonjs/e2etest/projectConfig.test.js +111 -0
  18. package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -0
  19. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -0
  20. package/lib-commonjs/e2etest/projectConfig.utils.js +77 -0
  21. package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
  22. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
  23. package/lib-commonjs/e2etest/runWindows.test.js +61 -0
  24. package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
  25. package/lib-commonjs/generator-common/index.d.ts +16 -0
  26. package/lib-commonjs/generator-common/index.js +60 -39
  27. package/lib-commonjs/generator-common/index.js.map +1 -1
  28. package/lib-commonjs/generator-windows/index.d.ts +2 -2
  29. package/lib-commonjs/generator-windows/index.js +265 -182
  30. package/lib-commonjs/generator-windows/index.js.map +1 -1
  31. package/lib-commonjs/healthChecks.d.ts +2 -0
  32. package/lib-commonjs/healthChecks.js +88 -0
  33. package/lib-commonjs/healthChecks.js.map +1 -0
  34. package/lib-commonjs/index.d.ts +5 -0
  35. package/lib-commonjs/index.js +28 -8
  36. package/lib-commonjs/index.js.map +1 -1
  37. package/lib-commonjs/runWindows/runWindows.js +239 -52
  38. package/lib-commonjs/runWindows/runWindows.js.map +1 -1
  39. package/lib-commonjs/runWindows/runWindowsOptions.d.ts +14 -10
  40. package/lib-commonjs/runWindows/runWindowsOptions.js +15 -11
  41. package/lib-commonjs/runWindows/runWindowsOptions.js.map +1 -1
  42. package/lib-commonjs/runWindows/utils/autolink.d.ts +88 -1
  43. package/lib-commonjs/runWindows/utils/autolink.js +594 -260
  44. package/lib-commonjs/runWindows/utils/autolink.js.map +1 -1
  45. package/lib-commonjs/runWindows/utils/build.d.ts +1 -2
  46. package/lib-commonjs/runWindows/utils/build.js +24 -31
  47. package/lib-commonjs/runWindows/utils/build.js.map +1 -1
  48. package/lib-commonjs/runWindows/utils/checkRequirements.js +11 -7
  49. package/lib-commonjs/runWindows/utils/checkRequirements.js.map +1 -1
  50. package/lib-commonjs/runWindows/utils/commandWithProgress.d.ts +11 -3
  51. package/lib-commonjs/runWindows/utils/commandWithProgress.js +58 -22
  52. package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +1 -1
  53. package/lib-commonjs/runWindows/utils/deploy.d.ts +1 -1
  54. package/lib-commonjs/runWindows/utils/deploy.js +168 -82
  55. package/lib-commonjs/runWindows/utils/deploy.js.map +1 -1
  56. package/lib-commonjs/runWindows/utils/info.js +5 -2
  57. package/lib-commonjs/runWindows/utils/info.js.map +1 -1
  58. package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +11 -5
  59. package/lib-commonjs/runWindows/utils/msbuildtools.js +148 -64
  60. package/lib-commonjs/runWindows/utils/msbuildtools.js.map +1 -1
  61. package/lib-commonjs/runWindows/utils/telemetryHelpers.d.ts +29 -0
  62. package/lib-commonjs/runWindows/utils/telemetryHelpers.js +113 -0
  63. package/lib-commonjs/runWindows/utils/telemetryHelpers.js.map +1 -0
  64. package/lib-commonjs/runWindows/utils/version.d.ts +4 -4
  65. package/lib-commonjs/runWindows/utils/version.js.map +1 -1
  66. package/lib-commonjs/runWindows/utils/vsInstalls.d.ts +4 -1
  67. package/lib-commonjs/runWindows/utils/vsInstalls.js +22 -7
  68. package/lib-commonjs/runWindows/utils/vsInstalls.js.map +1 -1
  69. package/lib-commonjs/runWindows/utils/vstools.d.ts +1 -0
  70. package/lib-commonjs/runWindows/utils/vstools.js +40 -27
  71. package/lib-commonjs/runWindows/utils/vstools.js.map +1 -1
  72. package/lib-commonjs/runWindows/utils/winappdeploytool.d.ts +3 -3
  73. package/lib-commonjs/runWindows/utils/winappdeploytool.js +17 -14
  74. package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +1 -1
  75. package/package.json +40 -22
  76. package/powershell/Add-AppDevPackage.ps1 +2 -2
  77. package/powershell/Eval-MsBuildProperties.ps1 +156 -0
  78. package/powershell/WindowsStoreAppUtils.ps1 +10 -0
  79. package/CHANGELOG.json +0 -185
  80. package/CHANGELOG.md +0 -93
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
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
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
12
+ const path_1 = __importDefault(require("path"));
13
+ const projectConfig_1 = require("../config/projectConfig");
14
+ const autolink_1 = require("../runWindows/utils/autolink");
15
+ const projectConfig_utils_1 = require("./projectConfig.utils");
16
+ function project(name, setup) {
17
+ return [name, setup];
18
+ }
19
+ const projects = [
20
+ // Nothing but a react-native.config.js, with nulls
21
+ project('BlankApp'),
22
+ // Nothing but a windows folder
23
+ project('MissingProjectFilesApp', async (folder) => {
24
+ const windowsDir = path_1.default.join(folder, 'windows');
25
+ await (0, projectConfig_utils_1.tryMkdir)(windowsDir);
26
+ }),
27
+ // New C++ project based on the template
28
+ project('SimpleCppApp', async (folder) => {
29
+ await (0, projectConfig_utils_1.ensureCppAppProject)(folder, 'SimpleCppApp');
30
+ }),
31
+ // New C# project based on the template
32
+ project('SimpleCSharpApp', async (folder) => {
33
+ await (0, projectConfig_utils_1.ensureCSharpAppProject)(folder, 'SimpleCSharpApp');
34
+ }),
35
+ project('WithWinUI3', async (folder) => {
36
+ await (0, projectConfig_utils_1.ensureWinUI3Project)(folder);
37
+ }),
38
+ project('WithHermes', async (folder) => {
39
+ await (0, projectConfig_utils_1.ensureHermesProject)(folder);
40
+ }),
41
+ project('WithExperimentalNuget', async (folder) => {
42
+ await (0, projectConfig_utils_1.ensureExperimentalNuGetProject)(folder);
43
+ }),
44
+ project('WithIndirectDependency'),
45
+ ];
46
+ // Tests that given userConfig is null, the result will always be null
47
+ test.each(projects)('projectConfig - %s (userConfig is null)', async (name, setup) => {
48
+ const folder = path_1.default.resolve('src/e2etest/projects/', name);
49
+ if (setup !== undefined) {
50
+ await setup(folder);
51
+ }
52
+ const userConfig = null;
53
+ expect((0, projectConfig_1.projectConfigWindows)(folder, userConfig)).toBeNull();
54
+ });
55
+ // Tests the result given a windows project config in react-native.config.js
56
+ test.each(projects)('projectConfig - %s (Use react-native.config.js)', async (name, setup) => {
57
+ const folder = path_1.default.resolve('src/e2etest/projects/', name);
58
+ const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
59
+ if (setup !== undefined) {
60
+ await setup(folder);
61
+ }
62
+ const userConfig = rnc.project.windows;
63
+ if (name === 'BlankApp') {
64
+ expect((0, projectConfig_1.projectConfigWindows)(folder, userConfig)).toMatchSnapshot();
65
+ }
66
+ else {
67
+ expect((0, projectConfig_1.projectConfigWindows)(folder, userConfig)).toMatchSnapshot({
68
+ folder: expect.stringContaining(name),
69
+ });
70
+ }
71
+ });
72
+ // Tests the result of ignoring the windows project config in react-native.config.js
73
+ test.each(projects)('projectConfig - %s (Ignore react-native.config.js)', async (name, setup) => {
74
+ const folder = path_1.default.resolve('src/e2etest/projects/', name);
75
+ if (setup !== undefined) {
76
+ await setup(folder);
77
+ }
78
+ const userConfig = {};
79
+ if (name === 'BlankApp') {
80
+ expect((0, projectConfig_1.projectConfigWindows)(folder, userConfig)).toMatchSnapshot();
81
+ }
82
+ else {
83
+ expect((0, projectConfig_1.projectConfigWindows)(folder, userConfig)).toMatchSnapshot({
84
+ folder: expect.stringContaining(name),
85
+ });
86
+ }
87
+ });
88
+ test('useWinUI3=true in react-native.config.js, UseWinUI3=false in ExperimentalFeatures.props', async () => {
89
+ const folder = path_1.default.resolve('src/e2etest/projects/WithWinUI3');
90
+ // Create project with UseWinUI3 == false in ExperimentalFeatures.props
91
+ await (0, projectConfig_utils_1.ensureCppAppProject)(folder, 'WithWinUI3', false, false, false);
92
+ const rnc = require(path_1.default.join(folder, 'react-native.config.js'));
93
+ const config = (0, projectConfig_1.projectConfigWindows)(folder, rnc.project.windows);
94
+ // Set useWinUI3=true in react-native.config.js
95
+ config.useWinUI3 = true;
96
+ const experimentalFeaturesPropsFile = path_1.default.join(folder, 'windows/ExperimentalFeatures.props');
97
+ // Verify starting props file
98
+ const startingExperimentalFeatures = (await fs_1.default.readFile(experimentalFeaturesPropsFile)).toString();
99
+ expect(startingExperimentalFeatures.replace(/\r/g, '')).toMatchSnapshot();
100
+ // Run Autolink to sync the files
101
+ const al = new autolink_1.AutolinkWindows({ windows: config }, {}, {
102
+ check: false,
103
+ logging: false,
104
+ });
105
+ const exd = await al.ensureXAMLDialect();
106
+ expect(exd).toBeTruthy();
107
+ // Verify ending props file
108
+ const finalExperimentalFeatures = (await fs_1.default.readFile(experimentalFeaturesPropsFile)).toString();
109
+ expect(finalExperimentalFeatures.replace(/\r/g, '')).toMatchSnapshot();
110
+ });
111
+ //# sourceMappingURL=projectConfig.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projectConfig.test.js","sourceRoot":"","sources":["../../src/e2etest/projectConfig.test.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;AAEH,kEAA0C;AAC1C,gDAAwB;AAExB,2DAGiC;AAEjC,2DAA6D;AAC7D,+DAO+B;AAI/B,SAAS,OAAO,CACd,IAAY,EACZ,KAAyC;IAEzC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,QAAQ,GAAoB;IAChC,mDAAmD;IACnD,OAAO,CAAC,UAAU,CAAC;IACnB,+BAA+B;IAC/B,OAAO,CAAC,wBAAwB,EAAE,KAAK,EAAE,MAAc,EAAE,EAAE;QACzD,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAChD,MAAM,IAAA,8BAAQ,EAAC,UAAU,CAAC,CAAC;IAC7B,CAAC,CAAC;IACF,wCAAwC;IACxC,OAAO,CAAC,cAAc,EAAE,KAAK,EAAE,MAAc,EAAE,EAAE;QAC/C,MAAM,IAAA,yCAAmB,EAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACpD,CAAC,CAAC;IACF,uCAAuC;IACvC,OAAO,CAAC,iBAAiB,EAAE,KAAK,EAAE,MAAc,EAAE,EAAE;QAClD,MAAM,IAAA,4CAAsB,EAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC1D,CAAC,CAAC;IACF,OAAO,CAAC,YAAY,EAAE,KAAK,EAAE,MAAc,EAAE,EAAE;QAC7C,MAAM,IAAA,yCAAmB,EAAC,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC;IACF,OAAO,CAAC,YAAY,EAAE,KAAK,EAAE,MAAc,EAAE,EAAE;QAC7C,MAAM,IAAA,yCAAmB,EAAC,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC;IACF,OA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AAC;IAClE,+CAA+C;IAC/C,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC;IAExB,MAAM,6BAA6B,GAAG,cAAI,CAAC,IAAI,CAC7C,MAAM,EACN,oCAAoC,CACrC,CAAC;IAEF,6BAA6B;IAC7B,MAAM,4BAA4B,GAAG,CACnC,MAAM,YAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CACjD,CAAC,QAAQ,EAAE,CAAC;IACb,MAAM,CAAC,4BAA4B,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;IAE1E,iCAAiC;IACjC,MAAM,EAAE,GAAG,IAAI,0BAAe,CAC5B,EAAC,OAAO,EAAE,MAAM,EAAC,EACjB,EAAE,EACF;QACE,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,KAAK;KACf,CACF,CAAC;IAEF,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,iBAAiB,EAAE,CAAC;IACzC,MAAM,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC;IAEzB,2BAA2B;IAC3B,MAAM,yBAAyB,GAAG,CAChC,MAAM,YAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CACjD,CAAC,QAAQ,EAAE,CAAC;IAEb,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;AACzE,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n * @format\n */\n\nimport fs from '@react-native-windows/fs';\nimport path from 'path';\n\nimport {\n projectConfigWindows,\n WindowsProjectConfig,\n} from '../config/projectConfig';\n\nimport {AutolinkWindows} from '../runWindows/utils/autolink';\nimport {\n ensureCppAppProject,\n ensureCSharpAppProject,\n ensureWinUI3Project,\n ensureHermesProject,\n ensureExperimentalNuGetProject,\n tryMkdir,\n} from './projectConfig.utils';\n\ntype TargetProject = [string, ((folder: string) => Promise<void>)?];\n\nfunction project(\n name: string,\n setup?: (folder: string) => Promise<void>,\n): TargetProject {\n return [name, setup];\n}\n\nconst projects: TargetProject[] = [\n // Nothing but a react-native.config.js, with nulls\n project('BlankApp'),\n // Nothing but a windows folder\n project('MissingProjectFilesApp', async (folder: string) => {\n const windowsDir = path.join(folder, 'windows');\n await tryMkdir(windowsDir);\n }),\n // New C++ project based on the template\n project('SimpleCppApp', async (folder: string) => {\n await ensureCppAppProject(folder, 'SimpleCppApp');\n }),\n // New C# project based on the template\n project('SimpleCSharpApp', async (folder: string) => {\n await ensureCSharpAppProject(folder, 'SimpleCSharpApp');\n }),\n project('WithWinUI3', async (folder: string) => {\n await ensureWinUI3Project(folder);\n }),\n project('WithHermes', async (folder: string) => {\n await ensureHermesProject(folder);\n }),\n project('WithExperimentalNuget', async (folder: string) => {\n await ensureExperimentalNuGetProject(folder);\n }),\n project('WithIndirectDependency'),\n];\n\n// Tests that given userConfig is null, the result will always be null\ntest.each(projects)(\n 'projectConfig - %s (userConfig is null)',\n async (name, setup) => {\n const folder = path.resolve('src/e2etest/projects/', name);\n\n if (setup !== undefined) {\n await setup(folder);\n }\n\n const userConfig = null;\n\n expect(projectConfigWindows(folder, userConfig)).toBeNull();\n },\n);\n\n// Tests the result given a windows project config in react-native.config.js\ntest.each(projects)(\n 'projectConfig - %s (Use react-native.config.js)',\n async (name, setup) => {\n const folder = path.resolve('src/e2etest/projects/', name);\n const rnc = require(path.join(folder, 'react-native.config.js'));\n\n if (setup !== undefined) {\n await setup(folder);\n }\n\n const userConfig: Partial<WindowsProjectConfig> = rnc.project.windows;\n\n if (name === 'BlankApp') {\n expect(projectConfigWindows(folder, userConfig)).toMatchSnapshot();\n } else {\n expect(projectConfigWindows(folder, userConfig)).toMatchSnapshot({\n folder: expect.stringContaining(name),\n });\n }\n },\n);\n\n// Tests the result of ignoring the windows project config in react-native.config.js\ntest.each(projects)(\n 'projectConfig - %s (Ignore react-native.config.js)',\n async (name, setup) => {\n const folder = path.resolve('src/e2etest/projects/', name);\n\n if (setup !== undefined) {\n await setup(folder);\n }\n\n const userConfig: Partial<WindowsProjectConfig> = {};\n\n if (name === 'BlankApp') {\n expect(projectConfigWindows(folder, userConfig)).toMatchSnapshot();\n } else {\n expect(projectConfigWindows(folder, userConfig)).toMatchSnapshot({\n folder: expect.stringContaining(name),\n });\n }\n },\n);\n\ntest('useWinUI3=true in react-native.config.js, UseWinUI3=false in ExperimentalFeatures.props', async () => {\n const folder = path.resolve('src/e2etest/projects/WithWinUI3');\n\n // Create project with UseWinUI3 == false in ExperimentalFeatures.props\n await ensureCppAppProject(folder, 'WithWinUI3', false, false, false);\n\n const rnc = require(path.join(folder, 'react-native.config.js'));\n\n const config = projectConfigWindows(folder, rnc.project.windows)!;\n // Set useWinUI3=true in react-native.config.js\n config.useWinUI3 = true;\n\n const experimentalFeaturesPropsFile = path.join(\n folder,\n 'windows/ExperimentalFeatures.props',\n );\n\n // Verify starting props file\n const startingExperimentalFeatures = (\n await fs.readFile(experimentalFeaturesPropsFile)\n ).toString();\n expect(startingExperimentalFeatures.replace(/\\r/g, '')).toMatchSnapshot();\n\n // Run Autolink to sync the files\n const al = new AutolinkWindows(\n {windows: config},\n {},\n {\n check: false,\n logging: false,\n },\n );\n\n const exd = await al.ensureXAMLDialect();\n expect(exd).toBeTruthy();\n\n // Verify ending props file\n const finalExperimentalFeatures = (\n await fs.readFile(experimentalFeaturesPropsFile)\n ).toString();\n\n expect(finalExperimentalFeatures.replace(/\\r/g, '')).toMatchSnapshot();\n});\n"]}
@@ -0,0 +1,8 @@
1
+ export declare const templateRoot: string;
2
+ export declare const testProjectGuid = "{416476D5-974A-4EE2-8145-4E331297247E}";
3
+ export declare function tryMkdir(dir: string): Promise<void>;
4
+ export declare function ensureCppAppProject(folder: string, name: string, useWinUI3?: boolean, useHermes?: boolean, useExperimentaNuget?: boolean): Promise<void>;
5
+ export declare function ensureCSharpAppProject(folder: string, name: string, useWinUI3?: boolean, useHermes?: boolean, useExperimentaNuget?: boolean): Promise<void>;
6
+ export declare function ensureWinUI3Project(folder: string): Promise<void>;
7
+ export declare function ensureHermesProject(folder: string): Promise<void>;
8
+ export declare function ensureExperimentalNuGetProject(folder: string): Promise<void>;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ensureExperimentalNuGetProject = exports.ensureHermesProject = exports.ensureWinUI3Project = exports.ensureCSharpAppProject = exports.ensureCppAppProject = exports.tryMkdir = exports.testProjectGuid = exports.templateRoot = void 0;
7
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const generator_common_1 = require("../generator-common");
10
+ exports.templateRoot = path_1.default.resolve('../../../vnext/template');
11
+ exports.testProjectGuid = '{416476D5-974A-4EE2-8145-4E331297247E}';
12
+ async function tryMkdir(dir) {
13
+ try {
14
+ await fs_1.default.mkdir(dir, { recursive: true });
15
+ }
16
+ catch (err) { }
17
+ }
18
+ exports.tryMkdir = tryMkdir;
19
+ async function ensureCppAppProject(folder, name, useWinUI3, useHermes, useExperimentaNuget) {
20
+ const windowsDir = path_1.default.join(folder, 'windows');
21
+ if (fs_1.default.existsSync(windowsDir)) {
22
+ await fs_1.default.rmdir(windowsDir, { recursive: true });
23
+ }
24
+ await tryMkdir(windowsDir);
25
+ const replacements = {
26
+ name,
27
+ namespace: name,
28
+ useMustache: true,
29
+ projectGuidUpper: exports.testProjectGuid,
30
+ projectGuidLower: exports.testProjectGuid.toLowerCase(),
31
+ useWinUI3: !!useWinUI3,
32
+ useHermes: !!useHermes,
33
+ useExperimentalNuget: !!useExperimentaNuget,
34
+ };
35
+ await (0, generator_common_1.copyAndReplace)(path_1.default.join(exports.templateRoot, 'cpp-app/proj/MyApp.sln'), path_1.default.join(windowsDir, `${name}.sln`), replacements, null);
36
+ const projDir = path_1.default.join(windowsDir, name);
37
+ await tryMkdir(projDir);
38
+ await (0, generator_common_1.copyAndReplace)(path_1.default.join(exports.templateRoot, 'cpp-app/proj/MyApp.vcxproj'), path_1.default.join(projDir, `${name}.vcxproj`), replacements, null);
39
+ await (0, generator_common_1.copyAndReplace)(path_1.default.join(exports.templateRoot, 'shared-app/proj/ExperimentalFeatures.props'), path_1.default.join(windowsDir, 'ExperimentalFeatures.props'), replacements, null);
40
+ }
41
+ exports.ensureCppAppProject = ensureCppAppProject;
42
+ async function ensureCSharpAppProject(folder, name, useWinUI3, useHermes, useExperimentaNuget) {
43
+ const windowsDir = path_1.default.join(folder, 'windows');
44
+ if (fs_1.default.existsSync(windowsDir)) {
45
+ await fs_1.default.rmdir(windowsDir, { recursive: true });
46
+ }
47
+ await tryMkdir(windowsDir);
48
+ const replacements = {
49
+ name,
50
+ namespace: name,
51
+ useMustache: true,
52
+ projectGuidUpper: exports.testProjectGuid,
53
+ projectGuidLower: exports.testProjectGuid.toLowerCase(),
54
+ useWinUI3: !!useWinUI3,
55
+ useHermes: !!useHermes,
56
+ useExperimentalNuget: !!useExperimentaNuget,
57
+ };
58
+ await (0, generator_common_1.copyAndReplace)(path_1.default.join(exports.templateRoot, 'cs-app/proj/MyApp.sln'), path_1.default.join(windowsDir, `${name}.sln`), replacements, null);
59
+ const projDir = path_1.default.join(windowsDir, name);
60
+ await tryMkdir(projDir);
61
+ await (0, generator_common_1.copyAndReplace)(path_1.default.join(exports.templateRoot, 'cs-app/proj/MyApp.csproj'), path_1.default.join(projDir, `${name}.csproj`), replacements, null);
62
+ await (0, generator_common_1.copyAndReplace)(path_1.default.join(exports.templateRoot, 'shared-app/proj/ExperimentalFeatures.props'), path_1.default.join(windowsDir, 'ExperimentalFeatures.props'), replacements, null);
63
+ }
64
+ exports.ensureCSharpAppProject = ensureCSharpAppProject;
65
+ async function ensureWinUI3Project(folder) {
66
+ await ensureCppAppProject(folder, 'WithWinUI3', true, false, false);
67
+ }
68
+ exports.ensureWinUI3Project = ensureWinUI3Project;
69
+ async function ensureHermesProject(folder) {
70
+ await ensureCppAppProject(folder, 'WithHermes', false, true, false);
71
+ }
72
+ exports.ensureHermesProject = ensureHermesProject;
73
+ async function ensureExperimentalNuGetProject(folder) {
74
+ await ensureCppAppProject(folder, 'WithExperimentalNuGet', false, false, true);
75
+ }
76
+ exports.ensureExperimentalNuGetProject = ensureExperimentalNuGetProject;
77
+ //# sourceMappingURL=projectConfig.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projectConfig.utils.js","sourceRoot":"","sources":["../../src/e2etest/projectConfig.utils.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAyC;AACzC,gDAAwB;AACxB,0DAAqD;AAExC,QAAA,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAEvD,QAAA,eAAe,GAAG,wCAAwC,CAAC;AAEjE,KAAK,UAAU,QAAQ,CAAC,GAAW;IACxC,IAAI;QACF,MAAM,YAAE,CAAC,KAAK,CAAC,GAAG,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;KACxC;IAAC,OAAO,GAAG,EAAE,GAAE;AAClB,CAAC;AAJD,4BAIC;AAEM,KAAK,UAAU,mBAAmB,CAAC,MAAc,EAAE,IAAY,EAAE,SAAmB,EAAE,SAAmB,EAAE,mBAA6B;IAC7I,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAChD,IAAI,YAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;QAC7B,MAAM,YAAE,CAAC,KAAK,CAAC,UAAU,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;KAC/C;IACD,MAAM,QAAQ,CAAC,UAAU,CAAC,CAAC;IAE3B,MAAM,YAAY,GAAG;QACnB,IAAI;QACJ,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,IAAI;QACjB,gBA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AY,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AACtE,CAAC;AAFD,kDAEC;AAEM,KAAK,UAAU,8BAA8B,CAAC,MAAc;IACjE,MAAM,mBAAmB,CAAC,MAAM,EAAE,uBAAuB,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AACjF,CAAC;AAFD,wEAEC","sourcesContent":["import fs from '@react-native-windows/fs'\nimport path from 'path';\nimport { copyAndReplace } from '../generator-common';\n\nexport const templateRoot = path.resolve('../../../vnext/template');\n\nexport const testProjectGuid = '{416476D5-974A-4EE2-8145-4E331297247E}';\n\nexport async function tryMkdir(dir: string): Promise<void> {\n try {\n await fs.mkdir(dir, {recursive: true});\n } catch (err) {}\n}\n\nexport async function ensureCppAppProject(folder: string, name: string, useWinUI3?: boolean, useHermes?: boolean, useExperimentaNuget?: boolean) {\n const windowsDir = path.join(folder, 'windows');\n if (fs.existsSync(windowsDir)) {\n await fs.rmdir(windowsDir, {recursive: true});\n }\n await tryMkdir(windowsDir);\n\n const replacements = {\n name,\n namespace: name,\n useMustache: true,\n projectGuidUpper: testProjectGuid,\n projectGuidLower: testProjectGuid.toLowerCase(),\n useWinUI3: !!useWinUI3,\n useHermes: !!useHermes,\n useExperimentalNuget: !!useExperimentaNuget,\n };\n\n await copyAndReplace(\n path.join(templateRoot, 'cpp-app/proj/MyApp.sln'),\n path.join(windowsDir, `${name}.sln`),\n replacements,\n null\n );\n\n const projDir = path.join(windowsDir, name);\n await tryMkdir(projDir);\n\n await copyAndReplace(\n path.join(templateRoot, 'cpp-app/proj/MyApp.vcxproj'),\n path.join(projDir, `${name}.vcxproj`),\n replacements,\n null\n );\n\n await copyAndReplace(\n path.join(templateRoot, 'shared-app/proj/ExperimentalFeatures.props'),\n path.join(windowsDir, 'ExperimentalFeatures.props'),\n replacements,\n null\n );\n}\n\nexport async function ensureCSharpAppProject(folder: string, name: string, useWinUI3?: boolean, useHermes?: boolean, useExperimentaNuget?: boolean) {\n const windowsDir = path.join(folder, 'windows');\n if (fs.existsSync(windowsDir)) {\n await fs.rmdir(windowsDir, {recursive: true});\n }\n await tryMkdir(windowsDir);\n\n const replacements = {\n name,\n namespace: name,\n useMustache: true,\n projectGuidUpper: testProjectGuid,\n projectGuidLower: testProjectGuid.toLowerCase(),\n useWinUI3: !!useWinUI3,\n useHermes: !!useHermes,\n useExperimentalNuget: !!useExperimentaNuget,\n };\n\n await copyAndReplace(\n path.join(templateRoot, 'cs-app/proj/MyApp.sln'),\n path.join(windowsDir, `${name}.sln`),\n replacements,\n null\n );\n\n const projDir = path.join(windowsDir, name);\n await tryMkdir(projDir);\n\n await copyAndReplace(\n path.join(templateRoot, 'cs-app/proj/MyApp.csproj'),\n path.join(projDir, `${name}.csproj`),\n replacements,\n null\n );\n\n await copyAndReplace(\n path.join(templateRoot, 'shared-app/proj/ExperimentalFeatures.props'),\n path.join(windowsDir, 'ExperimentalFeatures.props'),\n replacements,\n null\n );\n}\n\nexport async function ensureWinUI3Project(folder: string) {\n await ensureCppAppProject(folder, 'WithWinUI3', true, false, false);\n}\n\nexport async function ensureHermesProject(folder: string) {\n await ensureCppAppProject(folder, 'WithHermes', false, true, false);\n}\n\nexport async function ensureExperimentalNuGetProject(folder: string) {\n await ensureCppAppProject(folder, 'WithExperimentalNuGet', false, false, true);\n}"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ export {};
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const telemetry_1 = require("@react-native-windows/telemetry");
9
+ const runWindowsOptions_1 = require("../runWindows/runWindowsOptions");
10
+ // eslint-disable-next-line complexity
11
+ function validateOptionName(name, optionName) {
12
+ // Do not add a default case here. Every item must explicitly return true
13
+ switch (optionName) {
14
+ case 'release':
15
+ case 'root':
16
+ case 'arch':
17
+ case 'singleproc':
18
+ case 'emulator':
19
+ case 'device':
20
+ case 'target':
21
+ case 'remoteDebugging':
22
+ case 'logging':
23
+ case 'packager':
24
+ case 'bundle':
25
+ case 'launch':
26
+ case 'autolink':
27
+ case 'build':
28
+ case 'deploy':
29
+ case 'deployFromLayout':
30
+ case 'sln':
31
+ case 'proj':
32
+ case 'msbuildprops':
33
+ case 'buildLogDirectory':
34
+ case 'info':
35
+ case 'directDebugging':
36
+ case 'telemetry':
37
+ return true;
38
+ }
39
+ throw new Error(`Unable to find ${optionName} to match '${name}' in RunWindowsOptions.`);
40
+ }
41
+ test('runWindowsOptions - validate options', () => {
42
+ for (const commandOption of runWindowsOptions_1.runWindowsOptions) {
43
+ // Validate names
44
+ expect(commandOption.name).not.toBeNull();
45
+ expect(commandOption.name.startsWith('--')).toBe(true);
46
+ expect(commandOption.name).toBe(commandOption.name.trim());
47
+ // Validate defaults
48
+ if (!commandOption.name.endsWith(' [string]') &&
49
+ !commandOption.name.endsWith(' [number]')) {
50
+ // Commander ignores defaults for flags, so leave undefined to prevent confusion
51
+ expect(commandOption.default).toBeUndefined();
52
+ }
53
+ // Validate description
54
+ expect(commandOption.description).not.toBeNull();
55
+ expect(commandOption.description).toBe(commandOption.description.trim());
56
+ // Validate all command options are present in RunWindowsOptions
57
+ const optionName = (0, telemetry_1.commanderNameToOptionName)(commandOption.name);
58
+ expect(validateOptionName(commandOption.name, optionName)).toBe(true);
59
+ }
60
+ });
61
+ //# sourceMappingURL=runWindows.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runWindows.test.js","sourceRoot":"","sources":["../../src/e2etest/runWindows.test.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAEH,+DAA0E;AAE1E,uEAGyC;AAEzC,sCAAsC;AACtC,SAAS,kBAAkB,CACzB,IAAY,EACZ,UAAmC;IAEnC,yEAAyE;IACzE,QAAQ,U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gFAAgF;YAChF,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,CAAC;SAC/C;QAED,uBAAuB;QACvB,MAAM,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,WAAY,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,WAAY,CAAC,IAAI,EAAE,CAAC,CAAC;QAE3E,gEAAgE;QAChE,MAAM,UAAU,GAAG,IAAA,qCAAyB,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QACjE,MAAM,CACJ,kBAAkB,CAChB,aAAa,CAAC,IAAI,EAClB,UAAqC,CACtC,CACF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACd;AACH,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation. All rights reserved.\n * Licensed under the MIT License.\n * @format\n */\n\nimport {commanderNameToOptionName} from '@react-native-windows/telemetry';\n\nimport {\n runWindowsOptions,\n RunWindowsOptions,\n} from '../runWindows/runWindowsOptions';\n\n// eslint-disable-next-line complexity\nfunction validateOptionName(\n name: string,\n optionName: keyof RunWindowsOptions,\n): boolean {\n // Do not add a default case here. Every item must explicitly return true\n switch (optionName) {\n case 'release':\n case 'root':\n case 'arch':\n case 'singleproc':\n case 'emulator':\n case 'device':\n case 'target':\n case 'remoteDebugging':\n case 'logging':\n case 'packager':\n case 'bundle':\n case 'launch':\n case 'autolink':\n case 'build':\n case 'deploy':\n case 'deployFromLayout':\n case 'sln':\n case 'proj':\n case 'msbuildprops':\n case 'buildLogDirectory':\n case 'info':\n case 'directDebugging':\n case 'telemetry':\n return true;\n }\n throw new Error(\n `Unable to find ${optionName} to match '${name}' in RunWindowsOptions.`,\n );\n}\n\ntest('runWindowsOptions - validate options', () => {\n for (const commandOption of runWindowsOptions) {\n // Validate names\n expect(commandOption.name).not.toBeNull();\n expect(commandOption.name.startsWith('--')).toBe(true);\n expect(commandOption.name).toBe(commandOption.name.trim());\n\n // Validate defaults\n if (\n !commandOption.name.endsWith(' [string]') &&\n !commandOption.name.endsWith(' [number]')\n ) {\n // Commander ignores defaults for flags, so leave undefined to prevent confusion\n expect(commandOption.default).toBeUndefined();\n }\n\n // Validate description\n expect(commandOption.description).not.toBeNull();\n expect(commandOption.description!).toBe(commandOption.description!.trim());\n\n // Validate all command options are present in RunWindowsOptions\n const optionName = commanderNameToOptionName(commandOption.name);\n expect(\n validateOptionName(\n commandOption.name,\n optionName as keyof RunWindowsOptions,\n ),\n ).toBe(true);\n }\n});\n"]}
@@ -18,6 +18,22 @@ export declare type Replacements = {
18
18
  * @return The contents of the file with the replacements applied.
19
19
  */
20
20
  export declare function resolveContents(srcPath: string, replacements: Replacements): string;
21
+ declare type ContentChangedCallbackOption = 'identical' | 'changed' | 'new' | null;
22
+ declare type ContentChangedCallback = (path: string, option: ContentChangedCallbackOption) => Promise<'keep' | 'overwrite'>;
23
+ /**
24
+ * Copy a file to given destination, replacing parts of its contents.
25
+ * @param srcPath Path to a file to be copied.
26
+ * @param destPath Destination path.
27
+ * @param replacements: e.g. {'TextToBeReplaced': 'Replacement'}
28
+ * @param contentChangedCallback
29
+ * Used when upgrading projects. Based on if file contents would change
30
+ * when being replaced, allows the caller to specify whether the file
31
+ * should be replaced or not.
32
+ * If null, files will be overwritten.
33
+ * Function(path, 'identical' | 'changed' | 'new') => 'keep' | 'overwrite'
34
+ */
35
+ export declare function copyAndReplace(srcPath: string, destPath: string, replacements: Replacements, contentChangedCallback: ContentChangedCallback | null): Promise<void>;
21
36
  export declare function createDir(destPath: string): void;
22
37
  export declare function copyAndReplaceWithChangedCallback(srcPath: string, destRoot: string, relativeDestPath: string, replacements?: Record<string, string>, alwaysOverwrite?: boolean): Promise<void>;
23
38
  export declare function copyAndReplaceAll(srcPath: string, destPath: string, relativeDestDir: string, replacements: Replacements, alwaysOverwrite: boolean): Promise<void>;
39
+ export {};
@@ -4,20 +4,24 @@
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.copyAndReplaceAll = exports.copyAndReplaceWithChangedCallback = exports.createDir = exports.resolveContents = void 0;
9
- const fs = require("fs");
10
- const chalk = require("chalk");
11
- const inquirer = require("inquirer");
12
- const path = require("path");
13
- const mustache = require("mustache");
11
+ exports.copyAndReplaceAll = exports.copyAndReplaceWithChangedCallback = exports.createDir = exports.copyAndReplace = exports.resolveContents = void 0;
12
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
13
+ const chalk_1 = __importDefault(require("chalk"));
14
+ const prompts_1 = __importDefault(require("prompts"));
15
+ const path_1 = __importDefault(require("path"));
16
+ const mustache_1 = __importDefault(require("mustache"));
17
+ const telemetry_1 = require("@react-native-windows/telemetry");
14
18
  function walk(current) {
15
- if (!fs.lstatSync(current).isDirectory()) {
19
+ if (!fs_1.default.lstatSync(current).isDirectory()) {
16
20
  return [current];
17
21
  }
18
- const files = fs
22
+ const files = fs_1.default
19
23
  .readdirSync(current)
20
- .map(child => walk(path.join(current, child)));
24
+ .map(child => walk(path_1.default.join(current, child)));
21
25
  const result = [];
22
26
  return result.concat.apply([current], files);
23
27
  }
@@ -28,9 +32,25 @@ function walk(current) {
28
32
  * @return The contents of the file with the replacements applied.
29
33
  */
30
34
  function resolveContents(srcPath, replacements) {
31
- let content = fs.readFileSync(srcPath, 'utf8');
35
+ let content = fs_1.default.readFileSync(srcPath, 'utf8');
36
+ if (content.includes('\r\n')) {
37
+ // CRLF file, make sure multiline replacements are also CRLF
38
+ for (const key of Object.keys(replacements)) {
39
+ if (typeof replacements[key] === 'string') {
40
+ replacements[key] = replacements[key].replace(/(?<!\r)\n/g, '\r\n');
41
+ }
42
+ }
43
+ }
44
+ else {
45
+ // LF file, make sure multiline replacements are also LF
46
+ for (const key of Object.keys(replacements)) {
47
+ if (typeof replacements[key] === 'string') {
48
+ replacements[key] = replacements[key].replace(/\r\n/g, '\n');
49
+ }
50
+ }
51
+ }
32
52
  if (replacements.useMustache) {
33
- content = mustache.render(content, replacements);
53
+ content = mustache_1.default.render(content, replacements);
34
54
  (replacements.regExpPatternsToRemove || []).forEach(regexPattern => {
35
55
  content = content.replace(new RegExp(regexPattern, 'g'), '');
36
56
  });
@@ -58,22 +78,22 @@ const binaryExtensions = ['.png', '.jar', '.keystore'];
58
78
  * Function(path, 'identical' | 'changed' | 'new') => 'keep' | 'overwrite'
59
79
  */
60
80
  async function copyAndReplace(srcPath, destPath, replacements, contentChangedCallback) {
61
- if (fs.lstatSync(srcPath).isDirectory()) {
62
- if (!fs.existsSync(destPath)) {
63
- fs.mkdirSync(destPath);
81
+ if (fs_1.default.lstatSync(srcPath).isDirectory()) {
82
+ if (!fs_1.default.existsSync(destPath)) {
83
+ fs_1.default.mkdirSync(destPath);
64
84
  }
65
85
  // Not recursive
66
86
  return;
67
87
  }
68
- const extension = path.extname(srcPath);
69
- if (binaryExtensions.indexOf(extension) !== -1) {
88
+ const extension = path_1.default.extname(srcPath);
89
+ if (binaryExtensions.includes(extension)) {
70
90
  // Binary file
71
91
  let shouldOverwrite = 'overwrite';
72
92
  if (contentChangedCallback) {
73
- const newContentBuffer = fs.readFileSync(srcPath);
93
+ const newContentBuffer = fs_1.default.readFileSync(srcPath);
74
94
  let contentChanged = 'identical';
75
95
  try {
76
- const origContentBuffer = fs.readFileSync(destPath);
96
+ const origContentBuffer = fs_1.default.readFileSync(destPath);
77
97
  if (Buffer.compare(origContentBuffer, newContentBuffer) !== 0) {
78
98
  contentChanged = 'changed';
79
99
  }
@@ -98,14 +118,14 @@ async function copyAndReplace(srcPath, destPath, replacements, contentChangedCal
98
118
  }
99
119
  else {
100
120
  // Text file
101
- const srcPermissions = fs.statSync(srcPath).mode;
102
- let content = resolveContents(srcPath, replacements);
121
+ const srcPermissions = fs_1.default.statSync(srcPath).mode;
122
+ const content = resolveContents(srcPath, replacements);
103
123
  let shouldOverwrite = 'overwrite';
104
124
  if (contentChangedCallback) {
105
125
  // Check if contents changed and ask to overwrite
106
126
  let contentChanged = 'identical';
107
127
  try {
108
- const origContent = fs.readFileSync(destPath, 'utf8');
128
+ const origContent = fs_1.default.readFileSync(destPath, 'utf8');
109
129
  if (content !== origContent) {
110
130
  // logger.info('Content changed: ' + destPath);
111
131
  contentChanged = 'changed';
@@ -122,24 +142,25 @@ async function copyAndReplace(srcPath, destPath, replacements, contentChangedCal
122
142
  shouldOverwrite = await contentChangedCallback(destPath, contentChanged);
123
143
  }
124
144
  if (shouldOverwrite === 'overwrite') {
125
- fs.writeFileSync(destPath, content, {
145
+ fs_1.default.writeFileSync(destPath, content, {
126
146
  encoding: 'utf8',
127
147
  mode: srcPermissions,
128
148
  });
129
149
  }
130
150
  }
131
151
  }
152
+ exports.copyAndReplace = copyAndReplace;
132
153
  /**
133
154
  * Same as 'cp' on Unix. Don't do any replacements.
134
155
  */
135
156
  function copyBinaryFile(srcPath, destPath, cb) {
136
157
  let cbCalled = false;
137
- const srcPermissions = fs.statSync(srcPath).mode;
138
- const readStream = fs.createReadStream(srcPath);
158
+ const srcPermissions = fs_1.default.statSync(srcPath).mode;
159
+ const readStream = fs_1.default.createReadStream(srcPath);
139
160
  readStream.on('error', err => {
140
161
  done(err);
141
162
  });
142
- const writeStream = fs.createWriteStream(destPath, {
163
+ const writeStream = fs_1.default.createWriteStream(destPath, {
143
164
  mode: srcPermissions,
144
165
  });
145
166
  writeStream.on('error', err => {
@@ -157,8 +178,8 @@ function copyBinaryFile(srcPath, destPath, cb) {
157
178
  }
158
179
  }
159
180
  function createDir(destPath) {
160
- if (!fs.existsSync(destPath)) {
161
- fs.mkdirSync(destPath);
181
+ if (!fs_1.default.existsSync(destPath)) {
182
+ fs_1.default.mkdirSync(destPath);
162
183
  }
163
184
  }
164
185
  exports.createDir = createDir;
@@ -169,54 +190,54 @@ async function copyAndReplaceWithChangedCallback(srcPath, destRoot, relativeDest
169
190
  const contentChangedCallback = alwaysOverwrite
170
191
  ? (_, contentChanged) => alwaysOverwriteContentChangedCallback(srcPath, relativeDestPath, contentChanged)
171
192
  : (_, contentChanged) => upgradeFileContentChangedCallback(srcPath, relativeDestPath, contentChanged);
172
- await copyAndReplace(srcPath, path.join(destRoot, relativeDestPath), replacements, contentChangedCallback);
193
+ await copyAndReplace(srcPath, path_1.default.join(destRoot, relativeDestPath), replacements, contentChangedCallback);
173
194
  }
174
195
  exports.copyAndReplaceWithChangedCallback = copyAndReplaceWithChangedCallback;
175
196
  async function copyAndReplaceAll(srcPath, destPath, relativeDestDir, replacements, alwaysOverwrite) {
176
197
  for (const absoluteSrcFilePath of walk(srcPath)) {
177
- const filename = path.relative(srcPath, absoluteSrcFilePath);
178
- const relativeDestPath = path.join(relativeDestDir, filename);
198
+ const filename = path_1.default.relative(srcPath, absoluteSrcFilePath);
199
+ const relativeDestPath = path_1.default.join(relativeDestDir, filename);
179
200
  await copyAndReplaceWithChangedCallback(absoluteSrcFilePath, destPath, relativeDestPath, replacements, alwaysOverwrite);
180
201
  }
181
202
  }
182
203
  exports.copyAndReplaceAll = copyAndReplaceAll;
183
204
  async function alwaysOverwriteContentChangedCallback(absoluteSrcFilePath, relativeDestPath, contentChanged) {
184
205
  if (contentChanged === 'new') {
185
- console.log(`${chalk.bold('new')} ${relativeDestPath}`);
206
+ console.log(`${chalk_1.default.bold('new')} ${relativeDestPath}`);
186
207
  return 'overwrite';
187
208
  }
188
209
  if (contentChanged === 'changed') {
189
- console.log(`${chalk.bold('changed')} ${relativeDestPath} ${chalk.yellow('[overwriting]')}`);
210
+ console.log(`${chalk_1.default.bold('changed')} ${relativeDestPath} ${chalk_1.default.yellow('[overwriting]')}`);
190
211
  return 'overwrite';
191
212
  }
192
213
  if (contentChanged === 'identical') {
193
214
  return 'keep';
194
215
  }
195
- throw new Error(`Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
216
+ throw new telemetry_1.CodedError('Autolinking', `Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
196
217
  }
197
218
  async function upgradeFileContentChangedCallback(absoluteSrcFilePath, relativeDestPath, contentChanged) {
198
219
  if (contentChanged === 'new') {
199
- console.log(`${chalk.bold('new')} ${relativeDestPath}`);
220
+ console.log(`${chalk_1.default.bold('new')} ${relativeDestPath}`);
200
221
  return 'overwrite';
201
222
  }
202
223
  if (contentChanged === 'changed') {
203
- console.log(`${chalk.bold(relativeDestPath)} ` +
224
+ console.log(`${chalk_1.default.bold(relativeDestPath)} ` +
204
225
  `has changed in the new version.\nDo you want to keep your ${relativeDestPath} or replace it with the ` +
205
226
  'latest version?\nMake sure you have any changes you made to this file saved somewhere.\n' +
206
227
  `You can see the new version here: ${absoluteSrcFilePath}`);
207
- const { shoudReplace } = await inquirer.prompt([
228
+ const { shouldReplace } = await (0, prompts_1.default)([
208
229
  {
209
230
  name: 'shouldReplace',
210
231
  type: 'confirm',
211
232
  message: `Do you want to replace ${relativeDestPath}?`,
212
- default: false,
233
+ initial: false,
213
234
  },
214
235
  ]);
215
- return shoudReplace ? 'overwrite' : 'keep';
236
+ return shouldReplace ? 'overwrite' : 'keep';
216
237
  }
217
238
  if (contentChanged === 'identical') {
218
239
  return 'keep';
219
240
  }
220
- throw new Error(`Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
241
+ throw new telemetry_1.CodedError('Autolinking', `Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
221
242
  }
222
243
  //# sourceMappingURL=index.js.map
@@ -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,qCAAqC;AACrC,6BAA6B;AAC7B,qCAAqC;AAWrC,SAAS,IAAI,CAAC,OAAe;IAC3B,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EA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b,+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>;