react-native-windows-init 0.0.0-canary.1016
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 +31 -0
- package/bin.js +13 -0
- package/lib-commonjs/Cli.d.ts +75 -0
- package/lib-commonjs/Cli.js +478 -0
- package/lib-commonjs/Cli.js.map +1 -0
- package/lib-commonjs/GenerateWindowsType.d.ts +9 -0
- package/lib-commonjs/GenerateWindowsType.js +9 -0
- package/lib-commonjs/GenerateWindowsType.js.map +1 -0
- package/lib-commonjs/e2etest/cli.test.d.ts +7 -0
- package/lib-commonjs/e2etest/cli.test.js +68 -0
- package/lib-commonjs/e2etest/cli.test.js.map +1 -0
- package/lib-commonjs/requireGenerateWindows.d.ts +12 -0
- package/lib-commonjs/requireGenerateWindows.js +29 -0
- package/lib-commonjs/requireGenerateWindows.js.map +1 -0
- package/package.json +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# react-native-windows-init
|
|
2
|
+
|
|
3
|
+
CLI to bootstrap the addition of the Windows platform to `react-native` projects.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Run this from an existing `react-native` project, to install `react-native-windows` and generate initial project files for windows.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Example usage
|
|
11
|
+
```
|
|
12
|
+
npx react-native-windows-init --language cpp
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
| option | description | type |
|
|
17
|
+
|-------------|------------------------------------------------|--------------------------------------------------|
|
|
18
|
+
| `--help` | Show help | [boolean] |
|
|
19
|
+
| `--version` | The version of react-native-windows to use. | [string] |
|
|
20
|
+
| `--namespace` | The native project namespace. | [string] |
|
|
21
|
+
| `--verbose` | Enables logging. | [boolean] |
|
|
22
|
+
| `--language` | Which language the app is written in. | [string] [choices: "cs", "cpp"] [default: "cpp"] |
|
|
23
|
+
| `--overwrite` | Overwrite any existing files without prompting | [boolean] |
|
|
24
|
+
| `--useWinUI3` | Targets WinUI 3 (through the [Windows App SDK](https://docs.microsoft.com/windows/apps/windows-app-sdk/)) instead of UWP XAML. | [boolean] |
|
|
25
|
+
| `--no-telemetry` | Disables sending telemetry that allows analysis of failures of the react-native-windows CLI | [boolean] |
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## Data Collection
|
|
29
|
+
The software may collect information about you and your use of the software and send it to Microsoft. Microsoft may use this information to provide services and improve our products and services. You may turn off the telemetry as described in the repository. There are also some features in the software that may enable you and Microsoft to collect data from users of your applications. If you use these features, you must comply with applicable law, including providing appropriate notices to users of your applications together with a copy of Microsoft's privacy statement. Our privacy statement is located at https://go.microsoft.com/fwlink/?LinkID=824704. You can learn more about data collection and use in the help documentation and our privacy statement. Your use of the software operates as your consent to these practices.
|
|
30
|
+
|
|
31
|
+
This data collection notice only applies to the process of **creating** a new React Native for Windows app with the CLI.
|
package/bin.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
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
|
+
useWinUI3: {
|
|
51
|
+
type: "boolean";
|
|
52
|
+
describe: string;
|
|
53
|
+
hidden: true;
|
|
54
|
+
default: boolean;
|
|
55
|
+
};
|
|
56
|
+
nuGetTestVersion: {
|
|
57
|
+
type: "string";
|
|
58
|
+
describe: string;
|
|
59
|
+
hidden: true;
|
|
60
|
+
};
|
|
61
|
+
nuGetTestFeed: {
|
|
62
|
+
type: "string";
|
|
63
|
+
describe: string;
|
|
64
|
+
hidden: true;
|
|
65
|
+
};
|
|
66
|
+
useDevMode: {
|
|
67
|
+
type: "boolean";
|
|
68
|
+
describe: string;
|
|
69
|
+
hidden: true;
|
|
70
|
+
default: undefined;
|
|
71
|
+
conflicts: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
export declare function reactNativeWindowsInit(args?: string[]): Promise<void>;
|
|
75
|
+
export type WindowsInitOptions = yargs.InferredOptionTypes<typeof windowsInitOptions>;
|
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*
|
|
6
|
+
* @format
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
var _a;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.reactNativeWindowsInit = exports.windowsInitOptions = void 0;
|
|
14
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
15
|
+
const fs_1 = __importDefault(require("@react-native-windows/fs"));
|
|
16
|
+
const semver_1 = __importDefault(require("semver"));
|
|
17
|
+
const child_process_1 = require("child_process");
|
|
18
|
+
const valid_url_1 = __importDefault(require("valid-url"));
|
|
19
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
20
|
+
const find_up_1 = __importDefault(require("find-up"));
|
|
21
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
22
|
+
const npm_registry_fetch_1 = __importDefault(require("npm-registry-fetch"));
|
|
23
|
+
const telemetry_1 = require("@react-native-windows/telemetry");
|
|
24
|
+
/**
|
|
25
|
+
* Important:
|
|
26
|
+
* Do not use process.exit() in this script as it will prevent telemetry from being sent.
|
|
27
|
+
* See https://github.com/microsoft/ApplicationInsights-node.js/issues/580
|
|
28
|
+
*/
|
|
29
|
+
const requireGenerateWindows_1 = __importDefault(require("./requireGenerateWindows"));
|
|
30
|
+
let NPM_REGISTRY_URL = 'https://registry.npmjs.org';
|
|
31
|
+
try {
|
|
32
|
+
const npmConfReg = (0, child_process_1.execSync)('npm config get registry').toString().trim();
|
|
33
|
+
if (valid_url_1.default.isUri(npmConfReg)) {
|
|
34
|
+
NPM_REGISTRY_URL = npmConfReg;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
// Ignore workspace errors as `npm config` does not support it
|
|
39
|
+
const stderr = ((_a = error === null || error === void 0 ? void 0 : error.stderr) === null || _a === void 0 ? void 0 : _a.toString()) || '';
|
|
40
|
+
if (!stderr.includes('ENOWORKSPACES')) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Causes the type-checker to ensure the options object is a valid yargs options object
|
|
45
|
+
function initOptions(options) {
|
|
46
|
+
return options;
|
|
47
|
+
}
|
|
48
|
+
exports.windowsInitOptions = initOptions({
|
|
49
|
+
version: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
describe: 'The version of react-native-windows to use.',
|
|
52
|
+
},
|
|
53
|
+
namespace: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
describe: "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",
|
|
56
|
+
},
|
|
57
|
+
verbose: {
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
describe: 'Enables logging.',
|
|
60
|
+
default: false,
|
|
61
|
+
},
|
|
62
|
+
telemetry: {
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
describe: 'Controls sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',
|
|
65
|
+
default: true,
|
|
66
|
+
},
|
|
67
|
+
language: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
describe: 'The language the project is written in.',
|
|
70
|
+
choices: ['cs', 'cpp'],
|
|
71
|
+
default: 'cpp',
|
|
72
|
+
},
|
|
73
|
+
overwrite: {
|
|
74
|
+
type: 'boolean',
|
|
75
|
+
describe: 'Overwrite any existing files without prompting',
|
|
76
|
+
default: false,
|
|
77
|
+
},
|
|
78
|
+
projectType: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
describe: 'The type of project to initialize (supported on 0.64+)',
|
|
81
|
+
choices: ['app', 'lib'],
|
|
82
|
+
default: 'app',
|
|
83
|
+
},
|
|
84
|
+
experimentalNuGetDependency: {
|
|
85
|
+
type: 'boolean',
|
|
86
|
+
describe: '[Experimental] change to start consuming a NuGet containing a pre-built dll version of Microsoft.ReactNative',
|
|
87
|
+
hidden: true,
|
|
88
|
+
default: false,
|
|
89
|
+
},
|
|
90
|
+
useWinUI3: {
|
|
91
|
+
type: 'boolean',
|
|
92
|
+
describe: '[Experimental] Use WinUI 3 (Windows App SDK)',
|
|
93
|
+
hidden: true,
|
|
94
|
+
default: false,
|
|
95
|
+
},
|
|
96
|
+
nuGetTestVersion: {
|
|
97
|
+
type: 'string',
|
|
98
|
+
describe: '[internalTesting] By default the NuGet version matches the rnw package. This flag allows manually specifying the version for internal testing.',
|
|
99
|
+
hidden: true,
|
|
100
|
+
},
|
|
101
|
+
nuGetTestFeed: {
|
|
102
|
+
type: 'string',
|
|
103
|
+
describe: '[internalTesting] Allows a test feed to be added to the generated NuGet configuration',
|
|
104
|
+
hidden: true,
|
|
105
|
+
},
|
|
106
|
+
useDevMode: {
|
|
107
|
+
type: 'boolean',
|
|
108
|
+
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.',
|
|
109
|
+
hidden: true,
|
|
110
|
+
default: undefined,
|
|
111
|
+
conflicts: 'version',
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
const yargsParser = yargs_1.default
|
|
115
|
+
.version(false)
|
|
116
|
+
.options(exports.windowsInitOptions)
|
|
117
|
+
.strict(true);
|
|
118
|
+
function getReactNativeProjectName() {
|
|
119
|
+
console.log('Reading project name from package.json...');
|
|
120
|
+
const cwd = process.cwd();
|
|
121
|
+
const pkgJsonPath = find_up_1.default.sync('package.json', { cwd });
|
|
122
|
+
if (!pkgJsonPath) {
|
|
123
|
+
throw new telemetry_1.CodedError('NoPackageJson', 'Unable to find package.json. This should be run from within an existing react-native project.');
|
|
124
|
+
}
|
|
125
|
+
let name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
|
|
126
|
+
if (!name) {
|
|
127
|
+
const appJsonPath = find_up_1.default.sync('app.json', { cwd });
|
|
128
|
+
if (appJsonPath) {
|
|
129
|
+
console.log('Reading project name from app.json...');
|
|
130
|
+
name = fs_1.default.readJsonFileSync(pkgJsonPath).name;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!name) {
|
|
134
|
+
console.error('Please specify name in package.json or app.json');
|
|
135
|
+
}
|
|
136
|
+
return name;
|
|
137
|
+
}
|
|
138
|
+
function getReactNativeVersion() {
|
|
139
|
+
console.log('Reading react-native version from node_modules...');
|
|
140
|
+
const rnPkgJsonPath = require.resolve('react-native/package.json', {
|
|
141
|
+
paths: [process.cwd()],
|
|
142
|
+
});
|
|
143
|
+
if (fs_1.default.existsSync(rnPkgJsonPath)) {
|
|
144
|
+
return require(rnPkgJsonPath).version;
|
|
145
|
+
}
|
|
146
|
+
throw new telemetry_1.CodedError('NoReactNativeFound', 'Must be run from a project that already depends on react-native, and has react-native installed.');
|
|
147
|
+
}
|
|
148
|
+
function getDefaultReactNativeWindowsSemVerForReactNativeVersion(rnVersion) {
|
|
149
|
+
const validVersion = semver_1.default.valid(rnVersion);
|
|
150
|
+
if (validVersion) {
|
|
151
|
+
const major = semver_1.default.major(validVersion);
|
|
152
|
+
const minor = semver_1.default.minor(validVersion);
|
|
153
|
+
if (major === 0 && minor >= 59) {
|
|
154
|
+
return `^${major}.${minor}.0-0`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
throw new telemetry_1.CodedError('UnsupportedReactNativeVersion', `Error: Unsupported version of react-native: ${chalk_1.default.cyan(rnVersion)} react-native-windows supports react-native versions ${chalk_1.default.cyan('>=0.60')}`);
|
|
158
|
+
}
|
|
159
|
+
function getMatchingReactNativeSemVerForReactNativeWindowsVersion(rnwVersion) {
|
|
160
|
+
const validVersion = semver_1.default.valid(rnwVersion);
|
|
161
|
+
if (validVersion) {
|
|
162
|
+
const major = semver_1.default.major(validVersion);
|
|
163
|
+
const minor = semver_1.default.minor(validVersion);
|
|
164
|
+
if (major === 0 && minor >= 59) {
|
|
165
|
+
return `^${major}.${minor}`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return 'unknown';
|
|
169
|
+
}
|
|
170
|
+
async function getLatestMatchingVersion(pkg, versionSemVer) {
|
|
171
|
+
const npmResponse = await npm_registry_fetch_1.default.json(pkg, { registry: NPM_REGISTRY_URL });
|
|
172
|
+
// Check if versionSemVer is a tag (i.e. 'canary', 'latest', 'preview', etc.)
|
|
173
|
+
if ('dist-tags' in npmResponse) {
|
|
174
|
+
const distTags = npmResponse['dist-tags'];
|
|
175
|
+
if (versionSemVer in distTags) {
|
|
176
|
+
return distTags[versionSemVer];
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Check if versionSemVer is a semver version (i.e. '^0.60.0-0', '0.63.1', etc.)
|
|
180
|
+
if ('versions' in npmResponse) {
|
|
181
|
+
const versions = Object.keys(npmResponse.versions);
|
|
182
|
+
if (versions.length > 0) {
|
|
183
|
+
const candidates = versions
|
|
184
|
+
.filter(v => semver_1.default.satisfies(v, versionSemVer))
|
|
185
|
+
.sort(semver_1.default.rcompare);
|
|
186
|
+
if (candidates.length > 0) {
|
|
187
|
+
return candidates[0];
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
throw new telemetry_1.CodedError('NoMatchingPackageVersion', `No matching version of ${pkg}@${versionSemVer} found`);
|
|
192
|
+
}
|
|
193
|
+
async function getLatestRNWVersion() {
|
|
194
|
+
const rnwLatestVersion = await getLatestMatchingRNWVersion('latest');
|
|
195
|
+
if (!rnwLatestVersion) {
|
|
196
|
+
throw new telemetry_1.CodedError('NoLatestReactNativeWindows', 'Error: No version of react-native-windows@latest found');
|
|
197
|
+
}
|
|
198
|
+
return rnwLatestVersion;
|
|
199
|
+
}
|
|
200
|
+
async function getLatestMatchingRNWVersion(versionSemVer) {
|
|
201
|
+
try {
|
|
202
|
+
const version = await getLatestMatchingVersion('react-native-windows', versionSemVer);
|
|
203
|
+
return version;
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function installReactNativeWindows(version, verbose, useDevMode) {
|
|
210
|
+
const cwd = process.cwd();
|
|
211
|
+
const execOptions = verbose ? { stdio: 'inherit' } : {};
|
|
212
|
+
if (useDevMode) {
|
|
213
|
+
const packageCmd = isProjectUsingYarn(cwd) ? 'yarn' : 'npm';
|
|
214
|
+
(0, child_process_1.execSync)(`${packageCmd} link react-native-windows`, execOptions);
|
|
215
|
+
version = '*';
|
|
216
|
+
}
|
|
217
|
+
else if (!version) {
|
|
218
|
+
throw new telemetry_1.CodedError('Unknown', 'Unexpected error encountered. If you are able, please file an issue on: https://github.com/microsoft/react-native-windows/issues/new/choose');
|
|
219
|
+
}
|
|
220
|
+
const parsedVersion = semver_1.default.parse(version);
|
|
221
|
+
if (parsedVersion) {
|
|
222
|
+
const newSteps = 'Please see https://microsoft.github.io/react-native-windows/docs/getting-started for the latest method for adding RNW to your project.';
|
|
223
|
+
if (parsedVersion.minor > 75 ||
|
|
224
|
+
(parsedVersion.minor === 0 &&
|
|
225
|
+
parsedVersion.prerelease.length > 1 &&
|
|
226
|
+
parsedVersion.prerelease[0] === 'canary' &&
|
|
227
|
+
typeof parsedVersion.prerelease[1] === 'number' &&
|
|
228
|
+
parsedVersion.prerelease[1] > 843)) {
|
|
229
|
+
// Full-stop, you can't use the command anymore.
|
|
230
|
+
throw new telemetry_1.CodedError('UnsupportedReactNativeVersion', `react-native-windows-init only supports react-native-windows <= 0.75. ${newSteps}`);
|
|
231
|
+
}
|
|
232
|
+
else if (parsedVersion.minor === 75) {
|
|
233
|
+
// You can use the command for now, but it will be deprecated soon.
|
|
234
|
+
console.warn(chalk_1.default.yellow(`Warning: react-native-windows-init will be deprecated for RNW > 0.75. ${newSteps}`));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
console.log(`Installing ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(version)}...`);
|
|
238
|
+
const pkgJsonPath = find_up_1.default.sync('package.json', { cwd });
|
|
239
|
+
if (!pkgJsonPath) {
|
|
240
|
+
throw new telemetry_1.CodedError('NoPackageJson', 'Unable to find package.json');
|
|
241
|
+
}
|
|
242
|
+
const pkgJson = require(pkgJsonPath);
|
|
243
|
+
// check how react-native is installed
|
|
244
|
+
if ('dependencies' in pkgJson && 'react-native' in pkgJson.dependencies) {
|
|
245
|
+
// regular dependency (probably an app), inject into json and run install
|
|
246
|
+
pkgJson.dependencies['react-native-windows'] = version;
|
|
247
|
+
fs_1.default.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 2));
|
|
248
|
+
(0, child_process_1.execSync)(isProjectUsingYarn(cwd) ? 'yarn' : 'npm install', execOptions);
|
|
249
|
+
}
|
|
250
|
+
else if ('devDependencies' in pkgJson &&
|
|
251
|
+
'react-native' in pkgJson.devDependencies) {
|
|
252
|
+
// only a dev dependency (probably a native module),
|
|
253
|
+
(0, child_process_1.execSync)(isProjectUsingYarn(cwd)
|
|
254
|
+
? `yarn add react-native-windows@${version} --dev`
|
|
255
|
+
: `npm install react-native-windows@${version} --save-dev`, execOptions);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
throw new telemetry_1.CodedError('NoReactNativeDependencies', "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.");
|
|
259
|
+
}
|
|
260
|
+
console.log(chalk_1.default.green(`react-native-windows@${chalk_1.default.cyan(require(require.resolve('react-native-windows/package.json', {
|
|
261
|
+
paths: [cwd],
|
|
262
|
+
})).version)} successfully installed.`));
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Sanitizes the given option for telemetry.
|
|
266
|
+
* @param key The key of the option.
|
|
267
|
+
* @param value The unsanitized value of the option.
|
|
268
|
+
* @returns The sanitized value of the option.
|
|
269
|
+
*/
|
|
270
|
+
function optionSanitizer(key, value) {
|
|
271
|
+
// Do not add a default case here.
|
|
272
|
+
// Strings risking PII should just return true if present, false otherwise.
|
|
273
|
+
// All others should return the value (or false if undefined).
|
|
274
|
+
switch (key) {
|
|
275
|
+
case 'namespace':
|
|
276
|
+
case 'nuGetTestFeed':
|
|
277
|
+
case 'nuGetTestVersion':
|
|
278
|
+
return value ? true : false;
|
|
279
|
+
case 'verbose':
|
|
280
|
+
case 'version':
|
|
281
|
+
case 'telemetry':
|
|
282
|
+
case 'language':
|
|
283
|
+
case 'overwrite':
|
|
284
|
+
case 'projectType':
|
|
285
|
+
case 'experimentalNuGetDependency':
|
|
286
|
+
case 'useWinUI3':
|
|
287
|
+
case 'useDevMode':
|
|
288
|
+
return value === undefined ? false : value;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Sets up and starts the telemetry gathering for the CLI command.
|
|
293
|
+
* @param args The raw CLI args.
|
|
294
|
+
* @param options The CLI args parsed by yargs.
|
|
295
|
+
*/
|
|
296
|
+
async function startTelemetrySession(args, options) {
|
|
297
|
+
const verbose = options.verbose === true;
|
|
298
|
+
if (!options.telemetry) {
|
|
299
|
+
if (verbose) {
|
|
300
|
+
console.log('Telemetry is disabled');
|
|
301
|
+
}
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
if (verbose) {
|
|
305
|
+
console.log(`Running ${(0, telemetry_1.nodeArchitecture)()} node on a ${(0, telemetry_1.deviceArchitecture)()} machine`);
|
|
306
|
+
}
|
|
307
|
+
if ((0, telemetry_1.deviceArchitecture)() !== (0, telemetry_1.nodeArchitecture)()) {
|
|
308
|
+
console.warn('This version of node was built for a different architecture than this machine and may cause unintended behavior');
|
|
309
|
+
}
|
|
310
|
+
// Setup telemetry, but don't get NPM package version info right away as
|
|
311
|
+
// we're going to change things and this may interfere with the resolver
|
|
312
|
+
await telemetry_1.Telemetry.setup({ populateNpmPackageVersions: false });
|
|
313
|
+
const sanitizedOptions = (0, telemetry_1.yargsOptionsToOptions)(options, optionSanitizer);
|
|
314
|
+
const sanitizedDefaultOptions = (0, telemetry_1.yargsOptionsToOptions)(yargsParser.parse(''), optionSanitizer);
|
|
315
|
+
const sanitizedArgs = (0, telemetry_1.optionsToArgs)(sanitizedOptions, args);
|
|
316
|
+
const startInfo = {
|
|
317
|
+
commandName: 'react-native-windows-init',
|
|
318
|
+
args: sanitizedArgs,
|
|
319
|
+
options: sanitizedOptions,
|
|
320
|
+
defaultOptions: sanitizedDefaultOptions,
|
|
321
|
+
};
|
|
322
|
+
telemetry_1.Telemetry.startCommand(startInfo);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Adds the new project's telemetry info by calling and processing `npx @react-native-community/cli config`.
|
|
326
|
+
*/
|
|
327
|
+
async function addProjectInfoToTelemetry() {
|
|
328
|
+
if (!telemetry_1.Telemetry.isEnabled()) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
try {
|
|
332
|
+
const config = JSON.parse((0, child_process_1.execSync)('npx @react-native-community/cli config', {
|
|
333
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
334
|
+
}).toString());
|
|
335
|
+
const projectInfo = await (0, telemetry_1.configToProjectInfo)(config);
|
|
336
|
+
if (projectInfo) {
|
|
337
|
+
telemetry_1.Telemetry.setProjectInfo(projectInfo);
|
|
338
|
+
}
|
|
339
|
+
const projectFile = (0, telemetry_1.getProjectFileFromConfig)(config);
|
|
340
|
+
if (projectFile) {
|
|
341
|
+
await telemetry_1.Telemetry.populateNuGetPackageVersions(projectFile);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
catch (_a) { }
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Ends the gathering of telemetry for the CLI command.
|
|
348
|
+
* @param error The error (if any) thrown during the command.
|
|
349
|
+
*/
|
|
350
|
+
function endTelemetrySession(error) {
|
|
351
|
+
const endInfo = {
|
|
352
|
+
resultCode: 'Success',
|
|
353
|
+
};
|
|
354
|
+
if (error) {
|
|
355
|
+
endInfo.resultCode =
|
|
356
|
+
error instanceof telemetry_1.CodedError ? error.type : 'Unknown';
|
|
357
|
+
}
|
|
358
|
+
telemetry_1.Telemetry.endCommand(endInfo);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Sets the process exit code and offers some information at the end of a CLI command.
|
|
362
|
+
* @param loggingIsEnabled Is verbose logging enabled.
|
|
363
|
+
* @param error The error caught during the process, if any.
|
|
364
|
+
*/
|
|
365
|
+
function setExitProcessWithError(loggingIsEnabled, error) {
|
|
366
|
+
if (error) {
|
|
367
|
+
const errorType = error instanceof telemetry_1.CodedError ? error.type : 'Unknown';
|
|
368
|
+
process.exitCode = telemetry_1.CodedErrors[errorType];
|
|
369
|
+
if (loggingIsEnabled) {
|
|
370
|
+
console.log(`Command failed with error ${chalk_1.default.bold(errorType)}: ${error.message}`);
|
|
371
|
+
if (telemetry_1.Telemetry.isEnabled()) {
|
|
372
|
+
console.log(`Your telemetry sessionId was ${chalk_1.default.bold(telemetry_1.Telemetry.getSessionId())}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
console.log(`Command failed. Re-run the command with ${chalk_1.default.bold('--verbose')} for more information.`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Check if project is using Yarn (has `yarn.lock` in the tree)
|
|
382
|
+
*/
|
|
383
|
+
function isProjectUsingYarn(cwd) {
|
|
384
|
+
return !!find_up_1.default.sync('yarn.lock', { cwd });
|
|
385
|
+
}
|
|
386
|
+
async function reactNativeWindowsInit(args) {
|
|
387
|
+
args = args !== null && args !== void 0 ? args : process.argv;
|
|
388
|
+
const options = yargsParser.parse(args);
|
|
389
|
+
if (options.verbose) {
|
|
390
|
+
console.log(options);
|
|
391
|
+
}
|
|
392
|
+
await startTelemetrySession(args, options);
|
|
393
|
+
let initWindowsError;
|
|
394
|
+
try {
|
|
395
|
+
const name = getReactNativeProjectName();
|
|
396
|
+
const ns = options.namespace || name;
|
|
397
|
+
const useDevMode = !!options.useDevMode; // TS assumes the type is undefined
|
|
398
|
+
let version = options.version;
|
|
399
|
+
if (options.useWinUI3 && options.experimentalNuGetDependency) {
|
|
400
|
+
throw new telemetry_1.CodedError('IncompatibleOptions', "Error: Incompatible options specified. Options '--useWinUI3' and '--experimentalNuGetDependency' are incompatible", { detail: 'useWinUI3 and experimentalNuGetDependency' });
|
|
401
|
+
}
|
|
402
|
+
if (!useDevMode) {
|
|
403
|
+
if (!version) {
|
|
404
|
+
const rnVersion = getReactNativeVersion();
|
|
405
|
+
version =
|
|
406
|
+
getDefaultReactNativeWindowsSemVerForReactNativeVersion(rnVersion);
|
|
407
|
+
}
|
|
408
|
+
const rnwResolvedVersion = await getLatestMatchingRNWVersion(version);
|
|
409
|
+
if (!rnwResolvedVersion) {
|
|
410
|
+
if (options.version) {
|
|
411
|
+
console.warn(`Warning: Querying npm to find react-native-windows@${options.version} failed. Attempting to continue anyway...`);
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
const rnwLatestVersion = await getLatestRNWVersion();
|
|
415
|
+
throw new telemetry_1.CodedError('NoAutoMatchingReactNativeWindows', `
|
|
416
|
+
No compatible version of ${chalk_1.default.green('react-native-windows')} found.
|
|
417
|
+
The latest supported version is ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwLatestVersion)}.
|
|
418
|
+
Please modify your application to use ${chalk_1.default.green('react-native')}@${chalk_1.default.cyan(getMatchingReactNativeSemVerForReactNativeWindowsVersion(rnwLatestVersion))} or another supported version of ${chalk_1.default.green('react-native')} and try again.
|
|
419
|
+
`, { rnwLatestVersion: rnwLatestVersion });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (!options.version) {
|
|
423
|
+
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)}`);
|
|
424
|
+
if (rnwResolvedVersion && semver_1.default.prerelease(rnwResolvedVersion)) {
|
|
425
|
+
const rnwLatestVersion = await getLatestRNWVersion();
|
|
426
|
+
console.warn(`
|
|
427
|
+
${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwResolvedVersion)} is a ${chalk_1.default.yellow('pre-release')} version.
|
|
428
|
+
The latest supported version is ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwLatestVersion)}.
|
|
429
|
+
You can either downgrade your version of ${chalk_1.default.green('react-native')} to ${chalk_1.default.cyan(getMatchingReactNativeSemVerForReactNativeWindowsVersion(rnwLatestVersion))}, or continue with a ${chalk_1.default.yellow('pre-release')} version of ${chalk_1.default.bold('react-native-windows')}.
|
|
430
|
+
`);
|
|
431
|
+
const confirm = (await (0, prompts_1.default)({
|
|
432
|
+
type: 'confirm',
|
|
433
|
+
name: 'confirm',
|
|
434
|
+
message: `Do you wish to continue with ${chalk_1.default.green('react-native-windows')}@${chalk_1.default.cyan(rnwResolvedVersion)}?`,
|
|
435
|
+
})).confirm;
|
|
436
|
+
if (!confirm) {
|
|
437
|
+
throw new telemetry_1.CodedError('UserCancel', 'User canceled');
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (rnwResolvedVersion) {
|
|
442
|
+
version = rnwResolvedVersion;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
installReactNativeWindows(version, options.verbose, useDevMode);
|
|
446
|
+
const generateWindows = (0, requireGenerateWindows_1.default)();
|
|
447
|
+
// Now that new NPM packages have been installed, get their versions
|
|
448
|
+
await telemetry_1.Telemetry.populateNpmPackageVersions();
|
|
449
|
+
await generateWindows(process.cwd(), name, ns, {
|
|
450
|
+
language: options.language,
|
|
451
|
+
overwrite: options.overwrite,
|
|
452
|
+
verbose: options.verbose,
|
|
453
|
+
projectType: options.projectType,
|
|
454
|
+
experimentalNuGetDependency: options.experimentalNuGetDependency,
|
|
455
|
+
useWinUI3: options.useWinUI3,
|
|
456
|
+
useDevMode: useDevMode,
|
|
457
|
+
nuGetTestVersion: options.nuGetTestVersion,
|
|
458
|
+
nuGetTestFeed: options.nuGetTestFeed,
|
|
459
|
+
telemetry: options.telemetry,
|
|
460
|
+
});
|
|
461
|
+
// Now that the project has been generated, add project info
|
|
462
|
+
await addProjectInfoToTelemetry();
|
|
463
|
+
}
|
|
464
|
+
catch (ex) {
|
|
465
|
+
// Since we may have failed before generating a project, make
|
|
466
|
+
// sure we get those NPM package versions
|
|
467
|
+
await telemetry_1.Telemetry.populateNpmPackageVersions();
|
|
468
|
+
initWindowsError =
|
|
469
|
+
ex instanceof Error ? ex : new Error(String(ex));
|
|
470
|
+
telemetry_1.Telemetry.trackException(initWindowsError);
|
|
471
|
+
console.error(chalk_1.default.red(initWindowsError.message));
|
|
472
|
+
console.error(initWindowsError);
|
|
473
|
+
}
|
|
474
|
+
endTelemetrySession(initWindowsError);
|
|
475
|
+
setExitProcessWithError(options.verbose, initWindowsError);
|
|
476
|
+
}
|
|
477
|
+
exports.reactNativeWindowsInit = reactNativeWindowsInit;
|
|
478
|
+
//# sourceMappingURL=Cli.js.map
|
|
@@ -0,0 +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,+DAcyC;AAEzC;;;;GAIG;AAEH,sFAA8D;AAE9D,IAAI,gBAAgB,GAAG,4BAA4B,CAAC;AACpD,IAAI;IACF,MAAM,UAAU,GAAG,IAAA,wBAAQ,EAAC,yBAAyB,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;IACzE,IAAI,mBAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;QAC9B,gBAAgB,GAAG,UAAU,CAAC;KAC/B;CACF;AAAC,OAAO,KAAU,EAAE;IACnB,8DAA8D;IAC9D,MAAM,MAAM,GAAG,CAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,0CAAE,QAAQ,EAAE,KAAI,EAAE,CAAC;IAC/C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;QACrC,MAAM,KAAK,CAAC;KACb;CACF;AA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,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;AAzJD,wDAyJC","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 deviceArchitecture,\n nodeArchitecture,\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\nlet NPM_REGISTRY_URL = 'https://registry.npmjs.org';\ntry {\n const npmConfReg = execSync('npm config get registry').toString().trim();\n if (validUrl.isUri(npmConfReg)) {\n NPM_REGISTRY_URL = npmConfReg;\n }\n} catch (error: any) {\n // Ignore workspace errors as `npm config` does not support it\n const stderr = error?.stderr?.toString() || '';\n if (!stderr.includes('ENOWORKSPACES')) {\n throw error;\n }\n}\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 useWinUI3: {\n type: 'boolean',\n describe: '[Experimental] Use WinUI 3 (Windows App SDK)',\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: undefined, // This must be undefined because we define the conflicts field below. Defining a default here will break the version option\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 const parsedVersion = semver.parse(version);\n if (parsedVersion) {\n const newSteps =\n 'Please see https://microsoft.github.io/react-native-windows/docs/getting-started for the latest method for adding RNW to your project.';\n if (\n parsedVersion.minor > 75 ||\n (parsedVersion.minor === 0 &&\n parsedVersion.prerelease.length > 1 &&\n parsedVersion.prerelease[0] === 'canary' &&\n typeof parsedVersion.prerelease[1] === 'number' &&\n parsedVersion.prerelease[1] > 843)\n ) {\n // Full-stop, you can't use the command anymore.\n throw new CodedError(\n 'UnsupportedReactNativeVersion',\n `react-native-windows-init only supports react-native-windows <= 0.75. ${newSteps}`,\n );\n } else if (parsedVersion.minor === 75) {\n // You can use the command for now, but it will be deprecated soon.\n console.warn(\n chalk.yellow(\n `Warning: react-native-windows-init will be deprecated for RNW > 0.75. ${newSteps}`,\n ),\n );\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 '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 const verbose = options.verbose === true;\n\n if (!options.telemetry) {\n if (verbose) {\n console.log('Telemetry is disabled');\n }\n return;\n }\n\n if (verbose) {\n console.log(\n `Running ${nodeArchitecture()} node on a ${deviceArchitecture()} machine`,\n );\n }\n\n if (deviceArchitecture() !== nodeArchitecture()) {\n console.warn(\n 'This version of node was built for a different architecture than this machine and may cause unintended behavior',\n );\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 `npx @react-native-community/cli 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-community/cli 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 as unknown); // TS assumes the type is undefined\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 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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
import type { generateWindows, GenerateOptions } from '@react-native-windows/cli';
|
|
8
|
+
export type GenerateWindows = typeof generateWindows;
|
|
9
|
+
export type GenerateWindows62 = (projectDir: string, name: string, ns: string, options: GenerateOptions) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateWindowsType.js","sourceRoot":"","sources":["../src/GenerateWindowsType.ts"],"names":[],"mappings":";AAAA;;;;;GAKG","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\n// TS 3.8 type-only imports lead to parse errors with versions of prettier\n// earlier than 2.0, which React Native uses as of 0.63. Isolate the type\n// import to just this file and blocklist the file to get around it. Note that\n// we cannot import the real module because it may be in a different location\n// for older versions of RNW.\nimport type {generateWindows, GenerateOptions} from '@react-native-windows/cli';\n\n// Current version\nexport type GenerateWindows = typeof generateWindows;\n\n// Older versions of GenerateWindows were synchronous\nexport type GenerateWindows62 = (projectDir: string, name: string, ns: string, options: GenerateOptions) => void;\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 'useWinUI3':
|
|
22
|
+
case 'nuGetTestVersion':
|
|
23
|
+
case 'nuGetTestFeed':
|
|
24
|
+
case 'useDevMode':
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Unable to find ${optionName} to match '${name}' in WindowsInitOptions.`);
|
|
28
|
+
}
|
|
29
|
+
test('windowsInitOptions - validate options', () => {
|
|
30
|
+
const options = Cli_1.windowsInitOptions;
|
|
31
|
+
for (const optionName of Object.keys(options)) {
|
|
32
|
+
const option = options[optionName];
|
|
33
|
+
// Validate type
|
|
34
|
+
expect(option.type).toBeDefined();
|
|
35
|
+
// Validate defaults
|
|
36
|
+
if (option.type === 'string') {
|
|
37
|
+
if (option.choices !== undefined) {
|
|
38
|
+
// If there are choices (enum value) make sure
|
|
39
|
+
// the default is present and of that type
|
|
40
|
+
expect(Array.isArray(option.choices)).toBe(true);
|
|
41
|
+
expect(option).toHaveProperty('default');
|
|
42
|
+
expect(option.default).toBeDefined();
|
|
43
|
+
expect(option.choices.includes(option.default)).toBe(true);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// Regular strings should not have defined default
|
|
47
|
+
expect(option.default).not.toBeDefined();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (option.conflicts !== undefined) {
|
|
51
|
+
// Options with conflicts defined should have default = undefined
|
|
52
|
+
expect(option).toHaveProperty('default');
|
|
53
|
+
expect(option.default).toBeUndefined();
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Regular options should have defined defaults
|
|
57
|
+
expect(option).toHaveProperty('default');
|
|
58
|
+
expect(option.default).toBeDefined();
|
|
59
|
+
}
|
|
60
|
+
// Validate description
|
|
61
|
+
expect(option.describe).toBeDefined();
|
|
62
|
+
expect(option.describe).not.toBeNull();
|
|
63
|
+
expect(option.describe).toBe(option.describe.trim());
|
|
64
|
+
// Validate all command options are present in WindowsInitOptions
|
|
65
|
+
expect(validateOptionName(optionName, optionName)).toBe(true);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
//# 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,kBAAkB,CAAC;QACxB,KAAK,eAAe,CAAC;QACrB,KAAK,YAAY;YACf,OAAO,IAAI,CAAC;KACf;IACD,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,cAAc,IAAI,0BAA0B,CACzE,CAAC;AACJ,CAAC;AAED,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IACjD,MAAM,OAAO,GAAG,wBAAyC,CAAC;IAC1D,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QAEnC,gBAAgB;QAChB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAElC,oBAAoB;QACpB,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE;YAC5B,IAAI,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C,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 '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 if (option.conflicts !== undefined) {\n // Options with conflicts defined should have default = undefined\n expect(option).toHaveProperty('default');\n expect(option.default).toBeUndefined();\n } else {\n // Regular options should have defined defaults\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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
import { GenerateWindows } from './GenerateWindowsType';
|
|
8
|
+
/**
|
|
9
|
+
* Returns the Windows template generator function, normalizing the function
|
|
10
|
+
* to any differences across RN versions.
|
|
11
|
+
*/
|
|
12
|
+
export default function requireGenerateWindows(): GenerateWindows;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Returns the Windows template generator function, normalizing the function
|
|
11
|
+
* to any differences across RN versions.
|
|
12
|
+
*/
|
|
13
|
+
function requireGenerateWindows() {
|
|
14
|
+
try {
|
|
15
|
+
// Try the path for 0.63+
|
|
16
|
+
const requirePath = require.resolve('react-native-windows/generate', {
|
|
17
|
+
paths: [process.cwd()],
|
|
18
|
+
});
|
|
19
|
+
return require(requirePath);
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
// Fall back to trying the older path
|
|
23
|
+
const requirePath = require.resolve('react-native-windows/local-cli/generate-windows', { paths: [process.cwd()] });
|
|
24
|
+
const generate62 = require(requirePath);
|
|
25
|
+
return async (...args) => generate62(...args);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.default = requireGenerateWindows;
|
|
29
|
+
//# sourceMappingURL=requireGenerateWindows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requireGenerateWindows.js","sourceRoot":"","sources":["../src/requireGenerateWindows.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAIH;;;GAGG;AACH,SAAwB,sBAAsB;IAC5C,IAAI;QACF,yBAAyB;QACzB,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,+BAA+B,EAAE;YACnE,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;SACvB,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC;KAC7B;IAAC,WAAM;QACN,qCAAqC;QACrC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CACjC,iDAAiD,EACjD,EAAC,KAAK,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAC,CACzB,CAAC;QAEF,MAAM,UAAU,GAAsB,OAAO,CAAC,WAAW,CAAC,CAAC;QAC3D,OAAO,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;KAC/C;AACH,CAAC;AAlBD,yCAkBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport {GenerateWindows, GenerateWindows62} from './GenerateWindowsType';\n\n/**\n * Returns the Windows template generator function, normalizing the function\n * to any differences across RN versions.\n */\nexport default function requireGenerateWindows(): GenerateWindows {\n try {\n // Try the path for 0.63+\n const requirePath = require.resolve('react-native-windows/generate', {\n paths: [process.cwd()],\n });\n\n return require(requirePath);\n } catch {\n // Fall back to trying the older path\n const requirePath = require.resolve(\n 'react-native-windows/local-cli/generate-windows',\n {paths: [process.cwd()]},\n );\n\n const generate62: GenerateWindows62 = require(requirePath);\n return async (...args) => generate62(...args);\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-windows-init",
|
|
3
|
+
"version": "0.0.0-canary.1016",
|
|
4
|
+
"description": "CLI to add react-native-windows to an existing react-native project",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/microsoft/react-native-windows",
|
|
9
|
+
"directory": "packages/react-native-windows-init"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"private": false,
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rnw-scripts build",
|
|
15
|
+
"clean": "rnw-scripts clean",
|
|
16
|
+
"lint": "rnw-scripts lint",
|
|
17
|
+
"lint:fix": "rnw-scripts lint:fix",
|
|
18
|
+
"test": "rnw-scripts test",
|
|
19
|
+
"watch": "rnw-scripts watch"
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"react-native-windows-init": "./bin.js"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@react-native-windows/fs": "0.0.0-canary.70",
|
|
26
|
+
"@react-native-windows/telemetry": "0.0.0-canary.129",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^7.1.1",
|
|
28
|
+
"@typescript-eslint/parser": "^7.1.1",
|
|
29
|
+
"chalk": "^4.1.0",
|
|
30
|
+
"find-up": "^4.1.0",
|
|
31
|
+
"mustache": "^4.0.1",
|
|
32
|
+
"npm-registry-fetch": "^11.0.0",
|
|
33
|
+
"prompts": "^2.4.1",
|
|
34
|
+
"semver": "^7.3.2",
|
|
35
|
+
"source-map-support": "^0.5.19",
|
|
36
|
+
"valid-url": "^1.0.9",
|
|
37
|
+
"yargs": "^16.2.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@react-native-windows/cli": "0.0.0-canary.281",
|
|
41
|
+
"@rnw-scripts/eslint-config": "1.2.38",
|
|
42
|
+
"@rnw-scripts/jest-unittest-config": "1.5.12",
|
|
43
|
+
"@rnw-scripts/just-task": "2.3.58",
|
|
44
|
+
"@rnw-scripts/ts-config": "2.0.6",
|
|
45
|
+
"@types/chalk": "^2.2.0",
|
|
46
|
+
"@types/jest": "^29.2.2",
|
|
47
|
+
"@types/node": "^22.14.0",
|
|
48
|
+
"@types/npm-registry-fetch": "^8.0.0",
|
|
49
|
+
"@types/prompts": "2.0.10",
|
|
50
|
+
"@types/semver": "7.3.3",
|
|
51
|
+
"@types/valid-url": "^1.0.3",
|
|
52
|
+
"@types/yargs": "16.0.0",
|
|
53
|
+
"babel-jest": "^29.6.3",
|
|
54
|
+
"eslint": "^8.19.0",
|
|
55
|
+
"jest": "^29.7.0",
|
|
56
|
+
"prettier": "2.8.8",
|
|
57
|
+
"typescript": "5.0.4"
|
|
58
|
+
},
|
|
59
|
+
"files": [
|
|
60
|
+
"bin.js",
|
|
61
|
+
"lib-commonjs",
|
|
62
|
+
"README.md"
|
|
63
|
+
],
|
|
64
|
+
"beachball": {
|
|
65
|
+
"defaultNpmTag": "canary",
|
|
66
|
+
"disallowedChangeTypes": [
|
|
67
|
+
"major",
|
|
68
|
+
"minor",
|
|
69
|
+
"patch",
|
|
70
|
+
"premajor",
|
|
71
|
+
"preminor",
|
|
72
|
+
"prepatch"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
"promoteRelease": true
|
|
76
|
+
}
|