@embrace-io/react-native
Version:
A React Native wrapper for the Embrace SDK
68 lines (67 loc) • 3.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAIN_CLASS_BY_LANGUAGE = exports.addLineBeforeToTextInFile = exports.addLineAfterToTextInFile = exports.OBJECTIVEC_APP_DELEGATE = exports.SWIFT_APP_DELEGATE = exports.KOTLIN_MAIN_ACTIVITY = exports.JAVA_MAIN_ACTIVITY = void 0;
const EmbraceLogger_1 = require("../../../src/utils/EmbraceLogger");
// TODO refactor this
const logger = new EmbraceLogger_1.default(console);
exports.JAVA_MAIN_ACTIVITY = "MainApplication.java";
exports.KOTLIN_MAIN_ACTIVITY = "MainApplication.kt";
exports.SWIFT_APP_DELEGATE = "AppDelegate.swift";
exports.OBJECTIVEC_APP_DELEGATE = "AppDelegate.*(m|mm)";
/**
* Adds a line to the specified file after the specified search text.
*
* This function will return true if the line was successfully added to the file.
*
* @param file The file where the new line will be added.
* @param lineToAdd The line that will be added to the file.
* @param searchText The text used to determine the location where the new line will be added.
* The new line will be added after the first occurrence of this text.
* @param fileName The name of the file, used only for logging purposes.
* @return Returns true if the line was successfully added to the file, false if the line already exists.
*/
const addLineAfterToTextInFile = (file, lineToAdd, searchText, fileName) => {
if (file.hasLine(lineToAdd)) {
logger.warn(`${fileName} already contains the line: ${lineToAdd}`);
return false;
}
else {
logger.warn(`Adding: ${lineToAdd} in ${fileName}`);
file.addAfter(searchText, lineToAdd);
return true;
}
};
exports.addLineAfterToTextInFile = addLineAfterToTextInFile;
/**
* Adds a line to the specified file after the specified search text.
*
* This function will return true if the line was successfully added to the file.
*
* @param file The file where the new line will be added.
* @param lineToAdd The line that will be added to the file.
* @param searchText The text used to determine the location where the new line will be added.
* The new line will be added after the first occurrence of this text.
* @param fileName The name of the file, used only for logging purposes.
* @return Returns true if the line was successfully added to the file, false if the line already exists.
*/
const addLineBeforeToTextInFile = (file, lineToAdd, searchText, fileName) => {
if (file.hasLine(lineToAdd)) {
logger.warn(`${fileName} already contains the line: ${lineToAdd}`);
return false;
}
else {
logger.warn(`Adding the line: ${lineToAdd} in ${fileName}`);
file.addBefore(searchText, lineToAdd);
return true;
}
};
exports.addLineBeforeToTextInFile = addLineBeforeToTextInFile;
const MAIN_CLASS_BY_LANGUAGE = {
kotlin: exports.KOTLIN_MAIN_ACTIVITY,
java: exports.JAVA_MAIN_ACTIVITY,
objectivec: exports.OBJECTIVEC_APP_DELEGATE,
swift: exports.SWIFT_APP_DELEGATE,
swift5x: exports.SWIFT_APP_DELEGATE,
objectivec5x: exports.OBJECTIVEC_APP_DELEGATE,
};
exports.MAIN_CLASS_BY_LANGUAGE = MAIN_CLASS_BY_LANGUAGE;