@react-native-windows/cli 0.73.1 → 0.74.0-preview.1

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 (76) hide show
  1. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.d.ts +87 -87
  2. package/lib-commonjs/commands/autolinkWindows/autolinkWindows.js +654 -654
  3. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.d.ts +14 -14
  4. package/lib-commonjs/commands/autolinkWindows/autolinkWindowsOptions.js +32 -32
  5. package/lib-commonjs/commands/codegenWindows/codegenWindows.d.ts +27 -27
  6. package/lib-commonjs/commands/codegenWindows/codegenWindows.js +205 -205
  7. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.d.ts +12 -12
  8. package/lib-commonjs/commands/codegenWindows/codegenWindowsOptions.js +22 -22
  9. package/lib-commonjs/commands/config/configUtils.d.ts +123 -123
  10. package/lib-commonjs/commands/config/configUtils.js +380 -380
  11. package/lib-commonjs/commands/config/dependencyConfig.d.ts +37 -37
  12. package/lib-commonjs/commands/config/dependencyConfig.js +227 -227
  13. package/lib-commonjs/commands/config/projectConfig.d.ts +27 -27
  14. package/lib-commonjs/commands/config/projectConfig.js +180 -180
  15. package/lib-commonjs/commands/healthCheck/healthCheckList.d.ts +6 -6
  16. package/lib-commonjs/commands/healthCheck/healthCheckList.js +20 -20
  17. package/lib-commonjs/commands/healthCheck/healthCheckList.js.map +1 -1
  18. package/lib-commonjs/commands/healthCheck/healthChecks.d.ts +7 -7
  19. package/lib-commonjs/commands/healthCheck/healthChecks.js +123 -123
  20. package/lib-commonjs/commands/initWindows/initWindows.d.ts +46 -46
  21. package/lib-commonjs/commands/initWindows/initWindows.js +243 -243
  22. package/lib-commonjs/commands/initWindows/initWindowsOptions.d.ts +15 -15
  23. package/lib-commonjs/commands/initWindows/initWindowsOptions.js +37 -37
  24. package/lib-commonjs/commands/runWindows/runWindows.d.ts +10 -10
  25. package/lib-commonjs/commands/runWindows/runWindows.js +321 -321
  26. package/lib-commonjs/commands/runWindows/runWindowsOptions.d.ts +56 -56
  27. package/lib-commonjs/commands/runWindows/runWindowsOptions.js +132 -132
  28. package/lib-commonjs/e2etest/autolink.test.d.ts +6 -6
  29. package/lib-commonjs/e2etest/autolink.test.js +366 -366
  30. package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -6
  31. package/lib-commonjs/e2etest/dependencyConfig.test.js +129 -129
  32. package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -6
  33. package/lib-commonjs/e2etest/healthChecks.test.js +30 -30
  34. package/lib-commonjs/e2etest/initWindows.test.d.ts +6 -6
  35. package/lib-commonjs/e2etest/initWindows.test.js +42 -42
  36. package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -6
  37. package/lib-commonjs/e2etest/projectConfig.test.js +110 -110
  38. package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -8
  39. package/lib-commonjs/e2etest/projectConfig.utils.js +76 -76
  40. package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -6
  41. package/lib-commonjs/e2etest/runWindows.test.js +60 -60
  42. package/lib-commonjs/e2etest/typesUpToDate.test.d.ts +6 -0
  43. package/lib-commonjs/e2etest/typesUpToDate.test.js +21 -0
  44. package/lib-commonjs/e2etest/typesUpToDate.test.js.map +1 -0
  45. package/lib-commonjs/generator-common/index.d.ts +39 -39
  46. package/lib-commonjs/generator-common/index.js +242 -242
  47. package/lib-commonjs/generator-windows/index.d.ts +10 -10
  48. package/lib-commonjs/generator-windows/index.js +316 -316
  49. package/lib-commonjs/index.d.ts +50 -50
  50. package/lib-commonjs/index.js +77 -77
  51. package/lib-commonjs/utils/build.d.ts +12 -12
  52. package/lib-commonjs/utils/build.js +84 -84
  53. package/lib-commonjs/utils/checkRequirements.d.ts +6 -6
  54. package/lib-commonjs/utils/checkRequirements.js +69 -69
  55. package/lib-commonjs/utils/commandWithProgress.d.ts +21 -21
  56. package/lib-commonjs/utils/commandWithProgress.js +149 -149
  57. package/lib-commonjs/utils/deploy.d.ts +12 -12
  58. package/lib-commonjs/utils/deploy.js +353 -353
  59. package/lib-commonjs/utils/info.d.ts +6 -6
  60. package/lib-commonjs/utils/info.js +28 -28
  61. package/lib-commonjs/utils/msbuildtools.d.ts +28 -28
  62. package/lib-commonjs/utils/msbuildtools.js +273 -273
  63. package/lib-commonjs/utils/msbuildtools.js.map +1 -1
  64. package/lib-commonjs/utils/pathHelpers.d.ts +9 -9
  65. package/lib-commonjs/utils/pathHelpers.js +36 -36
  66. package/lib-commonjs/utils/telemetryHelpers.d.ts +29 -29
  67. package/lib-commonjs/utils/telemetryHelpers.js +120 -120
  68. package/lib-commonjs/utils/version.d.ts +19 -19
  69. package/lib-commonjs/utils/version.js +109 -109
  70. package/lib-commonjs/utils/vsInstalls.d.ts +34 -34
  71. package/lib-commonjs/utils/vsInstalls.js +99 -99
  72. package/lib-commonjs/utils/vstools.d.ts +16 -16
  73. package/lib-commonjs/utils/vstools.js +189 -189
  74. package/lib-commonjs/utils/winappdeploytool.d.ts +24 -24
  75. package/lib-commonjs/utils/winappdeploytool.js +108 -108
  76. package/package.json +16 -16
