drapcode-utility 2.4.9 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -40,4 +40,8 @@ export declare const removeProjectFromFile: (project: Project) => void;
|
|
|
40
40
|
* @throws {ProjectError} If file operations fail
|
|
41
41
|
*/
|
|
42
42
|
export declare const clearProjectSubfolder: (projectId: string, subfolder: string) => void;
|
|
43
|
+
export declare const clearProjectFilesInSubfolder: (projectId: string, subfolder: string, files: {
|
|
44
|
+
uuid: string;
|
|
45
|
+
slug?: string;
|
|
46
|
+
}[]) => void;
|
|
43
47
|
export {};
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.clearProjectSubfolder = exports.removeProjectFromFile = exports.findProjectFromFile = exports.saveProjectToFile = void 0;
|
|
6
|
+
exports.clearProjectFilesInSubfolder = exports.clearProjectSubfolder = exports.removeProjectFromFile = exports.findProjectFromFile = exports.saveProjectToFile = void 0;
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const file_util_1 = require("./file-util");
|
|
@@ -146,7 +146,7 @@ const clearProjectSubfolder = (projectId, subfolder) => {
|
|
|
146
146
|
throw new ProjectError("Sub Folder is required");
|
|
147
147
|
}
|
|
148
148
|
try {
|
|
149
|
-
if ((0, file_util_1.verifyProjectSettingFolder)(projectId)) {
|
|
149
|
+
if (!(0, file_util_1.verifyProjectSettingFolder)(projectId)) {
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
152
152
|
const projectPath = path_1.default.join(filePath, `${PROJECT_PREFIX}${projectId}`, subfolder);
|
|
@@ -159,6 +159,59 @@ const clearProjectSubfolder = (projectId, subfolder) => {
|
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
161
|
exports.clearProjectSubfolder = clearProjectSubfolder;
|
|
162
|
+
const clearProjectFilesInSubfolder = (projectId, subfolder, files) => {
|
|
163
|
+
if (!projectId) {
|
|
164
|
+
throw new ProjectError("Project ID is required");
|
|
165
|
+
}
|
|
166
|
+
if (!subfolder) {
|
|
167
|
+
throw new ProjectError("Sub Folder is required");
|
|
168
|
+
}
|
|
169
|
+
if (!Array.isArray(files)) {
|
|
170
|
+
throw new ProjectError("Files must be an array");
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
if (!(0, file_util_1.verifyProjectSettingFolder)(projectId)) {
|
|
174
|
+
console.log("Project settings folder does not exist — skipping delete.");
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const projectPath = path_1.default.join(filePath, `${PROJECT_PREFIX}${projectId}`, subfolder);
|
|
178
|
+
const useSlug = subfolder === "pages";
|
|
179
|
+
deleteFilesInTheSubFolder(projectPath, files, useSlug);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
183
|
+
console.error("Failed to delete files:", message);
|
|
184
|
+
throw new ProjectError(`Failed to delete files: ${message}`);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
exports.clearProjectFilesInSubfolder = clearProjectFilesInSubfolder;
|
|
188
|
+
const deleteFilesInTheSubFolder = (folderPath, files, useSlug = false) => {
|
|
189
|
+
for (const file of files) {
|
|
190
|
+
let fileName;
|
|
191
|
+
if (useSlug) {
|
|
192
|
+
fileName = file.name ? `${file.name}.json`.toLowerCase() : undefined;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
fileName = file.uuid ? `${file.uuid}.json` : undefined;
|
|
196
|
+
}
|
|
197
|
+
if (!fileName) {
|
|
198
|
+
console.log("Invalid file, skipping:", file);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const filePathToDelete = path_1.default.join(folderPath, fileName);
|
|
202
|
+
if ((0, fs_1.existsSync)(filePathToDelete)) {
|
|
203
|
+
try {
|
|
204
|
+
(0, fs_1.unlinkSync)(filePathToDelete);
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
console.error("Failed to delete file:", filePathToDelete, err);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
console.log("File not found, skipping:", filePathToDelete);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
162
215
|
// Helper functions
|
|
163
216
|
const verifyProjectsFolder = () => {
|
|
164
217
|
const projectPath = path_1.default.join(filePath, PROJECTS_FOLDER);
|