1 | "use strict";
|
2 | var __rest = (this && this.__rest) || function (s, e) {
|
3 | var t = {};
|
4 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
5 | t[p] = s[p];
|
6 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
7 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
8 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
9 | t[p[i]] = s[p[i]];
|
10 | }
|
11 | return t;
|
12 | };
|
13 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
14 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
15 | };
|
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
17 | const Constants_1 = require("./Constants");
|
18 | const path_1 = __importDefault(require("path"));
|
19 | const cwd = path_1.default.join.bind(path_1.default, process.cwd());
|
20 |
|
21 |
|
22 | const isApiRe = /.*react-native-(.*)-api$/;
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function normalizeConfig(_a) {
|
38 | var { name , bridgeVersion , reactNativeVersion , targetDependencies , apiVersion, apiDescription, apiAuthor, namespace, npmScope, apiSchemaPath = Constants_1.MODEL_FILE, moduleName, artifactId, packageName } = _a, rest = __rest(_a, ["name", "bridgeVersion", "reactNativeVersion", "targetDependencies", "apiVersion", "apiDescription", "apiAuthor", "namespace", "npmScope", "apiSchemaPath", "moduleName", "artifactId", "packageName"]);
|
39 | let simpleName = name;
|
40 | if (isApiRe.test(name)) {
|
41 | simpleName = isApiRe.exec(name).pop();
|
42 | }
|
43 | const config = {};
|
44 | if (simpleName) {
|
45 | if (/^@/.test(simpleName)) {
|
46 | const reExec = /^@(.+?)\/(?:react-native-)?(.+?)(?:-api)?$/.exec(simpleName);
|
47 | const pkgName = reExec[1];
|
48 | const apiName = reExec[2];
|
49 | simpleName = apiName;
|
50 | if (!namespace) {
|
51 | namespace = pkgName ? `com.${pkgName}.${simpleName}` : simpleName;
|
52 | }
|
53 | }
|
54 | config.moduleName = simpleName;
|
55 | }
|
56 | if (namespace) {
|
57 | config.namespace = namespace;
|
58 | }
|
59 | if (!config.namespace) {
|
60 | config.namespace = npmScope
|
61 | ? `com.${npmScope}.${simpleName}.ern`
|
62 | : `com.${simpleName}.ern`;
|
63 | }
|
64 | if (apiVersion) {
|
65 | config.apiVersion = apiVersion;
|
66 | }
|
67 | if (apiDescription) {
|
68 | config.apiDescription = apiDescription;
|
69 | }
|
70 | if (npmScope) {
|
71 | config.npmScope = npmScope;
|
72 | }
|
73 | if (!config.moduleName) {
|
74 | config.moduleName = moduleName || simpleName;
|
75 | }
|
76 | if (!config.apiAuthor) {
|
77 | config.apiAuthor = apiAuthor || process.env.EMAIL || process.env.USER;
|
78 | }
|
79 | if (!config.apiVersion) {
|
80 | config.apiVersion = '1.0.0';
|
81 | }
|
82 | if (!config.apiDescription) {
|
83 | config.apiDescription = `ERN Generated API for ${config.moduleName}`;
|
84 | }
|
85 | if (bridgeVersion) {
|
86 | config.bridgeVersion = bridgeVersion;
|
87 | }
|
88 | if (reactNativeVersion) {
|
89 | config.reactNativeVersion = reactNativeVersion;
|
90 | }
|
91 | if (apiSchemaPath) {
|
92 | config.apiSchemaPath = apiSchemaPath;
|
93 | }
|
94 | if (!config.artifactId) {
|
95 | config.artifactId = `react-native-${simpleName}-api`;
|
96 | }
|
97 | if (targetDependencies) {
|
98 | config.targetDependencies = targetDependencies;
|
99 | }
|
100 | if (packageName) {
|
101 | config.packageName = packageName;
|
102 | }
|
103 | return config;
|
104 | }
|
105 | exports.default = normalizeConfig;
|
106 |
|
\ | No newline at end of file |