Skip to content
This repository has been archived by the owner on Sep 25, 2023. It is now read-only.

Commit

Permalink
feat(logs): added colored logs
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Aug 17, 2021
1 parent 1ddf9a8 commit ff2eba7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
"supertest": "^6.1.3",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"dependencies": {
"colors": "^1.4.0"
}
}
14 changes: 2 additions & 12 deletions packages/express-krabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@ import { getTenantConfig } from '../utils/config';
import { Config } from '../utils/config/config';
import findTenant from '../utils/tenants/findTenant';
import resolveRoutes from '../utils/routes/resolve';
import { currentEnv, safeEnv } from '../utils/env';
import { currentEnv, environmentWarningMessage } from '../utils/env';

if (!currentEnv) {
const warningMessage = `
\u{26A0}\u{FE0F} (' Warning ')
The ('NODE_ENV') environment variable is ('undefined').
Krabs will run in (${safeEnv}) mode, meaning it will only serve
tenants domains set as (${safeEnv}) domains.
`
.split('\n')
.map((line) => line.trimLeft())
.join('\n');

console.warn(warningMessage);
console.warn(environmentWarningMessage);
}

async function krabs(
Expand Down
14 changes: 2 additions & 12 deletions packages/fastify-krabs/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import type { FastifyRequest, FastifyReply } from 'fastify';
import { currentEnv, safeEnv } from '../utils/env';
import { getTenantConfig } from '../utils/config';
import { Config } from '../utils/config/config';
import findTenant from '../utils/tenants/findTenant';
import resolveRoutes from '../utils/routes/resolve';
import { currentEnv, environmentWarningMessage } from '../utils/env';

if (!currentEnv) {
const warningMessage = `
\u{26A0}\u{FE0F} (' Warning ')
The ('NODE_ENV') environment variable is ('undefined').
Krabs will run in (${safeEnv}) mode, meaning it will only serve
tenants domains set as (${safeEnv}) domains.
`
.split('\n')
.map((line) => line.trimLeft())
.join('\n');

console.warn(warningMessage);
console.warn(environmentWarningMessage);
}

export default async function krabs(
Expand Down
9 changes: 9 additions & 0 deletions packages/utils/env/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
import { bold } from 'colors';

export const currentEnv = process.env?.NODE_ENV;
export const safeEnv = currentEnv ?? 'development';

export const environmentWarningMessage = [
`\n\u{26A0}\u{FE0F} ${bold('Warning')}\n`,
`The ${bold('NODE_ENV')} environment variable is ${bold('undefined')}.`,
`Krabs will run in ${safeEnv.bold} mode, meaning`,
`it will only serve tenants domains set as ${safeEnv.bold} domains.\n`,
].join('\n').yellow;
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4424,7 +4424,7 @@ colorette@^1.2.2:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.2.tgz#cbcc79d5e99caea2dbf10eb3a26fd8b3e6acfa94"
integrity sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==

colors@^1.1.2:
colors@^1.1.2, colors@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.4.0.tgz#c50491479d4c1bdaed2c9ced32cf7c7dc2360f78"
integrity sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==
Expand Down

0 comments on commit ff2eba7

Please sign in to comment.