From 7208a8284ff4103d2ae3078a2a53b63a92c99593 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 17 Jan 2024 17:53:48 +0100 Subject: [PATCH] fix: refs #5123 clean now merges directories when archive exists --- myt-clean.js | 23 ++++++++++++++++++----- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/myt-clean.js b/myt-clean.js index 03ef6cc..825f003 100644 --- a/myt-clean.js +++ b/myt-clean.js @@ -52,11 +52,24 @@ class Clean extends Command { if (!await fs.pathExists(archiveDir)) await fs.mkdir(archiveDir); - for (const oldVersion of oldVersions) - await fs.move( - path.join(opts.versionsDir, oldVersion), - path.join(archiveDir, oldVersion) - ); + for (const oldVersion of oldVersions) { + const srcDir = path.join(opts.versionsDir, oldVersion); + const dstDir = path.join(archiveDir, oldVersion); + + if (!await fs.pathExists(dstDir)) + await fs.mkdir(dstDir); + + const scripts = await fs.readdir(srcDir); + for (const script of scripts) { + await fs.move( + path.join(srcDir, script), + path.join(dstDir, script), + {overwrite: true} + ); + } + + await fs.rmdir(srcDir); + } console.log(`Old versions archived: ${oldVersions.length}`); } else diff --git a/package-lock.json b/package-lock.json index 795db60..65e2ce1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@verdnatura/myt", - "version": "1.5.25", + "version": "1.5.26", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@verdnatura/myt", - "version": "1.5.25", + "version": "1.5.26", "license": "GPL-3.0", "dependencies": { "@sqltools/formatter": "^1.2.5", diff --git a/package.json b/package.json index 95ece9d..af019fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@verdnatura/myt", - "version": "1.5.25", + "version": "1.5.26", "author": "Verdnatura Levante SL", "description": "MySQL version control", "license": "GPL-3.0",