Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(run): use --input flag to search for project root dir path [fixes DXJ-232] #113

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { access, readFile, unlink, writeFile } from "node:fs/promises";
import { resolve } from "node:path";
import { dirname, resolve } from "node:path";

import { AvmLoglevel, FluencePeer, KeyPair } from "@fluencelabs/fluence";
import { callFunctionImpl } from "@fluencelabs/fluence/dist/internal/compilerSupport/v3impl/callFunction";
Expand Down Expand Up @@ -64,6 +64,8 @@ import { getRandomRelayAddr } from "../lib/multiaddr";
import {
ensureFluenceTmpAppServiceJsonPath,
projectRootDirPromise,
recursivelyFindProjectRootDir,
setProjectRootDir,
} from "../lib/paths";
import { input, list } from "../lib/prompt";

Expand Down Expand Up @@ -156,8 +158,21 @@ export default class Run extends BaseCommand<typeof Run> {
...KEY_PAIR_FLAG,
};
async run(): Promise<void> {
const parseResult = await this.parse(Run);
const inputFlag = parseResult.flags[INPUT_FLAG_NAME];

if (typeof inputFlag === "string") {
const resolvedInputDirName = resolve(dirname(inputFlag));

const projectRootDir = await recursivelyFindProjectRootDir(
resolvedInputDirName
);

setProjectRootDir(projectRootDir);
}

const { commandObj, flags, isInteractive, maybeFluenceConfig } =
await initCli(this, await this.parse(Run));
await initCli(this, parseResult);

const logLevelAVM: AvmLoglevel | undefined = await resolveAVMLogLevel({
commandObj: this,
Expand Down
13 changes: 10 additions & 3 deletions src/lib/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,13 @@ export const ensureUserFluenceCargoDir = async (
// cwd is cached in order for paths to be correct even if cwd changes during the
// execution (e.g. Marince CLI has to change cwd in order to work correctly)
const initialCwd = process.cwd();
export let projectRootDirPromise = (async (): Promise<string> => {

export const recursivelyFindProjectRootDir = async (
initialPath: string
): Promise<string> => {
const fluenceConfigPath = await recursivelyFindFile(
FLUENCE_CONFIG_FILE_NAME,
initialCwd
initialPath
);

if (fluenceConfigPath === null) {
Expand All @@ -140,7 +143,11 @@ export let projectRootDirPromise = (async (): Promise<string> => {

const newProjectRootDir = path.dirname(fluenceConfigPath);
return newProjectRootDir;
})().catch((error): never => {
};

export let projectRootDirPromise = recursivelyFindProjectRootDir(
initialCwd
).catch((error): never => {
throw error;
});

Expand Down