Skip to content

Commit

Permalink
Update setup-care-apps scripts to remove existing apps that are not c…
Browse files Browse the repository at this point in the history
…onfigured in env if any (ohcnetwork#9052)
  • Loading branch information
rithviknishad authored Nov 8, 2024
1 parent 4b8b4a4 commit 66ef112
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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

0 comments on commit 66ef112

Please sign in to comment.