TD-253: Init

This commit is contained in:
Rinat Arsaev 2022-03-31 11:49:31 +03:00
commit d321bd77e8
13 changed files with 2258 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/node_modules

5
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<includedPredefinedLibrary name="Node.js Core" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/openapi-cli.iml" filepath="$PROJECT_DIR$/.idea/openapi-cli.iml" />
</modules>
</component>
</project>

12
.idea/openapi-cli.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

7
.idea/prettier.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PrettierConfiguration">
<option name="myRunOnSave" value="true" />
<option name="myRunOnReformat" value="true" />
</component>
</project>

6
.idea/thriftCompiler.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ThriftCompiler">
<compilers />
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

3
.prettierignore Normal file
View File

@ -0,0 +1,3 @@
package.json
package-lock.json
node_modules

5
.prettierrc Normal file
View File

@ -0,0 +1,5 @@
{
"printWidth": 120,
"singleQuote": true,
"tabWidth": 4
}

61
lib/bin.js Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env node
const shell = require('shelljs');
const sade = require('sade');
const path = require('path');
const fs = require('fs');
const PACKAGE_JSON = require('../package.json');
const CLI_NAME = Object.keys(PACKAGE_JSON.bin)[0];
const prog = sade(CLI_NAME).describe('OpenAPI generator CLI').version(PACKAGE_JSON.version);
prog.command('generate <src>')
.describe('Generate OpenAPI for Angular')
.option('-o, --output')
.option('-n, --ng-version')
.action((src, opts) => {
const angularVersion = opts.n || '~13.0.0';
const openapiGeneratorCliVersion = opts.n || '~2.4.0';
const outputDir = opts.o || 'lib';
const ngCommand = `npm_config_yes=true npx -p @angular/cli@${angularVersion} ng`;
const openapiGeneratorCliCommand = `npx @openapitools/openapi-generator-cli@${openapiGeneratorCliVersion}`;
const generatedDir = CLI_NAME;
const packageJson = require(path.join(process.cwd(), 'package.json'));
const libraryName = packageJson.name;
const libraryPath = path.join(generatedDir, 'projects', libraryName.replace('@', ''));
shell.rm('-rf', generatedDir);
shell.rm('-rf', outputDir);
shell.exec(`${ngCommand} new ${generatedDir} --no-create-application`);
shell.cd(generatedDir);
shell.exec(`${ngCommand} generate library ${libraryName}`);
shell.cd(`..`);
shell.rm('-rf', path.join(libraryPath, 'src/lib'));
fs.writeFileSync(path.join(libraryPath, 'src/public-api.ts'), 'export * from "./lib";');
shell.exec(
`${openapiGeneratorCliCommand} generate -i ${src} -g typescript-angular -o ${path.join(
libraryPath,
'src/lib'
)} -p=fileNaming=kebab-case,useSingleRequestParameter=true`
);
shell.cd(generatedDir);
shell.exec(`npm run build`);
shell.cd('..');
shell.mv(path.join(generatedDir, 'dist', libraryName.replace('@', '')), outputDir);
let resultPackageJson = require(path.join(process.cwd(), outputDir, 'package.json'));
resultPackageJson = {
...resultPackageJson,
version: packageJson.version || resultPackageJson.version,
license: packageJson.license || 'MIT',
publishConfig: packageJson.publishConfig || {
access: 'public',
registry: 'https://registry.npmjs.org/',
},
};
fs.writeFileSync(path.join(outputDir, 'package.json'), JSON.stringify(resultPackageJson, null, 2));
shell.rm('-rf', generatedDir);
});
prog.parse(process.argv);

2116
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

22
package.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "@vality/openapi-generator-cli",
"version": "0.1.0",
"description": "",
"main": "lib/index.js",
"bin": {
"vality-openapi": "lib/bin.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Vality",
"license": "Apache-2.0",
"devDependencies": {
"prettier": "^2.6.1"
},
"dependencies": {
"@openapitools/openapi-generator-cli": "^2.4.26",
"sade": "^1.8.1",
"shelljs": "^0.8.5"
}
}