react-native-windows-init 1.1.76 → 1.1.77

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/bin.js CHANGED
@@ -8,4 +8,6 @@
8
8
  */
9
9
 
10
10
  require('source-map-support').install();
11
- require('./lib-commonjs/Cli');
11
+ const cli = require('./lib-commonjs/Cli');
12
+
13
+ cli.reactNativeWindowsInit();
@@ -4,4 +4,77 @@
4
4
  *
5
5
  * @format
6
6
  */
7
- export {};
7
+ import yargs from 'yargs';
8
+ export declare const windowsInitOptions: {
9
+ version: {
10
+ type: "string";
11
+ describe: string;
12
+ };
13
+ namespace: {
14
+ type: "string";
15
+ describe: string;
16
+ };
17
+ verbose: {
18
+ type: "boolean";
19
+ describe: string;
20
+ default: boolean;
21
+ };
22
+ telemetry: {
23
+ type: "boolean";
24
+ describe: string;
25
+ default: boolean;
26
+ };
27
+ language: {
28
+ type: "string";
29
+ describe: string;
30
+ choices: string[];
31
+ default: string;
32
+ };
33
+ overwrite: {
34
+ type: "boolean";
35
+ describe: string;
36
+ default: boolean;
37
+ };
38
+ projectType: {
39
+ type: "string";
40
+ describe: string;
41
+ choices: string[];
42
+ default: string;
43
+ };
44
+ experimentalNuGetDependency: {
45
+ type: "boolean";
46
+ describe: string;
47
+ hidden: true;
48
+ default: boolean;
49
+ };
50
+ useHermes: {
51
+ type: "boolean";
52
+ describe: string;
53
+ default: boolean;
54
+ };
55
+ useWinUI3: {
56
+ type: "boolean";
57
+ describe: string;
58
+ hidden: true;
59
+ default: boolean;
60
+ };
61
+ nuGetTestVersion: {
62
+ type: "string";
63
+ describe: string;
64
+ hidden: true;
65
+ };
66
+ nuGetTestFeed: {
67
+ type: "string";
68
+ describe: string;
69
+ hidden: true;
70
+ };
71
+ useDevMode: {
72
+ type: "boolean";
73
+ describe: string;
74
+ hidden: true;
75
+ default: boolean;
76
+ conflicts: string;
77
+ };
78
+ };
79
+ export declare function reactNativeWindowsInit(args?: string[]): Promise<void>;
80
+ export declare type WindowsInitOptions = yargs.InferredOptionTypes<typeof windowsInitOptions>;
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.reactNativeWindowsInit = exports.windowsInitOptions = void 0;
12
13
  const yargs_1 = __importDefault(require("yargs"));
13
14
  const fs_1 = __importDefault(require("@react-native-windows/fs"));
14
15
  const semver_1 = __importDefault(require("semver"));
@@ -29,10 +30,11 @@ const npmConfReg = (0, child_process_1.execSync)('npm config get registry').toSt
29
30
  const NPM_REGISTRY_URL = valid_url_1.default.isUri(npmConfReg)
30
31
  ? npmConfReg
31
32
  : 'http://registry.npmjs.org';
32
- const yargsParser = yargs_1.default
33
- .version(false)
34
- .strict(true)
35
- .options({
33
+ // Causes the type-checker to ensure the options object is a valid yargs options object
34
+ function initOptions(options) {
35
+ return options;
36
+ }
37
+ exports.windowsInitOptions = initOptions({
36
38
  version: {
37
39
  type: 'string',
38
40
  describe: 'The version of react-native-windows to use.',
@@ -99,11 +101,14 @@ const yargsParser = yargs_1.default
99
101
  type: 'boolean',
100
102
  describe: '[internalTesting] Link rather than Add/Install the react-native-windows package. This option is for the development workflow of the developers working on react-native-windows.',
101
103
  hidden: true,
104
+ default: false,
102
105
  conflicts: 'version',
103
106
  },
104
- })
107
+ });
108
+ const yargsParser = yargs_1.default
109
+ .version(false)
110
+ .options(exports.windowsInitOptions)
105
111
  .strict(true);
106
- const argv = yargsParser.argv;
107
112
  function getReactNativeProjectName() {
108
113
  console.log('Reading project name from package.json...');
109
114
  const cwd = process.cwd();
@@ -195,9 +200,9 @@ async function getLatestMatchingRNWVersion(versionSemVer) {
195
200
  return null;
196
201
  }
197
202
  }
