Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update setup-care-apps scripts to remove existing apps that are not configured in env if any #9052

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ cypress/fixtures/token.json
# Care Apps
/apps/*
src/pluginMap.ts
/apps_backup/*
30 changes: 30 additions & 0 deletions scripts/setup-care-apps.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ const installApp = (app) => {
);
};

const backupDir = path.join(__dirname, "..", "apps_backup");

// Create backup directory if needed
if (!fs.existsSync(backupDir)) {
fs.mkdirSync(backupDir);
}

try {
fs.readdirSync(appsDir, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map((dirent) => dirent.name)
.filter(
(dir) =>
!appsConfig.map((app) => app.package.split("/")[1]).includes(dir),
)
.forEach((unusedApp) => {
const appPath = path.join(appsDir, unusedApp);
const backupPath = path.join(backupDir, `${unusedApp}_${Date.now()}`);
console.log(`Backing up '${unusedApp}' to ${backupPath}`);
fs.cpSync(appPath, backupPath, { recursive: true });
console.log(
`Removing existing app '${unusedApp}' as it is not configured.`,
);
fs.rmSync(appPath, { recursive: true, force: true });
});
} catch (error) {
console.error("Error during cleanup:", error);
process.exit(1);
}

// Clone or pull care apps
appsConfig.forEach((app) => {
const appDir = path.join(appsDir, app.package.split("/")[1]);
Expand Down
Loading