@@ -1,244 +1,244 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Microsoft Corporation.
4
- * Licensed under the MIT License.
5
- * @format
6
- */
7
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
- if (k2 === undefined) k2 = k;
9
- var desc = Object.getOwnPropertyDescriptor(m, k);
10
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
- desc = { enumerable: true, get: function() { return m[k]; } };
12
- }
13
- Object.defineProperty(o, k2, desc);
14
- }) : (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- o[k2] = m[k];
17
- }));
18
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
- Object.defineProperty(o, "default", { enumerable: true, value: v });
20
- }) : function(o, v) {
21
- o["default"] = v;
22
- });
23
- var __importStar = (this && this.__importStar) || function (mod) {
24
- if (mod && mod.__esModule) return mod;
25
- var result = {};
26
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
- __setModuleDefault(result, mod);
28
- return result;
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.initCommand = exports.initWindowsInternal = exports.InitWindows = void 0;
35
- const fs_1 = __importDefault(require("@react-native-windows/fs"));
36
- const path_1 = __importDefault(require("path"));
37
- const chalk_1 = __importDefault(require("chalk"));
38
- const glob_1 = require("glob");
39
- const lodash_1 = __importDefault(require("lodash"));
40
- const perf_hooks_1 = require("perf_hooks");
41
- const util_1 = __importDefault(require("util"));
42
- const glob = util_1.default.promisify(glob_1.glob);
43
- const telemetry_1 = require("@react-native-windows/telemetry");
44
- const commandWithProgress_1 = require("../../utils/commandWithProgress");
45
- const pathHelpers = __importStar(require("../../utils/pathHelpers"));
46
- const telemetryHelpers_1 = require("../../utils/telemetryHelpers");
47
- const generator_common_1 = require("../../generator-common");
48
- const initWindowsOptions_1 = require("./initWindowsOptions");
49
- class InitWindows {
50
- constructor(config, options) {
51
- this.config = config;
52
- this.options = options;
53
- this.templates = new Map();
54
- this.rnwPath = pathHelpers.resolveRnwRoot(this.config.root);
55
- }
56
- verboseMessage(message) {
57
- verboseMessage(message, !!this.options.logging);
58
- }
59
- async loadTemplates() {
60
- const templatesRoot = path_1.default.join(this.rnwPath, 'templates');
61
- for (const file of await glob('**/template.config.js', {
62
- cwd: templatesRoot,
63
- })) {
64
- const templateName = path_1.default.dirname(file).replace('\\', '/');
65
- const templateConfig = require(path_1.default.join(templatesRoot, file));
66
- this.templates.set(templateName, templateConfig);
67
- }
68
- if (this.templates.size === 0) {
69
- throw new telemetry_1.CodedError('NoTemplatesFound', `No templates were found in ${templatesRoot}.`);
70
- }
71
- }
72
- getDefaultTemplateName() {
73
- for (const [name, config] of this.templates) {
74
- if (config.isDefault) {
75
- return name;
76
- }
77
- }
78
- throw new telemetry_1.CodedError('NoDefaultTemplate', 'No template specified and no default template found.');
79
- }
80
- pascalCase(str) {
81
- const camelCase = lodash_1.default.camelCase(str);
82
- return camelCase[0].toUpperCase() + camelCase.substr(1);
83
- }
84
- isValidProjectName(name) {
85
- if (name.match(/^[a-z][a-z0-9]*$/gi)) {
86
- return true;
87
- }
88
- return false;
89
- }
90
- getReactNativeProjectName(projectDir) {
91
- this.verboseMessage('Looking for project name in package.json...');
92
- const pkgJsonPath = path_1.default.join(projectDir, 'package.json');
93
- if (!fs_1.default.existsSync(pkgJsonPath)) {
94
- throw new telemetry_1.CodedError('NoPackageJson', 'Unable to find package.json. This should be run from within an existing react-native project.');
95
- }
96
- let name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
97
- if (!name) {
98
- const appJsonPath = path_1.default.join(projectDir, 'app.json');
99
- if (fs_1.default.existsSync(appJsonPath)) {
100
- this.verboseMessage('Looking for project name in app.json...');
101
- name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
102
- }
103
- }
104
- if (!name) {
105
- throw new telemetry_1.CodedError('NoProjectName', 'Please specify name in package.json or app.json');
106
- }
107
- return name;
108
- }
109
- async run(spinner) {
110
- var _a, _b;
111
- var _c, _d;
112
- await this.loadTemplates();
113
- spinner.info();
114
- (_a = (_c = this.options).template) !== null && _a !== void 0 ? _a : (_c.template = this.getDefaultTemplateName());
115
- spinner.info(`Using template '${this.options.template}'...`);
116
- if (!this.templates.has(this.options.template.replace('\\', '/'))) {
117
- throw new telemetry_1.CodedError('InvalidTemplateName', `Unable to find template '${this.options.template}'.`);
118
- }
119
- const templateConfig = this.templates.get(this.options.template);
120
- if (this.options.name && !this.isValidProjectName(this.options.name)) {
121
- throw new telemetry_1.CodedError('InvalidProjectName', `The specified name is not a valid identifier`);
122
- }
123
- if (!this.options.name) {
124
- const projectName = this.getReactNativeProjectName(this.config.root);
125
- this.options.name = this.isValidProjectName(projectName)
126
- ? projectName
127
- : this.pascalCase(projectName);
128
- }
129
- (_b = (_d = this.options).namespace) !== null && _b !== void 0 ? _b : (_d.namespace = this.options.name);
130
- if (templateConfig.preInstall) {
131
- spinner.info(`Running ${this.options.template} preInstall()...`);
132
- await templateConfig.preInstall(this.config, this.options);
133
- }
134
- // Get template files to copy and copy if available
135
- if (templateConfig.getFileMappings) {
136
- const fileMappings = await templateConfig.getFileMappings(this.config, this.options);
137
- for (const fileMapping of fileMappings) {
138
- const targetDir = path_1.default.join(this.config.root, path_1.default.dirname(fileMapping.to));
139
- if (!(await fs_1.default.exists(targetDir))) {
140
- await fs_1.default.mkdir(targetDir, { recursive: true });
141
- }
142
- await (0, generator_common_1.copyAndReplaceWithChangedCallback)(fileMapping.from, this.config.root, fileMapping.to, fileMapping.replacements, this.options.overwrite);
143
- }
144
- }
145
- if (templateConfig.postInstall) {
146
- spinner.info(`Running ${this.options.template} postInstall()...`);
147
- await templateConfig.postInstall(this.config, this.options);
148
- }
149
- spinner.succeed();
150
- }
151
- }
152
- exports.InitWindows = InitWindows;
153
- /**
154
- * Logs the given message if verbose is True.
155
- * @param message The message to log.
156
- * @param verbose Whether or not verbose logging is enabled.
157
- */
158
- function verboseMessage(message, verbose) {
159
- if (verbose) {
160
- console.log(message);
161
- }
162
- }
163
- /**
164
- * Sanitizes the given option for telemetry.
165
- * @param key The key of the option.
166
- * @param value The unsanitized value of the option.
167
- * @returns The sanitized value of the option.
168
- */
169
- function optionSanitizer(key, value) {
170
- // Do not add a default case here.
171
- // Strings risking PII should just return true if present, false otherwise.
172
- // All others should return the value (or false if undefined).
173
- switch (key) {
174
- case 'name':
175
- case 'namespace':
176
- return value === undefined ? false : true; // Strip PII
177
- case 'logging':
178
- case 'template':
179
- case 'overwrite':
180
- case 'telemetry':
181
- return value === undefined ? false : value; // Return value
182
- }
183
- }
184
- /**
185
- * Get the extra props to add to the `init-windows` telemetry event.
186
- * @returns The extra props.
187
- */
188
- async function getExtraProps() {
189
- const extraProps = {};
190
- return extraProps;
191
- }
192
- /**
193
- * The function run when calling `react-native init-windows`.
194
- * @param args Unprocessed args passed from react-native CLI.
195
- * @param config Config passed from react-native CLI.
196
- * @param options Options passed from react-native CLI.
197
- */
198
- async function initWindows(args, config, options) {
199
- await (0, telemetryHelpers_1.startTelemetrySession)('init-windows', config, options, (0, telemetryHelpers_1.getDefaultOptions)(config, initWindowsOptions_1.initOptions), optionSanitizer);
200
- let initWindowsError;
201
- try {
202
- await initWindowsInternal(args, config, options);
203
- }
204
- catch (ex) {
205
- initWindowsError =
206
- ex instanceof Error ? ex : new Error(String(ex));
207
- telemetry_1.Telemetry.trackException(initWindowsError);
208
- }
209
- await (0, telemetryHelpers_1.endTelemetrySession)(initWindowsError, getExtraProps);
210
- (0, commandWithProgress_1.setExitProcessWithError)(options.logging, initWindowsError);
211
- }
212
- /**
213
- * Initializes a new RNW project from a given template.
214
- * @param args Unprocessed args passed from react-native CLI.
215
- * @param config Config passed from react-native CLI.
216
- * @param options Options passed from react-native CLI.
217
- */
218
- async function initWindowsInternal(args, config, options) {
219
- const startTime = perf_hooks_1.performance.now();
220
- const spinner = (0, commandWithProgress_1.newSpinner)('Running init-windows...');
221
- try {
222
- const codegen = new InitWindows(config, options);
223
- await codegen.run(spinner);
224
- const endTime = perf_hooks_1.performance.now();
225
- console.log(`${chalk_1.default.green('Success:')} init-windows completed. (${Math.round(endTime - startTime)}ms)`);
226
- }
227
- catch (e) {
228
- spinner.fail();
229
- const endTime = perf_hooks_1.performance.now();
230
- console.log(`${chalk_1.default.red('Error:')} ${e.toString()}. (${Math.round(endTime - startTime)}ms)`);
231
- throw e;
232
- }
233
- }
234
- exports.initWindowsInternal = initWindowsInternal;
235
- /**
236
- * Initializes a new RNW project from a given template.
237
- */
238
- exports.initCommand = {
239
- name: 'init-windows',
240
- description: 'Initializes a new RNW project from a given template.',
241
- func: initWindows,
242
- options: initWindowsOptions_1.initOptions,
243
- };
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ * @format
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || function (mod) {
24
+ if (mod && mod.__esModule) return mod;
25
+ var result = {};
26
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
+ __setModuleDefault(result, mod);
28
+ return result;
29
+ };
30
+ var __importDefault = (this && this.__importDefault) || function (mod) {
31
+ return (mod && mod.__esModule) ? mod : { "default": mod };
32
+ };
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.initCommand = exports.initWindowsInternal = exports.InitWindows = void 0;
35
+ const fs_1 = __importDefault(require("@react-native-windows/fs"));
36
+ const path_1 = __importDefault(require("path"));
37
+ const chalk_1 = __importDefault(require("chalk"));
38
+ const glob_1 = require("glob");
39
+ const lodash_1 = __importDefault(require("lodash"));
40
+ const perf_hooks_1 = require("perf_hooks");
41
+ const util_1 = __importDefault(require("util"));
42
+ const glob = util_1.default.promisify(glob_1.glob);
43
+ const telemetry_1 = require("@react-native-windows/telemetry");
44
+ const commandWithProgress_1 = require("../../utils/commandWithProgress");
45
+ const pathHelpers = __importStar(require("../../utils/pathHelpers"));
46
+ const telemetryHelpers_1 = require("../../utils/telemetryHelpers");
47
+ const generator_common_1 = require("../../generator-common");
48
+ const initWindowsOptions_1 = require("./initWindowsOptions");
49
+ class InitWindows {
50
+ constructor(config, options) {
51
+ this.config = config;
52
+ this.options = options;
53
+ this.templates = new Map();
54
+ this.rnwPath = pathHelpers.resolveRnwRoot(this.config.root);
55
+ }
56
+ verboseMessage(message) {
57
+ verboseMessage(message, !!this.options.logging);
58
+ }
59
+ async loadTemplates() {
60
+ const templatesRoot = path_1.default.join(this.rnwPath, 'templates');
61
+ for (const file of await glob('**/template.config.js', {
62
+ cwd: templatesRoot,
63
+ })) {
64
+ const templateName = path_1.default.dirname(file).replace('\\', '/');
65
+ const templateConfig = require(path_1.default.join(templatesRoot, file));
66
+ this.templates.set(templateName, templateConfig);
67
+ }
68
+ if (this.templates.size === 0) {
69
+ throw new telemetry_1.CodedError('NoTemplatesFound', `No templates were found in ${templatesRoot}.`);
70
+ }
71
+ }
72
+ getDefaultTemplateName() {
73
+ for (const [name, config] of this.templates) {
74
+ if (config.isDefault) {
75
+ return name;
76
+ }
77
+ }
78
+ throw new telemetry_1.CodedError('NoDefaultTemplate', 'No template specified and no default template found.');
79
+ }
80
+ pascalCase(str) {
81
+ const camelCase = lodash_1.default.camelCase(str);
82
+ return camelCase[0].toUpperCase() + camelCase.substr(1);
83
+ }
84
+ isValidProjectName(name) {
85
+ if (name.match(/^[a-z][a-z0-9]*$/gi)) {
86
+ return true;
87
+ }
88
+ return false;
89
+ }
90
+ getReactNativeProjectName(projectDir) {
91
+ this.verboseMessage('Looking for project name in package.json...');
92
+ const pkgJsonPath = path_1.default.join(projectDir, 'package.json');
93
+ if (!fs_1.default.existsSync(pkgJsonPath)) {
94
+ throw new telemetry_1.CodedError('NoPackageJson', 'Unable to find package.json. This should be run from within an existing react-native project.');
95
+ }
96
+ let name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
97
+ if (!name) {
98
+ const appJsonPath = path_1.default.join(projectDir, 'app.json');
99
+ if (fs_1.default.existsSync(appJsonPath)) {
100
+ this.verboseMessage('Looking for project name in app.json...');
101
+ name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
102
+ }
103
+ }
104
+ if (!name) {
105
+ throw new telemetry_1.CodedError('NoProjectName', 'Please specify name in package.json or app.json');
106
+ }
107
+ return name;
108
+ }
109
+ async run(spinner) {
110
+ var _a, _b;
111
+ var _c, _d;
112
+ await this.loadTemplates();
113
+ spinner.info();
114
+ (_a = (_c = this.options).template) !== null && _a !== void 0 ? _a : (_c.template = this.getDefaultTemplateName());
115
+ spinner.info(`Using template '${this.options.template}'...`);
116
+ if (!this.templates.has(this.options.template.replace('\\', '/'))) {
117
+ throw new telemetry_1.CodedError('InvalidTemplateName', `Unable to find template '${this.options.template}'.`);
118
+ }
119
+ const templateConfig = this.templates.get(this.options.template);
120
+ if (this.options.name && !this.isValidProjectName(this.options.name)) {
121
+ throw new telemetry_1.CodedError('InvalidProjectName', `The specified name is not a valid identifier`);
122
+ }
123
+ if (!this.options.name) {
124
+ const projectName = this.getReactNativeProjectName(this.config.root);
125
+ this.options.name = this.isValidProjectName(projectName)
126
+ ? projectName
127
+ : this.pascalCase(projectName);
128
+ }
129
+ (_b = (_d = this.options).namespace) !== null && _b !== void 0 ? _b : (_d.namespace = this.options.name);
130
+ if (templateConfig.preInstall) {
131
+ spinner.info(`Running ${this.options.template} preInstall()...`);
132
+ await templateConfig.preInstall(this.config, this.options);
133
+ }
134
+ // Get template files to copy and copy if available
135
+ if (templateConfig.getFileMappings) {
136
+ const fileMappings = await templateConfig.getFileMappings(this.config, this.options);
137
+ for (const fileMapping of fileMappings) {
138
+ const targetDir = path_1.default.join(this.config.root, path_1.default.dirname(fileMapping.to));
139
+ if (!(await fs_1.default.exists(targetDir))) {
140
+ await fs_1.default.mkdir(targetDir, { recursive: true });
141
+ }
142
+ await (0, generator_common_1.copyAndReplaceWithChangedCallback)(fileMapping.from, this.config.root, fileMapping.to, fileMapping.replacements, this.options.overwrite);
143
+ }
144
+ }
145
+ if (templateConfig.postInstall) {
146
+ spinner.info(`Running ${this.options.template} postInstall()...`);
147
+ await templateConfig.postInstall(this.config, this.options);
148
+ }
149
+ spinner.succeed();
150
+ }
151
+ }
152
+ exports.InitWindows = InitWindows;
153
+ /**
154
+ * Logs the given message if verbose is True.
155
+ * @param message The message to log.
156
+ * @param verbose Whether or not verbose logging is enabled.
157
+ */
158
+ function verboseMessage(message, verbose) {
159
+ if (verbose) {
160
+ console.log(message);
161
+ }
162
+ }
163
+ /**
164
+ * Sanitizes the given option for telemetry.
165
+ * @param key The key of the option.
166
+ * @param value The unsanitized value of the option.
167
+ * @returns The sanitized value of the option.
168
+ */
169
+ function optionSanitizer(key, value) {
170
+ // Do not add a default case here.
171
+ // Strings risking PII should just return true if present, false otherwise.
172
+ // All others should return the value (or false if undefined).
173
+ switch (key) {
174
+ case 'name':
175
+ case 'namespace':
176
+ return value === undefined ? false : true; // Strip PII
177
+ case 'logging':
178
+ case 'template':
179
+ case 'overwrite':
180
+ case 'telemetry':
181
+ return value === undefined ? false : value; // Return value
182
+ }
183
+ }
184
+ /**
185
+ * Get the extra props to add to the `init-windows` telemetry event.
186
+ * @returns The extra props.
187
+ */
188
+ async function getExtraProps() {
189
+ const extraProps = {};
190
+ return extraProps;
191
+ }
192
+ /**
193
+ * The function run when calling `react-native init-windows`.
194
+ * @param args Unprocessed args passed from react-native CLI.
195
+ * @param config Config passed from react-native CLI.
196
+ * @param options Options passed from react-native CLI.
197
+ */
198
+ async function initWindows(args, config, options) {
199
+ await (0, telemetryHelpers_1.startTelemetrySession)('init-windows', config, options, (0, telemetryHelpers_1.getDefaultOptions)(config, initWindowsOptions_1.initOptions), optionSanitizer);
200
+ let initWindowsError;
201
+ try {
202
+ await initWindowsInternal(args, config, options);
203
+ }
204
+ catch (ex) {
205
+ initWindowsError =
206
+ ex instanceof Error ? ex : new Error(String(ex));
207
+ telemetry_1.Telemetry.trackException(initWindowsError);
208
+ }
209
+ await (0, telemetryHelpers_1.endTelemetrySession)(initWindowsError, getExtraProps);
210
+ (0, commandWithProgress_1.setExitProcessWithError)(options.logging, initWindowsError);
211
+ }
212
+ /**
213
+ * Initializes a new RNW project from a given template.
214
+ * @param args Unprocessed args passed from react-native CLI.
215
+ * @param config Config passed from react-native CLI.
216
+ * @param options Options passed from react-native CLI.
217
+ */
218
+ async function initWindowsInternal(args, config, options) {
219
+ const startTime = perf_hooks_1.performance.now();
220
+ const spinner = (0, commandWithProgress_1.newSpinner)('Running init-windows...');
221
+ try {
222
+ const codegen = new InitWindows(config, options);
223
+ await codegen.run(spinner);
224
+ const endTime = perf_hooks_1.performance.now();
225
+ console.log(`${chalk_1.default.green('Success:')} init-windows completed. (${Math.round(endTime - startTime)}ms)`);
226
+ }
227
+ catch (e) {
228
+ spinner.fail();
229
+ const endTime = perf_hooks_1.performance.now();
230
+ console.log(`${chalk_1.default.red('Error:')} ${e.toString()}. (${Math.round(endTime - startTime)}ms)`);
231
+ throw e;
232
+ }
233
+ }
234
+ exports.initWindowsInternal = initWindowsInternal;
235
+ /**
236
+ * Initializes a new RNW project from a given template.
237
+ */
238
+ exports.initCommand = {
239
+ name: 'init-windows',
240
+ description: 'Initializes a new RNW project from a given template.',
241
+ func: initWindows,
242
+ options: initWindowsOptions_1.initOptions,
243
+ };
244
244
  //# sourceMappingURL=initWindows.js.map
@@ -1,15 +1,15 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- * @format
5
- */
6
- import { CommandOption } from '@react-native-community/cli-types';
7
- export interface InitOptions {
8
- logging?: boolean;
9
- template?: string;
10
- name?: string;
11
- namespace?: string;
12
- overwrite?: boolean;
13
- telemetry?: boolean;
14
- }
15
- export declare const initOptions: CommandOption[];
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { CommandOption } from '@react-native-community/cli-types';
7
+ export interface InitOptions {
8
+ logging?: boolean;
9
+ template?: string;
10
+ name?: string;
11
+ namespace?: string;
12
+ overwrite?: boolean;
13
+ telemetry?: boolean;
14
+ }
15
+ export declare const initOptions: CommandOption[];
@@ -1,38 +1,38 @@
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.initOptions = void 0;
9
- exports.initOptions = [
10
- {
11
- name: '--logging',
12
- description: 'Verbose output logging',
13
- },
14
- {
15
- name: '--template [string]',
16
- description: 'Specify the template to use',
17
- default: undefined,
18
- },
19
- {
20
- name: '--name [string]',
21
- description: 'The native project name. Defaults to the name property iin app.json or package.json',
22
- default: undefined,
23
- },
24
- {
25
- name: '--namespace [string]',
26
- description: "The native project namespace. This should be expressed using dots as separators. i.e. 'Level1.Level2.Level3'. The generator will apply the correct syntax for the target language.",
27
- default: undefined,
28
- },
29
- {
30
- name: '--overwrite',
31
- description: 'Overwrite any existing files without prompting',
32
- },
33
- {
34
- name: '--no-telemetry',
35
- description: 'Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',
36
- },
37
- ];
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.initOptions = void 0;
9
+ exports.initOptions = [
10
+ {
11
+ name: '--logging',
12
+ description: 'Verbose output logging',
13
+ },
14
+ {
15
+ name: '--template [string]',
16
+ description: 'Specify the template to use',
17
+ default: undefined,
18
+ },
19
+ {
20
+ name: '--name [string]',
21
+ description: 'The native project name. Defaults to the name property iin app.json or package.json',
22
+ default: undefined,
23
+ },
24
+ {
25
+ name: '--namespace [string]',
26
+ description: "The native project namespace. This should be expressed using dots as separators. i.e. 'Level1.Level2.Level3'. The generator will apply the correct syntax for the target language.",
27
+ default: undefined,
28
+ },
29
+ {
30
+ name: '--overwrite',
31
+ description: 'Overwrite any existing files without prompting',
32
+ },
33
+ {
34
+ name: '--no-telemetry',
35
+ description: 'Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',
36
+ },
37
+ ];
38
38
  //# sourceMappingURL=initWindowsOptions.js.map
@@ -1,10 +1,10 @@
1
- /**
2
- * Copyright (c) Microsoft Corporation.
3
- * Licensed under the MIT License.
4
- * @format
5
- */
6
- import { Command } from '@react-native-community/cli-types';
7
- /**
8
- * Starts the app on a connected Windows emulator or mobile device.
9
- */
10
- export declare const runWindowsCommand: Command;
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import { Command } from '@react-native-community/cli-types';
7
+ /**
8
+ * Starts the app on a connected Windows emulator or mobile device.
9
+ */
10
+ export declare const runWindowsCommand: Command;