Is it possible to use Wrangler / Direct Upload from JS?

I'm working on a plugin for Obsidian to convert Markdown pages to HTML, using a template, generate static assets and then upload them to Cloudflare Pages. I'd like to have all this done in the plugin, without the need for installing any other packages or run commands in the CLI. Is there a good documentation for the wrangler API? I imagine something along the lines of
import { pages } from 'wrangler';
pages.publish(DIRECTORY_PATH, { ...options })
import { pages } from 'wrangler';
pages.publish(DIRECTORY_PATH, { ...options })
2 Replies
Walshy
Walshy2y ago
There is but it isn’t documented yet and is unstable so may change at any point. import { unstable_pages } unstable_pages.publish https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/api/pages/publish.tsx
Mihai Bîrsan
Mihai Bîrsan2y ago
Sweet! I'll give it a shot! Thanks! I was able to get the script to work from the command line. Can't seem to get it to work from the Electron app. It errors when being loaded, with the following message: Plugin failure: obsidian-sample-plugin RuntimeError: Aborted(Error: Invalid package C:\Users\mbirsan\AppData\Local\Obsidian\resources\electron.asar). Build with -sASSERTIONS for more info. I can provide more information if it helps development. Additionally, the built module seems to include a lot of cruft related to the CLI which shouldn't be needed. Noticed it opens a browser window to login with Wrangler, which again... should it be necessary when the API KEY is already configured? Now I'm wondering whether I could just issues use the REST API do do the direct upload.
Want results from more Discord servers?
Add your server