UNPKG

1.84 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.findLibraryName = findLibraryName;
7
8function _fs() {
9 const data = _interopRequireDefault(require("fs"));
10
11 _fs = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function _path() {
19 const data = _interopRequireDefault(require("path"));
20
21 _path = function () {
22 return data;
23 };
24
25 return data;
26}
27
28function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
30function findLibraryName(root, sourceDir) {
31 const packageJsonPath = _path().default.join(root, 'package.json');
32
33 const buildGradlePath = _path().default.join(sourceDir, 'build.gradle');
34
35 const buildGradleKtsPath = _path().default.join(sourceDir, 'build.gradle.kts'); // We first check if there is a codegenConfig.name inside the package.json file.
36
37
38 if (_fs().default.existsSync(packageJsonPath)) {
39 var _packageJson$codegenC;
40
41 const packageJson = JSON.parse(_fs().default.readFileSync(packageJsonPath, 'utf8'));
42
43 if ((_packageJson$codegenC = packageJson.codegenConfig) === null || _packageJson$codegenC === void 0 ? void 0 : _packageJson$codegenC.name) {
44 return packageJson.codegenConfig.name;
45 }
46 } // If not, we check if the library specified it in the build.gradle file.
47
48
49 let buildGradleContents = '';
50
51 if (_fs().default.existsSync(buildGradlePath)) {
52 buildGradleContents = _fs().default.readFileSync(buildGradlePath, 'utf-8');
53 } else if (_fs().default.existsSync(buildGradleKtsPath)) {
54 buildGradleContents = _fs().default.readFileSync(buildGradleKtsPath, 'utf-8');
55 } else {
56 return undefined;
57 }
58
59 const match = buildGradleContents.match(/libraryName = ["'](.+)["']/);
60
61 if (match) {
62 return match[1];
63 } else {
64 return undefined;
65 }
66}
67
68//# sourceMappingURL=findLibraryName.js.map
\No newline at end of file