1082815dcSEvan Bacon"use strict"; 2082815dcSEvan Bacon 3082815dcSEvan BaconObject.defineProperty(exports, "__esModule", { 4082815dcSEvan Bacon value: true 5082815dcSEvan Bacon}); 6082815dcSEvan Baconexports.applyNameSettingsGradle = applyNameSettingsGradle; 7082815dcSEvan Baconexports.getName = getName; 8082815dcSEvan Baconexports.sanitizeNameForGradle = sanitizeNameForGradle; 9082815dcSEvan Baconexports.withNameSettingsGradle = exports.withName = void 0; 10082815dcSEvan Baconfunction _Resources() { 11082815dcSEvan Bacon const data = require("./Resources"); 12082815dcSEvan Bacon _Resources = function () { 13082815dcSEvan Bacon return data; 14082815dcSEvan Bacon }; 15082815dcSEvan Bacon return data; 16082815dcSEvan Bacon} 17082815dcSEvan Baconfunction _Strings() { 18082815dcSEvan Bacon const data = require("./Strings"); 19082815dcSEvan Bacon _Strings = function () { 20082815dcSEvan Bacon return data; 21082815dcSEvan Bacon }; 22082815dcSEvan Bacon return data; 23082815dcSEvan Bacon} 24*8a424bebSJames Idefunction _androidPlugins() { 25*8a424bebSJames Ide const data = require("../plugins/android-plugins"); 26*8a424bebSJames Ide _androidPlugins = function () { 27*8a424bebSJames Ide return data; 28*8a424bebSJames Ide }; 29*8a424bebSJames Ide return data; 30*8a424bebSJames Ide} 31*8a424bebSJames Idefunction _warnings() { 32*8a424bebSJames Ide const data = require("../utils/warnings"); 33*8a424bebSJames Ide _warnings = function () { 34*8a424bebSJames Ide return data; 35*8a424bebSJames Ide }; 36*8a424bebSJames Ide return data; 37*8a424bebSJames Ide} 38082815dcSEvan Bacon/** 39082815dcSEvan Bacon * Sanitize a name, this should be used for files and gradle names. 40082815dcSEvan Bacon * - `[/, \, :, <, >, ", ?, *, |]` are not allowed 41082815dcSEvan Bacon * https://docs.gradle.org/4.2/release-notes.html#path-separator-characters-in-names-are-deprecated 42082815dcSEvan Bacon * 43082815dcSEvan Bacon * @param name 44082815dcSEvan Bacon */ 45082815dcSEvan Baconfunction sanitizeNameForGradle(name) { 46082815dcSEvan Bacon // Remove escape characters which are valid in XML names but not in gradle. 47ee216927STomasz Sapeta name = name.replace(/[\n\r\t]/g, ''); 48082815dcSEvan Bacon 49ee216927STomasz Sapeta // Gradle disallows these: 50ee216927STomasz Sapeta // The project name 'My-Special Co/ol_Project' must not contain any of the following characters: [/, \, :, <, >, ", ?, *, |]. Set the 'rootProject.name' or adjust the 'include' statement (see https://docs.gradle.org/6.2/dsl/org.gradle.api.initialization.Settings.html#org.gradle.api.initialization.Settings:include(java.lang.String[]) for more details). 51082815dcSEvan Bacon return name.replace(/(\/|\\|:|<|>|"|\?|\*|\|)/g, ''); 52082815dcSEvan Bacon} 53082815dcSEvan Baconconst withName = (0, _androidPlugins().createStringsXmlPlugin)(applyNameFromConfig, 'withName'); 54082815dcSEvan Baconexports.withName = withName; 55082815dcSEvan Baconconst withNameSettingsGradle = config => { 56082815dcSEvan Bacon return (0, _androidPlugins().withSettingsGradle)(config, config => { 57082815dcSEvan Bacon if (config.modResults.language === 'groovy') { 58082815dcSEvan Bacon config.modResults.contents = applyNameSettingsGradle(config, config.modResults.contents); 59082815dcSEvan Bacon } else { 60082815dcSEvan Bacon (0, _warnings().addWarningAndroid)('name', `Cannot automatically configure settings.gradle if it's not groovy`); 61082815dcSEvan Bacon } 62082815dcSEvan Bacon return config; 63082815dcSEvan Bacon }); 64082815dcSEvan Bacon}; 65082815dcSEvan Baconexports.withNameSettingsGradle = withNameSettingsGradle; 66082815dcSEvan Baconfunction getName(config) { 67082815dcSEvan Bacon return typeof config.name === 'string' ? config.name : null; 68082815dcSEvan Bacon} 69082815dcSEvan Baconfunction applyNameFromConfig(config, stringsJSON) { 70082815dcSEvan Bacon const name = getName(config); 71082815dcSEvan Bacon if (name) { 72082815dcSEvan Bacon return (0, _Strings().setStringItem)([(0, _Resources().buildResourceItem)({ 73082815dcSEvan Bacon name: 'app_name', 74082815dcSEvan Bacon value: name 75082815dcSEvan Bacon })], stringsJSON); 76082815dcSEvan Bacon } 77082815dcSEvan Bacon return (0, _Strings().removeStringItem)('app_name', stringsJSON); 78082815dcSEvan Bacon} 79ee216927STomasz Sapeta 80082815dcSEvan Bacon/** 81082815dcSEvan Bacon * Regex a name change -- fragile. 82082815dcSEvan Bacon * 83082815dcSEvan Bacon * @param config 84082815dcSEvan Bacon * @param settingsGradle 85082815dcSEvan Bacon */ 86082815dcSEvan Baconfunction applyNameSettingsGradle(config, settingsGradle) { 87082815dcSEvan Bacon var _getName; 88ee216927STomasz Sapeta const name = sanitizeNameForGradle((_getName = getName(config)) !== null && _getName !== void 0 ? _getName : ''); 89082815dcSEvan Bacon 90ee216927STomasz Sapeta // Select rootProject.name = '***' and replace the contents between the quotes. 91082815dcSEvan Bacon return settingsGradle.replace(/rootProject.name\s?=\s?(["'])(?:(?=(\\?))\2.)*?\1/g, `rootProject.name = '${name.replace(/'/g, "\\'")}'`); 92082815dcSEvan Bacon} 93082815dcSEvan Bacon//# sourceMappingURL=Name.js.map