@comcomputesdk/cmd (英语)
类型安全 shell 命令构建器,用于计算SDK沙盒.
安装
npm install @computesdk/cmd
使用量
基本命令
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'));
使用运行命令选项
现代计算SDK沙盒手柄 cwd, (中文(简体) ), env,以及 background 直接选项 :
import { npm, node } from '@computesdk/cmd';
// Let the sandbox handle execution options
await sandbox.runCommand('npm install', { cwd: '/app' })
await sandbox.runCommand('node server.js', { background: true })
await sandbox.runCommand('npm run dev', {
cwd: '/app',
background: true,
env: { NODE_ENV: 'production' }
})
壳包 (高级)
对于需要明确外壳包装的情况,请使用 shell(), (中文(简体) ), sh(), (中文(简体) ), bash(),或 zsh()数字 :
import { shell, bash, zsh, npm } from '@computesdk/cmd';
// Default shell wrapper (sh)
shell(npm.install(), { cwd: '/app' })
// => ['sh', '-c', 'cd "/app" && npm install']
// Bash-specific
bash(npm.install(), { cwd: '/app' })
// => ['bash', '-c', 'cd "/app" && npm install']
// Zsh with background
zsh(npm.run('dev'), { background: true })
// => ['zsh', '-c', 'nohup npm run dev > /dev/null 2>&1 &']
说明: 很少需要壳包 - 喜欢使用 runCommand() 选项.
可用命令
文件系统
mkdir(path, options?)- 创建目录(默认重复)rm(path, options?)- 删除文件/目录cp(src, dest, options?)- 收到了吗mv(src, dest)- 移动/重命名ls(path?, options?)- 列表目录pwd()- 打印工作目录chmod(mode, path, options?)- 更改权限chown(owner, path, options?)- 改变所有者touch(path)- 创建文件/更新时间戳cat(path)- 读取文件ln(target, link, options?)- 创建链接readlink(path, options?)- 解开连锁rsync(src, dest, options?)- 同步文件/目录
文件系统测试
test.exists(path)- 文件/目录存在test.isFile(path)- 是一个文件test.isDir(path)- 是个目录test.isReadable(path)- 是可读test.isWritable(path)- 是可写test.isExecutable(path)- 是可执行的test.notEmpty(path)- 文件不是空的test.isSymlink(path)- 是连锁
进程/执行
node(script, args?)- 运行节点.js脚本python(script, args?)- 运行 Python 脚本kill(pid, signal?)- 由 PID 制作的杀戮程序pkill(name, options?)- 杀人的名字ps(options?)- 清单进程timeout(seconds, command, args?)- 与超时运行
软件包管理器( 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?)
软件包管理器( 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)
软件包运行器
npx(pkg, args?)- 运行与npxnpx.concurrently(commands, options?)- 并行运行命令bunx(pkg, args?)- 和Bunx一起跑吗bunx.concurrently(commands, options?)
图形
git.init()- 初始化仓库git.clone(url, options?)- 克隆存储器git.add(path, options?)- 阶段文件git.commit(message, options?)- 提交更改git.push(options?)- 推到遥控器git.pull()- 拉变化git.fetch(options?)- 从远程获取git.checkout(branch, options?)- 离职分支git.branch(name?, options?)- 列表/创建分支git.status()- 显示状态git.diff(options?)- 显示更改git.log(options?)- 显示承诺的历史git.stash(options?)- 结构变化git.reset(options?)- 重置更改
网络
curl(url, options?)- 用卷曲下载wget(url, options?)- 用 wget 下载net.ping(host, count?)- 主持人net.check(host, port)- 检查连接net.publicIp()- 获取公开IPnet.interfaces()- 显示网络接口
港口
port.find(port)- 利用端口查找进程port.kill(port)- 在端口上杀死进程port.isUsed(port)- 检查端口是否在使用中port.list()- 列出监听端口port.waitFor(port, timeout?)- 等待开口
档案
tar.extract(file, options?)- 提取焦油归档tar.create(output, source)- 创建沥青档案unzip(file, options?)- 提取 zip 归档
文本处理
grep(pattern, file?, options?)- 寻找模式sed(expression, file, options?)- 流编辑器awk(program, file?, options?)- 图案扫描head(file, lines?)- 文件的第一行tail(file, lines?, options?)- 文件的最后行wc(file, options?)- 单词/行数sort(file, options?)- 排序行uniq(file, options?)- 过滤复制jq(filter, file?, options?)- JSON进程cut(file, options)- 提取列tr(set1, set2?, options?)- 翻译字符xargs(command, args?, options?)- 从 stdin 构建命令
系统
df(path?, options?)- 磁盘空间du(path, options?)- 目录大小whoami()- 当前用户uname(options?)- 系统信息hostname()- 主机名称env()- 环境变量printenv(name?)- 打印掩体变量which(command)- 寻找命令位置
编码/检查和
base64.encode(file?)- 编码到基地64base64.decode(file?)- 从64基地解码md5sum(file, options?)- MD5核对和sha256sum(file, options?)- SHA256支票和sha1sum(file, options?)- SHA1支票和
公用事业
sleep(seconds)- 延迟执行date(format?)- 打印日期/时间find(path, options?)- 查找文件tee(file, options?)- 写到文件 和 stdoutdiff(file1, file2, options?)- 比较文件echo(text)- 打印文本parallel(commands, options?)- 并行运行命令raw(command, args?)- 自定义命令
公用事业
esc(string)
为 shell 安全起见, 跳出字符串中的双引号 :
import { esc } from '@computesdk/cmd';
esc('path with "quotes"') // 'path with \\"quotes\\"'
许可证
麻省理工学院