Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit 9e513cf

Browse files
author
Johan Eliasson
authored
Merge pull request #75 from nhost/canary
git
2 parents bdd0631 + 51c874f commit 9e513cf

6 files changed

Lines changed: 224 additions & 177 deletions

File tree

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nhost",
33
"description": "Nhost's command-line",
4-
"version": "0.4.0",
4+
"version": "0.4.1",
55
"author": "Nuno Pato @nhost",
66
"bin": {
77
"nhost": "./bin/run"
@@ -20,7 +20,6 @@
2020
"inquirer": "^7.3.2",
2121
"js-yaml": "^3.13.1",
2222
"node-fetch": "^2.6.0",
23-
"nunjucks": "^3.2.1",
2423
"ora": "^4.0.4",
2524
"tree-kill": "^1.2.2",
2625
"write-json-file": "^4.3.0"

src/commands/dev.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ const { spawn, execSync } = require("child_process");
44
const yaml = require("js-yaml");
55
const crypto = require("crypto");
66
const chalk = require("chalk");
7-
const nunjucks = require("nunjucks");
87
const kill = require("tree-kill");
98
const detect = require("detect-port");
109

1110
const spinnerWith = require("../util/spinner");
12-
const getComposeTemplate = require("../util/compose");
11+
const { generateNhostBackendYaml } = require("../util/compose");
1312
const getDockerApiTemplate = require("../util/docker-api");
1413

1514
const util = require("util");
@@ -151,19 +150,23 @@ class DevCommand extends Command {
151150
process.exit(1);
152151
}
153152

154-
if (await exists("./api")) {
155-
nhostConfig["startApi"] = true;
156-
}
153+
nhostConfig["startAPI"] = await exists("./api");
157154

158155
nhostConfig.graphql_jwt_key = crypto
159156
.randomBytes(128)
160157
.toString("hex")
161158
.slice(0, 128);
162159

163-
await writeFile(
164-
`${dotNhost}/docker-compose.yaml`,
165-
nunjucks.renderString(getComposeTemplate(), nhostConfig)
166-
);
160+
// generate
161+
const nhostBackendYaml = generateNhostBackendYaml(nhostConfig);
162+
163+
// write to file
164+
const safeDumpOptions = {
165+
skipInvalid: true,
166+
};
167+
const dockerComposeYaml = yaml.safeDump(nhostBackendYaml, safeDumpOptions);
168+
169+
await writeFile(`${dotNhost}/docker-compose.yaml`, dockerComposeYaml);
167170

168171
// write docker api file
169172
await writeFile(`${dotNhost}/Dockerfile-api`, getDockerApiTemplate());
@@ -272,6 +275,4 @@ DevCommand.description = `Start Nhost project for local development
272275
Start Nhost project for local development
273276
`;
274277

275-
nunjucks.configure({ autoescape: true });
276-
277278
module.exports = DevCommand;

src/commands/init.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const { Command } = require("@oclif/command");
2-
const nunjucks = require("nunjucks");
32
const fs = require("fs");
43
const fetch = require("node-fetch");
54
const chalk = require("chalk");
@@ -8,14 +7,15 @@ const exec = util.promisify(require("child_process").exec);
87
const exists = util.promisify(fs.exists);
98
const writeFile = util.promisify(fs.writeFile);
109
const mkdir = util.promisify(fs.mkdir);
10+
const yaml = require("js-yaml");
1111

1212
const spinnerWith = require("../util/spinner");
1313
const selectProject = require("../util/projects");
1414
const {
1515
authFileExists,
1616
readAuthFile,
1717
getCustomApiEndpoint,
18-
getNhostConfigTemplate,
18+
getNhostConfig,
1919
} = require("../util/config");
2020
const { validateAuth } = require("../util/login");
2121
const 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

Comments
 (0)