Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 8b65689b authored by VIAUD Nathan's avatar VIAUD Nathan
Browse files

fix: saving returns errors

parent 9f446bc3
Branches
Tags
1 merge request!117Resolve "saving without the icons folder returns an error"
Pipeline #948899 passed
...@@ -317,12 +317,15 @@ const getAllAssets = function (workdir) { ...@@ -317,12 +317,15 @@ const getAllAssets = function (workdir) {
if (stat.isFile()) assetPaths.push(itemPath); if (stat.isFile()) assetPaths.push(itemPath);
} }
const iconItems = fs.readdirSync(iconsPath); // return if icons folder does not exist
for (const item of iconItems) { if (fs.existsSync(iconsPath)) {
const itemPath = path.join(iconsPath, item); const iconItems = fs.readdirSync(iconsPath);
const stat = fs.statSync(itemPath); for (const item of iconItems) {
const itemPath = path.join(iconsPath, item);
if (stat.isFile()) assetPaths.push(itemPath); const stat = fs.statSync(itemPath);
if (stat.isFile()) assetPaths.push(itemPath);
}
} }
} catch (e) { } catch (e) {
console.error('Error reading assets directory', e); console.error('Error reading assets directory', e);
...@@ -340,6 +343,8 @@ const getAllAssets = function (workdir) { ...@@ -340,6 +343,8 @@ const getAllAssets = function (workdir) {
}; };
const getUsedAssets = function (workdir) { const getUsedAssets = function (workdir) {
// if(!fs.existsSync(path.join(workdir, 'project.json'))) return [];
const projectJSON = fs.readFileSync(path.join(workdir, 'project.json'), 'utf8'); const projectJSON = fs.readFileSync(path.join(workdir, 'project.json'), 'utf8');
const regex = /"assets[\\/\\\\]([^"]+)"/g; const regex = /"assets[\\/\\\\]([^"]+)"/g;
const matches = projectJSON.match(regex); const matches = projectJSON.match(regex);
...@@ -357,7 +362,11 @@ const getUsedAssets = function (workdir) { ...@@ -357,7 +362,11 @@ const getUsedAssets = function (workdir) {
}); });
}; };
// TODO: Add a parameter to see if exporting or not to get data from content.json instead of project.json
const getUnusedAssets = function (workdir) { const getUnusedAssets = function (workdir) {
//? On first save this function is called before project.json is created
if(!fs.existsSync(path.join(workdir, 'project.json'))) return [];
const allAssets = getAllAssets(workdir); const allAssets = getAllAssets(workdir);
const usedAssets = getUsedAssets(workdir); const usedAssets = getUsedAssets(workdir);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment