Skip to content

How to use zx as a library/dependency in Electron ? #227

Discussion options

You must be logged in to vote

I have made a simple prototype that prove zx can be fork to execute .mjs file in a tmp folder: https://github.com/tiddly-gittly/TiddlyGit-Desktop/blob/0c6b26c0c1113e0c66d6f49f022c5733d4fa85e8/src/services/native/zxWorker.ts

First you will need https://github.com/sindresorhus/fix-path to use shell in a GUI app. And for electron, use sindresorhus/fix-path#15 (comment)

The core concept is:

import { mkdtemp, writeFile } from 'fs-extra';
import { fork } from 'child_process';
import path from 'path';
import { tmpdir } from 'os';

const zxPath = '/Users/TiddlyGit-Desktop/node_modules/zx/zx.mjs';
const fileName = 'aaa.md';

const fileContent = `

# aaa

\`\`\`sh
pwd
ls
\`\`\`

\`\`\`js

const res…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by linonetwo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant