UNPKG

4.38 kBJavaScriptView Raw
1"use strict";
2var __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};
13var __importDefault = (this && this.__importDefault) || function (mod) {
14 return (mod && mod.__esModule) ? mod : { "default": mod };
15};
16Object.defineProperty(exports, "__esModule", { value: true });
17const Constants_1 = require("./Constants");
18const path_1 = __importDefault(require("path"));
19const cwd = path_1.default.join.bind(path_1.default, process.cwd());
20// Generate a configuration. This looks in the apigen schema
21// and the things passed in.
22const isApiRe = /.*react-native-(.*)-api$/;
23//
24// Options :
25// - name : Name of the api [REQUIRED]
26// - bridgeVersion : The version of the bridge to use to generate API [REQUIRED]
27// - reactNativeVersion : Version of react native to use [REQUIRED]
28// - apiVersion : Version of the api [default: 1.0.0]
29// - apiDescription : Description of the API [default: ERN Generated API for {name}]
30// - apiAuthor : Author of the API [Default: EMAIL or USER env variable]
31// - namespace : Namespace to use for messages [Default: com.{npmscope}.{name}.ern]
32// - npmScope: Npm scope to use for the module [Default: no scope]
33// - modelsSchemaPath : Path to the file holding the models schema [Default : no path]
34// - apiSchemaPath : Path to the file holding the api schema [Default : no path]
35// - moduleName : Name of the generated npm module
36// - packageName : npm package name of the moduleName
37function normalizeConfig(_a) {
38 var { name /* REQUIRED */, bridgeVersion /* REQUIRED */, reactNativeVersion /* REQUIRED */, targetDependencies /* REQUIRED */, 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}
105exports.default = normalizeConfig;
106//# sourceMappingURL=normalizeConfig.js.map
\No newline at end of file