@react-native-windows/cli 0.0.0-canary.21 → 0.0.0-canary.210

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 (141) hide show
  1. package/README.md +47 -0
  2. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.d.ts +87 -0
  3. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js +661 -0
  4. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js.map +1 -0
  5. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.d.ts +14 -0
  6. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js +33 -0
  7. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js.map +1 -0
  8. package/lib-commonjs/commands/codegenWindows/codegenWindows.d.ts +27 -0
  9. package/lib-commonjs/commands/codegenWindows/codegenWindows.js +206 -0
  10. package/lib-commonjs/commands/codegenWindows/codegenWindows.js.map +1 -0
  11. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.d.ts +12 -0
  12. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js +23 -0
  13. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js.map +1 -0
  14. package/lib-commonjs/{config → commands/config}/configUtils.d.ts +123 -93
  15. package/lib-commonjs/commands/config/configUtils.js +381 -0
  16. package/lib-commonjs/commands/config/configUtils.js.map +1 -0
  17. package/lib-commonjs/{config → commands/config}/dependencyConfig.d.ts +37 -37
  18. package/lib-commonjs/commands/config/dependencyConfig.js +228 -0
  19. package/lib-commonjs/commands/config/dependencyConfig.js.map +1 -0
  20. package/lib-commonjs/{config → commands/config}/projectConfig.d.ts +27 -24
  21. package/lib-commonjs/{config → commands/config}/projectConfig.js +180 -120
  22. package/lib-commonjs/commands/config/projectConfig.js.map +1 -0
  23. package/lib-commonjs/commands/healthCheck/healthCheckList.d.ts +6 -0
  24. package/lib-commonjs/commands/healthCheck/healthCheckList.js +21 -0
  25. package/lib-commonjs/commands/healthCheck/healthCheckList.js.map +1 -0
  26. package/lib-commonjs/commands/healthCheck/healthChecks.d.ts +7 -0
  27. package/lib-commonjs/commands/healthCheck/healthChecks.js +124 -0
  28. package/lib-commonjs/commands/healthCheck/healthChecks.js.map +1 -0
  29. package/lib-commonjs/commands/initWindows/initWindows.d.ts +46 -0
  30. package/lib-commonjs/commands/initWindows/initWindows.js +244 -0
  31. package/lib-commonjs/commands/initWindows/initWindows.js.map +1 -0
  32. package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +15 -0
  33. package/lib-commonjs/commands/initWindows/initWindowsOptions.js +38 -0
  34. package/lib-commonjs/commands/initWindows/initWindowsOptions.js.map +1 -0
  35. package/lib-commonjs/{runWindows → commands/runWindows}/runWindows.d.ts +10 -10
  36. package/lib-commonjs/commands/runWindows/runWindows.js +322 -0
  37. package/lib-commonjs/commands/runWindows/runWindows.js.map +1 -0
  38. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.d.ts +56 -52
  39. package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.js +132 -131
  40. package/lib-commonjs/commands/runWindows/runWindowsOptions.js.map +1 -0
  41. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -0
  42. package/lib-commonjs/e2etest/autolink.test.js +367 -0
  43. package/lib-commonjs/e2etest/autolink.test.js.map +1 -0
  44. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -0
  45. package/lib-commonjs/e2etest/dependencyConfig.test.js +130 -0
  46. package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -0
  47. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -0
  48. package/lib-commonjs/e2etest/healthChecks.test.js +31 -0
  49. package/lib-commonjs/e2etest/healthChecks.test.js.map +1 -0
  50. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -0
  51. package/lib-commonjs/e2etest/initWindows.test.js +43 -0
  52. package/lib-commonjs/e2etest/initWindows.test.js.map +1 -0
  53. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -0
  54. package/lib-commonjs/e2etest/projectConfig.test.js +111 -0
  55. package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -0
  56. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -0
  57. package/lib-commonjs/e2etest/projectConfig.utils.js +77 -0
  58. package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
  59. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
  60. package/lib-commonjs/e2etest/runWindows.test.js +61 -0
  61. package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
  62. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  63. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  64. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  65. package/lib-commonjs/generator-common/index.d.ts +39 -23
  66. package/lib-commonjs/generator-common/index.js +242 -221
  67. package/lib-commonjs/generator-common/index.js.map +1 -1
  68. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  69. package/lib-commonjs/generator-windows/index.js +316 -352
  70. package/lib-commonjs/generator-windows/index.js.map +1 -1
  71. package/lib-commonjs/index.d.ts +50 -46
  72. package/lib-commonjs/index.js +77 -39
  73. package/lib-commonjs/index.js.map +1 -1
  74. package/lib-commonjs/{runWindows/utils → utils}/build.d.ts +12 -13
  75. package/lib-commonjs/{runWindows/utils → utils}/build.js +84 -91
  76. package/lib-commonjs/utils/build.js.map +1 -0
  77. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.d.ts +6 -6
  78. package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.js +69 -65
  79. package/lib-commonjs/utils/checkRequirements.js.map +1 -0
  80. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.d.ts +21 -13
  81. package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.js +149 -113
  82. package/lib-commonjs/utils/commandWithProgress.js.map +1 -0
  83. package/lib-commonjs/{runWindows/utils → utils}/deploy.d.ts +12 -12
  84. package/lib-commonjs/utils/deploy.js +354 -0
  85. package/lib-commonjs/utils/deploy.js.map +1 -0
  86. package/lib-commonjs/{runWindows/utils → utils}/info.d.ts +6 -6
  87. package/lib-commonjs/{runWindows/utils → utils}/info.js +28 -25
  88. package/lib-commonjs/utils/info.js.map +1 -0
  89. package/lib-commonjs/utils/msbuildtools.d.ts +28 -0
  90. package/lib-commonjs/utils/msbuildtools.js +274 -0
  91. package/lib-commonjs/utils/msbuildtools.js.map +1 -0
  92. package/lib-commonjs/utils/pathHelpers.d.ts +9 -0
  93. package/lib-commonjs/utils/pathHelpers.js +37 -0
  94. package/lib-commonjs/utils/pathHelpers.js.map +1 -0
  95. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -0
  96. package/lib-commonjs/utils/telemetryHelpers.js +121 -0
  97. package/lib-commonjs/utils/telemetryHelpers.js.map +1 -0
  98. package/lib-commonjs/{runWindows/utils → utils}/version.d.ts +19 -19
  99. package/lib-commonjs/{runWindows/utils → utils}/version.js +109 -109
  100. package/lib-commonjs/utils/version.js.map +1 -0
  101. package/lib-commonjs/{runWindows/utils → utils}/vsInstalls.d.ts +34 -34
  102. package/lib-commonjs/utils/vsInstalls.js +100 -0
  103. package/lib-commonjs/utils/vsInstalls.js.map +1 -0
  104. package/lib-commonjs/{runWindows/utils → utils}/vstools.d.ts +16 -15
  105. package/lib-commonjs/utils/vstools.js +190 -0
  106. package/lib-commonjs/utils/vstools.js.map +1 -0
  107. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.d.ts +24 -24
  108. package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.js +108 -105
  109. package/lib-commonjs/utils/winappdeploytool.js.map +1 -0
  110. package/package.json +50 -30
  111. package/{powershell → src/powershell}/Add-AppDevPackage.ps1 +2 -2
  112. package/src/powershell/Eval-MsBuildProperties.ps1 +156 -0
  113. package/{powershell → src/powershell}/WindowsStoreAppUtils.ps1 +10 -0
  114. package/CHANGELOG.json +0 -317
  115. package/CHANGELOG.md +0 -159
  116. package/lib-commonjs/config/configUtils.js +0 -253
  117. package/lib-commonjs/config/configUtils.js.map +0 -1
  118. package/lib-commonjs/config/dependencyConfig.js +0 -167
  119. package/lib-commonjs/config/dependencyConfig.js.map +0 -1
  120. package/lib-commonjs/config/projectConfig.js.map +0 -1
  121. package/lib-commonjs/runWindows/runWindows.js +0 -159
  122. package/lib-commonjs/runWindows/runWindows.js.map +0 -1
  123. package/lib-commonjs/runWindows/runWindowsOptions.js.map +0 -1
  124. package/lib-commonjs/runWindows/utils/autolink.d.ts +0 -7
  125. package/lib-commonjs/runWindows/utils/autolink.js +0 -353
  126. package/lib-commonjs/runWindows/utils/autolink.js.map +0 -1
  127. package/lib-commonjs/runWindows/utils/build.js.map +0 -1
  128. package/lib-commonjs/runWindows/utils/checkRequirements.js.map +0 -1
  129. package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +0 -1
  130. package/lib-commonjs/runWindows/utils/deploy.js +0 -247
  131. package/lib-commonjs/runWindows/utils/deploy.js.map +0 -1
  132. package/lib-commonjs/runWindows/utils/info.js.map +0 -1
  133. package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +0 -22
  134. package/lib-commonjs/runWindows/utils/msbuildtools.js +0 -195
  135. package/lib-commonjs/runWindows/utils/msbuildtools.js.map +0 -1
  136. package/lib-commonjs/runWindows/utils/version.js.map +0 -1
  137. package/lib-commonjs/runWindows/utils/vsInstalls.js +0 -70
  138. package/lib-commonjs/runWindows/utils/vsInstalls.js.map +0 -1
  139. package/lib-commonjs/runWindows/utils/vstools.js +0 -150
  140. package/lib-commonjs/runWindows/utils/vstools.js.map +0 -1
  141. package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +0 -1
