Skip to content

Commit

Permalink
Remove dotenv support
Browse files Browse the repository at this point in the history
Signed-off-by: Abhinav Pandey <[email protected]>
  • Loading branch information
Sweetdevil144 committed Jul 13, 2024
1 parent 581bee0 commit ce8c11a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"homepage": "https://github.com/Sweetdevil144/dotgenv#readme",
"devDependencies": {
"@types/chalk": "^2.2.0",
"@types/dotenv": "^8.2.0",
"@types/inquirer": "^9.0.6",
"@types/jest": "^29.5.6",
"@types/node": "^20.8.3",
Expand All @@ -52,7 +51,6 @@
},
"dependencies": {
"chalk": "^5.3.0",
"dotenv": "^16.4.5",
"inquirer": "^9.2.11",
"yargs": "^17.7.2"
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { readEnvFile, writeEnvFile } from './envManager.js';
import { readEnvFile, writeEnvFile, parseEnvFile } from './envManager.js';
import fs from 'fs';
import path from 'path';
import dotenv from 'dotenv';

export function setEnv(key: string, value: string) {
const envVars = readEnvFile();
Expand Down Expand Up @@ -36,7 +35,7 @@ export function importEnv(key: string) {
let localEnvVars: { [key: string]: string } = {};

if (fs.existsSync(localEnvPath)) {
localEnvVars = dotenv.parse(fs.readFileSync(localEnvPath));
localEnvVars = parseEnvFile(localEnvPath);
}

if (globalEnvVars[key]) {
Expand Down
18 changes: 16 additions & 2 deletions src/commands/envManager.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import fs from 'fs';
import path from 'path';
import dotenv from 'dotenv';

const GLOBAL_ENV_PATH = path.join(
process.env.HOME || process.env.USERPROFILE || '.',
'.global.env',
);

export function parseEnvFile(filePath: string): { [key: string]: string } {
let envValue: string = '';
const env: { [key: string]: string } = {};
const fileContent = fs.readFileSync(filePath, 'utf8');
fileContent.split('\n').forEach((line) => {
let [key, ...value] = line.split('=');
key = key.trim();
envValue = value.join('=').trim();
if (key != null && envValue != null) {
env[key]= envValue;
}
});
return env;
}

export function readEnvFile(): { [key: string]: string } {
try {
if (!fs.existsSync(GLOBAL_ENV_PATH)) {
return {};
}
return dotenv.parse(fs.readFileSync(GLOBAL_ENV_PATH));
return parseEnvFile(GLOBAL_ENV_PATH);
} catch (error) {
console.error('Error reading global env file: ', error);
return {};
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/* Modules */
"module": "ES6", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
Expand Down Expand Up @@ -55,7 +55,7 @@
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
Expand Down

0 comments on commit ce8c11a

Please sign in to comment.