@splunk/rum-cli
Version:
Tools for handling symbol and mapping files for symbolication
83 lines (82 loc) • 3.79 kB
JavaScript
;
/*
* Copyright Splunk Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractManifestData = void 0;
const xml2js_1 = require("xml2js");
const fs_1 = __importDefault(require("fs"));
const userFriendlyErrors_1 = require("./userFriendlyErrors");
const extractManifestData = (manifestPath) => __awaiter(void 0, void 0, void 0, function* () {
try {
const manifestContent = fs_1.default.readFileSync(manifestPath, 'utf-8');
const result = yield (0, xml2js_1.parseStringPromise)(manifestContent);
const packageId = extractPackageId(result);
const versionCode = extractVersionCode(result);
const splunkBuildId = extractSplunkBuildId(result);
return {
package: packageId,
versionCode,
splunkBuildId,
};
}
catch (error) {
const fileMessages = {
EACCES: `Failed to access the manifest file "${manifestPath}" due to missing permissions.\nMake sure that the CLI tool has "read" access to the file.`,
ENOENT: `The manifest file "${manifestPath}" does not exist.\nMake sure the correct path is being passed to --manifest.`,
ENOTDIR: `The path "${manifestPath}" is not a valid manifest file.\nEnsure you are providing a path to a valid AndroidManifest.xml.`,
};
(0, userFriendlyErrors_1.throwAsUserFriendlyErrnoException)(error, fileMessages);
}
});
exports.extractManifestData = extractManifestData;
/* eslint-disable */
const extractPackageId = (manifest) => {
try {
return manifest.manifest.$.package;
}
catch (error) {
throw new userFriendlyErrors_1.UserFriendlyError(error, "Failed to extract packageId from the manifest.");
}
};
/* eslint-disable */
const extractVersionCode = (manifest) => {
try {
return manifest.manifest.$['android:versionCode'];
}
catch (error) {
throw new userFriendlyErrors_1.UserFriendlyError(error, 'Failed to extract versionCode from the manifest.');
}
};
/* eslint-disable */
const extractSplunkBuildId = (manifest) => {
const metaData = manifest.manifest.application[0]['meta-data'];
if (!metaData)
return undefined;
const splunkBuildIdMeta = metaData.find((meta) => meta.$['android:name'] === 'splunk.build_id');
return splunkBuildIdMeta ? splunkBuildIdMeta.$['android:value'] : undefined;
};