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

fix: ensure .fluence/aqua dir exists #52

Merged
merged 1 commit into from
Oct 13, 2022
Merged
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
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