Skip to content

Commit

Permalink
Merge pull request #155 from thesemaphoreslim/main
Browse files Browse the repository at this point in the history
Fix for empty config.json
  • Loading branch information
MichaelTaylor3D authored Oct 26, 2024
2 parents db6a86e + 171e6dc commit 7909add
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
.dig
dist
dig.config.json
dig.config.json
.vs
83 changes: 45 additions & 38 deletions package-lock.json

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

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@dignetwork/datalayer-driver": "^0.1.29",
"@dignetwork/dig-sdk": "^0.0.1-alpha.158",
"archiver": "^7.0.1",
"async-mutex": "^0.5.0",
"axios": "^1.7.7",
"bip39": "^3.1.0",
"bottleneck": "^2.19.5",
Expand All @@ -41,7 +42,7 @@
"figures": "^6.1.0",
"fs-extra": "^11.2.0",
"ignore": "^5.3.2",
"inquirer": "^10.1.8",
"inquirer": "^10.2.2",
"lodash": "^4.17.21",
"merkletreejs": "^0.4.0",
"nanospinner": "^1.1.0",
Expand All @@ -50,30 +51,30 @@
"node-stun": "^0.1.2",
"progress-stream": "^2.0.0",
"proper-lockfile": "^4.1.2",
"superagent": "^10.1.0",
"redis": "^4.7.0",
"superagent": "^10.0.0",
"unzipper": "^0.12.3"
},
"devDependencies": {
"@types/archiver": "^6.0.2",
"@types/chai": "^4.3.17",
"@types/chai": "^4.3.20",
"@types/cli-progress": "^3.11.6",
"@types/crypto-js": "^4.2.2",
"@types/fs-extra": "^11.0.4",
"@types/inquirer": "^9.0.7",
"@types/lodash": "^4.17.7",
"@types/mocha": "^10.0.7",
"@types/lodash": "^4.17.10",
"@types/mocha": "^10.0.9",
"@types/nconf": "^0.10.7",
"@types/node": "^22.1.0",
"@types/node": "^22.7.5",
"@types/progress-stream": "^2.0.5",
"@types/proper-lockfile": "^4.1.4",
"@types/superagent": "^8.1.8",
"@types/superagent": "^8.1.9",
"@types/unzipper": "^0.10.10",
"chai": "^5.1.1",
"copyfiles": "^2.4.1",
"mocha": "^10.7.0",
"mocha": "^10.7.3",
"standard-version": "^9.5.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
"typescript": "^5.6.3"
}
}
24 changes: 15 additions & 9 deletions src/utils/NconfManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import nconf from "nconf";
import fs from "fs-extra";
import { Mutex } from 'async-mutex';
import path from "path";
import { USER_DIR_PATH } from "./config";
import { Environment } from "./Environment";

const CONF_FOLDER_PATH = Environment.DIG_FOLDER_PATH || USER_DIR_PATH;
const fileMutex = new Mutex();

export class NconfManager {
private configFilePath: string;
Expand All @@ -14,18 +16,22 @@ export class NconfManager {
this.initializeConfig();
}

private async initializeConfig(): Promise<void> {
private async initializeConfig(): Promise<void> {
const release = await fileMutex.acquire();
const directory = path.dirname(this.configFilePath);
if (!(await fs.pathExists(directory))) {
await fs.mkdirp(directory);
console.log("Directory created:", directory);
}
try {
if (!(await fs.pathExists(directory))) {
await fs.mkdirp(directory);
console.log("Directory created:", directory);
}

if (!(await fs.pathExists(this.configFilePath))) {
await fs.writeFile(this.configFilePath, "{}");
console.log("Configuration file created:", this.configFilePath);
if (!(await fs.pathExists(this.configFilePath))) {
await fs.writeFile(this.configFilePath, "{}");
console.log("Configuration file created:", this.configFilePath);
}
} finally {
release();
}

nconf.file({ file: this.configFilePath });
}

Expand Down

0 comments on commit 7909add

Please sign in to comment.