Skip to content

Commit

Permalink
❌ Remove dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashu11-A committed Jul 11, 2024
1 parent 85d73c0 commit 78debbe
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 20 deletions.
12 changes: 0 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
"cloudflare": "^3.4.0",
"country-code-to-flag-emoji": "^1.3.3",
"crypto-js": "^4.2.0",
"dotenv": "^16.4.5",
"enmap": "^6.0.2",
"enquirer": "^2.4.1",
"glob": "^10.4.3",
Expand Down
11 changes: 5 additions & 6 deletions src/class/crypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { passwordStrength } from 'check-password-strength'
import { watch } from 'chokidar'
import { randomBytes } from 'crypto'
import CryptoJS from 'crypto-js'
import 'dotenv/config'
import { readFile, rm, writeFile } from 'fs/promises'
import forge from 'node-forge'
import { join } from 'path'
Expand All @@ -19,7 +18,7 @@ export const credentials = new Map<string, string | object | boolean | number>()

export class Crypt {
async checker () {
if (!(await exists(join(rootPath, '..', '.env'))) && process.env?.token === undefined) await this.create()
if (!(await exists(join(rootPath, '..', '.env'))) && await this.getToken() === undefined) await this.create()
if (!(await exists(join(rootPath, '..', 'privateKey.pem'))) || !(await exists(join(rootPath, '..', 'publicKey.pem')))) await this.genKeys()

for (const path of ['.key', '.hash']) {
Expand Down Expand Up @@ -102,8 +101,8 @@ export class Crypt {
}
}

getToken (): string | undefined {
let token = process.env.token
async getToken (): Promise<string | undefined> {
let token = (await readFile(join(rootPath, '..', '.env'), { encoding: 'utf-8' })).split('=')[1]

if (token === undefined) token = credentials.get('token') as string

Expand All @@ -129,7 +128,7 @@ export class Crypt {
}

async read (ephemeral?: boolean): Promise<DataCrypted | undefined> {
const token = this.getToken()
const token = await this.getToken()
if (token === undefined) return
const existKey = await exists(join(rootPath, '..', '.key'))
if (!existKey) return undefined
Expand Down Expand Up @@ -162,7 +161,7 @@ export class Crypt {
async write (value: Record<string, string> | string | object) {
if (!isJson(value)) throw new Error(i18('error.invalid', { element: '.key' }))

const token = this.getToken()
const token = await this.getToken()
if (token === undefined) return

const data = Object.assign(await this.read(true) ?? {}, value)
Expand Down
1 change: 0 additions & 1 deletion src/class/pages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { page, rootPath } from '@/index.js'
import { PageProps, PageTypes } from '@/types/page.js'
import chalk from 'chalk'
import 'dotenv/config'
import { glob } from 'glob'
import ora from 'ora'
import { join } from 'path'
Expand Down

0 comments on commit 78debbe

Please sign in to comment.