Skip to content

Commit efe3b80

Browse files
committed
fix: apply manifest should appload the whole directory recursively
1 parent 3b04084 commit efe3b80

File tree

3 files changed

+28
-41
lines changed

3 files changed

+28
-41
lines changed

src/controllers/utilities/resources.util.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@ export const getLocalResources = async (
2424
const fileName = path.basename(resourcesPath);
2525
try {
2626
const fileBuffer = fs.readFileSync(resourcesPath);
27-
const mappedResources = { [fileName]: fileBuffer };
27+
const mappedResources = { [fileName]: new Uint8Array(fileBuffer) };
2828
return { data: mappedResources };
2929
} catch (error) {
3030
return { error: error as Error };
3131
}
3232
}
33-
const mappedResources = stats.isFile()
34-
? await mapFilesToContentInBytes(resourcesPath, [resourcesPath])
35-
: await mapFilesToContentInBytes(resourcesPath, await readDirectoryRecursive(resourcesPath));
3633

37-
return { data: mappedResources };
34+
try {
35+
const allFiles = await readDirectoryRecursive(resourcesPath);
36+
const mappedBuffers = await mapFilesToContentInBytes(resourcesPath, allFiles);
37+
const mappedResources: Record<string, Uint8Array> = {};
38+
for (const [key, buffer] of Object.entries(mappedBuffers)) {
39+
mappedResources[key] = new Uint8Array(buffer);
40+
}
41+
return { data: mappedResources };
42+
} catch (error) {
43+
return { error: error as Error };
44+
}
3845
};

src/utilities/fileSystem.utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,30 @@ export const readDirectoryRecursive = async (directoryPath: string): Promise<str
9999
let files: string[] = [];
100100
const isWin = process.platform === "win32";
101101

102-
const readDirSync = (dirPath: string) => {
103-
fs.readdirSync(dirPath).forEach(async (file) => {
102+
const readDirRecursive = async (dirPath: string): Promise<void> => {
103+
const entries = fs.readdirSync(dirPath);
104+
105+
for (const file of entries) {
104106
const fullPath = path.join(dirPath, file);
105107

106108
if (isWin && isWinHiddenPath(fullPath)) {
107-
return;
109+
continue;
108110
}
109111

110112
if (!isWin && isUnixHiddenPath(fullPath)) {
111-
return;
113+
continue;
112114
}
113115

114116
const stats = fs.statSync(fullPath);
115117
if (stats.isDirectory()) {
116-
files = files.concat(await readDirectoryRecursive(fullPath));
118+
await readDirRecursive(fullPath);
117119
} else if (stats.isFile()) {
118120
files.push(fullPath);
119121
}
120-
});
122+
}
121123
};
122124

123-
readDirSync(directoryPath);
125+
await readDirRecursive(directoryPath);
124126
return files;
125127
};
126128

src/vscommands/applyManifest.vscommands.ts

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const applyManifest = async () => {
5050
return;
5151
}
5252

53-
const { error: createError } = await ProjectsService.create({
53+
const { data: projectId, error: createError } = await ProjectsService.create({
5454
name: projectName,
5555
organizationId,
5656
});
@@ -78,34 +78,13 @@ export const applyManifest = async () => {
7878
}
7979
const manifestDirectory = getDirectoryOfFile(filePath);
8080

81-
if (!manifestResponse?.projectIds.length) {
82-
LoggerService.error(
83-
namespaces.applyManifest,
84-
translate().t("errors.applyManifestNoProjectsLog", {
85-
request: "applyManifest",
86-
})
87-
);
88-
return;
89-
}
90-
91-
const { logs, projectIds } = manifestResponse!;
81+
const { logs } = manifestResponse!;
9282
const currentProjectPaths = (await commands.executeCommand(
9383
vsCommands.getContext,
9484
"projectsPaths"
9585
)) as unknown as string;
9686

9787
let vscodeProjectsPaths = JSON.parse(currentProjectPaths);
98-
if (!projectIds.length) {
99-
commands.executeCommand(vsCommands.showErrorMessage, translate().t("manifest.ProjectCreationFailed"));
100-
LoggerService.error(
101-
namespaces.applyManifest,
102-
translate().t("manifest.ProjectCreationFailedLog", {
103-
request: "applyManifest",
104-
error: (createError as Error).message,
105-
})
106-
);
107-
return;
108-
}
10988

11089
if (Object.keys(vscodeProjectsPaths || {}).length) {
11190
let projectLocallyExists;
@@ -122,23 +101,22 @@ export const applyManifest = async () => {
122101
vsCommands.showErrorMessage,
123102
namespaces.applyManifest,
124103
translate().t("projects.projectLocallyExistsFilesNotUpdated", {
125-
projectId: projectIds[0],
104+
projectId,
126105
directory: manifestDirectory,
127106
})
128107
);
129108

130109
LoggerService.error(
131110
namespaces.applyManifest,
132111
translate().t("projects.projectLocallyExistsFilesNotUpdatedLog", {
133-
projectId: projectIds[0],
112+
projectId,
134113
directory: manifestDirectory,
135114
})
136115
);
137116
return;
138117
}
139118
}
140-
const projectId = projectIds[0];
141-
vscodeProjectsPaths[projectId] = manifestDirectory;
119+
vscodeProjectsPaths[projectId!] = manifestDirectory;
142120
await commands.executeCommand(vsCommands.setContext, "projectsPaths", JSON.stringify(vscodeProjectsPaths));
143121

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

152-
const { data: resources, error: resourcesError } = await getLocalResources(manifestDirectory, projectId);
130+
const { data: resources, error: resourcesError } = await getLocalResources(manifestDirectory, projectId!);
153131

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

165-
const { error: setResourcesError } = await ProjectsService.setResources(projectId, filteredResources);
143+
const { error: setResourcesError } = await ProjectsService.setResources(projectId!, filteredResources);
166144

167145
if (setResourcesError) {
168146
LoggerService.error(

0 commit comments

Comments
 (0)