手动创建注册表索引文件
本页讨论如何手动创建注册表索引文件。 要使用脚本生成注册表索引文件,请参阅创建注册表索引文件。
创建注册表索引文件:
复制以下 TypeScript 模板并将其保存为
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. The message can point to a snippet helping solve that error. matches: RegExp[]; message: string; } interface SnippetDescription { // The *npm* package name. 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. For example, // this could be an URL to a git repository or a tarball. installSpec?: string; // A version field. Users do not interact with this, as currently, `snippet` // always installs the latest versions of snippets. version: string; description: string; readme: string; // License should be a SPDX license identifier. 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))); 根据需要编辑代码段包的
make-index.ts
。 使用注释作为填写所需信息的指南。运行
ts-node make-index.ts
以创建index.bson.br file
。将
index.bson.br
上传到您的 GitHub 存储库。更新
snippetIndexSourceURLs
以包含引用index.bson.br
的 URL。