Create a Registry Index File Manually手动创建注册表索引文件
Warning
Experimental feature实验特性
This feature is experimental. MongoDB does not provide support for Snippets. 此功能是实验性的。MongoDB不支持Snippets。This feature may be changed or removed at any time without prior notice.此功能可能随时更改或删除,恕不另行通知。
Bugs are not expected, however should you encounter one, please open an issue in the GitHub repository预计不会出现ugs,但如果您遇到ugs,请在此项目的GitHub存储库 for this project.
中打开一个问题。
This page discusses how to manually create a registry index file. 本页讨论如何手动创建注册表索引文件。To generate the registry index file using a script, see Create a Registry Index File.要使用脚本生成注册表索引文件,请参阅创建注册表索引文件。
To create the registry index file:要创建注册表索引文件,请执行以下操作:
Copy the following TypeScript template and save it as复制以下TypeScript模板并将其保存为make-index.ts
:make-index.ts
:import bson from 'bson';
import zlib from 'zlib';
interface ErrorMatcher {
//Add additional information to shell errors matching one of the regular expressions.将附加信息添加到与某个正则表达式错误匹配的shell错误中。
//The message can point to a snippet helping solve that error.该消息可以指向帮助解决该错误的片段。
matches: RegExp[];
message: string;
}
interface SnippetDescription {
//The *npm* package name.*npm*程序包名称。Users do not interact with this.用户不与此交互。
name: string;
//The snippet name.代码段名称。This is what users interact with.这就是用户交互的内容。
snippetName: string;
//An optional install specifier that can be used to point npm towards packages that are not uploaded to the registry.可选的安装说明符,可用于将npm指向未上载到注册表的程序包。
//For example, this could be an URL to a git repository or a tarball.例如,这可以是git存储库或tarball的URL。
installSpec?: string;
//A version field.版本字段。Users do not interact with this, as currently, `snippet` always installs the latest versions of snippets.用户不与此交互,因为目前“snippet”总是安装snippet的最新版本。
version: string;
description: string;
readme: string;
//License should be a SPDX license identifier.许可证应该是SPDX许可证标识符。
license: string;
errorMatchers?: ErrorMatcher[];
}
interface SnippetIndexFile {
// This must be 1 currently.
indexFileVersion: 1;
index: SnippetDescription[];
metadata: { homepage: string };
}
const indexFileContents: SnippetIndexFile = {
indexFileVersion: 1,
index: [ /* ... */ ],
metadata: { homepage: 'https://example.com' }
};
//Serialize, compress and store the index file:序列化、压缩和存储索引文件:
fs.writeFileSync('index.bson.br',
zlib.brotliCompressSync(
bson.serialize(indexFileContents)));Edit根据需要编辑代码段包的make-index.ts
as needed for your snippet package.make-index.ts
。Use the comments as a guide to filling out the required information.使用注释作为填写所需信息的指南。Run运行ts-node make-index.ts
to create theindex.bson.br file
.ts-node make-index.ts
以index.bson.br file
文件。Upload将index.bson.br
to your GitHub repository.index.bson.br
上传到您的GitHub存储库。Update更新snippetIndexSourceURLs
to include a URL that references yourindex.bson.br
.snippetIndexSourceURLs
以包含引用您的index.bson.br
的URL。