Skip to content

Commit

Permalink
fix: dont dynamically import package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed May 20, 2022
1 parent 11fcf52 commit 6e8f823
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 51 deletions.
14 changes: 1 addition & 13 deletions src/config/config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,17 @@ const fs = require('fs');
const os = require('os');
const path = require('path');
const logger = require('./logger.cjs').logger;
const packageJson = require('../../package.json');

const homeDir = os.homedir();
const defaultConfig = require('../utils/defaultConfig.json');

const getDataModelVersion = () => {
const packageJson = fileLoader('package.json');
const version = packageJson.version;
const majorVersion = version.split('.')[0];
return `v${majorVersion}`;
};

const fileLoader = _.memoize((filepath) => {
logger.debug(`Reading file at ${filepath}`);

const file = path.resolve(filepath);

try {
return yaml.load(fs.readFileSync(file, 'utf8'));
} catch (e) {
logger.error(`File not found at ${file}`, e);
}
});

const persistanceFolder = `${homeDir}/.chia/climate-warehouse/${getDataModelVersion()}`;

// Adding this duplicate function here because im having trouble
Expand Down
19 changes: 1 addition & 18 deletions src/config/logger.cjs
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
const _ = require('lodash');
const winston = require('winston');
const { format, transports, createLogger } = winston;
const yaml = require('js-yaml');
const DailyRotateFile = require('winston-daily-rotate-file');
const path = require('path');

const fs = require('fs');
const os = require('os');
const homeDir = os.homedir();

const fileLoader = _.memoize((filepath) => {
console.log(`Reading file at ${filepath}`);

const file = path.resolve(filepath);

try {
return yaml.load(fs.readFileSync(file, 'utf8'));
} catch (e) {
console.log(`File not found at ${file}`, e);
}
});
const packageJson = require('../../package.json');

const getDataModelVersion = () => {
const packageJson = fileLoader('package.json');
const version = packageJson.version;
const majorVersion = version.split('.')[0];
return `v${majorVersion}`;
};



const logDir = `${homeDir}/.chia/climate-warehouse/${getDataModelVersion()}/logs`;

if (!fs.existsSync(logDir)) {
Expand Down
18 changes: 0 additions & 18 deletions src/utils/file-loader.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from 'lodash';

import { isPluralized } from './string-utils.js';
import { formatModelAssociationName } from './model-utils.js';
import { fileLoader } from './file-loader';
import packageJson from '../../package.json';

export const paginationParams = (page, limit) => {
if (page === undefined || limit === undefined) {
Expand Down Expand Up @@ -78,7 +78,6 @@ export const columnsToInclude = (userColumns, foreignKeys) => {
};

export const getDataModelVersion = () => {
const packageJson = fileLoader('package.json');
const version = packageJson.version;
const majorVersion = version.split('.')[0];
return `v${majorVersion}`;
Expand Down

0 comments on commit 6e8f823

Please sign in to comment.