@ bluwy/ giget- core (英语)
一个 JavaScript API 从 git 仓库或 URL 下载模板. 该代码主要基于 吉娃娃 (并包括其许可证),但有以下差异:
- 只有JavaScript API. (简体中文). CLI和无关的API被剥去.
- 依赖性减少到只有1个(现代塔尔) (中文(简体) ).
- 减少了输入和输出 API 表面.
- 已删除自定义注册和 JSON 模板支持 .
- 删除
GIGET_特殊环境变量支持. - 删除自动获取代理支持 .
- 支持获取寄存器的默认分支 .
- 额外的API公用事业.
- 节点18和无害环境管理.
见 从巨头移走 如何迁移到 @bluwy/giget-core。 。 。 .
使用量
API 有大量文献记载于 ./src/index.d.ts (中文(简体) )下面是使用这些工具的一些例子:
downloadTemplate
用给定的输入字符串下载模板 .
import { downloadTemplate } from '@bluwy/giget-core'
// Basic usage. Download from github repo.
const result = await downloadTemplate('unjs/template')
// info: { ... } - The template information parsed by providers
// dir: '...' - The directory where the template is downloaded to
// source: '...' - The source URL of the template (Prefix like `gh:` is stripped)
// Other input syntaxes
await downloadTemplate('unjs/template/subdir')
await downloadTemplate('unjs/template#main')
await downloadTemplate('gh:unjs/template')
await downloadTemplate('gitlab:unjs/template')
await downloadTemplate('bitbucket:unjs/template')
await downloadTemplate(
'https://api.github.com/repos/unjs/template/tarball/main',
)
// Download to a specific directory (relative to cwd)
await downloadTemplate('unjs/template', { dir: 'my-project' })
// Download to a directory even if it has existing content
// (merges directories and replaces matching files)
await downloadTemplate('unjs/template', { force: true })
// Clean directory before downloading to it
await downloadTemplate('unjs/template', { force: 'clean' })
// Use offline cache only
await downloadTemplate('unjs/template', { offline: true })
// Use offline cache if available, otherwise download
await downloadTemplate('unjs/template', { offline: 'prefer' })
// Specify provider explicitly (if input has a provider prefix, it'll
// take precedence instead)
await downloadTemplate('unjs/template', { provider: 'gitlab' })
// Pass authentication token to access private repositories
// (handled by providers to pass as headers when downloading the tarball)
await downloadTemplate('unjs/template', { providerOptions: { auth: 'xxx' } })
verifyTemplate
检查模板是否有效 。 需要网络访问.
import { verifyTemplate } from '@bluwy/giget-core'
await verifyTemplate('unjs/template') // true
await verifyTemplate('unjs/template/subdir') // true
await verifyTemplate('unjs/template#main') // true
await verifyTemplate('gh:unjs/template') // true
await verifyTemplate('gitlab:unjs/template') // true
await verifyTemplate('bitbucket:unjs/template') // true
await verifyTemplate('https://api.github.com/repos/unjs/template/tarball/main') // true
await verifyTemplate('unjs/non-existent-repo') // false
await verifyTemplate('unjs/template/not-existent-subdir') // false
await verifyTemplate('unjs/template#not-existent-branch') // false
parseGitURI
分析一个输入( 例如 ). 'owner/repo/templates/foo#main'改为a GitInfo 对象。 对需要解析给定输入的自定义提供者有用 .
import { parseGitURI } from '@bluwy/giget-core'
parseGitURI('owner/repo') // { repo: 'owner/repo', subdir: '/' }
parseGitURI('owner/repo/subdir') // { repo: 'owner/repo', subdir: '/subdir' }
parseGitURI('owner/repo#main') // { repo: 'owner/repo', subdir: '/', ref: 'main' }
parseGitURI('owner/repo/subdir#main') // { repo: 'owner/repo', subdir: '/subdir', ref: 'main' }
从巨头移走
giget 出口a downloadTemplate (a) 方案辅助规划。 如果设置了任何选项,可能需要调整如下:
- 这个
forceClean选项合并为force: 'clean'。 。 。 . - 这个
preferOffline选项合并为offline: 'prefer'。 。 。 . - 这个
registry选项将删除。 您不能再下载主机的模板 千兆重现。通过直接沥青球 URL 或 git repo 代替. - 这个
install财务报告和审定财务报表silent删除用于安装依赖关系的选项。 您应该自己手动安装依赖性 .giget用途 yp 在引擎盖下. - 这个
auth选项已移动到providerOptions.auth。 。 。 . - 这个
TemplateProvider财务报告和审定财务报表TemplateInfo接口providers选项将略作修改.TemplateProvider: 函数必须返回 aTemplateInfo而不是无效。 如果它不能处理某事,它应该尝试一个有用的错误.TemplateInfo:它不再允许返回对象中的任意键.
- 返回的对象有:
TemplateInfo编辑info属性而不是在返回对象上展开. GIGET_环境变量支持被删除。 相反,它们应作为明确的选择予以通过.- 自动获取代理支持被删除 。 要重新启用,请使用Node.js 页:1 及以上,并设定
NODE_USE_ENV_PROXY=1在环境变量中。 见 节点.js 文件 更多信息.
归属
如上所述,该项目在很大程度上基于 吉娃娃谢谢 @ pi0 (韩语) 原作和战斗测试.
将来,我希望这里的代码可以合并到 giget,也许作为一个 giget-core 图书馆,并拥有 giget CLI作为包装库.
许可证
麻省理工学院