@@ -1,222 +1,243 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- * @format
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.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");
14
- function walk(current) {
15
- if (!fs.lstatSync(current).isDirectory()) {
16
- return [current];
17
- }
18
- const files = fs
19
- .readdirSync(current)
20
- .map(child => walk(path.join(current, child)));
21
- const result = [];
22
- return result.concat.apply([current], files);
23
- }
24
- /**
25
- * Get a source file and replace parts of its contents.
26
- * @param srcPath Path to the source file.
27
- * @param replacements e.g. {'TextToBeReplaced': 'Replacement'}
28
- * @return The contents of the file with the replacements applied.
29
- */
30
- function resolveContents(srcPath, replacements) {
31
- let content = fs.readFileSync(srcPath, 'utf8');
32
- if (replacements.useMustache) {
33
- content = mustache.render(content, replacements);
34
- (replacements.regExpPatternsToRemove || []).forEach(regexPattern => {
35
- content = content.replace(new RegExp(regexPattern, 'g'), '');
36
- });
37
- }
38
- else {
39
- Object.keys(replacements).forEach(regex => {
40
- content = content.replace(new RegExp(regex, 'g'), replacements[regex]);
41
- });
42
- }
43
- return content;
44
- }
45
- exports.resolveContents = resolveContents;
46
- // Binary files, don't process these (avoid decoding as utf8)
47
- const binaryExtensions = ['.png', '.jar', '.keystore'];
48
- /**
49
- * Copy a file to given destination, replacing parts of its contents.
50
- * @param srcPath Path to a file to be copied.
51
- * @param destPath Destination path.
52
- * @param replacements: e.g. {'TextToBeReplaced': 'Replacement'}
53
- * @param contentChangedCallback
54
- * Used when upgrading projects. Based on if file contents would change
55
- * when being replaced, allows the caller to specify whether the file
56
- * should be replaced or not.
57
- * If null, files will be overwritten.
58
- * Function(path, 'identical' | 'changed' | 'new') => 'keep' | 'overwrite'
59
- */
60
- async function copyAndReplace(srcPath, destPath, replacements, contentChangedCallback) {
61
- if (fs.lstatSync(srcPath).isDirectory()) {
62
- if (!fs.existsSync(destPath)) {
63
- fs.mkdirSync(destPath);
64
- }
65
- // Not recursive
66
- return;
67
- }
68
- const extension = path.extname(srcPath);
69
- if (binaryExtensions.indexOf(extension) !== -1) {
70
- // Binary file
71
- let shouldOverwrite = 'overwrite';
72
- if (contentChangedCallback) {
73
- const newContentBuffer = fs.readFileSync(srcPath);
74
- let contentChanged = 'identical';
75
- try {
76
- const origContentBuffer = fs.readFileSync(destPath);
77
- if (Buffer.compare(origContentBuffer, newContentBuffer) !== 0) {
78
- contentChanged = 'changed';
79
- }
80
- }
81
- catch (err) {
82
- if (err.code === 'ENOENT') {
83
- contentChanged = 'new';
84
- }
85
- else {
86
- throw err;
87
- }
88
- }
89
- shouldOverwrite = await contentChangedCallback(destPath, contentChanged);
90
- }
91
- if (shouldOverwrite === 'overwrite') {
92
- copyBinaryFile(srcPath, destPath, err => {
93
- if (err) {
94
- throw err;
95
- }
96
- });
97
- }
98
- }
99
- else {
100
- // Text file
101
- const srcPermissions = fs.statSync(srcPath).mode;
102
- let content = resolveContents(srcPath, replacements);
103
- let shouldOverwrite = 'overwrite';
104
- if (contentChangedCallback) {
105
- // Check if contents changed and ask to overwrite
106
- let contentChanged = 'identical';
107
- try {
108
- const origContent = fs.readFileSync(destPath, 'utf8');
109
- if (content !== origContent) {
110
- // logger.info('Content changed: ' + destPath);
111
- contentChanged = 'changed';
112
- }
113
- }
114
- catch (err) {
115
- if (err.code === 'ENOENT') {
116
- contentChanged = 'new';
117
- }
118
- else {
119
- throw err;
120
- }
121
- }
122
- shouldOverwrite = await contentChangedCallback(destPath, contentChanged);
123
- }
124
- if (shouldOverwrite === 'overwrite') {
125
- fs.writeFileSync(destPath, content, {
126
- encoding: 'utf8',
127
- mode: srcPermissions,
128
- });
129
- }
130
- }
131
- }
132
- /**
133
- * Same as 'cp' on Unix. Don't do any replacements.
134
- */
135
- function copyBinaryFile(srcPath, destPath, cb) {
136
- let cbCalled = false;
137
- const srcPermissions = fs.statSync(srcPath).mode;
138
- const readStream = fs.createReadStream(srcPath);
139
- readStream.on('error', err => {
140
- done(err);
141
- });
142
- const writeStream = fs.createWriteStream(destPath, {
143
- mode: srcPermissions,
144
- });
145
- writeStream.on('error', err => {
146
- done(err);
147
- });
148
- writeStream.on('close', () => {
149
- done();
150
- });
151
- readStream.pipe(writeStream);
152
- function done(err) {
153
- if (!cbCalled) {
154
- cb(err);
155
- cbCalled = true;
156
- }
157
- }
158
- }
159
- function createDir(destPath) {
160
- if (!fs.existsSync(destPath)) {
161
- fs.mkdirSync(destPath);
162
- }
163
- }
164
- exports.createDir = createDir;
165
- async function copyAndReplaceWithChangedCallback(srcPath, destRoot, relativeDestPath, replacements, alwaysOverwrite) {
166
- if (!replacements) {
167
- replacements = {};
168
- }
169
- const contentChangedCallback = alwaysOverwrite
170
- ? (_, contentChanged) => alwaysOverwriteContentChangedCallback(srcPath, relativeDestPath, contentChanged)
171
- : (_, contentChanged) => upgradeFileContentChangedCallback(srcPath, relativeDestPath, contentChanged);
172
- await copyAndReplace(srcPath, path.join(destRoot, relativeDestPath), replacements, contentChangedCallback);
173
- }
174
- exports.copyAndReplaceWithChangedCallback = copyAndReplaceWithChangedCallback;
175
- async function copyAndReplaceAll(srcPath, destPath, relativeDestDir, replacements, alwaysOverwrite) {
176
- for (const absoluteSrcFilePath of walk(srcPath)) {
177
- const filename = path.relative(srcPath, absoluteSrcFilePath);
178
- const relativeDestPath = path.join(relativeDestDir, filename);
179
- await copyAndReplaceWithChangedCallback(absoluteSrcFilePath, destPath, relativeDestPath, replacements, alwaysOverwrite);
180
- }
181
- }
182
- exports.copyAndReplaceAll = copyAndReplaceAll;
183
- async function alwaysOverwriteContentChangedCallback(absoluteSrcFilePath, relativeDestPath, contentChanged) {
184
- if (contentChanged === 'new') {
185
- console.log(`${chalk.bold('new')} ${relativeDestPath}`);
186
- return 'overwrite';
187
- }
188
- if (contentChanged === 'changed') {
189
- console.log(`${chalk.bold('changed')} ${relativeDestPath} ${chalk.yellow('[overwriting]')}`);
190
- return 'overwrite';
191
- }
192
- if (contentChanged === 'identical') {
193
- return 'keep';
194
- }
195
- throw new Error(`Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
196
- }
197
- async function upgradeFileContentChangedCallback(absoluteSrcFilePath, relativeDestPath, contentChanged) {
198
- if (contentChanged === 'new') {
199
- console.log(`${chalk.bold('new')} ${relativeDestPath}`);
200
- return 'overwrite';
201
- }
202
- if (contentChanged === 'changed') {
203
- console.log(`${chalk.bold(relativeDestPath)} ` +
204
- `has changed in the new version.\nDo you want to keep your ${relativeDestPath} or replace it with the ` +
205
- 'latest version?\nMake sure you have any changes you made to this file saved somewhere.\n' +
206
- `You can see the new version here: ${absoluteSrcFilePath}`);
207
- const { shoudReplace } = await inquirer.prompt([
208
- {
209
- name: 'shouldReplace',
210
- type: 'confirm',
211
- message: `Do you want to replace ${relativeDestPath}?`,
212
- default: false,
213
- },
214
- ]);
215
- return shoudReplace ? 'overwrite' : 'keep';
216
- }
217
- if (contentChanged === 'identical') {
218
- return 'keep';
219
- }
220
- throw new Error(`Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
221
- }
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.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");
18
+ function walk(current) {
19
+ if (!fs_1.default.lstatSync(current).isDirectory()) {
20
+ return [current];
21
+ }
22
+ const files = fs_1.default
23
+ .readdirSync(current)
24
+ .map(child => walk(path_1.default.join(current, child)));
25
+ const result = [];
26
+ return result.concat.apply([current], files);
27
+ }
28
+ /**
29
+ * Get a source file and replace parts of its contents.
30
+ * @param srcPath Path to the source file.
31
+ * @param replacements e.g. {'TextToBeReplaced': 'Replacement'}
32
+ * @return The contents of the file with the replacements applied.
33
+ */
34
+ function resolveContents(srcPath, replacements) {
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
+ }
52
+ if (replacements.useMustache) {
53
+ content = mustache_1.default.render(content, replacements);
54
+ (replacements.regExpPatternsToRemove || []).forEach(regexPattern => {
55
+ content = content.replace(new RegExp(regexPattern, 'g'), '');
56
+ });
57
+ }
58
+ else {
59
+ Object.keys(replacements).forEach(regex => {
60
+ content = content.replace(new RegExp(regex, 'g'), replacements[regex]);
61
+ });
62
+ }
63
+ return content;
64
+ }
65
+ exports.resolveContents = resolveContents;
66
+ // Binary files, don't process these (avoid decoding as utf8)
67
+ const binaryExtensions = ['.png', '.jar', '.keystore', '.ico', '.rc'];
68
+ /**
69
+ * Copy a file to given destination, replacing parts of its contents.
70
+ * @param srcPath Path to a file to be copied.
71
+ * @param destPath Destination path.
72
+ * @param replacements: e.g. {'TextToBeReplaced': 'Replacement'}
73
+ * @param contentChangedCallback
74
+ * Used when upgrading projects. Based on if file contents would change
75
+ * when being replaced, allows the caller to specify whether the file
76
+ * should be replaced or not.
77
+ * If null, files will be overwritten.
78
+ * Function(path, 'identical' | 'changed' | 'new') => 'keep' | 'overwrite'
79
+ */
80
+ async function copyAndReplace(srcPath, destPath, replacements, contentChangedCallback) {
81
+ if (fs_1.default.lstatSync(srcPath).isDirectory()) {
82
+ if (!fs_1.default.existsSync(destPath)) {
83
+ fs_1.default.mkdirSync(destPath);
84
+ }
85
+ // Not recursive
86
+ return;
87
+ }
88
+ const extension = path_1.default.extname(srcPath);
89
+ if (binaryExtensions.includes(extension)) {
90
+ // Binary file
91
+ let shouldOverwrite = 'overwrite';
92
+ if (contentChangedCallback) {
93
+ const newContentBuffer = fs_1.default.readFileSync(srcPath);
94
+ let contentChanged = 'identical';
95
+ try {
96
+ const origContentBuffer = fs_1.default.readFileSync(destPath);
97
+ if (Buffer.compare(origContentBuffer, newContentBuffer) !== 0) {
98
+ contentChanged = 'changed';
99
+ }
100
+ }
101
+ catch (err) {
102
+ if (err.code === 'ENOENT') {
103
+ contentChanged = 'new';
104
+ }
105
+ else {
106
+ throw err;
107
+ }
108
+ }
109
+ shouldOverwrite = await contentChangedCallback(destPath, contentChanged);
110
+ }
111
+ if (shouldOverwrite === 'overwrite') {
112
+ copyBinaryFile(srcPath, destPath, err => {
113
+ if (err) {
114
+ throw err;
115
+ }
116
+ });
117
+ }
118
+ }
119
+ else {
120
+ // Text file
121
+ const srcPermissions = fs_1.default.statSync(srcPath).mode;
122
+ const content = resolveContents(srcPath, replacements);
123
+ let shouldOverwrite = 'overwrite';
124
+ if (contentChangedCallback) {
125
+ // Check if contents changed and ask to overwrite
126
+ let contentChanged = 'identical';
127
+ try {
128
+ const origContent = fs_1.default.readFileSync(destPath, 'utf8');
129
+ if (content !== origContent) {
130
+ // logger.info('Content changed: ' + destPath);
131
+ contentChanged = 'changed';
132
+ }
133
+ }
134
+ catch (err) {
135
+ if (err.code === 'ENOENT') {
136
+ contentChanged = 'new';
137
+ }
138
+ else {
139
+ throw err;
140
+ }
141
+ }
142
+ shouldOverwrite = await contentChangedCallback(destPath, contentChanged);
143
+ }
144
+ if (shouldOverwrite === 'overwrite') {
145
+ fs_1.default.writeFileSync(destPath, content, {
146
+ encoding: 'utf8',
147
+ mode: srcPermissions,
148
+ });
149
+ }
150
+ }
151
+ }
152
+ exports.copyAndReplace = copyAndReplace;
153
+ /**
154
+ * Same as 'cp' on Unix. Don't do any replacements.
155
+ */
156
+ function copyBinaryFile(srcPath, destPath, cb) {
157
+ let cbCalled = false;
158
+ const srcPermissions = fs_1.default.statSync(srcPath).mode;
159
+ const readStream = fs_1.default.createReadStream(srcPath);
160
+ readStream.on('error', err => {
161
+ done(err);
162
+ });
163
+ const writeStream = fs_1.default.createWriteStream(destPath, {
164
+ mode: srcPermissions,
165
+ });
166
+ writeStream.on('error', err => {
167
+ done(err);
168
+ });
169
+ writeStream.on('close', () => {
170
+ done();
171
+ });
172
+ readStream.pipe(writeStream);
173
+ function done(err) {
174
+ if (!cbCalled) {
175
+ cb(err);
176
+ cbCalled = true;
177
+ }
178
+ }
179
+ }
180
+ function createDir(destPath) {
181
+ if (!fs_1.default.existsSync(destPath)) {
182
+ fs_1.default.mkdirSync(destPath);
183
+ }
184
+ }
185
+ exports.createDir = createDir;
186
+ async function copyAndReplaceWithChangedCallback(srcPath, destRoot, relativeDestPath, replacements, alwaysOverwrite) {
187
+ if (!replacements) {
188
+ replacements = {};
189
+ }
190
+ const contentChangedCallback = alwaysOverwrite
191
+ ? (_, contentChanged) => alwaysOverwriteContentChangedCallback(srcPath, relativeDestPath, contentChanged)
192
+ : (_, contentChanged) => upgradeFileContentChangedCallback(srcPath, relativeDestPath, contentChanged);
193
+ await copyAndReplace(srcPath, path_1.default.join(destRoot, relativeDestPath), replacements, contentChangedCallback);
194
+ }
195
+ exports.copyAndReplaceWithChangedCallback = copyAndReplaceWithChangedCallback;
196
+ async function copyAndReplaceAll(srcPath, destPath, relativeDestDir, replacements, alwaysOverwrite) {
197
+ for (const absoluteSrcFilePath of walk(srcPath)) {
198
+ const filename = path_1.default.relative(srcPath, absoluteSrcFilePath);
199
+ const relativeDestPath = path_1.default.join(relativeDestDir, filename);
200
+ await copyAndReplaceWithChangedCallback(absoluteSrcFilePath, destPath, relativeDestPath, replacements, alwaysOverwrite);
201
+ }
202
+ }
203
+ exports.copyAndReplaceAll = copyAndReplaceAll;
204
+ async function alwaysOverwriteContentChangedCallback(absoluteSrcFilePath, relativeDestPath, contentChanged) {
205
+ if (contentChanged === 'new') {
206
+ console.log(`${chalk_1.default.bold('new')} ${relativeDestPath}`);
207
+ return 'overwrite';
208
+ }
209
+ if (contentChanged === 'changed') {
210
+ console.log(`${chalk_1.default.bold('changed')} ${relativeDestPath} ${chalk_1.default.yellow('[overwriting]')}`);
211
+ return 'overwrite';
212
+ }
213
+ if (contentChanged === 'identical') {
214
+ return 'keep';
215
+ }
216
+ throw new telemetry_1.CodedError('Autolinking', `Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
217
+ }
218
+ async function upgradeFileContentChangedCallback(absoluteSrcFilePath, relativeDestPath, contentChanged) {
219
+ if (contentChanged === 'new') {
220
+ console.log(`${chalk_1.default.bold('new')} ${relativeDestPath}`);
221
+ return 'overwrite';
222
+ }
223
+ if (contentChanged === 'changed') {
224
+ console.log(`${chalk_1.default.bold(relativeDestPath)} ` +
225
+ `has changed in the new version.\nDo you want to keep your ${relativeDestPath} or replace it with the ` +
226
+ 'latest version?\nMake sure you have any changes you made to this file saved somewhere.\n' +
227
+ `You can see the new version here: ${absoluteSrcFilePath}`);
228
+ const { shouldReplace } = await (0, prompts_1.default)([
229
+ {
230
+ name: 'shouldReplace',
231
+ type: 'confirm',
232
+ message: `Do you want to replace ${relativeDestPath}?`,
233
+ initial: false,
234
+ },
235
+ ]);
236
+ return shouldReplace ? 'overwrite' : 'keep';
237
+ }
238
+ if (contentChanged === 'identical') {
239
+ return 'keep';
240
+ }
241
+ throw new telemetry_1.CodedError('Autolinking', `Unknown file changed state: ${relativeDestPath}, ${contentChanged}`);
242
+ }
222
243
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator-common/index.ts"],"names":[],"mappings":";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D,OAAO,EAAE,KAAK;aACf;SACF,CAAC,CAAC;QAEH,OAAO,aAAa,CAAC,CAAC,CAAC,WAAW,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', '.ico', '.rc'];\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"]}
@@ -1,10 +1,10 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- * @format
5
- */
6
- import { GenerateOptions } from '..';
7
- export declare function copyProjectTemplateAndReplace(srcRootPath: string, destPath: string, newProjectName: string, namespace: string, options: GenerateOptions): Promise<void>;
8
- export declare function installDependencies(options: {
9
- verbose: boolean;
10
- }): void;
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { GenerateOptions } from '..';
7
+ export declare function copyProjectTemplateAndReplace(srcRootPath: string, destPath: string, newProjectName: string, namespace: string, options: GenerateOptions): Promise<void>;
8
+ export declare function installScriptsAndDependencies(options: {
9
+ verbose: boolean;
10
+ }): Promise<void>;