1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4  value: true
5});
6exports.getAndroidManifestAsync = getAndroidManifestAsync;
7exports.getAppBuildGradleAsync = getAppBuildGradleAsync;
8exports.getAppBuildGradleFilePath = getAppBuildGradleFilePath;
9exports.getFileInfo = getFileInfo;
10exports.getGradleFilePath = getGradleFilePath;
11exports.getMainActivityAsync = getMainActivityAsync;
12exports.getMainApplicationAsync = getMainApplicationAsync;
13exports.getProjectBuildGradleAsync = getProjectBuildGradleAsync;
14exports.getProjectBuildGradleFilePath = getProjectBuildGradleFilePath;
15exports.getProjectFilePath = getProjectFilePath;
16exports.getProjectPathOrThrowAsync = getProjectPathOrThrowAsync;
17exports.getResourceFolderAsync = getResourceFolderAsync;
18exports.getResourceXMLPathAsync = getResourceXMLPathAsync;
19exports.getSettingsGradleAsync = getSettingsGradleAsync;
20exports.getSettingsGradleFilePath = getSettingsGradleFilePath;
21function _assert() {
22  const data = _interopRequireDefault(require("assert"));
23  _assert = function () {
24    return data;
25  };
26  return data;
27}
28function _fs() {
29  const data = _interopRequireDefault(require("fs"));
30  _fs = function () {
31    return data;
32  };
33  return data;
34}
35function _glob() {
36  const data = require("glob");
37  _glob = function () {
38    return data;
39  };
40  return data;
41}
42function path() {
43  const data = _interopRequireWildcard(require("path"));
44  path = function () {
45    return data;
46  };
47  return data;
48}
49function _errors() {
50  const data = require("../utils/errors");
51  _errors = function () {
52    return data;
53  };
54  return data;
55}
56function _modules() {
57  const data = require("../utils/modules");
58  _modules = function () {
59    return data;
60  };
61  return data;
62}
63function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
64function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
65function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
66function getProjectFilePath(projectRoot, name) {
67  const filePath = (0, _glob().sync)(path().join(projectRoot, `android/app/src/main/java/**/${name}.@(java|kt)`))[0];
68  (0, _assert().default)(filePath, `Project file "${name}" does not exist in android project for root "${projectRoot}"`);
69  return filePath;
70}
71function getLanguage(filePath) {
72  const extension = path().extname(filePath);
73  switch (extension) {
74    case '.java':
75      return 'java';
76    case '.kts':
77    case '.kt':
78      return 'kt';
79    case '.groovy':
80    case '.gradle':
81      return 'groovy';
82    default:
83      throw new (_errors().UnexpectedError)(`Unexpected Android file extension: ${extension}`);
84  }
85}
86function getFileInfo(filePath) {
87  return {
88    path: path().normalize(filePath),
89    contents: _fs().default.readFileSync(filePath, 'utf8'),
90    language: getLanguage(filePath)
91  };
92}
93async function getMainApplicationAsync(projectRoot) {
94  const filePath = getProjectFilePath(projectRoot, 'MainApplication');
95  return getFileInfo(filePath);
96}
97async function getMainActivityAsync(projectRoot) {
98  const filePath = getProjectFilePath(projectRoot, 'MainActivity');
99  return getFileInfo(filePath);
100}
101function getGradleFilePath(projectRoot, gradleName) {
102  const groovyPath = path().resolve(projectRoot, `${gradleName}.gradle`);
103  const ktPath = path().resolve(projectRoot, `${gradleName}.gradle.kts`);
104  const isGroovy = _fs().default.existsSync(groovyPath);
105  const isKotlin = !isGroovy && _fs().default.existsSync(ktPath);
106  if (!isGroovy && !isKotlin) {
107    throw new Error(`Failed to find '${gradleName}.gradle' file for project: ${projectRoot}.`);
108  }
109  const filePath = isGroovy ? groovyPath : ktPath;
110  return filePath;
111}
112function getProjectBuildGradleFilePath(projectRoot) {
113  return getGradleFilePath(path().join(projectRoot, 'android'), 'build');
114}
115async function getProjectBuildGradleAsync(projectRoot) {
116  return getFileInfo(getProjectBuildGradleFilePath(projectRoot));
117}
118function getSettingsGradleFilePath(projectRoot) {
119  return getGradleFilePath(path().join(projectRoot, 'android'), 'settings');
120}
121async function getSettingsGradleAsync(projectRoot) {
122  return getFileInfo(getSettingsGradleFilePath(projectRoot));
123}
124function getAppBuildGradleFilePath(projectRoot) {
125  return getGradleFilePath(path().join(projectRoot, 'android', 'app'), 'build');
126}
127async function getAppBuildGradleAsync(projectRoot) {
128  return getFileInfo(getAppBuildGradleFilePath(projectRoot));
129}
130async function getProjectPathOrThrowAsync(projectRoot) {
131  const projectPath = path().join(projectRoot, 'android');
132  if (await (0, _modules().directoryExistsAsync)(projectPath)) {
133    return projectPath;
134  }
135  throw new Error(`Android project folder is missing in project: ${projectRoot}`);
136}
137async function getAndroidManifestAsync(projectRoot) {
138  const projectPath = await getProjectPathOrThrowAsync(projectRoot);
139  const filePath = path().join(projectPath, 'app/src/main/AndroidManifest.xml');
140  return filePath;
141}
142async function getResourceFolderAsync(projectRoot) {
143  const projectPath = await getProjectPathOrThrowAsync(projectRoot);
144  return path().join(projectPath, `app/src/main/res`);
145}
146async function getResourceXMLPathAsync(projectRoot, {
147  kind = 'values',
148  name
149}) {
150  const resourcePath = await getResourceFolderAsync(projectRoot);
151  const filePath = path().join(resourcePath, `${kind}/${name}.xml`);
152  return filePath;
153}
154//# sourceMappingURL=Paths.js.map