Skip to content

Commit

Permalink
feat(cli): support dotenv at development mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed May 24, 2021
1 parent dd63b3b commit 5a77568
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 5 deletions.
3 changes: 3 additions & 0 deletions example/hoth-quickstart/src/config/developmemt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export = {
development: 1,
};
3 changes: 3 additions & 0 deletions example/hoth-quickstart/src/config/development-foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export = {
foo: 1,
};
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"watch": ["*.ts"],
"ignore": ["*.test.ts", "node_modules/*", "*.d.ts", "templates/*"],
"ignore": ["*.test.ts", "node_modules/*", "*.d.ts", "templates/*", "__tests__/*"],
"ext": "ts,js",
"exec": "yarn run build && NODE_ENV=development yarn run hoth start --app-dir='example/hoth-quickstart/dist' --app-name='quickstart'",
"legacyWatch": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/app-autoload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ async function load(appConfig: AppConfig, childInstance: FastifyInstance) {
...appConfig,
});

console.log(config);

const configProxy = {
get(property: string | string[]) {
const props = Array.isArray(property)
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@hoth/utils": "^1.1.2",
"chalk": "^4.1.0",
"commist": "^1.1.0",
"dotenv": "^10.0.0",
"fastify-warmup": "0.1.1",
"generify": "^4.2.0",
"help-me": "^2.0.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ async function runFastify(opts: Args) {

let address;
if (opts.address) {
// eslint-disable-next-line
address = await fastifyInstance.listen(opts.port, opts.address);
}
else if (opts.socket) {
Expand All @@ -145,6 +144,10 @@ async function runFastify(opts: Args) {


async function start(args: string[]) {
if (process.env.NODE_ENV === 'development') {
require('dotenv').config();
}

const opts = parseArgs(args);

if (opts.help) {
Expand Down
4 changes: 2 additions & 2 deletions packages/view/src/__tests__/swig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('reply.render with swig engine', () => {
engine: {
swig: Swig,
},
rootPath: __dirname,
templatesDir: __dirname,
});

fastify.get('/', (req: FastifyRequest, reply: FastifyReply) => {
Expand All @@ -24,7 +24,7 @@ describe('reply.render with swig engine', () => {
});

expect(response.statusCode).toBe(200);
expect(response.headers['content-type']).toBe('text/html; charset=utf-8');
expect(response.body).toBe('<h1>fastify</h1>\n<p>text</p>');
expect(response.headers['content-type']).toBe('text/html; charset=utf-8');
});
});
5 changes: 4 additions & 1 deletion packages/view/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"compilerOptions": {
"rootDir": "src",
"outDir": "dist"
}
},
"references": [
{ "path": "../decorators" }
]
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,11 @@ dot-prop@^6.0.1:
dependencies:
is-obj "^2.0.0"

dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==

duplexer3@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
Expand Down

0 comments on commit 5a77568

Please sign in to comment.