ern-api-gen
Version:
Electrode Native API generator
279 lines • 11.2 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const DefaultGenerator_1 = __importDefault(require("../DefaultGenerator"));
const CodegenConfigurator_1 = __importDefault(require("../config/CodegenConfigurator"));
const LoggerFactory_1 = __importDefault(require("../java/LoggerFactory"));
const StringUtils_1 = require("../java/StringUtils");
const CodegenConfiguratorUtils_1 = require("../config/CodegenConfiguratorUtils");
const cli_1 = require("../java/cli");
const CodegenConstants_1 = __importDefault(require("../CodegenConstants"));
const beanUtils_1 = require("../java/beanUtils");
const hasArg = true;
class Generate {
constructor(values) {
this.output = '';
beanUtils_1.apply(this, values);
}
run() {
return __awaiter(this, void 0, void 0, function* () {
let configurator = CodegenConfigurator_1.default.fromFile(this.configFile);
if (configurator == null) {
configurator = new CodegenConfigurator_1.default();
}
if (this.verbose != null) {
configurator.setVerbose(this.verbose);
}
if (this.skipOverwrite != null) {
configurator.setSkipOverwrite(this.skipOverwrite);
}
if (StringUtils_1.isNotEmpty(this.spec)) {
configurator.setInputSpec(this.spec);
}
if (StringUtils_1.isNotEmpty(this.lang)) {
configurator.setLang(this.lang);
}
if (StringUtils_1.isNotEmpty(this.output)) {
configurator.setOutputDir(this.output);
}
if (StringUtils_1.isNotEmpty(this.auth)) {
configurator.setAuth(this.auth);
}
if (StringUtils_1.isNotEmpty(this.templateDir)) {
configurator.setTemplateDir(this.templateDir);
}
if (StringUtils_1.isNotEmpty(this.apiPackage)) {
configurator.setApiPackage(this.apiPackage);
}
if (StringUtils_1.isNotEmpty(this.modelPackage)) {
configurator.setModelPackage(this.modelPackage);
}
if (StringUtils_1.isNotEmpty(this.modelNamePrefix)) {
configurator.setModelNamePrefix(this.modelNamePrefix);
}
if (StringUtils_1.isNotEmpty(this.modelNameSuffix)) {
configurator.setModelNameSuffix(this.modelNameSuffix);
}
if (StringUtils_1.isNotEmpty(this.invokerPackage)) {
configurator.setInvokerPackage(this.invokerPackage);
}
if (StringUtils_1.isNotEmpty(this.groupId)) {
configurator.setGroupId(this.groupId);
}
if (StringUtils_1.isNotEmpty(this.artifactId)) {
configurator.setArtifactId(this.artifactId);
}
if (StringUtils_1.isNotEmpty(this.artifactVersion)) {
configurator.setArtifactVersion(this.artifactVersion);
}
if (StringUtils_1.isNotEmpty(this.library)) {
configurator.setLibrary(this.library);
}
if (StringUtils_1.isNotEmpty(this.gitUserId)) {
configurator.setGitUserId(this.gitUserId);
}
if (StringUtils_1.isNotEmpty(this.gitRepoId)) {
configurator.setGitRepoId(this.gitRepoId);
}
if (StringUtils_1.isNotEmpty(this.releaseNote)) {
configurator.setReleaseNote(this.releaseNote);
}
if (StringUtils_1.isNotEmpty(this.httpUserAgent)) {
configurator.setHttpUserAgent(this.httpUserAgent);
}
CodegenConfiguratorUtils_1.applySystemPropertiesKvp(this.systemProperties, configurator);
CodegenConfiguratorUtils_1.applyInstantiationTypesKvp(this.instantiationTypes, configurator);
CodegenConfiguratorUtils_1.applyImportMappingsKvp(this.importMappings, configurator);
CodegenConfiguratorUtils_1.applyTypeMappingsKvp(this.typeMappings, configurator);
CodegenConfiguratorUtils_1.applyAdditionalPropertiesKvp(this.additionalProperties, configurator);
CodegenConfiguratorUtils_1.applyLanguageSpecificPrimitivesCsv(this.languageSpecificPrimitives, configurator);
const clientOptInput = yield configurator.toClientOptInput();
const dg = new DefaultGenerator_1.default().opts(clientOptInput);
dg.generate();
});
}
}
Generate.Usage = new cli_1.Command({ name: 'generate', description: 'Generate code with chosen lang' }, [
{ name: ['-v', '--verbose'], description: 'verbose mode' },
{
description: 'client language to generate ({maybe class name in classpath, required},',
hasArg,
name: ['-l', '--lang'],
property: 'lang',
required: true,
title: 'language',
},
{
description: 'where to write the generated files ({current dir by default},',
hasArg,
name: ['-o', '--output'],
property: 'output',
title: 'output directory',
},
{
description: 'location of the swagger spec, as URL or file ({required},',
hasArg,
name: ['-i', '--input-spec'],
property: 'spec',
required: true,
title: 'spec file',
},
{
description: 'folder containing the template files',
hasArg,
name: ['-t', '--template-dir'],
title: 'template directory',
},
{
description: 'adds authorization headers when fetching the swagger definitions remotely. ' +
'Pass in a URL-encoded string of name:header with a comma separating multiple values',
hasArg,
name: ['-a', '--auth'],
property: 'auth',
title: 'authorization',
},
{
description: 'sets specified system properties in ' +
'the format of name:value,name:value',
hasArg,
name: ['-D'],
title: 'system properties',
},
{
description: 'Path to json configuration file. ' +
'File content should be in a json format ["optionKey":"optionValue", "optionKey1":"optionValue1"...] ' +
'Supported options can be different for each language. Run config-help -l [lang] command for language specific config options.',
hasArg,
name: ['-c', '--config'],
property: 'configFile',
title: 'configuration file',
},
{
description: 'specifies if the existing files should be overwritten during the generation.',
name: ['-s', '--skip-overwrite'],
title: 'skip overwrite',
},
{
description: CodegenConstants_1.default.API_PACKAGE_DESC,
hasArg,
name: ['--api-package'],
title: 'api package',
},
{
description: CodegenConstants_1.default.MODEL_PACKAGE_DESC,
hasArg,
name: ['--model-package'],
title: 'model package',
},
{
description: CodegenConstants_1.default.MODEL_NAME_PREFIX_DESC,
hasArg,
name: ['--model-name-prefix'],
title: 'model name prefix',
},
{
description: CodegenConstants_1.default.MODEL_NAME_SUFFIX_DESC,
hasArg,
name: ['--model-name-suffix'],
title: 'model name suffix',
},
{
description: 'sets instantiation type mappings in the format of type:instantiatedType,type:instantiatedType.' +
'For example ({in Java},: array:ArrayList,map:HashMap. In other words array types will get instantiated as ArrayList in generated code.',
hasArg,
name: ['--instantiation-types'],
title: 'instantiation types',
},
{
description: 'sets mappings between swagger spec types and generated code types ' +
'in the format of swaggerType:generatedType,swaggerType:generatedType. For example: array:List,map:Map,string:String',
hasArg,
name: ['--type-mappings'],
title: 'type mappings',
},
{
description: 'sets additional properties that can be referenced by the mustache templates in the format of name:value,name:value',
hasArg,
name: ['--additional-properties'],
title: 'additional properties',
},
{
description: 'specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double',
hasArg,
name: ['--language-specific-primitives'],
title: 'language specific primitives',
},
{
description: 'specifies mappings between a given class and the import that should be used for that class in the format of type:import,type:import',
hasArg,
name: ['--import-mappings'],
title: 'import mappings',
},
{
description: CodegenConstants_1.default.INVOKER_PACKAGE_DESC,
hasArg,
name: ['--invoker-package'],
title: 'invoker package',
},
{
description: CodegenConstants_1.default.GROUP_ID_DESC,
hasArg,
name: ['--group-id'],
title: 'group id',
},
{
description: CodegenConstants_1.default.ARTIFACT_ID_DESC,
hasArg,
name: ['--artifact-id'],
title: 'artifact id',
},
{
description: CodegenConstants_1.default.ARTIFACT_VERSION_DESC,
hasArg,
name: ['--artifact-version'],
title: 'artifact version',
},
{
description: CodegenConstants_1.default.LIBRARY_DESC,
hasArg,
name: ['--library'],
title: 'library',
},
{
description: CodegenConstants_1.default.GIT_USER_ID_DESC,
hasArg,
name: ['--git-user-id'],
title: 'git user id',
},
{
description: CodegenConstants_1.default.GIT_REPO_ID_DESC,
hasArg,
name: ['--git-repo-id'],
title: 'git repo id',
},
{
description: CodegenConstants_1.default.RELEASE_NOTE_DESC,
hasArg,
name: ['--release-note'],
title: 'release note',
},
{
description: CodegenConstants_1.default.HTTP_USER_AGENT_DESC,
hasArg,
name: ['--http-user-agent'],
title: 'http user agent',
},
]);
exports.default = Generate;
const Log = LoggerFactory_1.default.getLogger(Generate);
//# sourceMappingURL=Generate.js.map