198
- function installReactNativeWindows(version, useDevMode) {
203
+ function installReactNativeWindows(version, verbose, useDevMode) {
199
204
  const cwd = process.cwd();
200
- const execOptions = argv.verbose ? { stdio: 'inherit' } : {};
205
+ const execOptions = verbose ? { stdio: 'inherit' } : {};
201
206
  if (useDevMode) {
202
207
  const packageCmd = isProjectUsingYarn(cwd) ? 'yarn' : 'npm';
203
208
  (0, child_process_1.execSync)(`${packageCmd} link react-native-windows`, execOptions);
@@ -240,19 +245,35 @@ function installReactNativeWindows(version, useDevMode) {
240
245
  * @returns The sanitized value of the option.
241
246
  */
242
247
  function optionSanitizer(key, value) {
248
+ // Do not add a default case here.
249
+ // Strings risking PII should just return true if present, false otherwise.
250
+ // All others should return the value (or false if undefined).
243
251
  switch (key) {
244
252
  case 'namespace':
245
- return value === undefined ? false : true;
246
- default:
253
+ case 'nuGetTestFeed':
254
+ case 'nuGetTestVersion':
255
+ return value ? true : false;
256
+ case 'verbose':
257
+ case 'version':
258
+ case 'telemetry':
259
+ case 'language':
260
+ case 'overwrite':
261
+ case 'projectType':
262
+ case 'experimentalNuGetDependency':
263
+ case 'useHermes':
264
+ case 'useWinUI3':
265
+ case 'useDevMode':
247
266
  return value === undefined ? false : value;
248
267
  }
249
268
  }
250
269
  /**
251
270
  * Sets up and starts the telemetry gathering for the CLI command.
271
+ * @param args The raw CLI args.
272
+ * @param options The CLI args parsed by yargs.
252
273
  */
253
- async function startTelemetrySession() {
254
- if (!argv.telemetry) {
255
- if (argv.verbose) {
274
+ async function startTelemetrySession(args, options) {
275
+ if (!options.telemetry) {
276
+ if (options.verbose) {
256
277
  console.log('Telemetry is disabled');
257
278
  }
258
279
  return;
@@ -260,9 +281,9 @@ async function startTelemetrySession() {
260
281
  // Setup telemetry, but don't get NPM package version info right away as
261
282
  // we're going to change things and this may interfere with the resolver
262
283
  await telemetry_1.Telemetry.setup({ populateNpmPackageVersions: false });
263
- const sanitizedOptions = (0, telemetry_1.yargsOptionsToOptions)(argv, optionSanitizer);
284
+ const sanitizedOptions = (0, telemetry_1.yargsOptionsToOptions)(options, optionSanitizer);
264
285
  const sanitizedDefaultOptions = (0, telemetry_1.yargsOptionsToOptions)(yargsParser.parse(''), optionSanitizer);
265
- const sanitizedArgs = (0, telemetry_1.optionsToArgs)(sanitizedOptions, process.argv);
286
+ const sanitizedArgs = (0, telemetry_1.optionsToArgs)(sanitizedOptions, args);
266
287
  const startInfo = {
267
288
  commandName: 'react-native-windows-init',
268
289
  args: sanitizedArgs,
@@ -333,18 +354,20 @@ function setExitProcessWithError(loggingIsEnabled, error) {
333
354
  function isProjectUsingYarn(cwd) {
334
355
  return !!find_up_1.default.sync('yarn.lock', { cwd });
335
356
  }
336
- (async () => {
337
- if (argv.verbose) {
338
- console.log(argv);
357
+ async function reactNativeWindowsInit(args) {
358
+ args = args !== null && args !== void 0 ? args : process.argv;
359
+ const options = yargsParser.parse(args);
360
+ if (options.verbose) {
361
+ console.log(options);
339
362
  }
340
- await startTelemetrySession();
363
+ await startTelemetrySession(args, options);
341
364
  let initWindowsError;
342
365
  try {
343
366
  const name = getReactNativeProjectName();
344
- const ns = argv.namespace || name;
345
- const useDevMode = !!argv.useDevMode;
346
- let version = argv.version;
347
- if (argv.useWinUI3 && argv.experimentalNuGetDependency) {
367
+ const ns = options.namespace || name;
368
+ const useDevMode = options.useDevMode;
369
+ let version = options.version;
370
+ if (options.useWinUI3 && options.experimentalNuGetDependency) {
348
371
  throw new telemetry_1.CodedError('IncompatibleOptions', "Error: Incompatible options specified. Options '--useWinUI3' and '--experimentalNuGetDependency' are incompatible", { detail: 'useWinUI3 and experimentalNuGetDependency' });
349
372
  }
350
373
  if (!useDevMode) {
@@ -355,8 +378,8 @@ function isProjectUsingYarn(cwd) {
355
378
  }
356
379
  const rnwResolvedVersion = await getLatestMatchingRNWVersion(version);
357
380
  if (!rnwResolvedVersion) {
358
- if (argv.version) {
359
- console.warn(`Warning: Querying npm to find react-native-windows@${argv.version} failed. Attempting to continue anyway...`);
381
+ if (options.version) {
382
+ console.warn(`Warning: Querying npm to find react-native-windows@${options.version} failed. Attempting to continue anyway...`);
360
383
  }
361
384
  else {
362
385
  const rnwLatestVersion = await getLatestRNWVersion();
@@ -367,7 +390,7 @@ function isProjectUsingYarn(cwd) {
367
390
  `, { rnwLatestVersion: rnwLatestVersion });
368
391
  }
369
392
  }
370
- if (!argv.version) {
393
+ if (!options.version) {
371
394
  console.log(`Latest matching version of ${chalk_1.default.bold('react-native-windows')} for ${chalk_1.default.green('react-native')}@${chalk_1.default.cyan(getReactNativeVersion())} is ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwResolvedVersion)}`);
372
395
  if (rnwResolvedVersion && semver_1.default.prerelease(rnwResolvedVersion)) {
373
396
  const rnwLatestVersion = await getLatestRNWVersion();
@@ -390,22 +413,22 @@ function isProjectUsingYarn(cwd) {
390
413
  version = rnwResolvedVersion;
391
414
  }
392
415
  }
393
- installReactNativeWindows(version, useDevMode);
416
+ installReactNativeWindows(version, options.verbose, useDevMode);
394
417
  const generateWindows = (0, requireGenerateWindows_1.default)();
395
418
  // Now that new NPM packages have been installed, get their versions
396
419
  await telemetry_1.Telemetry.populateNpmPackageVersions();
397
420
  await generateWindows(process.cwd(), name, ns, {
398
- language: argv.language,
399
- overwrite: argv.overwrite,
400
- verbose: argv.verbose,
401
- projectType: argv.projectType,
402
- experimentalNuGetDependency: argv.experimentalNuGetDependency,
403
- useWinUI3: argv.useWinUI3,
404
- useHermes: argv.useHermes,
421
+ language: options.language,
422
+ overwrite: options.overwrite,
423
+ verbose: options.verbose,
424
+ projectType: options.projectType,
425
+ experimentalNuGetDependency: options.experimentalNuGetDependency,
426
+ useWinUI3: options.useWinUI3,
427
+ useHermes: options.useHermes,
405
428
  useDevMode: useDevMode,
406
- nuGetTestVersion: argv.nuGetTestVersion,
407
- nuGetTestFeed: argv.nuGetTestFeed,
408
- telemetry: argv.telemetry,
429
+ nuGetTestVersion: options.nuGetTestVersion,
430
+ nuGetTestFeed: options.nuGetTestFeed,
431
+ telemetry: options.telemetry,
409
432
  });
410
433
  // Now that the project has been generated, add project info
411
434
  await addProjectInfoToTelemetry();
@@ -421,6 +444,7 @@ function isProjectUsingYarn(cwd) {
421
444
  console.error(initWindowsError);
422
445
  }
423
446
  endTelemetrySession(initWindowsError);
424
- setExitProcessWithError(argv.verbose, initWindowsError);
425
- })();
447
+ setExitProcessWithError(options.verbose, initWindowsError);
448
+ }
449
+ exports.reactNativeWindowsInit = reactNativeWindowsInit;
426
450
  //# sourceMappingURL=Cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,kEAA0C;AAC1C,oDAA4B;AAC5B,iDAAuC;AACvC,0DAAiC;AACjC,sDAA8B;AAC9B,sDAA6B;AAC7B,kDAA0B;AAC1B,4EAA0C;AAE1C,+DAUyC;AAEzC;;;;GAIG;AAEH,sFAA8D;AAE9D,MAAM,UAAU,GAAG,IAAA,wBAAQ,EAAC,yBAAyB,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;AACzE,MAAM,gBAAgB,GAAG,mBAAQ,CAAC,KAAK,CAAC,UAAU,CAAC;IACjD,CAAC,CAAC,UAAU;IACZ,CAAC,CAAC,2BAA2B,CAAC;AAEhC,MAAM,WAAW,GAAG,eAAK;KACtB,OAAO,CAAC,KAAK,CAAC;KACd,MAAM,CAAC,IAAI,CAAC;KACZ,OAAO,CAAC;IACP,OAAO,EAAE;QACP,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,6CAA6C;KACxD;IACD,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,QAAQ,EACN,mLAAmL;KACtL;IACD,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,kBAAkB;QAC5B,OAAO,EAAE,KAAK;KACf;IACD,SAAS,EAAE;QACT,IAAI,EAAE,SAAS;QACf,QAAQ,EACN,uGAAuG;QACzG,OAAO,EAAE,IAAI;KACd;IACD,QAAQ,EAAE;QACR,IAAI,EAAE,QAAQ;QACd,QAAQ,EA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MAAM,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;YAC7C,QAAQ,EAAE,IAAI,CAAC,QAAwB;YACvC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,IAAI,CAAC,WAA4B;YAC9C,2BAA2B,EAAE,IAAI,CAAC,2BAA2B;YAC7D,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,UAAU,EAAE,UAAU;YACtB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;YACvC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC,CAAC;QAEH,4DAA4D;QAC5D,MAAM,yBAAyB,EAAE,CAAC;KACnC;IAAC,OAAO,EAAE,EAAE;QACX,6DAA6D;QAC7D,yCAAyC;QACzC,MAAM,qBAAS,CAAC,0BAA0B,EAAE,CAAC;QAE7C,gBAAgB;YACd,EAAE,YAAY,KAAK,CAAC,CAAC,CAAE,EAAY,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9D,qBAAS,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QAE3C,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;QACnD,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;KACjC;IACD,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACtC,uBAAuB,CAAC,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;AAC1D,CAAC,CAAC,EAAE,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport fs from '@react-native-windows/fs';\nimport semver from 'semver';\nimport {execSync} from 'child_process';\nimport validUrl from 'valid-url';\nimport prompts from 'prompts';\nimport findUp from 'find-up';\nimport chalk from 'chalk';\nimport npmFetch from 'npm-registry-fetch';\n\nimport {\n Telemetry,\n CommandStartInfo,\n CommandEndInfo,\n CodedErrors,\n CodedError,\n yargsOptionsToOptions,\n optionsToArgs,\n configToProjectInfo,\n getProjectFileFromConfig,\n} from '@react-native-windows/telemetry';\n\n/**\n * Important:\n * Do not use process.exit() in this script as it will prevent telemetry from being sent.\n * See https://github.com/microsoft/ApplicationInsights-node.js/issues/580\n */\n\nimport requireGenerateWindows from './requireGenerateWindows';\n\nconst npmConfReg = execSync('npm config get registry').toString().trim();\nconst NPM_REGISTRY_URL = validUrl.isUri(npmConfReg)\n ? npmConfReg\n : 'http://registry.npmjs.org';\n\nconst yargsParser = yargs\n .version(false)\n .strict(true)\n .options({\n version: {\n type: 'string',\n describe: 'The version of react-native-windows to use.',\n },\n namespace: {\n type: 'string',\n describe:\n \"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\",\n },\n verbose: {\n type: 'boolean',\n describe: 'Enables logging.',\n default: false,\n },\n telemetry: {\n type: 'boolean',\n describe:\n 'Controls sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',\n default: true,\n },\n language: {\n type: 'string',\n describe: 'The language the project is written in.',\n choices: ['cs', 'cpp'],\n default: 'cpp',\n },\n overwrite: {\n type: 'boolean',\n describe: 'Overwrite any existing files without prompting',\n default: false,\n },\n projectType: {\n type: 'string',\n describe: 'The type of project to initialize (supported on 0.64+)',\n choices: ['app', 'lib'],\n default: 'app',\n },\n experimentalNuGetDependency: {\n type: 'boolean',\n describe:\n '[Experimental] change to start consuming a NuGet containing a pre-built dll version of Microsoft.ReactNative',\n hidden: true,\n default: false,\n },\n useHermes: {\n type: 'boolean',\n describe:\n '[Experimental] Use Hermes instead of Chakra as the JS engine (supported on 0.64+ for C++ projects)',\n default: false,\n },\n useWinUI3: {\n type: 'boolean',\n describe: '[Experimental] Use WinUI3',\n hidden: true,\n default: false,\n },\n nuGetTestVersion: {\n type: 'string',\n describe:\n '[internalTesting] By default the NuGet version matches the rnw package. This flag allows manually specifying the version for internal testing.',\n hidden: true,\n },\n nuGetTestFeed: {\n type: 'string',\n describe:\n '[internalTesting] Allows a test feed to be added to the generated NuGet configuration',\n hidden: true,\n },\n useDevMode: {\n type: 'boolean',\n describe:\n '[internalTesting] Link rather than Add/Install the react-native-windows package. This option is for the development workflow of the developers working on react-native-windows.',\n hidden: true,\n conflicts: 'version',\n },\n })\n .strict(true);\n\nconst argv = yargsParser.argv;\n\nfunction getReactNativeProjectName(): string {\n console.log('Reading project name from package.json...');\n const cwd = process.cwd();\n const pkgJsonPath = findUp.sync('package.json', {cwd});\n if (!pkgJsonPath) {\n throw new CodedError(\n 'NoPackageJson',\n 'Unable to find package.json. This should be run from within an existing react-native project.',\n );\n }\n type PackageJson = {name: string};\n\n let name = fs.readJsonFileSync<PackageJson>(pkgJsonPath).name;\n if (!name) {\n const appJsonPath = findUp.sync('app.json', {cwd});\n if (appJsonPath) {\n console.log('Reading project name from app.json...');\n name = fs.readJsonFileSync<PackageJson>(pkgJsonPath).name;\n }\n }\n if (!name) {\n console.error('Please specify name in package.json or app.json');\n }\n return name;\n}\n\nfunction getReactNativeVersion(): string {\n console.log('Reading react-native version from node_modules...');\n const rnPkgJsonPath = require.resolve('react-native/package.json', {\n paths: [process.cwd()],\n });\n if (fs.existsSync(rnPkgJsonPath)) {\n return require(rnPkgJsonPath).version;\n }\n\n throw new CodedError(\n 'NoReactNativeFound',\n 'Must be run from a project that already depends on react-native, and has react-native installed.',\n );\n}\n\nfunction getDefaultReactNativeWindowsSemVerForReactNativeVersion(\n rnVersion: string,\n): string {\n const validVersion = semver.valid(rnVersion);\n if (validVersion) {\n const major = semver.major(validVersion);\n const minor = semver.minor(validVersion);\n if (major === 0 && minor >= 59) {\n return `^${major}.${minor}.0-0`;\n }\n }\n\n throw new CodedError(\n 'UnsupportedReactNativeVersion',\n `Error: Unsupported version of react-native: ${chalk.cyan(\n rnVersion,\n )} react-native-windows supports react-native versions ${chalk.cyan(\n '>=0.60',\n )}`,\n );\n}\n\nfunction getMatchingReactNativeSemVerForReactNativeWindowsVersion(\n rnwVersion: string,\n): string {\n const validVersion = semver.valid(rnwVersion);\n if (validVersion) {\n const major = semver.major(validVersion);\n const minor = semver.minor(validVersion);\n if (major === 0 && minor >= 59) {\n return `^${major}.${minor}`;\n }\n }\n return 'unknown';\n}\n\nasync function getLatestMatchingVersion(\n pkg: string,\n versionSemVer: string,\n): Promise<string> {\n const npmResponse = await npmFetch.json(pkg, {registry: NPM_REGISTRY_URL});\n\n // Check if versionSemVer is a tag (i.e. 'canary', 'latest', 'preview', etc.)\n if ('dist-tags' in npmResponse) {\n const distTags = npmResponse['dist-tags'] as Record<string, string>;\n if (versionSemVer in distTags) {\n return distTags[versionSemVer];\n }\n }\n\n // Check if versionSemVer is a semver version (i.e. '^0.60.0-0', '0.63.1', etc.)\n if ('versions' in npmResponse) {\n const versions = Object.keys(\n npmResponse.versions as Record<string, unknown>,\n );\n if (versions.length > 0) {\n const candidates = versions\n .filter((v) => semver.satisfies(v, versionSemVer))\n .sort(semver.rcompare);\n if (candidates.length > 0) {\n return candidates[0];\n }\n }\n }\n\n throw new CodedError(\n 'NoMatchingPackageVersion',\n `No matching version of ${pkg}@${versionSemVer} found`,\n );\n}\n\nasync function getLatestRNWVersion(): Promise<string> {\n const rnwLatestVersion = await getLatestMatchingRNWVersion('latest');\n if (!rnwLatestVersion) {\n throw new CodedError(\n 'NoLatestReactNativeWindows',\n 'Error: No version of react-native-windows@latest found',\n );\n }\n return rnwLatestVersion;\n}\n\nasync function getLatestMatchingRNWVersion(\n versionSemVer: string,\n): Promise<string | null> {\n try {\n const version = await getLatestMatchingVersion(\n 'react-native-windows',\n versionSemVer,\n );\n return version;\n } catch (err) {\n return null;\n }\n}\n\nfunction installReactNativeWindows(\n version: string | undefined,\n useDevMode: boolean,\n) {\n const cwd = process.cwd();\n const execOptions = argv.verbose ? {stdio: 'inherit' as 'inherit'} : {};\n\n if (useDevMode) {\n const packageCmd = isProjectUsingYarn(cwd) ? 'yarn' : 'npm';\n execSync(`${packageCmd} link react-native-windows`, execOptions);\n version = '*';\n } else if (!version) {\n throw new CodedError(\n 'Unknown',\n 'Unexpected error encountered. If you are able, please file an issue on: https://github.com/microsoft/react-native-windows/issues/new/choose',\n );\n }\n\n console.log(\n `Installing ${chalk.green('react-native-windows')}@${chalk.cyan(\n version,\n )}...`,\n );\n\n const pkgJsonPath = findUp.sync('package.json', {cwd});\n if (!pkgJsonPath) {\n throw new CodedError('NoPackageJson', 'Unable to find package.json');\n }\n\n const pkgJson = require(pkgJsonPath);\n\n // check how react-native is installed\n if ('dependencies' in pkgJson && 'react-native' in pkgJson.dependencies) {\n // regular dependency (probably an app), inject into json and run install\n pkgJson.dependencies['react-native-windows'] = version;\n fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));\n execSync(isProjectUsingYarn(cwd) ? 'yarn' : 'npm install', execOptions);\n } else if (\n 'devDependencies' in pkgJson &&\n 'react-native' in pkgJson.devDependencies\n ) {\n // only a dev dependency (probably a native module),\n execSync(\n isProjectUsingYarn(cwd)\n ? `yarn add react-native-windows@${version} --dev`\n : `npm install react-native-windows@${version} --save-dev`,\n execOptions,\n );\n } else {\n throw new CodedError(\n 'NoReactNativeDependencies',\n \"Unable to find 'react-native' in package.json's dependencies or devDependencies. This should be run from within an existing react-native app or lib.\",\n );\n }\n\n console.log(\n chalk.green(\n `react-native-windows@${chalk.cyan(\n require(require.resolve('react-native-windows/package.json', {\n paths: [cwd],\n })).version,\n )} successfully installed.`,\n ),\n );\n}\n\n/**\n * Sanitizes the given option for telemetry.\n * @param key The key of the option.\n * @param value The unsanitized value of the option.\n * @returns The sanitized value of the option.\n */\nfunction optionSanitizer(key: string, value: any): any {\n switch (key) {\n case 'namespace':\n return value === undefined ? false : true;\n default:\n return value === undefined ? false : value;\n }\n}\n\n/**\n * Sets up and starts the telemetry gathering for the CLI command.\n */\nasync function startTelemetrySession() {\n if (!argv.telemetry) {\n if (argv.verbose) {\n console.log('Telemetry is disabled');\n }\n return;\n }\n\n // Setup telemetry, but don't get NPM package version info right away as\n // we're going to change things and this may interfere with the resolver\n await Telemetry.setup({populateNpmPackageVersions: false});\n\n const sanitizedOptions = yargsOptionsToOptions(argv, optionSanitizer);\n const sanitizedDefaultOptions = yargsOptionsToOptions(\n yargsParser.parse(''),\n optionSanitizer,\n );\n const sanitizedArgs = optionsToArgs(sanitizedOptions, process.argv);\n\n const startInfo: CommandStartInfo = {\n commandName: 'react-native-windows-init',\n args: sanitizedArgs,\n options: sanitizedOptions,\n defaultOptions: sanitizedDefaultOptions,\n };\n\n Telemetry.startCommand(startInfo);\n}\n\n/**\n * Adds the new project's telemetry info by calling and processing `react-native config`.\n */\nasync function addProjectInfoToTelemetry() {\n if (!Telemetry.isEnabled()) {\n return;\n }\n\n try {\n const config = JSON.parse(\n execSync('npx react-native config', {\n stdio: ['ignore', 'pipe', 'ignore'],\n }).toString(),\n );\n const projectInfo = await configToProjectInfo(config);\n if (projectInfo) {\n Telemetry.setProjectInfo(projectInfo);\n }\n\n const projectFile = getProjectFileFromConfig(config);\n if (projectFile) {\n await Telemetry.populateNuGetPackageVersions(projectFile);\n }\n } catch {}\n}\n\n/**\n * Ends the gathering of telemetry for the CLI command.\n * @param error The error (if any) thrown during the command.\n */\nfunction endTelemetrySession(error?: Error) {\n const endInfo: CommandEndInfo = {\n resultCode: 'Success',\n };\n\n if (error) {\n endInfo.resultCode =\n error instanceof CodedError ? (error as CodedError).type : 'Unknown';\n }\n\n Telemetry.endCommand(endInfo);\n}\n\n/**\n * Sets the process exit code and offers some information at the end of a CLI command.\n * @param loggingIsEnabled Is verbose logging enabled.\n * @param error The error caught during the process, if any.\n */\nfunction setExitProcessWithError(\n loggingIsEnabled: boolean,\n error?: Error,\n): void {\n if (error) {\n const errorType =\n error instanceof CodedError ? (error as CodedError).type : 'Unknown';\n\n process.exitCode = CodedErrors[errorType];\n\n if (loggingIsEnabled) {\n console.log(\n `Command failed with error ${chalk.bold(errorType)}: ${error.message}`,\n );\n if (Telemetry.isEnabled()) {\n console.log(\n `Your telemetry sessionId was ${chalk.bold(\n Telemetry.getSessionId(),\n )}`,\n );\n }\n } else {\n console.log(\n `Command failed. Re-run the command with ${chalk.bold(\n '--verbose',\n )} for more information.`,\n );\n }\n }\n}\n\n/**\n * Check if project is using Yarn (has `yarn.lock` in the tree)\n */\nfunction isProjectUsingYarn(cwd: string): boolean {\n return !!findUp.sync('yarn.lock', {cwd});\n}\n\n(async () => {\n if (argv.verbose) {\n console.log(argv);\n }\n\n await startTelemetrySession();\n\n let initWindowsError: Error | undefined;\n try {\n const name = getReactNativeProjectName();\n const ns = argv.namespace || name;\n const useDevMode = !!argv.useDevMode;\n let version = argv.version;\n\n if (argv.useWinUI3 && argv.experimentalNuGetDependency) {\n throw new CodedError(\n 'IncompatibleOptions',\n \"Error: Incompatible options specified. Options '--useWinUI3' and '--experimentalNuGetDependency' are incompatible\",\n {detail: 'useWinUI3 and experimentalNuGetDependency'},\n );\n }\n\n if (!useDevMode) {\n if (!version) {\n const rnVersion = getReactNativeVersion();\n version =\n getDefaultReactNativeWindowsSemVerForReactNativeVersion(rnVersion);\n }\n\n const rnwResolvedVersion = await getLatestMatchingRNWVersion(version);\n\n if (!rnwResolvedVersion) {\n if (argv.version) {\n console.warn(\n `Warning: Querying npm to find react-native-windows@${argv.version} failed. Attempting to continue anyway...`,\n );\n } else {\n const rnwLatestVersion = await getLatestRNWVersion();\n throw new CodedError(\n 'NoAutoMatchingReactNativeWindows',\n `\n No compatible version of ${chalk.green('react-native-windows')} found.\n The latest supported version is ${chalk.green(\n 'react-native-windows',\n )}@${chalk.cyan(rnwLatestVersion)}.\n Please modify your application to use ${chalk.green(\n 'react-native',\n )}@${chalk.cyan(\n getMatchingReactNativeSemVerForReactNativeWindowsVersion(\n rnwLatestVersion,\n ),\n )} or another supported version of ${chalk.green(\n 'react-native',\n )} and try again.\n `,\n {rnwLatestVersion: rnwLatestVersion},\n );\n }\n }\n\n if (!argv.version) {\n console.log(\n `Latest matching version of ${chalk.bold(\n 'react-native-windows',\n )} for ${chalk.green('react-native')}@${chalk.cyan(\n getReactNativeVersion(),\n )} is ${chalk.green('react-native-windows')}@${chalk.cyan(\n rnwResolvedVersion,\n )}`,\n );\n\n if (rnwResolvedVersion && semver.prerelease(rnwResolvedVersion)) {\n const rnwLatestVersion = await getLatestRNWVersion();\n console.warn(\n `\n ${chalk.green('react-native-windows')}@${chalk.cyan(\n rnwResolvedVersion,\n )} is a ${chalk.yellow('pre-release')} version.\n The latest supported version is ${chalk.green(\n 'react-native-windows',\n )}@${chalk.cyan(rnwLatestVersion)}.\n You can either downgrade your version of ${chalk.green(\n 'react-native',\n )} to ${chalk.cyan(\n getMatchingReactNativeSemVerForReactNativeWindowsVersion(\n rnwLatestVersion,\n ),\n )}, or continue with a ${chalk.yellow(\n 'pre-release',\n )} version of ${chalk.bold('react-native-windows')}.\n `,\n );\n\n const confirm: boolean = (\n await prompts({\n type: 'confirm',\n name: 'confirm',\n message: `Do you wish to continue with ${chalk.green(\n 'react-native-windows',\n )}@${chalk.cyan(rnwResolvedVersion)}?`,\n })\n ).confirm;\n\n if (!confirm) {\n throw new CodedError('UserCancel', 'User canceled');\n }\n }\n }\n\n if (rnwResolvedVersion) {\n version = rnwResolvedVersion;\n }\n }\n\n installReactNativeWindows(version, useDevMode);\n\n const generateWindows = requireGenerateWindows();\n\n // Now that new NPM packages have been installed, get their versions\n await Telemetry.populateNpmPackageVersions();\n\n await generateWindows(process.cwd(), name, ns, {\n language: argv.language as 'cs' | 'cpp',\n overwrite: argv.overwrite,\n verbose: argv.verbose,\n projectType: argv.projectType as 'lib' | 'app',\n experimentalNuGetDependency: argv.experimentalNuGetDependency,\n useWinUI3: argv.useWinUI3,\n useHermes: argv.useHermes,\n useDevMode: useDevMode,\n nuGetTestVersion: argv.nuGetTestVersion,\n nuGetTestFeed: argv.nuGetTestFeed,\n telemetry: argv.telemetry,\n });\n\n // Now that the project has been generated, add project info\n await addProjectInfoToTelemetry();\n } catch (ex) {\n // Since we may have failed before generating a project, make\n // sure we get those NPM package versions\n await Telemetry.populateNpmPackageVersions();\n\n initWindowsError =\n ex instanceof Error ? (ex as Error) : new Error(String(ex));\n Telemetry.trackException(initWindowsError);\n\n console.error(chalk.red(initWindowsError.message));\n console.error(initWindowsError);\n }\n endTelemetrySession(initWindowsError);\n setExitProcessWithError(argv.verbose, initWindowsError);\n})();\n"]}
1
+ {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,kDAA0B;AAC1B,kEAA0C;AAC1C,oDAA4B;AAC5B,iDAAuC;AACvC,0DAAiC;AACjC,sDAA8B;AAC9B,sDAA6B;AAC7B,kDAA0B;AAC1B,4EAA0C;AAE1C,+DAYyC;AAEzC;;;;GAIG;AAEH,sFAA8D;AAE9D,MAAM,UAAU,GAAG,IAAA,wBAAQ,EAAC,yBAAyB,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;AACzE,MAAM,gBAAgB,GAAG,mBAAQ,CAAC,KAAK,CAAC,UAAU,CAAC;IACjD,CAAC,CAAC,UAAU;IACZ,CAAC,CAAC,2BAA2B,CAAC;AAEhC,uFAAuF;AACvF,SAAS,WAAW,CAA0C,OAAU;IACtE,OAAO,OAAO,CAAC;AACjB,CAAC;AAEY,QAAA,kBAAkB,GAAG,WAAW,CAAC;IAC5C,OAAO,EAAE;QACP,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,6CAA6C;KACxD;IACD,SAAS,EAAE;QACT,IAAI,EAAE,QAAQ;QACd,QAAQ,EACN,mLAAmL;KACtL;IACD,OAAO,EAAE;QACP,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,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Aa;YACpC,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC,CAAC;QAEH,4DAA4D;QAC5D,MAAM,yBAAyB,EAAE,CAAC;KACnC;IAAC,OAAO,EAAE,EAAE;QACX,6DAA6D;QAC7D,yCAAyC;QACzC,MAAM,qBAAS,CAAC,0BAA0B,EAAE,CAAC;QAE7C,gBAAgB;YACd,EAAE,YAAY,KAAK,CAAC,CAAC,CAAE,EAAY,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9D,qBAAS,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QAE3C,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;QACnD,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;KACjC;IACD,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;IACtC,uBAAuB,CAAC,OAAO,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;AAC7D,CAAC;AA1JD,wDA0JC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport fs from '@react-native-windows/fs';\nimport semver from 'semver';\nimport {execSync} from 'child_process';\nimport validUrl from 'valid-url';\nimport prompts from 'prompts';\nimport findUp from 'find-up';\nimport chalk from 'chalk';\nimport npmFetch from 'npm-registry-fetch';\n\nimport {\n Telemetry,\n CommandStartInfo,\n CommandEndInfo,\n CodedErrors,\n CodedError,\n yargsOptionsToOptions,\n optionsToArgs,\n configToProjectInfo,\n getProjectFileFromConfig,\n OptionSanitizer,\n YargsOptionsType,\n} from '@react-native-windows/telemetry';\n\n/**\n * Important:\n * Do not use process.exit() in this script as it will prevent telemetry from being sent.\n * See https://github.com/microsoft/ApplicationInsights-node.js/issues/580\n */\n\nimport requireGenerateWindows from './requireGenerateWindows';\n\nconst npmConfReg = execSync('npm config get registry').toString().trim();\nconst NPM_REGISTRY_URL = validUrl.isUri(npmConfReg)\n ? npmConfReg\n : 'http://registry.npmjs.org';\n\n// Causes the type-checker to ensure the options object is a valid yargs options object\nfunction initOptions<T extends Record<string, yargs.Options>>(options: T): T {\n return options;\n}\n\nexport const windowsInitOptions = initOptions({\n version: {\n type: 'string',\n describe: 'The version of react-native-windows to use.',\n },\n namespace: {\n type: 'string',\n describe:\n \"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\",\n },\n verbose: {\n type: 'boolean',\n describe: 'Enables logging.',\n default: false,\n },\n telemetry: {\n type: 'boolean',\n describe:\n 'Controls sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',\n default: true,\n },\n language: {\n type: 'string',\n describe: 'The language the project is written in.',\n choices: ['cs', 'cpp'],\n default: 'cpp',\n },\n overwrite: {\n type: 'boolean',\n describe: 'Overwrite any existing files without prompting',\n default: false,\n },\n projectType: {\n type: 'string',\n describe: 'The type of project to initialize (supported on 0.64+)',\n choices: ['app', 'lib'],\n default: 'app',\n },\n experimentalNuGetDependency: {\n type: 'boolean',\n describe:\n '[Experimental] change to start consuming a NuGet containing a pre-built dll version of Microsoft.ReactNative',\n hidden: true,\n default: false,\n },\n useHermes: {\n type: 'boolean',\n describe:\n '[Experimental] Use Hermes instead of Chakra as the JS engine (supported on 0.64+ for C++ projects)',\n default: false,\n },\n useWinUI3: {\n type: 'boolean',\n describe: '[Experimental] Use WinUI3',\n hidden: true,\n default: false,\n },\n nuGetTestVersion: {\n type: 'string',\n describe:\n '[internalTesting] By default the NuGet version matches the rnw package. This flag allows manually specifying the version for internal testing.',\n hidden: true,\n },\n nuGetTestFeed: {\n type: 'string',\n describe:\n '[internalTesting] Allows a test feed to be added to the generated NuGet configuration',\n hidden: true,\n },\n useDevMode: {\n type: 'boolean',\n describe:\n '[internalTesting] Link rather than Add/Install the react-native-windows package. This option is for the development workflow of the developers working on react-native-windows.',\n hidden: true,\n default: false,\n conflicts: 'version',\n },\n});\n\nconst yargsParser = yargs\n .version(false)\n .options(windowsInitOptions)\n .strict(true);\n\nfunction getReactNativeProjectName(): string {\n console.log('Reading project name from package.json...');\n const cwd = process.cwd();\n const pkgJsonPath = findUp.sync('package.json', {cwd});\n if (!pkgJsonPath) {\n throw new CodedError(\n 'NoPackageJson',\n 'Unable to find package.json. This should be run from within an existing react-native project.',\n );\n }\n type PackageJson = {name: string};\n\n let name = fs.readJsonFileSync<PackageJson>(pkgJsonPath).name;\n if (!name) {\n const appJsonPath = findUp.sync('app.json', {cwd});\n if (appJsonPath) {\n console.log('Reading project name from app.json...');\n name = fs.readJsonFileSync<PackageJson>(pkgJsonPath).name;\n }\n }\n if (!name) {\n console.error('Please specify name in package.json or app.json');\n }\n return name;\n}\n\nfunction getReactNativeVersion(): string {\n console.log('Reading react-native version from node_modules...');\n const rnPkgJsonPath = require.resolve('react-native/package.json', {\n paths: [process.cwd()],\n });\n if (fs.existsSync(rnPkgJsonPath)) {\n return require(rnPkgJsonPath).version;\n }\n\n throw new CodedError(\n 'NoReactNativeFound',\n 'Must be run from a project that already depends on react-native, and has react-native installed.',\n );\n}\n\nfunction getDefaultReactNativeWindowsSemVerForReactNativeVersion(\n rnVersion: string,\n): string {\n const validVersion = semver.valid(rnVersion);\n if (validVersion) {\n const major = semver.major(validVersion);\n const minor = semver.minor(validVersion);\n if (major === 0 && minor >= 59) {\n return `^${major}.${minor}.0-0`;\n }\n }\n\n throw new CodedError(\n 'UnsupportedReactNativeVersion',\n `Error: Unsupported version of react-native: ${chalk.cyan(\n rnVersion,\n )} react-native-windows supports react-native versions ${chalk.cyan(\n '>=0.60',\n )}`,\n );\n}\n\nfunction getMatchingReactNativeSemVerForReactNativeWindowsVersion(\n rnwVersion: string,\n): string {\n const validVersion = semver.valid(rnwVersion);\n if (validVersion) {\n const major = semver.major(validVersion);\n const minor = semver.minor(validVersion);\n if (major === 0 && minor >= 59) {\n return `^${major}.${minor}`;\n }\n }\n return 'unknown';\n}\n\nasync function getLatestMatchingVersion(\n pkg: string,\n versionSemVer: string,\n): Promise<string> {\n const npmResponse = await npmFetch.json(pkg, {registry: NPM_REGISTRY_URL});\n\n // Check if versionSemVer is a tag (i.e. 'canary', 'latest', 'preview', etc.)\n if ('dist-tags' in npmResponse) {\n const distTags = npmResponse['dist-tags'] as Record<string, string>;\n if (versionSemVer in distTags) {\n return distTags[versionSemVer];\n }\n }\n\n // Check if versionSemVer is a semver version (i.e. '^0.60.0-0', '0.63.1', etc.)\n if ('versions' in npmResponse) {\n const versions = Object.keys(\n npmResponse.versions as Record<string, unknown>,\n );\n if (versions.length > 0) {\n const candidates = versions\n .filter((v) => semver.satisfies(v, versionSemVer))\n .sort(semver.rcompare);\n if (candidates.length > 0) {\n return candidates[0];\n }\n }\n }\n\n throw new CodedError(\n 'NoMatchingPackageVersion',\n `No matching version of ${pkg}@${versionSemVer} found`,\n );\n}\n\nasync function getLatestRNWVersion(): Promise<string> {\n const rnwLatestVersion = await getLatestMatchingRNWVersion('latest');\n if (!rnwLatestVersion) {\n throw new CodedError(\n 'NoLatestReactNativeWindows',\n 'Error: No version of react-native-windows@latest found',\n );\n }\n return rnwLatestVersion;\n}\n\nasync function getLatestMatchingRNWVersion(\n versionSemVer: string,\n): Promise<string | null> {\n try {\n const version = await getLatestMatchingVersion(\n 'react-native-windows',\n versionSemVer,\n );\n return version;\n } catch (err) {\n return null;\n }\n}\n\nfunction installReactNativeWindows(\n version: string | undefined,\n verbose: boolean,\n useDevMode: boolean,\n) {\n const cwd = process.cwd();\n const execOptions = verbose ? {stdio: 'inherit' as 'inherit'} : {};\n\n if (useDevMode) {\n const packageCmd = isProjectUsingYarn(cwd) ? 'yarn' : 'npm';\n execSync(`${packageCmd} link react-native-windows`, execOptions);\n version = '*';\n } else if (!version) {\n throw new CodedError(\n 'Unknown',\n 'Unexpected error encountered. If you are able, please file an issue on: https://github.com/microsoft/react-native-windows/issues/new/choose',\n );\n }\n\n console.log(\n `Installing ${chalk.green('react-native-windows')}@${chalk.cyan(\n version,\n )}...`,\n );\n\n const pkgJsonPath = findUp.sync('package.json', {cwd});\n if (!pkgJsonPath) {\n throw new CodedError('NoPackageJson', 'Unable to find package.json');\n }\n\n const pkgJson = require(pkgJsonPath);\n\n // check how react-native is installed\n if ('dependencies' in pkgJson && 'react-native' in pkgJson.dependencies) {\n // regular dependency (probably an app), inject into json and run install\n pkgJson.dependencies['react-native-windows'] = version;\n fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));\n execSync(isProjectUsingYarn(cwd) ? 'yarn' : 'npm install', execOptions);\n } else if (\n 'devDependencies' in pkgJson &&\n 'react-native' in pkgJson.devDependencies\n ) {\n // only a dev dependency (probably a native module),\n execSync(\n isProjectUsingYarn(cwd)\n ? `yarn add react-native-windows@${version} --dev`\n : `npm install react-native-windows@${version} --save-dev`,\n execOptions,\n );\n } else {\n throw new CodedError(\n 'NoReactNativeDependencies',\n \"Unable to find 'react-native' in package.json's dependencies or devDependencies. This should be run from within an existing react-native app or lib.\",\n );\n }\n\n console.log(\n chalk.green(\n `react-native-windows@${chalk.cyan(\n require(require.resolve('react-native-windows/package.json', {\n paths: [cwd],\n })).version,\n )} successfully installed.`,\n ),\n );\n}\n\n/**\n * Sanitizes the given option for telemetry.\n * @param key The key of the option.\n * @param value The unsanitized value of the option.\n * @returns The sanitized value of the option.\n */\nfunction optionSanitizer(key: keyof WindowsInitOptions, value: any): any {\n // Do not add a default case here.\n // Strings risking PII should just return true if present, false otherwise.\n // All others should return the value (or false if undefined).\n switch (key) {\n case 'namespace':\n case 'nuGetTestFeed':\n case 'nuGetTestVersion':\n return value ? true : false;\n case 'verbose':\n case 'version':\n case 'telemetry':\n case 'language':\n case 'overwrite':\n case 'projectType':\n case 'experimentalNuGetDependency':\n case 'useHermes':\n case 'useWinUI3':\n case 'useDevMode':\n return value === undefined ? false : value;\n }\n}\n\n/**\n * Sets up and starts the telemetry gathering for the CLI command.\n * @param args The raw CLI args.\n * @param options The CLI args parsed by yargs.\n */\nasync function startTelemetrySession(\n args: string[],\n options: YargsOptionsType,\n) {\n if (!options.telemetry) {\n if (options.verbose) {\n console.log('Telemetry is disabled');\n }\n return;\n }\n\n // Setup telemetry, but don't get NPM package version info right away as\n // we're going to change things and this may interfere with the resolver\n await Telemetry.setup({populateNpmPackageVersions: false});\n\n const sanitizedOptions = yargsOptionsToOptions(\n options,\n optionSanitizer as OptionSanitizer,\n );\n const sanitizedDefaultOptions = yargsOptionsToOptions(\n yargsParser.parse(''),\n optionSanitizer as OptionSanitizer,\n );\n const sanitizedArgs = optionsToArgs(sanitizedOptions, args);\n\n const startInfo: CommandStartInfo = {\n commandName: 'react-native-windows-init',\n args: sanitizedArgs,\n options: sanitizedOptions,\n defaultOptions: sanitizedDefaultOptions,\n };\n\n Telemetry.startCommand(startInfo);\n}\n\n/**\n * Adds the new project's telemetry info by calling and processing `react-native config`.\n */\nasync function addProjectInfoToTelemetry() {\n if (!Telemetry.isEnabled()) {\n return;\n }\n\n try {\n const config = JSON.parse(\n execSync('npx react-native config', {\n stdio: ['ignore', 'pipe', 'ignore'],\n }).toString(),\n );\n const projectInfo = await configToProjectInfo(config);\n if (projectInfo) {\n Telemetry.setProjectInfo(projectInfo);\n }\n\n const projectFile = getProjectFileFromConfig(config);\n if (projectFile) {\n await Telemetry.populateNuGetPackageVersions(projectFile);\n }\n } catch {}\n}\n\n/**\n * Ends the gathering of telemetry for the CLI command.\n * @param error The error (if any) thrown during the command.\n */\nfunction endTelemetrySession(error?: Error) {\n const endInfo: CommandEndInfo = {\n resultCode: 'Success',\n };\n\n if (error) {\n endInfo.resultCode =\n error instanceof CodedError ? (error as CodedError).type : 'Unknown';\n }\n\n Telemetry.endCommand(endInfo);\n}\n\n/**\n * Sets the process exit code and offers some information at the end of a CLI command.\n * @param loggingIsEnabled Is verbose logging enabled.\n * @param error The error caught during the process, if any.\n */\nfunction setExitProcessWithError(\n loggingIsEnabled: boolean,\n error?: Error,\n): void {\n if (error) {\n const errorType =\n error instanceof CodedError ? (error as CodedError).type : 'Unknown';\n\n process.exitCode = CodedErrors[errorType];\n\n if (loggingIsEnabled) {\n console.log(\n `Command failed with error ${chalk.bold(errorType)}: ${error.message}`,\n );\n if (Telemetry.isEnabled()) {\n console.log(\n `Your telemetry sessionId was ${chalk.bold(\n Telemetry.getSessionId(),\n )}`,\n );\n }\n } else {\n console.log(\n `Command failed. Re-run the command with ${chalk.bold(\n '--verbose',\n )} for more information.`,\n );\n }\n }\n}\n\n/**\n * Check if project is using Yarn (has `yarn.lock` in the tree)\n */\nfunction isProjectUsingYarn(cwd: string): boolean {\n return !!findUp.sync('yarn.lock', {cwd});\n}\n\nexport async function reactNativeWindowsInit(args?: string[]) {\n args = args ?? process.argv;\n const options = yargsParser.parse(args) as WindowsInitOptions;\n\n if (options.verbose) {\n console.log(options);\n }\n\n await startTelemetrySession(args, options);\n\n let initWindowsError: Error | undefined;\n try {\n const name = getReactNativeProjectName();\n const ns = options.namespace || name;\n const useDevMode = options.useDevMode;\n let version = options.version;\n\n if (options.useWinUI3 && options.experimentalNuGetDependency) {\n throw new CodedError(\n 'IncompatibleOptions',\n \"Error: Incompatible options specified. Options '--useWinUI3' and '--experimentalNuGetDependency' are incompatible\",\n {detail: 'useWinUI3 and experimentalNuGetDependency'},\n );\n }\n\n if (!useDevMode) {\n if (!version) {\n const rnVersion = getReactNativeVersion();\n version =\n getDefaultReactNativeWindowsSemVerForReactNativeVersion(rnVersion);\n }\n\n const rnwResolvedVersion = await getLatestMatchingRNWVersion(version);\n\n if (!rnwResolvedVersion) {\n if (options.version) {\n console.warn(\n `Warning: Querying npm to find react-native-windows@${options.version} failed. Attempting to continue anyway...`,\n );\n } else {\n const rnwLatestVersion = await getLatestRNWVersion();\n throw new CodedError(\n 'NoAutoMatchingReactNativeWindows',\n `\n No compatible version of ${chalk.green('react-native-windows')} found.\n The latest supported version is ${chalk.green(\n 'react-native-windows',\n )}@${chalk.cyan(rnwLatestVersion)}.\n Please modify your application to use ${chalk.green(\n 'react-native',\n )}@${chalk.cyan(\n getMatchingReactNativeSemVerForReactNativeWindowsVersion(\n rnwLatestVersion,\n ),\n )} or another supported version of ${chalk.green(\n 'react-native',\n )} and try again.\n `,\n {rnwLatestVersion: rnwLatestVersion},\n );\n }\n }\n\n if (!options.version) {\n console.log(\n `Latest matching version of ${chalk.bold(\n 'react-native-windows',\n )} for ${chalk.green('react-native')}@${chalk.cyan(\n getReactNativeVersion(),\n )} is ${chalk.green('react-native-windows')}@${chalk.cyan(\n rnwResolvedVersion,\n )}`,\n );\n\n if (rnwResolvedVersion && semver.prerelease(rnwResolvedVersion)) {\n const rnwLatestVersion = await getLatestRNWVersion();\n console.warn(\n `\n ${chalk.green('react-native-windows')}@${chalk.cyan(\n rnwResolvedVersion,\n )} is a ${chalk.yellow('pre-release')} version.\n The latest supported version is ${chalk.green(\n 'react-native-windows',\n )}@${chalk.cyan(rnwLatestVersion)}.\n You can either downgrade your version of ${chalk.green(\n 'react-native',\n )} to ${chalk.cyan(\n getMatchingReactNativeSemVerForReactNativeWindowsVersion(\n rnwLatestVersion,\n ),\n )}, or continue with a ${chalk.yellow(\n 'pre-release',\n )} version of ${chalk.bold('react-native-windows')}.\n `,\n );\n\n const confirm: boolean = (\n await prompts({\n type: 'confirm',\n name: 'confirm',\n message: `Do you wish to continue with ${chalk.green(\n 'react-native-windows',\n )}@${chalk.cyan(rnwResolvedVersion)}?`,\n })\n ).confirm;\n\n if (!confirm) {\n throw new CodedError('UserCancel', 'User canceled');\n }\n }\n }\n\n if (rnwResolvedVersion) {\n version = rnwResolvedVersion;\n }\n }\n\n installReactNativeWindows(version, options.verbose, useDevMode);\n\n const generateWindows = requireGenerateWindows();\n\n // Now that new NPM packages have been installed, get their versions\n await Telemetry.populateNpmPackageVersions();\n\n await generateWindows(process.cwd(), name, ns, {\n language: options.language as 'cs' | 'cpp',\n overwrite: options.overwrite,\n verbose: options.verbose,\n projectType: options.projectType as 'lib' | 'app',\n experimentalNuGetDependency: options.experimentalNuGetDependency,\n useWinUI3: options.useWinUI3,\n useHermes: options.useHermes,\n useDevMode: useDevMode,\n nuGetTestVersion: options.nuGetTestVersion,\n nuGetTestFeed: options.nuGetTestFeed,\n telemetry: options.telemetry,\n });\n\n // Now that the project has been generated, add project info\n await addProjectInfoToTelemetry();\n } catch (ex) {\n // Since we may have failed before generating a project, make\n // sure we get those NPM package versions\n await Telemetry.populateNpmPackageVersions();\n\n initWindowsError =\n ex instanceof Error ? (ex as Error) : new Error(String(ex));\n Telemetry.trackException(initWindowsError);\n\n console.error(chalk.red(initWindowsError.message));\n console.error(initWindowsError);\n }\n endTelemetrySession(initWindowsError);\n setExitProcessWithError(options.verbose, initWindowsError);\n}\n\nexport type WindowsInitOptions = yargs.InferredOptionTypes<\n typeof windowsInitOptions\n>;\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ *
5
+ * @format
6
+ */
7
+ export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Microsoft Corporation.
4
+ * Licensed under the MIT License.
5
+ *
6
+ * @format
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const Cli_1 = require("../Cli");
10
+ function validateOptionName(name, optionName) {
11
+ // Do not add a default case here. Every item must explicitly return true
12
+ switch (optionName) {
13
+ case 'version':
14
+ case 'namespace':
15
+ case 'verbose':
16
+ case 'telemetry':
17
+ case 'language':
18
+ case 'overwrite':
19
+ case 'projectType':
20
+ case 'experimentalNuGetDependency':
21
+ case 'useHermes':
22
+ case 'useWinUI3':
23
+ case 'nuGetTestVersion':
24
+ case 'nuGetTestFeed':
25
+ case 'useDevMode':
26
+ return true;
27
+ }
28
+ throw new Error(`Unable to find ${optionName} to match '${name}' in WindowsInitOptions.`);
29
+ }
30
+ test('windowsInitOptions - validate options', () => {
31
+ const options = Cli_1.windowsInitOptions;
32
+ for (const optionName of Object.keys(options)) {
33
+ const option = options[optionName];
34
+ // Validate type
35
+ expect(option.type).toBeDefined();
36
+ // Validate defaults
37
+ if (option.type === 'string') {
38
+ if (option.choices !== undefined) {
39
+ // If there are choices (enum value) make sure
40
+ // the default is present and of that type
41
+ expect(Array.isArray(option.choices)).toBe(true);
42
+ expect(option).toHaveProperty('default');
43
+ expect(option.default).toBeDefined();
44
+ expect(option.choices.includes(option.default)).toBe(true);
45
+ }
46
+ else {
47
+ // Regular strings should not have defined default
48
+ expect(option.default).not.toBeDefined();
49
+ }
50
+ }
51
+ else {
52
+ expect(option).toHaveProperty('default');
53
+ expect(option.default).toBeDefined();
54
+ }
55
+ // Validate description
56
+ expect(option.describe).toBeDefined();
57
+ expect(option.describe).not.toBeNull();
58
+ expect(option.describe).toBe(option.describe.trim());
59
+ // Validate all command options are present in WindowsInitOptions
60
+ expect(validateOptionName(optionName, optionName)).toBe(true);
61
+ }
62
+ });
63
+ //# sourceMappingURL=cli.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.test.js","sourceRoot":"","sources":["../../src/e2etest/cli.test.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAEH,gCAA8D;AAE9D,SAAS,kBAAkB,CACzB,IAAY,EACZ,UAAoC;IAEpC,yEAAyE;IACzE,QAAQ,UAAU,EAAE;QAClB,KAAK,SAAS,CAAC;QACf,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS,CAAC;QACf,KAAK,WAAW,CAAC;QACjB,KAAK,UAAU,CAAC;QAChB,KAAK,WAAW,CAAC;QACjB,KAAK,aAAa,CAAC;QACnB,KAAK,6BAA6B,CAAC;QACnC,KAAK,WAAW,CAAC;QACjB,KAAK,WAAW,CAAC;QACjB,KAAK,kBAAkB,CAAC;QACxB,KAAK,eAAe,CAAC;QACrB,KAAK,YAAY;YACf,OAAO,IAAI,CAAC;KACf;IACD,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,cAAc,IAAI,0BAA0B,C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C,QAAQ,EAAE,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,QAAS,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAS,CAAC,IAAI,EAAE,CAAC,CAAC;QAEvD,iEAAiE;QACjE,MAAM,CACJ,kBAAkB,CAAC,UAAU,EAAE,UAAsC,CAAC,CACvE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KACd;AACH,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport {windowsInitOptions, WindowsInitOptions} from '../Cli';\n\nfunction validateOptionName(\n name: string,\n optionName: keyof WindowsInitOptions,\n): boolean {\n // Do not add a default case here. Every item must explicitly return true\n switch (optionName) {\n case 'version':\n case 'namespace':\n case 'verbose':\n case 'telemetry':\n case 'language':\n case 'overwrite':\n case 'projectType':\n case 'experimentalNuGetDependency':\n case 'useHermes':\n case 'useWinUI3':\n case 'nuGetTestVersion':\n case 'nuGetTestFeed':\n case 'useDevMode':\n return true;\n }\n throw new Error(\n `Unable to find ${optionName} to match '${name}' in WindowsInitOptions.`,\n );\n}\n\ntest('windowsInitOptions - validate options', () => {\n const options = windowsInitOptions as Record<string, any>;\n for (const optionName of Object.keys(options)) {\n const option = options[optionName];\n\n // Validate type\n expect(option.type).toBeDefined();\n\n // Validate defaults\n if (option.type === 'string') {\n if (option.choices !== undefined) {\n // If there are choices (enum value) make sure\n // the default is present and of that type\n expect(Array.isArray(option.choices)).toBe(true);\n expect(option).toHaveProperty('default');\n expect(option.default).toBeDefined();\n expect(option.choices.includes(option.default)).toBe(true);\n } else {\n // Regular strings should not have defined default\n expect(option.default).not.toBeDefined();\n }\n } else {\n expect(option).toHaveProperty('default');\n expect(option.default).toBeDefined();\n }\n\n // Validate description\n expect(option.describe).toBeDefined();\n expect(option.describe).not.toBeNull();\n expect(option.describe!).toBe(option.describe!.trim());\n\n // Validate all command options are present in WindowsInitOptions\n expect(\n validateOptionName(optionName, optionName as keyof WindowsInitOptions),\n ).toBe(true);\n }\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-windows-init",
3
- "version": "1.1.76",
3
+ "version": "1.1.77",
4
4
  "description": "CLI to add react-native-windows to an existing react-native project",
5
5
  "main": "index.js",
6
6
  "repository": "https://github.com/microsoft/react-native-windows",