ern-api-gen
Version:
Electrode Native API generator
104 lines • 4.3 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Constants_1 = require("./Constants");
const path_1 = __importDefault(require("path"));
const cwd = path_1.default.join.bind(path_1.default, process.cwd());
// Generate a configuration. This looks in the apigen schema
// and the things passed in.
const isApiRe = /.*react-native-(.*)-api$/;
//
// Options :
// - name : Name of the api [REQUIRED]
// - bridgeVersion : The version of the bridge to use to generate API [REQUIRED]
// - reactNativeVersion : Version of react native to use [REQUIRED]
// - apiVersion : Version of the api [default: 1.0.0]
// - apiDescription : Description of the API [default: ERN Generated API for {name}]
// - apiAuthor : Author of the API [Default: EMAIL or USER env variable]
// - namespace : Namespace to use for messages [Default: com.{npmscope}.{name}.ern]
// - npmScope: Npm scope to use for the module [Default: no scope]
// - modelsSchemaPath : Path to the file holding the models schema [Default : no path]
// - apiSchemaPath : Path to the file holding the api schema [Default : no path]
// - moduleName : Name of the generated npm module
// - packageName : npm package name of the moduleName
function normalizeConfig(_a) {
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"]);
let simpleName = name;
if (isApiRe.test(name)) {
simpleName = isApiRe.exec(name).pop();
}
const config = {};
if (simpleName) {
if (/^@/.test(simpleName)) {
const reExec = /^@(.+?)\/(?:react-native-)?(.+?)(?:-api)?$/.exec(simpleName);
const pkgName = reExec[1];
const apiName = reExec[2];
simpleName = apiName;
if (!namespace) {
namespace = pkgName ? `com.${pkgName}.${simpleName}` : simpleName;
}
}
config.moduleName = simpleName;
}
if (namespace) {
config.namespace = namespace;
}
if (!config.namespace) {
config.namespace = npmScope
? `com.${npmScope}.${simpleName}.ern`
: `com.${simpleName}.ern`;
}
if (apiVersion) {
config.apiVersion = apiVersion;
}
if (apiDescription) {
config.apiDescription = apiDescription;
}
if (npmScope) {
config.npmScope = npmScope;
}
if (!config.moduleName) {
config.moduleName = moduleName || simpleName;
}
if (!config.apiAuthor) {
config.apiAuthor = apiAuthor || process.env.EMAIL || process.env.USER;
}
if (!config.apiVersion) {
config.apiVersion = '1.0.0';
}
if (!config.apiDescription) {
config.apiDescription = `ERN Generated API for ${config.moduleName}`;
}
if (bridgeVersion) {
config.bridgeVersion = bridgeVersion;
}
if (reactNativeVersion) {
config.reactNativeVersion = reactNativeVersion;
}
if (apiSchemaPath) {
config.apiSchemaPath = apiSchemaPath;
}
if (!config.artifactId) {
config.artifactId = `react-native-${simpleName}-api`;
}
if (targetDependencies) {
config.targetDependencies = targetDependencies;
}
if (packageName) {
config.packageName = packageName;
}
return config;
}
exports.default = normalizeConfig;
//# sourceMappingURL=normalizeConfig.js.map