Skip to content

Commit

Permalink
refactor(core): moved dotenv init to core constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
exreplay committed Jun 16, 2019
1 parent 973e3a5 commit b4305f6
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions packages/core/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import dotenv from 'dotenv';
import { getAverjsConfig } from '@averjs/config';
import ora from 'ora';

if (!process.env.AVER_NO_INIT) {
if (fs.existsSync(path.resolve(process.env.PROJECT_PATH, '../.env'))) {
const envConfig = dotenv.parse(fs.readFileSync(path.resolve(process.env.PROJECT_PATH, '../.env')));
for (let k in envConfig) {
process.env[k] = envConfig[k];
}
if (dotenv.error) {
throw dotenv.error;
export default class Core {
constructor() {
if (fs.existsSync(path.resolve(process.env.PROJECT_PATH, '../.env'))) {
const envConfig = dotenv.parse(fs.readFileSync(path.resolve(process.env.PROJECT_PATH, '../.env')));
for (let k in envConfig) {
process.env[k] = envConfig[k];
}
if (dotenv.error) {
throw dotenv.error;
}
} else {
console.warn("In order to use dotenv, please create a '.env' file in your project root.");
}
} else {
console.warn("In order to use dotenv, please create a '.env' file in your project root.");
}
}

export default class Core {

run(hooks = {}) {
this.hooks = new Hooks();
this.globalConfig = getAverjsConfig();
Expand Down

0 comments on commit b4305f6

Please sign in to comment.