Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0aa2747736 | ||
|
|
0351a2eaab | ||
|
|
4276ddbfb1 | ||
|
|
0094c08d1c | ||
|
|
14824e3473 | ||
|
|
ea32a8fbbe | ||
|
|
e7363070f1 | ||
|
|
39c22295bc | ||
|
|
881e48a10c | ||
|
|
dc6b71b494 | ||
|
|
d938df9f4f | ||
|
|
9ea8e993c4 | ||
|
|
cdca60ff04 |
@@ -0,0 +1,21 @@
|
||||
name: Publish to Comfy registry
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- "pyproject.toml"
|
||||
|
||||
jobs:
|
||||
publish-node:
|
||||
name: Publish Custom Node to registry
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish Custom Node
|
||||
uses: Comfy-Org/publish-node-action@main
|
||||
with:
|
||||
## Add your own personal access token to your Github Repository secrets and reference it here.
|
||||
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
||||
+16
-1
@@ -211,8 +211,18 @@ class CodeGenerator:
|
||||
for idx, data, is_special_function in load_order:
|
||||
# Generate class definition and inputs from the data
|
||||
inputs, class_type = data["inputs"], data["class_type"]
|
||||
input_types = self.node_class_mappings[class_type].INPUT_TYPES()
|
||||
class_def = self.node_class_mappings[class_type]()
|
||||
|
||||
# If required inputs are not present, skip the node as it will break the code if passed through to the script
|
||||
missing_required_variable = False
|
||||
if "required" in input_types.keys():
|
||||
for required in input_types["required"]:
|
||||
if required not in inputs.keys():
|
||||
missing_required_variable = True
|
||||
if missing_required_variable:
|
||||
continue
|
||||
|
||||
# If the class hasn't been initialized yet, initialize it and generate the import statements
|
||||
if class_type not in initialized_objects:
|
||||
# No need to use preview image nodes since we are executing the script in a terminal
|
||||
@@ -242,7 +252,12 @@ class CodeGenerator:
|
||||
if no_params or key in class_def_params
|
||||
}
|
||||
# Deal with hidden variables
|
||||
if class_def_params is not None:
|
||||
if (
|
||||
"hidden" in input_types.keys()
|
||||
and "unique_id" in input_types["hidden"].keys()
|
||||
):
|
||||
inputs["unique_id"] = random.randint(1, 2**64)
|
||||
elif class_def_params is not None:
|
||||
if "unique_id" in class_def_params:
|
||||
inputs["unique_id"] = random.randint(1, 2**64)
|
||||
|
||||
|
||||
+85
-30
@@ -10,6 +10,37 @@ app.registerExtension({
|
||||
});
|
||||
},
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const menu = document.querySelector(".comfy-menu");
|
||||
const separator = document.createElement("hr");
|
||||
|
||||
@@ -19,37 +50,61 @@ app.registerExtension({
|
||||
|
||||
const saveButton = document.createElement("button");
|
||||
saveButton.textContent = "Save as Script";
|
||||
saveButton.onclick = () => {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
console.log("SaveAsScript loaded");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
[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"
|
||||
dependencies = ["black"]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/pydn/ComfyUI-to-Python-Extension"
|
||||
# Used by Comfy Registry https://comfyregistry.org
|
||||
|
||||
[tool.comfy]
|
||||
PublisherId = "pydn"
|
||||
DisplayName = "ComfyUI-to-Python-Extension"
|
||||
Icon = ""
|
||||
Reference in New Issue
Block a user