Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #147 from ForestAdmin/fix/generate
Browse files Browse the repository at this point in the history
[*] Generate - Fixing port and authentication
  • Loading branch information
Vincent Molinié authored Jul 10, 2018
2 parents b8e89e8 + e682c25 commit f9e0d3a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [Unreleased]
### Fixed
- Generate - App port is set in .env file

## Release 1.10.0
### Changed
- MySQL & PostgreSQL - Detect enum type for model generation.
Expand Down
20 changes: 8 additions & 12 deletions lumber-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,15 @@ program
}

let project;
if (config.authToken) {
try {
project = await authenticator.createProject(config);
} catch (error) {
if (error.message === 'Unauthorized') {
logger.error('💀 Oops, you are unauthorized to connect to forest. 💀 Try the "lumber logout && lumber login" command.');
} else {
logger.error('💀 Oops, authentication operation aborted 💀 due to the following error: ', error);
}
process.exit(1);
try {
project = await authenticator.authenticateAndCreateProject(config);
} catch (error) {
if (error.message === 'Unauthorized') {
logger.error('💀 Oops, you are unauthorized to connect to forest. 💀 Try the "lumber logout && lumber login" command.');
} else {
logger.error('💀 Oops, authentication operation aborted 💀 due to the following error: ', error);
}
} else {
project = await authenticator.register(config);
process.exit(1);
}

const dumper = await new Dumper(project, config);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lumber-cli",
"version": "1.10.0",
"version": "1.10.1",
"description": "Generate the admin micro-service of your application",
"main": "lumber.js",
"scripts": {
Expand Down
15 changes: 12 additions & 3 deletions services/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Authenticator() {
});
};

this.register = (config) => {
this.registerAndCreateProject = (config) => {
let guest = { email: config.email };

return agent
Expand Down Expand Up @@ -116,8 +116,9 @@ function Authenticator() {
})
.catch((err) => {
if (err.status === 409) {
logger.error('💀 Oops, this email already exists. Please, run ' +
chalk.bold('$ lumber login') + ' before 💀');
// NOTICE: Account already exists
return this.login(config)
.then(() => this.createProject(config));
} else {
logger.error('💀 Ouch, cannot create your account 💀');
}
Expand All @@ -138,6 +139,14 @@ function Authenticator() {
return fs.writeFileSync(`${os.homedir()}/.lumberrc`, auth.token);
});
};

this.authenticateAndCreateProject = (config) => {
if (config.authToken) {
return this.createProject(config);
}

return this.registerAndCreateProject(config);
};
}

module.exports = new Authenticator();
3 changes: 2 additions & 1 deletion services/dumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ function Dumper(project, config) {
forestUrl: process.env.FOREST_URL,
ssl: config.ssl,
encrypt: config.ssl && config.dbDialect === 'mssql',
dbSchema: config.dbSchema
dbSchema: config.dbSchema,
port: config.appPort
};

fs.writeFileSync(`${path}/.env`, template(settings));
Expand Down
1 change: 1 addition & 0 deletions templates/app/env
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ FOREST_ENV_SECRET=<%= forestEnvSecret %>
<% if (!encrypt) {%>#<% } %>ENCRYPT_DATABASE=true
<% if (forestUrl) {%>FOREST_URL=<%= forestUrl %><% } %>
<% if (dbSchema) {%>DATABASE_SCHEMA=<%= dbSchema %><% } %>
<% if (port) {%>PORT=<%= port %><% } %>

0 comments on commit f9e0d3a

Please sign in to comment.