Skip to content

Commit

Permalink
fix: ensure .fluence/aqua dir exists (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamsartem authored Oct 13, 2022
1 parent 2261f3f commit dad22a6
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/lib/helpers/aquaImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ import { installAllNPMDependenciesFromFluenceConfig } from "../../commands/depen
import { ajv } from "../ajv";
import type { FluenceConfig } from "../configs/project/fluence";
import {
AQUA_DIR_NAME,
CommandObj,
DOT_BIN_DIR_NAME,
FLUENCE_DIR_NAME,
FS_OPTIONS,
NODE_MODULES_DIR_NAME,
} from "../const";
import {
ensureFluenceAquaDir,
ensureUserFluenceNpmDir,
ensureVSCodeSettingsJsonPath,
} from "../paths";
Expand All @@ -41,13 +40,10 @@ type GetAquaImportsArg = {
fluenceConfig: FluenceConfig | null;
};

export function ensureAquaImports(): string[];
export function ensureAquaImports(args: GetAquaImportsArg): Promise<string[]>;

export function ensureAquaImports(
export async function ensureAquaImports(
args?: GetAquaImportsArg
): string[] | Promise<string[]> {
const defaultImports = [path.join(FLUENCE_DIR_NAME, AQUA_DIR_NAME)];
): Promise<string[]> {
const defaultImports = [await ensureFluenceAquaDir()];

if (args === undefined) {
return defaultImports;
Expand Down Expand Up @@ -94,10 +90,10 @@ const settingsJsonSchema: JSONSchemaType<SettingsJson> = {

const validateSettingsJson = ajv.compile(settingsJsonSchema);

const initSettingsConfig = (
const initSettingsConfig = async (
aquaImports: string[] | undefined
): SettingsJson => ({
[AQUA_SETTINGS_IMPORTS]: aquaImports ?? ensureAquaImports(),
): Promise<SettingsJson> => ({
[AQUA_SETTINGS_IMPORTS]: aquaImports ?? (await ensureAquaImports()),
});

type EnsureRecommendedSettings = {
Expand All @@ -121,7 +117,7 @@ export const ensureVSCodeSettingsJSON = async ({
if (generateSettingsJson) {
await fsPromises.writeFile(
settingsJsonPath,
JSON.stringify(initSettingsConfig(aquaImports), null, 2) + "\n",
JSON.stringify(await initSettingsConfig(aquaImports), null, 2) + "\n",
FS_OPTIONS
);
}
Expand All @@ -138,7 +134,7 @@ export const ensureVSCodeSettingsJSON = async ({
}

if (validateSettingsJson(parsedFileContent)) {
const newAquaImports = [...(aquaImports ?? ensureAquaImports())];
const newAquaImports = [...(aquaImports ?? (await ensureAquaImports()))];
const userFluenceNpmDir = await ensureUserFluenceNpmDir(commandObj);

const newAquaImportPathStartsFromUserFluenceNpmDir = new Set(
Expand Down

0 comments on commit dad22a6

Please sign in to comment.