Mentions légales du service

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

Fix prune for windows

parent b3b639a6
No related branches found
No related tags found
1 merge request!83Resolve "Prune assets doesn't on windows because of path separators"
Pipeline #880700 passed
...@@ -164,21 +164,36 @@ const saveAsEpocProject = async function (project) { ...@@ -164,21 +164,36 @@ const saveAsEpocProject = async function (project) {
}; };
/** /**
* Zip the content of an ePoc project file from the project workdir * Zip files of an ePoc project
* @returns {string} * @param {string} workdir the path to the workdir
* @param {string} filepath the path to the .epoc project file
* @param {boolean} exporting if true, the project.json file will not be included
*/ */
const zipEpocProject = async function (workdir, filepath) { const zipFiles = async function(workdir, filepath, exporting) {
if (!filepath || !workdir) return null; // Do not use path.join here, admZIP normalize the entries path
const unusedAssets = getUnusedAssets(workdir).map(asset => 'assets/' + asset);
const unusedAssets = getUnusedAssets(workdir).map(asset => path.join('assets', asset)); const excluded = ['.DS_Store', '__MACOSX', '.git'];
excluded.push(...unusedAssets);
if(exporting) excluded.push('project.json');
const zip = new AdmZip(); const zip = new AdmZip();
zip.addLocalFolder(workdir, '', (entry) => { zip.addLocalFolder(workdir, '', (entry) => {
const excluded = ['.DS_Store', '__MACOSX', '.git'];
excluded.push(...unusedAssets);
return excluded.every(e => entry.indexOf(e) === -1) ; return excluded.every(e => entry.indexOf(e) === -1) ;
}); });
await zip.writeZipPromise(filepath, null); await zip.writeZipPromise(filepath, null);
};
/**
* Zip the content of an ePoc project file from the project workdir
* @returns {string}
*/
const zipEpocProject = async function (workdir, filepath) {
if (!filepath || !workdir) return null;
await zipFiles(workdir, filepath, false);
return filepath; return filepath;
}; };
...@@ -198,16 +213,9 @@ const exportProject = async function (workdir, filepath) { ...@@ -198,16 +213,9 @@ const exportProject = async function (workdir, filepath) {
if(!exportPath) return null; if(!exportPath) return null;
const unusedAssets = getUnusedAssets(workdir).map(asset => path.join('assets', asset)); await zipFiles(workdir, exportPath, true);
const zip = new AdmZip();
zip.addLocalFolder(workdir, '', (entry) => {
const excluded = ['project.json','.DS_Store', '__MACOSX', '.git'];
excluded.push(...unusedAssets);
return excluded.every(e => entry.indexOf(e) === -1) ;
});
await zip.writeZipPromise(exportPath, null);
shell.showItemInFolder(exportPath); shell.showItemInFolder(exportPath);
return exportPath; return exportPath;
}; };
...@@ -322,8 +330,8 @@ const getAllAssets = function (workdir) { ...@@ -322,8 +330,8 @@ const getAllAssets = function (workdir) {
const assetsName = []; const assetsName = [];
for(const asset of assetPaths) { for(const asset of assetPaths) {
const pathParts = asset.split('/'); const pathParts = asset.split(path.sep);
const prefix = pathParts[pathParts.length - 2] === 'icons' ? 'icons/' : ''; const prefix = pathParts[pathParts.length - 2] === 'icons' ? `icons${path.sep}` : '';
const filename = prefix + pathParts[pathParts.length - 1]; const filename = prefix + pathParts[pathParts.length - 1];
assetsName.push(filename); assetsName.push(filename);
} }
...@@ -332,13 +340,13 @@ const getAllAssets = function (workdir) { ...@@ -332,13 +340,13 @@ const getAllAssets = function (workdir) {
const getUsedAssets = function (workdir) { const getUsedAssets = function (workdir) {
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);
if(!matches) return []; if(!matches) return [];
return matches.map(match => { return matches.map(match => {
return match.replace('"assets/', '') return match.replace(`assets${path.sep}`, '')
.replace('"', '') .replaceAll('"', '')
// To only keep the slash after icons // To only keep the slash after icons
.replace(/\/+/g, '/') .replace(/\/+/g, '/')
.replace(/\\/g, ''); .replace(/\\/g, '');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment