@react-native-windows/cli 0.0.0-canary.18 → 0.0.0-canary.181
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/lib-commonjs/codegen.d.ts +32 -0
- package/lib-commonjs/codegen.js +207 -0
- package/lib-commonjs/codegen.js.map +1 -0
- package/lib-commonjs/config/configUtils.d.ts +25 -2
- package/lib-commonjs/config/configUtils.js +138 -30
- package/lib-commonjs/config/configUtils.js.map +1 -1
- package/lib-commonjs/config/dependencyConfig.js +104 -43
- package/lib-commonjs/config/dependencyConfig.js.map +1 -1
- package/lib-commonjs/config/projectConfig.d.ts +4 -1
- package/lib-commonjs/config/projectConfig.js +72 -12
- package/lib-commonjs/config/projectConfig.js.map +1 -1
- package/lib-commonjs/e2etest/autolink.test.d.ts +6 -0
- package/lib-commonjs/e2etest/autolink.test.js +366 -0
- package/lib-commonjs/e2etest/autolink.test.js.map +1 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.d.ts +6 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.js +130 -0
- package/lib-commonjs/e2etest/dependencyConfig.test.js.map +1 -0
- package/lib-commonjs/e2etest/healthChecks.test.d.ts +6 -0
- package/lib-commonjs/e2etest/healthChecks.test.js +31 -0
- package/lib-commonjs/e2etest/healthChecks.test.js.map +1 -0
- package/lib-commonjs/e2etest/projectConfig.test.d.ts +6 -0
- package/lib-commonjs/e2etest/projectConfig.test.js +111 -0
- package/lib-commonjs/e2etest/projectConfig.test.js.map +1 -0
- package/lib-commonjs/e2etest/projectConfig.utils.d.ts +8 -0
- package/lib-commonjs/e2etest/projectConfig.utils.js +77 -0
- package/lib-commonjs/e2etest/projectConfig.utils.js.map +1 -0
- package/lib-commonjs/e2etest/runWindows.test.d.ts +6 -0
- package/lib-commonjs/e2etest/runWindows.test.js +61 -0
- package/lib-commonjs/e2etest/runWindows.test.js.map +1 -0
- package/lib-commonjs/generator-common/index.d.ts +17 -1
- package/lib-commonjs/generator-common/index.js +60 -39
- package/lib-commonjs/generator-common/index.js.map +1 -1
- package/lib-commonjs/generator-windows/index.d.ts +2 -2
- package/lib-commonjs/generator-windows/index.js +184 -202
- package/lib-commonjs/generator-windows/index.js.map +1 -1
- package/lib-commonjs/healthCheckList.d.ts +1 -0
- package/lib-commonjs/healthCheckList.js +16 -0
- package/lib-commonjs/healthCheckList.js.map +1 -0
- package/lib-commonjs/healthChecks.d.ts +2 -0
- package/lib-commonjs/healthChecks.js +84 -0
- package/lib-commonjs/healthChecks.js.map +1 -0
- package/lib-commonjs/index.d.ts +4 -0
- package/lib-commonjs/index.js +30 -9
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/runWindows/runWindows.js +220 -55
- package/lib-commonjs/runWindows/runWindows.js.map +1 -1
- package/lib-commonjs/runWindows/runWindowsOptions.d.ts +15 -11
- package/lib-commonjs/runWindows/runWindowsOptions.js +19 -11
- package/lib-commonjs/runWindows/runWindowsOptions.js.map +1 -1
- package/lib-commonjs/runWindows/utils/autolink.d.ts +88 -1
- package/lib-commonjs/runWindows/utils/autolink.js +593 -260
- package/lib-commonjs/runWindows/utils/autolink.js.map +1 -1
- package/lib-commonjs/runWindows/utils/build.d.ts +1 -2
- package/lib-commonjs/runWindows/utils/build.js +24 -31
- package/lib-commonjs/runWindows/utils/build.js.map +1 -1
- package/lib-commonjs/runWindows/utils/checkRequirements.js +11 -7
- package/lib-commonjs/runWindows/utils/checkRequirements.js.map +1 -1
- package/lib-commonjs/runWindows/utils/commandWithProgress.d.ts +11 -3
- package/lib-commonjs/runWindows/utils/commandWithProgress.js +58 -22
- package/lib-commonjs/runWindows/utils/commandWithProgress.js.map +1 -1
- package/lib-commonjs/runWindows/utils/deploy.d.ts +1 -1
- package/lib-commonjs/runWindows/utils/deploy.js +168 -82
- package/lib-commonjs/runWindows/utils/deploy.js.map +1 -1
- package/lib-commonjs/runWindows/utils/info.js +5 -2
- package/lib-commonjs/runWindows/utils/info.js.map +1 -1
- package/lib-commonjs/runWindows/utils/msbuildtools.d.ts +12 -6
- package/lib-commonjs/runWindows/utils/msbuildtools.js +145 -66
- package/lib-commonjs/runWindows/utils/msbuildtools.js.map +1 -1
- package/lib-commonjs/runWindows/utils/telemetryHelpers.d.ts +29 -0
- package/lib-commonjs/runWindows/utils/telemetryHelpers.js +113 -0
- package/lib-commonjs/runWindows/utils/telemetryHelpers.js.map +1 -0
- package/lib-commonjs/runWindows/utils/version.d.ts +4 -4
- package/lib-commonjs/runWindows/utils/version.js.map +1 -1
- package/lib-commonjs/runWindows/utils/vsInstalls.d.ts +2 -2
- package/lib-commonjs/runWindows/utils/vsInstalls.js +40 -10
- package/lib-commonjs/runWindows/utils/vsInstalls.js.map +1 -1
- package/lib-commonjs/runWindows/utils/vstools.d.ts +1 -0
- package/lib-commonjs/runWindows/utils/vstools.js +73 -33
- package/lib-commonjs/runWindows/utils/vstools.js.map +1 -1
- package/lib-commonjs/runWindows/utils/winappdeploytool.d.ts +3 -3
- package/lib-commonjs/runWindows/utils/winappdeploytool.js +17 -14
- package/lib-commonjs/runWindows/utils/winappdeploytool.js.map +1 -1
- package/package.json +46 -28
- package/powershell/Add-AppDevPackage.ps1 +2 -2
- package/powershell/Eval-MsBuildProperties.ps1 +156 -0
- package/powershell/WindowsStoreAppUtils.ps1 +10 -0
- package/CHANGELOG.json +0 -266
- package/CHANGELOG.md +0 -134
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @react-native-windows/cli
|
|
2
|
+
|
|
3
|
+
CLI to build and run React Native for Windows apps.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Run this from an existing `react-native` project with React Native Windows to build and deploy apps.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Example usage
|
|
11
|
+
```
|
|
12
|
+
npx react-native run-windows
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
| option | description | type |
|
|
17
|
+
|-----------------------|--------------------------------------|--------------------------------------------------|
|
|
18
|
+
| `--release` | Specifies a Release build | [boolean] |
|
|
19
|
+
| `--root` | Override the root directory for the windows build which contains the windows folder. (default: "E:\\test63") | [string] |
|
|
20
|
+
| `--arch` | The build architecture (ARM64, x86, x64). defaults to system architecture | [string] |
|
|
21
|
+
| `--singleproc` | Disables multi-proc build | [boolean] |
|
|
22
|
+
| `--emulator` | Deploys the app to an emulator | [boolean] |
|
|
23
|
+
| `--device` | Deploys the app to a connected device | [boolean] |
|
|
24
|
+
| `--target` | Deploys the app to the specified GUID for a device | [string] |
|
|
25
|
+
| `--remote-debugging` | Deploys the app in remote debugging mode. | [boolean] |
|
|
26
|
+
| `--logging` | Enables logging | [boolean] |
|
|
27
|
+
| `--no-packager` | Do not launch packager while building | [boolean] |
|
|
28
|
+
| `--bundle` | Enable Bundle configuration and it would be ReleaseBundle/DebugBundle other than Release/Debug | [boolean] |
|
|
29
|
+
| `--no-launch` | Do not launch the app after deployment | [boolean] |
|
|
30
|
+
| `--no-autolink` | Do not run autolinking | [boolean] |
|
|
31
|
+
| `--no-build` | Do not build the solution | [boolean] |
|
|
32
|
+
| `--no-deploy` | Do not deploy the app | [boolean] |
|
|
33
|
+
| `--deploy-from-layout`| Force deploy from layout, even in release builds | [boolean] |
|
|
34
|
+
| `--sln` | Override the app solution file determined by 'react-native config', e.g. windows\myApp.sln | [string] |
|
|
35
|
+
| `--proj` | Override the app project file determined by 'react-native config', e.g. windows\myApp\myApp.vcxproj | [string] |
|
|
36
|
+
| `--msbuildprops` | Comma separated props to pass to MSBuild, eg: prop1=value1,prop2=value2 | [string] |
|
|
37
|
+
| `--buildLogDirectory` | Optional directory where MSBuild log files should be stored | [string] |
|
|
38
|
+
| `--info` | Dump environment information | [boolean] |
|
|
39
|
+
| `--direct-debugging` | Enable direct debugging on specified port | [number] |
|
|
40
|
+
| `--no-telemetry` | Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI | [boolean] |
|
|
41
|
+
| `-h`, `--help` | output usage information | [boolean] |
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
## Data Collection
|
|
45
|
+
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.
|
|
46
|
+
|
|
47
|
+
This data collection notice only applies to the process of running the react-native-windows CLI (run-windows and related tools like autolinking).
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
* @format
|
|
5
|
+
*/
|
|
6
|
+
import { Command, CommandOption, Config } from '@react-native-community/cli-types';
|
|
7
|
+
import { Ora } from 'ora';
|
|
8
|
+
export declare class CodeGenWindows {
|
|
9
|
+
readonly root: string;
|
|
10
|
+
readonly options: CodeGenOptions;
|
|
11
|
+
private changesNecessary;
|
|
12
|
+
areChangesNeeded(): boolean;
|
|
13
|
+
constructor(root: string, options: CodeGenOptions);
|
|
14
|
+
run(spinner: Ora): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Performs codegen for RNW native modules and apps.
|
|
18
|
+
* @param args Unprocessed args passed from react-native CLI.
|
|
19
|
+
* @param config Config passed from react-native CLI.
|
|
20
|
+
* @param options Options passed from react-native CLI.
|
|
21
|
+
*/
|
|
22
|
+
export declare function codegenWindowsInternal(args: string[], config: Config, options: CodeGenOptions): Promise<void>;
|
|
23
|
+
export interface CodeGenOptions {
|
|
24
|
+
logging?: boolean;
|
|
25
|
+
check?: boolean;
|
|
26
|
+
telemetry?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare const codegenOptions: CommandOption[];
|
|
29
|
+
/**
|
|
30
|
+
* Performs codegen for RNW native modules.
|
|
31
|
+
*/
|
|
32
|
+
export declare const codegenCommand: Command;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
* @format
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.codegenCommand = exports.codegenOptions = exports.codegenWindowsInternal = exports.CodeGenWindows = void 0;
|
|
12
|
+
const path_1 = __importDefault(require("path"));
|
|
13
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
14
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
15
|
+
const commandWithProgress_1 = require("./runWindows/utils/commandWithProgress");
|
|
16
|
+
const telemetry_1 = require("@react-native-windows/telemetry");
|
|
17
|
+
const telemetryHelpers_1 = require("./runWindows/utils/telemetryHelpers");
|
|
18
|
+
const codegen_1 = require("@react-native-windows/codegen");
|
|
19
|
+
class CodeGenWindows {
|
|
20
|
+
areChangesNeeded() {
|
|
21
|
+
return this.changesNecessary;
|
|
22
|
+
}
|
|
23
|
+
constructor(root, options) {
|
|
24
|
+
this.root = root;
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.changesNecessary = false;
|
|
27
|
+
}
|
|
28
|
+
async run(spinner) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const verbose = this.options.logging;
|
|
31
|
+
verboseMessage('', verbose);
|
|
32
|
+
verboseMessage('Loading codegenConfig from package.json');
|
|
33
|
+
const pkgJson = require(path_1.default.join(this.root, 'package.json'));
|
|
34
|
+
if (!pkgJson.codegenConfig) {
|
|
35
|
+
spinner.info(`No ${chalk_1.default.bold('codegenConfig')} specified in package.json - ${chalk_1.default.yellow('Skipping codegen-windows')}`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const codegenConfigType = pkgJson.codegenConfig.type;
|
|
39
|
+
if (codegenConfigType !== 'modules' && codegenConfigType !== 'all') {
|
|
40
|
+
spinner.info(`${chalk_1.default.bold('codegenConfig.type')} in package.json is not ${chalk_1.default.bold('modules')} or ${chalk_1.default.bold('all')} - ${chalk_1.default.yellow('Skipping codegen-windows')}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!pkgJson.codegenConfig.windows) {
|
|
44
|
+
spinner.info(`No ${chalk_1.default.bold('codegenConfig.windows')} specified in package.json - ${chalk_1.default.yellow('Skipping codegen-windows')}`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!pkgJson.codegenConfig.windows.namespace) {
|
|
48
|
+
throw new telemetry_1.CodedError('InvalidCodegenConfig', `Missing ${chalk_1.default.bold('codegenConfig.windows.namespace')} value in package.json`);
|
|
49
|
+
}
|
|
50
|
+
let cppStringType = 'std::string';
|
|
51
|
+
if (pkgJson.codegenConfig.windows.cppStringType) {
|
|
52
|
+
switch (pkgJson.codegenConfig.windows.cppStringType) {
|
|
53
|
+
case 'std::string':
|
|
54
|
+
case 'std::wstring':
|
|
55
|
+
cppStringType = pkgJson.codegenConfig.windows.cppStringType;
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
throw new telemetry_1.CodedError('InvalidCodegenConfig', `Value of ${chalk_1.default.bold('codegenConfig.windows.cppStringType')} package.json should be either 'std::string' or 'std::wstring'`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!pkgJson.codegenConfig.name) {
|
|
62
|
+
throw new telemetry_1.CodedError('InvalidCodegenConfig', `Missing ${chalk_1.default.bold('codegenConfig.name')} value in package.json`);
|
|
63
|
+
}
|
|
64
|
+
const projectName = pkgJson.codegenConfig.name.replace(/[^a-zA-Z]/g, '');
|
|
65
|
+
const projectNamespace = pkgJson.codegenConfig.windows.namespace;
|
|
66
|
+
const jsRootDir = pkgJson.codegenConfig.jsSrcsDir
|
|
67
|
+
? path_1.default.join(this.root, pkgJson.codegenConfig.jsSrcsDir)
|
|
68
|
+
: this.root;
|
|
69
|
+
const codegenOutputDir = (_a = pkgJson.codegenConfig.windows.outputDirectory) !== null && _a !== void 0 ? _a : 'codegen';
|
|
70
|
+
const generators = (_b = pkgJson.codegenConfig.windows.generators) !== null && _b !== void 0 ? _b : [
|
|
71
|
+
'modulesWindows',
|
|
72
|
+
];
|
|
73
|
+
const jsRootPathRelative = path_1.default.relative(process.cwd(), jsRootDir);
|
|
74
|
+
const options = {
|
|
75
|
+
files: [
|
|
76
|
+
`${jsRootPathRelative}${jsRootPathRelative ? '/' : ''}**/*Native*.[jt]s`,
|
|
77
|
+
],
|
|
78
|
+
cppStringType,
|
|
79
|
+
libraryName: projectName,
|
|
80
|
+
methodOnly: false,
|
|
81
|
+
modulesCxx: generators.indexOf('modulesCxx') !== -1,
|
|
82
|
+
modulesTypeScriptTypes: generators.indexOf('modulesTypeScriptTypes') !== -1,
|
|
83
|
+
modulesWindows: generators.indexOf('modulesWindows') !== -1,
|
|
84
|
+
namespace: projectNamespace,
|
|
85
|
+
outputDirectory: path_1.default.join(this.root, codegenOutputDir),
|
|
86
|
+
test: !!this.options.check,
|
|
87
|
+
};
|
|
88
|
+
verboseMessage(`Run codegen with options: \n${JSON.stringify(options, null, 2)}`, verbose);
|
|
89
|
+
this.changesNecessary = (0, codegen_1.runCodeGen)(options);
|
|
90
|
+
spinner.succeed();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.CodeGenWindows = CodeGenWindows;
|
|
94
|
+
/**
|
|
95
|
+
* Logs the given message if verbose is True.
|
|
96
|
+
* @param message The message to log.
|
|
97
|
+
* @param verbose Whether or not verbose logging is enabled.
|
|
98
|
+
*/
|
|
99
|
+
function verboseMessage(message, verbose) {
|
|
100
|
+
if (verbose) {
|
|
101
|
+
console.log(message);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sanitizes the given option for telemetry.
|
|
106
|
+
* @param key The key of the option.
|
|
107
|
+
* @param value The unsanitized value of the option.
|
|
108
|
+
* @returns The sanitized value of the option.
|
|
109
|
+
*/
|
|
110
|
+
function optionSanitizer(key, value) {
|
|
111
|
+
// Do not add a default case here.
|
|
112
|
+
// Strings risking PII should just return true if present, false otherwise.
|
|
113
|
+
// All others should return the value (or false if undefined).
|
|
114
|
+
switch (key) {
|
|
115
|
+
case 'logging':
|
|
116
|
+
case 'check':
|
|
117
|
+
case 'telemetry':
|
|
118
|
+
return value === undefined ? false : value; // Return value
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Get the extra props to add to the `codegen-windows` telemetry event.
|
|
123
|
+
* @returns The extra props.
|
|
124
|
+
*/
|
|
125
|
+
async function getExtraProps() {
|
|
126
|
+
const extraProps = {};
|
|
127
|
+
return extraProps;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The function run when calling `react-native codegen-windows`.
|
|
131
|
+
* @param args Unprocessed args passed from react-native CLI.
|
|
132
|
+
* @param config Config passed from react-native CLI.
|
|
133
|
+
* @param options Options passed from react-native CLI.
|
|
134
|
+
*/
|
|
135
|
+
async function codegenWindows(args, config, options) {
|
|
136
|
+
await (0, telemetryHelpers_1.startTelemetrySession)('codegen-windows', config, options, (0, telemetryHelpers_1.getDefaultOptions)(config, exports.codegenOptions), optionSanitizer);
|
|
137
|
+
let codegenWindowsError;
|
|
138
|
+
try {
|
|
139
|
+
await codegenWindowsInternal(args, config, options);
|
|
140
|
+
}
|
|
141
|
+
catch (ex) {
|
|
142
|
+
codegenWindowsError =
|
|
143
|
+
ex instanceof Error ? ex : new Error(String(ex));
|
|
144
|
+
telemetry_1.Telemetry.trackException(codegenWindowsError);
|
|
145
|
+
}
|
|
146
|
+
await (0, telemetryHelpers_1.endTelemetrySession)(codegenWindowsError, getExtraProps);
|
|
147
|
+
(0, commandWithProgress_1.setExitProcessWithError)(options.logging, codegenWindowsError);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Performs codegen for RNW native modules and apps.
|
|
151
|
+
* @param args Unprocessed args passed from react-native CLI.
|
|
152
|
+
* @param config Config passed from react-native CLI.
|
|
153
|
+
* @param options Options passed from react-native CLI.
|
|
154
|
+
*/
|
|
155
|
+
async function codegenWindowsInternal(args, config, options) {
|
|
156
|
+
const startTime = perf_hooks_1.performance.now();
|
|
157
|
+
const spinner = (0, commandWithProgress_1.newSpinner)(options.check
|
|
158
|
+
? 'Checking codegen-windows files...'
|
|
159
|
+
: 'Running codegen-windows...');
|
|
160
|
+
try {
|
|
161
|
+
const codegen = new CodeGenWindows(config.root, options);
|
|
162
|
+
await codegen.run(spinner);
|
|
163
|
+
const endTime = perf_hooks_1.performance.now();
|
|
164
|
+
if (!codegen.areChangesNeeded()) {
|
|
165
|
+
console.log(`${chalk_1.default.green('Success:')} No codegen-windows changes necessary. (${Math.round(endTime - startTime)}ms)`);
|
|
166
|
+
}
|
|
167
|
+
else if (options.check) {
|
|
168
|
+
const codegenCommand = 'npx react-native codegen-windows';
|
|
169
|
+
console.log(`${chalk_1.default.yellow('Warning:')} Codegen-windows changes were necessary but ${chalk_1.default.bold('--check')} specified. Run '${chalk_1.default.bold(`${codegenCommand}`)}' to apply the changes. (${Math.round(endTime - startTime)}ms)`);
|
|
170
|
+
throw new telemetry_1.CodedError('NeedCodegen', `Codegen-windows changes were necessary but --check was specified. Run '${codegenCommand}' to apply the changes`);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
console.log(`${chalk_1.default.green('Success:')} Codegen-windows changes completed. (${Math.round(endTime - startTime)}ms)`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
spinner.fail();
|
|
178
|
+
const endTime = perf_hooks_1.performance.now();
|
|
179
|
+
console.log(`${chalk_1.default.red('Error:')} ${e.toString()}. (${Math.round(endTime - startTime)}ms)`);
|
|
180
|
+
throw e;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
exports.codegenWindowsInternal = codegenWindowsInternal;
|
|
184
|
+
exports.codegenOptions = [
|
|
185
|
+
{
|
|
186
|
+
name: '--logging',
|
|
187
|
+
description: 'Verbose output logging',
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
name: '--check',
|
|
191
|
+
description: 'Only check whether any codegen files need to change',
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: '--no-telemetry',
|
|
195
|
+
description: 'Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
/**
|
|
199
|
+
* Performs codegen for RNW native modules.
|
|
200
|
+
*/
|
|
201
|
+
exports.codegenCommand = {
|
|
202
|
+
name: 'codegen-windows',
|
|
203
|
+
description: 'Runs Windows specific codegen',
|
|
204
|
+
func: codegenWindows,
|
|
205
|
+
options: exports.codegenOptions,
|
|
206
|
+
};
|
|
207
|
+
//# sourceMappingURL=codegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../src/codegen.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,gDAAwB;AACxB,kDAA0B;AAC1B,2CAAuC;AAEvC,gFAGgD;AAOhD,+DAAsE;AACtE,0EAI6C;AAE7C,2DAIuC;AAGvC,MAAa,cAAc;IAGlB,gBAAgB;QACrB,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC/B,CAAC;IAED,YAAqB,IAAY,EAAW,OAAuB;QAA9C,SAAI,GAAJ,IAAI,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAgB;QACjE,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;IAChC,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,OAAY;;QAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,OAA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;QACjB,WAAW,EAAE,wBAAwB;KACtC;IACD;QACE,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,qDAAqD;KACnE;IACD;QACE,IAAI,EAAE,gBAAgB;QACtB,WAAW,EACT,uGAAuG;KAC1G;CACF,CAAC;AAEF;;GAEG;AACU,QAAA,cAAc,GAAY;IACrC,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,+BAA+B;IAC5C,IAAI,EAAE,cAAc;IACpB,OAAO,EAAE,sBAAc;CACxB,CAAC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\nimport path from 'path';\nimport chalk from 'chalk';\nimport {performance} from 'perf_hooks';\n\nimport {\n newSpinner,\n setExitProcessWithError,\n} from './runWindows/utils/commandWithProgress';\n\nimport {\n Command,\n CommandOption,\n Config,\n} from '@react-native-community/cli-types';\nimport {Telemetry, CodedError} from '@react-native-windows/telemetry';\nimport {\n getDefaultOptions,\n startTelemetrySession,\n endTelemetrySession,\n} from './runWindows/utils/telemetryHelpers';\n\nimport {\n CodeGenOptions as RnwCodeGenOptions,\n CppStringTypes,\n runCodeGen,\n} from '@react-native-windows/codegen';\nimport {Ora} from 'ora';\n\nexport class CodeGenWindows {\n private changesNecessary: boolean;\n\n public areChangesNeeded() {\n return this.changesNecessary;\n }\n\n constructor(readonly root: string, readonly options: CodeGenOptions) {\n this.changesNecessary = false;\n }\n\n public async run(spinner: Ora) {\n const verbose = this.options.logging;\n\n verboseMessage('', verbose);\n\n verboseMessage('Loading codegenConfig from package.json');\n const pkgJson = require(path.join(this.root, 'package.json'));\n\n if (!pkgJson.codegenConfig) {\n spinner.info(\n `No ${chalk.bold(\n 'codegenConfig',\n )} specified in package.json - ${chalk.yellow(\n 'Skipping codegen-windows',\n )}`,\n );\n return;\n }\n\n const codegenConfigType = pkgJson.codegenConfig.type;\n if (codegenConfigType !== 'modules' && codegenConfigType !== 'all') {\n spinner.info(\n `${chalk.bold(\n 'codegenConfig.type',\n )} in package.json is not ${chalk.bold('modules')} or ${chalk.bold(\n 'all',\n )} - ${chalk.yellow('Skipping codegen-windows')}`,\n );\n return;\n }\n\n if (!pkgJson.codegenConfig.windows) {\n spinner.info(\n `No ${chalk.bold(\n 'codegenConfig.windows',\n )} specified in package.json - ${chalk.yellow(\n 'Skipping codegen-windows',\n )}`,\n );\n return;\n }\n\n if (!pkgJson.codegenConfig.windows.namespace) {\n throw new CodedError(\n 'InvalidCodegenConfig',\n `Missing ${chalk.bold(\n 'codegenConfig.windows.namespace',\n )} value in package.json`,\n );\n }\n\n let cppStringType: CppStringTypes = 'std::string';\n if (pkgJson.codegenConfig.windows.cppStringType) {\n switch (pkgJson.codegenConfig.windows.cppStringType) {\n case 'std::string':\n case 'std::wstring':\n cppStringType = pkgJson.codegenConfig.windows.cppStringType;\n break;\n default:\n throw new CodedError(\n 'InvalidCodegenConfig',\n `Value of ${chalk.bold(\n 'codegenConfig.windows.cppStringType',\n )} package.json should be either 'std::string' or 'std::wstring'`,\n );\n }\n }\n\n if (!pkgJson.codegenConfig.name) {\n throw new CodedError(\n 'InvalidCodegenConfig',\n `Missing ${chalk.bold('codegenConfig.name')} value in package.json`,\n );\n }\n\n const projectName = pkgJson.codegenConfig.name.replace(/[^a-zA-Z]/g, '');\n const projectNamespace = pkgJson.codegenConfig.windows.namespace;\n const jsRootDir = pkgJson.codegenConfig.jsSrcsDir\n ? path.join(this.root, pkgJson.codegenConfig.jsSrcsDir)\n : this.root;\n const codegenOutputDir =\n pkgJson.codegenConfig.windows.outputDirectory ?? 'codegen';\n\n const generators = pkgJson.codegenConfig.windows.generators ?? [\n 'modulesWindows',\n ];\n\n const jsRootPathRelative = path.relative(process.cwd(), jsRootDir);\n const options: RnwCodeGenOptions = {\n files: [\n `${jsRootPathRelative}${\n jsRootPathRelative ? '/' : ''\n }**/*Native*.[jt]s`,\n ],\n cppStringType,\n libraryName: projectName,\n methodOnly: false,\n modulesCxx: generators.indexOf('modulesCxx') !== -1,\n modulesTypeScriptTypes:\n generators.indexOf('modulesTypeScriptTypes') !== -1,\n modulesWindows: generators.indexOf('modulesWindows') !== -1,\n namespace: projectNamespace,\n outputDirectory: path.join(this.root, codegenOutputDir),\n test: !!this.options.check,\n };\n\n verboseMessage(\n `Run codegen with options: \\n${JSON.stringify(options, null, 2)}`,\n verbose,\n );\n\n this.changesNecessary = runCodeGen(options);\n\n spinner.succeed();\n }\n}\n\n/**\n * Logs the given message if verbose is True.\n * @param message The message to log.\n * @param verbose Whether or not verbose logging is enabled.\n */\nfunction verboseMessage(message: any, verbose?: boolean) {\n if (verbose) {\n console.log(message);\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 CodeGenOptions, 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 'logging':\n case 'check':\n case 'telemetry':\n return value === undefined ? false : value; // Return value\n }\n}\n\n/**\n * Get the extra props to add to the `codegen-windows` telemetry event.\n * @returns The extra props.\n */\nasync function getExtraProps(): Promise<Record<string, any>> {\n const extraProps: Record<string, any> = {};\n return extraProps;\n}\n\n/**\n * The function run when calling `react-native codegen-windows`.\n * @param args Unprocessed args passed from react-native CLI.\n * @param config Config passed from react-native CLI.\n * @param options Options passed from react-native CLI.\n */\nasync function codegenWindows(\n args: string[],\n config: Config,\n options: CodeGenOptions,\n) {\n await startTelemetrySession(\n 'codegen-windows',\n config,\n options,\n getDefaultOptions(config, codegenOptions),\n optionSanitizer,\n );\n\n let codegenWindowsError: Error | undefined;\n try {\n await codegenWindowsInternal(args, config, options);\n } catch (ex) {\n codegenWindowsError =\n ex instanceof Error ? (ex as Error) : new Error(String(ex));\n Telemetry.trackException(codegenWindowsError);\n }\n\n await endTelemetrySession(codegenWindowsError, getExtraProps);\n setExitProcessWithError(options.logging, codegenWindowsError);\n}\n\n/**\n * Performs codegen for RNW native modules and apps.\n * @param args Unprocessed args passed from react-native CLI.\n * @param config Config passed from react-native CLI.\n * @param options Options passed from react-native CLI.\n */\nexport async function codegenWindowsInternal(\n args: string[],\n config: Config,\n options: CodeGenOptions,\n) {\n const startTime = performance.now();\n const spinner = newSpinner(\n options.check\n ? 'Checking codegen-windows files...'\n : 'Running codegen-windows...',\n );\n try {\n const codegen = new CodeGenWindows(config.root, options);\n await codegen.run(spinner);\n const endTime = performance.now();\n\n if (!codegen.areChangesNeeded()) {\n console.log(\n `${chalk.green(\n 'Success:',\n )} No codegen-windows changes necessary. (${Math.round(\n endTime - startTime,\n )}ms)`,\n );\n } else if (options.check) {\n const codegenCommand = 'npx react-native codegen-windows';\n console.log(\n `${chalk.yellow(\n 'Warning:',\n )} Codegen-windows changes were necessary but ${chalk.bold(\n '--check',\n )} specified. Run '${chalk.bold(\n `${codegenCommand}`,\n )}' to apply the changes. (${Math.round(endTime - startTime)}ms)`,\n );\n throw new CodedError(\n 'NeedCodegen',\n `Codegen-windows changes were necessary but --check was specified. Run '${codegenCommand}' to apply the changes`,\n );\n } else {\n console.log(\n `${chalk.green(\n 'Success:',\n )} Codegen-windows changes completed. (${Math.round(\n endTime - startTime,\n )}ms)`,\n );\n }\n } catch (e) {\n spinner.fail();\n const endTime = performance.now();\n console.log(\n `${chalk.red('Error:')} ${(e as any).toString()}. (${Math.round(\n endTime - startTime,\n )}ms)`,\n );\n throw e;\n }\n}\n\nexport interface CodeGenOptions {\n logging?: boolean;\n check?: boolean;\n telemetry?: boolean;\n}\n\nexport const codegenOptions: CommandOption[] = [\n {\n name: '--logging',\n description: 'Verbose output logging',\n },\n {\n name: '--check',\n description: 'Only check whether any codegen files need to change',\n },\n {\n name: '--no-telemetry',\n description:\n 'Disables sending telemetry that allows analysis of usage and failures of the react-native-windows CLI',\n },\n];\n\n/**\n * Performs codegen for RNW native modules.\n */\nexport const codegenCommand: Command = {\n name: 'codegen-windows',\n description: 'Runs Windows specific codegen',\n func: codegenWindows,\n options: codegenOptions,\n};\n"]}
|
|
@@ -64,7 +64,8 @@ export declare function readProjectFile(projectPath: string): Document;
|
|
|
64
64
|
* @param propertyName The property to look for.
|
|
65
65
|
* @return The value of the tag if it exists.
|
|
66
66
|
*/
|
|
67
|
-
export declare function
|
|
67
|
+
export declare function tryFindPropertyValue(projectContents: Node, propertyName: string): string | null;
|
|
68
|
+
export declare function findPropertyValue(projectContents: Node, propertyName: string, filePath: string): string;
|
|
68
69
|
/**
|
|
69
70
|
* Search for the given import project in the project contents and return if it exists.
|
|
70
71
|
* @param projectContents The XML project contents.
|
|
@@ -72,13 +73,34 @@ export declare function findPropertyValue(projectContents: Node, propertyName: s
|
|
|
72
73
|
* @return If the target exists.
|
|
73
74
|
*/
|
|
74
75
|
export declare function importProjectExists(projectContents: Node, projectName: string): boolean;
|
|
76
|
+
export type ConfigurationType = 'application' | 'dynamiclibrary' | 'generic' | 'staticlibrary' | 'unknown';
|
|
77
|
+
/**
|
|
78
|
+
* Gets the configuration type of the project from the project contents.
|
|
79
|
+
* @param projectContents The XML project contents.
|
|
80
|
+
* @return The project configuration type.
|
|
81
|
+
*/
|
|
82
|
+
export declare function getConfigurationType(projectContents: Node): ConfigurationType;
|
|
83
|
+
export type OutputType = 'appcontainerexe' | 'exe' | 'library' | 'module' | 'unknown' | 'winexe' | 'winmdobj';
|
|
84
|
+
/**
|
|
85
|
+
* Gets the output type of the project from the project contents.
|
|
86
|
+
* @param projectContents The XML project contents.
|
|
87
|
+
* @return The project output type.
|
|
88
|
+
*/
|
|
89
|
+
export declare function getOutputType(projectContents: Node): OutputType;
|
|
90
|
+
/**
|
|
91
|
+
* Gets the type of the project from the project contents.
|
|
92
|
+
* @param projectPath The project file path to check.
|
|
93
|
+
* @param projectContents The XML project contents.
|
|
94
|
+
* @return The project type.
|
|
95
|
+
*/
|
|
96
|
+
export declare function getProjectType(projectPath: string, projectContents: Node): ConfigurationType | OutputType;
|
|
75
97
|
/**
|
|
76
98
|
* Gets the name of the project from the project contents.
|
|
77
99
|
* @param projectPath The project file path to check.
|
|
78
100
|
* @param projectContents The XML project contents.
|
|
79
101
|
* @return The project name.
|
|
80
102
|
*/
|
|
81
|
-
export declare function getProjectName(projectContents: Node): string;
|
|
103
|
+
export declare function getProjectName(projectPath: string, projectContents: Node): string;
|
|
82
104
|
/**
|
|
83
105
|
* Gets the namespace of the project from the project contents.
|
|
84
106
|
* @param projectContents The XML project contents.
|
|
@@ -91,3 +113,4 @@ export declare function getProjectNamespace(projectContents: Node): string | nul
|
|
|
91
113
|
* @return The project guid.
|
|
92
114
|
*/
|
|
93
115
|
export declare function getProjectGuid(projectContents: Node): string | null;
|
|
116
|
+
export declare function getExperimentalFeatures(solutionDir: string): Record<string, string> | undefined;
|
|
@@ -4,14 +4,18 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
* @format
|
|
6
6
|
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
7
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.getProjectGuid = exports.getProjectNamespace = exports.getProjectName = exports.importProjectExists = exports.findPropertyValue = exports.readProjectFile = exports.getProjectLanguage = exports.findAppProjectFiles = exports.findDependencyProjectFiles = exports.isRnwDependencyProject = exports.findSolutionFiles = exports.isRnwSolution = exports.findWindowsFolder = exports.findFiles = void 0;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const xmldom_1 = require("xmldom");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
exports.getExperimentalFeatures = exports.getProjectGuid = exports.getProjectNamespace = exports.getProjectName = exports.getProjectType = exports.getOutputType = exports.getConfigurationType = exports.importProjectExists = exports.findPropertyValue = exports.tryFindPropertyValue = exports.readProjectFile = exports.getProjectLanguage = exports.findAppProjectFiles = exports.findDependencyProjectFiles = exports.isRnwDependencyProject = exports.findSolutionFiles = exports.isRnwSolution = exports.findWindowsFolder = exports.findFiles = void 0;
|
|
12
|
+
const fs_1 = __importDefault(require("@react-native-windows/fs"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const glob_1 = __importDefault(require("glob"));
|
|
15
|
+
const xmldom_1 = require("@xmldom/xmldom");
|
|
16
|
+
const xpath_1 = __importDefault(require("xpath"));
|
|
17
|
+
const telemetry_1 = require("@react-native-windows/telemetry");
|
|
18
|
+
const msbuildSelect = xpath_1.default.useNamespaces({
|
|
15
19
|
msbuild: 'http://schemas.microsoft.com/developer/msbuild/2003',
|
|
16
20
|
});
|
|
17
21
|
/**
|
|
@@ -21,13 +25,12 @@ const msbuildSelect = xpath.useNamespaces({
|
|
|
21
25
|
* @return Return the array of relative file paths.
|
|
22
26
|
*/
|
|
23
27
|
function findFiles(folder, filenamePattern) {
|
|
24
|
-
const files =
|
|
28
|
+
const files = glob_1.default.sync(path_1.default.join('**', filenamePattern), {
|
|
25
29
|
cwd: folder,
|
|
26
30
|
ignore: [
|
|
27
31
|
'node_modules/**',
|
|
28
32
|
'**/Debug/**',
|
|
29
33
|
'**/Release/**',
|
|
30
|
-
'**/WinUI3/**',
|
|
31
34
|
'**/Generated Files/**',
|
|
32
35
|
'**/packages/**',
|
|
33
36
|
],
|
|
@@ -42,8 +45,8 @@ exports.findFiles = findFiles;
|
|
|
42
45
|
*/
|
|
43
46
|
function findWindowsFolder(folder) {
|
|
44
47
|
const winDir = 'windows';
|
|
45
|
-
const joinedDir =
|
|
46
|
-
if (
|
|
48
|
+
const joinedDir = path_1.default.join(folder, winDir);
|
|
49
|
+
if (fs_1.default.existsSync(joinedDir)) {
|
|
47
50
|
return joinedDir;
|
|
48
51
|
}
|
|
49
52
|
return null;
|
|
@@ -55,7 +58,7 @@ exports.findWindowsFolder = findWindowsFolder;
|
|
|
55
58
|
* @return Whether the path is to a RNW solution file.
|
|
56
59
|
*/
|
|
57
60
|
function isRnwSolution(filePath) {
|
|
58
|
-
return (
|
|
61
|
+
return (fs_1.default
|
|
59
62
|
.readFileSync(filePath)
|
|
60
63
|
.toString()
|
|
61
64
|
.search(/ReactNative/) > 0);
|
|
@@ -77,11 +80,11 @@ function findSolutionFiles(winFolder) {
|
|
|
77
80
|
// If there is exactly one solution file, assume it's it
|
|
78
81
|
return [allSolutions[0]];
|
|
79
82
|
}
|
|
80
|
-
|
|
83
|
+
const solutionFiles = [];
|
|
81
84
|
// Try to find any solution file that appears to be a React Native solution
|
|
82
85
|
for (const solutionFile of allSolutions) {
|
|
83
|
-
if (isRnwSolution(
|
|
84
|
-
solutionFiles.push(solutionFile);
|
|
86
|
+
if (isRnwSolution(path_1.default.join(winFolder, solutionFile))) {
|
|
87
|
+
solutionFiles.push(path_1.default.normalize(solutionFile));
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
return solutionFiles;
|
|
@@ -118,16 +121,30 @@ function findDependencyProjectFiles(winFolder) {
|
|
|
118
121
|
// If there're no project files, return 0
|
|
119
122
|
return [];
|
|
120
123
|
}
|
|
121
|
-
|
|
124
|
+
const dependencyProjectFiles = [];
|
|
122
125
|
// Try to find any project file that appears to be a dependency project
|
|
123
126
|
for (const projectFile of allProjects) {
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
// A project is marked as a RNW dependency iff either:
|
|
128
|
+
// - If the project has the standard native module imports, or
|
|
129
|
+
// - If we only have a single project (and it doesn't have the standard native module imports),
|
|
130
|
+
// pick it and hope for the best. This enables autolinking for modules that were written
|
|
131
|
+
// before the standard native module template existed.
|
|
132
|
+
if (allProjects.length === 1 ||
|
|
133
|
+
isRnwDependencyProject(path_1.default.join(winFolder, projectFile))) {
|
|
134
|
+
dependencyProjectFiles.push(path_1.default.normalize(projectFile));
|
|
126
135
|
}
|
|
127
136
|
}
|
|
128
137
|
return dependencyProjectFiles;
|
|
129
138
|
}
|
|
130
139
|
exports.findDependencyProjectFiles = findDependencyProjectFiles;
|
|
140
|
+
function getReactNativeProjectType(value) {
|
|
141
|
+
switch (value) {
|
|
142
|
+
case 'App-WinAppSDK':
|
|
143
|
+
return value;
|
|
144
|
+
default:
|
|
145
|
+
return 'unknown';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
131
148
|
/**
|
|
132
149
|
* Checks if the target file path is a RNW app project file.
|
|
133
150
|
* @param filePath The absolute file path to check.
|
|
@@ -135,6 +152,10 @@ exports.findDependencyProjectFiles = findDependencyProjectFiles;
|
|
|
135
152
|
*/
|
|
136
153
|
function isRnwAppProject(filePath) {
|
|
137
154
|
const projectContents = readProjectFile(filePath);
|
|
155
|
+
const rnProjectType = getReactNativeProjectType(tryFindPropertyValue(projectContents, 'ReactNativeProjectType'));
|
|
156
|
+
if (rnProjectType !== 'unknown') {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
138
159
|
const projectLang = getProjectLanguage(filePath);
|
|
139
160
|
if (projectLang === 'cs') {
|
|
140
161
|
return importProjectExists(projectContents, 'Microsoft.ReactNative.Uwp.CSharpApp.targets');
|
|
@@ -158,11 +179,11 @@ function findAppProjectFiles(winFolder) {
|
|
|
158
179
|
// If there're no project files, return 0
|
|
159
180
|
return [];
|
|
160
181
|
}
|
|
161
|
-
|
|
182
|
+
const appProjectFiles = [];
|
|
162
183
|
// Try to find any project file that appears to be an app project
|
|
163
184
|
for (const projectFile of allProjects) {
|
|
164
|
-
if (isRnwAppProject(
|
|
165
|
-
appProjectFiles.push(projectFile);
|
|
185
|
+
if (isRnwAppProject(path_1.default.join(winFolder, projectFile))) {
|
|
186
|
+
appProjectFiles.push(path_1.default.normalize(projectFile));
|
|
166
187
|
}
|
|
167
188
|
}
|
|
168
189
|
return appProjectFiles;
|
|
@@ -189,7 +210,7 @@ exports.getProjectLanguage = getProjectLanguage;
|
|
|
189
210
|
* @return The project file contents.
|
|
190
211
|
*/
|
|
191
212
|
function readProjectFile(projectPath) {
|
|
192
|
-
const projectContents =
|
|
213
|
+
const projectContents = fs_1.default.readFileSync(projectPath, 'utf8').toString();
|
|
193
214
|
return new xmldom_1.DOMParser().parseFromString(projectContents, 'application/xml');
|
|
194
215
|
}
|
|
195
216
|
exports.readProjectFile = readProjectFile;
|
|
@@ -199,14 +220,29 @@ exports.readProjectFile = readProjectFile;
|
|
|
199
220
|
* @param propertyName The property to look for.
|
|
200
221
|
* @return The value of the tag if it exists.
|
|
201
222
|
*/
|
|
202
|
-
function
|
|
203
|
-
|
|
223
|
+
function tryFindPropertyValue(projectContents, propertyName) {
|
|
224
|
+
const nodes = msbuildSelect(`//msbuild:PropertyGroup/msbuild:${propertyName}`, projectContents);
|
|
204
225
|
if (nodes.length > 0) {
|
|
205
226
|
// Take the last one
|
|
206
227
|
return nodes[nodes.length - 1].textContent;
|
|
207
228
|
}
|
|
229
|
+
else {
|
|
230
|
+
const noNamespaceNodes = xpath_1.default.select(`//PropertyGroup/${propertyName}`, projectContents);
|
|
231
|
+
if (noNamespaceNodes.length > 0) {
|
|
232
|
+
return noNamespaceNodes[noNamespaceNodes.length - 1]
|
|
233
|
+
.textContent;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
208
236
|
return null;
|
|
209
237
|
}
|
|
238
|
+
exports.tryFindPropertyValue = tryFindPropertyValue;
|
|
239
|
+
function findPropertyValue(projectContents, propertyName, filePath) {
|
|
240
|
+
const res = tryFindPropertyValue(projectContents, propertyName);
|
|
241
|
+
if (!res) {
|
|
242
|
+
throw new telemetry_1.CodedError('NoPropertyInProject', `Couldn't find property ${propertyName} from ${filePath}`, { propertyName: propertyName });
|
|
243
|
+
}
|
|
244
|
+
return res;
|
|
245
|
+
}
|
|
210
246
|
exports.findPropertyValue = findPropertyValue;
|
|
211
247
|
/**
|
|
212
248
|
* Search for the given import project in the project contents and return if it exists.
|
|
@@ -215,19 +251,76 @@ exports.findPropertyValue = findPropertyValue;
|
|
|
215
251
|
* @return If the target exists.
|
|
216
252
|
*/
|
|
217
253
|
function importProjectExists(projectContents, projectName) {
|
|
218
|
-
|
|
254
|
+
const nodes = msbuildSelect(`//msbuild:Import[contains(@Project,'${projectName}')]`, projectContents);
|
|
219
255
|
return nodes.length > 0;
|
|
220
256
|
}
|
|
221
257
|
exports.importProjectExists = importProjectExists;
|
|
258
|
+
/**
|
|
259
|
+
* Gets the configuration type of the project from the project contents.
|
|
260
|
+
* @param projectContents The XML project contents.
|
|
261
|
+
* @return The project configuration type.
|
|
262
|
+
*/
|
|
263
|
+
function getConfigurationType(projectContents) {
|
|
264
|
+
var _a;
|
|
265
|
+
const configurationType = (_a = tryFindPropertyValue(projectContents, 'ConfigurationType')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
266
|
+
switch (configurationType) {
|
|
267
|
+
case 'application':
|
|
268
|
+
case 'dynamiclibrary':
|
|
269
|
+
case 'generic':
|
|
270
|
+
case 'staticlibrary':
|
|
271
|
+
return configurationType;
|
|
272
|
+
default:
|
|
273
|
+
return 'unknown';
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.getConfigurationType = getConfigurationType;
|
|
277
|
+
/**
|
|
278
|
+
* Gets the output type of the project from the project contents.
|
|
279
|
+
* @param projectContents The XML project contents.
|
|
280
|
+
* @return The project output type.
|
|
281
|
+
*/
|
|
282
|
+
function getOutputType(projectContents) {
|
|
283
|
+
var _a;
|
|
284
|
+
const outputType = (_a = tryFindPropertyValue(projectContents, 'OutputType')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
285
|
+
switch (outputType) {
|
|
286
|
+
case 'appcontainerexe':
|
|
287
|
+
case 'exe':
|
|
288
|
+
case 'library':
|
|
289
|
+
case 'module':
|
|
290
|
+
case 'winexe':
|
|
291
|
+
case 'winmdobj':
|
|
292
|
+
return outputType;
|
|
293
|
+
default:
|
|
294
|
+
return 'unknown';
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.getOutputType = getOutputType;
|
|
298
|
+
/**
|
|
299
|
+
* Gets the type of the project from the project contents.
|
|
300
|
+
* @param projectPath The project file path to check.
|
|
301
|
+
* @param projectContents The XML project contents.
|
|
302
|
+
* @return The project type.
|
|
303
|
+
*/
|
|
304
|
+
function getProjectType(projectPath, projectContents) {
|
|
305
|
+
switch (getProjectLanguage(projectPath)) {
|
|
306
|
+
case 'cpp':
|
|
307
|
+
return getConfigurationType(projectContents);
|
|
308
|
+
case 'cs':
|
|
309
|
+
return getOutputType(projectContents);
|
|
310
|
+
default:
|
|
311
|
+
return 'unknown';
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.getProjectType = getProjectType;
|
|
222
315
|
/**
|
|
223
316
|
* Gets the name of the project from the project contents.
|
|
224
317
|
* @param projectPath The project file path to check.
|
|
225
318
|
* @param projectContents The XML project contents.
|
|
226
319
|
* @return The project name.
|
|
227
320
|
*/
|
|
228
|
-
function getProjectName(projectContents) {
|
|
229
|
-
const name =
|
|
230
|
-
|
|
321
|
+
function getProjectName(projectPath, projectContents) {
|
|
322
|
+
const name = tryFindPropertyValue(projectContents, 'ProjectName') ||
|
|
323
|
+
path_1.default.parse(projectPath).name ||
|
|
231
324
|
'';
|
|
232
325
|
return name;
|
|
233
326
|
}
|
|
@@ -238,7 +331,7 @@ exports.getProjectName = getProjectName;
|
|
|
238
331
|
* @return The project namespace.
|
|
239
332
|
*/
|
|
240
333
|
function getProjectNamespace(projectContents) {
|
|
241
|
-
return
|
|
334
|
+
return tryFindPropertyValue(projectContents, 'RootNamespace');
|
|
242
335
|
}
|
|
243
336
|
exports.getProjectNamespace = getProjectNamespace;
|
|
244
337
|
/**
|
|
@@ -247,7 +340,22 @@ exports.getProjectNamespace = getProjectNamespace;
|
|
|
247
340
|
* @return The project guid.
|
|
248
341
|
*/
|
|
249
342
|
function getProjectGuid(projectContents) {
|
|
250
|
-
return
|
|
343
|
+
return tryFindPropertyValue(projectContents, 'ProjectGuid');
|
|
251
344
|
}
|
|
252
345
|
exports.getProjectGuid = getProjectGuid;
|
|
346
|
+
function getExperimentalFeatures(solutionDir) {
|
|
347
|
+
const propsFile = path_1.default.join(solutionDir, 'ExperimentalFeatures.props');
|
|
348
|
+
if (!fs_1.default.existsSync(propsFile)) {
|
|
349
|
+
return undefined;
|
|
350
|
+
}
|
|
351
|
+
const result = {};
|
|
352
|
+
const propsContents = readProjectFile(propsFile);
|
|
353
|
+
const nodes = msbuildSelect(`//msbuild:PropertyGroup/msbuild:*`, propsContents);
|
|
354
|
+
for (const node of nodes) {
|
|
355
|
+
const propertyNode = node;
|
|
356
|
+
result[propertyNode.nodeName] = propertyNode.textContent;
|
|
357
|
+
}
|
|
358
|
+
return result;
|
|
359
|
+
}
|
|
360
|
+
exports.getExperimentalFeatures = getExperimentalFeatures;
|
|
253
361
|
//# sourceMappingURL=configUtils.js.map
|