@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.
- package/README.md +47 -0
- package/lib-commonjs/commands/autolinkWindows/autolinkWindows.d.ts +87 -0
- package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js +661 -0
- package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js.map +1 -0
- package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.d.ts +14 -0
- package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js +33 -0
- package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js.map +1 -0
- package/lib-commonjs/commands/codegenWindows/codegenWindows.d.ts +27 -0
- package/lib-commonjs/commands/codegenWindows/codegenWindows.js +206 -0
- package/lib-commonjs/commands/codegenWindows/codegenWindows.js.map +1 -0
- package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.d.ts +12 -0
- package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js +23 -0
- package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js.map +1 -0
- package/lib-commonjs/{config → commands/config}/configUtils.d.ts +123 -93
- package/lib-commonjs/commands/config/configUtils.js +381 -0
- package/lib-commonjs/commands/config/configUtils.js.map +1 -0
- package/lib-commonjs/{config → commands/config}/dependencyConfig.d.ts +37 -37
- package/lib-commonjs/commands/config/dependencyConfig.js +228 -0
- package/lib-commonjs/commands/config/dependencyConfig.js.map +1 -0
- package/lib-commonjs/{config → commands/config}/projectConfig.d.ts +27 -24
- package/lib-commonjs/{config → commands/config}/projectConfig.js +180 -120
- package/lib-commonjs/commands/config/projectConfig.js.map +1 -0
- package/lib-commonjs/commands/healthCheck/healthCheckList.d.ts +6 -0
- package/lib-commonjs/commands/healthCheck/healthCheckList.js +21 -0
- package/lib-commonjs/commands/healthCheck/healthCheckList.js.map +1 -0
- package/lib-commonjs/commands/healthCheck/healthChecks.d.ts +7 -0
- package/lib-commonjs/commands/healthCheck/healthChecks.js +124 -0
- package/lib-commonjs/commands/healthCheck/healthChecks.js.map +1 -0
- package/lib-commonjs/commands/initWindows/initWindows.d.ts +46 -0
- package/lib-commonjs/commands/initWindows/initWindows.js +244 -0
- package/lib-commonjs/commands/initWindows/initWindows.js.map +1 -0
- package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +15 -0
- package/lib-commonjs/commands/initWindows/initWindowsOptions.js +38 -0
- package/lib-commonjs/commands/initWindows/initWindowsOptions.js.map +1 -0
- package/lib-commonjs/{runWindows → commands/runWindows}/runWindows.d.ts +10 -10
- package/lib-commonjs/commands/runWindows/runWindows.js +322 -0
- package/lib-commonjs/commands/runWindows/runWindows.js.map +1 -0
- package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.d.ts +56 -52
- package/lib-commonjs/{runWindows → commands/runWindows}/runWindowsOptions.js +132 -131
- package/lib-commonjs/commands/runWindows/runWindowsOptions.js.map +1 -0
- package/lib-commonjs/e2etest/autolink.test.d.ts +6 -0
- package/lib-commonjs/e2etest/autolink.test.js +367 -0
- package/lib-commonjs/e2etest/autolink.test.js.map +1 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.js +130 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -0
- package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -0
- package/lib-commonjs/e2etest/healthChecks.test.js +31 -0
- package/lib-commonjs/e2etest/healthChecks.test.js.map +1 -0
- package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -0
- package/lib-commonjs/e2etest/initWindows.test.js +43 -0
- package/lib-commonjs/e2etest/initWindows.test.js.map +1 -0
- package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -0
- package/lib-commonjs/e2etest/projectConfig.test.js +111 -0
- package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -0
- package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -0
- package/lib-commonjs/e2etest/projectConfig.utils.js +77 -0
- package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
- package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
- package/lib-commonjs/e2etest/runWindows.test.js +61 -0
- package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
- package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
- package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
- package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
- package/lib-commonjs/generator-common/index.d.ts +39 -23
- package/lib-commonjs/generator-common/index.js +242 -221
- package/lib-commonjs/generator-common/index.js.map +1 -1
- package/lib-commonjs/generator-windows/index.d.ts +10 -10
- package/lib-commonjs/generator-windows/index.js +316 -352
- package/lib-commonjs/generator-windows/index.js.map +1 -1
- package/lib-commonjs/index.d.ts +50 -46
- package/lib-commonjs/index.js +77 -39
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/{runWindows/utils → utils}/build.d.ts +12 -13
- package/lib-commonjs/{runWindows/utils → utils}/build.js +84 -91
- package/lib-commonjs/utils/build.js.map +1 -0
- package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.d.ts +6 -6
- package/lib-commonjs/{runWindows/utils → utils}/checkRequirements.js +69 -65
- package/lib-commonjs/utils/checkRequirements.js.map +1 -0
- package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.d.ts +21 -13
- package/lib-commonjs/{runWindows/utils → utils}/commandWithProgress.js +149 -113
- package/lib-commonjs/utils/commandWithProgress.js.map +1 -0
- package/lib-commonjs/{runWindows/utils → utils}/deploy.d.ts +12 -12
- package/lib-commonjs/utils/deploy.js +354 -0
- package/lib-commonjs/utils/deploy.js.map +1 -0
- package/lib-commonjs/{runWindows/utils → utils}/info.d.ts +6 -6
- package/lib-commonjs/{runWindows/utils → utils}/info.js +28 -25
- package/lib-commonjs/utils/info.js.map +1 -0
- package/lib-commonjs/utils/msbuildtools.d.ts +28 -0
- package/lib-commonjs/utils/msbuildtools.js +274 -0
- package/lib-commonjs/utils/msbuildtools.js.map +1 -0
- package/lib-commonjs/utils/pathHelpers.d.ts +9 -0
- package/lib-commonjs/utils/pathHelpers.js +37 -0
- package/lib-commonjs/utils/pathHelpers.js.map +1 -0
- package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -0
- package/lib-commonjs/utils/telemetryHelpers.js +121 -0
- package/lib-commonjs/utils/telemetryHelpers.js.map +1 -0
- package/lib-commonjs/{runWindows/utils → utils}/version.d.ts +19 -19
- package/lib-commonjs/{runWindows/utils → utils}/version.js +109 -109
- package/lib-commonjs/utils/version.js.map +1 -0
- package/lib-commonjs/{runWindows/utils → utils}/vsInstalls.d.ts +34 -34
- package/lib-commonjs/utils/vsInstalls.js +100 -0
- package/lib-commonjs/utils/vsInstalls.js.map +1 -0
- package/lib-commonjs/{runWindows/utils → utils}/vstools.d.ts +16 -15
- package/lib-commonjs/utils/vstools.js +190 -0
- package/lib-commonjs/utils/vstools.js.map +1 -0
- package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.d.ts +24 -24
- package/lib-commonjs/{runWindows/utils → utils}/winappdeploytool.js +108 -105
- package/lib-commonjs/utils/winappdeploytool.js.map +1 -0
- package/package.json +50 -30
- package/{powershell → src/powershell}/Add-AppDevPackage.ps1 +2 -2
- package/src/powershell/Eval-MsBuildProperties.ps1 +156 -0
- package/{powershell → src/powershell}/WindowsStoreAppUtils.ps1 +10 -0
- package/CHANGELOG.json +0 -317
- package/CHANGELOG.md +0 -159
- package/lib-commonjs/config/configUtils.js +0 -253
- package/lib-commonjs/config/configUtils.js.map +0 -1
- package/lib-commonjs/config/dependencyConfig.js +0 -167
- package/lib-commonjs/config/dependencyConfig.js.map +0 -1
- package/lib-commonjs/config/projectConfig.js.map +0 -1
- package/lib-commonjs/runWindows/runWindows.js +0 -159
- package/lib-commonjs/runWindows/runWindows.js.map +0 -1
- package/lib-commonjs/runWindows/runWindowsOptions.js.map +0 -1
- package/lib-commonjs/runWindows/utils/autolink.d.ts +0 -7
- package/lib-commonjs/runWindows/utils/autolink.js +0 -353
- package/lib-commonjs/runWindows/utils/autolink.js.map +0 -1
- package/lib-commonjs/runWindows/utils/build.js.map +0 -1
- package/lib-commonjs/runWindows/utils/checkRequirements.js.map +0 -1
- package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +0 -1
- package/lib-commonjs/runWindows/utils/deploy.js +0 -247
- package/lib-commonjs/runWindows/utils/deploy.js.map +0 -1
- package/lib-commonjs/runWindows/utils/info.js.map +0 -1
- package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +0 -22
- package/lib-commonjs/runWindows/utils/msbuildtools.js +0 -195
- package/lib-commonjs/runWindows/utils/msbuildtools.js.map +0 -1
- package/lib-commonjs/runWindows/utils/version.js.map +0 -1
- package/lib-commonjs/runWindows/utils/vsInstalls.js +0 -70
- package/lib-commonjs/runWindows/utils/vsInstalls.js.map +0 -1
- package/lib-commonjs/runWindows/utils/vstools.js +0 -150
- package/lib-commonjs/runWindows/utils/vstools.js.map +0 -1
- 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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":";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,EAAE;QACxC,OAAO,CAAC,OAAO,CAAC,CAAC;KAClB;IAED,MAAM,KAAK,GAAG,EAAE;SACb,WAAW,CAAC,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","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
|
|
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>;
|