Skip to content

Commit bb2af08

Browse files
committed
Fixing config file import error
1 parent 217d3d1 commit bb2af08

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

packages/common/core/base-provider.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
const path = require("path");
2-
const ncConfig = require(path.join(process.cwd(), ".nc.config"));
2+
const fs = require("fs");
33
const validProviders = require("./providers-list");
4+
const ncConfig = require(getConfigFilePath());
5+
6+
function getConfigFilePath() {
7+
const triables = process.cwd().split("\\").length;
8+
const dirs = process.cwd().split("\\");
9+
let configFilePath;
10+
11+
for (let i = 0; i < triables; i++) {
12+
configFilePath = path.join(dirs.join("\\"), ".nc.config.js");
13+
if (fs.existsSync(configFilePath)) {
14+
return configFilePath;
15+
}
16+
dirs.splice(-1, 1);
17+
configFilePath = null;
18+
}
19+
20+
if (!configFilePath) {
21+
throw new Error(
22+
"Provider config file not found. Please create a config file in project root."
23+
);
24+
}
25+
}
426

527
class Provider {
628
/**

packages/common/test/core/base-provider.test.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const providersList = require("../../core/providers-list");
2+
const { assert } = require("chai");
3+
4+
describe("providers list", function() {
5+
context("with array of provider names", function() {
6+
it("should have at least one provider", function() {
7+
assert(providersList.length !== 0);
8+
});
9+
it("should have string literals", function() {
10+
providersList.forEach(provider => assert.isString(provider));
11+
});
12+
});
13+
});

packages/common/test/providers.test.js renamed to packages/common/test/core/providers.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const chai = require("chai");
22
const assert = chai.assert;
3-
const providers = require("../core/providers");
3+
const providers = require("../../core/providers");
44

55
describe("Providers list", () => {
66
it("should check for providers", done => {

0 commit comments

Comments
 (0)