Skip to content

Commit

Permalink
fix config
Browse files Browse the repository at this point in the history
  • Loading branch information
timbrinded committed Nov 6, 2023
1 parent fc1e674 commit 34914bb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
6 changes: 5 additions & 1 deletion packages/cli/src/internal/cmdFunctions/initialisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,8 @@ export function createConfig(options: {
};
}

const textBlob = `// TEST TEST TEST\n`;
const textBlob = `// This Moonwall Config file should be modified to include all types
// of environments you wish to test against.
// For more information on how to configure Moonwall, please visit:
// https://moonsong-labs.github.io/moonwall/config/intro.html\n`;
47 changes: 23 additions & 24 deletions packages/cli/src/lib/configReader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "@moonbeam-network/api-augment";
import { MoonwallConfig } from "@moonwall/types";
import fs, { readFile } from "fs/promises";
import { readFile } from "fs/promises";
import { readFileSync } from "fs";
import JSONC from "jsonc-parser";
import path, { extname } from "path";
Expand All @@ -26,22 +26,27 @@ async function parseConfig(filePath: string) {

return result;
}
function parseConfigSync(filePath: string) {
let result: any;

const file = readFileSync(filePath, "utf8");

export async function loadConfig(path: string): Promise<MoonwallConfig> {
if (
!(await fs
.access(path)
.then(() => true)
.catch(() => false))
) {
throw new Error(`Moonwall Config file ${path} cannot be found`);
switch (extname(filePath)) {
case ".json":
result = JSON.parse(file);
break;
case ".config":
result = JSONC.parse(file);
break;
default:
result = undefined;
break;
}

const file = await fs.readFile(path, { encoding: "utf-8" });
const json: MoonwallConfig = JSON.parse(file);
return json;
return result;
}


export async function importConfig(configPath: string): Promise<MoonwallConfig> {
return await import(configPath);
}
Expand Down Expand Up @@ -70,10 +75,9 @@ export async function cacheConfig() {
const configPath = process.env.MOON_CONFIG_PATH!;
const filePath = path.isAbsolute(configPath) ? configPath : path.join(process.cwd(), configPath);
try {
const file = await readFile(filePath, "utf8");
const json = JSON.parse(file);
const replacedJson = replaceEnvVars(json);
cachedConfig = replacedJson as MoonwallConfig;
const config = parseConfigSync(filePath);
const replacedConfig = replaceEnvVars(config);
cachedConfig = replacedConfig as MoonwallConfig;
} catch (e) {
console.error(e);
throw new Error(`Error import config at ${filePath}`);
Expand All @@ -89,11 +93,9 @@ export function importJsonConfig(): MoonwallConfig {
const filePath = path.isAbsolute(configPath) ? configPath : path.join(process.cwd(), configPath);

try {
const file = readFileSync(filePath, "utf8");
const json = JSON.parse(file);
const replacedJson = replaceEnvVars(json);

cachedConfig = replacedJson as MoonwallConfig;
const config = parseConfigSync(filePath);
const replacedConfig = replaceEnvVars(config);
cachedConfig = replacedConfig as MoonwallConfig;
return cachedConfig;
} catch (e) {
console.error(e);
Expand All @@ -110,9 +112,6 @@ export async function importAsyncConfig(): Promise<MoonwallConfig> {
const filePath = path.isAbsolute(configPath) ? configPath : path.join(process.cwd(), configPath);

try {
// const file = await readFile(filePath, "utf8");
// const json = JSON.parse(file);

const config = await parseConfig(filePath);
const replacedConfig = replaceEnvVars(config);

Expand Down
23 changes: 23 additions & 0 deletions test/moonwall.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This Moonwall Config file should be modified to include all types
// of environments you wish to test against.

// For more information on how to configure Moonwall, please visit:
// https://moonsong-labs.github.io/moonwall/config/intro.html
{
"label": "moonwall_config",
"defaultTestTimeout": 30000,
"environments": [
{
"name": "default_env",
"testFileDir": [
"tests/"
],
"foundation": {
"type": "dev",
"launchSpec": [{
"binPath": "./tmp/moonbeam"
}]
}
}
]
}
File renamed without changes.

0 comments on commit 34914bb

Please sign in to comment.