Skip to content

Commit 7e2b08c

Browse files
authored
Adding options to override library version and platform version (#118)
Adding cli override options for library name, version and platform versions
1 parent 864c6a1 commit 7e2b08c

File tree

78 files changed

+1190
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1190
-30
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## 11.6.0
8+
### Added
9+
- Added options for defining `library_version` and `platform_version`
10+
- Added library version and platform version to composer.json and package.json
11+
712
## 11.5.0
813
### Changed
914
- `apiClient` property is changed from private to protected, to be able to extend factory class

src/Paysera/Bundle/JavascriptGeneratorBundle/Command/GeneratePackageCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ protected function configure()
4747
->addArgument('output_dir', InputArgument::REQUIRED, 'Where to put generated code')
4848
->addArgument('client_name', InputArgument::REQUIRED, 'Name of the main client class')
4949
->addOption('library_name', null, InputOption::VALUE_OPTIONAL, 'Optional package name in package.json')
50+
->addOption('library_version', null, InputOption::VALUE_OPTIONAL, 'Optional package version in package.json')
51+
->addOption('platform_version', null, InputOption::VALUE_OPTIONAL, 'Optional platform version in package.json')
5052
;
5153
}
5254

@@ -60,6 +62,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
6062
if ($input->getOption('library_name') !== null) {
6163
$options['library_name'] = $input->getOption('library_name');
6264
}
65+
if ($input->getOption('library_version') !== null) {
66+
$options['library_version'] = $input->getOption('library_version');
67+
}
68+
if ($input->getOption('platform_version') !== null) {
69+
$options['platform_version'] = $input->getOption('platform_version');
70+
}
6371

