@computesdk/cmd
v0.3.1
Published
Type-safe shell command builders for ComputeSDK sandboxes
Maintainers
Readme
@computesdk/cmd
Type-safe shell command builders for use with ComputeSDK sandboxes.
Installation
npm install @computesdk/cmdUsage
Basic Commands
import { cmd, npm, node, git } from '@computesdk/cmd';
// Build command tuples
npm.install('express') // ['npm', 'install', 'express']
node('server.js') // ['node', 'server.js']
git.clone('https://...') // ['git', 'clone', 'https://...']
// Use with sandbox.runCommand()
await sandbox.runCommand(npm.install('express'));
await sandbox.runCommand(node('server.js'));Shell Wrapping with cmd()
Use cmd() to wrap commands with cwd or background options:
import { cmd, npm, node } from '@computesdk/cmd';
// Run in a specific directory
cmd(npm.install(), { cwd: '/app' })
// => ['sh', '-c', 'cd "/app" && npm install']
// Run in background
cmd(node('server.js'), { background: true })
// => ['sh', '-c', 'nohup node server.js > /dev/null 2>&1 &']
// Both options
cmd(npm.run('dev'), { cwd: '/app', background: true })
// => ['sh', '-c', 'nohup cd "/app" && npm run dev > /dev/null 2>&1 &']Shell-Specific Wrappers
Use sh, bash, or zsh for explicit shell selection:
import { bash, zsh, npm } from '@computesdk/cmd';
bash(npm.install(), { cwd: '/app' })
// => ['bash', '-c', 'cd "/app" && npm install']
zsh(npm.run('dev'), { background: true })
// => ['zsh', '-c', 'nohup npm run dev > /dev/null 2>&1 &']Available Commands
File System
mkdir(path, options?)- Create directory (recursive by default)rm(path, options?)- Remove file/directorycp(src, dest, options?)- Copymv(src, dest)- Move/renamels(path?, options?)- List directorypwd()- Print working directorychmod(mode, path, options?)- Change permissionschown(owner, path, options?)- Change ownertouch(path)- Create file/update timestampcat(path)- Read fileln(target, link, options?)- Create linkreadlink(path, options?)- Resolve symlinkrsync(src, dest, options?)- Sync files/directories
Filesystem Tests
test.exists(path)- File/dir existstest.isFile(path)- Is a filetest.isDir(path)- Is a directorytest.isReadable(path)- Is readabletest.isWritable(path)- Is writabletest.isExecutable(path)- Is executabletest.notEmpty(path)- File is not emptytest.isSymlink(path)- Is a symlink
Process/Execution
node(script, args?)- Run Node.js scriptpython(script, args?)- Run Python scriptkill(pid, signal?)- Kill process by PIDpkill(name, options?)- Kill by nameps(options?)- List processestimeout(seconds, command, args?)- Run with timeout
Package Managers (JavaScript)
npm.install(pkg?, options?),npm.run(script),npm.init(),npm.uninstall(pkg)pnpm.install(pkg?, options?),pnpm.run(script)yarn.install(),yarn.add(pkg, options?),yarn.run(script)bun.install(pkg?, options?),bun.run(script),bun.exec(file)deno.run(file, options?),deno.install(url, options?)
Package Managers (Python)
pip.install(pkg),pip.uninstall(pkg)uv.install(pkg),uv.run(script),uv.sync(),uv.venv(path?)poetry.install(options?),poetry.add(pkg, options?),poetry.run(cmd),poetry.build()pipx.install(pkg),pipx.run(pkg, args?),pipx.uninstall(pkg),pipx.upgrade(pkg)
Package Runners
npx(pkg, args?)- Run with npxnpx.concurrently(commands, options?)- Run commands in parallelbunx(pkg, args?)- Run with bunxbunx.concurrently(commands, options?)
Git
git.init()- Initialize repositorygit.clone(url, options?)- Clone repositorygit.add(path, options?)- Stage filesgit.commit(message, options?)- Commit changesgit.push(options?)- Push to remotegit.pull()- Pull changesgit.fetch(options?)- Fetch from remotegit.checkout(branch, options?)- Checkout branchgit.branch(name?, options?)- List/create branchesgit.status()- Show statusgit.diff(options?)- Show changesgit.log(options?)- Show commit historygit.stash(options?)- Stash changesgit.reset(options?)- Reset changes
Network
curl(url, options?)- Download with curlwget(url, options?)- Download with wgetnet.ping(host, count?)- Ping hostnet.check(host, port)- Check connectivitynet.publicIp()- Get public IPnet.interfaces()- Show network interfaces
Ports
port.find(port)- Find process using portport.kill(port)- Kill process on portport.isUsed(port)- Check if port is in useport.list()- List listening portsport.waitFor(port, timeout?)- Wait for port
Archives
tar.extract(file, options?)- Extract tar archivetar.create(output, source)- Create tar archiveunzip(file, options?)- Extract zip archive
Text Processing
grep(pattern, file?, options?)- Search for patternsed(expression, file, options?)- Stream editorawk(program, file?, options?)- Pattern scanninghead(file, lines?)- First lines of filetail(file, lines?, options?)- Last lines of filewc(file, options?)- Word/line countsort(file, options?)- Sort linesuniq(file, options?)- Filter duplicatesjq(filter, file?, options?)- Process JSONcut(file, options)- Extract columnstr(set1, set2?, options?)- Translate charactersxargs(command, args?, options?)- Build commands from stdin
System
df(path?, options?)- Disk spacedu(path, options?)- Directory sizewhoami()- Current useruname(options?)- System infohostname()- Hostnameenv()- Environment variablesprintenv(name?)- Print env variablewhich(command)- Find command location
Encoding/Checksums
base64.encode(file?)- Encode to base64base64.decode(file?)- Decode from base64md5sum(file, options?)- MD5 checksumsha256sum(file, options?)- SHA256 checksumsha1sum(file, options?)- SHA1 checksum
Utilities
sleep(seconds)- Delay executiondate(format?)- Print date/timefind(path, options?)- Find filestee(file, options?)- Write to file and stdoutdiff(file1, file2, options?)- Compare filesecho(text)- Print textparallel(commands, options?)- Run commands in parallelraw(command, args?)- Custom command
Utilities
esc(string)
Escape double quotes in strings for shell safety:
import { esc } from '@computesdk/cmd';
esc('path with "quotes"') // 'path with \\"quotes\\"'License
MIT
