Skip to content

Commit 92e73aa

Browse files
committed
Add new environment variables
1 parent 5922cc2 commit 92e73aa

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ script:
1313
- yarn test
1414
- yarn lint
1515
- yarn test-gen
16+
- yarn test-gen-env
1617
- yarn check
1718

1819
deploy:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"lint": "eslint src",
4444
"build": "babel src -d lib --ignore '*.test.js'",
4545
"watch": "babel --watch src -d lib --ignore '*.test.js'",
46-
"test-gen": "rm -rf ./tmp && npm run build && ./lib/index.js https://demo.api-platform.com ./tmp"
46+
"test-gen": "rm -rf ./tmp && npm run build && ./lib/index.js https://demo.api-platform.com ./tmp",
47+
"test-gen-env": "rm -rf ./tmp && npm run build && API_PLATFORM_CLIENT_GENERATOR_ENTRYPOINT=https://demo.api-platform.com API_PLATFORM_CLIENT_GENERATOR_OUTPUT=./tmp ./lib/index.js"
4748
},
4849
"bin": {
4950
"generate-api-platform-client": "./lib/index.js"

src/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,39 @@ import generators from './generators';
99
program
1010
.version(version)
1111
.description('Generate a CRUD application built with React, Redux and React Router from an Hydra-enabled API')
12-
.usage('apiEntrypoint outputDirectory')
12+
.usage('entrypoint outputDirectory')
1313
.option('-r, --resource [resourceName]', 'Generate CRUD for the given resource')
1414
.option('-p, --hydra-prefix [hydraPrefix]', 'The hydra prefix used by the API', 'hydra:')
1515
.option('-g, --generator [generator]', 'The generator to use, one of "react", "angular" etc.', 'react')
1616
.parse(process.argv);
1717

18-
if (2 !== program.args.length) {
18+
if (2 !== program.args.length && (!process.env.API_PLATFORM_CLIENT_GENERATOR_ENTRYPOINT || !process.env.API_PLATFORM_CLIENT_GENERATOR_OUTPUT)) {
1919
program.help();
2020
}
2121

22-
const generator = generators(program.generator)(program.hydraPrefix)
22+
const entrypoint = program.args[0] || process.env.API_PLATFORM_CLIENT_GENERATOR_ENTRYPOINT;
23+
const outputDirectory = program.args[1] || process.env.API_PLATFORM_CLIENT_GENERATOR_OUTPUT;
24+
25+
const generator = generators(program.generator)(program.hydraPrefix);
2326
const resourceToGenerate = program.resource ? program.resource.toLowerCase() : null;
2427

25-
parseHydraDocumentation(program.args[0]).then(api => {
28+
parseHydraDocumentation(entrypoint).then(api => {
2629
for (let resource of api.api.resources) {
2730
const nameLc = resource.name.toLowerCase();
2831
const titleLc = resource.title.toLowerCase();
2932

3033
if (null === resourceToGenerate || nameLc === resourceToGenerate || titleLc === resourceToGenerate) {
31-
generator.generate(api, resource, program.args[1]);
34+
generator.generate(api, resource, outputDirectory);
3235
generator.help(resource)
3336
}
3437
}
3538

3639
if ('entrypoint' in generator) {
37-
generator.entrypoint(program.args[0], program.args[1]);
40+
generator.entrypoint(entrypoint, outputDirectory);
3841
}
3942

4043
if ('utils' in generator) {
41-
generator.utils(program.args[1]);
44+
generator.utils(outputDirectory);
4245
}
4346
}).catch((e) => {
4447
console.log(e);

0 commit comments

Comments
 (0)