@rnv/engine-rn-windows
Version:
ReNative Engine to build for Windows platform with react native support.
62 lines • 2.26 kB
JavaScript
;
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
* @format
*/
var fs = require('fs');
var path = require('path');
var glob = require('glob');
var xmldom_1 = require('@xmldom/xmldom');
var xpath = require('xpath');
var msbuildSelect = xpath.useNamespaces({
msbuild: 'http://schemas.microsoft.com/developer/msbuild/2003',
});
/**
* Search for files matching the pattern under the target folder.
* @param folder The absolute path to target folder.
* @param filenamePattern The pattern to search for.
* @return Return the array of relative file paths.
*/
function findFiles(folder, filenamePattern) {
var files = glob.sync(path.join('**', filenamePattern), {
cwd: folder,
ignore: ['node_modules/**', '**/Debug/**', '**/Release/**', '**/Generated Files/**', '**/packages/**'],
});
return files;
}
exports.findFiles = findFiles;
/**
* Reads in the contents of the target project file.
* @param projectPath The target project file path.
* @return The project file contents.
*/
function readProjectFile(projectPath) {
var projectContents = fs.readFileSync(projectPath, 'utf8').toString();
return new xmldom_1.DOMParser().parseFromString(projectContents, 'application/xml');
}
exports.readProjectFile = readProjectFile;
/**
* Search for the given property in the project contents and return its value.
* @param projectContents The XML project contents.
* @param propertyName The property to look for.
* @return The value of the tag if it exists.
*/
function tryFindPropertyValue(projectContents, propertyName) {
var nodes = msbuildSelect("//msbuild:PropertyGroup/msbuild:".concat(propertyName), projectContents);
if (nodes.length > 0) {
// Take the last one
return nodes[nodes.length - 1].textContent;
}
return null;
}
exports.tryFindPropertyValue = tryFindPropertyValue;
function findPropertyValue(projectContents, propertyName, filePath) {
var res = tryFindPropertyValue(projectContents, propertyName);
if (!res) {
throw new Error("Couldn't find property ".concat(propertyName, " from ").concat(filePath));
}
return res;
}
exports.findPropertyValue = findPropertyValue;
//# sourceMappingURL=configUtils.js.map