Skip to content
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
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
"@vscode/codicons": "^0.0.36",
"adm-zip": "^0.5.12",
"cross-spawn": "^7.0.3",
"fast-glob": "^3.3.3",
"i18next": "^23.11.4",
"lodash.isequal": "^4.5.0",
"module-alias": "^2.2.3",
Expand Down
17 changes: 12 additions & 5 deletions src/controllers/utilities/resources.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ export const getLocalResources = async (
const fileName = path.basename(resourcesPath);
try {
const fileBuffer = fs.readFileSync(resourcesPath);
const mappedResources = { [fileName]: fileBuffer };
const mappedResources = { [fileName]: new Uint8Array(fileBuffer) };
return { data: mappedResources };
} catch (error) {
return { error: error as Error };
}
}
const mappedResources = stats.isFile()
? await mapFilesToContentInBytes(resourcesPath, [resourcesPath])
: await mapFilesToContentInBytes(resourcesPath, await readDirectoryRecursive(resourcesPath));

return { data: mappedResources };
try {
const allFiles = await readDirectoryRecursive(resourcesPath);
const mappedBuffers = await mapFilesToContentInBytes(resourcesPath, allFiles);
const mappedResources: Record<string, Uint8Array> = {};
for (const [key, buffer] of Object.entries(mappedBuffers)) {
mappedResources[key] = new Uint8Array(buffer);
}
return { data: mappedResources };
} catch (error) {
return { error: error as Error };
}
};
41 changes: 7 additions & 34 deletions src/utilities/fileSystem.utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import spawn from "cross-spawn";
import fg from "fast-glob";
import * as fs from "fs";
import * as fsPromises from "fs/promises";
import * as path from "path";
import * as winattr from "winattr";

import { translate } from "@i18n";

Expand Down Expand Up @@ -86,41 +86,14 @@ export const listFilesInDirectory = async (dirPath: string, includeDirectories:
return files;
};

const isUnixHiddenPath = function (path: string) {
return /(^|\/)\.[^\/\.]/g.test(path);
};

const isWinHiddenPath = function (path: string) {
const pathAttrs = winattr.getSync(path);
return pathAttrs.hidden;
};

export const readDirectoryRecursive = async (directoryPath: string): Promise<string[]> => {
let files: string[] = [];
const isWin = process.platform === "win32";

const readDirSync = (dirPath: string) => {
fs.readdirSync(dirPath).forEach(async (file) => {
const fullPath = path.join(dirPath, file);

if (isWin && isWinHiddenPath(fullPath)) {
return;
}

if (!isWin && isUnixHiddenPath(fullPath)) {
return;
}

const stats = fs.statSync(fullPath);
if (stats.isDirectory()) {
files = files.concat(await readDirectoryRecursive(fullPath));
} else if (stats.isFile()) {
files.push(fullPath);
}
});
};
const files = await fg("**/*", {
cwd: directoryPath,
absolute: true,
dot: false,
onlyFiles: true,
});

readDirSync(directoryPath);
return files;
};

Expand Down
36 changes: 7 additions & 29 deletions src/vscommands/applyManifest.vscommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const applyManifest = async () => {
return;
}

const { error: createError } = await ProjectsService.create({
const { data: projectId, error: createError } = await ProjectsService.create({
name: projectName,
organizationId,
});
Expand Down Expand Up @@ -78,34 +78,13 @@ export const applyManifest = async () => {
}
const manifestDirectory = getDirectoryOfFile(filePath);

if (!manifestResponse?.projectIds.length) {
LoggerService.error(
namespaces.applyManifest,
translate().t("errors.applyManifestNoProjectsLog", {
request: "applyManifest",
})
);
return;
}

const { logs, projectIds } = manifestResponse!;
const { logs } = manifestResponse!;
const currentProjectPaths = (await commands.executeCommand(
vsCommands.getContext,
"projectsPaths"
)) as unknown as string;

let vscodeProjectsPaths = JSON.parse(currentProjectPaths);
if (!projectIds.length) {
commands.executeCommand(vsCommands.showErrorMessage, translate().t("manifest.ProjectCreationFailed"));
LoggerService.error(
namespaces.applyManifest,
translate().t("manifest.ProjectCreationFailedLog", {
request: "applyManifest",
error: (createError as Error).message,
})
);
return;
}

if (Object.keys(vscodeProjectsPaths || {}).length) {
let projectLocallyExists;
Expand All @@ -122,23 +101,22 @@ export const applyManifest = async () => {
vsCommands.showErrorMessage,
namespaces.applyManifest,
translate().t("projects.projectLocallyExistsFilesNotUpdated", {
projectId: projectIds[0],
projectId,
directory: manifestDirectory,
})
);

LoggerService.error(
namespaces.applyManifest,
translate().t("projects.projectLocallyExistsFilesNotUpdatedLog", {
projectId: projectIds[0],
projectId,
directory: manifestDirectory,
})
);
return;
}
}
const projectId = projectIds[0];
vscodeProjectsPaths[projectId] = manifestDirectory;
vscodeProjectsPaths[projectId!] = manifestDirectory;
await commands.executeCommand(vsCommands.setContext, "projectsPaths", JSON.stringify(vscodeProjectsPaths));

const organizationName =
Expand All @@ -149,7 +127,7 @@ export const applyManifest = async () => {
commands.executeCommand(vsCommands.showInfoMessage, translate().t("manifest.appliedSuccessfully"));
setTimeout(() => commands.executeCommand(vsCommands.refreshSidebar), 2500);

const { data: resources, error: resourcesError } = await getLocalResources(manifestDirectory, projectId);
const { data: resources, error: resourcesError } = await getLocalResources(manifestDirectory, projectId!);

if (resourcesError || !resources) {
LoggerService.error(
Expand All @@ -162,7 +140,7 @@ export const applyManifest = async () => {
const filteredResources = { ...resources };
delete filteredResources["autokitteh.yaml"];

const { error: setResourcesError } = await ProjectsService.setResources(projectId, filteredResources);
const { error: setResourcesError } = await ProjectsService.setResources(projectId!, filteredResources);

if (setResourcesError) {
LoggerService.error(
Expand Down
Loading