1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.applyNameSettingsGradle = applyNameSettingsGradle;
7exports.getName = getName;
8exports.sanitizeNameForGradle = sanitizeNameForGradle;
9exports.withNameSettingsGradle = exports.withName = void 0;
10
11function _androidPlugins() {
12  const data = require("../plugins/android-plugins");
13
14  _androidPlugins = function () {
15    return data;
16  };
17
18  return data;
19}
20
21function _warnings() {
22  const data = require("../utils/warnings");
23
24  _warnings = function () {
25    return data;
26  };
27
28  return data;
29}
30
31function _Resources() {
32  const data = require("./Resources");
33
34  _Resources = function () {
35    return data;
36  };
37
38  return data;
39}
40
41function _Strings() {
42  const data = require("./Strings");
43
44  _Strings = function () {
45    return data;
46  };
47
48  return data;
49}
50
51/**
52 * Sanitize a name, this should be used for files and gradle names.
53 * - `[/, \, :, <, >, ", ?, *, |]` are not allowed
54 * https://docs.gradle.org/4.2/release-notes.html#path-separator-characters-in-names-are-deprecated
55 *
56 * @param name
57 */
58function sanitizeNameForGradle(name) {
59  // Remove escape characters which are valid in XML names but not in gradle.
60  name = name.replace(/[\n\r\t]/g, ''); // Gradle disallows these:
61  // 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).
62
63  return name.replace(/(\/|\\|:|<|>|"|\?|\*|\|)/g, '');
64}
65
66const withName = (0, _androidPlugins().createStringsXmlPlugin)(applyNameFromConfig, 'withName');
67exports.withName = withName;
68
69const withNameSettingsGradle = config => {
70  return (0, _androidPlugins().withSettingsGradle)(config, config => {
71    if (config.modResults.language === 'groovy') {
72      config.modResults.contents = applyNameSettingsGradle(config, config.modResults.contents);
73    } else {
74      (0, _warnings().addWarningAndroid)('name', `Cannot automatically configure settings.gradle if it's not groovy`);
75    }
76
77    return config;
78  });
79};
80
81exports.withNameSettingsGradle = withNameSettingsGradle;
82
83function getName(config) {
84  return typeof config.name === 'string' ? config.name : null;
85}
86
87function applyNameFromConfig(config, stringsJSON) {
88  const name = getName(config);
89
90  if (name) {
91    return (0, _Strings().setStringItem)([(0, _Resources().buildResourceItem)({
92      name: 'app_name',
93      value: name
94    })], stringsJSON);
95  }
96
97  return (0, _Strings().removeStringItem)('app_name', stringsJSON);
98}
99/**
100 * Regex a name change -- fragile.
101 *
102 * @param config
103 * @param settingsGradle
104 */
105
106
107function applyNameSettingsGradle(config, settingsGradle) {
108  var _getName;
109
110  const name = sanitizeNameForGradle((_getName = getName(config)) !== null && _getName !== void 0 ? _getName : ''); // Select rootProject.name = '***' and replace the contents between the quotes.
111
112  return settingsGradle.replace(/rootProject.name\s?=\s?(["'])(?:(?=(\\?))\2.)*?\1/g, `rootProject.name = '${name.replace(/'/g, "\\'")}'`);
113}
114//# sourceMappingURL=Name.js.map