Skip to content

Commit

Permalink
feat(run): use --input flag to search for project root dir path [fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsartem authored Jan 19, 2023
1 parent 9193992 commit b3c7897
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
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

0 comments on commit b3c7897

Please sign in to comment.