Skip to content

Commit

Permalink
Bundle deterministic frontend at build time (#195)
Browse files Browse the repository at this point in the history
* Bundle determinstic frontend at build time

* nit

* nit
  • Loading branch information
huchenlei authored Nov 6, 2024
1 parent c3f6518 commit 5d2da51
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,27 @@
"description": "The best modular GUI to run AI diffusion models.",
"main": ".vite/build/main.js",
"packageManager": "[email protected]",
"config": {
"frontendVersion": "1.3.33"
},
"scripts": {
"clean": "rimraf .vite dist out",
"clean:assets": "rimraf assets/.env assets/ComfyUI assets/python.tgz & yarn run clean:assets:dev",
"clean:assets:dev": "yarn run clean:assets:git && rimraf assets/python assets/override.txt & rimraf assets/cpython*.tar.gz & rimraf assets/requirements.*",
"clean:assets:git": "rimraf assets/ComfyUI/.git assets/ComfyUI/custom_nodes/ComfyUI_Manager/.git assets/ComfyUI/custom_nodes/DesktopSettingsExtension/.git",
"clean:slate": "yarn run clean & yarn run clean:assets & rimraf node_modules",
"clone-settings-extension": "git clone https://github.com/Comfy-Org/DesktopSettingsExtension.git assets/ComfyUI/custom_nodes/DesktopSettingsExtension",
"download-frontend": "node scripts/downloadFrontend.js",
"make:frontend": "yarn run download-frontend && yarn run clone-settings-extension",
"format": "prettier --check .",
"format:fix": "prettier --write .",
"lint": "eslint --ext .ts,.tsx .",
"lint:fix": "eslint --fix --ext .ts,.tsx .",
"make": "yarn run vite:compile && electron-builder build --config=builder-debug.config.ts",
"make:assets:amd": "cd assets && comfy-cli --skip-prompt --here install --fast-deps --amd --manager-url https://github.com/Comfy-Org/manager-core && comfy-cli --here standalone && yarn run clone-settings-extension",
"make:assets:cpu": "cd assets && comfy-cli --skip-prompt --here install --fast-deps --cpu --manager-url https://github.com/Comfy-Org/manager-core && comfy-cli --here standalone && node ../scripts/env.mjs && yarn run clone-settings-extension",
"make:assets:macos": "cd assets && comfy-cli --skip-prompt --here install --fast-deps --m-series --manager-url https://github.com/Comfy-Org/manager-core && comfy-cli --here standalone && yarn run clone-settings-extension && ../scripts/checkAssetsMacos.sh python",
"make:assets:nvidia": "cd assets && comfy-cli --skip-prompt --here install --fast-deps --nvidia --manager-url https://github.com/Comfy-Org/manager-core && comfy-cli --here standalone && yarn run clone-settings-extension",
"make:assets:amd": "cd assets && comfy-cli --skip-prompt --here install --fast-deps --amd --manager-url https://github.com/Comfy-Org/manager-core && comfy-cli --here standalone && yarn run make:frontend",
"make:assets:cpu": "cd assets && comfy-cli --skip-prompt --here install --fast-deps --cpu --manager-url https://github.com/Comfy-Org/manager-core && comfy-cli --here standalone && node ../scripts/env.mjs && yarn run make:frontend",
"make:assets:macos": "cd assets && comfy-cli --skip-prompt --here install --fast-deps --m-series --manager-url https://github.com/Comfy-Org/manager-core && comfy-cli --here standalone && yarn run make:frontend && ../scripts/checkAssetsMacos.sh python",
"make:assets:nvidia": "cd assets && comfy-cli --skip-prompt --here install --fast-deps --nvidia --manager-url https://github.com/Comfy-Org/manager-core && comfy-cli --here standalone && yarn run make:frontend",
"make:nvidia": "yarn run make -- --nvidia",
"notarize": "node debug/notarize.js",
"package": "yarn run vite:compile && todesktop build --code-sign=false --async",
Expand Down
47 changes: 47 additions & 0 deletions scripts/downloadFrontend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const axios = require('axios');
const extract = require('extract-zip');
const fs = require('fs/promises');
const path = require('path');

// Example "v1.3.34"
const version = process.argv[2] || require('../package.json').config.frontendVersion;
if (!version) {
console.error('No version specified');
process.exit(1);
}

const url = `https://github.com/Comfy-Org/ComfyUI_frontend/releases/download/v${version}/dist.zip`;
const downloadPath = 'temp_frontend.zip';
const extractPath = 'assets/ComfyUI/web_custom_versions/desktop_app';

async function downloadAndExtractFrontend() {
try {
// Create directories if they don't exist
await fs.mkdir(extractPath, { recursive: true });

// Download the file
console.log('Downloading frontend...');
const response = await axios({
method: 'GET',
url: url,
responseType: 'arraybuffer'
});

// Save to temporary file
await fs.writeFile(downloadPath, response.data);

// Extract the zip file
console.log('Extracting frontend...');
await extract(downloadPath, { dir: path.resolve(extractPath) });

// Clean up temporary file
await fs.unlink(downloadPath);

console.log('Frontend downloaded and extracted successfully!');
} catch (error) {
console.error('Error downloading frontend:', error.message);
process.exit(1);
}
}

downloadAndExtractFrontend();
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ const launchPythonServer = async (
'--output-directory',
outputDirectoryPath,
...(process.env.COMFYUI_CPU_ONLY === 'true' ? ['--cpu'] : []),
'--front-end-version',
'Comfy-Org/ComfyUI_frontend@latest',
'--front-end-root',
path.join(appResourcesPath, 'ComfyUI', 'web_custom_versions', 'desktop_app'),
'--extra-model-paths-config',
modelConfigPath,
'--port',
Expand Down

0 comments on commit 5d2da51

Please sign in to comment.