Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32d42bf472 | ||
|
|
281b8408c9 | ||
|
|
b215c83b76 | ||
|
|
76bc1c343e | ||
|
|
42bc6926ae | ||
|
|
351a68831d | ||
|
|
1c0585fabe | ||
|
|
60d55d904b | ||
|
|
3a5ef069d9 | ||
|
|
77a493f0eb | ||
|
|
2f6a649801 | ||
|
|
4d0de66b0b |
@@ -7,15 +7,19 @@ on:
|
||||
paths:
|
||||
- "pyproject.toml"
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
|
||||
jobs:
|
||||
publish-node:
|
||||
name: Publish Custom Node to registry
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.repository_owner == 'pydn' }}
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish Custom Node
|
||||
uses: Comfy-Org/publish-node-action@main
|
||||
uses: Comfy-Org/publish-node-action@v1
|
||||
with:
|
||||
## Add your own personal access token to your Github Repository secrets and reference it here.
|
||||
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
||||
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
||||
|
||||
@@ -11,7 +11,8 @@ from argparse import ArgumentParser
|
||||
|
||||
import black
|
||||
|
||||
|
||||
# Add current directory to Python path
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from comfyui_to_python_utils import (
|
||||
import_custom_nodes,
|
||||
find_path,
|
||||
|
||||
@@ -12,6 +12,7 @@ def import_custom_nodes() -> None:
|
||||
import asyncio
|
||||
import execution
|
||||
from nodes import init_extra_nodes
|
||||
sys.path.insert(0, find_path("ComfyUI"))
|
||||
import server
|
||||
|
||||
# Creating a new event loop and setting it as the default loop
|
||||
@@ -23,7 +24,7 @@ def import_custom_nodes() -> None:
|
||||
execution.PromptQueue(server_instance)
|
||||
|
||||
# Initializing custom nodes
|
||||
init_extra_nodes()
|
||||
asyncio.run(init_extra_nodes())
|
||||
|
||||
|
||||
def find_path(name: str, path: str = None) -> str:
|
||||
|
||||
+45
-96
@@ -1,111 +1,60 @@
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { api } from "../../scripts/api.js";
|
||||
import { app } from "../../scripts/app.js";
|
||||
import { $el } from "../../scripts/ui.js";
|
||||
|
||||
app.registerExtension({
|
||||
const extension = {
|
||||
name: "Comfy.SaveAsScript",
|
||||
commands: [
|
||||
{
|
||||
id: "triggerSaveAsScript",
|
||||
label: "Save As Script",
|
||||
function: () => { extension.savePythonScript(); }
|
||||
}
|
||||
],
|
||||
menuCommands: [
|
||||
{
|
||||
path: ["File"],
|
||||
commands: ["triggerSaveAsScript"]
|
||||
}
|
||||
],
|
||||
init() {
|
||||
$el("style", {
|
||||
parent: document.head,
|
||||
});
|
||||
},
|
||||
async setup() {
|
||||
function savePythonScript() {
|
||||
var filename = prompt("Save script as:");
|
||||
if(filename === undefined || filename === null || filename === "") {
|
||||
return
|
||||
}
|
||||
|
||||
app.graphToPrompt().then(async (p) => {
|
||||
const json = JSON.stringify({name: filename + ".json", workflow: JSON.stringify(p.output, null, 2)}, null, 2); // convert the data to a JSON string
|
||||
var response = await api.fetchApi(`/saveasscript`, { method: "POST", body: json });
|
||||
if(response.status == 200) {
|
||||
const blob = new Blob([await response.text()], {type: "text/python;charset=utf-8"});
|
||||
const url = URL.createObjectURL(blob);
|
||||
if(!filename.endsWith(".py")) {
|
||||
filename += ".py";
|
||||
}
|
||||
|
||||
const a = $el("a", {
|
||||
href: url,
|
||||
download: filename,
|
||||
style: {display: "none"},
|
||||
parent: document.body,
|
||||
});
|
||||
a.click();
|
||||
setTimeout(function () {
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
savePythonScript() {
|
||||
var filename = prompt("Save script as:");
|
||||
if(filename === undefined || filename === null || filename === "") {
|
||||
return
|
||||
}
|
||||
|
||||
app.graphToPrompt().then(async (p) => {
|
||||
const json = JSON.stringify({name: filename + ".json", workflow: JSON.stringify(p.output, null, 2)}, null, 2); // convert the data to a JSON string
|
||||
var response = await api.fetchApi(`/saveasscript`, { method: "POST", body: json });
|
||||
if(response.status == 200) {
|
||||
const blob = new Blob([await response.text()], {type: "text/python;charset=utf-8"});
|
||||
const url = URL.createObjectURL(blob);
|
||||
if(!filename.endsWith(".py")) {
|
||||
filename += ".py";
|
||||
}
|
||||
|
||||
const menu = document.querySelector(".comfy-menu");
|
||||
const separator = document.createElement("hr");
|
||||
|
||||
separator.style.margin = "20px 0";
|
||||
separator.style.width = "100%";
|
||||
menu.append(separator);
|
||||
|
||||
const saveButton = document.createElement("button");
|
||||
saveButton.textContent = "Save as Script";
|
||||
saveButton.onclick = () => savePythonScript();
|
||||
menu.append(saveButton);
|
||||
|
||||
|
||||
// Also load to new style menu
|
||||
const dropdownMenu = document.querySelectorAll(".p-menubar-submenu ")[0];
|
||||
// Get submenu items
|
||||
const listItems = dropdownMenu.querySelectorAll("li");
|
||||
let newSetsize = listItems.length;
|
||||
|
||||
const separatorMenu = document.createElement("li");
|
||||
separatorMenu.setAttribute("id", "pv_id_8_0_" + (newSetsize - 1).toString());
|
||||
separatorMenu.setAttribute("class", "p-menubar-separator");
|
||||
separatorMenu.setAttribute("role", "separator");
|
||||
separatorMenu.setAttribute("data-pc-section", "separator");
|
||||
|
||||
dropdownMenu.append(separatorMenu);
|
||||
|
||||
// Adjust list items within to increase setsize
|
||||
listItems.forEach((item) => {
|
||||
// First check if it's a separator
|
||||
if(item.getAttribute("data-pc-section") !== "separator") {
|
||||
item.setAttribute("aria-setsize", newSetsize);
|
||||
const a = $el("a", {
|
||||
href: url,
|
||||
download: filename,
|
||||
style: {display: "none"},
|
||||
parent: document.body,
|
||||
});
|
||||
a.click();
|
||||
setTimeout(function () {
|
||||
a.remove();
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(newSetsize);
|
||||
|
||||
// Here's the format of list items
|
||||
const saveButtonText = document.createElement("li");
|
||||
saveButtonText.setAttribute("id", "pv_id_8_0_" + newSetsize.toString());
|
||||
saveButtonText.setAttribute("class", "p-menubar-item relative");
|
||||
saveButtonText.setAttribute("role", "menuitem");
|
||||
saveButtonText.setAttribute("aria-label", "Save as Script");
|
||||
saveButtonText.setAttribute("aria-level", "2");
|
||||
saveButtonText.setAttribute("aria-setsize", newSetsize.toString());
|
||||
saveButtonText.setAttribute("aria-posinset", newSetsize.toString());
|
||||
saveButtonText.setAttribute("data-pc-section", "item");
|
||||
saveButtonText.setAttribute("data-p-active", "false");
|
||||
saveButtonText.setAttribute("data-p-focused", "false");
|
||||
|
||||
saveButtonText.innerHTML = `
|
||||
<div class="p-menubar-item-content" data-pc-section="itemcontent">
|
||||
<a class="p-menubar-item-link" tabindex="-1" aria-hidden="true" data-pc-section="itemlink" target="_blank">
|
||||
<span class="p-menubar-item-icon pi pi-book"></span>
|
||||
<span class="p-menubar-item-label">Save as Script</span>
|
||||
</a>
|
||||
</div>
|
||||
`
|
||||
|
||||
saveButtonText.onclick = () => savePythonScript();
|
||||
|
||||
dropdownMenu.append(saveButtonText);
|
||||
|
||||
|
||||
|
||||
},
|
||||
async setup() {
|
||||
console.log("SaveAsScript loaded");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
app.registerExtension(extension);
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
[project]
|
||||
name = "comfyui-to-python-extension"
|
||||
description = "This custom node allows you to generate pure python code from your ComfyUI workflow with the click of a button. Great for rapid experimentation or production deployment."
|
||||
version = "1.3.0"
|
||||
license = "LICENSE"
|
||||
version = "1.3.1"
|
||||
license = { text = "MIT License" }
|
||||
dependencies = ["black"]
|
||||
|
||||
[project.urls]
|
||||
|
||||
Reference in New Issue
Block a user