6472
$this->codeGenerator->generateCode(
6573
self::CODE_TYPE,

src/Paysera/Bundle/JavascriptGeneratorBundle/Resources/views/Package/package.json.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "{{ js_get_package_name(vendor_prefix, api) }}",
3-
"version": "0.0.1",
3+
"version": "{{ js_get_package_version(api)|raw }}",
44
"author": "{{ vendor_prefix }}",
55
"main": "dist/umd/main.js",
66
"module": "dist/es/index.js",
@@ -18,6 +18,12 @@
1818
"prepublishOnly": "npm run build",
1919
"lint": "eslint src/**/*.js"
2020
},
21+
{% set platform_version = js_get_platform_version(api) -%}
22+
{% if not platform_version is null -%}
23+
"engines": {
24+
"node": "{{ platform_version|raw }}"
25+
},
26+
{% endif -%}
2127
"dependencies": {
2228
{% for libraryConfig in get_external_libraries(api) %}
2329
"{{ libraryConfig.name }}": "{{ libraryConfig.version }}"{{ loop.last ? '' : ',' }}

src/Paysera/Bundle/JavascriptGeneratorBundle/Twig/ApiMethodExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function getFunctions()
4646
return [
4747
new Twig_SimpleFunction('js_get_client_name', [$this, 'getClientName']),
4848
new Twig_SimpleFunction('js_get_package_name', [$this, 'getPackageName']),
49+
new Twig_SimpleFunction('js_get_package_version', [$this, 'getPackageVersion']),
50+
new Twig_SimpleFunction('js_get_platform_version', [$this, 'getPlatformVersion']),
4951
new Twig_SimpleFunction('js_get_angular_module_name', [$this, 'getAngularJsModuleName'], ['is_safe' => ['js']]),
5052
new Twig_SimpleFunction('js_get_angular_client_factory_name', [$this, 'getAngularJsFactoryClassName']),
5153
new Twig_SimpleFunction('js_generate_uri', [$this, 'generateUri'], ['is_safe' => ['html']]),
@@ -71,6 +73,16 @@ public function getPackageName(string $vendor, ApiDefinition $api): string
7173
return sprintf('@%s/%s', $vendor, StringHelper::kebabCase($api->getName()));
7274
}
7375

76+
public function getPackageVersion(ApiDefinition $api): string
77+
{
78+
return $api->getOptions()['library_version'] ?? '0.0.1';
79+
}
80+
81+
public function getPlatformVersion(ApiDefinition $api): ?string
82+
{
83+
return $api->getOptions()['platform_version'] ?? null;
84+
}
85+
7486
public function getAngularJsModuleName(string $vendor, string $apiName) : string
7587
{
7688
return sprintf('%s.http.%s', $vendor, StringHelper::kebabCase($apiName));

src/Paysera/Bundle/PhpGeneratorBundle/Command/GenerateRestClientCommand.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ protected function configure()
3838
->addArgument('output_dir', InputArgument::REQUIRED, 'Where to put generated code')
3939
->addArgument('namespace', InputArgument::REQUIRED, 'Namespace of generated library, i.e.: Acme\\\\Client\\\\AcmeClient')
4040
->addOption('library_name', null, InputOption::VALUE_OPTIONAL, 'Optional library name in composer.json')
41+
->addOption('library_version', null, InputOption::VALUE_OPTIONAL, 'Optional library version in composer.json')
42+
->addOption('platform_version', null, InputOption::VALUE_OPTIONAL, 'Optional platform version in composer.json')
4143
;
4244
}
4345

@@ -52,6 +54,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
5254
if ($input->getOption('library_name') !== null) {
5355
$options['library_name'] = $input->getOption('library_name');
5456
}
57+
if ($input->getOption('library_version') !== null) {
58+
$options['library_version'] = $input->getOption('library_version');
59+
}
60+
if ($input->getOption('platform_version') !== null) {
61+
$options['platform_version'] = $input->getOption('platform_version');
62+
}
5563

5664
$this->codeGenerator->generateCode(
5765
self::CODE_TYPE,

src/Paysera/Bundle/PhpGeneratorBundle/Resources/views/RestClient/composer.json.twig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"name": "{{ php_get_library_name(vendor_prefix, api) }}",
33
"description": "{{ api.name|to_class_name }}",
4+
{% set library_version = php_get_library_version(api) -%}
5+
{% if not library_version is null -%}
6+
"version": "{{ library_version|raw }}",
7+
{% endif -%}
48
"autoload": {
59
"psr-4": {
610
"{{ (api.namespace ~ '\\')|replace({'\\':'\\\\'}) }}": "src"
711
}
812
},
913
"require": {
10-
"php": ">=5.5",
14+
"php": "{{ php_get_platform_version(api)|raw }}",
1115
{% for libraryConfig in get_external_libraries(api) -%}
1216
"{{ libraryConfig.name }}": "{{ libraryConfig.version }}",
1317
{% endfor -%}

src/Paysera/Bundle/PhpGeneratorBundle/Twig/ApiMethodExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public function getFunctions()
5858
new Twig_SimpleFunction('php_generate_method_arguments', [$this, 'generateMethodArguments'], ['needs_context' => true]),
5959
new Twig_SimpleFunction('php_inline_argument_names', [$this, 'getInlineArgumentNames']),
6060
new Twig_SimpleFunction('php_get_library_name', [$this, 'getLibraryName']),
61+
new Twig_SimpleFunction('php_get_library_version', [$this, 'getLibraryVersion']),
62+
new Twig_SimpleFunction('php_get_platform_version', [$this, 'getPlatformVersion']),
6163
new Twig_SimpleFunction('php_generate_entity_converter', [$this, 'generateEntityFromArgument'], ['needs_context' => true, 'is_safe' => ['html']]),
6264
];
6365
}
@@ -77,6 +79,16 @@ public function getLibraryName(string $vendor, ApiDefinition $api): string
7779
return sprintf('%s/lib-%s', $vendor, StringHelper::kebabCase($api->getName()));
7880
}
7981

82+
public function getLibraryVersion(ApiDefinition $api): ?string
83+
{
84+
return $api->getOptions()['library_version'] ?? $api->getRamlDefinition()->getVersion() ?? null;
85+
}
86+
87+
public function getPlatformVersion(ApiDefinition $api): string
88+
{
89+
return $api->getOptions()['platform_version'] ?? '>=5.5';
90+
}
91+
8092
/**
8193
* @param ArgumentDefinition[] $arguments
8294
* @return ArgumentDefinition[]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = (api) => {
2+
api.cache.forever();
3+
4+
return {
5+
presets: [
6+
['@babel/preset-env', { modules: false }],
7+
],
8+
plugins: ['@babel/plugin-transform-runtime'],
9+
};
10+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
},
5+
parser: 'babel-eslint',
6+
'extends': [
7+
'@paysera',
8+
],
9+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

0 commit comments

Comments
 (0)