Skip to content

Commit

Permalink
Add reset-install command to remove your existing install. (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang authored Nov 16, 2024
1 parent ed49df0 commit 8e55f55
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"postinstall": "node ./scripts/todesktop/postInstall.js",
"prepare": "husky",
"publish": "yarn run vite:compile && todesktop build --async",
"reset-install": "node scripts/resetInstall.js",
"sign": "node debug/sign.js",
"start": "node ./scripts/launchdev.js",
"test:e2e": "npx playwright test",
Expand Down
75 changes: 75 additions & 0 deletions scripts/resetInstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const fs = require('fs');
const path = require('path');
const os = require('os');
const yaml = require('yaml');
const readline = require('readline');

/**
* Get the path to the extra_models_config.yaml file based on the platform.
* @returns The path to the extra_models_config.yaml file.
*/

function getConfigPath() {
switch (process.platform) {
case 'darwin': // macOS
return path.join(os.homedir(), 'Library', 'Application Support', 'ComfyUI', 'extra_models_config.yaml');
case 'win32': // Windows
return path.join(process.env.APPDATA, 'ComfyUI', 'extra_models_config.yaml');
default:
console.log('Platform not supported for this operation');
process.exit(1);
}
}

async function askForConfirmation(question) {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

return new Promise(resolve => {
rl.question(question + ' (y/N): ', answer => {
rl.close();
resolve(answer.toLowerCase() === 'y');
});
});
}

async function main() {
try {
const configPath = getConfigPath();
let basePath = null;

// Read base_path before deleting the config file
if (fs.existsSync(configPath)) {
const configContent = fs.readFileSync(configPath, 'utf8');
const config = yaml.parse(configContent);
basePath = config?.comfyui?.base_path;

// Delete config file
fs.unlinkSync(configPath);
console.log(`Successfully removed ${configPath}`);
} else {
console.log('Config file not found, nothing to remove');
}

// If base_path exists, ask user if they want to delete it
if (basePath && fs.existsSync(basePath)) {
console.log(`Found ComfyUI installation directory at: ${basePath}`);
const shouldDelete = await askForConfirmation('Would you like to delete this directory as well?');

if (shouldDelete) {
fs.rmSync(basePath, { recursive: true, force: true });
console.log(`Successfully removed ComfyUI directory at ${basePath}`);
} else {
console.log('Skipping ComfyUI directory deletion');
}
}

} catch (error) {
console.error('Error during reset:', error);
process.exit(1);
}
}

main();

0 comments on commit 8e55f55

Please sign in to comment.