Skip to content

Commit

Permalink
resolve issues with cleanup command
Browse files Browse the repository at this point in the history
  • Loading branch information
ejnshtein committed Feb 7, 2022
1 parent 5ba1bc4 commit e7861f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 2 additions & 0 deletions build-packages/magento-scripts/lib/tasks/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const {
uninstallMagento,
removeMagento
} = require('./magento');
const getMagentoVersionConfig = require('../config/get-magento-version-config');
const { stopPhpFpm } = require('./php-fpm');
const getProjectConfiguration = require('../config/get-project-configuration');
const checkConfigurationFile = require('../config/check-configuration-file');
Expand All @@ -16,6 +17,7 @@ const cleanup = () => ({
title: 'Cleanup project',
task: (ctx, task) => task.newListr([
checkConfigurationFile(),
getMagentoVersionConfig(),
getProjectConfiguration(),
stopPhpFpm(),
stopServices(),
Expand Down
38 changes: 18 additions & 20 deletions build-packages/magento-scripts/lib/tasks/magento/remove-magento.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,27 @@ const magentoFiles = [
*/
const removeMagento = () => ({
title: 'Remove magento application folder',
task: async (ctx, task) => {
skip: async (ctx) => {
const { config: { baseConfig } } = ctx;
const appPathExists = await pathExists(baseConfig.magentoDir);

if (appPathExists && ctx.force) {
await Promise.all(magentoFiles.map(async (fileName) => {
const filePath = path.join(baseConfig.magentoDir, fileName);
const fileExists = await pathExists(filePath);
if (!fileExists) {
return;
}
const file = await fs.promises.stat(filePath);
if (file.isFile()) {
await fs.promises.unlink(filePath);
} else if (file.isDirectory()) {
await fs.promises.rmdir(filePath, { recursive: true });
}
}));

return;
}

task.skip();
return !(appPathExists && ctx.force);
},
task: async (ctx) => {
const { config: { baseConfig } } = ctx;
await Promise.all(magentoFiles.map(async (fileName) => {
const filePath = path.join(baseConfig.magentoDir, fileName);
const fileExists = await pathExists(filePath);
if (!fileExists) {
return;
}
const file = await fs.promises.stat(filePath);
if (file.isFile()) {
await fs.promises.unlink(filePath);
} else if (file.isDirectory()) {
await fs.promises.rmdir(filePath, { recursive: true });
}
}));
}
});

Expand Down

0 comments on commit e7861f5

Please sign in to comment.