forked from dyne/zenpub-client
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcodegen.js
25 lines (22 loc) · 877 Bytes
/
codegen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const {createConfig} = require('@graphql-codegen/cli/dist/commonjs/config');
const {generate} = require('@graphql-codegen/cli/dist/commonjs/generate-and-save');
const {lifecycleHooks} = require('@graphql-codegen/cli/dist/commonjs/hooks');
const fs = require('fs')
const dotenv = require('dotenv')
dotenv.config()
if((!process.env.NODE_ENV || process.env.NODE_ENV === 'development') && fs.existsSync('.env.development')){
console.log('DEVELOPMENT MODE')
const envConfig = dotenv.parse(fs.readFileSync('.env.development'))
console.log('.env overrides:')
for (const k in envConfig) {
console.log(k,':',envConfig[k])
process.env[k] = envConfig[k]
}
}
createConfig({ config:'./codegen.yml' })
.then(config=>{
return generate(config).catch(async (error) => {
await lifecycleHooks(config.hooks).onError(error.toString());
throw error;
});
})