11const { Command } = require ( "@oclif/command" ) ;
2- const nunjucks = require ( "nunjucks" ) ;
32const fs = require ( "fs" ) ;
43const fetch = require ( "node-fetch" ) ;
54const chalk = require ( "chalk" ) ;
@@ -8,14 +7,15 @@ const exec = util.promisify(require("child_process").exec);
87const exists = util . promisify ( fs . exists ) ;
98const writeFile = util . promisify ( fs . writeFile ) ;
109const mkdir = util . promisify ( fs . mkdir ) ;
10+ const yaml = require ( "js-yaml" ) ;
1111
1212const spinnerWith = require ( "../util/spinner" ) ;
1313const selectProject = require ( "../util/projects" ) ;
1414const {
1515 authFileExists,
1616 readAuthFile,
1717 getCustomApiEndpoint,
18- getNhostConfigTemplate ,
18+ getNhostConfig ,
1919} = require ( "../util/config" ) ;
2020const { validateAuth } = require ( "../util/login" ) ;
2121const checkForHasura = require ( "../util/dependencies" ) ;
@@ -159,12 +159,17 @@ class InitCommand extends Command {
159159 `project_id: ${ selectedProjectId } `
160160 ) ;
161161
162+ // generate Nhost config
163+ const nhostConfig = getNhostConfig ( project ) ;
164+
165+ const safeDumpOptions = {
166+ skipInvalid : true ,
167+ } ;
168+ const nhostConfigYaml = yaml . safeDump ( nhostConfig , safeDumpOptions ) ;
169+
162170 // config.yaml holds configuration for GraphQL engine, PostgreSQL and HBP
163171 // it is also a requirement for hasura to work
164- await writeFile (
165- `${ nhostDir } /config.yaml` ,
166- nunjucks . renderString ( getNhostConfigTemplate ( ) , project )
167- ) ;
172+ await writeFile ( `${ nhostDir } /config.yaml` , nhostConfigYaml ) ;
168173
169174 // create directory for migrations
170175 const migrationDirectory = `${ nhostDir } /migrations` ;
@@ -307,8 +312,7 @@ class InitCommand extends Command {
307312 if ( project . backend_user_fields ) {
308313 await this . _writeToFileSync (
309314 envFile ,
310- `JWT_CUSTOM_FIELDS=${ project . backend_user_fields } \n` ,
311- { flag : "a" }
315+ `JWT_CUSTOM_FIELDS=${ project . backend_user_fields } \n`
312316 ) ;
313317 }
314318
0 commit comments